-
-
Notifications
You must be signed in to change notification settings - Fork 488
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
(x^2).subs({x: sqrt(x)}) returns sqrt(x) instead of x #30378
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
comment:6
I did some debugging and can report the following: this bug happens in https://github.com/pynac/pynac/blob/85c43c230e8050a1f71898889a021fec28318502/ginac/power.cpp#L747; in fact the correct power in the case of the substitution Changing the code such that
(Context: I don't really see a good solution right now, maybe someone else has some thoughts? |
comment:7
I am not sure how to fix this either - presumably it was precisely for some sort of wildcard situation that this was in there - but I do note the following in
so far, so good
Wait, what? Shouldn't these be fourth powers? That Note that the corresponding Ginac code always returns the |
comment:8
Replying to @kcrisman:
I can only make sense of the eighth powers in a setting where the substitution acts on a power like Unfortunately,
Interesting! I only saw that something concerning |
comment:9
In the
|
comment:10
In the case of substitution where all keys are variables rather than general expressions, shouldn't we be able to write robust code that does not rely on pattern matching? |
comment:11
Presumably, but just keep in mind the "not reinventing the wheel" guideline. |
comment:12
Several things to note here:
|
comment:13
A fix for
Higher level library code (such as in |
comment:14
#30688 may be germane Shouldn't this one be a |
comment:16
I would agree that this should ideally be a blocker, but unfortunately we don't seem to have many active developers who have time to work on the symbolics code. Comment 13 sketches a possible implementation strategy that can be done purely within sagelib and does not require changes in pynac. |
comment:18
this remark might or might not be relevant to the current problem. |
comment:20
What can I do to help? Unfortunately, my knowledge about Ginac and its interface via SageMath is very limited. If you can give me a doc or something, I can try. |
comment:21
Comment 13 outlines an implementation strategy that does not require changes to pynac |
comment:22
I just looked into the code and I tried to make sense of e.g. |
comment:23
If you follow comment 13, you would not need to modify |
Branch: public/30378 |
comment:25
A similar problem for I implemented a fix along the lines suggested by mkoeppe in comment:13. The PR solves the problem in the ticket description, but there is a bug that I don't understand:
All answers are correct except the last two. I don't know much about cython or pynac, so suggestions are welcome. (For example, I don't know how to clear a GExMap, so I declared new ones, instead of reusing the variable New commits:
|
Commit: |
comment:26
It's possible that the problem is in Ginac itself too, somehow. As for the new (and definitely bad) bug, sounds like some stuff isn't even being translated back into Sage. If you keep doing |
comment:36
I'm sorry, I was sure I added exactly that type of warning to the docstring, but it's not there, and it doesn't seem to be in my local branches, so I must have deleted it somehow. That's too bad, because I thought it was pretty good, and had some instructive examples of what could go wrong. I'll write a new warning (if I can't find the old one on my hard drive). I did know that there were still problems (which is why I tried to add the comment to the docstring) so I certainly agree that the comment is misleading. My PR was intended just to fix the special case of substituting values into variables. I think this (plus a warning in the docstring) is the minimum we need for 9.3. In the long run, I think there should be two different methods. Part of the problem is that
It should be easy to upgrade my patch to solve the case in comment:34. If we do that, then I think we should have a keyword argument to enable the original pynac interpretation of |
comment:37
What is implemented on this ticket already is good enough to fix the critical issue with function application,
I think more general tweaks to the subs algorithm should be addressed in pynac. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:40
I could not find the warning that I wrote before, so I drafted a new one. Improvements are welcome. |
comment:41
Looking great, thanks very much for this work. |
Reviewer: Matthias Koeppe |
comment:42
Thanks to you, too. My PR just implemented your suggestion in comment:13. |
comment:43
Docbuild fails, see patchbot |
Changed branch from public/30378v2 to public/30378v3 |
comment:47
Thanks! |
Changed branch from public/30378v3 to |
comment:49
Unfortunately, this fix causes more embarrassing bugs:
|
Changed commit from |
comment:50
Thanks for catching this. I have opened #31530 for this |
As discussed in https://groups.google.com/d/msg/sage-devel/kYZ4N73oiCM/-iDyQLWyBAAJ, we have currently
A consequence of this bug is
Note that the following outputs are correct:
Moreover, distinct powers of
x
seem OK:But a match is problematic:
CC: @nbruin @rwst @kcrisman @EmmanuelCharpentier
Component: symbolics
Keywords: sqrt, substitution, pynac
Author: Dave Morris
Branch:
8d4db46
Reviewer: Matthias Koeppe
Issue created by migration from https://trac.sagemath.org/ticket/30378
The text was updated successfully, but these errors were encountered: