#NEWLINE# def test_multiple_expressions( ) : #NEWLINE# #INDENT# e1 = ( ( x + y ) * z ) #NEWLINE# e2 = ( ( x + y ) * w ) #NEWLINE# ( substs , reduced ) = cse ( [ e1 , e2 ] ) #NEWLINE# assert ( substs == [ ( x0 , ( x + y ) ) ] ) #NEWLINE# assert ( reduced == [ ( x0 * z ) , ( x0 * w ) ] ) #NEWLINE# l = [ ( ( ( w * x ) * y ) + z ) , ( w * y ) ] #NEWLINE# ( substs , reduced ) = cse ( l ) #NEWLINE# ( rsubsts , _ ) = cse ( reversed ( l ) ) #NEWLINE# assert ( substs == rsubsts ) #NEWLINE# assert ( reduced == [ ( z + ( x * x0 ) ) , x0 ] ) #NEWLINE# l = [ ( ( w * x ) * y ) , ( ( ( w * x ) * y ) + z ) , ( w * y ) ] #NEWLINE# ( substs , reduced ) = cse ( l ) #NEWLINE# ( rsubsts , _ ) = cse ( reversed ( l ) ) #NEWLINE# assert ( substs == rsubsts ) #NEWLINE# assert ( reduced == [ x1 , ( x1 + z ) , x0 ] ) #NEWLINE# l = [ ( ( x - z ) * ( y - z ) ) , ( x - z ) , ( y - z ) ] #NEWLINE# ( substs , reduced ) = cse ( l ) #NEWLINE# ( rsubsts , _ ) = cse ( reversed ( l ) ) #NEWLINE# assert ( _ == [ ( x0 , ( - z ) ) , ( x1 , ( x + x0 ) ) , ( x2 , ( x0 + y ) ) ] ) #NEWLINE# assert ( rsubsts == [ ( x0 , ( - z ) ) , ( x1 , ( x0 + y ) ) , ( x2 , ( x + x0 ) ) ] ) #NEWLINE# assert ( reduced == [ ( x1 * x2 ) , x1 , x2 ] ) #NEWLINE# l = [ ( ( ( ( ( w * y ) + w ) + x ) + y ) + z ) , ( ( w * x ) * y ) ] #NEWLINE# assert ( cse ( l ) == ( [ ( x0 , ( w * y ) ) ] , [ ( ( ( ( w + x ) + x0 ) + y ) + z ) , ( x * x0 ) ] ) ) #NEWLINE# assert ( cse ( [ ( x + y ) , ( ( x + y ) + z ) ] ) == ( [ ( x0 , ( x + y ) ) ] , [ x0 , ( z + x0 ) ] ) ) #NEWLINE# assert ( cse ( [ ( x + y ) , ( x + z ) ] ) == ( [ ] , [ ( x + y ) , ( x + z ) ] ) ) #NEWLINE# assert ( cse ( [ ( x * y ) , ( z + ( x * y ) ) , ( ( ( x * y ) * z ) + 3 ) ] ) == ( [ ( x0 , ( x * y ) ) ] , [ x0 , ( z + x0 ) , ( 3 + ( x0 * z ) ) ] ) )