1 from sympy
import Symbol
, Rational
, Derivative
, I
, log
, sqrt
, exp
, sin
10 assert str(1/x
) == "1/x"
13 #if any of these tests fails, it can still be correct, just the terms can
14 #be in a different order. That happens for example when we change the
15 #hash algorithm. If it is correct, just add another item in the list [] of
17 assert str((2*x
-(7*x
**2 - 2) + 3*y
)) in ["2 - 7*x**2 + 2*x + 3*y",
18 "2 + 3*y + 2*x - 7*x**2", "2 + 3*y - 7*x**2 + 2*x",
19 "3*y + 2*x + 2 - 7*x**2", "2 + 2*x + 3*y - 7*x**2"]
20 assert str(x
-y
) in ["x - y", "-y + x"]
21 assert str(2+-x
) in ["2 - x", "-x + 2"]
22 assert str(x
-2) in ["x - 2", "(-2) + x", "-2 + x"]
23 assert str(x
-y
-z
-w
) in ["x - y - z - w","-w - y - z + x","x - w - y - z",
24 "-w + x - y - z","-z - w - y + x","-y + x - w - z",
26 assert str(x
-y
-z
-w
) in [
27 "-w - y - z + x","x - w - y - z","-w + x - z - y","-y - w - z + x",
28 "-y + x - z - w","-y + x - w - z","-w + x - y - z","-z - w - y +x",
30 assert str(x
-z
*y
**2*z
*w
) in ["-z**2*y**2*w + x", "x - w*y**2*z**2",
31 "-y**2*z**2*w + x","x - w*z**2*y**2","x - y**2*z**2*w",
32 "x - y**2*w*z**2","x - z**2*y**2*w","-w*z**2*y**2 + x",
33 "-w*y**2*z**2 + x","x - z**2*w*y**2"]
36 assert str(x
-1*y
*x
*y
) in ["x - x*y**2", "-x*y**2 + x"]
47 assert str(e
) == "x**(1/2)"
52 e
= -2*sqrt(x
)-w
/sqrt(x
)/2
53 assert str(e
) not in ["(-2)*x**1/2(-1/2)*x**(-1/2)*w",
54 "-2*x**1/2(-1/2)*x**(-1/2)*w","-2*x**1/2-1/2*x**-1/2*w"]
55 assert str(e
) in ["-2*x**(1/2) - 1/2*x**(-1/2)*w", "-2*x**(1/2) - 1/2*w*x**(-1/2)",
56 "-1/2*x**(-1/2)*w - 2*x**(1/2)", "-1/2*w*x**(-1/2) - 2*x**(1/2)"]
58 def test_Derivative():
62 e
= Derivative(x
**2, x
, evaluate
=False)
63 assert str(e
) == "D(x**2, x)"
65 e
= Derivative(x
**2/y
, x
, y
, evaluate
=False)
66 assert str(e
) == "D(x**2/y, x, y)"
71 assert str(x
/y
) == "x/y"
72 assert str(y
/x
) == "y/x"
76 assert str(sin(x
).series(x
, 0, 15)) == "x - 1/6*x**3 + (1/120)*x**5 - 1/5040*x**7 + (1/362880)*x**9 - 1/39916800*x**11 + (1/6227020800)*x**13 + O(x**15)"