-
-
Notifications
You must be signed in to change notification settings - Fork 487
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
derivative of integer wrt to variable in polynomial ring should belong to that ring, not symbolic ring #20812
Comments
Attachment: functional.py.patch.gz |
comment:1
If you take care to use the correct zero, this just works:
But there is room for improvement, for sure. |
comment:2
The derivative of a symbolic expression is a symbolic expression :
Therefore this :
is a special case, indicating that 0 is cast to a symbolic expression (probably by However :
conforms to the requirement that the derivative of an object belongs its parent ring. Pedantism works both ways... ==> marking as invalid and requesting review in order to close. |
comment:3
This behavior is confusing. I think it's reasonable to expect that the derivative(f,g) will lie in the smallest ring containing f and g. Why not fix this? |
comment:4
Replying to @sagetrac-dgulotta:
In order
...even when this function, expression or polynomial happens to be a "constant" or degree-0 monomial, in which case the derivative can be taken to be the null "constant" or degree-0 monomial. Your remark may be more relevant in the reverse case:
So far, so good. But
is nonsensical, unless we mean to do implicitly :
In other words, take note that
even if
HTH, |
comment:5
It is difficult to do the right thing in all cases but I think that the patch that I submitted improves the situation for derivatives. I could write something similar for integrals if there is agreement that this would be useful. The reason why I don't like casting things into the symbolic ring is that it leads to errors that are very difficult to track down. For example:
It is not at all clear from the error message that In principle I think it is better to raise an error with a detailed message than to implicitly cast into the symbolic ring. I guess it may be too late to make that change since it might break existing code. Attempting to cast into a polynomial ring when possible seems like a reasonable compromise. |
comment:6
Replying to @sagetrac-dgulotta: [ Snip... ]
Which patch ? I find no patch in the ticket. More generally, I think that the problem is to define and compute "the smallest ring containing f and g". To illustrate :
This cast is reasonable and might be expected (i. e. one can reasonably expect Harder :
One might expect the
I'm not sure that this can be expressed in Sage... For the integrals :
Again, a "reasonable" cast. The case And we might have worse difficulties : what should be the "smallest ring" containing Casting to SR is, indeed, far from ideal, but it seems tome that the possible enhancements are fraught with more difficulties than they solve. Your thoughts ? |
comment:7
There is an attachment to this ticket, which is a patch. The patch uses |
comment:8
Replying to @sagetrac-dgulotta:
Would you mind submitting a branch, as described in Sagemath's developer's guide ? |
Commit: |
comment:10
It is a bad idea to put a lot of code inside the New commits:
|
comment:11
This might be an interesting data point:
|
comment:12
Setting in needs works because of [comment:10]. |
comment:13
Also [comment:2] makes a good point A more sensible change for
|
Author: Daniel Gulotta, Vincent Delecroix |
comment:17
There's a typo in,
But personally, instead of an example that says
I would prefer if the documentation just told me what the parent will be in the |
comment:18
Currently
I don't like it... though I am not sure what it should be. |
comment:19
Replying to @videlec:
It should be an error, because the integer zero is not a function. But I guess that behavior is consistent with the usual abuse of notation. We convert constants to symbolic expressions so that they can be evaluated like a function. In this case, we convert |
comment:20
Replying to @orlitzky:
If this is your answer, then you should arguethat the derivative of any element of
Precisely, this ticket is changing that behaviour as it also make sense to take derivatives of polynomials, Laurent polynomials, power series, etc. If you find this behaviour consistent, then this ticket should not be merged at all. |
comment:21
I suspect the behaviour on the integers was installed to deal with some edge cases that happened interactively or perhaps internally in SR. As far as I can see, For instance:
In fact,
so the functionality here is just part of the top-level These convenience functions are just not a good way of dispatching on type data. You'd have to move to a different language then, that has full signature dispatch rather than python's "first argument" dispatch through method calls. |
comment:22
Replying to @videlec:
That's right.
These top-level convenience functions that take any sage or python object are always a mess. The principled approach is to use So I think |
If I try to take the derivative of an integer (or nonzero rational, or integer mod n), then the result is an element of the symbolic ring:
It seems like it would be more natural for the returned value to belong to the ring containing x instead.
This may seem kind of pedantic, but it did trip me up when I was working with a list of polynomials, some of which were constant, and things were getting cast to Expression unexpectedly.
I am not particularly familiar with the Sage codebase, but I am attaching a patch that seems to fix the issue.
CC: @orlitzky
Component: calculus
Author: Daniel Gulotta, Vincent Delecroix
Branch/Commit: u/vdelecroix/20812 @
04dbe4c
Issue created by migration from https://trac.sagemath.org/ticket/20812
The text was updated successfully, but these errors were encountered: