Skip to content

Commit

Permalink
[zarith] [micromega] Bump to 1.10.0 and remove some hacks
Browse files Browse the repository at this point in the history
In particular, behavior of `Z.gcd` and `Z.lcm` has been fixed in
1.10.0, see

ocaml/Zarith#58
  • Loading branch information
ejgallego committed Sep 14, 2020
1 parent 9a84ffd commit 0f4fceb
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ stages:
variables:
# Format: $IMAGE-V$DATE [Cache is not used as of today but kept here
# for reference]
CACHEKEY: "bionic_coq-V2020-08-28-V92"
CACHEKEY: "bionic_coq-V2020-09-15-V83"
IMAGE: "$CI_REGISTRY_IMAGE:$CACHEKEY"
# By default, jobs run in the base switch; override to select another switch
OPAM_SWITCH: "base"
Expand Down
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To compile Coq yourself, you need:
- The [num](https://github.com/ocaml/num) library; note that it is
included in the OCaml distribution for OCaml versions < 4.06.0

- The [ZArith library](https://github.com/ocaml/Zarith) >= 1.8
- The [ZArith library](https://github.com/ocaml/Zarith) >= 1.10

- The [findlib](http://projects.camlcity.org/projects/findlib.html) library (version >= 1.8.0)

Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
opam switch set ocaml-base-compiler.$COMPILER
eval $(opam env)
opam update
opam install -j "$NJOBS" num ocamlfind${FINDLIB_VER} ounit lablgtk3-sourceview3 zarith.1.9.1
opam install -j "$NJOBS" num ocamlfind${FINDLIB_VER} ounit lablgtk3-sourceview3 zarith.1.10.0
opam list
displayName: 'Install OCaml dependencies'
env:
Expand Down
2 changes: 1 addition & 1 deletion coq.opam
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ depends: [
"dune" { >= "2.5.0" }
"ocamlfind" { build }
"num"
"zarith" { >= "1.9.1" }
"zarith" { >= "1.10.0" }
]

build: [
Expand Down
2 changes: 1 addition & 1 deletion coq.opam.docker
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ depends: [
"ocaml" { >= "4.05.0" }
"ocamlfind" { build }
"num"
"zarith" { >= "1.9.1" }
"zarith" { >= "1.10.0" }
"conf-findutils" {build}
]

Expand Down
2 changes: 1 addition & 1 deletion dev/build/windows/makecoq_mingw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ function make_num {

function make_zarith {
make_ocaml
if build_prep https://github.com/ocaml/Zarith/archive release-1.9.1 tar.gz 1 zarith-1.9.1; then
if build_prep https://github.com/ocaml/Zarith/archive release-1.10.0 tar.gz 1 zarith-1.10.0; then
logn configure ./configure
log1 make
log2 make install
Expand Down
6 changes: 3 additions & 3 deletions dev/ci/docker/bionic_coq/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CACHEKEY: "bionic_coq-V2020-08-28-V92"
# CACHEKEY: "bionic_coq-V2020-09-15-V83"
# ^^ Update when modifying this file.

FROM ubuntu:bionic
Expand Down Expand Up @@ -43,7 +43,7 @@ ENV COMPILER="4.05.0"
# Common OPAM packages, num to be removed once the migration to
# micromega is complete, `num` also does not have a version number as
# the right version to install varies with the compiler version.
ENV BASE_OPAM="num zarith.1.9.1 ocamlfind.1.8.1 ounit2.2.2.3 odoc.1.5.0" \
ENV BASE_OPAM="num zarith.1.10.0 ocamlfind.1.8.1 ounit2.2.2.3 odoc.1.5.0" \
CI_OPAM="menhir.20190626 ocamlgraph.1.8.8" \
BASE_ONLY_OPAM="elpi.1.11.0"

Expand All @@ -59,7 +59,7 @@ RUN opam init -a --disable-sandboxing --compiler="$COMPILER" default https://opa

# base+32bit switch, note the zarith hack
RUN opam switch create "${COMPILER}+32bit" && eval $(opam env) && \
i386 env CC='gcc -m32' opam install zarith.1.9.1 && \
i386 env CC='gcc -m32' opam install zarith.1.10.0 && \
opam install $BASE_OPAM

# EDGE switch
Expand Down
13 changes: 5 additions & 8 deletions plugins/micromega/numCompat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ module type ZArith = sig
end

module Z = struct
(* Beware this only works fine in ZArith >= 1.10.0 due to
https://github.com/ocaml/Zarith/issues/58 *)
include Z

(* Constants *)
Expand All @@ -39,13 +41,8 @@ module Z = struct
let power_int = Big_int_Z.power_big_int_positive_int
let quomod = Big_int_Z.quomod_big_int

(* Workaround https://github.com/ocaml/Zarith/issues/58 , remove
the abs when zarith 1.9.2 is released *)
let gcd x y = Z.abs (Z.gcd x y)

(* zarith fails with division by zero if x && y == 0 *)
let lcm x y =
if Z.equal x zero && Z.equal y zero then zero else Z.abs (Z.lcm x y)
(* zarith fails with division by zero if x == 0 && y == 0 *)
let lcm x y = if Z.equal x zero && Z.equal y zero then zero else Z.lcm x y

let ppcm x y =
let g = gcd x y in
Expand Down Expand Up @@ -144,7 +141,7 @@ module Q : QArith with module Z = Z = struct
let ceiling q : t = Z.cdiv (Q.num q) (Q.den q) |> Q.of_bigint
let half = Q.make Z.one Z.two

(* Num round is to the nearest *)
(* We imitate Num's round which is to the nearest *)
let round q = floor (Q.add half q)

(* XXX: review / improve *)
Expand Down
7 changes: 7 additions & 0 deletions plugins/micromega/numCompat.mli
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ module type ZArith = sig
val power_int : t -> int -> t
val quomod : t -> t -> t * t
val ppcm : t -> t -> t

(** [gcd x y] Greatest Common Divisor. Must always return a
positive number *)
val gcd : t -> t -> t

(** [lcm x y] Least Common Multiplier. Must always return a
positive number *)
val lcm : t -> t -> t

val to_string : t -> string
end

Expand Down

0 comments on commit 0f4fceb

Please sign in to comment.