1from sympy.abc import x, y 2from sympy.core.parameters import evaluate 3from sympy.core import Mul, Add, Pow, S 4from sympy import sqrt, oo 5 6def test_add(): 7 with evaluate(False): 8 p = oo - oo 9 assert isinstance(p, Add) and p.args == (oo, -oo) 10 p = 5 - oo 11 assert isinstance(p, Add) and p.args == (-oo, 5) 12 p = oo - 5 13 assert isinstance(p, Add) and p.args == (oo, -5) 14 p = oo + 5 15 assert isinstance(p, Add) and p.args == (oo, 5) 16 p = 5 + oo 17 assert isinstance(p, Add) and p.args == (oo, 5) 18 p = -oo + 5 19 assert isinstance(p, Add) and p.args == (-oo, 5) 20 p = -5 - oo 21 assert isinstance(p, Add) and p.args == (-oo, -5) 22 23 with evaluate(False): 24 expr = x + x 25 assert isinstance(expr, Add) 26 assert expr.args == (x, x) 27 28 with evaluate(True): 29 assert (x + x).args == (2, x) 30 31 assert (x + x).args == (x, x) 32 33 assert isinstance(x + x, Mul) 34 35 with evaluate(False): 36 assert S.One + 1 == Add(1, 1) 37 assert 1 + S.One == Add(1, 1) 38 39 assert S(4) - 3 == Add(4, -3) 40 assert -3 + S(4) == Add(4, -3) 41 42 assert S(2) * 4 == Mul(2, 4) 43 assert 4 * S(2) == Mul(2, 4) 44 45 assert S(6) / 3 == Mul(6, Pow(3, -1)) 46 assert S.One / 3 * 6 == Mul(S.One / 3, 6) 47 48 assert 9 ** S(2) == Pow(9, 2) 49 assert S(2) ** 9 == Pow(2, 9) 50 51 assert S(2) / 2 == Mul(2, Pow(2, -1)) 52 assert S.One / 2 * 2 == Mul(S.One / 2, 2) 53 54 assert S(2) / 3 + 1 == Add(S(2) / 3, 1) 55 assert 1 + S(2) / 3 == Add(1, S(2) / 3) 56 57 assert S(4) / 7 - 3 == Add(S(4) / 7, -3) 58 assert -3 + S(4) / 7 == Add(-3, S(4) / 7) 59 60 assert S(2) / 4 * 4 == Mul(S(2) / 4, 4) 61 assert 4 * (S(2) / 4) == Mul(4, S(2) / 4) 62 63 assert S(6) / 3 == Mul(6, Pow(3, -1)) 64 assert S.One / 3 * 6 == Mul(S.One / 3, 6) 65 66 assert S.One / 3 + sqrt(3) == Add(S.One / 3, sqrt(3)) 67 assert sqrt(3) + S.One / 3 == Add(sqrt(3), S.One / 3) 68 69 assert S.One / 2 * 10.333 == Mul(S.One / 2, 10.333) 70 assert 10.333 * (S.One / 2) == Mul(10.333, S.One / 2) 71 72 assert sqrt(2) * sqrt(2) == Mul(sqrt(2), sqrt(2)) 73 74 assert S.One / 2 + x == Add(S.One / 2, x) 75 assert x + S.One / 2 == Add(x, S.One / 2) 76 77 assert S.One / x * x == Mul(S.One / x, x) 78 assert x * (S.One / x) == Mul(x, Pow(x, -1)) 79 80 assert S.One / 3 == Pow(3, -1) 81 assert S.One / x == Pow(x, -1) 82 assert 1 / S(3) == Pow(3, -1) 83 assert 1 / x == Pow(x, -1) 84 85def test_nested(): 86 with evaluate(False): 87 expr = (x + x) + (y + y) 88 assert expr.args == ((x + x), (y + y)) 89 assert expr.args[0].args == (x, x) 90