-
-
Notifications
You must be signed in to change notification settings - Fork 567
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
implement gcd(a,b,hold=True) #16721
Comments
comment:1
One could argue this is (currently) user error, but this would be a great enhancement. |
comment:3
Here's another example, which seems to put this in the "mathematically wrong answer" category:
I would expect the answer to be 8 instead of 4:
|
Stopgaps: todo |
comment:4
I think the problem is that while we do get the "right" thing when two polynomials are involved, we somehow don't for a polynomial and an integer, and this isn't well documented. I agree that the end user may not care and that we should find a way to fix it (or at least to raise an error when a symbolic thing shows up in it). This won't be completely trivial, though. |
comment:5
and indeed
So in the symbolic ring this IS the gcd. Hmm. And if you think of this as a polynomial, it makes sense. So I'm not sure what to say here. The
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
comment:7
Replying to @kcrisman: I agree that all examples you give are consistent *if the So just make sure a big NOTE is given in the documentation. |
comment:8
Are there any problematic cases that don't involve the I'm wondering if the implementation of |
comment:9
Replying to @sagetrac-kbaut:
That they are different is a rather fundamental python language feature. Making the two behave equivalently would require rather major surgery on the python parser or some nasty trickery in preparsing. |
comment:10
Replying to @sagetrac-kbaut:
|
comment:11
You'd first need to decide what "gcd(A,B)" of two symbolic expressions is:
We have too little information to define gcd on SR properly. Currently even this doesn't work:
The gcd we are currently interfacing with is:
which is limited to polynomials over QQ, but at least it fixes the choice: it's polynomial gcd. In any setting, gcd tends to be not stable under evaluation, meaning that if
then for a specialization |
comment:12
That may be, but it presupposes that evaluation is demanded in So, what arguments against |
comment:14
Replying to @rwst:
How do you control when
what do you do to clear to "unhold" the expression and how do you control the order in which that happens? In particular, for your application, you'd need the values of |
comment:15
I see. But then the only reasonable way to achieve it is with different gcd functions, so one can sort out when to hold, i.e., the rational constant version would do it when an expression appeared as argument. |
comment:16
There are more than one solution to represent the function |
This comment has been minimized.
This comment has been minimized.
comment:18
Replying to @nbruin:
I do not understand. In what way is this different from
which simply does not work, and from which one usually comes to this:
|
comment:19
Replying to @rwst:
The problem is that "hold" semantics aren't well-defined, so you'd better make sure that for "held" expressions, the answers aren't wildly different depending on when the "hold" is lifted. Never mind that "hold" isn't implemented for sums. You can usually get an implicit hold by doing something like
and with that transform you see that your suggested iterator expression is NOT the same:
The hold apparently gets lifted by "sum" already (because our "hold" doesn't get translated to maxima, perhaps because a corresponding notion doesn't exist for sine there) and apparently, sum simplifies the expression under the assumption that t is an integer. That's why I think "hold" is not an appropriate mechanism for a wildly non-continuous function such as "gcd". It's meant to be a manipulation on (polynomial) expressions, not a symbolic function. I don't think SR is equipped to handle operations like that "symbolically". I know systems like maple and mathematica tend to not make a distinction between "operations" and "symbolic expressions", allowing deferred evaluation on pretty much anything, and in my experience predictability and debuggability of code suffers from it. Nothing prevents you from defining |
comment:20
So, summarily, |
comment:21
I believe that this should be "positive review". It was set to invalid 20 months ago and nobody complained so it can probably go away. |
The implemented behaviour of
gcd
is consistent if its arguments are rational numbers or polynomials. Trying to give a symbolic variable willconvert to polynomial which behaves unexpectedly:
The natural way to handle it is using the keyword
hold
:As comment:18 shows this may not be easy and involve other changes.
See also #15497
CC: @sagetrac-kbaut
Component: symbolics
Stopgaps: todo
Issue created by migration from https://trac.sagemath.org/ticket/16721
The text was updated successfully, but these errors were encountered: