def test_inversion(): R, x = ring('x', QQ) p = 2 + x + 2 * x**2 n = 5 p1 = rs_series_inversion(p, x, n) assert rs_trunc(p * p1, x, n) == 1 R, x, y = ring('x, y', QQ) p = 2 + x + 2 * x**2 + y * x + x**2 * y p1 = rs_series_inversion(p, x, n) assert rs_trunc(p * p1, x, n) == 1 R, x, y = ring('x, y', QQ) p = 1 + x + y raises(NotImplementedError, lambda: rs_series_inversion(p, x, 4)) p = R.zero raises(ZeroDivisionError, lambda: rs_series_inversion(p, x, 3))
def test_log(): R, x = ring('x', QQ) p = 1 + x p1 = rs_log(p, x, 4) / x**2 assert p1 == Rational(1, 3) * x - S.Half + x**(-1) p = 1 + x + 2 * x**2 / 3 p1 = rs_log(p, x, 9) assert p1 == -17*x**8/648 + 13*x**7/189 - 11*x**6/162 - x**5/45 + \ 7*x**4/36 - x**3/3 + x**2/6 + x p2 = rs_series_inversion(p, x, 9) p3 = rs_log(p2, x, 9) assert p3 == -p1 R, x, y = ring('x, y', QQ) p = 1 + x + 2 * y * x**2 p1 = rs_log(p, x, 6) assert p1 == (4 * x**5 * y**2 - 2 * x**5 * y - 2 * x**4 * y**2 + x**5 / 5 + 2 * x**4 * y - x**4 / 4 - 2 * x**3 * y + x**3 / 3 + 2 * x**2 * y - x**2 / 2 + x) # Constant term in series a = symbols('a') R, x, y = ring('x, y', EX) assert rs_log(x + a, x, 5) == -EX(1/(4*a**4))*x**4 + EX(1/(3*a**3))*x**3 \ - EX(1/(2*a**2))*x**2 + EX(1/a)*x + EX(log(a)) assert rs_log(x + x**2*y + a, x, 4) == -EX(a**(-2))*x**3*y + \ EX(1/(3*a**3))*x**3 + EX(1/a)*x**2*y - EX(1/(2*a**2))*x**2 + \ EX(1/a)*x + EX(log(a)) p = x + x**2 + 3 assert rs_log(p, x, 10).compose( x, 5) == EX(log(3) + Rational(19281291595, 9920232))
def test_exp(): R, x = ring('x', QQ) p = x + x**4 for h in [10, 30]: q = rs_series_inversion(1 + p, x, h) - 1 p1 = rs_exp(q, x, h) q1 = rs_log(p1, x, h) assert q1 == q p1 = rs_exp(p, x, 30) assert p1.coeff(x**29) == QQ(74274246775059676726972369, 353670479749588078181744640000) prec = 21 p = rs_log(1 + x, x, prec) p1 = rs_exp(p, x, prec) assert p1 == x + 1 # Constant term in series a = symbols('a') R, x, y = ring('x, y', QQ[exp(a), a]) assert rs_exp(x + a, x, 5) == exp(a)*x**4/24 + exp(a)*x**3/6 + \ exp(a)*x**2/2 + exp(a)*x + exp(a) assert rs_exp(x + x**2*y + a, x, 5) == exp(a)*x**4*y**2/2 + \ exp(a)*x**4*y/2 + exp(a)*x**4/24 + exp(a)*x**3*y + \ exp(a)*x**3/6 + exp(a)*x**2*y + exp(a)*x**2/2 + exp(a)*x + exp(a) R, x, y = ring('x, y', EX) assert rs_exp(x + a, x, 5) == EX(exp(a)/24)*x**4 + EX(exp(a)/6)*x**3 + \ EX(exp(a)/2)*x**2 + EX(exp(a))*x + EX(exp(a)) assert rs_exp(x + x**2*y + a, x, 5) == EX(exp(a)/2)*x**4*y**2 + \ EX(exp(a)/2)*x**4*y + EX(exp(a)/24)*x**4 + EX(exp(a))*x**3*y + \ EX(exp(a)/6)*x**3 + EX(exp(a))*x**2*y + EX(exp(a)/2)*x**2 + \ EX(exp(a))*x + EX(exp(a))
def test_inversion(): R, x = ring('x', QQ) p = 2 + x + 2*x**2 n = 5 p1 = rs_series_inversion(p, x, n) assert rs_trunc(p*p1, x, n) == 1 R, x, y = ring('x, y', QQ) p = 2 + x + 2*x**2 + y*x + x**2*y p1 = rs_series_inversion(p, x, n) assert rs_trunc(p*p1, x, n) == 1 R, x, y = ring('x, y', QQ) p = 1 + x + y def test2(p): p1 = rs_series_inversion(p, x, 4) raises(NotImplementedError, lambda: test2(p))
def test_log(): R, x = ring('x', QQ) p = 1 + x p1 = rs_log(p, x, 4)/x**2 assert p1 == S(1)/3*x - S(1)/2 + x**(-1) p = 1 + x +2*x**2/3 p1 = rs_log(p, x, 9) assert p1 == -17*x**8/648 + 13*x**7/189 - 11*x**6/162 - x**5/45 + \ 7*x**4/36 - x**3/3 + x**2/6 + x p2 = rs_series_inversion(p, x, 9) p3 = rs_log(p2, x, 9) assert p3 == -p1 R, x, y = ring('x, y', QQ) p = 1 + x + 2*y*x**2 p1 = rs_log(p, x, 6) assert p1 == (4*x**5*y**2 - 2*x**5*y - 2*x**4*y**2 + x**5/5 + 2*x**4*y - x**4/4 - 2*x**3*y + x**3/3 + 2*x**2*y - x**2/2 + x) # Constant term in series a = symbols('a') R, x, y = ring('x, y', EX) assert rs_log(x + a, x, 5) == -EX(1/(4*a**4))*x**4 + EX(1/(3*a**3))*x**3 \ - EX(1/(2*a**2))*x**2 + EX(1/a)*x + EX(log(a)) assert rs_log(x + x**2*y + a, x, 4) == -EX(a**(-2))*x**3*y + \ EX(1/(3*a**3))*x**3 + EX(1/a)*x**2*y - EX(1/(2*a**2))*x**2 + \ EX(1/a)*x + EX(log(a)) p = x + x**2 + 3 assert rs_log(p, x, 10).compose(x, 5) == EX(log(3) + S(19281291595)/9920232)
def test_exp(): R, x = ring('x', QQ) p = x + x**4 for h in [10, 30]: q = rs_series_inversion(1 + p, x, h) - 1 p1 = rs_exp(q, x, h) q1 = rs_log(p1, x, h) assert q1 == q p1 = rs_exp(p, x, 30) assert p1.coeff(x**29) == QQ(74274246775059676726972369, 353670479749588078181744640000) prec = 21 p = rs_log(1 + x, x, prec) p1 = rs_exp(p, x, prec) assert p1 == x + 1
def test_log(): R, x = ring('x', QQ) p = 1 + x p1 = rs_log(p, x, 4) assert p1 == x - x**2/2 + x**3/3 p = 1 + x +2*x**2/3 p1 = rs_log(p, x, 9) assert p1 == -17*x**8/648 + 13*x**7/189 - 11*x**6/162 - x**5/45 + \ 7*x**4/36 - x**3/3 + x**2/6 + x p2 = rs_series_inversion(p, x, 9) p3 = rs_log(p2, x, 9) assert p3 == -p1 R, x, y = ring('x, y', QQ) p = 1 + x + 2*y*x**2 p1 = rs_log(p, x, 6) assert p1 == (4*x**5*y**2 - 2*x**5*y - 2*x**4*y**2 + x**5/5 + 2*x**4*y - x**4/4 - 2*x**3*y + x**3/3 + 2*x**2*y - x**2/2 + x)
def test_puiseux(): R, x, y = ring('x, y', QQ) p = x**QQ(2,5) + x**QQ(2,3) + x r = rs_series_inversion(p, x, 1) r1 = -x**QQ(14,15) + x**QQ(4,5) - 3*x**QQ(11,15) + x**QQ(2,3) + \ 2*x**QQ(7,15) - x**QQ(2,5) - x**QQ(1,5) + x**QQ(2,15) - x**QQ(-2,15) \ + x**QQ(-2,5) assert r == r1 r = rs_nth_root(1 + p, 3, x, 1) assert r == -x**QQ(4,5)/9 + x**QQ(2,3)/3 + x**QQ(2,5)/3 + 1 r = rs_log(1 + p, x, 1) assert r == -x**QQ(4,5)/2 + x**QQ(2,3) + x**QQ(2,5) r = rs_LambertW(p, x, 1) assert r == -x**QQ(4,5) + x**QQ(2,3) + x**QQ(2,5) p1 = x + x**QQ(1,5)*y r = rs_exp(p1, x, 1) assert r == x**QQ(4,5)*y**4/24 + x**QQ(3,5)*y**3/6 + x**QQ(2,5)*y**2/2 + \ x**QQ(1,5)*y + 1 r = rs_atan(p, x, 2) assert r == -x**QQ(9,5) - x**QQ(26,15) - x**QQ(22,15) - x**QQ(6,5)/3 + \ x + x**QQ(2,3) + x**QQ(2,5) r = rs_atan(p1, x, 2) assert r == x**QQ(9,5)*y**9/9 + x**QQ(9,5)*y**4 - x**QQ(7,5)*y**7/7 - \ x**QQ(7,5)*y**2 + x*y**5/5 + x - x**QQ(3,5)*y**3/3 + x**QQ(1,5)*y r = rs_asin(p, x, 2) assert r == x**QQ(9,5)/2 + x**QQ(26,15)/2 + x**QQ(22,15)/2 + \ x**QQ(6,5)/6 + x + x**QQ(2,3) + x**QQ(2,5) r = rs_cot(p, x, 1) assert r == -x**QQ(14,15) + x**QQ(4,5) - 3*x**QQ(11,15) + \ 2*x**QQ(2,3)/3 + 2*x**QQ(7,15) - 4*x**QQ(2,5)/3 - x**QQ(1,5) + \ x**QQ(2,15) - x**QQ(-2,15) + x**QQ(-2,5) r = rs_cos_sin(p, x, 2) assert r[0] == x**QQ(28,15)/6 - x**QQ(5,3) + x**QQ(8,5)/24 - x**QQ(7,5) - \ x**QQ(4,3)/2 - x**QQ(16,15) - x**QQ(4,5)/2 + 1 assert r[1] == -x**QQ(9,5)/2 - x**QQ(26,15)/2 - x**QQ(22,15)/2 - \ x**QQ(6,5)/6 + x + x**QQ(2,3) + x**QQ(2,5) r = rs_atanh(p, x, 2) assert r == x**QQ(9,5) + x**QQ(26,15) + x**QQ(22,15) + x**QQ(6,5)/3 + x + \ x**QQ(2,3) + x**QQ(2,5) r = rs_sinh(p, x, 2) assert r == x**QQ(9,5)/2 + x**QQ(26,15)/2 + x**QQ(22,15)/2 + \ x**QQ(6,5)/6 + x + x**QQ(2,3) + x**QQ(2,5) r = rs_cosh(p, x, 2) assert r == x**QQ(28,15)/6 + x**QQ(5,3) + x**QQ(8,5)/24 + x**QQ(7,5) + \ x**QQ(4,3)/2 + x**QQ(16,15) + x**QQ(4,5)/2 + 1 r = rs_tanh(p, x, 2) assert r == -x**QQ(9,5) - x**QQ(26,15) - x**QQ(22,15) - x**QQ(6,5)/3 + \ x + x**QQ(2,3) + x**QQ(2,5)
def test3(p): p1 = rs_series_inversion(p, x, 3)
def test2(p): p1 = rs_series_inversion(p, x, 4)
def test_puiseux(): R, x, y = ring('x, y', QQ) p = x**QQ(2, 5) + x**QQ(2, 3) + x r = rs_series_inversion(p, x, 1) r1 = -x**QQ(14,15) + x**QQ(4,5) - 3*x**QQ(11,15) + x**QQ(2,3) + \ 2*x**QQ(7,15) - x**QQ(2,5) - x**QQ(1,5) + x**QQ(2,15) - x**QQ(-2,15) \ + x**QQ(-2,5) assert r == r1 r = rs_nth_root(1 + p, 3, x, 1) assert r == -x**QQ(4, 5) / 9 + x**QQ(2, 3) / 3 + x**QQ(2, 5) / 3 + 1 r = rs_log(1 + p, x, 1) assert r == -x**QQ(4, 5) / 2 + x**QQ(2, 3) + x**QQ(2, 5) r = rs_LambertW(p, x, 1) assert r == -x**QQ(4, 5) + x**QQ(2, 3) + x**QQ(2, 5) p1 = x + x**QQ(1, 5) * y r = rs_exp(p1, x, 1) assert r == x**QQ(4,5)*y**4/24 + x**QQ(3,5)*y**3/6 + x**QQ(2,5)*y**2/2 + \ x**QQ(1,5)*y + 1 r = rs_atan(p, x, 2) assert r == -x**QQ(9,5) - x**QQ(26,15) - x**QQ(22,15) - x**QQ(6,5)/3 + \ x + x**QQ(2,3) + x**QQ(2,5) r = rs_atan(p1, x, 2) assert r == x**QQ(9,5)*y**9/9 + x**QQ(9,5)*y**4 - x**QQ(7,5)*y**7/7 - \ x**QQ(7,5)*y**2 + x*y**5/5 + x - x**QQ(3,5)*y**3/3 + x**QQ(1,5)*y r = rs_asin(p, x, 2) assert r == x**QQ(9,5)/2 + x**QQ(26,15)/2 + x**QQ(22,15)/2 + \ x**QQ(6,5)/6 + x + x**QQ(2,3) + x**QQ(2,5) r = rs_cot(p, x, 1) assert r == -x**QQ(14,15) + x**QQ(4,5) - 3*x**QQ(11,15) + \ 2*x**QQ(2,3)/3 + 2*x**QQ(7,15) - 4*x**QQ(2,5)/3 - x**QQ(1,5) + \ x**QQ(2,15) - x**QQ(-2,15) + x**QQ(-2,5) r = rs_cos_sin(p, x, 2) assert r[0] == x**QQ(28,15)/6 - x**QQ(5,3) + x**QQ(8,5)/24 - x**QQ(7,5) - \ x**QQ(4,3)/2 - x**QQ(16,15) - x**QQ(4,5)/2 + 1 assert r[1] == -x**QQ(9,5)/2 - x**QQ(26,15)/2 - x**QQ(22,15)/2 - \ x**QQ(6,5)/6 + x + x**QQ(2,3) + x**QQ(2,5) r = rs_atanh(p, x, 2) assert r == x**QQ(9,5) + x**QQ(26,15) + x**QQ(22,15) + x**QQ(6,5)/3 + x + \ x**QQ(2,3) + x**QQ(2,5) r = rs_sinh(p, x, 2) assert r == x**QQ(9,5)/2 + x**QQ(26,15)/2 + x**QQ(22,15)/2 + \ x**QQ(6,5)/6 + x + x**QQ(2,3) + x**QQ(2,5) r = rs_cosh(p, x, 2) assert r == x**QQ(28,15)/6 + x**QQ(5,3) + x**QQ(8,5)/24 + x**QQ(7,5) + \ x**QQ(4,3)/2 + x**QQ(16,15) + x**QQ(4,5)/2 + 1 r = rs_tanh(p, x, 2) assert r == -x**QQ(9,5) - x**QQ(26,15) - x**QQ(22,15) - x**QQ(6,5)/3 + \ x + x**QQ(2,3) + x**QQ(2,5)