def test_transform(): a = Integral(x**2 + 1, (x, -1, 2)) fx = x fy = 3 * y + 1 assert a.doit() == a.transform(fx, fy).doit() assert a.transform(fx, fy).transform(fy, fx) == a fx = 3 * x + 1 fy = y assert a.transform(fx, fy).transform(fy, fx) == a a = Integral(sin(1 / x), (x, 0, 1)) assert a.transform(x, 1 / y) == Integral(sin(y) / y**2, (y, 1, oo)) assert a.transform(x, 1 / y).transform(y, 1 / x) == a a = Integral(exp(-x**2), (x, -oo, oo)) assert a.transform(x, 2 * y) == Integral(2 * exp(-4 * y**2), (y, -oo, oo)) # < 3 arg limit handled properly assert Integral(x, x).transform(x, a*y).doit() == \ Integral(y*a**2, y).doit() assert Integral(x, (x, 0, -3)).transform(x, 1/y).doit() == \ Integral(-1/x**3, (x, -oo, Rational(-1, 3))).doit() assert Integral(x, (x, 0, 3)).transform(x, 1/y) == \ Integral(y**(-3), (y, Rational(1, 3), oo)) # issue sympy/sympy#8400 i = Integral(x + y, (x, 1, 2), (y, 1, 2)) assert i.transform(x, (x + 2*y, x)).doit() == \ i.transform(x, (x + 2*z, x)).doit() == 3
def test_transform(): a = Integral(x**2 + 1, (x, -1, 2)) fx = x fy = 3*y + 1 assert a.doit() == a.transform(fx, fy).doit() assert a.transform(fx, fy).transform(fy, fx) == a fx = 3*x + 1 fy = y assert a.transform(fx, fy).transform(fy, fx) == a a = Integral(sin(1/x), (x, 0, 1)) assert a.transform(x, 1/y) == Integral(sin(y)/y**2, (y, 1, oo)) assert a.transform(x, 1/y).transform(y, 1/x) == a a = Integral(exp(-x**2), (x, -oo, oo)) assert a.transform(x, 2*y) == Integral(2*exp(-4*y**2), (y, -oo, oo)) # < 3 arg limit handled properly assert Integral(x, x).transform(x, a*y).doit() == \ Integral(y*a**2, y).doit() assert Integral(x, (x, 0, -3)).transform(x, 1/y).doit() == \ Integral(-1/x**3, (x, -oo, Rational(-1, 3))).doit() assert Integral(x, (x, 0, 3)).transform(x, 1/y) == \ Integral(y**(-3), (y, Rational(1, 3), oo)) # issue sympy/sympy#8400 i = Integral(x + y, (x, 1, 2), (y, 1, 2)) assert i.transform(x, (x + 2*y, x)).doit() == \ i.transform(x, (x + 2*z, x)).doit() == 3
def test_sympyissue_21651(): a = Sum(floor(2 * 2**-n), (n, 1, 2)) b = floor(2 * 2**-1) + floor(2 * 2**-2) assert a.doit() == b.doit() c = Sum(ceiling(2 * 2**-n), (n, 1, 2)) d = ceiling(2 * 2**-1) + ceiling(2 * 2**-2) assert c.doit() == d.doit()
def test_transform(): a = Integral(x**2 + 1, (x, -1, 2)) fx = x fy = 3*y + 1 assert a.doit() == a.transform(fx, fy).doit() assert a.transform(fx, fy).transform(fy, fx) == a fx = 3*x + 1 fy = y assert a.transform(fx, fy).transform(fy, fx) == a a = Integral(sin(1/x), (x, 0, 1)) assert a.transform(x, 1/y) == Integral(sin(y)/y**2, (y, 1, oo)) assert a.transform(x, 1/y).transform(y, 1/x) == a a = Integral(exp(-x**2), (x, -oo, oo)) assert a.transform(x, 2*y) == Integral(2*exp(-4*y**2), (y, -oo, oo)) # < 3 arg limit handled properly assert Integral(x, x).transform(x, a*y).doit() == \ Integral(y*a**2, y).doit() assert Integral(x, (x, 0, -3)).transform(x, 1/y).doit() == \ Integral(-1/x**3, (x, -oo, Rational(-1, 3))).doit() assert Integral(x, (x, 0, 3)).transform(x, 1/y) == \ Integral(y**(-3), (y, Rational(1, 3), oo)) # issue sympy/sympy#8400 i = Integral(x + y, (x, 1, 2), (y, 1, 2)) assert i.transform(x, (x + 2*y, x)).doit() == \ i.transform(x, (x + 2*z, x)).doit() == 3 assert a.transform(b, x) == a assert a.transform(x, y) == Integral(exp(-y**2), (y, -oo, oo)) i2 = Integral(cos(x**2 - 1), (x, 0, y)) i = i2.subs({y: 1}) pytest.raises(ValueError, lambda: i.transform(x**2 - 1, y)) pytest.raises(ValueError, lambda: i.transform(x, y*z)) pytest.raises(ValueError, lambda: i.transform(x, (y, y + z))) pytest.raises(ValueError, lambda: i2.transform(x, (z*y, y))) pytest.raises(ValueError, lambda: i.transform(x, (sin(y), y)))