simplify: put disabled tests under XFAIL
[sympy.git] / sympy / simplify / tests / test_simplify.py
blobe7e30b18750733580f26e96fa5574c21efa11d11
2 from sympy import *
3 from sympy.utilities.pytest import XFAIL
5 def test_ratsimp():
6 x = Symbol("x")
7 y = Symbol("y")
8 e = 1/x+1/y
9 assert e != (x+y)/(x*y)
10 assert ratsimp(e) == (x+y)/(x*y)
12 e = 1/(1+1/x)
13 assert ratsimp(e) == x/(x+1)
14 assert (x+1)*ratsimp(e)/x == 1
15 assert ratsimp(exp(e)) == exp(x/(x+1))
17 @XFAIL
18 def test_ratsimp_X1():
19 e = -x-y-(x+y)**(-1)*y**2+(x+y)**(-1)*x**2
20 assert e != -2*y
21 assert ratsimp(e) == -2*y
23 @XFAIL
24 def test_ratsimp_X2():
25 e = x/(x+y)+y/(x+y)
26 assert e != 1
27 assert ratsimp(e) == 1
31 def test_trigsimp():
32 x,y = map(Symbol, 'xy')
34 assert trigsimp(1 - sin(x)**2) == cos(x)**2
35 assert trigsimp(1 - cos(x)**2) == sin(x)**2
36 assert trigsimp(sin(x)**2 + cos(x)**2) == 1
37 assert trigsimp(1 + tan(x)**2) == 1/cos(x)**2
38 assert trigsimp(1/cos(x)**2 - 1) == tan(x)**2
39 assert trigsimp(1/cos(x)**2 - tan(x)**2) == 1
40 assert trigsimp(1 + cot(x)**2) == 1/sin(x)**2
41 assert trigsimp(1/sin(x)**2 - 1) == cot(x)**2
42 assert trigsimp(1/sin(x)**2 - cot(x)**2) == 1
44 assert trigsimp(5*cos(x)**2 + 5*sin(x)**2) == 5
45 assert trigsimp(5*cos(x/2)**2 + 2*sin(x/2)**2) in \
46 [2 + 3*cos(x/2)**2, 5 - 3*sin(x/2)**2]
48 assert trigsimp(cos(0.12345)**2 + sin(0.12345)**2) == 1
49 e = 2*sin(x)**2 + 2*cos(x)**2
50 assert trigsimp(log(e), deep=True) == log(2)
52 @XFAIL
53 def test_factorial_simplify():
54 # There are more tests in test_factorials.py. These are just to
55 # ensure that simplify() calls factorial_simplify correctly
56 from sympy.specfun.factorials import factorial
57 x = Symbol('x')
58 assert simplify(factorial(x)/x) == factorial(x-1)
59 assert simplify(factorial(factorial(x))) == factorial(factorial(x))
61 def test_simplify():
62 x = Symbol('x')
63 y = Symbol('y')
64 e = 1/x + 1/y
65 assert e != (x+y)/(x*y)
66 assert simplify(e) == (x+y)/(x*y)
68 e = (4+4*x-2*(2+2*x))/(2+2*x)
69 assert simplify(e) == 0
71 e = (-4*x*y**2-2*y**3-2*x**2*y)/(x+y)**2
72 assert simplify(e) == -2*y
74 e = (x+y)**2/(-4*x*y**2-2*y**3-2*x**2*y)
75 assert simplify(e) == 1 / (-2*y)
77 e = -x-y-(x+y)**(-1)*y**2+(x+y)**(-1)*x**2
78 assert simplify(e) == -2*y
80 def test_fraction():
81 x, y, z = map(Symbol, 'xyz')
83 assert fraction(Rational(1, 2)) == (1, 2)
85 assert fraction(x) == (x, 1)
86 assert fraction(1/x) == (1, x)
87 assert fraction(x/y) == (x, y)
88 assert fraction(x/2) == (x, 2)
90 assert fraction(x*y/z) == (x*y, z)
91 assert fraction(x/(y*z)) == (x, y*z)
93 assert fraction(1/y**2) == (1, y**2)
94 assert fraction(x/y**2) == (x, y**2)
96 assert fraction((x**2+1)/y) == (x**2+1, y)
97 assert fraction(x*(y+1)/y**7) == (x*(y+1), y**7)
99 assert fraction(exp(-x), exact=True) == (exp(-x), 1)
101 def test_together():
102 x, y, z = map(Symbol, 'xyz')
104 assert together(1/x) == 1/x
106 assert together(1/x + 1) == (x+1)/x
107 assert together(1/x + x) == (x**2+1)/x
109 assert together(1/x + Rational(1, 2)) == (x+2)/(2*x)
111 assert together(1/x + 2/y) == (2*x+y)/(y*x)
112 assert together(1/(1 + 1/x)) == x/(1+x)
113 assert together(x/(1 + 1/x)) == x**2/(1+x)
115 assert together(1/x + 1/y + 1/z) == (x*y + x*z + y*z)/(x*y*z)
117 assert together(1/(x*y) + 1/(x*y)**2) == y**(-2)*x**(-2)*(1+x*y)
118 assert together(1/(x*y) + 1/(x*y)**4) == y**(-4)*x**(-4)*(1+x**3*y**3)
119 assert together(1/(x**7*y) + 1/(x*y)**4) == y**(-4)*x**(-7)*(x**3+y**3)
121 assert together(sin(1/x+1/y)) == sin(1/x+1/y)
122 assert together(sin(1/x+1/y), deep=True) == sin((x+y)/(x*y))
124 assert together(Rational(1,2) + x/2) == (x+1)/2
126 def test_separate():
127 x, y, z = map(Symbol, 'xyz')
129 assert separate((x*y*z)**4) == x**4*y**4*z**4
130 assert separate((x*y*z)**x) == x**x*y**x*z**x
131 assert separate((x*(y*z)**2)**3) == x**3*y**6*z**6
133 assert separate((sin((x*y)**2)*y)**z) == sin((x*y)**2)**z*y**z
134 assert separate((sin((x*y)**2)*y)**z, deep=True) == sin(x**2*y**2)**z*y**z
136 assert separate(exp(x)**2) == exp(2*x)
137 assert separate((exp(x)*exp(y))**2) == exp(2*x)*exp(2*y)
139 assert separate((exp((x*y)**z)*exp(y))**2) == exp(2*(x*y)**z)*exp(2*y)
140 assert separate((exp((x*y)**z)*exp(y))**2, deep=True) == exp(2*x**z*y**z)*exp(2*y)
142 @XFAIL
143 def test_separate_X1():
144 assert separate((exp(x)*exp(y))**z) == exp(x*z)*exp(y*z)
146 def test_powsimp():
147 x,y,n = symbols('xyn')
148 assert powsimp( y**n * (y/x)**(-n) ) == x**n
149 assert powsimp( 4**x * 2**(-x) * 2**(-x) ) == 1
150 assert powsimp( (-4)**x * (-2)**(-x) * 2**(-x) ) == 1
152 def test_collect():
153 x,y,n = symbols('xyn')
154 assert collect(2*x**2 + y*x**2 + 3*x*y, [x]) == x**2*(2+y) + 3*x*y
155 assert collect(2*x**2 + y*x**2 + 3*x*y, [y]) == 2*x**2 + y*(x**2+3*x)
157 def test_hypersimp():
158 n, k = symbols('nk', integer=True)
160 assert hypersimp(factorial(k), k) == k + 1
161 assert hypersimp(factorial(k**2), k) is None
163 assert hypersimp(2**k/factorial(k)**2, k) == 2/(k+1)**2
165 assert hypersimp(binomial(n, k), k) == (n-k)/(k+1)
166 assert hypersimp(binomial(n+1, k), k) == (n-k+1)/(k+1)
168 term = (4*k+1)*factorial(k)/factorial(2*k+1)
169 assert hypersimp(term, k) == (4*k + 5)/(6 + 16*k**2 + 28*k)
171 term = 1/((2*k-1)*factorial(2*k+1))
172 assert hypersimp(term, k) == (2*k-1)/(2*k+1)/(2*k+2)/(2*k+3)
174 term = binomial(n, k)*(-1)**k/factorial(k)
175 assert hypersimp(term, k) == (k - n)/(k+1)**2