see http://caml.inria.fr/mantis/view.php?id=6749

On Sat, Apr 18, 2015 at 7:14 PM, Tao Stein <taostein@gmail.com> wrote:

I'm getting a strange result using ocamlopt that seems to violate the basic axioms of integer division.

Some context first:
taostein@~/b2/f2: which ocamlopt
/Users/taostein/.opam/4.02.1/bin/ocamlopt
taostein@~/b2/f2: ocamlopt -o foo.opt foo.ml
taostein@~/b2/f2: which ocamlc
/Users/taostein/.opam/4.02.1/bin/ocamlc
taostein@~/artcode/b2/f2: ocamlc -o foo foo.ml

Built with ocamlopt, the following code throws an exception. Built with ocamlc it does not.

let k1 = 1;;
let rec f i k =
  if (((i / k1) * k1 + (i mod k1)) <> i)
  then (raise (Failure "violation of integer division axiom"))
  else (if (i < 10) then (f (i + 1) k) else ()) in
f 0 1;;

Now, if I change the above only on line 3 changing k1 to k, then it works fine, no problem.

let k1 = 1;;
let rec f i k =
  if (((i / k) * k + (i mod k)) <> i)
  then (raise (Failure "violation of integer division axiom"))
  else (if (i < 10) then (f (i + 1) k) else ()) in
f 0 1;;

No exception in either ocamlc or ocamlopt.

Using ocamlopt, it seems 1 mod 1 = 1. This is problematic.

Tao Stein / 石涛