-
-
Notifications
You must be signed in to change notification settings - Fork 490
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
gcd and xgcd over fields, PID and UFD #17671
Comments
comment:1
I am annoyed with the current implementation... it is written in the generic
This is completely crazy! And moreover different from what is in gcd!! |
Dependencies: #17673 |
Commit: |
Branch: u/vdelecroix/17671 |
This comment has been minimized.
This comment has been minimized.
comment:6
In except (AttributeError, NotImplementedError, TypeError, ValueError):
zero = self.parent.zero()
one = self.parent.one()
if self == zero:
return (other, zero, one)
elif other == zero:
return (self, one, zero)
else:
return (zero, zero, zero) I would have returned |
comment:7
Replying to @bgrenet:
You are totally right! Thanks! Vincent |
comment:9
Here is an example of a xgcd for two polynomials over the integers, where the linear
combination is not the gcd but the resultant::
sage: R.<x> = ZZ[]
sage: gcd(2*x*(x-1), x^2)
x
sage: xgcd(2*x*(x-1), x^2)
(2*x, -1, 2)
sage: (2*(x-1)).resultant(x)
2
New commits:
|
comment:10
Replying to @bgrenet:
right
The test is only for principal ideal domains. Up to now I encountered two cases where the convention are a bit special:
Vincent |
Branch pushed to git repo; I updated commit sha1. New commits:
|
This comment has been minimized.
This comment has been minimized.
comment:13
Replying to @videlec:
Oh, right! Then I agree with your test. Everything you've committed so far looks good to me (and passes the tests). There are two things left:
|
comment:14
Nope. There seems to be a regression with respect to timings (at least I do not understand what is happening). If I run the doctest on the file Moreover, in
is much longer for me. And if I remove the This is a critical issue. |
comment:15
I finally find out the problem in the tests:
I will add a small commit to fix some doctests. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:19
Salut Bruno, Sorry I had a typo in the two last commit messages so I had to do a forced push. Now everything looks all right. Note that before setting this one to positive review, we need to wait for the trivial #17673 to be in positive review (!hint!). Thanks to Ralf #17675 is already in positive review. In the last commits:
Vincent |
This comment has been minimized.
This comment has been minimized.
comment:21
Salut Vincent, I looked at #17673, but I am unable to review it since it goes beyond my knowledge in Sage... Or at least it will take some time for me to understand it and then review. Concerning the real number, I would have thought of an implementation acting as follows: sage: gcd(2.0,6.0)
2.00000000000000 I do not know if this makes sense. |
comment:22
Replying to @bgrenet:
Why? Would you like it to be nice only over ZZ and not over QQ? And this is where it becomes impossible. Within Sage any floating point can be converted to QQ...
So the only way I would agree with your proposition is to have also
which is currently False as well. Anyway mixing algebraic functions (like gcd) with floating point number is often a bad idea. So at least the proposed implementation tells you that something is wrong. Vincent |
comment:23
Replying to @videlec:
First of all, your current solution is mathematically perfectly correct and I am quite fine with it. This said, let me expose the reasons of my suggestion. With my suggestion, "integral floating point numbers" are treated differently than other floating point numbers. Reasons:
Also,
Finally, if a user asks for the GCD of two "integral floating point numbers", I have no difficulty to understand what s/he means (since the GCD of the integers they represent is a well-defined mathematical function). It is much more difficult to me to interpret the will of a user that asks for the GCD of two "rational floating point numbers", and this (also) justifies to treat differently the two situations.
I agree with that. |
comment:24
All right. Let us do it your way. (actually mine would be to not define floating point as a field ;-) |
Branch pushed to git repo; I updated commit sha1. This was a forced push. Last 10 new commits:
|
comment:26
I removed #17673 from the dependencies... I had to do a forced push to remove the commit coming from that branch. Vincent |
comment:27
It seems that I get the same problem you had in #17673, thus the tests in sage: P.<x> = QQ[]
sage: Q = P.quotient(x^2+2)
sage: Q in Fields()
True
sage: Q.an_element().gcd._module_
'sage.categories.fields' but the test doesn't pass, and I get |
comment:28
Yep. I forgot to change that. And the modification of gcd/lcm for floating point also causes some trouble for the symbolic ring. A commit is comming. Vincent |
Branch pushed to git repo; I updated commit sha1. New commits:
|
This comment has been minimized.
This comment has been minimized.
comment:31
All tests pass! LGTM. |
Reviewer: Bruno Grenet |
comment:32
Cool! Thanks for the review. |
Changed branch from u/vdelecroix/17671 to |
…ss the TestSuite <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> The output of `xgcd` does not match the `gcd` output, but this is required by sagemath#17671. We change the computation to make these match. We also fix another bug as it should also take non-Laurent polynomial inputs to `xgcd`. We also implement the `euclidean_domain()` method. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#37778 Reported by: Travis Scrimshaw Reviewer(s): Enrique Manuel Artal Bartolo, Travis Scrimshaw
…ss the TestSuite <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> The output of `xgcd` does not match the `gcd` output, but this is required by sagemath#17671. We change the computation to make these match. We also fix another bug as it should also take non-Laurent polynomial inputs to `xgcd`. We also implement the `euclidean_domain()` method. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#37778 Reported by: Travis Scrimshaw Reviewer(s): Enrique Manuel Artal Bartolo, Travis Scrimshaw
As reported on sage-support, gcd and xgcd disagree on fraction fields
In this ticket we:
gcd
andxgcd
are compatible over quotient fields by implementing thexgcd
in the appropriate place. In particular, with that branch we havexgcd
for trivial cases inrings.polynomial.polynomial_element_generic.Polynomial_generic_field
in order thatgcd
andxgcd
agree for them._test_gcd_vs_xgcd
in the categoryPrincipalIdealDomains
to ensure the compatibility ofgcd
andxgcd
.The only difference is that now, Sage returns floating point with the same parent
And the same kind of behavior will also hold for lcm and xgcd.
Note:
There is a method
xgcd
implemented for univariate polynomial over ZZ.This is not a proper name since it has nothing to do withThis might not be the best name since the first term is not the gcd in general (see this sage-devel thread and #17674)gcd
Depends on #17675
Component: basic arithmetic
Author: Vincent Delecroix
Branch/Commit:
2e0d79e
Reviewer: Bruno Grenet
Issue created by migration from https://trac.sagemath.org/ticket/17671
The text was updated successfully, but these errors were encountered: