replacewith 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=0is 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
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
Addobject whose arguments are
Mulobjects, not a vector.
In : srepr(H) Out: "Add(Mul(T.x, Function('Hx')(Symbol('x'), Symbol('y'), Symbol('z'))), Mul(T.y, Function('Hy')(Symbol('x'), Symbol('y'), Symbol('z'))), Mul(T.z, Function('Hz')(Symbol('x'), Symbol('y'), Symbol('z'))))"
Hi, I'd like to express a vector norm with indexed variables for differentation, but I don't quite know how. Every search I came up with led to matrix norms, which aren't really in question here. The variables are indeed vectors, but I don't care about the dimensionality in this case. Formulating a difference is easy enough, but I'm not sure how to continue.
# || x_a - y_b || x = sp.IndexedBase('x') a = sp.Idx('a') y = sp.IndexedBase('y') b = sp.Idx('b') diff = (x[a] - y[b])
How could this be achieved? I'm open for any other formulations as well! Much appreciated.