Re: mini-gmp mpz_gcdext Bézout coefficients do not match documentation

2024-02-20 Thread Guido Vranken
I've confirmed with my fuzzer that the committed patch resolves the issues. Thanks. On Sun, Feb 18, 2024 at 8:27 PM Niels Möller wrote: > marco.bodr...@tutanota.com writes: > > > The only reason why I prefer my solution is: when cmp<0, there is no > need to compute > > mpz_sub (t1, t0, t1); > >

Re: mini-gmp mpz_gcdext Bézout coefficients do not match documentation

2024-02-18 Thread Niels Möller
marco.bodr...@tutanota.com writes: > The only reason why I prefer my solution is: when cmp<0, there is no need to > compute > mpz_sub (t1, t0, t1); That's certainly a micro optimization, but let's keep things simple. I've pushed this fix now, I think there were only comment and ChangeLog

Re: mini-gmp mpz_gcdext Bézout coefficients do not match documentation

2024-02-18 Thread marco . bodrato
Ciao Niels, 18 feb 2024, 10:10 da ni...@lysator.liu.se: > marco.bodr...@tutanota.com writes: > >> What about; >> >> >> /* Arrange so that |s| < |u| / 2g */ >>   mpz_add (s1, s0, s1); >>   { >>     int cmp = mpz_cmpabs (s0, s1); >>     if (cmp >= 0) >>   { >>     mpz_swap (s0, s1); >>

Re: mini-gmp mpz_gcdext Bézout coefficients do not match documentation

2024-02-18 Thread Niels Möller
marco.bodr...@tutanota.com writes: > s==0 is not a special case, it's one of the cases with smaller |s|. Right, s == 0 is not a special case in itself, what's special is the case g = a = b, then we have too candidate cofactor pairs, s=1, t=0, s'=0, t'= 1. And we have the asymmetric preference

Re: mini-gmp mpz_gcdext Bézout coefficients do not match documentation

2024-02-17 Thread marco . bodrato
Ciao Niels, 17 feb 2024, 21:26 da ni...@lysator.liu.se: > marco.bodr...@tutanota.com writes: > >> Maybe we should also add the test: >> >>   /* Require that s==0 iff g==abs(b) */ >>   if (!mpz_sgn (s) ^ !mpz_cmpabs (g, b)) >>   goto fail; >> > > Good point, that's better than only checking

Re: mini-gmp mpz_gcdext Bézout coefficients do not match documentation

2024-02-17 Thread Niels Möller
marco.bodr...@tutanota.com writes: > Maybe we should also add the test: > >   /* Require that s==0 iff g==abs(b) */ >   if (!mpz_sgn (s) ^ !mpz_cmpabs (g, b)) >   goto fail; Good point, that's better than only checking the special case |a| == |b|. (But maybe more readable with != instead of

Re: mini-gmp mpz_gcdext Bézout coefficients do not match documentation

2024-02-17 Thread marco . bodrato
Ciao, 17 feb 2024, 19:15 da : > Ciao Niels, > > 17 feb 2024, 17:53 da ni...@lysator.liu.se: > >> Niels Möller writes: >> The documented conditions say that gmp should return the same cofactors >> > > The documentation also says "If abs(a) = abs(b), then s = 0, t = sgn(b)." > Maybe we should

Re: mini-gmp mpz_gcdext Bézout coefficients do not match documentation

2024-02-17 Thread Niels Möller
marco.bodr...@tutanota.com writes: > And if I correctly patched and tested your proposed code. with equal numbers > I get t=0, instead of s=0. Thanks for testing, I have to look into that case, then. > Shat about simply changing the test from > to >= ? > >    /* Arrange so that |s| < |u| / 2g

Re: mini-gmp mpz_gcdext Bézout coefficients do not match documentation

2024-02-17 Thread marco . bodrato
Ciao Niels, 17 feb 2024, 17:53 da ni...@lysator.liu.se: > Niels Möller writes: > The documented conditions say that gmp should return the same cofactors > The documentation also says "If abs(a) = abs(b), then s = 0, t = sgn(b)." > > canonicalization logic at the end wasn't right. Appending a

Re: mini-gmp mpz_gcdext Bézout coefficients do not match documentation

2024-02-17 Thread Niels Möller
Niels Möller writes: > Guido Vranken writes: > >> Computing extended gcd using mpz_gcdext where a = 1, b = 2: >> >> libgmp: g: 1, s: 1, t: 0 >> mini-gmp: g: 1, s: -1, t: 1 >> This violates the docs: "s = sgn(a) if abs(b) = 2", e.g. s must be 1 >> >> Computing extended gcd using mpz_gcdext where

Re: mini-gmp mpz_gcdext Bézout coefficients do not match documentation

2024-02-17 Thread Niels Möller
Guido Vranken writes: > Computing extended gcd using mpz_gcdext where a = 1, b = 2: > > libgmp: g: 1, s: 1, t: 0 > mini-gmp: g: 1, s: -1, t: 1 > This violates the docs: "s = sgn(a) if abs(b) = 2", e.g. s must be 1 > > Computing extended gcd using mpz_gcdext where a = 6, b = 4: > libgmp: g: 2, s:

mini-gmp mpz_gcdext Bézout coefficients do not match documentation

2024-02-17 Thread Guido Vranken
Computing extended gcd using mpz_gcdext where a = 1, b = 2: libgmp: g: 1, s: 1, t: 0 mini-gmp: g: 1, s: -1, t: 1 This violates the docs: "s = sgn(a) if abs(b) = 2", e.g. s must be 1 Computing extended gcd using mpz_gcdext where a = 6, b = 4: libgmp: g: 2, s: 1, t: -1 mini-libgmp: g: 2, s: -1, t: