Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
Activity
• 11:16
oscarbenjamin commented #21162
• 11:08
ThePauliPrinciple commented #22857
• 10:05
cjaitej commented #22857
• 10:04
cjaitej commented #22857
• 09:58
cjaitej synchronize #22857
• 09:56
cjaitej synchronize #22857
• 09:47
cjaitej synchronize #22857
• 09:45
cjaitej synchronize #22857
• 09:32
cjaitej synchronize #22857
• 08:41
moorepants commented #21377
• 08:40
Querela starred sympy/sympy
• 08:38
moorepants commented #21162
• 08:36
moorepants commented #21162
• 07:53
praneethratna commented #22831
• 07:18
precompiler starred sympy/sympy
• 06:51
anutosh491 commented #22905
• 05:36
faze-geek commented #22905
• 02:09
connorferster commented #21162
• 02:09
connorferster commented #21162
• 01:40
github-actions[bot] commented #22904
thorek1
@thorek1
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.

hackman01
@hackman01
i was trying to solve this issue #21463 but was not able to find source code of convert_to
Kalevi Suominen
@jksuom
sympy/physics/units/quantities.py: def convert_to(self, other, unit_system="SI")
samsja
@samsja:matrix.org
[m]
HI everybody, I am looking for a way to symbolically minimize a multivariate function. The sympy maximize function only work on monovariate function ( or at least what I understand out of the documentationI). What could I do ? I already try the approach of resolving the system where the gradient equal zero and then take the min of it however it does not include solution with unbound variable like the maximise function do by outputing things like infinity. Thanks in advance 🙂
Vishesh Mangla
@Teut2711
import sympy as sm
from sympy import I
w = sm.symbols("omega")
exp = 20/(I*w+1)/(I*w+2)/(I*w+3)
sm.simplify(exp)
how to simplify it? I want the w corresponding to which the imaginary part is 0