A computer algebra system written in pure Python http://sympy.org/ . To get started to with contributing https://github.com/sympy/sympy/wiki/Introduction-to-contributing
I am trying to simplify a general Taylor series of function f:
f = sym.Function('f')
x, x_0, h = sym.symbols("x x_0 h", real=True)
# works fine:
ts = sym.series(f(x),x, x_0, 4)
# but substituting x-x_0 by h
ts.subs(x-x_0,h)
# just returns 𝑂(1;𝑥→𝑥0)
Why is the (x-x0) in the Taylor series not substituted correctly?
@PrometheusPi subs
will replace a sum like x - x_0
(= x + (-1)*x_0
) in an expression only if that is also a sum that contains the same arguments:
In [19]: (x - x_0 + 1).subs(x - x_0, h)
Out[19]: h + 1
Otherwise, one must substitute x
alone:
In [24]: print(ts.subs(x, x_0 + h))
f(x_0) + h*Subs(Derivative(f(_xi_1), _xi_1), _xi_1, x_0) + h**2*Subs(Derivative(f(_xi_1), (_xi_1, 2)), _xi_1, x_0)/2 + h**3*Subs(Derivative(f(_xi_1), (_xi_1, 3)), _xi_1, x_0)/6 + O(h**4)
class MyCoordSys3D(CoordSys3D):
def __init__(self):
self.latex_vects = [r'\mathbf{%s}' % n for n in self.vector_names]
y
or alpha
.
replace
with a pattern.
>>> a, b, c = Wild('a'), Wild('b'), Wild('c')
>>> expr.replace((a**b)**c, a**(b*c))
y
integrate(Heaviside(x,0), (x,-1,1) =1
, but instead sympy returns Integral(Heaviside(x, 0), (x, -1, 1))
. Works fine if I omit the second argument of Heaviside
, but I think it should work in any case, as the value at x=0
is irrelevant for the integration (set of measure zero).
@laolux:privacytools.io Many integrators like meijerint
work by looking up the results in a table. The table may contain Heaviside(x)
but not Heaviside(x, 0)
which is a different object.
>>> Heaviside(x) == Heaviside(x, 0)
False
It may be possible to extend the matching code to handle this but that may not be easy to implement. Another entry should probably be added.
I ran into the following issue/error while trying to get the extrema of a simple 4th order polynomial:
import sympy as sym
x_sym = sym.symbols("x", real=True) # single variable
pot_sym = x_sym**4 - x_sym**2 + x_sym * 1/10 # function f
pot_prime_sym = sym.diff(pot_sym, x_sym) # first derivative of function df/fx
extrema = sym.solve(pot_prime_sym) # get extrema via df/dx == 0
for extremum in extrema:
print(sym.N(extremum), " == ", sym.N(sym.simplify(extremum))) # print values
returns:
0.050253826762553 - 0.e-23*I == 0.050253826762553 + 3.70576914423756e-22*I
0.680639276423668 + 0.e-23*I == 0.680639276423668
-0.730893103186221 + 0.e-23*I == -0.730893103186221
The last two results are equal, but the first entry does seem to cause an error of I simplify the result before returning its numeric value. There should be no complex contribution 3.7e-22*I
, thus something goes wrong here.
Is this a know issue, did I do something wrong, or is this a not-yet know issue and I should open a issue on github?
I am using sympy 1.7.1
.