## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
• 00:23
1marcelomanari starred sympy/sympy
• 00:17
github-actions[bot] commented #22754
• 00:12
github-actions[bot] commented #22876
• Jan 17 23:51
edwinhung starred sympy/sympy
• Jan 17 23:34
bertiewooster commented #22716
• Jan 17 23:33
github-actions[bot] commented #22875
• Jan 17 23:06
sympy-bot commented #22754
• Jan 17 23:05
oscarbenjamin reopened #22754
• Jan 17 23:05
oscarbenjamin closed #22754
• Jan 17 22:58
github-actions[bot] commented #22858
• Jan 17 22:43
sympy-bot commented #22876
• Jan 17 22:43
sympy-bot commented #22876
• Jan 17 22:43
bertiewooster opened #22876
• Jan 17 22:39
asmeurer commented #22754
• Jan 17 22:37
asmeurer commented #22716
• Jan 17 22:18
sympy-bot commented #22875
• Jan 17 22:18
sympy-bot commented #22875
• Jan 17 22:18
bertiewooster opened #22875
• Jan 17 21:31
sympy-bot commented #22858
• Jan 17 21:30
bertiewooster synchronize #22858
Megan Ly
@meganly

Thanks for the help @jksuom and @asmeurer . I tried

C= CoordSys3D('C', vector_names = ["\mathbf{i}", "\mathbf{j}", "\mathbf{k}"])

and now the latex for the base vector i is '\mathbf{\hat{\mathbf{i}}_{C}}'.
However, implementing a subclass to do custom printing should work.

thorek1
@thorek1
under which conditions does the follwoing simplify to y? simplify((y^(1/(1-alpha)))^(1 - alpha))
Aaron Meurer
@asmeurer
Look at the docstring of powdenest.
You need assumptions on either y or alpha.
thorek1
@thorek1
@vars alpha positive = true
@vars y real = true
still doesnt work
it seems i would need sympy to understand that 0 < alpha < 1
but i dont know how
powdenest((y^(1/(alpha)))^(alpha),force=true) works finde
Aaron Meurer
@asmeurer
I don't think that is sufficient. Consider y = -1 and alpha = 1/2
thorek1
@thorek1
true, in fact y > 0 and 0<alpha<1
docstring of powdenest doesnt help much in this case it seems
Aaron Meurer
@asmeurer
SymPy doesn't currently have a way to tell powdenest that alpha is less than 1. Using force=True is the best way, after manually verifying that the simplification is mathematically correct.
thorek1
@thorek1
ok, what is the best workaround then?
Aaron Meurer
@asmeurer
force=True
thorek1
@thorek1
doesnt get me there
@vars alpha y positive = true
powdenest((y^(1/(1-alpha)))^(1 - alpha))
Aaron Meurer
@asmeurer
only other option is to do a change of variables that lets you use the assumptions that sympy supports, like positive=True
oh hmm
thorek1
@thorek1
hmm, manually catch all int +/- var cases and replace them
Aaron Meurer
@asmeurer
that's a bug I guess
This seems related sympy/sympy#19627
I guess you can do something with replace with a pattern.
>>> a, b, c = Wild('a'), Wild('b'), Wild('c')
>>> expr.replace((a**b)**c, a**(b*c))
y
thorek1
@thorek1
yeah thats probably a good way to go
I get the solution assuming alpha is an integer but that doesnt seem very safe
thorek1
@thorek1
laolux
@laolux:privacytools.io
[m]
I have some issue with integrating the Heaviside function. Usually I would expect 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).
Is there something I am missing, or should I report it as a bug?
Kalevi Suominen
@jksuom

@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.

laolux
@laolux:privacytools.io
[m]
@jksuom Thanks for the explanation. I read im the documentation that “Heaviside(x)==Heaviside(x, None)”, but for integration that should not matter. But now I understand that sympy takes different ways to evaluate these functions. Anyways, “meijerint” seems to have some more issues with Heaviside, as I commented on github:
JSS95
@JSS95
@asmeurer can you take a look at #21423, please?
Richard Pausch
@PrometheusPi

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.

Kalevi Suominen
@jksuom
It is a known issue that is hard to avoid when working with complex floating point numbers. (There is an imaginary part because solve does not know that the result should be real.) For real floating point roots, it is often better to use nroots.
Richard Pausch
@PrometheusPi
@jksuom Thanks for the fast reply. nroots worked like a charm :+1:. If it is a know issue, I will refrain from opening another issue on GitHub.
fakuivan
@fakuivan
Hello
Is there a way to programmatically convert an expression with derived units to the equivalent with base units?
fakuivan
@fakuivan
what I have now is convert_to(expr, system._base_units) and then xreplace the base units
Emil Jiří Tywoniak
@EmilJ_gitlab
Hi, is there a way of defining a PDE with curl? It seems to me like curl operates by just... trying to compute the curl immediately.
H = Function('H')(x,y,z)
# H = cross.x *
print(type(curl(H)))
this tells me the curl of this unknown function is VectorZero
fakuivan
@fakuivan
doit=False maybe?
print(type(curl(H, doit=False)))
Emil Jiří Tywoniak
@EmilJ_gitlab
Hmm, right now H is acting like a scalar field, but how do I make it not... be that... without defining it
Emil Jiří Tywoniak
@EmilJ_gitlab
Hx = Function('Hx')(x,y,z)
Hy = Function('Hy')(x,y,z)
Hz = Function('Hz')(x,y,z)
delop = Del()
T = CoordSys3D(r'\$\bot')
H = Hx*T.x + Hy*T.y + Hz*T.z
print(type(delop.cross(H)))
AttributeError: 'Add' object has no attribute 'dot'
no clue.
Kalevi Suominen
@jksuom
H is an Add object whose arguments are Mul objects, not a vector.
In [10]: srepr(H)
Out[10]: "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'))))"
Samuel Lelièvre
@slel
On the SymPy page at PyPI, the "SymPy Banner" image does not display properly.
Felix Hildén
@felix-hilden

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.