#NEWLINE# def test_expand_non_commutative( ) : #NEWLINE# #INDENT# A = Symbol ( 'A' , commutative = False ) #NEWLINE# B = Symbol ( 'B' , commutative = False ) #NEWLINE# C = Symbol ( 'C' , commutative = False ) #NEWLINE# a = Symbol ( 'a' ) #NEWLINE# b = Symbol ( 'b' ) #NEWLINE# i = Symbol ( 'i' , integer = True ) #NEWLINE# n = Symbol ( 'n' , negative = True ) #NEWLINE# m = Symbol ( 'm' , negative = True ) #NEWLINE# p = Symbol ( 'p' , polar = True ) #NEWLINE# np = Symbol ( 'p' , polar = False ) #NEWLINE# assert ( ( C * ( A + B ) ) . expand ( ) == ( ( C * A ) + ( C * B ) ) ) #NEWLINE# assert ( ( C * ( A + B ) ) . expand ( ) != ( ( A * C ) + ( B * C ) ) ) #NEWLINE# assert ( ( ( A + B ) ** 2 ) . expand ( ) == ( ( ( ( A ** 2 ) + ( A * B ) ) + ( B * A ) ) + ( B ** 2 ) ) ) #NEWLINE# assert ( ( ( A + B ) ** 3 ) . expand ( ) == ( ( ( ( ( ( ( ( ( A ** 2 ) * B ) + ( ( B ** 2 ) * A ) ) + ( A * ( B ** 2 ) ) ) + ( B * ( A ** 2 ) ) ) + ( A ** 3 ) ) + ( B ** 3 ) ) + ( ( A * B ) * A ) ) + ( ( B * A ) * B ) ) ) #NEWLINE# assert ( ( ( ( ( a * A ) * B ) * ( A ** ( - 1 ) ) ) ** 2 ) . expand ( ) == ( ( ( ( a ** 2 ) * A ) * ( B ** 2 ) ) / A ) ) #NEWLINE# assert ( ( ( ( ( a * A ) * B ) * ( A ** ( - 1 ) ) ) ** 2 ) . expand ( deep = False ) == ( ( a ** 2 ) * ( ( ( A * B ) * ( A ** ( - 1 ) ) ) ** 2 ) ) ) #NEWLINE# assert ( ( ( ( ( a * A ) * B ) * ( A ** ( - 1 ) ) ) ** 2 ) . expand ( ) == ( ( a ** 2 ) * ( ( A * ( B ** 2 ) ) * ( A ** ( - 1 ) ) ) ) ) #NEWLINE# assert ( ( ( ( ( a * A ) * B ) * ( A ** ( - 1 ) ) ) ** 2 ) . expand ( force = True ) == ( ( ( ( a ** 2 ) * A ) * ( B ** 2 ) ) * ( A ** ( - 1 ) ) ) ) #NEWLINE# assert ( ( ( ( a * A ) * B ) ** 2 ) . expand ( ) == ( ( ( ( ( a ** 2 ) * A ) * B ) * A ) * B ) ) #NEWLINE# assert ( ( ( a * A ) ** 2 ) . expand ( ) == ( ( a ** 2 ) * ( A ** 2 ) ) ) #NEWLINE# assert ( ( ( ( a * A ) * B ) ** i ) . expand ( ) == ( ( a ** i ) * ( ( A * B ) ** i ) ) ) #NEWLINE# assert ( ( ( ( a * A ) * ( B * ( ( ( A * B ) / A ) ** 2 ) ) ) ** i ) . expand ( ) == ( ( a ** i ) * ( ( ( ( ( A * B ) * A ) * ( B ** 2 ) ) / A ) ** i ) ) ) #NEWLINE# assert ( ( ( A * B ) * ( ( A * B ) ** ( - 1 ) ) ) . expand ( ) == ( ( A * B ) * ( ( A * B ) ** ( - 1 ) ) ) ) #NEWLINE# assert ( ( ( a * A ) ** i ) . expand ( ) == ( ( a ** i ) * ( A ** i ) ) ) #NEWLINE# assert ( ( ( ( ( a * A ) * B ) * ( A ** ( - 1 ) ) ) ** 3 ) . expand ( ) == ( ( ( ( a ** 3 ) * A ) * ( B ** 3 ) ) / A ) ) #NEWLINE# assert ( ( ( ( ( ( ( a * A ) * B ) * A ) * B ) / A ) ** 3 ) . expand ( ) == ( ( ( ( ( ( ( ( a ** 3 ) * A ) * B ) * ( A * ( B ** 2 ) ) ) * ( A * ( B ** 2 ) ) ) * A ) * B ) * ( A ** ( - 1 ) ) ) ) #NEWLINE# assert ( ( ( ( ( ( ( a * A ) * B ) * A ) * B ) / A ) ** ( - 3 ) ) . expand ( ) == ( ( a ** ( - 3 ) ) * ( ( ( ( ( ( ( A * B ) * ( A * ( B ** 2 ) ) ) * ( A * ( B ** 2 ) ) ) * A ) * B ) * ( A ** ( - 1 ) ) ) ** ( - 1 ) ) ) ) #NEWLINE# assert ( ( ( ( ( ( a * b ) * A ) * B ) * ( A ** ( - 1 ) ) ) ** i ) . expand ( ) == ( ( ( a ** i ) * ( b ** i ) ) * ( ( ( A * B ) / A ) ** i ) ) ) #NEWLINE# assert ( ( ( a * ( ( a * b ) ** i ) ) ** i ) . expand ( ) == ( ( ( a ** i ) * ( a ** ( i ** 2 ) ) ) * ( b ** ( i ** 2 ) ) ) ) #NEWLINE# e = Pow ( Mul ( a , ( 1 / a ) , A , B , evaluate = False ) , S ( 2 ) , evaluate = False ) #NEWLINE# assert ( e . expand ( ) == ( ( ( A * B ) * A ) * B ) ) #NEWLINE# assert ( sqrt ( ( a * ( ( A * b ) ** i ) ) ) . expand ( ) == sqrt ( ( ( a * ( b ** i ) ) * ( A ** i ) ) ) ) #NEWLINE# assert ( ( sqrt ( ( - a ) ) ** a ) . expand ( ) == ( sqrt ( ( - a ) ) ** a ) ) #NEWLINE# assert ( expand ( ( ( ( - 2 ) * n ) ** ( i / 3 ) ) ) == ( ( 2 ** ( i / 3 ) ) * ( ( - n ) ** ( i / 3 ) ) ) ) #NEWLINE# assert ( expand ( ( ( ( ( - 2 ) * n ) * m ) ** ( i / a ) ) ) == ( ( ( ( - 2 ) ** ( i / a ) ) * ( ( - n ) ** ( i / a ) ) ) * ( ( - m ) ** ( i / a ) ) ) ) #NEWLINE# assert ( expand ( ( ( ( ( - 2 ) * a ) * p ) ** b ) ) == ( ( ( 2 ** b ) * ( p ** b ) ) * ( ( - a ) ** b ) ) ) #NEWLINE# assert ( expand ( ( ( ( ( - 2 ) * a ) * np ) ** b ) ) == ( ( 2 ** b ) * ( ( ( - a ) * np ) ** b ) ) ) #NEWLINE# assert ( expand ( sqrt ( ( A * B ) ) ) == sqrt ( ( A * B ) ) ) #NEWLINE# assert ( expand ( sqrt ( ( ( ( - 2 ) * a ) * b ) ) ) == ( sqrt ( 2 ) * sqrt ( ( ( - a ) * b ) ) ) )