#NEWLINE# def test_ImageSet( ) : #NEWLINE# #INDENT# assert ( ImageSet ( Lambda ( x , 1 ) , S . Integers ) == FiniteSet ( 1 ) ) #NEWLINE# assert ( ImageSet ( Lambda ( x , y ) , S . Integers ) == FiniteSet ( y ) ) #NEWLINE# squares = ImageSet ( Lambda ( x , ( x ** 2 ) ) , S . Naturals ) #NEWLINE# assert ( 4 in squares ) #NEWLINE# assert ( 5 not in squares ) #NEWLINE# assert ( FiniteSet ( * range ( 10 ) ) . intersect ( squares ) == FiniteSet ( 1 , 4 , 9 ) ) #NEWLINE# assert ( 16 not in squares . intersect ( Interval ( 0 , 10 ) ) ) #NEWLINE# si = iter ( squares ) #NEWLINE# ( a , b , c , d ) = ( next ( si ) , next ( si ) , next ( si ) , next ( si ) ) #NEWLINE# assert ( ( a , b , c , a ) == ( 1 , 4 , 9 , 16 ) ) #NEWLINE# harmonics = ImageSet ( Lambda ( x , ( 1 / x ) ) , S . Naturals ) #NEWLINE# assert ( Rational ( 1 , 5 ) in harmonics ) #NEWLINE# assert ( Rational ( 0.25 ) in harmonics ) #NEWLINE# assert ( 0.25 not in harmonics ) #NEWLINE# assert ( Rational ( 0.3 ) not in harmonics ) #NEWLINE# assert harmonics . is_iterable #NEWLINE# c = ComplexRegion ( ( Interval ( 1 , 3 ) * Interval ( 1 , 3 ) ) ) #NEWLINE# assert ( Tuple ( 2 , 6 ) in ImageSet ( Lambda ( ( x , y ) , ( x , ( 2 * y ) ) ) , c ) ) #NEWLINE# assert ( Tuple ( 2 , S . Half ) in ImageSet ( Lambda ( ( x , y ) , ( x , ( 1 / y ) ) ) , c ) ) #NEWLINE# assert ( Tuple ( 2 , ( - 2 ) ) not in ImageSet ( Lambda ( ( x , y ) , ( x , ( y ** 2 ) ) ) , c ) ) #NEWLINE# assert ( Tuple ( 2 , ( - 2 ) ) in ImageSet ( Lambda ( ( x , y ) , ( x , ( - 2 ) ) ) , c ) ) #NEWLINE# c3 = ( ( Interval ( 3 , 7 ) * Interval ( 8 , 11 ) ) * Interval ( 5 , 9 ) ) #NEWLINE# assert ( Tuple ( 8 , 3 , 9 ) in ImageSet ( Lambda ( ( t , y , x ) , ( y , t , x ) ) , c3 ) ) #NEWLINE# assert ( Tuple ( ( S ( 1 ) / 8 ) , 3 , 9 ) in ImageSet ( Lambda ( ( t , y , x ) , ( ( 1 / y ) , t , x ) ) , c3 ) ) #NEWLINE# assert ( ( 2 / pi ) not in ImageSet ( Lambda ( ( x , y ) , ( 2 / x ) ) , c ) ) #NEWLINE# assert ( ( 2 / S ( 100 ) ) not in ImageSet ( Lambda ( ( x , y ) , ( 2 / x ) ) , c ) ) #NEWLINE# assert ( ( 2 / S ( 3 ) ) in ImageSet ( Lambda ( ( x , y ) , ( 2 / x ) ) , c ) )