Skip to content
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

xgcd result violates the documentation #22237

Open
sagetrac-msaaltink mannequin opened this issue Jan 22, 2017 · 1 comment
Open

xgcd result violates the documentation #22237

sagetrac-msaaltink mannequin opened this issue Jan 22, 2017 · 1 comment

Comments

@sagetrac-msaaltink
Copy link
Mannequin

sagetrac-msaaltink mannequin commented Jan 22, 2017

In its documentation, xgcd(a,b) promises to return a triple "(g,s,t)" such that g = sa + tb (although it notes that we may not have g = gcd(a,b) when they belong to a ring that is not a PID). We do not always get this equality; here is an example in sage-7.5.1:

sage: _.<x> = Integers(4)[]
sage: a = x - 1
sage: b = 2*x + 1
sage: g,s,t = xgcd(a,b); g,s,t
(2,1,3)
sage: g == a*s + b*t
False
sage: a.resultant(b)
3

It is difficult to know how g=2 arises here! The documentation for a.xgcd, which no doubt gets called here, is less clear, saying only "Computes extended gcd of self and other" without giving any guarantees.

In particular in cases where the ideal (a,b) is the whole ring so that b should have an inverse mod a, this can make the computation of inverse_mod fail:

sage: _.<x> = Integers(4)[]
sage: a = x^2 + x + 1
sage: b = 2*x + 1
sage: g,s,t = xgcd(a,b); g,s,t
(1, 1, 3*x)
sage: a*s + b*t
3*x^2 + 1
sage: b.inverse_mod(a)
3*x
sage: (b.inverse_mod(a) * b) % a
x + 2
sage: b*b
1

So while b has an inverse (mod anything, in this ring), inverse_mod does not compute it.

There has been prior discussion over xgcd in rings that are not PIDs, such as we have here, in #17674 and https://groups.google.com/forum/#!topic/sage-devel/JV8fCPUqTzo, and related issues with inverse_mod have been noted before in #15788.

Component: algebra

Keywords: xgcd, inverse_mod, bezout coefficients

Author: Mark Saaltink

Issue created by migration from https://trac.sagemath.org/ticket/22237

@sagetrac-msaaltink sagetrac-msaaltink mannequin added this to the sage-7.6 milestone Jan 22, 2017
@defeo
Copy link
Member

defeo commented Feb 15, 2018

comment:1

This just popped up again in this StackOverflow question: https://stackoverflow.com/questions/48777337/.

Here's another very basic example

sage: _.<a> = Zmod(4)[]
sage: gcd(a^2 - 1, (a-1)^2)
1
sage: xgcd(a^2 - 1, (a-1)^2)
(1, 3*a, a + 2)

There's tons of people out there wanting to use Sage for playing with lattice-based crypto. We should do something about this (although I know it is quite painful to get gcds right for non-PIDs).

@mkoeppe mkoeppe removed this from the sage-7.6 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants