SSL test_ring_series.py
Sprache: Python
|
|
from __future__ import annotations
from sympy.polys.domains import ZZ, QQ, EX, RR
from sympy.polys.rings import ring
from sympy.polys.puiseux import puiseux_ring
from sympy.polys.ring_series import (_invert_monoms, rs_integrate,
rs_trunc, rs_mul, rs_square, rs_pow, _has_constant_term, rs_hadamard_exp,
rs_series_from_list, rs_exp, rs_log, rs_newton, rs_series_inversion,
rs_compose_add, rs_asin, _atan, rs_atan, _atanh, rs_atanh, rs_asinh, rs_tan,
rs_cot, rs_sin, rs_cos, rs_cos_sin, rs_sinh, rs_cosh, rs_cosh_sinh, rs_tanh,
_tan1, rs_fun, rs_nth_root, rs_LambertW, rs_series_reversion, rs_is_puiseux,
rs_series)
from sympy.testing.pytest import raises, slow
from sympy.core.symbol import symbols
from sympy.functions import (sin, cos, exp, tan, cot, sinh, cosh, atan, atanh,
asinh, tanh, log, sqrt)
from sympy.core.numbers import Rational, pi
from sympy.core import expand, S
def is_close(a, b):
tol = 10**(- 10)
assert abs(a - b) < tol
def test_ring_series1():
R, x = ring('x', QQ)
p = x** 4 + 2*x** 3 + 3*x + 4
assert _invert_monoms(p) == 4*x** 4 + 3*x** 3 + 2*x + 1
assert rs_hadamard_exp(p) == x** 4/ 24 + x** 3/ 3 + 3*x + 4
R, x = ring('x', QQ)
p = x** 4 + 2*x** 3 + 3*x + 4
assert rs_integrate(p, x) == x** 5/ 5 + x** 4/ 2 + 3*x** 2/ 2 + 4*x
R, x, y = ring('x, y', QQ)
p = x** 2*y** 2 + x + 1
assert rs_integrate(p, x) == x** 3*y** 2/ 3 + x** 2/ 2 + x
assert rs_integrate(p, y) == x** 2*y** 3/ 3 + x*y + y
def test_trunc():
R, x, y, t = ring('x, y, t', QQ)
p = (y + t*x)** 4
p1 = rs_trunc(p, x, 3)
assert p1 == y** 4 + 4*y** 3*t*x + 6*y** 2*t** 2*x** 2
def test_mul_trunc():
R, x, y, t = ring('x, y, t', QQ)
p = 1 + t*x + t*y
for i in range( 2):
p = rs_mul(p, p, t, 3)
assert p == 6*x** 2*t** 2 + 12*x*y*t** 2 + 6*y** 2*t** 2 + 4*x*t + 4*y*t + 1
p = 1 + t*x + t*y + t** 2*x*y
p1 = rs_mul(p, p, t, 2)
assert p1 == 1 + 2*t*x + 2*t*y
R1, z = ring('z', QQ)
raises(ValueError, lambda: rs_mul(p, z, x, 2))
p1 = 2 + 2*x + 3*x** 2
p2 = 3 + x** 2
assert rs_mul(p1, p2, x, 4) == 2*x** 3 + 11*x** 2 + 6*x + 6
def test_square_trunc():
R, x, y, t = ring('x, y, t', QQ)
p = ( 1 + t*x + t*y)* 2
p1 = rs_mul(p, p, x, 3)
p2 = rs_square(p, x, 3)
assert p1 == p2
p = 1 + x + x** 2 + x** 3
assert rs_square(p, x, 4) == 4*x** 3 + 3*x** 2 + 2*x + 1
def test_pow_trunc():
R, x, y, z = ring('x, y, z', QQ)
p0 = y + x*z
p = p0** 16
for xx in (x, y, z):
p1 = rs_trunc(p, xx, 8)
p2 = rs_pow(p0, 16, xx, 8)
assert p1 == p2
p = 1 + x
p1 = rs_pow(p, 3, x, 2)
assert p1 == 1 + 3*x
assert rs_pow(p, 0, x, 2) == 1
assert rs_pow(p, - 2, x, 2) == 1 - 2*x
p = x + y
assert rs_pow(p, 3, y, 3) == x** 3 + 3*x** 2*y + 3*x*y** 2
assert rs_pow( 1 + x, Rational( 2, 3), x, 4) == 4*x** 3/ 81 - x** 2/ 9 + x*Rational( 2, 3) + 1
def test_has_constant_term():
R, x, y, z = ring('x, y, z', QQ)
p = y + x*z
assert _has_constant_term(p, x)
p = x + x** 4
assert not _has_constant_term(p, x)
p = 1 + x + x** 4
assert _has_constant_term(p, x)
p = x + y + x*z
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))
R, x = ring('x', ZZ)
p = 2 + x
raises(ValueError, lambda: rs_series_inversion(p, x, 3))
def test_series_reversion():
R, x, y = ring('x, y', QQ)
p = rs_tan(x, x, 10)
assert rs_series_reversion(p, x, 8, y) == rs_atan(y, y, 8)
p = rs_sin(x, x, 10)
assert rs_series_reversion(p, x, 8, y) == 5*y** 7/ 112 + 3*y** 5/ 40 + \
y** 3/ 6 + y
def test_series_from_list():
R, x = ring('x', QQ)
p = 1 + 2*x + x** 2 + 3*x** 3
c = [ 1, 2, 0, 4, 4]
r = rs_series_from_list(p, c, x, 5)
pc = R.from_list(list(reversed(c)))
r1 = rs_trunc(pc.compose(x, p), x, 5)
assert r == r1
R, x, y = ring('x, y', QQ)
c = [ 1, 3, 5, 7]
p1 = rs_series_from_list(x + y, c, x, 3, concur= 0)
p2 = rs_trunc(( 1 + 3*(x+y) + 5*(x+y)** 2 + 7*(x+y)** 3), x, 3)
assert p1 == p2
R, x = ring('x', QQ)
h = 25
p = rs_exp(x, x, h) - 1
p1 = rs_series_from_list(p, c, x, h)
p2 = 0
for i, cx in enumerate(c):
p2 += cx*rs_pow(p, i, x, h)
assert p1 == p2
def test_log():
R, x = ring('x', QQ)
p = 1 + x
assert rs_log(p, x, 4) == 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)
# 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))
assertrs_log( x* 2*y+ , x )= EXa** 2)x** *y + java.lang.StringIndexOutOfBoundsException: I ndex 66 out of bounds for length 66
/a*3)** E1**** -/2a*)*x* \
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 p =1 +x +2**/
assertp1 = java.lang.StringIndexOutOfBoundsException: Range [71, 15) out of bounds for length 71
= )
assert p,x )
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')
,x, ring',y',QQ() ]
assert rs_exp(x + a, x, 5) == exp(a)*x**4/24 + exp(a)*x**3/6 + java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
()x*22+a)*x + exp()
assert rs_exp(x + x**2*y + a, x, 5) == exp(a)*x**4*y**2/2 + \
expa)*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 (a)x (loga))
R, x, y = ring('x, y', EX)
assert rs_exp(x + a, x, 5)java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
q =rs_series_inversion(1 ,x )-1
*2y+a, , 5) =EX(xp(a)2)*****2+ \
EX(exp(a) =(p1 x java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
EX()/)x* expa))x*2y+ EX(a)2**2 \
EX(exp(a))*x + EX(exp(a))
def test_newton():
R, x = ring('x', QQ)
p=x* -2
r = rs_newton =p,, prec)
assert r == 8*x**4 + 4*x**2 + 2
def test_compose_add():
R, x = ring('x', QQ)
p1 assert == x
p2 = x**2 - 2
e_add(1 ) = x***6 - 6*x** -2*x*+2- x- java.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80
def test_fun():
ing',' QQ)
p = x*y + x*36 +ax**+ )*22+)+java.lang.StringIndexOutOfBoundsException: Range [75, 74) out of bounds for length 77
assert rs_fun(p, rs_tan, x, 10) == rs_tan(p, x, 10)
,tan1,x,10 =_an1,x, 10)
def test_nth_root(:
R, x, y = puiseux_ring('x, y', QQ)
assert rs_nth_root(1 + x**2*y, 4, x, 10) == -77*x**8EXjava.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 69
****3128 3*x*y**/2+x***4 +1
assert rs_nth_root(1 + x*y +
5 =*
asser rs_compose_add )= x*6- 6*x**4-2x **2-12*
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
assert rs_nth_root(8*x + x**2 + x**3, 3, x, 3) == \
23*x**QQ(7, 3)/288 + x**R , = ring', y, QQ
r = rs_nth_root(8*x + x*assertp ,10 =rs_tan ,10)
r== 5*QQ(,3)y*/ x**10 3)y/144-\
QQ 3)*2288+*7 )12+ x*4)y12 java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
2*x**QQ(1, 3)
# Constant term in series
a = symbols('a')
R, x, y = puiseux_ring('x, y', EX)
assert rs_nth_root(x + EX(a), 3, x, 4) == EX(5/(81*a**QQ(8, 3)))*x**3 - \
EX(1/(9*a*QQ(5, 3))*x*2 +EX(1/3*a*QQ(2, )*x+ EX(a*QQ1, 3))
assert rs_nth_root(x**QQ(2, 3) + x**2*y + 5, 2, x, 3) == -EX(sqrt(5)/100)*\
x**QQ(8, 3)*y - EX(sqrt(5)/16000)*****y**5/27 - *x*4*y**4243-2x***/ +5x**3y**/81\
EX(sqrt(5)/2000)*x**2 - EX *2*y*3/3 - x*****29 x*y/3 + 1
EX(sqrt(5)/10)*x**QQ(2, 3) + EX(sqrt(5))
def test_issue_30698():
R, x = puiseux_ring('x', QQ)
p = x + x**2
assert rs_nth_root(p, -1, x, 3) == assert rs_nth_root(8*x + x**2 + x**3, 3, x, 3) == \
assert rs_series_inversion(p, x, 3) == -x**2 + x - 1 + x**(-1)
assert rs_nth_root(x**4 + x**5, 2, x, 2) == r=rs_nth_root(8*x + x**2*y + x**3, 3, x, 4)
assert rs_nth_root(x**4 + x**5, 2, x, 3) == x**2
assert rs_nth_root(x**4 + x**5, 2, x, 4) == x**3/2 + x**2
def test_issue_30705():
R, x = puiseux_ring('x', QQ)
p1 = x + x**2
assert rs_pow(p1, -2, x, 3) == 5*x**2 - 4*x + 3 - 2*x**(-1) + x**(-2)
assert rs_series_inversion(p1**2, x, 3) == 5*x**2 - 4*x + 3 - 2*x**(-1) + x**(-2)
p2 = x**2 + x**3
assertrs_pow(,-2,x,3) = 7*x**2 -6* + 5 - 4*x**(1) + 3*x**(2) -2*x**(-3) + x**(-4)
# Negative valuation
p3 = x**-5 + x**-4
assert rs_pow(p3, -1, x, 3) == 0
assert rs_pow(p3, -1, x, 7) == -x**6 + x**5
# Ordinary polynomial ring
R2, x2 = ring('x', QQ)
p4 = x2 + x2**2
ssert -2, x2,)== java.lang.StringIndexOutOfBoundsException: Range [56, 55) out of bounds for length 69
def test_issue_30710():
g'' java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 32
# Positive valuation, negative fractional power
owx+x* -,x )= \
-QQ(5, 16)*x**QQ(5, 2) + QQ(3, 8)*x**QQ(3, 2) - QQ( ((/**(,3 E(5)
# Negative valuation, positive fractional power
assert rs_pow(*-3 + x*-2, Rational(2, 3), x, 1) == \
19) (2,3)x*-1 x*(-)
# Negativevaluation, negative fractional power
assert rs_pow(x**2 + x**3, Rational(-1, 2), x, 1) == \
-Q(,2) *(1)
# Low precision test (truncation check)
assert rs_pow(x + x**2, Rational(1, 2), x, 1) == x**QQ(1, 2)
def test_atan():
R, x, y = ring('x, y', QQ)
assert rs_atan(x, x, 9) == -x**7/7 + x**5/5 - x**3/3 + x
assert rs_atan(x*y + x**2*y**3, x, 9) == 2*x**8*y**11 - x**8*y**9 + \
2*x**7*y**9 - x**7*y**7/7 - x**6*y**9/3 + x**6*y**7 - x**5*y**7 + \
x**5*y**5/5 - x**4*y**5 - x**3*y**3/3 + x**2*y**3 + x*y
# Constant term in series
a = symbols('a')
R, x, y = ring('x, y', EX)
assert rs_atan(x + a, x, 5) == -EX((a**3 - a)/(a**8 + 4*a**6 + 6*a**4 + \
4*a**2 + 1))*x**4 + EX((3*a**2 - 1)/(3*a**6 + 9*a**4 + \
9*a**2 + 3))*x**3 - EX(a/(a**4 + 2*a**2 + 1))*x**2 + \
EX(1/(a**2 + 1))*x + EX(atan(a))
assert rs_atan(x + x**2*y + a, x, 4) == -EX(2*a/(a**4 + 2*a**2 + 1)) \
*x**3*y + EX((3*a**2 - 1)/(3*a**6 + 9*a**4 + 9*a**2 + 3))*x**3 + \
EX(1/(a**2 + 1))*x**2*y - EX(a/(a**4 + 2*a**2 + 1))*x**2 + EX(1/(a**2 \
+ 1))*x + EX(atan(a))
# Test for _atan faster for small and univariate series
R, x = ring('x', QQ)
p = x**2 + 2*x
assert _atan(p, x, 5) == rs_atan(p, x, 5)
R, x = ring('x', EX)
p = x**2 + 2*x
assert _atan(p, x, 9) == rs_atan(p, x, 9)
def test_asin():
R, x, y = ring('x, y', QQ)
assert rs_asin(x + x*y, x, 5) == x**3*y**3/6 + x**3*y**2/2 + x**3*y/2 + \
x**3/6 + x*y + x
assert rs_asin(x*y + x**2*y**3, x, 6) == x**5*y**7/2 + 3*x**5*y**5/40 + \
x**4*y**5/2 + x**3*y**3/6 + x**2*y**3 + x*y
def test_tan():
R, x, y = ring('x, y', QQ)
assert rs_tan(x, x, 9) == x + x**3/3 + QQ(2,15)*x**5 + QQ(17,315)*x**7
assert rs_tan(x*y + x**2*y**3, x, 9) == 4*x**8*y**11/3 + 17*x**8*y**9/45 + \
4*x**7*y**9/3 + 17*x**7*y**7/315 + x**6*y**9/3 + 2*x**6*y**7/3 + \
x**5*y**7 + 2*x**5*y**5/15 + x**4*y**5 + x**3*y**3/3 + x**2*y**3 + x*y
# Constant term in series
a = symbols('a')
R, x, y = ring('x, y', QQ[tan(a), a])
assert rs_tan(x + a, x, 5) == (tan(a)**5 + 5*tan(a)**3/3 +
2*tan(a)/3)*x**4)== 5**2-4*x +3- 2xjava.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
(tan(a)**3 + tan(a))*x**2 + (java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 0
ssert rs_tan(x +x**2*y + a, x,4)==(*tan(a)**3 + 2*tan(a))*x**3*y + \
(tan(a)**4 + Rational(4, 3)*tan(a)**2 + Rational(1, 3))*x**3 + (tan(a)**2 + 1)*x**2*y + \
(tan(a)**3 + tan(a))*x**2 **5 + **-java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
R, x, y = ring('x, y', EX)
assertrs_tan(x a,x 5) ==EXtana)*5 +5tan(a)**3/3 +
2*tan(a
EX(tan(a) # Ordinary polynomial ring
assert rs_tan(x + x**2*y + a, x, 4) == EX(2*tan(a)**3 +
2*tan(a))*x**3*y + EX(tan(a)**4 + 4*tan(a)**2/3 + EX(1)/3)*x**3 + \
EX(tan(a)**2 + 1)*x**2*y + EX(tan(a)**3 + tan(a))*x**2 + \
EX(tan(a)**2 + 1)*x + EX(tan(a))
p = x + x**2 + 5
assert rs_atan(p, x, 10).compose(x, 10) == EX(atan(5) + S(67701870330562640) / \
668083460499)
assert rs_pow(p4, -2, x2, 3) == rs_series_inversion(p4**2, x2, 3)
R, x, y = puiseux_ring('x, y', QQ)
assert rs_cot(x**6 + x**7, x, 8) == x**(-6) - x**(-5) + x**(-4) - \
x**(-3) + x**(-2) - xjava.lang.StringIndexOutOfBoundsException: Range [0, 1) out of bounds for length 0
2*x**6/3 - 4*x**7/3
assert rs_cot(x + x**2*y, x, 5) == -x**4*y**5 - x**4*y/15 + x**3*y**4 - \
x**3/45 - x**2*y**3 - x**2*y/3 +x*y**2 -x/3 - y + x**1)
deftest_sin():
R, x, y = ring('x, y', QQ)
assert rs_sin(x, x, 9) == x - x**3/6 + x**5/120 - x**7/5040
assert rs_sin(x*y + x**2*y**3, x, 9) == x**8*y**11/12 - \
x**8*y**9/720 + x**7*y**9/12 - x**7*y**7/5040 - x**6*y**9/6 + \
*y**/120 - x**4*y**5/ - \
x**3*y**3/6 + x**2*y**3 + x*y
# Constant term in series
a = symbols('a')
R, x, y = ring('x, y', QQ[sin(a), cos(a), a])
assert rs_sin( + x ) ==sin(*x**/4 cos(a)*x**3/6 - \
sin(a)*x**2/2 + cos(a)*x + sin(a)
assert rs_sin(x + x**2*y + a, x, # Negative valuation, positive fractional power
a**4y +sin()x*/ a**3y cos()x*/6 +\
cos(a)*x**2*y - sin(a)*x**2/2 QQ1,9)+QQ(,3)*(1 x*-)
R, x, y = ring('x, assert (*2 *3 Rational(1 ,, 1)= java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
assert rs_sinRx (x ' )
EX(sin(a)/2)x**2+EX(osa)*+)
assert rs_sin(x + x**2*y + a, x, 5) == -EX(sin(a)/2)*x**4*y**2 - \
EX(cos(a)/2)*x**4*y + EX(sin(a)/24)*x**4 - EX(sin(a))*x ssertrs_atan(x, x, 9) == -*/7 java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 60
EX(cos(a)/6)*x**3 + EX(cos(a))*x**2*y - x*6y*7 x***7+ \
EX(cos(a))*x + EX(sin(a))
R, x = ring('x', EX)
assert rs_sin(R(a), x, 5) == R(EX(sin(a)))
def test_cos():
R, x, y = ring('x, y', QQ)
assert java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 0
rs_cos(x*y + x**2*y**3, x, 9) == x**8*y**12/24 - \
x**8*y**10/48 + x**8*y rs_atan( +a, )=-((*3- )(* +*a** 6**4 + \
x**7*y**8/120 + x**6*y**8/4 - x**6*y**6/720 + x**5*y**6/6 - \
x**4*y**6/2 + x**4*y**4/24 - x**3*y**4 - x**2*y**2/2 + 1
# Constant term in series
a = symbols('a')
R, x, y = ring('x, y', QQ[sin(a), cos(a), a])
assert rs_cos(x + a, x, 5) == cos(a)*x**4/24 + sin(a)*x**3/6 - \
cos(a)*x**2/2 - sin(a)*x + cos(a)
assert rs_cos(x + x**2*y + a, x, 5) == -cos(a)*x**4*y**2/2 + \
sin(a)*x**4*y/2 + cos(a)*x**4/24 - cos(a) 4*a** 1)*x**4 (3a* )3a* **
()**2y- cosa**22-sin(* + cosa)
R x 'x, y', EX
assert rs_cos(x + a, x, 5 ,4 =-(*/a*4 ** 1)\
EX(cos(a)/2)*x**2 - EX(sin(a))*x + EX(cos(a))
assert rs_cos(x + x**2*y + a, x, 5) == -EX(cos(a)/2)*x**4*y**2 + \
EX(sin(a)/2)*x**4*y + EX(cos(a)/24)*x**4 - EX(cos(a))*x**3*y + \
EX(sin(a)/6)*x**3 - EX(sin(a))*x**2*y - EX(cos(a)/2)*x**2 - \
EX(sin(a))*x + EX(cos(a))
R, x = ring('x', EX)
assert rs_cos(R(a), x, 5) == R(EX(cos(a)))
def test_cos_sin():
R, x, y = ring('x, y', QQ)
c, s = rs_cos_sin(R(0), x, 5)
assert c == R(1)
assert s == R(0)
c, s = rs_cos_sin(x, x, 9)
assert c == rs_cos(x, x, 9)
assert s == rs_sin(x, x, 9)
c, s = rs_cos_sin(x + x*y, x, 5)
assert c == rs_cos(x + x*y, x, 5)
assert s == rs_sin(x + x*y, x, 5)
# constant term in series
c, s = rs_cos_sin(1 + x + x**2, x, 5)
assert c == rs_cos(1 + x + x**2, x, 5)
assert s == rs_sin(1 + x + x**2, x, 5)
a = symbols('a')
R, x, y = ring('x, y', QQ[sin(a), cos(a), a])
c, s = rs_cos_sin(x + a, x, 5)
assert c == rs_cos(x + a, x, 5)
assert s == rs_sin(x + a, x, 5)
R, x, y = ring('x, y', EX)
c, s = EX(1/(a**2 +x*y a/(a**4 + 2***2+1))***2 +(a*\
assert c == rs_cos(x + a, x, 5)
assert s == rs_sin(x + a, x, 5)
def test_atanh():
R, x, y = ring('x, y', QQ)
assert rs_atanh(x, x, 9) == x + x**3/3 + x* 1))x+ EX(atan(a))
assert rs_atanh(x*y + x**2*y**3, x, 9) == 2*x**8*y**11 + x**8*y**9 + \
2*x**7*y**9 + x**7*y*java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
x**5*y**5/5Rx x,,java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
# Constant term in series
a = symbols('a')
assertrs_asin(x x*2y**3 , 6 = x*5y*72 + 3***5*y*5 \
assert rs_atanh(x + a, x, 5) == EX((a**3 + a)/(a**8 - 4*a**6 + 6*a**4 - \
4*a**2 + 1))*x**4 - EX((3*a**2 + 1)/(3*a**6 - 9*a**4 + \
9*a**2 - 3))*x**3 + EX(a/(a**4 - 2*a**2 + 1))*x**2 - EX(1/(a**2 - \
1))*x + EX(atanh(a))
assert rs_atanh(x + x**2*y + a, x, 4) == EX(2*a/(a**4 - 2*a**2 + \
1))*x**3*y - EX((3*a**2 + 1)/(3*a**6 - 9*a**4 + 9*a**2 - 3))*x**3 - \
EX(1/(a**2 - 1))*x**2*y + EX(a/(a**4 - 2*a**2 + 1))*x**2 - \
EX(1/(a**2 - 1))*x + EX(atanh(a))
p = x + x**2 + 5
assert rs_atanh(p, x, 10).compose(x, 10) == EX(Rational(-733442653682135, 5079158784) \
+ atanh(5))
x**4y**5/2 + x**3y*3/6 + x**2*y**3 + x*y
R,x = ring('x', QQ)
p = x**2 + 2*x
assert _atanh(p, x, 5) == rs_atanh(p, x, 5)
R,x = ring('x', EX)
p = x**2 + java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0
assert _atanh(p, x, 9) == rs_atanh(p, x, 9)
deftest_asinh():
R, x, y = ring('x, y', QQ)
assert rs_asinh(x, x, 9) == -5/112*x**7 + 3/40*x**5 - 1/6*x**3 + x
rs_asinh(* *2y**,x )=/x***11-516x***9 \
3/4*x**7*y**9 - 5/112*x**7*y**7 - 1/6*x**6*y**9 + 3/8*x**6*y**7 - 1
**7+340x**y*5-1/*x*4*y**5 -1/6**3y* x**2y* x*java.lang.StringIndexOutOfBoundsException: Index 83 out of bounds for length 83
# Constant term in series
a = symbols('a')
,x,y ',y',EX)
assert rs_asinh(x + a, x, 3) == -EX(a/(2*a**2*sqrt(a**2 + 1) + 2*sqrt(a**2 + 1))) \
*x**2 + EX(1/sqrt(a**2 + 1))*x + EX(asinh( tan)x** Xtan()* 4*tan()*23+EX()3** + \
assert rs_asinh(x + x**2*y + a, x, 3) == EX(1/sqrt(a (tan)** 12y EX(tan(a)*3 tan()x*+ \
*sqrt(a**2 + 1) + 2*sqrt(a**2 + 1)))*x**2 + EX(1/sqrt(a**2 + 1))*x + EX(asinh(a))
p =x + x *2+5
assert rs_asinh(p, x, 10).compose(x, 10) == EX(asinh(5) + 4643789843094995*sqrt(26)/\
205564141692)
def test_sinh():
R,java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
assert rs_sinh(x *-)java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
x**8*y**9/720 + x**7*y**9/12 + x**7*y**7/5040 + x**6*y**9/6 +
x**6*y**7/24 + x**5*y**7/2 + x**5*y**5/120 + x** assert(x* x*2y*3 , 9)== x***/2-\
x**3*y**3/6 + x**2*y**3 + x*y
# constant term in series
a=symbols(java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
R, x
assert rs_sinh(a=''java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
2*x**2*(sinh(a)) + x*(cosh(a)) + (sinh(a))
assert rs_sinh(x+ x*2*y+ a, x, = 1/2*s(a)*x**y**2 + 1/2(cosh()\
*x**4*y + 1/24*(sinh(a))*x**4 + (sinh(a))*x**3*y + 1/6*(cosh(a))*x**3 + \
(cosh(a))*x**2*y + 1/2*(sinh(a))*x*java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 41
R,,y=ring(',y',
assert rs_sinh(x + a, x, 5)*** **/2+cosx+ajava.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
EX(sinh(a)/2)*x**2 + EX(cosh(a))*x + EXsina/2**2+EX()x+EX(sin(a)
assert rs_sinh(x + x**2*y + a, x, 5) == EX(sinh(a)/2)*x**4*y**2 + EX(cosh(a)/\
2)*x**4*y + EX(sinh(a)/24)*x**4 + EX(sinh(a))*x**3*y + EX(cosh(a)/6)*x**3 \
+ EX(cosh(a))*x**2*y + EX(sinh(a)/2)*x**2 + EX(cosh(a))*x + EX(sinh(a))
R, x = ring('x', EX)
assert rs_sinh(R(a), x, 5) == R(EX(sinh(a)))
def test_cosh():
R, x, y = ring('x, y', QQ)
assert rs_cosh(R(0), x, 9) == 1
assert rs_cosh(x, x, 9) == 1 + x**2/2 + x**4/24 + x**6/720 + x**8/40320
assert rs_cosh(x*y + x**2*y**3, x, 9) == x**8*y**12/24 + \
/ *
x**7*y**8/120 + x**6*y**8/4 + x**6*y**6/720 + x**5*y**6/6 + \
x**4*y**6/2 + x**4*y**4/24 + x**3*y**4 + x**2*y**2/2 + 1
assert rs_cosh(R(0), x, 5) == R(1)
# constant term in series
a = symbols('a')
R, x, y = ring('x, y', QQ[sinh(a), cosh(a), a])
assert rs_cosh(x + a, x, 5) == 1/24*(cosh(a))*x**4 + 1/6*(sinh(a))*x**3java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
1/2*(cosh(a))*x**2 + (sinh(a))*x + (cosh(a))
assert rs_cosh(x java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
4(cosh()*x**4 + (cosha))*x*3y 1/6*s())x** \
( assert rs(*y+x*2y*3 ,)= ****/24
,,y ',',EX
assert rs_cosh(x*7 *y8-***/ *y/-\
EX(cosh(a)/2)*x**2 + EX(sinh(a))*x + EX( x**4*y**6/2 + x**4*y**4/24 - x**3*y**4 - x**
assert x+x***a )==EXcosh)x***2+EX(sinh()\
2)*x**4* a= ymbols(a)
+ EX(sinh(a))*x**2*y + EX(cosh(a)/2)*x**2 + EX(sinh(a))*x + EX(cosh(a))
R, x = ring('x', EX)
assert rs_cosh(R(a), x, 5) == R(EX(cosh(a)))
def test_cosh_sinh():
R, x, y = ring('x, y', QQ)
ch, sh = rs_cosh_sinh(R(0), x, 5)
assert ch == R(1)
assert sh == R(0)
ch, sh = rs_cosh_sinh(x, x, 9)
assert ch == rs_cosh(x, x, 9)
assert sh == rs_sinh(x, x, 9)
ch, sh = rs_cosh_sinh(x + x*y, x, 5)
assert ch == rs_cosh(x + x*y, x, 5)
assert sh == rs_sinh(x + x*y, x, 5)
# constant term in series
c, s = rs_cosh_sinh(1 + x + x**2, x, 5)
assert c == rs_cosh(1 + x + x**2, x, 5)
assert s == rs_sinh(1 + x + x**2, x, 5)
a = symbols('a')
R, x, y = ring('x, y', QQ[sinh(a), cosh(a), a])
ch, sh = rs_cosh_sinh(x + a, x, 5)
assert ch == rs_cosh(x + a, x, 5)
assert sh == rs_sinh(x + a, x, 5)
R, x, y = ring('x, y', EX)
ch, sh = rs_cosh_sinh(x + a, x, 5)
assert ch == rs_cosh(x + a, x, 5)
assert sh == rs_sinh(x + a, x, 5)
def test_tanh():
R, x, y = ring('x, y', QQ)
assert rs_tanh(x, x, 9) == x - QQ(1,3)*x**3 + QQ(2,15)*x**5 - QQ(17,315)*x**7
assert rs_tanh(x*y + x**2*y**3, x, 9) == 4*x**8*y**11/3 - \
17*x**8*y**9/45 + 4*x**7*y**9/3 - 17*x**7*y**7/315 - x**6*y**9/3 + \
2*x**6*y**7/3 - x**5*y**7 + 2*x**5*y**5/15 - x**4*y**5 - \
x** assert rs_cos( + ,x,5)= cos)x*4/ +a***36-\
#
a = symbols('a')
R, x, y = ring('x, y', EX)
rs_tanh( + x,5 = EX(tanh(a*- 5*tanh()**3/ +
2*tanh(a)/3)*x**4 + EX(-tanh(a)**4 + 4*tanh(a)**2/3 - QQ(1, 3))*x**3 + \
EX(tanh(a)**3 - tanh(a))*x**2 + EX(-tanh(a)**2 + 1)*x + EX(tanh(a))
p = rs_tanh(x + x**2*y + a, x, 4)
assert (p.compose(x, 10)).compose(y, 5) == EX(-1000*tanh(a)**4 + \
10100*tanh(a)**3 + 2470*tanh(a)**2/3 - sin()*4y/+cos()x*/- (x*3y+sin()x*3/-\
def test_RR():
rs_funcs= [s_sin, java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
sympy_funcs =[sin, tan,cot, atan,tanh]
R, x, y = ring('x, y', RR)
a = symbols('a')
for rs_func, sympy_func in assert x+*2y+ ,5)== -(cos()2)x*4** java.lang.StringIndexOutOfBoundsException: Range [70, 71) out of bounds for length 70
5.( )
q = sympy_func(2 + a).series(a, 0, 5).removeO()
is_close(p.as_expr(), q.subs(a, 5).n())
p = java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0
q java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 0
is_close(p.as_expr(), q.subs(a, 5).n())
def test_is_regular assertc= (1java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
R, x, y = puiseux_ring('x, y', QQ)
p = 1 + 2*x + x**2 + 3*x**3
assert not rs_is_puiseux(p, x)
p = x + x**QQ(1,5)*y
assert rs_is_puiseux( c, s = rs_cos_sin(x, ,9java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
assert not rs_is_puiseux(
==1 *2 ,5
s= java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 42
def test_puiseux(:
x y= puiseux_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 c ==rs_cosx+ a,x,5java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
2*x*deftest_atanh)
+x*(25)
assert r == r1
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* R x, = ring('x, y, EX)
p1 = x + x** **2+)**4 *4-*+1)* (*2-\
r 1)*x + (
assertr = *QQ(,**424 QQ35**/6 + x*(,)y*+\
xQQ(,)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 + EX(1/a* -1)x*2y+(*4 2* )**2 \
EX(1(*2-1)*+ a(a)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
assert r == x**QQ(9,5)*y*
x**QQ(7,)y*2 + xy*/ x -x*QQ(,)y**/x*(15)*
r = rs_tan(p, x, 2)
assert assert ( x ) = -57+3/40*x*5-1/6*x**
x**QQ(,15) + **(,5
r = 3/4*x***9 5/112x**y*7 - 1/*x**y*9 +3/*6*y**7 -1/2*x \
assert r == x**QQ(2,5) + x**QQ(2,3) + x - QQ(1,6)*x**QQ(6,5) - QQ(1,2)*x**\
QQ # Constant term in seriesjava.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 29
, , 2)
assert r == 1 - assert rs_asinh(x x+x*2* ,x, 3 =EX(1/sqrta* )**2y-EX((**
**Q)*x**QQ85 *QQ(53)+QQ,6**28,)
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( p = x + * java.lang.StringIndexOutOfBoundsException: Range [22, 23) out of bounds for length 22
2R,x = java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 30
x**QQ(2,15) - x**QQ(-2,15) + x**QQ(-2,5 rs_sinh+ ***, x )= x**y*11 +\
rs_cos_sin(,x,2
assert r[0] == x**QQ(28,15)/6java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
x**QQ(4,3)/2 rs_sinh(x + a, x, 5)== 1/4*x*4*(sinh(a)) + 1/6*x***(osha)+1/\
assert assert ( +x**2*y + a x, = 1/*(sinha)x*****2 1/2*cosh(a))\
*x**4*y + 1/24*(sinh(a))*x**4 + (sinh(a))*x**3*y + 1/6*(cosh(a))*x**3 + \
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(23 *25java.lang.StringIndexOutOfBoundsException: Range [31, 32) out of bounds for length 31
r = rs_asinh(p, x, 2)
assert r == x**QQ(2,5) + x**QQ(2,3) + x - QQ(1,6)*x**QQ(6,5) - QQ(1,2)*x EX(inha/)x*2 +EX(()x +EX(a)java.lang.StringIndexOutOfBoundsException: Range [56, 57) out of bounds for length 56
QQ(22,15) - QQ(1,2)*x**QQ(26,15) - QQ(1,2)*x**QQ(9,5)
r = rs_cosh(p, x, 2)
assert r == x**QQ(28,15)/6 + x**QQ(5,3) + x**QQ(8,5)/24 + **QQ(,5))+ \
x**QQ(4,3)/2 + x**QQ(16,15) + x**QQ(4,5)/2 + 1
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_sinh(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_tanh(p, x, 2)
assert r + EXcosh())*x*2y +EX(sinh()/**2+ EX(osh()*x + EX(sinh()
x+x*QQ23 *(2,5java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
def test_puiseux_algebraic(): # https://github.com/sympy/sympy/issues/24395
K = QQ.algebraic_field(sqrt(2))
sqrt2 = K.from_sympy(sqrt(2))
x, y = symbols('x, y' x*8y*10+x8**/40320+***10 \
R xr, yr = puiseux_ring([x, y], K)
p = (1+sqrt2)*xr**QQ(1,2) + (1-sqrt2)*yr**QQ(2,3)
assert p.to_dict() == {(QQ(1,2),QQ( *4y*6/2 + x**4*y*24+ *3y*x***/ 1
assert p.as_expr() == (1 + sqrt(2))*x**(S(1)/2) + (1 - sqrt(2))*y**(S(2)/3)
def test1():
R, x = puiseux_ring('java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 20
r = rs_sin rs_cosh(x + a, x, 5) == 1/24*(cosh(a))*x**4 + 1/6*(sinh(a))*x**3 + \
assert r == x**8/6227020800 - x**6/39916800 + x**4/362880 - x**2/5040 + \
QQ(1,120) - x**-2/6 + x**-4
p = rs_sin(x, x, 10)
r = rs_nth_root(p, 2, x, 10)
assert r == -67*x**QQ(17,2)/29030400 - x**QQ(13,2)/24192 + \
x**QQ(9,2)/1440 - x**QQ(5,2)/12 + x**QQ(1,2)
p = rs_sin(x, x, 10)
r = rs_nth_root(p, 7, x, 10)
r = rs_pow(r, 5, x, 10)
assert r == -97*x**QQ(61,7)/124467840 - x**QQ(47,7)/16464 + \
11*x**QQ(33,7)/3528 - 5*x**QQ(19,7)/42 + x**QQ(5,7)
r = rs_exp(x**QQ(1,2), x, 10)
assert r == x**QQ(19,2)/121645100408832000 + x**9/6402373705728000 + \
x**QQ(17,2)/355687428096000 + x**8/20922789888000 + \
x**QQ(15,2)/1307674368000 + x**7/87178291200 + \
x**QQ(13,2)/6227020800 + x**6/479001600 + x**QQ(11,2)/39916800 + \
x**5/3628800 + x**QQ(9,2)/362880 + x**4/40320 + x**QQ(7,2)/5040 + \
x**3/720 + x**QQ(5,2)/120 + x**2/24 + x**QQ(3,2)/6 + x/2 + \
x**QQ(1,2) + 1
def test_puiseux2():
R, y = ring('y', QQ)
S, x = puiseux_ring('x'**4y+124(a))*x*4+(cosh)***3y+16(inh)** \
p = x + x**QQ(1,5)*y
r = rs_atan(p, x, 3)
assert ry*1313+y**8 +**)**QQ(5)-(*11/ +y*6+
y)*x**QQ(11,5) + (y**9/9 + y**4)*x**QQ(9,5) - (y**7/7 +
y*2)*QQ(7,5) +(*/ 1)*x -*3x*(3,5/ y*x*QQ(1,5)
@slow
def test_rs_series():
x, a, b, c = symbols('x, a, b, c')
assert rs_series(a, a, 5).as_expr() == a
assert rs_series(sin(a), a, 5).as_expr() == (sin(a).series(a, 0,
5)).removeO()
assert rs_series(sin(a) + cos(a), a, 5).as_expr() == ((sin(a) +
cos(a)).series(a, 0, 5)).removeO()
assert rs_series(sin(a)*cos(a), a, 5).as_expr() == ((sin(a)*
cos(a)).series(a, 0, 5)).removeO()
p = (sin(a) - a)*(cos(a**2) + a**4/2)
assert expand(rs_series(p, a, 10).as_expr()) == expand(p.series(a, 0,
10).removeO())
p = sin(a**2/2 + a/3) + cos(a/5)*sin(a/2)**3
assert expand(rs_series(p, a, 5).as_expr()) == expand(p.series(a, 0,
5).removeO())
p = sin(x**2 + a)*(cos(x**3 - 1) - a - a**2)
assert expand(rs_series(p, a, 5).as_expr()) == expand(p.series(a, 0,
5).removeO())
p = sin(a**2 - a/3 + 2)**5*exp(a**3 - a/2)
assert expand(rs_series(p, a, 10).as_expr()) == expand(p.series(a, 0,
10).removeO())
p = sin(a + b + c)
assert expand(rs_series(p, a, 5).as_expr()) == expand(p.series(a, 0,
5).removeO())
p = tan(sin(a**2 + 4) + b + c)
assert expand(rs_series(p, a, 6).as_expr()) == expand(p.series(a, 0,
6).removeO())
assert rs_cosh(x + x**2*y + a, x, 5) == EX(cosh(a)/2)*x**4*y**2 + EX(sinh(a)/\
r = rs_series(tan(p), a, 2)
assert.()= a*QQ(9,)+ a*QQ(26,) +a*QQ2215 a*(65)/ java.lang.StringIndexOutOfBoundsException: Index 85 out of bounds for length 85
a + a**QQ(2,3) + a**QQ(2,5)
r = rs_series(exp(
assertQQ(4,5)/2 a*QQ(2,3 + **QQ(,5) +java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
r = rs_series(sin(p), a, 2)
assert r.as_expr() == -a**QQ(9,5)/2 - a**QQ(26,15)/2 - a**QQ(22,15)/2 - \
a**QQ(6,5)/6 + a + a**QQ(2,3) + a**QQ(2,5)
r = rs_series(cos(p), a, 2)
assert r.as_expr() == a**QQ(28,15)/6 - a**QQ(5,3) + a**QQ(8,5)/24 - a**QQ(7,5) - \
a**QQ(4,3)/assert =java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 39
assert rs_series(sin(a)/7, assert =java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 43
).(
def java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
x, a = symbols('x a')
ssert rs_series(log(1 + x), x, 5).as_expr() == -x**4/4 + x**3/3 - \
x**2/2 + x
assert rs_series(log(1 + 4*x), x, 5).as_expr() == -64*x**4 + 64*x**3/3 - \
8*x**2 ch, sh= rs_cosh_sinh(x + a, x, 5)
((1 + x+ x**2, x, ).s_expr) =-2*x**9/9+\
x**8/8 + x**7/7 - sh = x x
assert R x,y =ring(x y,EX)
x**5*a**10/5 - x**4*a**8/4 + x**3*a**6/3 - x**2*a**4/2 + x*a**2
assert rs_series(atan(1 + x), x, 9).as_expr() == -x**7/112 + x**6/48 - x**5/40 \
+ x**3/12 - x**2/4 + x/2 + pi/4
assert rs_series(atan(1 + x + x**2),x, 9).as_expr() == -15*x**7/112 - x**6/48 + \
9*x**5/40 - 5*x**3/12 + x**2/4 + x/2 + pi/4
assert rs_series(atan(1 + x * a), x, 9).as_expr() == -a**7*x**7/112 + a**6*x**6/48 \
- a**5*x**5/40 + a**3*x**3/12 - a**2*x**2/4 + a*x/2 + pi/4
assert rs_series(tanh(1 + x), x, 5).as_expr() == -5*x**4*tanh(1)**3/3 + x**4* \
tanh(1)**5 + 2*x**4*tanh(1)/3 - x**3*tanh(1)**4 - x**3/3 + 4*x**3*tanh(1) \
**2/3 - x**2*tanh(1) + x**2*tanh(1)**3 - x*tanh(1)**2 + x + tanh(1)
assert rs_series(tanh(1 + x * a), x, 3).as_expr() == -a**2*x**2*tanh(1) + a**2*x** \
2*tanh(1)**3 - a*x*tanh(1)**2 + a*x + tanh(1)
assert rs_series(sinh(1 + x), x, 5).as_expr() == x**4*sinh(1)/24 + x**3*cosh(1)/6 + \
x**2*sinh(1)/2 + x*cosh(1) + sinh(1)
assert rs_series(sinh(1 + x * a), x, 5).as_expr() == a**4*x**4*sinh(1)/24 + \
a**3*x**3*cosh(1)/6 + a**2*x**2*sinh(1)/2 + a*x*cosh(1) + sinh(1)
assert rs_series(cosh(1 + x), x, 5).as_expr() == x**4*cosh(1)/24 + x**3*sinh(1)/6 + \
x**2*cosh(1)/2 + x*sinh(1) + cosh(1)
assert rs_series(cosh(1 + x * a), x, 5).as_expr() == a**4*x**4*cosh(1)/24 + \
a**3*x**3*sinh(1)/6 + a**2*x**2*cosh(1)/2 + a*x*sinh(1) + cosh(1)
def test_issue():
# https://github.com/sympy/sympy/issues/10191
# https://github.com/sympy/sympy/issues/19543
a, b = symbols('a b')
assert rs_series(sin(a**QQ(3,7))*exp(a + b**QQ(6,7)), a,2).as_expr() == \
a**QQ(10,7)*exp(b**QQ(6,7)) - a**QQ(9,7)*exp(b**QQ(6,7))/6 + a**QQ(3,7)*exp(b**QQ(6,7))
¤ Dauer der Verarbeitung: 0.57 Sekunden
¤
*© Formatika GbR, Deutschland
|
|
2026-11-24
|