<s> from sympy import symbols , sin , exp , cos , Derivative , Integral , Basic , count_ops , S , And , I , pi , Eq , Or , Not , Xor , Nand , Nor , Implies , Equivalent , MatrixSymbol , Symbol , ITE <EOL> from sympy . core . containers import Tuple <EOL> x , y , z = symbols ( '<STR_LIT>' ) <EOL> a , b , c = symbols ( '<STR_LIT>' ) <EOL> def test_count_ops_non_visual ( ) : <EOL> def count ( val ) : <EOL> return count_ops ( val , visual = False ) <EOL> assert count ( x ) == <NUM_LIT:0> <EOL> assert count ( x ) is not S . Zero <EOL> assert count ( x + y ) == <NUM_LIT:1> <EOL> assert count ( x + y ) is not S . One <EOL> assert count ( x + y * x + <NUM_LIT:2> * y ) == <NUM_LIT:4> <EOL> assert count ( { x + y : x } ) == <NUM_LIT:1> <EOL> assert count ( { x + y : S ( <NUM_LIT:2> ) + x } ) is not S . One <EOL> assert count ( Or ( x , y ) ) == <NUM_LIT:1> <EOL> assert count ( And ( x , y ) ) == <NUM_LIT:1> <EOL> assert count ( Not ( x ) ) == <NUM_LIT:1> <EOL> assert count ( Nor ( x , y ) ) == <NUM_LIT:2> <EOL> assert count ( Nand ( x , y ) ) == <NUM_LIT:2> <EOL> assert count ( Xor ( x , y ) ) == <NUM_LIT:1> <EOL> assert count ( Implies ( x , y ) ) == <NUM_LIT:1> <EOL> assert count ( Equivalent ( x , y ) ) == <NUM_LIT:1> <EOL> assert count ( ITE ( x , y , z ) ) == <NUM_LIT:1> <EOL> assert count ( ITE ( True , x , y ) ) == <NUM_LIT:0> <EOL> def test_count_ops_visual ( ) : <EOL> ADD , MUL , POW , SIN , COS , EXP , AND , D , G = symbols ( <EOL> '<STR_LIT>' . upper ( ) ) <EOL> DIV , SUB , NEG = symbols ( '<STR_LIT>' ) <EOL> NOT , OR , AND , XOR , IMPLIES , EQUIVALENT , ITE , BASIC , TUPLE = symbols ( <EOL> '<STR_LIT>' . upper ( ) ) <EOL> def count ( val ) : <EOL> return count_ops ( val , visual = True ) <EOL> assert count ( <NUM_LIT:7> ) is S . Zero <EOL> assert count ( S ( <NUM_LIT:7> ) ) is S . Zero <EOL> assert count ( - <NUM_LIT:1> ) == NEG <EOL> assert count ( - <NUM_LIT:2> ) == NEG <EOL> assert count ( S ( <NUM_LIT:2> ) / <NUM_LIT:3> ) == DIV <EOL> assert count ( pi / <NUM_LIT:3> ) == DIV <EOL> assert count ( - pi / <NUM_LIT:3> ) == DIV + NEG <EOL> assert count ( I - <NUM_LIT:1> ) == SUB <EOL> assert count ( <NUM_LIT:1> - I ) == SUB <EOL> assert count ( <NUM_LIT:1> - <NUM_LIT:2> * I ) == SUB + MUL <EOL> assert count ( x ) is S . Zero <EOL> assert count ( - x ) == NEG <EOL> assert count ( - <NUM_LIT:2> * x / <NUM_LIT:3> ) == NEG + DIV + MUL <EOL> assert count ( <NUM_LIT:1> / x ) == DIV <EOL> assert count ( <NUM_LIT:1> / ( x * y ) ) == DIV + MUL <EOL> assert count ( - <NUM_LIT:1> / x ) == NEG + DIV <EOL> assert count ( - <NUM_LIT:2> / x ) == NEG + DIV <EOL> assert count ( x / y ) == DIV <EOL> assert count ( - x / y ) == NEG + DIV <EOL> assert count ( x ** <NUM_LIT:2> ) == POW <EOL> assert count ( - x ** <NUM_LIT:2> ) == POW + NEG <EOL> assert count ( - <NUM_LIT:2> * x ** <NUM_LIT:2> ) == POW + MUL + NEG <EOL> assert count ( x + pi / <NUM_LIT:3> ) == ADD + DIV <EOL> assert count ( x + S ( <NUM_LIT:1> ) / <NUM_LIT:3> ) == ADD + DIV <EOL> assert count ( x + y ) == ADD <EOL> assert count ( x - y ) == SUB <EOL> assert count ( y - x ) == SUB <EOL> assert count ( - <NUM_LIT:1> / ( x - y ) ) == DIV + NEG + SUB <EOL> assert count ( - <NUM_LIT:1> / ( y - x ) ) == DIV + NEG + SUB <EOL> assert count ( <NUM_LIT:1> + x ** y ) == ADD + POW <EOL> assert count ( <NUM_LIT:1> + x + y ) == <NUM_LIT:2> * ADD <EOL> assert count ( <NUM_LIT:1> + x + y + z ) == <NUM_LIT:3> * ADD <EOL> assert count ( <NUM_LIT:1> + x ** y + <NUM_LIT:2> * x * y + y ** <NUM_LIT:2> ) == <NUM_LIT:3> * ADD + <NUM_LIT:2> * POW + <NUM_LIT:2> * MUL <EOL> assert count ( <NUM_LIT:2> * z + y + x + <NUM_LIT:1> ) == <NUM_LIT:3> * ADD + MUL <EOL> assert count ( <NUM_LIT:2> * z + y ** <NUM_LIT> + x + <NUM_LIT:1> ) == <NUM_LIT:3> * ADD + MUL + POW <EOL> assert count ( <NUM_LIT:2> * z + y ** <NUM_LIT> + x + sin ( x ) ) == <NUM_LIT:3> * ADD + POW + MUL + SIN <EOL> assert count ( <NUM_LIT:2> * z + y ** <NUM_LIT> + x + sin ( x ** <NUM_LIT:2> ) ) == <NUM_LIT:3> * ADD + MUL + <NUM_LIT:2> * POW + SIN <EOL> assert count ( <NUM_LIT:2> * z + y ** <NUM_LIT> + x + sin ( <EOL> x ** <NUM_LIT:2> ) + exp ( cos ( x ) ) ) == <NUM_LIT:4> * ADD + MUL + <NUM_LIT:2> * POW + EXP + COS + SIN <EOL> assert count ( Derivative ( x , x ) ) == D <EOL> assert count ( Integral ( x , x ) + <NUM_LIT:2> * x / ( <NUM_LIT:1> + x ) ) == G + DIV + MUL + <NUM_LIT:2> * ADD <EOL> assert count ( Basic ( ) ) is S . Zero <EOL> assert count ( { x + <NUM_LIT:1> : sin ( x ) } ) == ADD + SIN <EOL> assert count ( [ x + <NUM_LIT:1> , sin ( x ) + y , None ] ) == ADD + SIN + ADD <EOL> assert count ( { x + <NUM_LIT:1> : sin ( x ) , y : cos ( x ) + <NUM_LIT:1> } ) == SIN + COS + <NUM_LIT:2> * ADD <EOL> assert count ( { } ) is S . Zero <EOL> assert count ( [ x + <NUM_LIT:1> , sin ( x ) * y , None ] ) == SIN + ADD + MUL <EOL> assert count ( [ ] ) is S . Zero <EOL> assert count ( Basic ( ) ) == <NUM_LIT:0> <EOL> assert count ( Basic ( Basic ( ) , Basic ( x , x + y ) ) ) == ADD + <NUM_LIT:2> * BASIC <EOL> assert count ( Basic ( x , x + y ) ) == ADD + BASIC <EOL> assert count ( Or ( x , y ) ) == OR <EOL> assert count ( And ( x , y ) ) == AND <EOL> assert count ( And ( x ** y , z ) ) == AND + POW <EOL> assert count ( Or ( x , Or ( y , And ( z , a ) ) ) ) == AND + OR <EOL> assert count ( Nor ( x , y ) ) == NOT + OR <EOL> assert count ( Nand ( x , y ) ) == NOT + AND <EOL> assert count ( Xor ( x , y ) ) == XOR <EOL> assert count ( Implies ( x , y ) ) == IMPLIES <EOL> assert count ( Equivalent ( x , y ) ) == EQUIVALENT <EOL> assert count ( ITE ( x , y , z ) ) == ITE <EOL> assert count ( [ Or ( x , y ) , And ( x , y ) , Basic ( x + y ) ] ) == ADD + AND + BASIC + OR <EOL> assert count ( Basic ( Tuple ( x ) ) ) == BASIC + TUPLE <EOL> assert count ( Eq ( x + y , S ( <NUM_LIT:2> ) ) ) == ADD <EOL> def test_issue_9324 ( ) : <EOL> def count ( val ) : <EOL> return count_ops ( val , visual = False ) <EOL> M = MatrixSymbol ( '<STR_LIT:M>' , <NUM_LIT:10> , <NUM_LIT:10> ) <EOL> assert count ( M [ <NUM_LIT:0> , <NUM_LIT:0> ] ) == <NUM_LIT:0> <EOL> assert count ( <NUM_LIT:2> * M [ <NUM_LIT:0> , <NUM_LIT:0> ] + M [ <NUM_LIT:5> , <NUM_LIT:7> ] ) == <NUM_LIT:2> <EOL> P = MatrixSymbol ( '<STR_LIT:P>' , <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> Q = MatrixSymbol ( '<STR_LIT>' , <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> assert count ( P + Q ) == <NUM_LIT:3> <EOL> m = Symbol ( '<STR_LIT:m>' , integer = True ) <EOL> n = Symbol ( '<STR_LIT:n>' , integer = True ) <EOL> M = MatrixSymbol ( '<STR_LIT:M>' , m + n , m * m ) <EOL> assert count ( M [ <NUM_LIT:0> , <NUM_LIT:1> ] ) == <NUM_LIT:2> </s>
