-
Notifications
You must be signed in to change notification settings - Fork 70
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
Fix Z.gcd when exactly one argument is zero #39
Conversation
OK, why not? But your patch only handles the case where both arguments are small integers. The case gcd(0,big_number) would require extra modifications. |
On 18/10/2018 10:07, Antoine Miné wrote:
OK, why not? But your patch only handles the case where both arguments are small integers. The case gcd(0,big_number) would require extra modifications.
Unfortunately, a similar modification in the slow path produces
segmentation faults…
As per the documentation
https://gmplib.org/manual/Low_002dlevel-Functions.html#index-mpn_005fgcd, this
is expected. Any hint on how to work around this is welcome.
Also, is there any sense in stating gcd(0,0)=0, given that gcd(a,a)=a holds for a > 0 ?
The higher-level function mpz_gcd does this
(https://gmplib.org/manual/Number-Theoretic-Functions.html#index-mpz_005fgcd).
|
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
gcdext remains defined only if both arguments are non-zero
OK. I added support for gcd(0,large_integer) and gcd(0,0). |
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
Your last change Antoine looks good to me. I’ve run the test-suite of Coq on branch coq/coq#8743 without Emilio’s workaround using this fix: there are a few issues but none seems related to a failing GCD computation. Thanks again. |
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
Thanks for merging. Can we expect a release including this change? Thanks. |
Yes, I've made a 1.8 release with this fix. |
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
We workaround a bug in Zarith's `gcd`. Indeed, `gcd n 0` when `n != 0` should be `n`. The problem can be witnessed here: ``` utop # Big_int_Z.(gcd_big_int zero_big_int unit_big_int);; Exception: Division_by_zero. utop # Big_int.(gcd_big_int zero_big_int unit_big_int);; - : Big_int.big_int = <big_int 1> ``` c.f: ocaml/Zarith#39
Congruences tests need zarith.1.8 to pass: ocaml/Zarith#39 in https://github.com/ocaml/Zarith/releases/tag/release-1.8.
The GCD operator is well defined when exactly one of its argument is zero. It should not raise a division-by-zero exception.