def test_pow_invpow(): assert cse(1/x**2 + x**2) == \ ([(x0, x**2)], [x0 + 1/x0]) assert cse(x**2 + (1 + 1/x**2)/x**2) == \ ([(x0, x**2), (x1, 1/x0)], [x0 + x1*(x1 + 1)]) assert cse(1/x**2 + (1 + 1/x**2)*x**2) == \ ([(x0, x**2), (x1, 1/x0)], [x0*(x1 + 1) + x1]) assert cse(cos(1/x**2) + sin(1/x**2)) == \ ([(x0, x**(-2))], [sin(x0) + cos(x0)]) assert cse(cos(x**2) + sin(x**2)) == \ ([(x0, x**2)], [sin(x0) + cos(x0)]) assert cse(y/(2 + x**2) + z/x**2/y) == \ ([(x0, x**2)], [y/(x0 + 2) + z/(x0*y)]) assert cse(exp(x**2) + x**2*cos(1/x**2)) == \ ([(x0, x**2)], [x0*cos(1/x0) + exp(x0)]) assert cse((1 + 1/x**2)/x**2) == \ ([(x0, x**(-2))], [x0*(x0 + 1)]) assert cse(x**(2*y) + x**(-2*y)) == \ ([(x0, x**(2*y))], [x0 + 1/x0])
def test_symbols_exhausted_error(): l = cos(x+y)+x+y+cos(w+y)+sin(w+y) sym = [x, y, z] with pytest.raises(ValueError): print(cse(l, symbols=sym))
def test_name_conflict_cust_symbols(): z1 = x0 + y z2 = x2 + x3 l = [cos(z1) + z1, cos(z2) + z2, x0 + x2] substs, reduced = cse(l, symbols("x:10")) assert [e.subs(dict(substs)) for e in reduced] == l
def test_name_conflict(): z1 = x0 + y z2 = x2 + x3 l = [cos(z1) + z1, cos(z2) + z2, x0 + x2] substs, reduced = cse(l) assert [e.subs(dict(substs)) for e in reduced] == l
def test_symbols_exhausted_error(): l_ = cos(x+y)+x+y+cos(w+y)+sin(w+y) sym = [x, y, z] with pytest.raises(ValueError): print(cse(l_, symbols=sym))
def test_name_conflict_cust_symbols(): z1 = x0 + y z2 = x2 + x3 l_ = [cos(z1) + z1, cos(z2) + z2, x0 + x2] substs, reduced = cse(l_, symbols("x:10")) assert [e.subs(dict(substs)) for e in reduced] == l_
def test_name_conflict(): z1 = x0 + y z2 = x2 + x3 l_ = [cos(z1) + z1, cos(z2) + z2, x0 + x2] substs, reduced = cse(l_) assert [e.subs(dict(substs)) for e in reduced] == l_