-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect substitution of multivariate derivatives #375
Comments
|
Have you seen that The result look OK to me:
|
It's a strange one, but I updated the OP to include a working example now...as minimal as I could get it. It is annoying because the problematic code 'contaminates' the REPL session, so you have to restart it everytime you want to check if the result changed. |
@mzaffalon Yes, that does look OK, but the problem comes when doing substitution on the derivatives. Please see the OP again; I have updated it with a working example. |
I can't replicate, I get 0 for all the cases. Did you replicate this behaviour @mzaffalon? |
It's 0 in all cases for me as well, with SymPy 1.0.30. |
I tried updating SymPy 1.0.28->1.0.30 to no effect. :( What is likely to be the problem then? PyCall? Julia? Python? |
My guess |
|
I'll have to update and check. I'll try and do so sometime soon. |
Well, this is odd. I have two different instances running each with SymPy 1.0.30, PyCall with 1.91.4, sympy.version at 1.6.2 and different answers for:
The different one is my local master, but that should be the same, and if not, certainly not what is seen here. One thing I tried, we to create a new project, activate that, add [email protected] and run these commands. This worked. Does the above work as expected on your machine if you try that? |
Neither your code nor mine in the OP gave the correct result after activating the fresh project. no idea why |
Wierd, I'll have to play around with that to see what might trigger this. Definitely worthy of the "!?" punctuation! |
Yeah, wierd. I couldn't replicate this AM; then I upgraded to 1.5.2 and voila -- it was back. I then tried with a reduced environment and it went away; now I can't make the issue come back. I'm at a loss for now. If it is an issue for you, can you try this PyCall-only test:
|
I'm still curious if the issue appears with the PyCall only version of the
problem I posted. If you have time, I'd love to hear.
…On Fri, Sep 25, 2020 at 10:21 AM Johannes van den Berg < ***@***.***> wrote:
I noticed this is sometimes an issue for other orders of derivatives too,
so the workaround I'm using right now is to run this at the start of the
session:
using ***@***.*** u ***@***.*** x y zfor ui in 0:6 # greater or equal to the order of derivative which will be used
for wi in 0:6 # idem
phi = sympy.Derivative(x(u,w), (u,ui), (w,wi))
phi00 = phi.subs(u,0).subs(w,0)
@Assert phi00.subs(phi00, 0) == Sym(0)
phi = sympy.Derivative(y(u,w), (u,ui), (w,wi))
phi00 = phi.subs(u,0).subs(w,0)
@Assert phi00.subs(phi00, 0) == Sym(0)
phi = sympy.Derivative(z(u,w), (u,ui), (w,wi))
phi00 = phi.subs(u,0).subs(w,0)
@Assert phi00.subs(phi00, 0) == Sym(0)
endend
With this everything seems to work as expected. Very far from an elegant
solution, but it will do for my purposes I think. Thanks for the help :)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#375 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADG6TD5GQ5TKP4TLFIP6ATSHSRPVANCNFSM4RXDNAWA>
.
--
John Verzani
Department of Mathematics
College of Staten Island, CUNY
[email protected]
|
By the way, the I had deleted the comment that you replied to. The "workaround" fixes the output of the MWE, but then when I run some of my other code it gives me wrong answers and the MWE returns the wrong value again. :/ So...apparently PyCall was not installed. I figured it would be a dependency of SymPy.jl, but seems not. I rewrote my MWE in python, and it gave the same erroneous result. So I suppose it is not really a problem with SymPy.jl then. |
Thanks!
BTW, regardless of where the issue lies, this is a weird one with its intermittency. |
I'm trying to get an example to file a bug report, but this is working for me. Perhaps it is os specific. I'm on a Mac. Does this run for you?
|
Yes that runs for me no problem. (I am running on Windows.) py"""
import sympy
from sympy import *
u,v = sympify("u,v")
x = Function("x")
f0 = diff(x(u,v), u, 4, v, 2).subs(v, 0)
g00 = diff(x(u,v), u, 2, v, 4).subs(u, 0).subs(v, 0)
f0.subs([(u, 0), (g00, 0)])
ϕ00 = diff(x(u,v), u, 5, v, 1).subs(u,0).subs(v,0)
print(sympy.__version__)
print(ϕ00.subs(ϕ00, 0))
""" |
So the straight python code runs, but the pycall interface doesn't always? That is
can fail, but
doesn't. If that is so, it would seem that perhaps PyCall is the bottleneck. |
Ah no, I added a few lines there. The code gives the same result with
Python vs PyCall.
2020年9月28日(月) 19:39 john verzani <[email protected]>:
…
So the straight python code runs, but the pycall interface doesn't always?
That is
using PyCall
sympy = PyCall.pyimport_conda("sympy", "sympy")
u,v = sympy.sympify("u,v")
x = sympy.Function("x")
ϕ = sympy.Derivative(x(u,v), (u,5), (v, 1))
ϕ₀₀ = sympy.Derivative(x(u,v), (u,5), (v, 1)).subs(u,0).subs(v,0)
ϕ₀₀.subs(ϕ₀₀, 0)
can fail, but
py"""
import sympy
from sympy import *
u,v = sympify("u,v")
x = Function("x")
f0 = diff(x(u,v), u, 4, v, 2).subs(v, 0)
g00 = diff(x(u,v), u, 2, v, 4).subs(u, 0).subs(v, 0)
f0.subs([(u, 0), (g00, 0)])
ϕ00 = diff(x(u,v), u, 5, v, 1).subs(u,0).subs(v,0)
print(sympy.__version__)
print(ϕ00.subs(ϕ00, 0))
doesn't. If that is so, it would seem that perhaps PyCall is the
bottleneck.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#375 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJ6PMBIWRYGCDYVPVUOUDY3SIDC37ANCNFSM4RXDNAWA>
.
|
Alright, now I'm confused. Both are working or none? |
Neither Python nor PyCall gives the correct result when I include the lines:
```
f0 = diff(x(u,v), u, 4, v, 2).subs(v, 0)
g00 = diff(x(u,v), u, 2, v, 4).subs(u, 0).subs(v, 0)
f0.subs([(u, 0), (g00, 0)])
```
2020年9月28日(月) 19:44 john verzani <[email protected]>:
…
Alright, now I'm confused. Both are working or none?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#375 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJ6PMBLWFCVHHTD6JF6A32TSIDDOXANCNFSM4RXDNAWA>
.
|
gives the output
I expect them all to be 0, but for some reason the evaluation of a (u, 5), (w, 1) derivative and other multivariate derivatives of total order 6 (not shown here) do not self-substitute correctly after evaluating the line
diff(dww, (u, 3))(u0...)
.The text was updated successfully, but these errors were encountered: