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

Fix Z.gcd when exactly one argument is zero #39

Merged
merged 3 commits into from
Mar 4, 2019

Conversation

vbgl
Copy link
Contributor

@vbgl vbgl commented Oct 18, 2018

The GCD operator is well defined when exactly one of its argument is zero. It should not raise a division-by-zero exception.

@antoinemine
Copy link
Collaborator

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.
Also, is there any sense in stating gcd(0,0)=0, given that gcd(a,a)=a holds for a > 0 ?

@vbgl
Copy link
Contributor Author

vbgl commented Oct 18, 2018 via email

ejgallego added a commit to ejgallego/coq that referenced this pull request Oct 18, 2018
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
@antoinemine
Copy link
Collaborator

OK. I added support for gcd(0,large_integer) and gcd(0,0).
Feedbacks are welcome before I merge into master.

ejgallego added a commit to ejgallego/coq that referenced this pull request Oct 18, 2018
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
ejgallego added a commit to ejgallego/coq that referenced this pull request Oct 18, 2018
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
ejgallego added a commit to ejgallego/coq that referenced this pull request Oct 18, 2018
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
ejgallego added a commit to ejgallego/coq that referenced this pull request Oct 23, 2018
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
ejgallego added a commit to ejgallego/coq that referenced this pull request Oct 25, 2018
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
ejgallego added a commit to ejgallego/coq that referenced this pull request Oct 25, 2018
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
ejgallego added a commit to ejgallego/coq that referenced this pull request Nov 17, 2018
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
ejgallego added a commit to ejgallego/coq that referenced this pull request Nov 17, 2018
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
ejgallego added a commit to ejgallego/coq that referenced this pull request Nov 20, 2018
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
ejgallego added a commit to ejgallego/coq that referenced this pull request Dec 6, 2018
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
ejgallego added a commit to ejgallego/coq that referenced this pull request Jan 31, 2019
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
ejgallego added a commit to ejgallego/coq that referenced this pull request Mar 4, 2019
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
@vbgl
Copy link
Contributor Author

vbgl commented Mar 4, 2019

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.

@antoinemine antoinemine merged commit 9ab3443 into ocaml:master Mar 4, 2019
@vbgl vbgl deleted the fix-gcd-zero branch March 4, 2019 14:24
ejgallego added a commit to ejgallego/coq that referenced this pull request Mar 12, 2019
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
vbgl pushed a commit to vbgl/coq that referenced this pull request Mar 13, 2019
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
vbgl pushed a commit to ejgallego/coq that referenced this pull request Mar 13, 2019
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
ejgallego added a commit to ejgallego/coq that referenced this pull request Mar 20, 2019
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
ejgallego added a commit to ejgallego/coq that referenced this pull request Mar 21, 2019
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
@vbgl
Copy link
Contributor Author

vbgl commented Mar 26, 2019

Thanks for merging. Can we expect a release including this change? Thanks.

@antoinemine
Copy link
Collaborator

Thanks for merging. Can we expect a release including this change? Thanks.

Yes, I've made a 1.8 release with this fix.

ejgallego added a commit to ejgallego/coq that referenced this pull request Apr 8, 2019
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
ejgallego added a commit to ejgallego/coq that referenced this pull request Mar 2, 2020
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
ejgallego added a commit to ejgallego/coq that referenced this pull request Mar 2, 2020
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
ejgallego added a commit to ejgallego/coq that referenced this pull request Mar 2, 2020
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
sim642 added a commit to goblint/analyzer that referenced this pull request Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants