<s> from __future__ import division <EOL> from sympy import ( Add , Basic , S , Symbol , Wild , Float , Integer , Rational , I , <EOL> sin , cos , tan , exp , log , nan , oo , sqrt , symbols , Integral , sympify , <EOL> WildFunction , Poly , Function , Derivative , Number , pi , NumberSymbol , zoo , <EOL> Piecewise , Mul , Pow , nsimplify , ratsimp , trigsimp , radsimp , powsimp , <EOL> simplify , together , collect , factorial , apart , combsimp , factor , refine , <EOL> cancel , Tuple , default_sort_key , DiracDelta , gamma , Dummy , Sum , E , <EOL> exp_polar , expand , diff , O , Heaviside , Si , Max ) <EOL> from sympy . core . function import AppliedUndef <EOL> from sympy . core . compatibility import range <EOL> from sympy . physics . secondquant import FockState <EOL> from sympy . physics . units import meter <EOL> from sympy . series . formal import FormalPowerSeries <EOL> from sympy . utilities . pytest import raises , XFAIL <EOL> from sympy . abc import a , b , c , n , t , u , x , y , z <EOL> class DummyNumber ( object ) : <EOL> """<STR_LIT>""" <EOL> def __radd__ ( self , a ) : <EOL> if isinstance ( a , ( int , float ) ) : <EOL> return a + self . number <EOL> return NotImplemented <EOL> def __truediv__ ( a , b ) : <EOL> return a . __div__ ( b ) <EOL> def __rtruediv__ ( a , b ) : <EOL> return a . __rdiv__ ( b ) <EOL> def __add__ ( self , a ) : <EOL> if isinstance ( a , ( int , float , DummyNumber ) ) : <EOL> return self . number + a <EOL> return NotImplemented <EOL> def __rsub__ ( self , a ) : <EOL> if isinstance ( a , ( int , float ) ) : <EOL> return a - self . number <EOL> return NotImplemented <EOL> def __sub__ ( self , a ) : <EOL> if isinstance ( a , ( int , float , DummyNumber ) ) : <EOL> return self . number - a <EOL> return NotImplemented <EOL> def __rmul__ ( self , a ) : <EOL> if isinstance ( a , ( int , float ) ) : <EOL> return a * self . number <EOL> return NotImplemented <EOL> def __mul__ ( self , a ) : <EOL> if isinstance ( a , ( int , float , DummyNumber ) ) : <EOL> return self . number * a <EOL> return NotImplemented <EOL> def __rdiv__ ( self , a ) : <EOL> if isinstance ( a , ( int , float ) ) : <EOL> return a / self . number <EOL> return NotImplemented <EOL> def __div__ ( self , a ) : <EOL> if isinstance ( a , ( int , float , DummyNumber ) ) : <EOL> return self . number / a <EOL> return NotImplemented <EOL> def __rpow__ ( self , a ) : <EOL> if isinstance ( a , ( int , float ) ) : <EOL> return a ** self . number <EOL> return NotImplemented <EOL> def __pow__ ( self , a ) : <EOL> if isinstance ( a , ( int , float , DummyNumber ) ) : <EOL> return self . number ** a <EOL> return NotImplemented <EOL> def __pos__ ( self ) : <EOL> return self . number <EOL> def __neg__ ( self ) : <EOL> return - self . number <EOL> class I5 ( DummyNumber ) : <EOL> number = <NUM_LIT:5> <EOL> def __int__ ( self ) : <EOL> return self . number <EOL> class F1_1 ( DummyNumber ) : <EOL> number = <NUM_LIT> <EOL> def __float__ ( self ) : <EOL> return self . number <EOL> i5 = I5 ( ) <EOL> f1_1 = F1_1 ( ) <EOL> basic_objs = [ <EOL> Rational ( <NUM_LIT:2> ) , <EOL> Float ( "<STR_LIT>" ) , <EOL> x , <EOL> y , <EOL> pow ( x , y ) * y , <EOL> ] <EOL> all_objs = basic_objs + [ <EOL> <NUM_LIT:5> , <EOL> <NUM_LIT> , <EOL> i5 , <EOL> f1_1 <EOL> ] <EOL> def dotest ( s ) : <EOL> for x in all_objs : <EOL> for y in all_objs : <EOL> s ( x , y ) <EOL> return True <EOL> def test_basic ( ) : <EOL> def j ( a , b ) : <EOL> x = a <EOL> x = + a <EOL> x = - a <EOL> x = a + b <EOL> x = a - b <EOL> x = a * b <EOL> x = a / b <EOL> x = a ** b <EOL> assert dotest ( j ) <EOL> def test_ibasic ( ) : <EOL> def s ( a , b ) : <EOL> x = a <EOL> x += b <EOL> x = a <EOL> x -= b <EOL> x = a <EOL> x *= b <EOL> x = a <EOL> x /= b <EOL> assert dotest ( s ) <EOL> def test_relational ( ) : <EOL> from sympy import Lt <EOL> assert ( pi < <NUM_LIT:3> ) is S . false <EOL> assert ( pi <= <NUM_LIT:3> ) is S . false <EOL> assert ( pi > <NUM_LIT:3> ) is S . true <EOL> assert ( pi >= <NUM_LIT:3> ) is S . true <EOL> assert ( - pi < <NUM_LIT:3> ) is S . true <EOL> assert ( - pi <= <NUM_LIT:3> ) is S . true <EOL> assert ( - pi > <NUM_LIT:3> ) is S . false <EOL> assert ( - pi >= <NUM_LIT:3> ) is S . false <EOL> r = Symbol ( '<STR_LIT:r>' , real = True ) <EOL> assert ( r - <NUM_LIT:2> < r - <NUM_LIT:3> ) is S . false <EOL> assert Lt ( x + I , x + I + <NUM_LIT:2> ) . func == Lt <EOL> def test_relational_assumptions ( ) : <EOL> from sympy import Lt , Gt , Le , Ge <EOL> m1 = Symbol ( "<STR_LIT>" , nonnegative = False ) <EOL> m2 = Symbol ( "<STR_LIT>" , positive = False ) <EOL> m3 = Symbol ( "<STR_LIT>" , nonpositive = False ) <EOL> m4 = Symbol ( "<STR_LIT>" , negative = False ) <EOL> assert ( m1 < <NUM_LIT:0> ) == Lt ( m1 , <NUM_LIT:0> ) <EOL> assert ( m2 <= <NUM_LIT:0> ) == Le ( m2 , <NUM_LIT:0> ) <EOL> assert ( m3 > <NUM_LIT:0> ) == Gt ( m3 , <NUM_LIT:0> ) <EOL> assert ( m4 >= <NUM_LIT:0> ) == Ge ( m4 , <NUM_LIT:0> ) <EOL> m1 = Symbol ( "<STR_LIT>" , nonnegative = False , real = True ) <EOL> m2 = Symbol ( "<STR_LIT>" , positive = False , real = True ) <EOL> m3 = Symbol ( "<STR_LIT>" , nonpositive = False , real = True ) <EOL> m4 = Symbol ( "<STR_LIT>" , negative = False , real = True ) <EOL> assert ( m1 < <NUM_LIT:0> ) is S . true <EOL> assert ( m2 <= <NUM_LIT:0> ) is S . true <EOL> assert ( m3 > <NUM_LIT:0> ) is S . true <EOL> assert ( m4 >= <NUM_LIT:0> ) is S . true <EOL> m1 = Symbol ( "<STR_LIT>" , negative = True ) <EOL> m2 = Symbol ( "<STR_LIT>" , nonpositive = True ) <EOL> m3 = Symbol ( "<STR_LIT>" , positive = True ) <EOL> m4 = Symbol ( "<STR_LIT>" , nonnegative = True ) <EOL> assert ( m1 < <NUM_LIT:0> ) is S . true <EOL> assert ( m2 <= <NUM_LIT:0> ) is S . true <EOL> assert ( m3 > <NUM_LIT:0> ) is S . true <EOL> assert ( m4 >= <NUM_LIT:0> ) is S . true <EOL> m1 = Symbol ( "<STR_LIT>" , negative = False , real = True ) <EOL> m2 = Symbol ( "<STR_LIT>" , nonpositive = False , real = True ) <EOL> m3 = Symbol ( "<STR_LIT>" , positive = False , real = True ) <EOL> m4 = Symbol ( "<STR_LIT>" , nonnegative = False , real = True ) <EOL> assert ( m1 < <NUM_LIT:0> ) is S . false <EOL> assert ( m2 <= <NUM_LIT:0> ) is S . false <EOL> assert ( m3 > <NUM_LIT:0> ) is S . false <EOL> assert ( m4 >= <NUM_LIT:0> ) is S . false <EOL> def test_relational_noncommutative ( ) : <EOL> from sympy import Lt , Gt , Le , Ge <EOL> A , B = symbols ( '<STR_LIT>' , commutative = False ) <EOL> assert ( A < B ) == Lt ( A , B ) <EOL> assert ( A <= B ) == Le ( A , B ) <EOL> assert ( A > B ) == Gt ( A , B ) <EOL> assert ( A >= B ) == Ge ( A , B ) <EOL> def test_basic_nostr ( ) : <EOL> for obj in basic_objs : <EOL> raises ( TypeError , lambda : obj + '<STR_LIT:1>' ) <EOL> raises ( TypeError , lambda : obj - '<STR_LIT:1>' ) <EOL> if obj == <NUM_LIT:2> : <EOL> assert obj * '<STR_LIT:1>' == '<STR_LIT>' <EOL> else : <EOL> raises ( TypeError , lambda : obj * '<STR_LIT:1>' ) <EOL> raises ( TypeError , lambda : obj / '<STR_LIT:1>' ) <EOL> raises ( TypeError , lambda : obj ** '<STR_LIT:1>' ) <EOL> def test_series_expansion_for_uniform_order ( ) : <EOL> assert ( <NUM_LIT:1> / x + y + x ) . series ( x , <NUM_LIT:0> , <NUM_LIT:0> ) == <NUM_LIT:1> / x + O ( <NUM_LIT:1> , x ) <EOL> assert ( <NUM_LIT:1> / x + y + x ) . series ( x , <NUM_LIT:0> , <NUM_LIT:1> ) == <NUM_LIT:1> / x + y + O ( x ) <EOL> assert ( <NUM_LIT:1> / x + <NUM_LIT:1> + x ) . series ( x , <NUM_LIT:0> , <NUM_LIT:0> ) == <NUM_LIT:1> / x + O ( <NUM_LIT:1> , x ) <EOL> assert ( <NUM_LIT:1> / x + <NUM_LIT:1> + x ) . series ( x , <NUM_LIT:0> , <NUM_LIT:1> ) == <NUM_LIT:1> / x + <NUM_LIT:1> + O ( x ) <EOL> assert ( <NUM_LIT:1> / x + x ) . series ( x , <NUM_LIT:0> , <NUM_LIT:0> ) == <NUM_LIT:1> / x + O ( <NUM_LIT:1> , x ) <EOL> assert ( <NUM_LIT:1> / x + y + y * x + x ) . series ( x , <NUM_LIT:0> , <NUM_LIT:0> ) == <NUM_LIT:1> / x + O ( <NUM_LIT:1> , x ) <EOL> assert ( <NUM_LIT:1> / x + y + y * x + x ) . series ( x , <NUM_LIT:0> , <NUM_LIT:1> ) == <NUM_LIT:1> / x + y + O ( x ) <EOL> def test_leadterm ( ) : <EOL> assert ( <NUM_LIT:3> + <NUM_LIT:2> * x ** ( log ( <NUM_LIT:3> ) / log ( <NUM_LIT:2> ) - <NUM_LIT:1> ) ) . leadterm ( x ) == ( <NUM_LIT:3> , <NUM_LIT:0> ) <EOL> assert ( <NUM_LIT:1> / x ** <NUM_LIT:2> + <NUM_LIT:1> + x + x ** <NUM_LIT:2> ) . leadterm ( x ) [ <NUM_LIT:1> ] == - <NUM_LIT:2> <EOL> assert ( <NUM_LIT:1> / x + <NUM_LIT:1> + x + x ** <NUM_LIT:2> ) . leadterm ( x ) [ <NUM_LIT:1> ] == - <NUM_LIT:1> <EOL> assert ( x ** <NUM_LIT:2> + <NUM_LIT:1> / x ) . leadterm ( x ) [ <NUM_LIT:1> ] == - <NUM_LIT:1> <EOL> assert ( <NUM_LIT:1> + x ** <NUM_LIT:2> ) . leadterm ( x ) [ <NUM_LIT:1> ] == <NUM_LIT:0> <EOL> assert ( x + <NUM_LIT:1> ) . leadterm ( x ) [ <NUM_LIT:1> ] == <NUM_LIT:0> <EOL> assert ( x + x ** <NUM_LIT:2> ) . leadterm ( x ) [ <NUM_LIT:1> ] == <NUM_LIT:1> <EOL> assert ( x ** <NUM_LIT:2> ) . leadterm ( x ) [ <NUM_LIT:1> ] == <NUM_LIT:2> <EOL> def test_as_leading_term ( ) : <EOL> assert ( <NUM_LIT:3> + <NUM_LIT:2> * x ** ( log ( <NUM_LIT:3> ) / log ( <NUM_LIT:2> ) - <NUM_LIT:1> ) ) . as_leading_term ( x ) == <NUM_LIT:3> <EOL> assert ( <NUM_LIT:1> / x ** <NUM_LIT:2> + <NUM_LIT:1> + x + x ** <NUM_LIT:2> ) . as_leading_term ( x ) == <NUM_LIT:1> / x ** <NUM_LIT:2> <EOL> assert ( <NUM_LIT:1> / x + <NUM_LIT:1> + x + x ** <NUM_LIT:2> ) . as_leading_term ( x ) == <NUM_LIT:1> / x <EOL> assert ( x ** <NUM_LIT:2> + <NUM_LIT:1> / x ) . as_leading_term ( x ) == <NUM_LIT:1> / x <EOL> assert ( <NUM_LIT:1> + x ** <NUM_LIT:2> ) . as_leading_term ( x ) == <NUM_LIT:1> <EOL> assert ( x + <NUM_LIT:1> ) . as_leading_term ( x ) == <NUM_LIT:1> <EOL> assert ( x + x ** <NUM_LIT:2> ) . as_leading_term ( x ) == x <EOL> assert ( x ** <NUM_LIT:2> ) . as_leading_term ( x ) == x ** <NUM_LIT:2> <EOL> assert ( x + oo ) . as_leading_term ( x ) == oo <EOL> def test_leadterm2 ( ) : <EOL> assert ( x * cos ( <NUM_LIT:1> ) * cos ( <NUM_LIT:1> + sin ( <NUM_LIT:1> ) ) + sin ( <NUM_LIT:1> + sin ( <NUM_LIT:1> ) ) ) . leadterm ( x ) == ( sin ( <NUM_LIT:1> + sin ( <NUM_LIT:1> ) ) , <NUM_LIT:0> ) <EOL> def test_leadterm3 ( ) : <EOL> assert ( y + z + x ) . leadterm ( x ) == ( y + z , <NUM_LIT:0> ) <EOL> def test_as_leading_term2 ( ) : <EOL> assert ( x * cos ( <NUM_LIT:1> ) * cos ( <NUM_LIT:1> + sin ( <NUM_LIT:1> ) ) + sin ( <NUM_LIT:1> + sin ( <NUM_LIT:1> ) ) ) . as_leading_term ( x ) == sin ( <NUM_LIT:1> + sin ( <NUM_LIT:1> ) ) <EOL> def test_as_leading_term3 ( ) : <EOL> assert ( <NUM_LIT:2> + pi + x ) . as_leading_term ( x ) == <NUM_LIT:2> + pi <EOL> assert ( <NUM_LIT:2> * x + pi * x + x ** <NUM_LIT:2> ) . as_leading_term ( x ) == ( <NUM_LIT:2> + pi ) * x <EOL> def test_as_leading_term4 ( ) : <EOL> n = Symbol ( '<STR_LIT:n>' , integer = True , positive = True ) <EOL> r = - n ** <NUM_LIT:3> / ( <NUM_LIT:2> * n ** <NUM_LIT:2> + <NUM_LIT:4> * n + <NUM_LIT:2> ) - n ** <NUM_LIT:2> / ( n ** <NUM_LIT:2> + <NUM_LIT:2> * n + <NUM_LIT:1> ) + n ** <NUM_LIT:2> / ( n + <NUM_LIT:1> ) - n / ( <NUM_LIT:2> * n ** <NUM_LIT:2> + <NUM_LIT:4> * n + <NUM_LIT:2> ) + n / ( n * x + x ) + <NUM_LIT:2> * n / ( n + <NUM_LIT:1> ) - <NUM_LIT:1> + <NUM_LIT:1> / ( n * x + x ) + <NUM_LIT:1> / ( n + <NUM_LIT:1> ) - <NUM_LIT:1> / x <EOL> assert r . as_leading_term ( x ) . cancel ( ) == n / <NUM_LIT:2> <EOL> def test_as_leading_term_stub ( ) : <EOL> class foo ( Function ) : <EOL> pass <EOL> assert foo ( <NUM_LIT:1> / x ) . as_leading_term ( x ) == foo ( <NUM_LIT:1> / x ) <EOL> assert foo ( <NUM_LIT:1> ) . as_leading_term ( x ) == foo ( <NUM_LIT:1> ) <EOL> raises ( NotImplementedError , lambda : foo ( x ) . as_leading_term ( x ) ) <EOL> def test_atoms ( ) : <EOL> assert x . atoms ( ) == { x } <EOL> assert ( <NUM_LIT:1> + x ) . atoms ( ) == { x , S ( <NUM_LIT:1> ) } <EOL> assert ( <NUM_LIT:1> + <NUM_LIT:2> * cos ( x ) ) . atoms ( Symbol ) == { x } <EOL> assert ( <NUM_LIT:1> + <NUM_LIT:2> * cos ( x ) ) . atoms ( Symbol , Number ) == { S ( <NUM_LIT:1> ) , S ( <NUM_LIT:2> ) , x } <EOL> assert ( <NUM_LIT:2> * ( x ** ( y ** x ) ) ) . atoms ( ) == { S ( <NUM_LIT:2> ) , x , y } <EOL> assert Rational ( <NUM_LIT:1> , <NUM_LIT:2> ) . atoms ( ) == { S . Half } <EOL> assert Rational ( <NUM_LIT:1> , <NUM_LIT:2> ) . atoms ( Symbol ) == set ( [ ] ) <EOL> assert sin ( oo ) . atoms ( oo ) == set ( ) <EOL> assert Poly ( <NUM_LIT:0> , x ) . atoms ( ) == { S . Zero } <EOL> assert Poly ( <NUM_LIT:1> , x ) . atoms ( ) == { S . One } <EOL> assert Poly ( x , x ) . atoms ( ) == { x } <EOL> assert Poly ( x , x , y ) . atoms ( ) == { x } <EOL> assert Poly ( x + y , x , y ) . atoms ( ) == { x , y } <EOL> assert Poly ( x + y , x , y , z ) . atoms ( ) == { x , y } <EOL> assert Poly ( x + y * t , x , y , z ) . atoms ( ) == { t , x , y } <EOL> assert ( I * pi ) . atoms ( NumberSymbol ) == { pi } <EOL> assert ( I * pi ) . atoms ( NumberSymbol , I ) == ( I * pi ) . atoms ( I , NumberSymbol ) == { pi , I } <EOL> assert exp ( exp ( x ) ) . atoms ( exp ) == { exp ( exp ( x ) ) , exp ( x ) } <EOL> assert ( <NUM_LIT:1> + x * ( <NUM_LIT:2> + y ) + exp ( <NUM_LIT:3> + z ) ) . atoms ( Add ) == { <NUM_LIT:1> + x * ( <NUM_LIT:2> + y ) + exp ( <NUM_LIT:3> + z ) , <NUM_LIT:2> + y , <NUM_LIT:3> + z } <EOL> f = Function ( '<STR_LIT:f>' ) <EOL> e = ( f ( x ) + sin ( x ) + <NUM_LIT:2> ) <EOL> assert e . atoms ( AppliedUndef ) == { f ( x ) } <EOL> assert e . atoms ( AppliedUndef , Function ) == { f ( x ) , sin ( x ) } <EOL> assert e . atoms ( Function ) == { f ( x ) , sin ( x ) } <EOL> assert e . atoms ( AppliedUndef , Number ) == { f ( x ) , S ( <NUM_LIT:2> ) } <EOL> assert e . atoms ( Function , Number ) == { S ( <NUM_LIT:2> ) , sin ( x ) , f ( x ) } <EOL> def test_is_polynomial ( ) : <EOL> k = Symbol ( '<STR_LIT:k>' , nonnegative = True , integer = True ) <EOL> assert Rational ( <NUM_LIT:2> ) . is_polynomial ( x , y , z ) is True <EOL> assert ( S . Pi ) . is_polynomial ( x , y , z ) is True <EOL> assert x . is_polynomial ( x ) is True <EOL> assert x . is_polynomial ( y ) is True <EOL> assert ( x ** <NUM_LIT:2> ) . is_polynomial ( x ) is True <EOL> assert ( x ** <NUM_LIT:2> ) . is_polynomial ( y ) is True <EOL> assert ( x ** ( - <NUM_LIT:2> ) ) . is_polynomial ( x ) is False <EOL> assert ( x ** ( - <NUM_LIT:2> ) ) . is_polynomial ( y ) is True <EOL> assert ( <NUM_LIT:2> ** x ) . is_polynomial ( x ) is False <EOL> assert ( <NUM_LIT:2> ** x ) . is_polynomial ( y ) is True <EOL> assert ( x ** k ) . is_polynomial ( x ) is False <EOL> assert ( x ** k ) . is_polynomial ( k ) is False <EOL> assert ( x ** x ) . is_polynomial ( x ) is False <EOL> assert ( k ** k ) . is_polynomial ( k ) is False <EOL> assert ( k ** x ) . is_polynomial ( k ) is False <EOL> assert ( x ** ( - k ) ) . is_polynomial ( x ) is False <EOL> assert ( ( <NUM_LIT:2> * x ) ** k ) . is_polynomial ( x ) is False <EOL> assert ( x ** <NUM_LIT:2> + <NUM_LIT:3> * x - <NUM_LIT:8> ) . is_polynomial ( x ) is True <EOL> assert ( x ** <NUM_LIT:2> + <NUM_LIT:3> * x - <NUM_LIT:8> ) . is_polynomial ( y ) is True <EOL> assert ( x ** <NUM_LIT:2> + <NUM_LIT:3> * x - <NUM_LIT:8> ) . is_polynomial ( ) is True <EOL> assert sqrt ( x ) . is_polynomial ( x ) is False <EOL> assert ( sqrt ( x ) ** <NUM_LIT:3> ) . is_polynomial ( x ) is False <EOL> assert ( x ** <NUM_LIT:2> + <NUM_LIT:3> * x * sqrt ( y ) - <NUM_LIT:8> ) . is_polynomial ( x ) is True <EOL> assert ( x ** <NUM_LIT:2> + <NUM_LIT:3> * x * sqrt ( y ) - <NUM_LIT:8> ) . is_polynomial ( y ) is False <EOL> assert ( ( x ** <NUM_LIT:2> ) * ( y ** <NUM_LIT:2> ) + x * ( y ** <NUM_LIT:2> ) + y * x + exp ( <NUM_LIT:2> ) ) . is_polynomial ( ) is True <EOL> assert ( ( x ** <NUM_LIT:2> ) * ( y ** <NUM_LIT:2> ) + x * ( y ** <NUM_LIT:2> ) + y * x + exp ( x ) ) . is_polynomial ( ) is False <EOL> assert ( <EOL> ( x ** <NUM_LIT:2> ) * ( y ** <NUM_LIT:2> ) + x * ( y ** <NUM_LIT:2> ) + y * x + exp ( <NUM_LIT:2> ) ) . is_polynomial ( x , y ) is True <EOL> assert ( <EOL> ( x ** <NUM_LIT:2> ) * ( y ** <NUM_LIT:2> ) + x * ( y ** <NUM_LIT:2> ) + y * x + exp ( x ) ) . is_polynomial ( x , y ) is False <EOL> def test_is_rational_function ( ) : <EOL> assert Integer ( <NUM_LIT:1> ) . is_rational_function ( ) is True <EOL> assert Integer ( <NUM_LIT:1> ) . is_rational_function ( x ) is True <EOL> assert Rational ( <NUM_LIT> , <NUM_LIT> ) . is_rational_function ( ) is True <EOL> assert Rational ( <NUM_LIT> , <NUM_LIT> ) . is_rational_function ( x ) is True <EOL> assert ( <NUM_LIT:12> / x ) . is_rational_function ( ) is True <EOL> assert ( <NUM_LIT:12> / x ) . is_rational_function ( x ) is True <EOL> assert ( x / y ) . is_rational_function ( ) is True <EOL> assert ( x / y ) . is_rational_function ( x ) is True <EOL> assert ( x / y ) . is_rational_function ( x , y ) is True <EOL> assert ( x ** <NUM_LIT:2> + <NUM_LIT:1> / x / y ) . is_rational_function ( ) is True <EOL> assert ( x ** <NUM_LIT:2> + <NUM_LIT:1> / x / y ) . is_rational_function ( x ) is True <EOL> assert ( x ** <NUM_LIT:2> + <NUM_LIT:1> / x / y ) . is_rational_function ( x , y ) is True <EOL> assert ( sin ( y ) / x ) . is_rational_function ( ) is False <EOL> assert ( sin ( y ) / x ) . is_rational_function ( y ) is False <EOL> assert ( sin ( y ) / x ) . is_rational_function ( x ) is True <EOL> assert ( sin ( y ) / x ) . is_rational_function ( x , y ) is False <EOL> assert ( S . NaN ) . is_rational_function ( ) is False <EOL> assert ( S . Infinity ) . is_rational_function ( ) is False <EOL> assert ( - S . Infinity ) . is_rational_function ( ) is False <EOL> assert ( S . ComplexInfinity ) . is_rational_function ( ) is False <EOL> def test_is_algebraic_expr ( ) : <EOL> assert sqrt ( <NUM_LIT:3> ) . is_algebraic_expr ( x ) is True <EOL> assert sqrt ( <NUM_LIT:3> ) . is_algebraic_expr ( ) is True <EOL> eq = ( ( <NUM_LIT:1> + x ** <NUM_LIT:2> ) / ( <NUM_LIT:1> - y ** <NUM_LIT:2> ) ) ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) <EOL> assert eq . is_algebraic_expr ( x ) is True <EOL> assert eq . is_algebraic_expr ( y ) is True <EOL> assert ( sqrt ( x ) + y ** ( S ( <NUM_LIT:2> ) / <NUM_LIT:3> ) ) . is_algebraic_expr ( x ) is True <EOL> assert ( sqrt ( x ) + y ** ( S ( <NUM_LIT:2> ) / <NUM_LIT:3> ) ) . is_algebraic_expr ( y ) is True <EOL> assert ( sqrt ( x ) + y ** ( S ( <NUM_LIT:2> ) / <NUM_LIT:3> ) ) . is_algebraic_expr ( ) is True <EOL> assert ( cos ( y ) / sqrt ( x ) ) . is_algebraic_expr ( ) is False <EOL> assert ( cos ( y ) / sqrt ( x ) ) . is_algebraic_expr ( x ) is True <EOL> assert ( cos ( y ) / sqrt ( x ) ) . is_algebraic_expr ( y ) is False <EOL> assert ( cos ( y ) / sqrt ( x ) ) . is_algebraic_expr ( x , y ) is False <EOL> def test_SAGE1 ( ) : <EOL> class MyInt : <EOL> def _sympy_ ( self ) : <EOL> return Integer ( <NUM_LIT:5> ) <EOL> m = MyInt ( ) <EOL> e = Rational ( <NUM_LIT:2> ) * m <EOL> assert e == <NUM_LIT:10> <EOL> raises ( TypeError , lambda : Rational ( <NUM_LIT:2> ) * MyInt ) <EOL> def test_SAGE2 ( ) : <EOL> class MyInt ( object ) : <EOL> def __int__ ( self ) : <EOL> return <NUM_LIT:5> <EOL> assert sympify ( MyInt ( ) ) == <NUM_LIT:5> <EOL> e = Rational ( <NUM_LIT:2> ) * MyInt ( ) <EOL> assert e == <NUM_LIT:10> <EOL> raises ( TypeError , lambda : Rational ( <NUM_LIT:2> ) * MyInt ) <EOL> def test_SAGE3 ( ) : <EOL> class MySymbol : <EOL> def __rmul__ ( self , other ) : <EOL> return ( '<STR_LIT>' , other , self ) <EOL> o = MySymbol ( ) <EOL> e = x * o <EOL> assert e == ( '<STR_LIT>' , x , o ) <EOL> def test_len ( ) : <EOL> e = x * y <EOL> assert len ( e . args ) == <NUM_LIT:2> <EOL> e = x + y + z <EOL> assert len ( e . args ) == <NUM_LIT:3> <EOL> def test_doit ( ) : <EOL> a = Integral ( x ** <NUM_LIT:2> , x ) <EOL> assert isinstance ( a . doit ( ) , Integral ) is False <EOL> assert isinstance ( a . doit ( integrals = True ) , Integral ) is False <EOL> assert isinstance ( a . doit ( integrals = False ) , Integral ) is True <EOL> assert ( <NUM_LIT:2> * Integral ( x , x ) ) . doit ( ) == x ** <NUM_LIT:2> <EOL> def test_attribute_error ( ) : <EOL> raises ( AttributeError , lambda : x . cos ( ) ) <EOL> raises ( AttributeError , lambda : x . sin ( ) ) <EOL> raises ( AttributeError , lambda : x . exp ( ) ) <EOL> def test_args ( ) : <EOL> assert ( x * y ) . args in ( ( x , y ) , ( y , x ) ) <EOL> assert ( x + y ) . args in ( ( x , y ) , ( y , x ) ) <EOL> assert ( x * y + <NUM_LIT:1> ) . args in ( ( x * y , <NUM_LIT:1> ) , ( <NUM_LIT:1> , x * y ) ) <EOL> assert sin ( x * y ) . args == ( x * y , ) <EOL> assert sin ( x * y ) . args [ <NUM_LIT:0> ] == x * y <EOL> assert ( x ** y ) . args == ( x , y ) <EOL> assert ( x ** y ) . args [ <NUM_LIT:0> ] == x <EOL> assert ( x ** y ) . args [ <NUM_LIT:1> ] == y <EOL> def test_noncommutative_expand_issue_3757 ( ) : <EOL> A , B , C = symbols ( '<STR_LIT>' , commutative = False ) <EOL> assert A * B - B * A != <NUM_LIT:0> <EOL> assert ( A * ( A + B ) * B ) . expand ( ) == A ** <NUM_LIT:2> * B + A * B ** <NUM_LIT:2> <EOL> assert ( A * ( A + B + C ) * B ) . expand ( ) == A ** <NUM_LIT:2> * B + A * B ** <NUM_LIT:2> + A * C * B <EOL> def test_as_numer_denom ( ) : <EOL> a , b , c = symbols ( '<STR_LIT>' ) <EOL> assert nan . as_numer_denom ( ) == ( nan , <NUM_LIT:1> ) <EOL> assert oo . as_numer_denom ( ) == ( oo , <NUM_LIT:1> ) <EOL> assert ( - oo ) . as_numer_denom ( ) == ( - oo , <NUM_LIT:1> ) <EOL> assert zoo . as_numer_denom ( ) == ( zoo , <NUM_LIT:1> ) <EOL> assert ( - zoo ) . as_numer_denom ( ) == ( zoo , <NUM_LIT:1> ) <EOL> assert x . as_numer_denom ( ) == ( x , <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:1> / x ) . as_numer_denom ( ) == ( <NUM_LIT:1> , x ) <EOL> assert ( x / y ) . as_numer_denom ( ) == ( x , y ) <EOL> assert ( x / <NUM_LIT:2> ) . as_numer_denom ( ) == ( x , <NUM_LIT:2> ) <EOL> assert ( x * y / z ) . as_numer_denom ( ) == ( x * y , z ) <EOL> assert ( x / ( y * z ) ) . as_numer_denom ( ) == ( x , y * z ) <EOL> assert Rational ( <NUM_LIT:1> , <NUM_LIT:2> ) . as_numer_denom ( ) == ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> assert ( <NUM_LIT:1> / y ** <NUM_LIT:2> ) . as_numer_denom ( ) == ( <NUM_LIT:1> , y ** <NUM_LIT:2> ) <EOL> assert ( x / y ** <NUM_LIT:2> ) . as_numer_denom ( ) == ( x , y ** <NUM_LIT:2> ) <EOL> assert ( ( x ** <NUM_LIT:2> + <NUM_LIT:1> ) / y ) . as_numer_denom ( ) == ( x ** <NUM_LIT:2> + <NUM_LIT:1> , y ) <EOL> assert ( x * ( y + <NUM_LIT:1> ) / y ** <NUM_LIT:7> ) . as_numer_denom ( ) == ( x * ( y + <NUM_LIT:1> ) , y ** <NUM_LIT:7> ) <EOL> assert ( x ** - <NUM_LIT:2> ) . as_numer_denom ( ) == ( <NUM_LIT:1> , x ** <NUM_LIT:2> ) <EOL> assert ( a / x + b / <NUM_LIT:2> / x + c / <NUM_LIT:3> / x ) . as_numer_denom ( ) == ( <NUM_LIT:6> * a + <NUM_LIT:3> * b + <NUM_LIT:2> * c , <NUM_LIT:6> * x ) <EOL> assert ( a / x + b / <NUM_LIT:2> / x + c / <NUM_LIT:3> / y ) . as_numer_denom ( ) == ( <NUM_LIT:2> * c * x + y * ( <NUM_LIT:6> * a + <NUM_LIT:3> * b ) , <NUM_LIT:6> * x * y ) <EOL> assert ( a / x + b / <NUM_LIT:2> / x + c / <NUM_LIT> / x ) . as_numer_denom ( ) == ( <NUM_LIT:2> * a + b + <NUM_LIT> * c , <NUM_LIT:2> * x ) <EOL> assert int ( log ( Add ( * [ Dummy ( ) / i / x for i in range ( <NUM_LIT:1> , <NUM_LIT> ) ] <EOL> ) . as_numer_denom ( ) [ <NUM_LIT:1> ] / x ) . n ( <NUM_LIT:4> ) ) == <NUM_LIT> <EOL> for i in [ S . Infinity , S . NegativeInfinity , S . ComplexInfinity ] : <EOL> assert ( i + x / <NUM_LIT:3> ) . as_numer_denom ( ) == ( x + i , <NUM_LIT:3> ) <EOL> assert ( S . Infinity + x / <NUM_LIT:3> + y / <NUM_LIT:4> ) . as_numer_denom ( ) == ( <NUM_LIT:4> * x + <NUM_LIT:3> * y + S . Infinity , <NUM_LIT:12> ) <EOL> assert ( oo * x + zoo * y ) . as_numer_denom ( ) == ( zoo * y + oo * x , <NUM_LIT:1> ) <EOL> A , B , C = symbols ( '<STR_LIT>' , commutative = False ) <EOL> assert ( A * B * C ** - <NUM_LIT:1> ) . as_numer_denom ( ) == ( A * B * C ** - <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> assert ( A * B * C ** - <NUM_LIT:1> / x ) . as_numer_denom ( ) == ( A * B * C ** - <NUM_LIT:1> , x ) <EOL> assert ( C ** - <NUM_LIT:1> * A * B ) . as_numer_denom ( ) == ( C ** - <NUM_LIT:1> * A * B , <NUM_LIT:1> ) <EOL> assert ( C ** - <NUM_LIT:1> * A * B / x ) . as_numer_denom ( ) == ( C ** - <NUM_LIT:1> * A * B , x ) <EOL> assert ( ( A * B * C ) ** - <NUM_LIT:1> ) . as_numer_denom ( ) == ( ( A * B * C ) ** - <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> assert ( ( A * B * C ) ** - <NUM_LIT:1> / x ) . as_numer_denom ( ) == ( ( A * B * C ) ** - <NUM_LIT:1> , x ) <EOL> def test_as_independent ( ) : <EOL> assert S . Zero . as_independent ( x , as_Add = True ) == ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> assert S . Zero . as_independent ( x , as_Add = False ) == ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> assert ( <NUM_LIT:2> * x * sin ( x ) + y + x ) . as_independent ( x ) == ( y , x + <NUM_LIT:2> * x * sin ( x ) ) <EOL> assert ( <NUM_LIT:2> * x * sin ( x ) + y + x ) . as_independent ( y ) == ( x + <NUM_LIT:2> * x * sin ( x ) , y ) <EOL> assert ( <NUM_LIT:2> * x * sin ( x ) + y + x ) . as_independent ( x , y ) == ( <NUM_LIT:0> , y + x + <NUM_LIT:2> * x * sin ( x ) ) <EOL> assert ( x * sin ( x ) * cos ( y ) ) . as_independent ( x ) == ( cos ( y ) , x * sin ( x ) ) <EOL> assert ( x * sin ( x ) * cos ( y ) ) . as_independent ( y ) == ( x * sin ( x ) , cos ( y ) ) <EOL> assert ( x * sin ( x ) * cos ( y ) ) . as_independent ( x , y ) == ( <NUM_LIT:1> , x * sin ( x ) * cos ( y ) ) <EOL> assert ( sin ( x ) ) . as_independent ( x ) == ( <NUM_LIT:1> , sin ( x ) ) <EOL> assert ( sin ( x ) ) . as_independent ( y ) == ( sin ( x ) , <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:2> * sin ( x ) ) . as_independent ( x ) == ( <NUM_LIT:2> , sin ( x ) ) <EOL> assert ( <NUM_LIT:2> * sin ( x ) ) . as_independent ( y ) == ( <NUM_LIT:2> * sin ( x ) , <NUM_LIT:1> ) <EOL> n1 , n2 , n3 = symbols ( '<STR_LIT>' , commutative = False ) <EOL> assert ( n1 + n1 * n2 ) . as_independent ( n2 ) == ( n1 , n1 * n2 ) <EOL> assert ( n2 * n1 + n1 * n2 ) . as_independent ( n2 ) == ( <NUM_LIT:0> , n1 * n2 + n2 * n1 ) <EOL> assert ( n1 * n2 * n1 ) . as_independent ( n2 ) == ( n1 , n2 * n1 ) <EOL> assert ( n1 * n2 * n1 ) . as_independent ( n1 ) == ( <NUM_LIT:1> , n1 * n2 * n1 ) <EOL> assert ( <NUM_LIT:3> * x ) . as_independent ( x , as_Add = True ) == ( <NUM_LIT:0> , <NUM_LIT:3> * x ) <EOL> assert ( <NUM_LIT:3> * x ) . as_independent ( x , as_Add = False ) == ( <NUM_LIT:3> , x ) <EOL> assert ( <NUM_LIT:3> + x ) . as_independent ( x , as_Add = True ) == ( <NUM_LIT:3> , x ) <EOL> assert ( <NUM_LIT:3> + x ) . as_independent ( x , as_Add = False ) == ( <NUM_LIT:1> , <NUM_LIT:3> + x ) <EOL> assert ( <NUM_LIT:3> * x ) . as_independent ( Symbol ) == ( <NUM_LIT:3> , x ) <EOL> assert ( n1 * x * y ) . as_independent ( x ) == ( n1 * y , x ) <EOL> assert ( ( x + n1 ) * ( x - y ) ) . as_independent ( x ) == ( <NUM_LIT:1> , ( x + n1 ) * ( x - y ) ) <EOL> assert ( ( x + n1 ) * ( x - y ) ) . as_independent ( y ) == ( x + n1 , x - y ) <EOL> assert ( DiracDelta ( x - n1 ) * DiracDelta ( x - y ) ) . as_independent ( x ) == ( <NUM_LIT:1> , DiracDelta ( x - n1 ) * DiracDelta ( x - y ) ) <EOL> assert ( x * y * n1 * n2 * n3 ) . as_independent ( n2 ) == ( x * y * n1 , n2 * n3 ) <EOL> assert ( x * y * n1 * n2 * n3 ) . as_independent ( n1 ) == ( x * y , n1 * n2 * n3 ) <EOL> assert ( x * y * n1 * n2 * n3 ) . as_independent ( n3 ) == ( x * y * n1 * n2 , n3 ) <EOL> assert ( DiracDelta ( x - n1 ) * DiracDelta ( y - n1 ) * DiracDelta ( x - n2 ) ) . as_independent ( y ) == ( DiracDelta ( x - n1 ) * DiracDelta ( x - n2 ) , DiracDelta ( y - n1 ) ) <EOL> assert ( x + Integral ( x , ( x , <NUM_LIT:1> , <NUM_LIT:2> ) ) ) . as_independent ( x , strict = True ) == ( Integral ( x , ( x , <NUM_LIT:1> , <NUM_LIT:2> ) ) , x ) <EOL> eq = Add ( x , - x , <NUM_LIT:2> , - <NUM_LIT:3> , evaluate = False ) <EOL> assert eq . as_independent ( x ) == ( - <NUM_LIT:1> , Add ( x , - x , evaluate = False ) ) <EOL> eq = Mul ( x , <NUM_LIT:1> / x , <NUM_LIT:2> , - <NUM_LIT:3> , evaluate = False ) <EOL> eq . as_independent ( x ) == ( - <NUM_LIT:6> , Mul ( x , <NUM_LIT:1> / x , evaluate = False ) ) <EOL> @ XFAIL <EOL> def test_call_2 ( ) : <EOL> f = Function ( '<STR_LIT:f>' ) <EOL> assert ( <NUM_LIT:2> * f ) ( x ) == <NUM_LIT:2> * f ( x ) <EOL> def test_replace ( ) : <EOL> f = log ( sin ( x ) ) + tan ( sin ( x ** <NUM_LIT:2> ) ) <EOL> assert f . replace ( sin , cos ) == log ( cos ( x ) ) + tan ( cos ( x ** <NUM_LIT:2> ) ) <EOL> assert f . replace ( <EOL> sin , lambda a : sin ( <NUM_LIT:2> * a ) ) == log ( sin ( <NUM_LIT:2> * x ) ) + tan ( sin ( <NUM_LIT:2> * x ** <NUM_LIT:2> ) ) <EOL> a = Wild ( '<STR_LIT:a>' ) <EOL> b = Wild ( '<STR_LIT:b>' ) <EOL> assert f . replace ( sin ( a ) , cos ( a ) ) == log ( cos ( x ) ) + tan ( cos ( x ** <NUM_LIT:2> ) ) <EOL> assert f . replace ( <EOL> sin ( a ) , lambda a : sin ( <NUM_LIT:2> * a ) ) == log ( sin ( <NUM_LIT:2> * x ) ) + tan ( sin ( <NUM_LIT:2> * x ** <NUM_LIT:2> ) ) <EOL> assert ( <NUM_LIT:2> * x ) . replace ( a * x + b , b - a , exact = True ) == <NUM_LIT:2> * x <EOL> assert ( <NUM_LIT:2> * x ) . replace ( a * x + b , b - a ) == <NUM_LIT:2> / x <EOL> assert ( <NUM_LIT:2> * x ) . replace ( a * x + b , lambda a , b : b - a , exact = True ) == <NUM_LIT:2> * x <EOL> assert ( <NUM_LIT:2> * x ) . replace ( a * x + b , lambda a , b : b - a ) == <NUM_LIT:2> / x <EOL> g = <NUM_LIT:2> * sin ( x ** <NUM_LIT:3> ) <EOL> assert g . replace ( <EOL> lambda expr : expr . is_Number , lambda expr : expr ** <NUM_LIT:2> ) == <NUM_LIT:4> * sin ( x ** <NUM_LIT:9> ) <EOL> assert cos ( x ) . replace ( cos , sin , map = True ) == ( sin ( x ) , { cos ( x ) : sin ( x ) } ) <EOL> assert sin ( x ) . replace ( cos , sin ) == sin ( x ) <EOL> cond , func = lambda x : x . is_Mul , lambda x : <NUM_LIT:2> * x <EOL> assert ( x * y ) . replace ( cond , func , map = True ) == ( <NUM_LIT:2> * x * y , { x * y : <NUM_LIT:2> * x * y } ) <EOL> assert ( x * ( <NUM_LIT:1> + x * y ) ) . replace ( cond , func , map = True ) == ( <NUM_LIT:2> * x * ( <NUM_LIT:2> * x * y + <NUM_LIT:1> ) , { x * ( <NUM_LIT:2> * x * y + <NUM_LIT:1> ) : <NUM_LIT:2> * x * ( <NUM_LIT:2> * x * y + <NUM_LIT:1> ) , x * y : <NUM_LIT:2> * x * y } ) <EOL> assert ( y * sin ( x ) ) . replace ( sin , lambda expr : sin ( expr ) / y , map = True ) == ( sin ( x ) , { sin ( x ) : sin ( x ) / y } ) <EOL> assert ( y * sin ( x ) ) . replace ( sin , lambda expr : sin ( expr ) / y , <EOL> simultaneous = False ) == sin ( x ) / y <EOL> assert ( x ** <NUM_LIT:2> + O ( x ** <NUM_LIT:3> ) ) . replace ( Pow , lambda b , e : b ** e / e ) == O ( <NUM_LIT:1> , x ) <EOL> assert ( x ** <NUM_LIT:2> + O ( x ** <NUM_LIT:3> ) ) . replace ( Pow , lambda b , e : b ** e / e , <EOL> simultaneous = False ) == x ** <NUM_LIT:2> / <NUM_LIT:2> + O ( x ** <NUM_LIT:3> ) <EOL> assert ( x * ( x * y + <NUM_LIT:3> ) ) . replace ( lambda x : x . is_Mul , lambda x : <NUM_LIT:2> + x ) == x * ( x * y + <NUM_LIT:5> ) + <NUM_LIT:2> <EOL> e = ( x * y + <NUM_LIT:1> ) * ( <NUM_LIT:2> * x * y + <NUM_LIT:1> ) + <NUM_LIT:1> <EOL> assert e . replace ( cond , func , map = True ) == ( <EOL> <NUM_LIT:2> * ( ( <NUM_LIT:2> * x * y + <NUM_LIT:1> ) * ( <NUM_LIT:4> * x * y + <NUM_LIT:1> ) ) + <NUM_LIT:1> , <EOL> { <NUM_LIT:2> * x * y : <NUM_LIT:4> * x * y , x * y : <NUM_LIT:2> * x * y , ( <NUM_LIT:2> * x * y + <NUM_LIT:1> ) * ( <NUM_LIT:4> * x * y + <NUM_LIT:1> ) : <EOL> <NUM_LIT:2> * ( ( <NUM_LIT:2> * x * y + <NUM_LIT:1> ) * ( <NUM_LIT:4> * x * y + <NUM_LIT:1> ) ) } ) <EOL> assert x . replace ( x , y ) == y <EOL> assert ( x + <NUM_LIT:1> ) . replace ( <NUM_LIT:1> , <NUM_LIT:2> ) == x + <NUM_LIT:2> <EOL> n1 , n2 , n3 = symbols ( '<STR_LIT>' , commutative = False ) <EOL> f = Function ( '<STR_LIT:f>' ) <EOL> assert ( n1 * f ( n2 ) ) . replace ( f , lambda x : x ) == n1 * n2 <EOL> assert ( n3 * f ( n2 ) ) . replace ( f , lambda x : x ) == n3 * n2 <EOL> def test_find ( ) : <EOL> expr = ( x + y + <NUM_LIT:2> + sin ( <NUM_LIT:3> * x ) ) <EOL> assert expr . find ( lambda u : u . is_Integer ) == { S ( <NUM_LIT:2> ) , S ( <NUM_LIT:3> ) } <EOL> assert expr . find ( lambda u : u . is_Symbol ) == { x , y } <EOL> assert expr . find ( lambda u : u . is_Integer , group = True ) == { S ( <NUM_LIT:2> ) : <NUM_LIT:1> , S ( <NUM_LIT:3> ) : <NUM_LIT:1> } <EOL> assert expr . find ( lambda u : u . is_Symbol , group = True ) == { x : <NUM_LIT:2> , y : <NUM_LIT:1> } <EOL> assert expr . find ( Integer ) == { S ( <NUM_LIT:2> ) , S ( <NUM_LIT:3> ) } <EOL> assert expr . find ( Symbol ) == { x , y } <EOL> assert expr . find ( Integer , group = True ) == { S ( <NUM_LIT:2> ) : <NUM_LIT:1> , S ( <NUM_LIT:3> ) : <NUM_LIT:1> } <EOL> assert expr . find ( Symbol , group = True ) == { x : <NUM_LIT:2> , y : <NUM_LIT:1> } <EOL> a = Wild ( '<STR_LIT:a>' ) <EOL> expr = sin ( sin ( x ) ) + sin ( x ) + cos ( x ) + x <EOL> assert expr . find ( lambda u : type ( u ) is sin ) == { sin ( x ) , sin ( sin ( x ) ) } <EOL> assert expr . find ( <EOL> lambda u : type ( u ) is sin , group = True ) == { sin ( x ) : <NUM_LIT:2> , sin ( sin ( x ) ) : <NUM_LIT:1> } <EOL> assert expr . find ( sin ( a ) ) == { sin ( x ) , sin ( sin ( x ) ) } <EOL> assert expr . find ( sin ( a ) , group = True ) == { sin ( x ) : <NUM_LIT:2> , sin ( sin ( x ) ) : <NUM_LIT:1> } <EOL> assert expr . find ( sin ) == { sin ( x ) , sin ( sin ( x ) ) } <EOL> assert expr . find ( sin , group = True ) == { sin ( x ) : <NUM_LIT:2> , sin ( sin ( x ) ) : <NUM_LIT:1> } <EOL> def test_count ( ) : <EOL> expr = ( x + y + <NUM_LIT:2> + sin ( <NUM_LIT:3> * x ) ) <EOL> assert expr . count ( lambda u : u . is_Integer ) == <NUM_LIT:2> <EOL> assert expr . count ( lambda u : u . is_Symbol ) == <NUM_LIT:3> <EOL> assert expr . count ( Integer ) == <NUM_LIT:2> <EOL> assert expr . count ( Symbol ) == <NUM_LIT:3> <EOL> assert expr . count ( <NUM_LIT:2> ) == <NUM_LIT:1> <EOL> a = Wild ( '<STR_LIT:a>' ) <EOL> assert expr . count ( sin ) == <NUM_LIT:1> <EOL> assert expr . count ( sin ( a ) ) == <NUM_LIT:1> <EOL> assert expr . count ( lambda u : type ( u ) is sin ) == <NUM_LIT:1> <EOL> def test_has_basics ( ) : <EOL> f = Function ( '<STR_LIT:f>' ) <EOL> g = Function ( '<STR_LIT:g>' ) <EOL> p = Wild ( '<STR_LIT:p>' ) <EOL> assert sin ( x ) . has ( x ) <EOL> assert sin ( x ) . has ( sin ) <EOL> assert not sin ( x ) . has ( y ) <EOL> assert not sin ( x ) . has ( cos ) <EOL> assert f ( x ) . has ( x ) <EOL> assert f ( x ) . has ( f ) <EOL> assert not f ( x ) . has ( y ) <EOL> assert not f ( x ) . has ( g ) <EOL> assert f ( x ) . diff ( x ) . has ( x ) <EOL> assert f ( x ) . diff ( x ) . has ( f ) <EOL> assert f ( x ) . diff ( x ) . has ( Derivative ) <EOL> assert not f ( x ) . diff ( x ) . has ( y ) <EOL> assert not f ( x ) . diff ( x ) . has ( g ) <EOL> assert not f ( x ) . diff ( x ) . has ( sin ) <EOL> assert ( x ** <NUM_LIT:2> ) . has ( Symbol ) <EOL> assert not ( x ** <NUM_LIT:2> ) . has ( Wild ) <EOL> assert ( <NUM_LIT:2> * p ) . has ( Wild ) <EOL> assert not x . has ( ) <EOL> def test_has_multiple ( ) : <EOL> f = x ** <NUM_LIT:2> * y + sin ( <NUM_LIT:2> ** t + log ( z ) ) <EOL> assert f . has ( x ) <EOL> assert f . has ( y ) <EOL> assert f . has ( z ) <EOL> assert f . has ( t ) <EOL> assert not f . has ( u ) <EOL> assert f . has ( x , y , z , t ) <EOL> assert f . has ( x , y , z , t , u ) <EOL> i = Integer ( <NUM_LIT> ) <EOL> assert not i . has ( x ) <EOL> assert ( i * x ** i ) . has ( x ) <EOL> assert not ( i * y ** i ) . has ( x ) <EOL> assert ( i * y ** i ) . has ( x , y ) <EOL> assert not ( i * y ** i ) . has ( x , z ) <EOL> def test_has_piecewise ( ) : <EOL> f = ( x * y + <NUM_LIT:3> / y ) ** ( <NUM_LIT:3> + <NUM_LIT:2> ) <EOL> g = Function ( '<STR_LIT:g>' ) <EOL> h = Function ( '<STR_LIT:h>' ) <EOL> p = Piecewise ( ( g ( x ) , x < - <NUM_LIT:1> ) , ( <NUM_LIT:1> , x <= <NUM_LIT:1> ) , ( f , True ) ) <EOL> assert p . has ( x ) <EOL> assert p . has ( y ) <EOL> assert not p . has ( z ) <EOL> assert p . has ( <NUM_LIT:1> ) <EOL> assert p . has ( <NUM_LIT:3> ) <EOL> assert not p . has ( <NUM_LIT:4> ) <EOL> assert p . has ( f ) <EOL> assert p . has ( g ) <EOL> assert not p . has ( h ) <EOL> def test_has_iterative ( ) : <EOL> A , B , C = symbols ( '<STR_LIT>' , commutative = False ) <EOL> f = x * gamma ( x ) * sin ( x ) * exp ( x * y ) * A * B * C * cos ( x * A * B ) <EOL> assert f . has ( x ) <EOL> assert f . has ( x * y ) <EOL> assert f . has ( x * sin ( x ) ) <EOL> assert not f . has ( x * sin ( y ) ) <EOL> assert f . has ( x * A ) <EOL> assert f . has ( x * A * B ) <EOL> assert not f . has ( x * A * C ) <EOL> assert f . has ( x * A * B * C ) <EOL> assert not f . has ( x * A * C * B ) <EOL> assert f . has ( x * sin ( x ) * A * B * C ) <EOL> assert not f . has ( x * sin ( x ) * A * C * B ) <EOL> assert not f . has ( x * sin ( y ) * A * B * C ) <EOL> assert f . has ( x * gamma ( x ) ) <EOL> assert not f . has ( x + sin ( x ) ) <EOL> assert ( x & y & z ) . has ( x & z ) <EOL> def test_has_integrals ( ) : <EOL> f = Integral ( x ** <NUM_LIT:2> + sin ( x * y * z ) , ( x , <NUM_LIT:0> , x + y + z ) ) <EOL> assert f . has ( x + y ) <EOL> assert f . has ( x + z ) <EOL> assert f . has ( y + z ) <EOL> assert f . has ( x * y ) <EOL> assert f . has ( x * z ) <EOL> assert f . has ( y * z ) <EOL> assert not f . has ( <NUM_LIT:2> * x + y ) <EOL> assert not f . has ( <NUM_LIT:2> * x * y ) <EOL> def test_has_tuple ( ) : <EOL> f = Function ( '<STR_LIT:f>' ) <EOL> g = Function ( '<STR_LIT:g>' ) <EOL> h = Function ( '<STR_LIT:h>' ) <EOL> assert Tuple ( x , y ) . has ( x ) <EOL> assert not Tuple ( x , y ) . has ( z ) <EOL> assert Tuple ( f ( x ) , g ( x ) ) . has ( x ) <EOL> assert not Tuple ( f ( x ) , g ( x ) ) . has ( y ) <EOL> assert Tuple ( f ( x ) , g ( x ) ) . has ( f ) <EOL> assert Tuple ( f ( x ) , g ( x ) ) . has ( f ( x ) ) <EOL> assert not Tuple ( f , g ) . has ( x ) <EOL> assert Tuple ( f , g ) . has ( f ) <EOL> assert not Tuple ( f , g ) . has ( h ) <EOL> assert Tuple ( True ) . has ( True ) is True <EOL> def test_has_units ( ) : <EOL> from sympy . physics . units import m , s <EOL> assert ( x * m / s ) . has ( x ) <EOL> assert ( x * m / s ) . has ( y , z ) is False <EOL> def test_has_polys ( ) : <EOL> poly = Poly ( x ** <NUM_LIT:2> + x * y * sin ( z ) , x , y , t ) <EOL> assert poly . has ( x ) <EOL> assert poly . has ( x , y , z ) <EOL> assert poly . has ( x , y , z , t ) <EOL> def test_has_physics ( ) : <EOL> assert FockState ( ( x , y ) ) . has ( x ) <EOL> def test_as_poly_as_expr ( ) : <EOL> f = x ** <NUM_LIT:2> + <NUM_LIT:2> * x * y <EOL> assert f . as_poly ( ) . as_expr ( ) == f <EOL> assert f . as_poly ( x , y ) . as_expr ( ) == f <EOL> assert ( f + sin ( x ) ) . as_poly ( x , y ) is None <EOL> p = Poly ( f , x , y ) <EOL> assert p . as_poly ( ) == p <EOL> def test_nonzero ( ) : <EOL> assert bool ( S . Zero ) is False <EOL> assert bool ( S . One ) is True <EOL> assert bool ( x ) is True <EOL> assert bool ( x + y ) is True <EOL> assert bool ( x - x ) is False <EOL> assert bool ( x * y ) is True <EOL> assert bool ( x * <NUM_LIT:1> ) is True <EOL> assert bool ( x * <NUM_LIT:0> ) is False <EOL> def test_is_number ( ) : <EOL> assert Float ( <NUM_LIT> ) . is_number is True <EOL> assert Integer ( <NUM_LIT> ) . is_number is True <EOL> assert Rational ( <NUM_LIT:3> , <NUM_LIT:2> ) . is_number is True <EOL> assert Rational ( <NUM_LIT:8> ) . is_number is True <EOL> assert x . is_number is False <EOL> assert ( <NUM_LIT:2> * x ) . is_number is False <EOL> assert ( x + y ) . is_number is False <EOL> assert log ( <NUM_LIT:2> ) . is_number is True <EOL> assert log ( x ) . is_number is False <EOL> assert ( <NUM_LIT:2> + log ( <NUM_LIT:2> ) ) . is_number is True <EOL> assert ( <NUM_LIT:8> + log ( <NUM_LIT:2> ) ) . is_number is True <EOL> assert ( <NUM_LIT:2> + log ( x ) ) . is_number is False <EOL> assert ( <NUM_LIT:8> + log ( <NUM_LIT:2> ) + x ) . is_number is False <EOL> assert ( <NUM_LIT:1> + x ** <NUM_LIT:2> / x - x ) . is_number is True <EOL> assert Tuple ( Integer ( <NUM_LIT:1> ) ) . is_number is False <EOL> assert Add ( <NUM_LIT:2> , x ) . is_number is False <EOL> assert Mul ( <NUM_LIT:3> , <NUM_LIT:4> ) . is_number is True <EOL> assert Pow ( log ( <NUM_LIT:2> ) , <NUM_LIT:2> ) . is_number is True <EOL> assert oo . is_number is True <EOL> g = WildFunction ( '<STR_LIT:g>' ) <EOL> assert g . is_number is False <EOL> assert ( <NUM_LIT:2> * g ) . is_number is False <EOL> assert ( x ** <NUM_LIT:2> ) . subs ( x , <NUM_LIT:3> ) . is_number is True <EOL> class A ( Basic ) : <EOL> pass <EOL> a = A ( ) <EOL> assert a . is_number is False <EOL> def test_as_coeff_add ( ) : <EOL> assert S ( <NUM_LIT:2> ) . as_coeff_add ( ) == ( <NUM_LIT:2> , ( ) ) <EOL> assert S ( <NUM_LIT> ) . as_coeff_add ( ) == ( <NUM_LIT:0> , ( S ( <NUM_LIT> ) , ) ) <EOL> assert S ( - <NUM_LIT> ) . as_coeff_add ( ) == ( <NUM_LIT:0> , ( S ( - <NUM_LIT> ) , ) ) <EOL> assert x . as_coeff_add ( ) == ( <NUM_LIT:0> , ( x , ) ) <EOL> assert ( x - <NUM_LIT:1> ) . as_coeff_add ( ) == ( - <NUM_LIT:1> , ( x , ) ) <EOL> assert ( x + <NUM_LIT:1> ) . as_coeff_add ( ) == ( <NUM_LIT:1> , ( x , ) ) <EOL> assert ( x + <NUM_LIT:2> ) . as_coeff_add ( ) == ( <NUM_LIT:2> , ( x , ) ) <EOL> assert ( x + y ) . as_coeff_add ( y ) == ( x , ( y , ) ) <EOL> assert ( <NUM_LIT:3> * x ) . as_coeff_add ( y ) == ( <NUM_LIT:3> * x , ( ) ) <EOL> e = ( x + y ) ** <NUM_LIT:2> <EOL> assert e . as_coeff_add ( y ) == ( <NUM_LIT:0> , ( e , ) ) <EOL> def test_as_coeff_mul ( ) : <EOL> assert S ( <NUM_LIT:2> ) . as_coeff_mul ( ) == ( <NUM_LIT:2> , ( ) ) <EOL> assert S ( <NUM_LIT> ) . as_coeff_mul ( ) == ( <NUM_LIT:1> , ( S ( <NUM_LIT> ) , ) ) <EOL> assert S ( - <NUM_LIT> ) . as_coeff_mul ( ) == ( - <NUM_LIT:1> , ( S ( <NUM_LIT> ) , ) ) <EOL> assert S ( - <NUM_LIT> ) . as_coeff_mul ( rational = False ) == ( - S ( <NUM_LIT> ) , ( ) ) <EOL> assert x . as_coeff_mul ( ) == ( <NUM_LIT:1> , ( x , ) ) <EOL> assert ( - x ) . as_coeff_mul ( ) == ( - <NUM_LIT:1> , ( x , ) ) <EOL> assert ( <NUM_LIT:2> * x ) . as_coeff_mul ( ) == ( <NUM_LIT:2> , ( x , ) ) <EOL> assert ( x * y ) . as_coeff_mul ( y ) == ( x , ( y , ) ) <EOL> assert ( <NUM_LIT:3> + x ) . as_coeff_mul ( ) == ( <NUM_LIT:1> , ( <NUM_LIT:3> + x , ) ) <EOL> assert ( <NUM_LIT:3> + x ) . as_coeff_mul ( y ) == ( <NUM_LIT:3> + x , ( ) ) <EOL> e = exp ( x + y ) <EOL> assert e . as_coeff_mul ( y ) == ( <NUM_LIT:1> , ( e , ) ) <EOL> e = <NUM_LIT:2> ** ( x + y ) <EOL> assert e . as_coeff_mul ( y ) == ( <NUM_LIT:1> , ( e , ) ) <EOL> assert ( <NUM_LIT> * x ) . as_coeff_mul ( rational = False ) == ( <NUM_LIT> , ( x , ) ) <EOL> assert ( <NUM_LIT> * x ) . as_coeff_mul ( ) == ( <NUM_LIT:1> , ( <NUM_LIT> , x ) ) <EOL> assert ( - oo * x ) . as_coeff_mul ( rational = True ) == ( - <NUM_LIT:1> , ( oo , x ) ) <EOL> def test_as_coeff_exponent ( ) : <EOL> assert ( <NUM_LIT:3> * x ** <NUM_LIT:4> ) . as_coeff_exponent ( x ) == ( <NUM_LIT:3> , <NUM_LIT:4> ) <EOL> assert ( <NUM_LIT:2> * x ** <NUM_LIT:3> ) . as_coeff_exponent ( x ) == ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assert ( <NUM_LIT:4> * x ** <NUM_LIT:2> ) . as_coeff_exponent ( x ) == ( <NUM_LIT:4> , <NUM_LIT:2> ) <EOL> assert ( <NUM_LIT:6> * x ** <NUM_LIT:1> ) . as_coeff_exponent ( x ) == ( <NUM_LIT:6> , <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:3> * x ** <NUM_LIT:0> ) . as_coeff_exponent ( x ) == ( <NUM_LIT:3> , <NUM_LIT:0> ) <EOL> assert ( <NUM_LIT:2> * x ** <NUM_LIT:0> ) . as_coeff_exponent ( x ) == ( <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> assert ( <NUM_LIT:1> * x ** <NUM_LIT:0> ) . as_coeff_exponent ( x ) == ( <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> assert ( <NUM_LIT:0> * x ** <NUM_LIT:0> ) . as_coeff_exponent ( x ) == ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> assert ( - <NUM_LIT:1> * x ** <NUM_LIT:0> ) . as_coeff_exponent ( x ) == ( - <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> assert ( - <NUM_LIT:2> * x ** <NUM_LIT:0> ) . as_coeff_exponent ( x ) == ( - <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> assert ( <NUM_LIT:2> * x ** <NUM_LIT:3> + pi * x ** <NUM_LIT:3> ) . as_coeff_exponent ( x ) == ( <NUM_LIT:2> + pi , <NUM_LIT:3> ) <EOL> assert ( x * log ( <NUM_LIT:2> ) / ( <NUM_LIT:2> * x + pi * x ) ) . as_coeff_exponent ( x ) == ( log ( <NUM_LIT:2> ) / ( <NUM_LIT:2> + pi ) , <NUM_LIT:0> ) <EOL> D = Derivative <EOL> f = Function ( '<STR_LIT:f>' ) <EOL> fx = D ( f ( x ) , x ) <EOL> assert fx . as_coeff_exponent ( f ( x ) ) == ( fx , <NUM_LIT:0> ) <EOL> def test_extractions ( ) : <EOL> assert ( ( x * y ) ** <NUM_LIT:3> ) . extract_multiplicatively ( x ** <NUM_LIT:2> * y ) == x * y ** <NUM_LIT:2> <EOL> assert ( ( x * y ) ** <NUM_LIT:3> ) . extract_multiplicatively ( x ** <NUM_LIT:4> * y ) is None <EOL> assert ( <NUM_LIT:2> * x ) . extract_multiplicatively ( <NUM_LIT:2> ) == x <EOL> assert ( <NUM_LIT:2> * x ) . extract_multiplicatively ( <NUM_LIT:3> ) is None <EOL> assert ( <NUM_LIT:2> * x ) . extract_multiplicatively ( - <NUM_LIT:1> ) is None <EOL> assert ( Rational ( <NUM_LIT:1> , <NUM_LIT:2> ) * x ) . extract_multiplicatively ( <NUM_LIT:3> ) == x / <NUM_LIT:6> <EOL> assert ( sqrt ( x ) ) . extract_multiplicatively ( x ) is None <EOL> assert ( sqrt ( x ) ) . extract_multiplicatively ( <NUM_LIT:1> / x ) is None <EOL> assert x . extract_multiplicatively ( - x ) is None <EOL> assert ( ( x * y ) ** <NUM_LIT:3> ) . extract_additively ( <NUM_LIT:1> ) is None <EOL> assert ( x + <NUM_LIT:1> ) . extract_additively ( x ) == <NUM_LIT:1> <EOL> assert ( x + <NUM_LIT:1> ) . extract_additively ( <NUM_LIT:2> * x ) is None <EOL> assert ( x + <NUM_LIT:1> ) . extract_additively ( - x ) is None <EOL> assert ( - x + <NUM_LIT:1> ) . extract_additively ( <NUM_LIT:2> * x ) is None <EOL> assert ( <NUM_LIT:2> * x + <NUM_LIT:3> ) . extract_additively ( x ) == x + <NUM_LIT:3> <EOL> assert ( <NUM_LIT:2> * x + <NUM_LIT:3> ) . extract_additively ( <NUM_LIT:2> ) == <NUM_LIT:2> * x + <NUM_LIT:1> <EOL> assert ( <NUM_LIT:2> * x + <NUM_LIT:3> ) . extract_additively ( <NUM_LIT:3> ) == <NUM_LIT:2> * x <EOL> assert ( <NUM_LIT:2> * x + <NUM_LIT:3> ) . extract_additively ( - <NUM_LIT:2> ) is None <EOL> assert ( <NUM_LIT:2> * x + <NUM_LIT:3> ) . extract_additively ( <NUM_LIT:3> * x ) is None <EOL> assert ( <NUM_LIT:2> * x + <NUM_LIT:3> ) . extract_additively ( <NUM_LIT:2> * x ) == <NUM_LIT:3> <EOL> assert x . extract_additively ( <NUM_LIT:0> ) == x <EOL> assert S ( <NUM_LIT:2> ) . extract_additively ( x ) is None <EOL> assert S ( <NUM_LIT> ) . extract_additively ( <NUM_LIT:2> ) == S . Zero <EOL> assert S ( <NUM_LIT:2> * x + <NUM_LIT:3> ) . extract_additively ( x + <NUM_LIT:1> ) == x + <NUM_LIT:2> <EOL> assert S ( <NUM_LIT:2> * x + <NUM_LIT:3> ) . extract_additively ( y + <NUM_LIT:1> ) is None <EOL> assert S ( <NUM_LIT:2> * x - <NUM_LIT:3> ) . extract_additively ( x + <NUM_LIT:1> ) is None <EOL> assert S ( <NUM_LIT:2> * x - <NUM_LIT:3> ) . extract_additively ( y + z ) is None <EOL> assert ( ( a + <NUM_LIT:1> ) * x * <NUM_LIT:4> + y ) . extract_additively ( x ) . expand ( ) == <NUM_LIT:4> * a * x + <NUM_LIT:3> * x + y <EOL> assert ( ( a + <NUM_LIT:1> ) * x * <NUM_LIT:4> + <NUM_LIT:3> * y ) . extract_additively ( x + <NUM_LIT:2> * y ) . expand ( ) == <NUM_LIT:4> * a * x + <NUM_LIT:3> * x + y <EOL> assert ( y * ( x + <NUM_LIT:1> ) ) . extract_additively ( x + <NUM_LIT:1> ) is None <EOL> assert ( ( y + <NUM_LIT:1> ) * ( x + <NUM_LIT:1> ) + <NUM_LIT:3> ) . extract_additively ( x + <NUM_LIT:1> ) == y * ( x + <NUM_LIT:1> ) + <NUM_LIT:3> <EOL> assert ( ( x + y ) * ( x + <NUM_LIT:1> ) + x + y + <NUM_LIT:3> ) . extract_additively ( x + y ) == x * ( x + y ) + <NUM_LIT:3> <EOL> assert ( x + y + <NUM_LIT:2> * ( ( x + y ) * ( x + <NUM_LIT:1> ) ) + <NUM_LIT:3> ) . extract_additively ( ( x + y ) * ( x + <NUM_LIT:1> ) ) == x + y + ( x + <NUM_LIT:1> ) * ( x + y ) + <NUM_LIT:3> <EOL> assert ( ( y + <NUM_LIT:1> ) * ( x + <NUM_LIT:2> * y + <NUM_LIT:1> ) + <NUM_LIT:3> ) . extract_additively ( y + <NUM_LIT:1> ) == ( x + <NUM_LIT:2> * y ) * ( y + <NUM_LIT:1> ) + <NUM_LIT:3> <EOL> n = Symbol ( "<STR_LIT:n>" , integer = True ) <EOL> assert ( Integer ( - <NUM_LIT:3> ) ) . could_extract_minus_sign ( ) is True <EOL> assert ( - n * x + x ) . could_extract_minus_sign ( ) != ( n * x - x ) . could_extract_minus_sign ( ) <EOL> assert ( x - y ) . could_extract_minus_sign ( ) != ( - x + y ) . could_extract_minus_sign ( ) <EOL> assert ( <NUM_LIT:1> - x - y ) . could_extract_minus_sign ( ) is True <EOL> assert ( <NUM_LIT:1> - x + y ) . could_extract_minus_sign ( ) is False <EOL> assert ( ( - x - x * y ) / y ) . could_extract_minus_sign ( ) is True <EOL> assert ( - ( x + x * y ) / y ) . could_extract_minus_sign ( ) is True <EOL> assert ( ( x + x * y ) / ( - y ) ) . could_extract_minus_sign ( ) is True <EOL> assert ( ( x + x * y ) / y ) . could_extract_minus_sign ( ) is False <EOL> assert ( x * ( - x - x ** <NUM_LIT:3> ) ) . could_extract_minus_sign ( ) is True <EOL> assert ( ( - x - y ) / ( x + y ) ) . could_extract_minus_sign ( ) is True <EOL> assert ( ( - x - y ) / ( x - y ) ) . could_extract_minus_sign ( ) is False or ( ( - x - y ) / ( y - x ) ) . could_extract_minus_sign ( ) is False <EOL> assert ( x - y ) . could_extract_minus_sign ( ) is False <EOL> assert ( - x + y ) . could_extract_minus_sign ( ) is True <EOL> def test_nan_extractions ( ) : <EOL> for r in ( <NUM_LIT:1> , <NUM_LIT:0> , I , nan ) : <EOL> assert nan . extract_additively ( r ) is None <EOL> assert nan . extract_multiplicatively ( r ) is None <EOL> def test_coeff ( ) : <EOL> assert ( x + <NUM_LIT:1> ) . coeff ( x + <NUM_LIT:1> ) == <NUM_LIT:1> <EOL> assert ( <NUM_LIT:3> * x ) . coeff ( <NUM_LIT:0> ) == <NUM_LIT:0> <EOL> assert ( z * ( <NUM_LIT:1> + x ) * x ** <NUM_LIT:2> ) . coeff ( <NUM_LIT:1> + x ) == z * x ** <NUM_LIT:2> <EOL> assert ( <NUM_LIT:1> + <NUM_LIT:2> * x * x ** ( <NUM_LIT:1> + x ) ) . coeff ( x * x ** ( <NUM_LIT:1> + x ) ) == <NUM_LIT:2> <EOL> assert ( <NUM_LIT:1> + <NUM_LIT:2> * x ** ( y + z ) ) . coeff ( x ** ( y + z ) ) == <NUM_LIT:2> <EOL> assert ( <NUM_LIT:3> + <NUM_LIT:2> * x + <NUM_LIT:4> * x ** <NUM_LIT:2> ) . coeff ( <NUM_LIT:1> ) == <NUM_LIT:0> <EOL> assert ( <NUM_LIT:3> + <NUM_LIT:2> * x + <NUM_LIT:4> * x ** <NUM_LIT:2> ) . coeff ( - <NUM_LIT:1> ) == <NUM_LIT:0> <EOL> assert ( <NUM_LIT:3> + <NUM_LIT:2> * x + <NUM_LIT:4> * x ** <NUM_LIT:2> ) . coeff ( x ) == <NUM_LIT:2> <EOL> assert ( <NUM_LIT:3> + <NUM_LIT:2> * x + <NUM_LIT:4> * x ** <NUM_LIT:2> ) . coeff ( x ** <NUM_LIT:2> ) == <NUM_LIT:4> <EOL> assert ( <NUM_LIT:3> + <NUM_LIT:2> * x + <NUM_LIT:4> * x ** <NUM_LIT:2> ) . coeff ( x ** <NUM_LIT:3> ) == <NUM_LIT:0> <EOL> assert ( - x / <NUM_LIT:8> + x * y ) . coeff ( x ) == - S ( <NUM_LIT:1> ) / <NUM_LIT:8> + y <EOL> assert ( - x / <NUM_LIT:8> + x * y ) . coeff ( - x ) == S ( <NUM_LIT:1> ) / <NUM_LIT:8> <EOL> assert ( <NUM_LIT:4> * x ) . coeff ( <NUM_LIT:2> * x ) == <NUM_LIT:0> <EOL> assert ( <NUM_LIT:2> * x ) . coeff ( <NUM_LIT:2> * x ) == <NUM_LIT:1> <EOL> assert ( - oo * x ) . coeff ( x * oo ) == - <NUM_LIT:1> <EOL> assert ( <NUM_LIT:10> * x ) . coeff ( x , <NUM_LIT:0> ) == <NUM_LIT:0> <EOL> assert ( <NUM_LIT:10> * x ) . coeff ( <NUM_LIT:10> * x , <NUM_LIT:0> ) == <NUM_LIT:0> <EOL> n1 , n2 = symbols ( '<STR_LIT>' , commutative = False ) <EOL> assert ( n1 * n2 ) . coeff ( n1 ) == <NUM_LIT:1> <EOL> assert ( n1 * n2 ) . coeff ( n2 ) == n1 <EOL> assert ( n1 * n2 + x * n1 ) . coeff ( n1 ) == <NUM_LIT:1> <EOL> assert ( n2 * n1 + x * n1 ) . coeff ( n1 ) == n2 + x <EOL> assert ( n2 * n1 + x * n1 ** <NUM_LIT:2> ) . coeff ( n1 ) == n2 <EOL> assert ( n1 ** x ) . coeff ( n1 ) == <NUM_LIT:0> <EOL> assert ( n1 * n2 + n2 * n1 ) . coeff ( n1 ) == <NUM_LIT:0> <EOL> assert ( <NUM_LIT:2> * ( n1 + n2 ) * n2 ) . coeff ( n1 + n2 , right = <NUM_LIT:1> ) == n2 <EOL> assert ( <NUM_LIT:2> * ( n1 + n2 ) * n2 ) . coeff ( n1 + n2 , right = <NUM_LIT:0> ) == <NUM_LIT:2> <EOL> f = Function ( '<STR_LIT:f>' ) <EOL> assert ( <NUM_LIT:2> * f ( x ) + <NUM_LIT:3> * f ( x ) . diff ( x ) ) . coeff ( f ( x ) ) == <NUM_LIT:2> <EOL> expr = z * ( x + y ) ** <NUM_LIT:2> <EOL> expr2 = z * ( x + y ) ** <NUM_LIT:2> + z * ( <NUM_LIT:2> * x + <NUM_LIT:2> * y ) ** <NUM_LIT:2> <EOL> assert expr . coeff ( z ) == ( x + y ) ** <NUM_LIT:2> <EOL> assert expr . coeff ( x + y ) == <NUM_LIT:0> <EOL> assert expr2 . coeff ( z ) == ( x + y ) ** <NUM_LIT:2> + ( <NUM_LIT:2> * x + <NUM_LIT:2> * y ) ** <NUM_LIT:2> <EOL> assert ( x + y + <NUM_LIT:3> * z ) . coeff ( <NUM_LIT:1> ) == x + y <EOL> assert ( - x + <NUM_LIT:2> * y ) . coeff ( - <NUM_LIT:1> ) == x <EOL> assert ( x - <NUM_LIT:2> * y ) . coeff ( - <NUM_LIT:1> ) == <NUM_LIT:2> * y <EOL> assert ( <NUM_LIT:3> + <NUM_LIT:2> * x + <NUM_LIT:4> * x ** <NUM_LIT:2> ) . coeff ( <NUM_LIT:1> ) == <NUM_LIT:0> <EOL> assert ( - x - <NUM_LIT:2> * y ) . coeff ( <NUM_LIT:2> ) == - y <EOL> assert ( x + sqrt ( <NUM_LIT:2> ) * x ) . coeff ( sqrt ( <NUM_LIT:2> ) ) == x <EOL> assert ( <NUM_LIT:3> + <NUM_LIT:2> * x + <NUM_LIT:4> * x ** <NUM_LIT:2> ) . coeff ( x ) == <NUM_LIT:2> <EOL> assert ( <NUM_LIT:3> + <NUM_LIT:2> * x + <NUM_LIT:4> * x ** <NUM_LIT:2> ) . coeff ( x ** <NUM_LIT:2> ) == <NUM_LIT:4> <EOL> assert ( <NUM_LIT:3> + <NUM_LIT:2> * x + <NUM_LIT:4> * x ** <NUM_LIT:2> ) . coeff ( x ** <NUM_LIT:3> ) == <NUM_LIT:0> <EOL> assert ( z * ( x + y ) ** <NUM_LIT:2> ) . coeff ( ( x + y ) ** <NUM_LIT:2> ) == z <EOL> assert ( z * ( x + y ) ** <NUM_LIT:2> ) . coeff ( x + y ) == <NUM_LIT:0> <EOL> assert ( <NUM_LIT:2> + <NUM_LIT:2> * x + ( x + <NUM_LIT:1> ) * y ) . coeff ( x + <NUM_LIT:1> ) == y <EOL> assert ( x + <NUM_LIT:2> * y + <NUM_LIT:3> ) . coeff ( <NUM_LIT:1> ) == x <EOL> assert ( x + <NUM_LIT:2> * y + <NUM_LIT:3> ) . coeff ( x , <NUM_LIT:0> ) == <NUM_LIT:2> * y + <NUM_LIT:3> <EOL> assert ( x ** <NUM_LIT:2> + <NUM_LIT:2> * y + <NUM_LIT:3> * x ) . coeff ( x ** <NUM_LIT:2> , <NUM_LIT:0> ) == <NUM_LIT:2> * y + <NUM_LIT:3> * x <EOL> assert x . coeff ( <NUM_LIT:0> , <NUM_LIT:0> ) == <NUM_LIT:0> <EOL> assert x . coeff ( x , <NUM_LIT:0> ) == <NUM_LIT:0> <EOL> n , m , o , l = symbols ( '<STR_LIT>' , commutative = False ) <EOL> assert n . coeff ( n ) == <NUM_LIT:1> <EOL> assert y . coeff ( n ) == <NUM_LIT:0> <EOL> assert ( <NUM_LIT:3> * n ) . coeff ( n ) == <NUM_LIT:3> <EOL> assert ( <NUM_LIT:2> + n ) . coeff ( x * m ) == <NUM_LIT:0> <EOL> assert ( <NUM_LIT:2> * x * n * m ) . coeff ( x ) == <NUM_LIT:2> * n * m <EOL> assert ( <NUM_LIT:2> + n ) . coeff ( x * m * n + y ) == <NUM_LIT:0> <EOL> assert ( <NUM_LIT:2> * x * n * m ) . coeff ( <NUM_LIT:3> * n ) == <NUM_LIT:0> <EOL> assert ( n * m + m * n * m ) . coeff ( n ) == <NUM_LIT:1> + m <EOL> assert ( n * m + m * n * m ) . coeff ( n , right = True ) == m <EOL> assert ( n * m + m * n ) . coeff ( n ) == <NUM_LIT:0> <EOL> assert ( n * m + o * m * n ) . coeff ( m * n ) == o <EOL> assert ( n * m + o * m * n ) . coeff ( m * n , right = <NUM_LIT:1> ) == <NUM_LIT:1> <EOL> assert ( n * m + n * m * n ) . coeff ( n * m , right = <NUM_LIT:1> ) == <NUM_LIT:1> + n <EOL> def test_coeff2 ( ) : <EOL> r , kappa = symbols ( '<STR_LIT>' ) <EOL> psi = Function ( "<STR_LIT>" ) <EOL> g = <NUM_LIT:1> / r ** <NUM_LIT:2> * ( <NUM_LIT:2> * r * psi ( r ) . diff ( r , <NUM_LIT:1> ) + r ** <NUM_LIT:2> * psi ( r ) . diff ( r , <NUM_LIT:2> ) ) <EOL> g = g . expand ( ) <EOL> assert g . coeff ( ( psi ( r ) . diff ( r ) ) ) == <NUM_LIT:2> / r <EOL> def test_coeff2_0 ( ) : <EOL> r , kappa = symbols ( '<STR_LIT>' ) <EOL> psi = Function ( "<STR_LIT>" ) <EOL> g = <NUM_LIT:1> / r ** <NUM_LIT:2> * ( <NUM_LIT:2> * r * psi ( r ) . diff ( r , <NUM_LIT:1> ) + r ** <NUM_LIT:2> * psi ( r ) . diff ( r , <NUM_LIT:2> ) ) <EOL> g = g . expand ( ) <EOL> assert g . coeff ( psi ( r ) . diff ( r , <NUM_LIT:2> ) ) == <NUM_LIT:1> <EOL> def test_coeff_expand ( ) : <EOL> expr = z * ( x + y ) ** <NUM_LIT:2> <EOL> expr2 = z * ( x + y ) ** <NUM_LIT:2> + z * ( <NUM_LIT:2> * x + <NUM_LIT:2> * y ) ** <NUM_LIT:2> <EOL> assert expr . coeff ( z ) == ( x + y ) ** <NUM_LIT:2> <EOL> assert expr2 . coeff ( z ) == ( x + y ) ** <NUM_LIT:2> + ( <NUM_LIT:2> * x + <NUM_LIT:2> * y ) ** <NUM_LIT:2> <EOL> def test_integrate ( ) : <EOL> assert x . integrate ( x ) == x ** <NUM_LIT:2> / <NUM_LIT:2> <EOL> assert x . integrate ( ( x , <NUM_LIT:0> , <NUM_LIT:1> ) ) == S ( <NUM_LIT:1> ) / <NUM_LIT:2> <EOL> def test_as_base_exp ( ) : <EOL> assert x . as_base_exp ( ) == ( x , S . One ) <EOL> assert ( x * y * z ) . as_base_exp ( ) == ( x * y * z , S . One ) <EOL> assert ( x + y + z ) . as_base_exp ( ) == ( x + y + z , S . One ) <EOL> assert ( ( x + y ) ** z ) . as_base_exp ( ) == ( x + y , z ) <EOL> def test_issue_4963 ( ) : <EOL> assert hasattr ( Mul ( x , y ) , "<STR_LIT>" ) <EOL> assert hasattr ( Mul ( x , y , evaluate = False ) , "<STR_LIT>" ) <EOL> assert hasattr ( Pow ( x , y ) , "<STR_LIT>" ) <EOL> assert hasattr ( Pow ( x , y , evaluate = False ) , "<STR_LIT>" ) <EOL> expr = Mul ( Pow ( <NUM_LIT:2> , <NUM_LIT:2> , evaluate = False ) , <NUM_LIT:3> , evaluate = False ) + <NUM_LIT:1> <EOL> assert hasattr ( expr , "<STR_LIT>" ) <EOL> def test_action_verbs ( ) : <EOL> assert nsimplify ( ( <NUM_LIT:1> / ( exp ( <NUM_LIT:3> * pi * x / <NUM_LIT:5> ) + <NUM_LIT:1> ) ) ) == ( <NUM_LIT:1> / ( exp ( <NUM_LIT:3> * pi * x / <NUM_LIT:5> ) + <NUM_LIT:1> ) ) . nsimplify ( ) <EOL> assert ratsimp ( <NUM_LIT:1> / x + <NUM_LIT:1> / y ) == ( <NUM_LIT:1> / x + <NUM_LIT:1> / y ) . ratsimp ( ) <EOL> assert trigsimp ( log ( x ) , deep = True ) == ( log ( x ) ) . trigsimp ( deep = True ) <EOL> assert radsimp ( <NUM_LIT:1> / ( <NUM_LIT:2> + sqrt ( <NUM_LIT:2> ) ) ) == ( <NUM_LIT:1> / ( <NUM_LIT:2> + sqrt ( <NUM_LIT:2> ) ) ) . radsimp ( ) <EOL> assert powsimp ( x ** y * x ** z * y ** z , combine = '<STR_LIT:all>' ) == ( x ** y * x ** z * y ** z ) . powsimp ( combine = '<STR_LIT:all>' ) <EOL> assert simplify ( x ** y * x ** z * y ** z ) == ( x ** y * x ** z * y ** z ) . simplify ( ) <EOL> assert together ( <NUM_LIT:1> / x + <NUM_LIT:1> / y ) == ( <NUM_LIT:1> / x + <NUM_LIT:1> / y ) . together ( ) <EOL> assert collect ( a * x ** <NUM_LIT:2> + b * x ** <NUM_LIT:2> + a * x - b * x + c , x ) == ( a * x ** <NUM_LIT:2> + b * x ** <NUM_LIT:2> + a * x - b * x + c ) . collect ( x ) <EOL> assert apart ( y / ( y + <NUM_LIT:2> ) / ( y + <NUM_LIT:1> ) , y ) == ( y / ( y + <NUM_LIT:2> ) / ( y + <NUM_LIT:1> ) ) . apart ( y ) <EOL> assert combsimp ( y / ( x + <NUM_LIT:2> ) / ( x + <NUM_LIT:1> ) ) == ( y / ( x + <NUM_LIT:2> ) / ( x + <NUM_LIT:1> ) ) . combsimp ( ) <EOL> assert factor ( x ** <NUM_LIT:2> + <NUM_LIT:5> * x + <NUM_LIT:6> ) == ( x ** <NUM_LIT:2> + <NUM_LIT:5> * x + <NUM_LIT:6> ) . factor ( ) <EOL> assert refine ( sqrt ( x ** <NUM_LIT:2> ) ) == sqrt ( x ** <NUM_LIT:2> ) . refine ( ) <EOL> assert cancel ( ( x ** <NUM_LIT:2> + <NUM_LIT:5> * x + <NUM_LIT:6> ) / ( x + <NUM_LIT:2> ) ) == ( ( x ** <NUM_LIT:2> + <NUM_LIT:5> * x + <NUM_LIT:6> ) / ( x + <NUM_LIT:2> ) ) . cancel ( ) <EOL> def test_as_powers_dict ( ) : <EOL> assert x . as_powers_dict ( ) == { x : <NUM_LIT:1> } <EOL> assert ( x ** y * z ) . as_powers_dict ( ) == { x : y , z : <NUM_LIT:1> } <EOL> assert Mul ( <NUM_LIT:2> , <NUM_LIT:2> , evaluate = False ) . as_powers_dict ( ) == { S ( <NUM_LIT:2> ) : S ( <NUM_LIT:2> ) } <EOL> assert ( x * y ) . as_powers_dict ( ) [ z ] == <NUM_LIT:0> <EOL> assert ( x + y ) . as_powers_dict ( ) [ z ] == <NUM_LIT:0> <EOL> def test_as_coefficients_dict ( ) : <EOL> check = [ S ( <NUM_LIT:1> ) , x , y , x * y , <NUM_LIT:1> ] <EOL> assert [ Add ( <NUM_LIT:3> * x , <NUM_LIT:2> * x , y , <NUM_LIT:3> ) . as_coefficients_dict ( ) [ i ] for i in check ] == [ <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:3> ] <EOL> assert [ ( <NUM_LIT:3> * x * y ) . as_coefficients_dict ( ) [ i ] for i in check ] == [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:0> ] <EOL> assert ( <NUM_LIT> * x * y ) . as_coefficients_dict ( ) [ <NUM_LIT> * x * y ] == <NUM_LIT:1> <EOL> def test_args_cnc ( ) : <EOL> A = symbols ( '<STR_LIT:A>' , commutative = False ) <EOL> assert ( x + A ) . args_cnc ( ) == [ [ ] , [ x + A ] ] <EOL> assert ( x + a ) . args_cnc ( ) == [ [ a + x ] , [ ] ] <EOL> assert ( x * a ) . args_cnc ( ) == [ [ a , x ] , [ ] ] <EOL> assert ( x * y * A * ( A + <NUM_LIT:1> ) ) . args_cnc ( cset = True ) == [ { x , y } , [ A , <NUM_LIT:1> + A ] ] <EOL> assert Mul ( x , x , evaluate = False ) . args_cnc ( cset = True , warn = False ) == [ { x } , [ ] ] <EOL> assert Mul ( x , x ** <NUM_LIT:2> , evaluate = False ) . args_cnc ( cset = True , warn = False ) == [ { x , x ** <NUM_LIT:2> } , [ ] ] <EOL> raises ( ValueError , lambda : Mul ( x , x , evaluate = False ) . args_cnc ( cset = True ) ) <EOL> assert Mul ( x , y , x , evaluate = False ) . args_cnc ( ) == [ [ x , y , x ] , [ ] ] <EOL> assert ( - <NUM_LIT:1.> * x ) . args_cnc ( ) == [ [ - <NUM_LIT:1> , <NUM_LIT:1.0> , x ] , [ ] ] <EOL> def test_new_rawargs ( ) : <EOL> n = Symbol ( '<STR_LIT:n>' , commutative = False ) <EOL> a = x + n <EOL> assert a . is_commutative is False <EOL> assert a . _new_rawargs ( x ) . is_commutative <EOL> assert a . _new_rawargs ( x , y ) . is_commutative <EOL> assert a . _new_rawargs ( x , n ) . is_commutative is False <EOL> assert a . _new_rawargs ( x , y , n ) . is_commutative is False <EOL> m = x * n <EOL> assert m . is_commutative is False <EOL> assert m . _new_rawargs ( x ) . is_commutative <EOL> assert m . _new_rawargs ( n ) . is_commutative is False <EOL> assert m . _new_rawargs ( x , y ) . is_commutative <EOL> assert m . _new_rawargs ( x , n ) . is_commutative is False <EOL> assert m . _new_rawargs ( x , y , n ) . is_commutative is False <EOL> assert m . _new_rawargs ( x , n , reeval = False ) . is_commutative is False <EOL> assert m . _new_rawargs ( S . One ) is S . One <EOL> def test_issue_5226 ( ) : <EOL> assert Add ( evaluate = False ) == <NUM_LIT:0> <EOL> assert Mul ( evaluate = False ) == <NUM_LIT:1> <EOL> assert Mul ( x + y , evaluate = False ) . is_Add <EOL> def test_free_symbols ( ) : <EOL> assert S ( <NUM_LIT:1> ) . free_symbols == set ( ) <EOL> assert ( x ) . free_symbols == { x } <EOL> assert Integral ( x , ( x , <NUM_LIT:1> , y ) ) . free_symbols == { y } <EOL> assert ( - Integral ( x , ( x , <NUM_LIT:1> , y ) ) ) . free_symbols == { y } <EOL> assert meter . free_symbols == set ( ) <EOL> assert ( meter ** x ) . free_symbols == { x } <EOL> def test_issue_5300 ( ) : <EOL> x = Symbol ( '<STR_LIT:x>' , commutative = False ) <EOL> assert x * sqrt ( <NUM_LIT:2> ) / sqrt ( <NUM_LIT:6> ) == x * sqrt ( <NUM_LIT:3> ) / <NUM_LIT:3> <EOL> def test_as_coeff_Mul ( ) : <EOL> assert S ( <NUM_LIT:0> ) . as_coeff_Mul ( ) == ( S . One , S . Zero ) <EOL> assert Integer ( <NUM_LIT:3> ) . as_coeff_Mul ( ) == ( Integer ( <NUM_LIT:3> ) , Integer ( <NUM_LIT:1> ) ) <EOL> assert Rational ( <NUM_LIT:3> , <NUM_LIT:4> ) . as_coeff_Mul ( ) == ( Rational ( <NUM_LIT:3> , <NUM_LIT:4> ) , Integer ( <NUM_LIT:1> ) ) <EOL> assert Float ( <NUM_LIT> ) . as_coeff_Mul ( ) == ( Float ( <NUM_LIT> ) , Integer ( <NUM_LIT:1> ) ) <EOL> assert ( Integer ( <NUM_LIT:3> ) * x ) . as_coeff_Mul ( ) == ( Integer ( <NUM_LIT:3> ) , x ) <EOL> assert ( Rational ( <NUM_LIT:3> , <NUM_LIT:4> ) * x ) . as_coeff_Mul ( ) == ( Rational ( <NUM_LIT:3> , <NUM_LIT:4> ) , x ) <EOL> assert ( Float ( <NUM_LIT> ) * x ) . as_coeff_Mul ( ) == ( Float ( <NUM_LIT> ) , x ) <EOL> assert ( Integer ( <NUM_LIT:3> ) * x * y ) . as_coeff_Mul ( ) == ( Integer ( <NUM_LIT:3> ) , x * y ) <EOL> assert ( Rational ( <NUM_LIT:3> , <NUM_LIT:4> ) * x * y ) . as_coeff_Mul ( ) == ( Rational ( <NUM_LIT:3> , <NUM_LIT:4> ) , x * y ) <EOL> assert ( Float ( <NUM_LIT> ) * x * y ) . as_coeff_Mul ( ) == ( Float ( <NUM_LIT> ) , x * y ) <EOL> assert ( x ) . as_coeff_Mul ( ) == ( S . One , x ) <EOL> assert ( x * y ) . as_coeff_Mul ( ) == ( S . One , x * y ) <EOL> assert ( - oo * x ) . as_coeff_Mul ( rational = True ) == ( - <NUM_LIT:1> , oo * x ) <EOL> def test_as_coeff_Add ( ) : <EOL> assert Integer ( <NUM_LIT:3> ) . as_coeff_Add ( ) == ( Integer ( <NUM_LIT:3> ) , Integer ( <NUM_LIT:0> ) ) <EOL> assert Rational ( <NUM_LIT:3> , <NUM_LIT:4> ) . as_coeff_Add ( ) == ( Rational ( <NUM_LIT:3> , <NUM_LIT:4> ) , Integer ( <NUM_LIT:0> ) ) <EOL> assert Float ( <NUM_LIT> ) . as_coeff_Add ( ) == ( Float ( <NUM_LIT> ) , Integer ( <NUM_LIT:0> ) ) <EOL> assert ( Integer ( <NUM_LIT:3> ) + x ) . as_coeff_Add ( ) == ( Integer ( <NUM_LIT:3> ) , x ) <EOL> assert ( Rational ( <NUM_LIT:3> , <NUM_LIT:4> ) + x ) . as_coeff_Add ( ) == ( Rational ( <NUM_LIT:3> , <NUM_LIT:4> ) , x ) <EOL> assert ( Float ( <NUM_LIT> ) + x ) . as_coeff_Add ( ) == ( Float ( <NUM_LIT> ) , x ) <EOL> assert ( Float ( <NUM_LIT> ) + x ) . as_coeff_Add ( rational = True ) == ( <NUM_LIT:0> , Float ( <NUM_LIT> ) + x ) <EOL> assert ( Integer ( <NUM_LIT:3> ) + x + y ) . as_coeff_Add ( ) == ( Integer ( <NUM_LIT:3> ) , x + y ) <EOL> assert ( Rational ( <NUM_LIT:3> , <NUM_LIT:4> ) + x + y ) . as_coeff_Add ( ) == ( Rational ( <NUM_LIT:3> , <NUM_LIT:4> ) , x + y ) <EOL> assert ( Float ( <NUM_LIT> ) + x + y ) . as_coeff_Add ( ) == ( Float ( <NUM_LIT> ) , x + y ) <EOL> assert ( x ) . as_coeff_Add ( ) == ( S . Zero , x ) <EOL> assert ( x * y ) . as_coeff_Add ( ) == ( S . Zero , x * y ) <EOL> def test_expr_sorting ( ) : <EOL> f , g = symbols ( '<STR_LIT>' , cls = Function ) <EOL> exprs = [ <NUM_LIT:1> / x ** <NUM_LIT:2> , <NUM_LIT:1> / x , sqrt ( sqrt ( x ) ) , sqrt ( x ) , x , sqrt ( x ) ** <NUM_LIT:3> , x ** <NUM_LIT:2> ] <EOL> assert sorted ( exprs , key = default_sort_key ) == exprs <EOL> exprs = [ x , <NUM_LIT:2> * x , <NUM_LIT:2> * x ** <NUM_LIT:2> , <NUM_LIT:2> * x ** <NUM_LIT:3> , x ** n , <NUM_LIT:2> * x ** n , sin ( x ) , sin ( x ) ** n , <EOL> sin ( x ** <NUM_LIT:2> ) , cos ( x ) , cos ( x ** <NUM_LIT:2> ) , tan ( x ) ] <EOL> assert sorted ( exprs , key = default_sort_key ) == exprs <EOL> exprs = [ x + <NUM_LIT:1> , x ** <NUM_LIT:2> + x + <NUM_LIT:1> , x ** <NUM_LIT:3> + x ** <NUM_LIT:2> + x + <NUM_LIT:1> ] <EOL> assert sorted ( exprs , key = default_sort_key ) == exprs <EOL> exprs = [ S ( <NUM_LIT:4> ) , x - <NUM_LIT:3> * I / <NUM_LIT:2> , x + <NUM_LIT:3> * I / <NUM_LIT:2> , x - <NUM_LIT:4> * I + <NUM_LIT:1> , x + <NUM_LIT:4> * I + <NUM_LIT:1> ] <EOL> assert sorted ( exprs , key = default_sort_key ) == exprs <EOL> exprs = [ f ( <NUM_LIT:1> ) , f ( <NUM_LIT:2> ) , f ( <NUM_LIT:3> ) , f ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) , g ( <NUM_LIT:1> ) , g ( <NUM_LIT:2> ) , g ( <NUM_LIT:3> ) , g ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ] <EOL> assert sorted ( exprs , key = default_sort_key ) == exprs <EOL> exprs = [ f ( x ) , g ( x ) , exp ( x ) , sin ( x ) , cos ( x ) , factorial ( x ) ] <EOL> assert sorted ( exprs , key = default_sort_key ) == exprs <EOL> exprs = [ Tuple ( x , y ) , Tuple ( x , z ) , Tuple ( x , y , z ) ] <EOL> assert sorted ( exprs , key = default_sort_key ) == exprs <EOL> exprs = [ [ <NUM_LIT:3> ] , [ <NUM_LIT:1> , <NUM_LIT:2> ] ] <EOL> assert sorted ( exprs , key = default_sort_key ) == exprs <EOL> exprs = [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:2> , <NUM_LIT:3> ] ] <EOL> assert sorted ( exprs , key = default_sort_key ) == exprs <EOL> exprs = [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ] <EOL> assert sorted ( exprs , key = default_sort_key ) == exprs <EOL> exprs = [ { x : - y } , { x : y } ] <EOL> assert sorted ( exprs , key = default_sort_key ) == exprs <EOL> exprs = [ { <NUM_LIT:1> } , { <NUM_LIT:1> , <NUM_LIT:2> } ] <EOL> assert sorted ( exprs , key = default_sort_key ) == exprs <EOL> a , b = exprs = [ Dummy ( '<STR_LIT:x>' ) , Dummy ( '<STR_LIT:x>' ) ] <EOL> assert sorted ( [ b , a ] , key = default_sort_key ) == exprs <EOL> def test_as_ordered_factors ( ) : <EOL> f , g = symbols ( '<STR_LIT>' , cls = Function ) <EOL> assert x . as_ordered_factors ( ) == [ x ] <EOL> assert ( <NUM_LIT:2> * x * x ** n * sin ( x ) * cos ( x ) ) . as_ordered_factors ( ) == [ Integer ( <NUM_LIT:2> ) , x , x ** n , sin ( x ) , cos ( x ) ] <EOL> args = [ f ( <NUM_LIT:1> ) , f ( <NUM_LIT:2> ) , f ( <NUM_LIT:3> ) , f ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) , g ( <NUM_LIT:1> ) , g ( <NUM_LIT:2> ) , g ( <NUM_LIT:3> ) , g ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ] <EOL> expr = Mul ( * args ) <EOL> assert expr . as_ordered_factors ( ) == args <EOL> A , B = symbols ( '<STR_LIT>' , commutative = False ) <EOL> assert ( A * B ) . as_ordered_factors ( ) == [ A , B ] <EOL> assert ( B * A ) . as_ordered_factors ( ) == [ B , A ] <EOL> def test_as_ordered_terms ( ) : <EOL> f , g = symbols ( '<STR_LIT>' , cls = Function ) <EOL> assert x . as_ordered_terms ( ) == [ x ] <EOL> assert ( sin ( x ) ** <NUM_LIT:2> * cos ( x ) + sin ( x ) * cos ( x ) ** <NUM_LIT:2> + <NUM_LIT:1> ) . as_ordered_terms ( ) == [ sin ( x ) ** <NUM_LIT:2> * cos ( x ) , sin ( x ) * cos ( x ) ** <NUM_LIT:2> , <NUM_LIT:1> ] <EOL> args = [ f ( <NUM_LIT:1> ) , f ( <NUM_LIT:2> ) , f ( <NUM_LIT:3> ) , f ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) , g ( <NUM_LIT:1> ) , g ( <NUM_LIT:2> ) , g ( <NUM_LIT:3> ) , g ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ] <EOL> expr = Add ( * args ) <EOL> assert expr . as_ordered_terms ( ) == args <EOL> assert ( <NUM_LIT:1> + <NUM_LIT:4> * sqrt ( <NUM_LIT:3> ) * pi * x ) . as_ordered_terms ( ) == [ <NUM_LIT:4> * pi * x * sqrt ( <NUM_LIT:3> ) , <NUM_LIT:1> ] <EOL> assert ( <NUM_LIT:2> + <NUM_LIT:3> * I ) . as_ordered_terms ( ) == [ <NUM_LIT:2> , <NUM_LIT:3> * I ] <EOL> assert ( - <NUM_LIT:2> + <NUM_LIT:3> * I ) . as_ordered_terms ( ) == [ - <NUM_LIT:2> , <NUM_LIT:3> * I ] <EOL> assert ( <NUM_LIT:2> - <NUM_LIT:3> * I ) . as_ordered_terms ( ) == [ <NUM_LIT:2> , - <NUM_LIT:3> * I ] <EOL> assert ( - <NUM_LIT:2> - <NUM_LIT:3> * I ) . as_ordered_terms ( ) == [ - <NUM_LIT:2> , - <NUM_LIT:3> * I ] <EOL> assert ( <NUM_LIT:4> + <NUM_LIT:3> * I ) . as_ordered_terms ( ) == [ <NUM_LIT:4> , <NUM_LIT:3> * I ] <EOL> assert ( - <NUM_LIT:4> + <NUM_LIT:3> * I ) . as_ordered_terms ( ) == [ - <NUM_LIT:4> , <NUM_LIT:3> * I ] <EOL> assert ( <NUM_LIT:4> - <NUM_LIT:3> * I ) . as_ordered_terms ( ) == [ <NUM_LIT:4> , - <NUM_LIT:3> * I ] <EOL> assert ( - <NUM_LIT:4> - <NUM_LIT:3> * I ) . as_ordered_terms ( ) == [ - <NUM_LIT:4> , - <NUM_LIT:3> * I ] <EOL> f = x ** <NUM_LIT:2> * y ** <NUM_LIT:2> + x * y ** <NUM_LIT:4> + y + <NUM_LIT:2> <EOL> assert f . as_ordered_terms ( order = "<STR_LIT>" ) == [ x ** <NUM_LIT:2> * y ** <NUM_LIT:2> , x * y ** <NUM_LIT:4> , y , <NUM_LIT:2> ] <EOL> assert f . as_ordered_terms ( order = "<STR_LIT>" ) == [ x * y ** <NUM_LIT:4> , x ** <NUM_LIT:2> * y ** <NUM_LIT:2> , y , <NUM_LIT:2> ] <EOL> assert f . as_ordered_terms ( order = "<STR_LIT>" ) == [ <NUM_LIT:2> , y , x * y ** <NUM_LIT:4> , x ** <NUM_LIT:2> * y ** <NUM_LIT:2> ] <EOL> assert f . as_ordered_terms ( order = "<STR_LIT>" ) == [ <NUM_LIT:2> , y , x ** <NUM_LIT:2> * y ** <NUM_LIT:2> , x * y ** <NUM_LIT:4> ] <EOL> def test_sort_key_atomic_expr ( ) : <EOL> from sympy . physics . units import m , s <EOL> assert sorted ( [ - m , s ] , key = lambda arg : arg . sort_key ( ) ) == [ - m , s ] <EOL> def test_issue_4199 ( ) : <EOL> a = x / y <EOL> assert a . _eval_interval ( x , <NUM_LIT:0> , oo ) . _eval_interval ( y , oo , <NUM_LIT:0> ) is S . NaN <EOL> assert a . _eval_interval ( x , <NUM_LIT:0> , oo ) . _eval_interval ( y , <NUM_LIT:0> , oo ) is S . NaN <EOL> a = x - y <EOL> assert a . _eval_interval ( x , <NUM_LIT:1> , oo ) . _eval_interval ( y , oo , <NUM_LIT:1> ) is S . NaN <EOL> raises ( ValueError , lambda : x . _eval_interval ( x , None , None ) ) <EOL> a = - y * Heaviside ( x - y ) <EOL> assert a . _eval_interval ( x , - oo , oo ) == - y <EOL> assert a . _eval_interval ( x , oo , - oo ) == y <EOL> def test_eval_interval_zoo ( ) : <EOL> assert Si ( <NUM_LIT:1> / x ) . _eval_interval ( x , <NUM_LIT:0> , <NUM_LIT:1> ) == - pi / <NUM_LIT:2> + Si ( <NUM_LIT:1> ) <EOL> def test_primitive ( ) : <EOL> assert ( <NUM_LIT:3> * ( x + <NUM_LIT:1> ) ** <NUM_LIT:2> ) . primitive ( ) == ( <NUM_LIT:3> , ( x + <NUM_LIT:1> ) ** <NUM_LIT:2> ) <EOL> assert ( <NUM_LIT:6> * x + <NUM_LIT:2> ) . primitive ( ) == ( <NUM_LIT:2> , <NUM_LIT:3> * x + <NUM_LIT:1> ) <EOL> assert ( x / <NUM_LIT:2> + <NUM_LIT:3> ) . primitive ( ) == ( S ( <NUM_LIT:1> ) / <NUM_LIT:2> , x + <NUM_LIT:6> ) <EOL> eq = ( <NUM_LIT:6> * x + <NUM_LIT:2> ) * ( x / <NUM_LIT:2> + <NUM_LIT:3> ) <EOL> assert eq . primitive ( ) [ <NUM_LIT:0> ] == <NUM_LIT:1> <EOL> eq = ( <NUM_LIT:2> + <NUM_LIT:2> * x ) ** <NUM_LIT:2> <EOL> assert eq . primitive ( ) [ <NUM_LIT:0> ] == <NUM_LIT:1> <EOL> assert ( <NUM_LIT> * x ) . primitive ( ) == ( <NUM_LIT:1> , <NUM_LIT> * x ) <EOL> assert ( <NUM_LIT> * x + y / <NUM_LIT:2> ) . primitive ( ) == ( S . Half , <NUM_LIT> * x + y ) <EOL> assert ( - <NUM_LIT:2> * x ) . primitive ( ) == ( <NUM_LIT:2> , - x ) <EOL> assert Add ( <NUM_LIT:5> * z / <NUM_LIT:7> , <NUM_LIT:0.5> * x , <NUM_LIT:3> * y / <NUM_LIT:2> , evaluate = False ) . primitive ( ) == ( S ( <NUM_LIT:1> ) / <NUM_LIT> , <NUM_LIT> * x + <NUM_LIT> * y + <NUM_LIT:10> * z ) <EOL> for i in [ S . Infinity , S . NegativeInfinity , S . ComplexInfinity ] : <EOL> assert ( i + x / <NUM_LIT:3> ) . primitive ( ) == ( S ( <NUM_LIT:1> ) / <NUM_LIT:3> , i + x ) <EOL> assert ( S . Infinity + <NUM_LIT:2> * x / <NUM_LIT:3> + <NUM_LIT:4> * y / <NUM_LIT:7> ) . primitive ( ) == ( S ( <NUM_LIT:1> ) / <NUM_LIT> , <NUM_LIT> * x + <NUM_LIT:12> * y + oo ) <EOL> assert S . Zero . primitive ( ) == ( S . One , S . Zero ) <EOL> def test_issue_5843 ( ) : <EOL> a = <NUM_LIT:1> + x <EOL> assert ( <NUM_LIT:2> * a ) . extract_multiplicatively ( a ) == <NUM_LIT:2> <EOL> assert ( <NUM_LIT:4> * a ) . extract_multiplicatively ( <NUM_LIT:2> * a ) == <NUM_LIT:2> <EOL> assert ( ( <NUM_LIT:3> * a ) * ( <NUM_LIT:2> * a ) ) . extract_multiplicatively ( a ) == <NUM_LIT:6> * a <EOL> def test_is_constant ( ) : <EOL> from sympy . solvers . solvers import checksol <EOL> Sum ( x , ( x , <NUM_LIT:1> , <NUM_LIT:10> ) ) . is_constant ( ) is True <EOL> Sum ( x , ( x , <NUM_LIT:1> , n ) ) . is_constant ( ) is False <EOL> Sum ( x , ( x , <NUM_LIT:1> , n ) ) . is_constant ( y ) is True <EOL> Sum ( x , ( x , <NUM_LIT:1> , n ) ) . is_constant ( n ) is False <EOL> Sum ( x , ( x , <NUM_LIT:1> , n ) ) . is_constant ( x ) is True <EOL> eq = a * cos ( x ) ** <NUM_LIT:2> + a * sin ( x ) ** <NUM_LIT:2> - a <EOL> eq . is_constant ( ) is True <EOL> assert eq . subs ( { x : pi , a : <NUM_LIT:2> } ) == eq . subs ( { x : pi , a : <NUM_LIT:3> } ) == <NUM_LIT:0> <EOL> assert x . is_constant ( ) is False <EOL> assert x . is_constant ( y ) is True <EOL> assert checksol ( x , x , Sum ( x , ( x , <NUM_LIT:1> , n ) ) ) is False <EOL> assert checksol ( x , x , Sum ( x , ( x , <NUM_LIT:1> , n ) ) ) is False <EOL> f = Function ( '<STR_LIT:f>' ) <EOL> assert checksol ( x , x , f ( x ) ) is False <EOL> p = symbols ( '<STR_LIT:p>' , positive = True ) <EOL> assert Pow ( x , S ( <NUM_LIT:0> ) , evaluate = False ) . is_constant ( ) is True <EOL> assert Pow ( S ( <NUM_LIT:0> ) , x , evaluate = False ) . is_constant ( ) is False <EOL> assert ( <NUM_LIT:2> ** x ) . is_constant ( ) is False <EOL> assert Pow ( S ( <NUM_LIT:2> ) , S ( <NUM_LIT:3> ) , evaluate = False ) . is_constant ( ) is True <EOL> z1 , z2 = symbols ( '<STR_LIT>' , zero = True ) <EOL> assert ( z1 + <NUM_LIT:2> * z2 ) . is_constant ( ) is True <EOL> assert meter . is_constant ( ) is True <EOL> assert ( <NUM_LIT:3> * meter ) . is_constant ( ) is True <EOL> assert ( x * meter ) . is_constant ( ) is False <EOL> def test_equals ( ) : <EOL> assert ( - <NUM_LIT:3> - sqrt ( <NUM_LIT:5> ) + ( - sqrt ( <NUM_LIT:10> ) / <NUM_LIT:2> - sqrt ( <NUM_LIT:2> ) / <NUM_LIT:2> ) ** <NUM_LIT:2> ) . equals ( <NUM_LIT:0> ) <EOL> assert ( x ** <NUM_LIT:2> - <NUM_LIT:1> ) . equals ( ( x + <NUM_LIT:1> ) * ( x - <NUM_LIT:1> ) ) <EOL> assert ( cos ( x ) ** <NUM_LIT:2> + sin ( x ) ** <NUM_LIT:2> ) . equals ( <NUM_LIT:1> ) <EOL> assert ( a * cos ( x ) ** <NUM_LIT:2> + a * sin ( x ) ** <NUM_LIT:2> ) . equals ( a ) <EOL> r = sqrt ( <NUM_LIT:2> ) <EOL> assert ( - <NUM_LIT:1> / ( r + r * x ) + <NUM_LIT:1> / r / ( <NUM_LIT:1> + x ) ) . equals ( <NUM_LIT:0> ) <EOL> assert factorial ( x + <NUM_LIT:1> ) . equals ( ( x + <NUM_LIT:1> ) * factorial ( x ) ) <EOL> assert sqrt ( <NUM_LIT:3> ) . equals ( <NUM_LIT:2> * sqrt ( <NUM_LIT:3> ) ) is False <EOL> assert ( sqrt ( <NUM_LIT:5> ) * sqrt ( <NUM_LIT:3> ) ) . equals ( sqrt ( <NUM_LIT:3> ) ) is False <EOL> assert ( sqrt ( <NUM_LIT:5> ) + sqrt ( <NUM_LIT:3> ) ) . equals ( <NUM_LIT:0> ) is False <EOL> assert ( sqrt ( <NUM_LIT:5> ) + pi ) . equals ( <NUM_LIT:0> ) is False <EOL> assert meter . equals ( <NUM_LIT:0> ) is False <EOL> assert ( <NUM_LIT:3> * meter ** <NUM_LIT:2> ) . equals ( <NUM_LIT:0> ) is False <EOL> eq = - ( - <NUM_LIT:1> ) ** ( S ( <NUM_LIT:3> ) / <NUM_LIT:4> ) * <NUM_LIT:6> ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:4> ) + ( - <NUM_LIT:6> ) ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:4> ) * I <EOL> if eq != <NUM_LIT:0> : <EOL> assert eq . equals ( <NUM_LIT:0> ) <EOL> assert sqrt ( x ) . equals ( <NUM_LIT:0> ) is False <EOL> i = <NUM_LIT:2> * sqrt ( <NUM_LIT:2> ) * x ** ( S ( <NUM_LIT:5> ) / <NUM_LIT:2> ) * ( <NUM_LIT:1> + <NUM_LIT:1> / ( <NUM_LIT:2> * x ) ) ** ( S ( <NUM_LIT:5> ) / <NUM_LIT:2> ) / <NUM_LIT:5> + <NUM_LIT:2> * sqrt ( <NUM_LIT:2> ) * x ** ( S ( <NUM_LIT:3> ) / <NUM_LIT:2> ) * ( <NUM_LIT:1> + <NUM_LIT:1> / ( <NUM_LIT:2> * x ) ) ** ( S ( <NUM_LIT:5> ) / <NUM_LIT:2> ) / ( - <NUM_LIT:6> - <NUM_LIT:3> / x ) <EOL> ans = sqrt ( <NUM_LIT:2> * x + <NUM_LIT:1> ) * ( <NUM_LIT:6> * x ** <NUM_LIT:2> + x - <NUM_LIT:1> ) / <NUM_LIT:15> <EOL> diff = i - ans <EOL> assert diff . equals ( <NUM_LIT:0> ) is False <EOL> assert diff . subs ( x , - S . Half / <NUM_LIT:2> ) == <NUM_LIT:7> * sqrt ( <NUM_LIT:2> ) / <NUM_LIT> <EOL> p = Symbol ( '<STR_LIT:p>' , positive = True ) <EOL> assert diff . subs ( x , p ) . equals ( <NUM_LIT:0> ) is True <EOL> assert diff . subs ( x , - <NUM_LIT:1> ) . equals ( <NUM_LIT:0> ) is True <EOL> eq = sqrt ( <NUM_LIT:1> + sqrt ( <NUM_LIT:3> ) ) + sqrt ( <NUM_LIT:3> + <NUM_LIT:3> * sqrt ( <NUM_LIT:3> ) ) - sqrt ( <NUM_LIT:10> + <NUM_LIT:6> * sqrt ( <NUM_LIT:3> ) ) <EOL> assert eq . equals ( <NUM_LIT:0> ) <EOL> q = <NUM_LIT:3> ** Rational ( <NUM_LIT:1> , <NUM_LIT:3> ) + <NUM_LIT:3> <EOL> p = expand ( q ** <NUM_LIT:3> ) ** Rational ( <NUM_LIT:1> , <NUM_LIT:3> ) <EOL> assert ( p - q ) . equals ( <NUM_LIT:0> ) <EOL> q = symbols ( '<STR_LIT:q>' ) <EOL> z = ( q * ( - sqrt ( - <NUM_LIT:2> * ( - ( q - S ( <NUM_LIT:7> ) / <NUM_LIT:8> ) ** S ( <NUM_LIT:2> ) / <NUM_LIT:8> - S ( <NUM_LIT> ) / <NUM_LIT> ) ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) - <EOL> S ( <NUM_LIT> ) / <NUM_LIT:12> ) / <NUM_LIT:2> - sqrt ( ( <NUM_LIT:2> * q - S ( <NUM_LIT:7> ) / <NUM_LIT:4> ) / sqrt ( - <NUM_LIT:2> * ( - ( q - S ( <NUM_LIT:7> ) / <NUM_LIT:8> ) ** S ( <NUM_LIT:2> ) / <NUM_LIT:8> - <EOL> S ( <NUM_LIT> ) / <NUM_LIT> ) ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) - S ( <NUM_LIT> ) / <NUM_LIT:12> ) + <NUM_LIT:2> * ( - ( q - S ( <NUM_LIT:7> ) / <NUM_LIT:8> ) ** S ( <NUM_LIT:2> ) / <NUM_LIT:8> - <EOL> S ( <NUM_LIT> ) / <NUM_LIT> ) ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) - S ( <NUM_LIT> ) / <NUM_LIT:6> ) / <NUM_LIT:2> - S ( <NUM_LIT:1> ) / <NUM_LIT:4> ) + q / <NUM_LIT:4> + ( - sqrt ( - <NUM_LIT:2> * ( - ( q <EOL> - S ( <NUM_LIT:7> ) / <NUM_LIT:8> ) ** S ( <NUM_LIT:2> ) / <NUM_LIT:8> - S ( <NUM_LIT> ) / <NUM_LIT> ) ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) - S ( <NUM_LIT> ) / <NUM_LIT:12> ) / <NUM_LIT:2> - sqrt ( ( <NUM_LIT:2> * q <EOL> - S ( <NUM_LIT:7> ) / <NUM_LIT:4> ) / sqrt ( - <NUM_LIT:2> * ( - ( q - S ( <NUM_LIT:7> ) / <NUM_LIT:8> ) ** S ( <NUM_LIT:2> ) / <NUM_LIT:8> - S ( <NUM_LIT> ) / <NUM_LIT> ) ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) - <EOL> S ( <NUM_LIT> ) / <NUM_LIT:12> ) + <NUM_LIT:2> * ( - ( q - S ( <NUM_LIT:7> ) / <NUM_LIT:8> ) ** S ( <NUM_LIT:2> ) / <NUM_LIT:8> - S ( <NUM_LIT> ) / <NUM_LIT> ) ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) - <EOL> S ( <NUM_LIT> ) / <NUM_LIT:6> ) / <NUM_LIT:2> - S ( <NUM_LIT:1> ) / <NUM_LIT:4> ) ** <NUM_LIT:4> + ( - sqrt ( - <NUM_LIT:2> * ( - ( q - S ( <NUM_LIT:7> ) / <NUM_LIT:8> ) ** S ( <NUM_LIT:2> ) / <NUM_LIT:8> - <EOL> S ( <NUM_LIT> ) / <NUM_LIT> ) ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) - S ( <NUM_LIT> ) / <NUM_LIT:12> ) / <NUM_LIT:2> - sqrt ( ( <NUM_LIT:2> * q - <EOL> S ( <NUM_LIT:7> ) / <NUM_LIT:4> ) / sqrt ( - <NUM_LIT:2> * ( - ( q - S ( <NUM_LIT:7> ) / <NUM_LIT:8> ) ** S ( <NUM_LIT:2> ) / <NUM_LIT:8> - S ( <NUM_LIT> ) / <NUM_LIT> ) ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) - <EOL> S ( <NUM_LIT> ) / <NUM_LIT:12> ) + <NUM_LIT:2> * ( - ( q - S ( <NUM_LIT:7> ) / <NUM_LIT:8> ) ** S ( <NUM_LIT:2> ) / <NUM_LIT:8> - S ( <NUM_LIT> ) / <NUM_LIT> ) ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) - <EOL> S ( <NUM_LIT> ) / <NUM_LIT:6> ) / <NUM_LIT:2> - S ( <NUM_LIT:1> ) / <NUM_LIT:4> ) ** <NUM_LIT:3> + <NUM_LIT:2> * ( - sqrt ( - <NUM_LIT:2> * ( - ( q - S ( <NUM_LIT:7> ) / <NUM_LIT:8> ) ** S ( <NUM_LIT:2> ) / <NUM_LIT:8> - <EOL> S ( <NUM_LIT> ) / <NUM_LIT> ) ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) - S ( <NUM_LIT> ) / <NUM_LIT:12> ) / <NUM_LIT:2> - sqrt ( ( <NUM_LIT:2> * q - <EOL> S ( <NUM_LIT:7> ) / <NUM_LIT:4> ) / sqrt ( - <NUM_LIT:2> * ( - ( q - S ( <NUM_LIT:7> ) / <NUM_LIT:8> ) ** S ( <NUM_LIT:2> ) / <NUM_LIT:8> - S ( <NUM_LIT> ) / <NUM_LIT> ) ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) - <EOL> S ( <NUM_LIT> ) / <NUM_LIT:12> ) + <NUM_LIT:2> * ( - ( q - S ( <NUM_LIT:7> ) / <NUM_LIT:8> ) ** S ( <NUM_LIT:2> ) / <NUM_LIT:8> - S ( <NUM_LIT> ) / <NUM_LIT> ) ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) - <EOL> S ( <NUM_LIT> ) / <NUM_LIT:6> ) / <NUM_LIT:2> - S ( <NUM_LIT:1> ) / <NUM_LIT:4> ) ** <NUM_LIT:2> - S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) <EOL> assert z . equals ( <NUM_LIT:0> ) <EOL> def test_random ( ) : <EOL> from sympy import posify , lucas <EOL> assert posify ( x ) [ <NUM_LIT:0> ] . _random ( ) is not None <EOL> assert lucas ( n ) . _random ( <NUM_LIT:2> , - <NUM_LIT:2> , <NUM_LIT:0> , - <NUM_LIT:1> , <NUM_LIT:1> ) is None <EOL> assert Piecewise ( ( Max ( x , y ) , z ) ) . _random ( ) is None <EOL> def test_round ( ) : <EOL> from sympy . abc import x <EOL> assert Float ( '<STR_LIT>' ) . round ( <NUM_LIT:2> ) == <NUM_LIT> <EOL> d20 = <NUM_LIT> <EOL> ans = S ( d20 ) . round ( <NUM_LIT:2> ) <EOL> assert ans . is_Float and ans == d20 <EOL> ans = S ( d20 ) . round ( - <NUM_LIT:2> ) <EOL> assert ans . is_Float and ans == <NUM_LIT> <EOL> assert S ( '<STR_LIT>' ) . round ( <NUM_LIT:4> ) == <NUM_LIT> <EOL> assert S ( '<STR_LIT>' ) . round ( <NUM_LIT:4> ) == <NUM_LIT> <EOL> assert S ( '<STR_LIT>' ) . round ( <NUM_LIT:2> ) == <NUM_LIT> <EOL> n = S ( <NUM_LIT> ) <EOL> ans = n . round ( ) <EOL> assert ans . is_Float <EOL> assert ans == n <EOL> ans = n . round ( <NUM_LIT:1> ) <EOL> assert ans . is_Float <EOL> assert ans == n <EOL> ans = n . round ( <NUM_LIT:4> ) <EOL> assert ans . is_Float <EOL> assert ans == n <EOL> assert n . round ( - <NUM_LIT:1> ) == <NUM_LIT> <EOL> r = n . round ( - <NUM_LIT:4> ) <EOL> assert r == <NUM_LIT> <EOL> assert all ( r == i for i in range ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> assert n . round ( - <NUM_LIT:5> ) == <NUM_LIT:0> <EOL> assert ( pi + sqrt ( <NUM_LIT:2> ) ) . round ( <NUM_LIT:2> ) == <NUM_LIT> <EOL> assert ( <NUM_LIT:10> * ( pi + sqrt ( <NUM_LIT:2> ) ) ) . round ( - <NUM_LIT:1> ) == <NUM_LIT:50> <EOL> raises ( TypeError , lambda : round ( x + <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> assert S ( <NUM_LIT> ) . round ( <NUM_LIT:1> ) == <NUM_LIT> <EOL> e = S ( <NUM_LIT> ) . round ( <NUM_LIT:2> ) <EOL> assert e == round ( <NUM_LIT> , <NUM_LIT:2> ) <EOL> assert type ( e ) is Float <EOL> assert ( Float ( <NUM_LIT> , <NUM_LIT:3> ) + <NUM_LIT:2> * pi ) . round ( ) == <NUM_LIT:7> <EOL> assert ( Float ( <NUM_LIT> , <NUM_LIT:3> ) + <NUM_LIT:2> * pi * <NUM_LIT:100> ) . round ( ) == <NUM_LIT> <EOL> assert ( Float ( <NUM_LIT> , <NUM_LIT:3> ) + <NUM_LIT:2> * pi / <NUM_LIT:100> ) . round ( <NUM_LIT:5> ) == <NUM_LIT> <EOL> assert ( Float ( <NUM_LIT> , <NUM_LIT:3> ) + <NUM_LIT:2> * pi / <NUM_LIT:100> ) . round ( <NUM_LIT:4> ) == <NUM_LIT> <EOL> assert ( pi + <NUM_LIT:2> * E * I ) . round ( ) == <NUM_LIT:3> + <NUM_LIT:5> * I <EOL> assert S . Zero . round ( ) == <NUM_LIT:0> <EOL> a = ( Add ( <NUM_LIT:1> , Float ( '<STR_LIT>' + '<STR_LIT>' * <NUM_LIT> , '<STR_LIT>' ) , evaluate = <NUM_LIT:0> ) ) <EOL> assert a . round ( <NUM_LIT:10> ) == Float ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert a . round ( <NUM_LIT> ) == Float ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert a . round ( <NUM_LIT> ) == Float ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert a . round ( <NUM_LIT> ) == Float ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert a . round ( <NUM_LIT:30> ) == Float ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> raises ( TypeError , lambda : x . round ( ) ) <EOL> f = Function ( '<STR_LIT:f>' ) <EOL> raises ( TypeError , lambda : f ( <NUM_LIT:1> ) . round ( ) ) <EOL> assert str ( S ( <NUM_LIT:1> ) . round ( ) ) == '<STR_LIT>' <EOL> assert str ( S ( <NUM_LIT:100> ) . round ( ) ) == '<STR_LIT>' <EOL> assert ( <NUM_LIT:2> * pi + E * I ) . round ( ) == <NUM_LIT:6> + <NUM_LIT:3> * I <EOL> assert ( <NUM_LIT:2> * pi + I / <NUM_LIT:10> ) . round ( ) == <NUM_LIT:6> <EOL> assert ( pi / <NUM_LIT:10> + <NUM_LIT:2> * I ) . round ( ) == <NUM_LIT:2> * I <EOL> assert str ( ( pi / <NUM_LIT:10> + E * I ) . round ( <NUM_LIT:2> ) ) == '<STR_LIT>' <EOL> assert ( pi / <NUM_LIT:10> + E * I ) . round ( <NUM_LIT:2> ) . as_real_imag ( ) == ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert ( pi / <NUM_LIT:10> + E * I ) . round ( <NUM_LIT:2> ) == Float ( <NUM_LIT> , <NUM_LIT:2> ) + I * Float ( <NUM_LIT> , <NUM_LIT:3> ) <EOL> assert ( I ** ( I + <NUM_LIT:3> ) ) . round ( <NUM_LIT:3> ) == Float ( '<STR_LIT>' , '<STR_LIT>' ) * I <EOL> assert S ( - <NUM_LIT> ) . round ( ) == - <NUM_LIT> <EOL> assert S ( - <NUM_LIT> ) . round ( ) == - <NUM_LIT> <EOL> assert S ( - <NUM_LIT> ) . round ( ) == - <NUM_LIT> <EOL> assert S ( - <NUM_LIT> - <NUM_LIT> * I ) . round ( ) == - <NUM_LIT> - <NUM_LIT> * I <EOL> assert str ( S ( <NUM_LIT> ) . round ( <NUM_LIT:2> ) ) == '<STR_LIT>' <EOL> assert str ( S ( <NUM_LIT> ) . round ( <NUM_LIT:4> ) ) == '<STR_LIT>' <EOL> assert S . NaN . round ( ) == S . NaN <EOL> assert S . Infinity . round ( ) == S . Infinity <EOL> assert S . NegativeInfinity . round ( ) == S . NegativeInfinity <EOL> assert S . ComplexInfinity . round ( ) == S . ComplexInfinity <EOL> def test_round_exception_nostr ( ) : <EOL> s = Symbol ( '<STR_LIT>' ) <EOL> try : <EOL> s . round ( ) <EOL> except TypeError as e : <EOL> assert '<STR_LIT>' not in str ( e ) <EOL> else : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> def test_extract_branch_factor ( ) : <EOL> assert exp_polar ( <NUM_LIT> * I * pi ) . extract_branch_factor ( ) == ( <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> def test_identity_removal ( ) : <EOL> assert Add . make_args ( x + <NUM_LIT:0> ) == ( x , ) <EOL> assert Mul . make_args ( x * <NUM_LIT:1> ) == ( x , ) <EOL> def test_float_0 ( ) : <EOL> assert Float ( <NUM_LIT:0.0> ) + <NUM_LIT:1> == Float ( <NUM_LIT:1.0> ) <EOL> @ XFAIL <EOL> def test_float_0_fail ( ) : <EOL> assert Float ( <NUM_LIT:0.0> ) * x == Float ( <NUM_LIT:0.0> ) <EOL> assert ( x + Float ( <NUM_LIT:0.0> ) ) . is_Add <EOL> def test_issue_6325 ( ) : <EOL> ans = ( b ** <NUM_LIT:2> + z ** <NUM_LIT:2> - ( b * ( a + b * t ) + z * ( c + t * z ) ) ** <NUM_LIT:2> / ( <EOL> ( a + b * t ) ** <NUM_LIT:2> + ( c + t * z ) ** <NUM_LIT:2> ) ) / sqrt ( ( a + b * t ) ** <NUM_LIT:2> + ( c + t * z ) ** <NUM_LIT:2> ) <EOL> e = sqrt ( ( a + b * t ) ** <NUM_LIT:2> + ( c + z * t ) ** <NUM_LIT:2> ) <EOL> assert diff ( e , t , <NUM_LIT:2> ) == ans <EOL> e . diff ( t , <NUM_LIT:2> ) == ans <EOL> assert diff ( e , t , <NUM_LIT:2> , simplify = False ) != ans <EOL> def test_issue_7426 ( ) : <EOL> f1 = a % c <EOL> f2 = x % z <EOL> assert f1 . equals ( f2 ) == False <EOL> def test_issue_10161 ( ) : <EOL> x = symbols ( '<STR_LIT:x>' , real = True ) <EOL> assert x * abs ( x ) * abs ( x ) == x ** <NUM_LIT:3> <EOL> def test_issue_10755 ( ) : <EOL> x = symbols ( '<STR_LIT:x>' ) <EOL> raises ( TypeError , lambda : int ( log ( x ) ) ) <EOL> raises ( TypeError , lambda : log ( x ) . round ( <NUM_LIT:2> ) ) </s>
