I am trying to make a program to calculate taylor series, recomended to me to make by my calculus professor for good practice, and have run into a bit of an error. When I calculate ln(x) by hand I get (1(x-1)/1)-(1(x-1)^2/2)+((x-1)^3/3)-((x-1)^4/4)
. From a SymPy program I get x - (x - 1)**4/4 + (x - 1)**3/3 - (x - 1)**2/2 - 1
Also, is there a way I can get it to be able to find the pattern and make the universal series, calculated by hand to be ((-1)^n*(x-1)^n+1)/(n+1)
?
SymPy re-arranges terms of an expression according to its own rules. If in doubt, look at each expression or test the equality by hand if you are prone to make visual mistakes:
>>> from sympy.abc import x
>>> from sympy.parsing.mathematica import mathematica as P
>>> P(' (1(x-1)/1)-(1(x-1)^2/2!)+((x-1)^3/3)-((x-1)^4/4)')
x - (x - 1)**4/4 + (x - 1)**3/3 - (x - 1)**2/2 - 1
>>> hand = _
>>> res = x - (x - 1)**4/4 + (x - 1)**3/3 - (x - 1)**2/2 - 1
>>> hand == res
True
You got the same thing from SymPy as you did by hand! :-)