<s> """<STR_LIT>""" <EOL> from sympy import ( S , Add , sin , Mul , Symbol , oo , Integral , sqrt , Tuple , I , <EOL> Interval , O , symbols , simplify , collect , Sum , Basic , Dict , <EOL> root , exp , cos , sin , oo , Dummy , log ) <EOL> from sympy . core . exprtools import ( decompose_power , Factors , Term , _gcd_terms , <EOL> gcd_terms , factor_terms , factor_nc , <EOL> _monotonic_sign ) <EOL> from sympy . core . mul import _keep_coeff as _keep_coeff <EOL> from sympy . simplify . cse_opts import sub_pre <EOL> from sympy . utilities . pytest import raises <EOL> from sympy . abc import a , b , t , x , y , z <EOL> def test_decompose_power ( ) : <EOL> assert decompose_power ( x ) == ( x , <NUM_LIT:1> ) <EOL> assert decompose_power ( x ** <NUM_LIT:2> ) == ( x , <NUM_LIT:2> ) <EOL> assert decompose_power ( x ** ( <NUM_LIT:2> * y ) ) == ( x ** y , <NUM_LIT:2> ) <EOL> assert decompose_power ( x ** ( <NUM_LIT:2> * y / <NUM_LIT:3> ) ) == ( x ** ( y / <NUM_LIT:3> ) , <NUM_LIT:2> ) <EOL> def test_Factors ( ) : <EOL> assert Factors ( ) == Factors ( { } ) == Factors ( S ( <NUM_LIT:1> ) ) <EOL> assert Factors ( ) . as_expr ( ) == S . One <EOL> assert Factors ( { x : <NUM_LIT:2> , y : <NUM_LIT:3> , sin ( x ) : <NUM_LIT:4> } ) . as_expr ( ) == x ** <NUM_LIT:2> * y ** <NUM_LIT:3> * sin ( x ) ** <NUM_LIT:4> <EOL> assert Factors ( S . Infinity ) == Factors ( { oo : <NUM_LIT:1> } ) <EOL> assert Factors ( S . NegativeInfinity ) == Factors ( { oo : <NUM_LIT:1> , - <NUM_LIT:1> : <NUM_LIT:1> } ) <EOL> a = Factors ( { x : <NUM_LIT:5> , y : <NUM_LIT:3> , z : <NUM_LIT:7> } ) <EOL> b = Factors ( { y : <NUM_LIT:4> , z : <NUM_LIT:3> , t : <NUM_LIT:10> } ) <EOL> assert a . mul ( b ) == a * b == Factors ( { x : <NUM_LIT:5> , y : <NUM_LIT:7> , z : <NUM_LIT:10> , t : <NUM_LIT:10> } ) <EOL> assert a . div ( b ) == divmod ( a , b ) == ( Factors ( { x : <NUM_LIT:5> , z : <NUM_LIT:4> } ) , Factors ( { y : <NUM_LIT:1> , t : <NUM_LIT:10> } ) ) <EOL> assert a . quo ( b ) == a / b == Factors ( { x : <NUM_LIT:5> , z : <NUM_LIT:4> } ) <EOL> assert a . rem ( b ) == a % b == Factors ( { y : <NUM_LIT:1> , t : <NUM_LIT:10> } ) <EOL> assert a . pow ( <NUM_LIT:3> ) == a ** <NUM_LIT:3> == Factors ( { x : <NUM_LIT:15> , y : <NUM_LIT:9> , z : <NUM_LIT> } ) <EOL> assert b . pow ( <NUM_LIT:3> ) == b ** <NUM_LIT:3> == Factors ( { y : <NUM_LIT:12> , z : <NUM_LIT:9> , t : <NUM_LIT:30> } ) <EOL> assert a . gcd ( b ) == Factors ( { y : <NUM_LIT:3> , z : <NUM_LIT:3> } ) <EOL> assert a . lcm ( b ) == Factors ( { x : <NUM_LIT:5> , y : <NUM_LIT:4> , z : <NUM_LIT:7> , t : <NUM_LIT:10> } ) <EOL> a = Factors ( { x : <NUM_LIT:4> , y : <NUM_LIT:7> , t : <NUM_LIT:7> } ) <EOL> b = Factors ( { z : <NUM_LIT:1> , t : <NUM_LIT:3> } ) <EOL> assert a . normal ( b ) == ( Factors ( { x : <NUM_LIT:4> , y : <NUM_LIT:7> , t : <NUM_LIT:4> } ) , Factors ( { z : <NUM_LIT:1> } ) ) <EOL> assert Factors ( sqrt ( <NUM_LIT:2> ) * x ) . as_expr ( ) == sqrt ( <NUM_LIT:2> ) * x <EOL> assert Factors ( - I ) * I == Factors ( ) <EOL> assert Factors ( { S ( - <NUM_LIT:1> ) : S ( <NUM_LIT:3> ) } ) * Factors ( { S ( - <NUM_LIT:1> ) : S ( <NUM_LIT:1> ) , I : S ( <NUM_LIT:5> ) } ) == Factors ( I ) <EOL> assert Factors ( S ( <NUM_LIT:2> ) ** x ) . div ( S ( <NUM_LIT:3> ) ** x ) == ( Factors ( { S ( <NUM_LIT:2> ) : x } ) , Factors ( { S ( <NUM_LIT:3> ) : x } ) ) <EOL> assert Factors ( <NUM_LIT:2> ** ( <NUM_LIT:2> * x + <NUM_LIT:2> ) ) . div ( S ( <NUM_LIT:8> ) ) == ( Factors ( { S ( <NUM_LIT:2> ) : <NUM_LIT:2> * x + <NUM_LIT:2> } ) , Factors ( { S ( <NUM_LIT:8> ) : S ( <NUM_LIT:1> ) } ) ) <EOL> assert Factors ( { S ( - <NUM_LIT:1> ) : S ( <NUM_LIT:3> ) / <NUM_LIT:2> } ) == Factors ( { I : S . One , S ( - <NUM_LIT:1> ) : S . One } ) <EOL> assert Factors ( { I : S ( <NUM_LIT:1> ) , S ( - <NUM_LIT:1> ) : S ( <NUM_LIT:1> ) / <NUM_LIT:3> } ) . as_expr ( ) == I * ( - <NUM_LIT:1> ) ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) <EOL> assert Factors ( - <NUM_LIT:1.> ) == Factors ( { S ( - <NUM_LIT:1> ) : S ( <NUM_LIT:1> ) , S ( <NUM_LIT:1.> ) : <NUM_LIT:1> } ) <EOL> assert Factors ( - <NUM_LIT> ) == Factors ( { S ( - <NUM_LIT:1> ) : S ( <NUM_LIT:1> ) , S ( <NUM_LIT> ) : <NUM_LIT:1> } ) <EOL> assert Factors ( ( - <NUM_LIT> ) ** x ) == Factors ( { S ( - <NUM_LIT> ) : x } ) <EOL> assert Factors ( S ( - <NUM_LIT:2> ) ) == Factors ( { S ( - <NUM_LIT:1> ) : S ( <NUM_LIT:1> ) , S ( <NUM_LIT:2> ) : <NUM_LIT:1> } ) <EOL> assert Factors ( S . Half ) == Factors ( { S ( <NUM_LIT:2> ) : - S . One } ) <EOL> assert Factors ( S ( <NUM_LIT:3> ) / <NUM_LIT:2> ) == Factors ( { S ( <NUM_LIT:3> ) : S . One , S ( <NUM_LIT:2> ) : S ( - <NUM_LIT:1> ) } ) <EOL> assert Factors ( { I : S ( <NUM_LIT:1> ) } ) == Factors ( I ) <EOL> assert Factors ( { - <NUM_LIT:1.0> : <NUM_LIT:2> , I : <NUM_LIT:1> } ) == Factors ( { S ( <NUM_LIT:1.0> ) : <NUM_LIT:1> , I : <NUM_LIT:1> } ) <EOL> assert Factors ( { S . NegativeOne : - S ( <NUM_LIT:3> ) / <NUM_LIT:2> } ) . as_expr ( ) == I <EOL> A = symbols ( '<STR_LIT:A>' , commutative = False ) <EOL> assert Factors ( <NUM_LIT:2> * A ** <NUM_LIT:2> ) == Factors ( { S ( <NUM_LIT:2> ) : <NUM_LIT:1> , A ** <NUM_LIT:2> : <NUM_LIT:1> } ) <EOL> assert Factors ( I ) == Factors ( { I : S . One } ) <EOL> assert Factors ( x ) . normal ( S ( <NUM_LIT:2> ) ) == ( Factors ( x ) , Factors ( S ( <NUM_LIT:2> ) ) ) <EOL> assert Factors ( x ) . normal ( S ( <NUM_LIT:0> ) ) == ( Factors ( ) , Factors ( S ( <NUM_LIT:0> ) ) ) <EOL> raises ( ZeroDivisionError , lambda : Factors ( x ) . div ( S ( <NUM_LIT:0> ) ) ) <EOL> assert Factors ( x ) . mul ( S ( <NUM_LIT:2> ) ) == Factors ( <NUM_LIT:2> * x ) <EOL> assert Factors ( x ) . mul ( S ( <NUM_LIT:0> ) ) . is_zero <EOL> assert Factors ( x ) . mul ( <NUM_LIT:1> / x ) . is_one <EOL> assert Factors ( x ** sqrt ( <NUM_LIT:2> ) ** <NUM_LIT:3> ) . as_expr ( ) == x ** ( <NUM_LIT:2> * sqrt ( <NUM_LIT:2> ) ) <EOL> assert Factors ( x ) ** Factors ( S ( <NUM_LIT:2> ) ) == Factors ( x ** <NUM_LIT:2> ) <EOL> assert Factors ( x ) . gcd ( S ( <NUM_LIT:0> ) ) == Factors ( x ) <EOL> assert Factors ( x ) . lcm ( S ( <NUM_LIT:0> ) ) . is_zero <EOL> assert Factors ( S ( <NUM_LIT:0> ) ) . div ( x ) == ( Factors ( S ( <NUM_LIT:0> ) ) , Factors ( ) ) <EOL> assert Factors ( x ) . div ( x ) == ( Factors ( ) , Factors ( ) ) <EOL> assert Factors ( { x : <NUM_LIT> } ) / Factors ( { x : <NUM_LIT> } ) == Factors ( ) <EOL> assert Factors ( x ) != Factors ( ) <EOL> assert Factors ( S ( <NUM_LIT:0> ) ) . normal ( x ) == ( Factors ( S ( <NUM_LIT:0> ) ) , Factors ( ) ) <EOL> n , d = x ** ( <NUM_LIT:2> + y ) , x ** <NUM_LIT:2> <EOL> f = Factors ( n ) <EOL> assert f . div ( d ) == f . normal ( d ) == ( Factors ( x ** y ) , Factors ( ) ) <EOL> assert f . gcd ( d ) == Factors ( ) <EOL> d = x ** y <EOL> assert f . div ( d ) == f . normal ( d ) == ( Factors ( x ** <NUM_LIT:2> ) , Factors ( ) ) <EOL> assert f . gcd ( d ) == Factors ( d ) <EOL> n = d = <NUM_LIT:2> ** x <EOL> f = Factors ( n ) <EOL> assert f . div ( d ) == f . normal ( d ) == ( Factors ( ) , Factors ( ) ) <EOL> assert f . gcd ( d ) == Factors ( d ) <EOL> n , d = <NUM_LIT:2> ** x , <NUM_LIT:2> ** y <EOL> f = Factors ( n ) <EOL> assert f . div ( d ) == f . normal ( d ) == ( Factors ( { S ( <NUM_LIT:2> ) : x } ) , Factors ( { S ( <NUM_LIT:2> ) : y } ) ) <EOL> assert f . gcd ( d ) == Factors ( ) <EOL> n = x ** ( x + <NUM_LIT:3> ) <EOL> assert Factors ( n ) . normal ( x ** - <NUM_LIT:3> ) == ( Factors ( { x : x + <NUM_LIT:6> } ) , Factors ( { } ) ) <EOL> assert Factors ( n ) . normal ( x ** <NUM_LIT:3> ) == ( Factors ( { x : x } ) , Factors ( { } ) ) <EOL> assert Factors ( n ) . normal ( x ** <NUM_LIT:4> ) == ( Factors ( { x : x } ) , Factors ( { x : <NUM_LIT:1> } ) ) <EOL> assert Factors ( n ) . normal ( x ** ( y - <NUM_LIT:3> ) ) == ( Factors ( { x : x + <NUM_LIT:6> } ) , Factors ( { x : y } ) ) <EOL> assert Factors ( n ) . normal ( x ** ( y + <NUM_LIT:3> ) ) == ( Factors ( { x : x } ) , Factors ( { x : y } ) ) <EOL> assert Factors ( n ) . normal ( x ** ( y + <NUM_LIT:4> ) ) == ( Factors ( { x : x } ) , Factors ( { x : y + <NUM_LIT:1> } ) ) <EOL> assert Factors ( n ) . div ( x ** - <NUM_LIT:3> ) == ( Factors ( { x : x + <NUM_LIT:6> } ) , Factors ( { } ) ) <EOL> assert Factors ( n ) . div ( x ** <NUM_LIT:3> ) == ( Factors ( { x : x } ) , Factors ( { } ) ) <EOL> assert Factors ( n ) . div ( x ** <NUM_LIT:4> ) == ( Factors ( { x : x } ) , Factors ( { x : <NUM_LIT:1> } ) ) <EOL> assert Factors ( n ) . div ( x ** ( y - <NUM_LIT:3> ) ) == ( Factors ( { x : x + <NUM_LIT:6> } ) , Factors ( { x : y } ) ) <EOL> assert Factors ( n ) . div ( x ** ( y + <NUM_LIT:3> ) ) == ( Factors ( { x : x } ) , Factors ( { x : y } ) ) <EOL> assert Factors ( n ) . div ( x ** ( y + <NUM_LIT:4> ) ) == ( Factors ( { x : x } ) , Factors ( { x : y + <NUM_LIT:1> } ) ) <EOL> def test_Term ( ) : <EOL> a = Term ( <NUM_LIT:4> * x * y ** <NUM_LIT:2> / z / t ** <NUM_LIT:3> ) <EOL> b = Term ( <NUM_LIT:2> * x ** <NUM_LIT:3> * y ** <NUM_LIT:5> / t ** <NUM_LIT:3> ) <EOL> assert a == Term ( <NUM_LIT:4> , Factors ( { x : <NUM_LIT:1> , y : <NUM_LIT:2> } ) , Factors ( { z : <NUM_LIT:1> , t : <NUM_LIT:3> } ) ) <EOL> assert b == Term ( <NUM_LIT:2> , Factors ( { x : <NUM_LIT:3> , y : <NUM_LIT:5> } ) , Factors ( { t : <NUM_LIT:3> } ) ) <EOL> assert a . as_expr ( ) == <NUM_LIT:4> * x * y ** <NUM_LIT:2> / z / t ** <NUM_LIT:3> <EOL> assert b . as_expr ( ) == <NUM_LIT:2> * x ** <NUM_LIT:3> * y ** <NUM_LIT:5> / t ** <NUM_LIT:3> <EOL> assert a . inv ( ) == Term ( S ( <NUM_LIT:1> ) / <NUM_LIT:4> , Factors ( { z : <NUM_LIT:1> , t : <NUM_LIT:3> } ) , Factors ( { x : <NUM_LIT:1> , y : <NUM_LIT:2> } ) ) <EOL> assert b . inv ( ) == Term ( S ( <NUM_LIT:1> ) / <NUM_LIT:2> , Factors ( { t : <NUM_LIT:3> } ) , Factors ( { x : <NUM_LIT:3> , y : <NUM_LIT:5> } ) ) <EOL> assert a . mul ( b ) == a * b == Term ( <NUM_LIT:8> , Factors ( { x : <NUM_LIT:4> , y : <NUM_LIT:7> } ) , Factors ( { z : <NUM_LIT:1> , t : <NUM_LIT:6> } ) ) <EOL> assert a . quo ( b ) == a / b == Term ( <NUM_LIT:2> , Factors ( { } ) , Factors ( { x : <NUM_LIT:2> , y : <NUM_LIT:3> , z : <NUM_LIT:1> } ) ) <EOL> assert a . pow ( <NUM_LIT:3> ) == a ** <NUM_LIT:3> == Term ( <NUM_LIT:64> , Factors ( { x : <NUM_LIT:3> , y : <NUM_LIT:6> } ) , Factors ( { z : <NUM_LIT:3> , t : <NUM_LIT:9> } ) ) <EOL> assert b . pow ( <NUM_LIT:3> ) == b ** <NUM_LIT:3> == Term ( <NUM_LIT:8> , Factors ( { x : <NUM_LIT:9> , y : <NUM_LIT:15> } ) , Factors ( { t : <NUM_LIT:9> } ) ) <EOL> assert a . pow ( - <NUM_LIT:3> ) == a ** ( - <NUM_LIT:3> ) == Term ( S ( <NUM_LIT:1> ) / <NUM_LIT:64> , Factors ( { z : <NUM_LIT:3> , t : <NUM_LIT:9> } ) , Factors ( { x : <NUM_LIT:3> , y : <NUM_LIT:6> } ) ) <EOL> assert b . pow ( - <NUM_LIT:3> ) == b ** ( - <NUM_LIT:3> ) == Term ( S ( <NUM_LIT:1> ) / <NUM_LIT:8> , Factors ( { t : <NUM_LIT:9> } ) , Factors ( { x : <NUM_LIT:9> , y : <NUM_LIT:15> } ) ) <EOL> assert a . gcd ( b ) == Term ( <NUM_LIT:2> , Factors ( { x : <NUM_LIT:1> , y : <NUM_LIT:2> } ) , Factors ( { t : <NUM_LIT:3> } ) ) <EOL> assert a . lcm ( b ) == Term ( <NUM_LIT:4> , Factors ( { x : <NUM_LIT:3> , y : <NUM_LIT:5> } ) , Factors ( { z : <NUM_LIT:1> , t : <NUM_LIT:3> } ) ) <EOL> a = Term ( <NUM_LIT:4> * x * y ** <NUM_LIT:2> / z / t ** <NUM_LIT:3> ) <EOL> b = Term ( <NUM_LIT:2> * x ** <NUM_LIT:3> * y ** <NUM_LIT:5> * t ** <NUM_LIT:7> ) <EOL> assert a . mul ( b ) == Term ( <NUM_LIT:8> , Factors ( { x : <NUM_LIT:4> , y : <NUM_LIT:7> , t : <NUM_LIT:4> } ) , Factors ( { z : <NUM_LIT:1> } ) ) <EOL> assert Term ( ( <NUM_LIT:2> * x + <NUM_LIT:2> ) ** <NUM_LIT:3> ) == Term ( <NUM_LIT:8> , Factors ( { x + <NUM_LIT:1> : <NUM_LIT:3> } ) , Factors ( { } ) ) <EOL> assert Term ( ( <NUM_LIT:2> * x + <NUM_LIT:2> ) * ( <NUM_LIT:3> * x + <NUM_LIT:6> ) ** <NUM_LIT:2> ) == Term ( <NUM_LIT> , Factors ( { x + <NUM_LIT:1> : <NUM_LIT:1> , x + <NUM_LIT:2> : <NUM_LIT:2> } ) , Factors ( { } ) ) <EOL> def test_gcd_terms ( ) : <EOL> f = <NUM_LIT:2> * ( x + <NUM_LIT:1> ) * ( x + <NUM_LIT:4> ) / ( <NUM_LIT:5> * x ** <NUM_LIT:2> + <NUM_LIT:5> ) + ( <NUM_LIT:2> * x + <NUM_LIT:2> ) * ( x + <NUM_LIT:5> ) / ( x ** <NUM_LIT:2> + <NUM_LIT:1> ) / <NUM_LIT:5> + ( <NUM_LIT:2> * x + <NUM_LIT:2> ) * ( x + <NUM_LIT:6> ) / ( <NUM_LIT:5> * x ** <NUM_LIT:2> + <NUM_LIT:5> ) <EOL> assert _gcd_terms ( f ) == ( ( S ( <NUM_LIT:6> ) / <NUM_LIT:5> ) * ( ( <NUM_LIT:1> + x ) / ( <NUM_LIT:1> + x ** <NUM_LIT:2> ) ) , <NUM_LIT:5> + x , <NUM_LIT:1> ) <EOL> assert _gcd_terms ( Add . make_args ( f ) ) == ( ( S ( <NUM_LIT:6> ) / <NUM_LIT:5> ) * ( ( <NUM_LIT:1> + x ) / ( <NUM_LIT:1> + x ** <NUM_LIT:2> ) ) , <NUM_LIT:5> + x , <NUM_LIT:1> ) <EOL> newf = ( S ( <NUM_LIT:6> ) / <NUM_LIT:5> ) * ( ( <NUM_LIT:1> + x ) * ( <NUM_LIT:5> + x ) / ( <NUM_LIT:1> + x ** <NUM_LIT:2> ) ) <EOL> assert gcd_terms ( f ) == newf <EOL> args = Add . make_args ( f ) <EOL> assert gcd_terms ( list ( args ) ) == newf <EOL> assert gcd_terms ( tuple ( args ) ) == newf <EOL> assert gcd_terms ( set ( args ) ) == newf <EOL> assert gcd_terms ( Tuple ( * args ) ) != newf <EOL> assert gcd_terms ( Basic ( Tuple ( <NUM_LIT:1> , <NUM_LIT:3> * y + <NUM_LIT:3> * x * y ) , Tuple ( <NUM_LIT:1> , <NUM_LIT:3> ) ) ) == Basic ( ( <NUM_LIT:1> , <NUM_LIT:3> * y * ( x + <NUM_LIT:1> ) ) , ( <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> assert gcd_terms ( Dict ( ( x * ( <NUM_LIT:1> + y ) , <NUM_LIT:2> ) , ( x + x * y , y + x * y ) ) ) == Dict ( { x * ( y + <NUM_LIT:1> ) : <NUM_LIT:2> , x + x * y : y * ( <NUM_LIT:1> + x ) } ) <EOL> assert gcd_terms ( ( <NUM_LIT:2> * x + <NUM_LIT:2> ) ** <NUM_LIT:3> + ( <NUM_LIT:2> * x + <NUM_LIT:2> ) ** <NUM_LIT:2> ) == <NUM_LIT:4> * ( x + <NUM_LIT:1> ) ** <NUM_LIT:2> * ( <NUM_LIT:2> * x + <NUM_LIT:3> ) <EOL> assert gcd_terms ( <NUM_LIT:0> ) == <NUM_LIT:0> <EOL> assert gcd_terms ( <NUM_LIT:1> ) == <NUM_LIT:1> <EOL> assert gcd_terms ( x ) == x <EOL> assert gcd_terms ( <NUM_LIT:2> + <NUM_LIT:2> * x ) == Mul ( <NUM_LIT:2> , <NUM_LIT:1> + x , evaluate = False ) <EOL> arg = x * ( <NUM_LIT:2> * x + <NUM_LIT:4> * y ) <EOL> garg = <NUM_LIT:2> * x * ( x + <NUM_LIT:2> * y ) <EOL> assert gcd_terms ( arg ) == garg <EOL> assert gcd_terms ( sin ( arg ) ) == sin ( garg ) <EOL> alpha , alpha1 , alpha2 , alpha3 = symbols ( '<STR_LIT>' ) <EOL> a = alpha ** <NUM_LIT:2> - alpha * x ** <NUM_LIT:2> + alpha + x ** <NUM_LIT:3> - x * ( alpha + <NUM_LIT:1> ) <EOL> rep = ( alpha , ( <NUM_LIT:1> + sqrt ( <NUM_LIT:5> ) ) / <NUM_LIT:2> + alpha1 * x + alpha2 * x ** <NUM_LIT:2> + alpha3 * x ** <NUM_LIT:3> ) <EOL> s = ( a / ( x - alpha ) ) . subs ( * rep ) . series ( x , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> assert simplify ( collect ( s , x ) ) == - sqrt ( <NUM_LIT:5> ) / <NUM_LIT:2> - S ( <NUM_LIT:3> ) / <NUM_LIT:2> + O ( x ) <EOL> assert _gcd_terms ( [ S . Zero , S . Zero ] ) == ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> assert _gcd_terms ( [ <NUM_LIT:2> * x + <NUM_LIT:4> ] ) == ( <NUM_LIT:2> , x + <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> eq = x / ( x + <NUM_LIT:1> / x ) <EOL> assert gcd_terms ( eq , fraction = False ) == eq <EOL> eq = x / <NUM_LIT:2> / y + <NUM_LIT:1> / x / y <EOL> assert gcd_terms ( eq , fraction = True , clear = True ) == ( x ** <NUM_LIT:2> + <NUM_LIT:2> ) / ( <NUM_LIT:2> * x * y ) <EOL> assert gcd_terms ( eq , fraction = True , clear = False ) == ( x ** <NUM_LIT:2> / <NUM_LIT:2> + <NUM_LIT:1> ) / ( x * y ) <EOL> assert gcd_terms ( eq , fraction = False , clear = True ) == ( x + <NUM_LIT:2> / x ) / ( <NUM_LIT:2> * y ) <EOL> assert gcd_terms ( eq , fraction = False , clear = False ) == ( x / <NUM_LIT:2> + <NUM_LIT:1> / x ) / y <EOL> def test_factor_terms ( ) : <EOL> A = Symbol ( '<STR_LIT:A>' , commutative = False ) <EOL> assert factor_terms ( <NUM_LIT:9> * ( x + x * y + <NUM_LIT:1> ) + ( <NUM_LIT:3> * x + <NUM_LIT:3> ) ** ( <NUM_LIT:2> + <NUM_LIT:2> * x ) ) == <NUM_LIT:9> * x * y + <NUM_LIT:9> * x + _keep_coeff ( S ( <NUM_LIT:3> ) , x + <NUM_LIT:1> ) ** _keep_coeff ( S ( <NUM_LIT:2> ) , x + <NUM_LIT:1> ) + <NUM_LIT:9> <EOL> assert factor_terms ( <NUM_LIT:9> * ( x + x * y + <NUM_LIT:1> ) + ( <NUM_LIT:3> ) ** ( <NUM_LIT:2> + <NUM_LIT:2> * x ) ) == _keep_coeff ( S ( <NUM_LIT:9> ) , <NUM_LIT:3> ** ( <NUM_LIT:2> * x ) + x * y + x + <NUM_LIT:1> ) <EOL> assert factor_terms ( <NUM_LIT:3> ** ( <NUM_LIT:2> + <NUM_LIT:2> * x ) + a * <NUM_LIT:3> ** ( <NUM_LIT:2> + <NUM_LIT:2> * x ) ) == <NUM_LIT:9> * <NUM_LIT:3> ** ( <NUM_LIT:2> * x ) * ( a + <NUM_LIT:1> ) <EOL> assert factor_terms ( x + x * A ) == x * ( <NUM_LIT:1> + A ) <EOL> assert factor_terms ( sin ( x + x * A ) ) == sin ( x * ( <NUM_LIT:1> + A ) ) <EOL> assert factor_terms ( ( <NUM_LIT:3> * x + <NUM_LIT:3> ) ** ( ( <NUM_LIT:2> + <NUM_LIT:2> * x ) / <NUM_LIT:3> ) ) == _keep_coeff ( S ( <NUM_LIT:3> ) , x + <NUM_LIT:1> ) ** _keep_coeff ( S ( <NUM_LIT:2> ) / <NUM_LIT:3> , x + <NUM_LIT:1> ) <EOL> assert factor_terms ( x + ( x * y + x ) ** ( <NUM_LIT:3> * x + <NUM_LIT:3> ) ) == x + ( x * ( y + <NUM_LIT:1> ) ) ** _keep_coeff ( S ( <NUM_LIT:3> ) , x + <NUM_LIT:1> ) <EOL> assert factor_terms ( a * ( x + x * y ) + b * ( x * <NUM_LIT:2> + y * x * <NUM_LIT:2> ) ) == x * ( a + <NUM_LIT:2> * b ) * ( y + <NUM_LIT:1> ) <EOL> i = Integral ( x , ( x , <NUM_LIT:0> , oo ) ) <EOL> assert factor_terms ( i ) == i <EOL> assert factor_terms ( x / <NUM_LIT:2> + y ) == x / <NUM_LIT:2> + y <EOL> assert factor_terms ( x / <NUM_LIT:2> + y , fraction = True ) == x / <NUM_LIT:2> + y <EOL> assert factor_terms ( x / <NUM_LIT:2> + y , clear = True ) == Mul ( S . Half , x + <NUM_LIT:2> * y , evaluate = False ) <EOL> eq = sqrt ( <NUM_LIT:2> ) + sqrt ( <NUM_LIT:10> ) <EOL> assert factor_terms ( eq ) == eq <EOL> assert factor_terms ( eq , radical = True ) == sqrt ( <NUM_LIT:2> ) * ( <NUM_LIT:1> + sqrt ( <NUM_LIT:5> ) ) <EOL> eq = root ( - <NUM_LIT:6> , <NUM_LIT:3> ) + root ( <NUM_LIT:6> , <NUM_LIT:3> ) <EOL> assert factor_terms ( eq , radical = True ) == <NUM_LIT:6> ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) * ( <NUM_LIT:1> + ( - <NUM_LIT:1> ) ** ( S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) ) <EOL> eq = [ x + x * y ] <EOL> ans = [ x * ( y + <NUM_LIT:1> ) ] <EOL> for c in [ list , tuple , set ] : <EOL> assert factor_terms ( c ( eq ) ) == c ( ans ) <EOL> assert factor_terms ( Tuple ( x + x * y ) ) == Tuple ( x * ( y + <NUM_LIT:1> ) ) <EOL> assert factor_terms ( Interval ( <NUM_LIT:0> , <NUM_LIT:1> ) ) == Interval ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> e = <NUM_LIT:1> / sqrt ( a / <NUM_LIT:2> + <NUM_LIT:1> ) <EOL> assert factor_terms ( e , clear = False ) == <NUM_LIT:1> / sqrt ( a / <NUM_LIT:2> + <NUM_LIT:1> ) <EOL> assert factor_terms ( e , clear = True ) == sqrt ( <NUM_LIT:2> ) / sqrt ( a + <NUM_LIT:2> ) <EOL> eq = x / ( x + <NUM_LIT:1> / x ) + <NUM_LIT:1> / ( x ** <NUM_LIT:2> + <NUM_LIT:1> ) <EOL> assert factor_terms ( eq , fraction = False ) == eq <EOL> assert factor_terms ( eq , fraction = True ) == <NUM_LIT:1> <EOL> assert factor_terms ( ( <NUM_LIT:1> / ( x ** <NUM_LIT:3> + x ** <NUM_LIT:2> ) + <NUM_LIT:2> / x ** <NUM_LIT:2> ) * y ) == y * ( <NUM_LIT:2> + <NUM_LIT:1> / ( x + <NUM_LIT:1> ) ) / x ** <NUM_LIT:2> <EOL> assert gcd_terms ( - x - y ) == - x - y <EOL> assert factor_terms ( - x - y ) == Mul ( - <NUM_LIT:1> , x + y , evaluate = False ) <EOL> assert gcd_terms ( exp ( Mul ( - <NUM_LIT:1> , x + <NUM_LIT:1> ) ) ) == exp ( - x - <NUM_LIT:1> ) <EOL> e = exp ( - x - <NUM_LIT:2> ) + x <EOL> assert factor_terms ( e ) == exp ( Mul ( - <NUM_LIT:1> , x + <NUM_LIT:2> , evaluate = False ) ) + x <EOL> assert factor_terms ( e , sign = False ) == e <EOL> assert factor_terms ( exp ( - <NUM_LIT:4> * x - <NUM_LIT:2> ) - x ) == - x + exp ( Mul ( - <NUM_LIT:2> , <NUM_LIT:2> * x + <NUM_LIT:1> , evaluate = False ) ) <EOL> def test_xreplace ( ) : <EOL> e = Mul ( <NUM_LIT:2> , <NUM_LIT:1> + x , evaluate = False ) <EOL> assert e . xreplace ( { } ) == e <EOL> assert e . xreplace ( { y : x } ) == e <EOL> def test_factor_nc ( ) : <EOL> x , y = symbols ( '<STR_LIT>' ) <EOL> k = symbols ( '<STR_LIT:k>' , integer = True ) <EOL> n , m , o = symbols ( '<STR_LIT>' , commutative = False ) <EOL> from sympy . core . function import _mexpand <EOL> e = x * ( <NUM_LIT:1> + y ) ** <NUM_LIT:2> <EOL> assert _mexpand ( e ) == x + x * <NUM_LIT:2> * y + x * y ** <NUM_LIT:2> <EOL> def factor_nc_test ( e ) : <EOL> ex = _mexpand ( e ) <EOL> assert ex . is_Add <EOL> f = factor_nc ( ex ) <EOL> assert not f . is_Add and _mexpand ( f ) == ex <EOL> factor_nc_test ( x * ( <NUM_LIT:1> + y ) ) <EOL> factor_nc_test ( n * ( x + <NUM_LIT:1> ) ) <EOL> factor_nc_test ( n * ( x + m ) ) <EOL> factor_nc_test ( ( x + m ) * n ) <EOL> factor_nc_test ( n * m * ( x * o + n * o * m ) * n ) <EOL> s = Sum ( x , ( x , <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> factor_nc_test ( x * ( <NUM_LIT:1> + s ) ) <EOL> factor_nc_test ( x * ( <NUM_LIT:1> + s ) * s ) <EOL> factor_nc_test ( x * ( <NUM_LIT:1> + sin ( s ) ) ) <EOL> factor_nc_test ( ( <NUM_LIT:1> + n ) ** <NUM_LIT:2> ) <EOL> factor_nc_test ( ( x + n ) * ( x + m ) * ( x + y ) ) <EOL> factor_nc_test ( x * ( n * m + <NUM_LIT:1> ) ) <EOL> factor_nc_test ( x * ( n * m + x ) ) <EOL> factor_nc_test ( x * ( x * n * m + <NUM_LIT:1> ) ) <EOL> factor_nc_test ( x * n * ( x * m + <NUM_LIT:1> ) ) <EOL> factor_nc_test ( x * ( m * n + x * n * m ) ) <EOL> factor_nc_test ( n * ( <NUM_LIT:1> - m ) * n ** <NUM_LIT:2> ) <EOL> factor_nc_test ( ( n + m ) ** <NUM_LIT:2> ) <EOL> factor_nc_test ( ( n - m ) * ( n + m ) ** <NUM_LIT:2> ) <EOL> factor_nc_test ( ( n + m ) ** <NUM_LIT:2> * ( n - m ) ) <EOL> factor_nc_test ( ( m - n ) * ( n + m ) ** <NUM_LIT:2> * ( n - m ) ) <EOL> assert factor_nc ( n * ( n + n * m ) ) == n ** <NUM_LIT:2> * ( <NUM_LIT:1> + m ) <EOL> assert factor_nc ( m * ( m * n + n * m * n ** <NUM_LIT:2> ) ) == m * ( m + n * m * n ) * n <EOL> eq = m * sin ( n ) - sin ( n ) * m <EOL> assert factor_nc ( eq ) == eq <EOL> from sympy . physics . secondquant import Commutator <EOL> from sympy import factor <EOL> eq = <NUM_LIT:1> + x * Commutator ( m , n ) <EOL> assert factor_nc ( eq ) == eq <EOL> eq = x * Commutator ( m , n ) + x * Commutator ( m , o ) * Commutator ( m , n ) <EOL> assert factor ( eq ) == x * ( <NUM_LIT:1> + Commutator ( m , o ) ) * Commutator ( m , n ) <EOL> assert ( <NUM_LIT:2> * n + <NUM_LIT:2> * m ) . factor ( ) == <NUM_LIT:2> * ( n + m ) <EOL> assert factor_nc ( n ** k + n ** ( k + <NUM_LIT:1> ) ) == n ** k * ( <NUM_LIT:1> + n ) <EOL> assert factor_nc ( ( m * n ) ** k + ( m * n ) ** ( k + <NUM_LIT:1> ) ) == ( <NUM_LIT:1> + m * n ) * ( m * n ) ** k <EOL> assert factor_nc ( - n * ( <NUM_LIT:2> * x ** <NUM_LIT:2> + <NUM_LIT:2> * x ) ) == - <NUM_LIT:2> * n * x * ( x + <NUM_LIT:1> ) <EOL> def test_issue_6360 ( ) : <EOL> a , b = symbols ( "<STR_LIT>" ) <EOL> apb = a + b <EOL> eq = apb + apb ** <NUM_LIT:2> * ( - <NUM_LIT:2> * a - <NUM_LIT:2> * b ) <EOL> assert factor_terms ( sub_pre ( eq ) ) == a + b - <NUM_LIT:2> * ( a + b ) ** <NUM_LIT:3> <EOL> def test_issue_7903 ( ) : <EOL> a = symbols ( r'<STR_LIT:a>' , real = True ) <EOL> t = exp ( I * cos ( a ) ) + exp ( - I * sin ( a ) ) <EOL> assert t . simplify ( ) <EOL> def test_monotonic_sign ( ) : <EOL> F = _monotonic_sign <EOL> x = symbols ( '<STR_LIT:x>' ) <EOL> assert F ( x ) is None <EOL> assert F ( - x ) is None <EOL> assert F ( Dummy ( prime = True ) ) == <NUM_LIT:2> <EOL> assert F ( Dummy ( prime = True , odd = True ) ) == <NUM_LIT:3> <EOL> assert F ( Dummy ( positive = True , integer = True ) ) == <NUM_LIT:1> <EOL> assert F ( Dummy ( positive = True , even = True ) ) == <NUM_LIT:2> <EOL> assert F ( Dummy ( negative = True , integer = True ) ) == - <NUM_LIT:1> <EOL> assert F ( Dummy ( negative = True , even = True ) ) == - <NUM_LIT:2> <EOL> assert F ( Dummy ( zero = True ) ) == <NUM_LIT:0> <EOL> assert F ( Dummy ( nonnegative = True ) ) == <NUM_LIT:0> <EOL> assert F ( Dummy ( nonpositive = True ) ) == <NUM_LIT:0> <EOL> assert F ( Dummy ( positive = True ) + <NUM_LIT:1> ) . is_positive <EOL> assert F ( Dummy ( positive = True , integer = True ) - <NUM_LIT:1> ) . is_nonnegative <EOL> assert F ( Dummy ( positive = True ) - <NUM_LIT:1> ) is None <EOL> assert F ( Dummy ( negative = True ) + <NUM_LIT:1> ) is None <EOL> assert F ( Dummy ( negative = True , integer = True ) - <NUM_LIT:1> ) . is_nonpositive <EOL> assert F ( Dummy ( negative = True ) - <NUM_LIT:1> ) . is_negative <EOL> assert F ( - Dummy ( positive = True ) + <NUM_LIT:1> ) is None <EOL> assert F ( - Dummy ( positive = True , integer = True ) - <NUM_LIT:1> ) . is_negative <EOL> assert F ( - Dummy ( positive = True ) - <NUM_LIT:1> ) . is_negative <EOL> assert F ( - Dummy ( negative = True ) + <NUM_LIT:1> ) . is_positive <EOL> assert F ( - Dummy ( negative = True , integer = True ) - <NUM_LIT:1> ) . is_nonnegative <EOL> assert F ( - Dummy ( negative = True ) - <NUM_LIT:1> ) is None <EOL> x = Dummy ( negative = True ) <EOL> assert F ( x ** <NUM_LIT:3> ) . is_nonpositive <EOL> assert F ( x ** <NUM_LIT:3> + log ( <NUM_LIT:2> ) * x - <NUM_LIT:1> ) . is_negative <EOL> x = Dummy ( positive = True ) <EOL> assert F ( - x ** <NUM_LIT:3> ) . is_nonpositive <EOL> p = Dummy ( positive = True ) <EOL> assert F ( <NUM_LIT:1> / p ) . is_positive <EOL> assert F ( p / ( p + <NUM_LIT:1> ) ) . is_positive <EOL> p = Dummy ( nonnegative = True ) <EOL> assert F ( p / ( p + <NUM_LIT:1> ) ) . is_nonnegative <EOL> p = Dummy ( positive = True ) <EOL> assert F ( - <NUM_LIT:1> / p ) . is_negative <EOL> p = Dummy ( nonpositive = True ) <EOL> assert F ( p / ( - p + <NUM_LIT:1> ) ) . is_nonpositive <EOL> p = Dummy ( positive = True , integer = True ) <EOL> q = Dummy ( positive = True , integer = True ) <EOL> assert F ( - <NUM_LIT:2> / p / q ) . is_negative <EOL> assert F ( - <NUM_LIT:2> / ( p - <NUM_LIT:1> ) / q ) is None <EOL> assert F ( ( p - <NUM_LIT:1> ) * q + <NUM_LIT:1> ) . is_positive <EOL> assert F ( - ( p - <NUM_LIT:1> ) * q - <NUM_LIT:1> ) . is_negative </s>
