def test_as_sum_raises(): e = Integral((x + y)**2, (x, 0, 1)) raises(ValueError, lambda: e.as_sum(-1)) raises(ValueError, lambda: e.as_sum(0)) raises(ValueError, lambda: Integral(x).as_sum(3)) raises(NotImplementedError, lambda: e.as_sum(oo)) raises(NotImplementedError, lambda: e.as_sum(3, method='xxxx2'))
def test_as_sum_right(): e = Integral((x + y)**2, (x, 0, 1)) assert e.as_sum(1, method="right").expand() == 1 + 2*y + y**2 assert e.as_sum(2, method="right").expand() == S(5)/8 + 3*y/2 + y**2 assert e.as_sum(3, method="right").expand() == S(14)/27 + 4*y/3 + y**2 assert e.as_sum(4, method="right").expand() == S(15)/32 + 5*y/4 + y**2 assert e.as_sum(n, method="right").expand() == \ y**2 + y + S(1)/3 + y/n + 1/(2*n) + 1/(6*n**2)
def test_as_sum_right(): e = Integral((x + y)**2, (x, 0, 1)) assert e.as_sum(1, method="right").expand() == 1 + 2 * y + y**2 assert e.as_sum(2, method="right").expand() == S(5) / 8 + 3 * y / 2 + y**2 assert e.as_sum(3, method="right").expand() == S(14) / 27 + 4 * y / 3 + y**2 assert e.as_sum(4, method="right").expand() == S(15) / 32 + 5 * y / 4 + y**2
def test_as_sum_trapezoid(): e = Integral((x + y)**2, (x, 0, 1)) assert e.as_sum(1, method="trapezoid").expand() == y**2 + y + S(1)/2 assert e.as_sum(2, method="trapezoid").expand() == y**2 + y + S(3)/8 assert e.as_sum(3, method="trapezoid").expand() == y**2 + y + S(19)/54 assert e.as_sum(4, method="trapezoid").expand() == y**2 + y + S(11)/32 assert e.as_sum(n, method="trapezoid").expand() == \ y**2 + y + S(1)/3 + 1/(6*n**2) assert Integral(sign(x), (x, 0, 1)).as_sum(1, 'trapezoid') == S(1)/2
def test_as_sum_left(): e = Integral((x + y)**2, (x, 0, 1)) assert e.as_sum(1, method="left").expand() == y**2 assert e.as_sum(2, method="left").expand() == S(1)/8 + y/2 + y**2 assert e.as_sum(3, method="left").expand() == S(5)/27 + 2*y/3 + y**2 assert e.as_sum(4, method="left").expand() == S(7)/32 + 3*y/4 + y**2 assert e.as_sum(n, method="left").expand() == \ y**2 + y + S(1)/3 - y/n - 1/(2*n) + 1/(6*n**2) assert e.as_sum(10, method="left", evaluate=False).has(Sum)
def test_as_sum_midpoint2(): e = Integral((x + y)**2, (x, 0, 1)) n = Symbol('n', positive=True, integer=True) assert e.as_sum(1, method="midpoint").expand() == S(1)/4 + y + y**2 assert e.as_sum(2, method="midpoint").expand() == S(5)/16 + y + y**2 assert e.as_sum(3, method="midpoint").expand() == S(35)/108 + y + y**2 assert e.as_sum(4, method="midpoint").expand() == S(21)/64 + y + y**2 assert e.as_sum(n, method="midpoint").expand() == \ y**2 + y + 1/3 - 1/(12*n**2)
def test_as_sum_midpoint1(): e = Integral(sqrt(x ** 3 + 1), (x, 2, 10)) assert e.as_sum(1, method="midpoint") == 8 * sqrt(217) assert e.as_sum(2, method="midpoint") == 4 * sqrt(65) + 12 * sqrt(57) assert e.as_sum(3, method="midpoint") == 8 * sqrt(217) / 3 + 8 * sqrt(3081) / 27 + 8 * sqrt(52809) / 27 assert e.as_sum(4, method="midpoint") == 2 * sqrt(730) + 4 * sqrt(7) + 4 * sqrt(86) + 6 * sqrt(14) assert abs(e.as_sum(4, method="midpoint").n() - e.n()) < 0.5 e = Integral(sqrt(x ** 3 + y ** 3), (x, 2, 10), (y, 0, 10)) raises(NotImplementedError, "e.as_sum(4)")
def test_as_sum_midpoint1(): e = Integral(sqrt(x**3 + 1), (x, 2, 10)) assert e.as_sum(1, method="midpoint") == 8 * sqrt(217) assert e.as_sum(2, method="midpoint") == 4 * sqrt(65) + 12 * sqrt(57) assert e.as_sum(3, method="midpoint") == 8*sqrt(217)/3 + \ 8*sqrt(3081)/27 + 8*sqrt(52809)/27 assert e.as_sum(4, method="midpoint") == 2*sqrt(730) + \ 4*sqrt(7) + 4*sqrt(86) + 6*sqrt(14) assert abs(e.as_sum(4, method="midpoint").n() - e.n()) < 0.5 e = Integral(sqrt(x**3 + y**3), (x, 2, 10), (y, 0, 10)) raises(NotImplementedError, lambda: e.as_sum(4))
def test_as_sum_midpoint1(): e = Integral(sqrt(x**3+1), (x, 2, 10)) assert e.as_sum(1, method="midpoint") == 8*217**(S(1)/2) assert e.as_sum(2, method="midpoint") == 4*65**(S(1)/2) + 12*57**(S(1)/2) assert e.as_sum(3, method="midpoint") == 8*217**(S(1)/2)/3 + \ 8*3081**(S(1)/2)/27 + 8*52809**(S(1)/2)/27 assert e.as_sum(4, method="midpoint") == 2*730**(S(1)/2) + \ 4*7**(S(1)/2) + 4*86**(S(1)/2) + 6*14**(S(1)/2) assert abs(e.as_sum(4, method="midpoint").n() - e.n()) < 0.5 e = Integral(sqrt(x**3+y**3), (x, 2, 10), (y, 0, 10)) raises(NotImplementedError, "e.as_sum(4)")
def test_as_sum_left(): e = Integral((x + y)**2, (x, 0, 1)) assert e.as_sum(1, method="left").expand() == y**2 assert e.as_sum(2, method="left").expand() == S(1) / 8 + y / 2 + y**2 assert e.as_sum(3, method="left").expand() == S(5) / 27 + 2 * y / 3 + y**2 assert e.as_sum(4, method="left").expand() == S(7) / 32 + 3 * y / 4 + y**2
def test_as_sum_midpoint2(): e = Integral((x + y)**2, (x, 0, 1)) assert e.as_sum(1, method="midpoint").expand() == S(1) / 4 + y + y**2 assert e.as_sum(2, method="midpoint").expand() == S(5) / 16 + y + y**2 assert e.as_sum(3, method="midpoint").expand() == S(35) / 108 + y + y**2 assert e.as_sum(4, method="midpoint").expand() == S(21) / 64 + y + y**2
def test_as_sum_left(): e = Integral((x + y)**2, (x, 0, 1)) assert e.as_sum(1, method="left").expand() == y**2 assert e.as_sum(2, method="left").expand() == S(1)/8 + y/2 + y**2 assert e.as_sum(3, method="left").expand() == S(5)/27 + 2*y/3 + y**2 assert e.as_sum(4, method="left").expand() == S(7)/32 + 3*y/4 + y**2
def test_as_sum_midpoint2(): e = Integral((x + y)**2, (x, 0, 1)) assert e.as_sum(1, method="midpoint").expand() == S(1)/4 + y + y**2 assert e.as_sum(2, method="midpoint").expand() == S(5)/16 + y + y**2 assert e.as_sum(3, method="midpoint").expand() == S(35)/108 + y + y**2 assert e.as_sum(4, method="midpoint").expand() == S(21)/64 + y + y**2