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
lagrange_polynomial(algorithm='divided_difference') fails over finite fields #9787
Comments
comment:2
The issue does not exist anymore with sage-5.12β3. |
comment:3
In 5.12.beta5, the following still fails:
|
comment:8
Here is a branch that should fix the bug. The only changes to the code are a few extra coercions (and one conversion, for reasons explained in a comment) to make sure everything lives in the right parent. A few doctests had to be fixed because they started with the wrong base ring ( |
Commit: |
Author: Peter Bruin |
comment:9
I would propose something like:
That way we make sure that all the operations happen in the right parent (be it the base ring of the parent, or some other parent where both the input and the parent fit) |
Reviewer: Miguel Marco |
comment:10
Replying to @miguelmarco:
Do you mean that |
comment:11
Well, you could have that even now:
You can either catch that and raise an exception (which is probably the mathematically strictly correct), or be more flexible and allow situations like the previous (which, i think, can be useful in several cases). In this case, i would vote for the second option, but i understand it is a matter of opinion. |
comment:12
Replying to @miguelmarco:
Actually, with this branch, you get
This is not ideal from my point of view (I would prefer to use
I see that this could be the expected behaviour given the general permissiveness in Sage with respect to extending parents, but I would still find it strange if |
comment:13
Well, if it is clearly stated that the result should be in R, conversion should also be allowed, from my point of view. I can see solid arguments for any of the possible choices: coerce to R.basis(), convert to R.basis(), or extend for the common universe of R.basis() and the input. My personal choice would be the last one, but as long as it is clearly documented, i could live with any. Another option would be to include a keyword (like 'extend', for example) to control the behaviour in this aspect. That way you can have a default functionality, but also another option for the user to choose. Although, it seems a bit overkill for this. |
comment:14
Replying to @miguelmarco:
Fair point, I'll change that and improve the documentation.
I still think that
This sounds like a reasonable option, but I do think it is a bit overkill, so someone who really wants it can implement it. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:16
Hello, On sage-6.5 at least, I got the right answer.
It would be cool to add it to the documentation since it was the initial purpose of the ticket. Vincent |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:19
Hello, Looks good! Concerning the comment:12, where is this example in the sage book (I was not able to find it)? Should it be added to the documentation as an example with a warning? Vincent PS: Note that using coerce is justified... but not from the viewpoint of performances
|
Changed reviewer from Miguel Marco to Miguel Marco, Vincent Delecroix |
comment:20
When making the change --- a/src/sage/rings/polynomial/polynomial_ring.py
+++ b/src/sage/rings/polynomial/polynomial_ring.py
@@ -1698,7 +1698,7 @@ class PolynomialRing_field(PolynomialRing_integral_domain,
MATLAB*. 3rd edition, Prentice-Hall, 1999.
"""
- to_base_ring = self.base_ring()
+ to_base_ring = self.base_ring().coerce
points = map(lambda x: map(to_base_ring, x), points)
n = len(points)
F = [[points[i][1]] for i in xrange(n)]
@@ -1859,12 +1859,7 @@ class PolynomialRing_field(PolynomialRing_integral_domain,
8th edition, Thomson Brooks/Cole, 2005.
"""
- # Perhaps we should be slightly stricter on the input and use
- # self.base_ring().coerce here and in the divided_difference()
- # method above. However, this breaks an example in
- # sage.tests.french_book.nonlinear_doctest where the base ring
- # is CC, but the function values lie in the symbolic ring.
- to_base_ring = self.base_ring()
+ to_base_ring = self.base_ring().coerce
points = map(lambda x: map(to_base_ring, x), points)
var = self.gen()
I get
|
comment:21
Thanks for pointing the example! Once again the symbolic ring is wrong
Parent should be
But
|
comment:22
Replying to @videlec:
Indeed; compare
Related ticket: #18092 |
comment:24
Replying to @videlec:
If I understand #18092 correctly, it will only make
I interpret this as a positive review, correct me if I'm wrong. |
comment:26
Replying to @pjbruin:
I thought that
In other words
Perfect! Vincent |
Changed branch from u/pbruin/9787-lagrange_polynomial to |
CC: @miguelmarco
Component: algebra
Author: Peter Bruin
Branch/Commit:
b73cd8b
Reviewer: Miguel Marco, Vincent Delecroix
Issue created by migration from https://trac.sagemath.org/ticket/9787
The text was updated successfully, but these errors were encountered: