Commit fee930ef authored by MARCHE Claude's avatar MARCHE Claude

fix mistakes in Coq driver related to division and modulo

parent 3a1212a5
...@@ -96,6 +96,10 @@ theory int.MinMax ...@@ -96,6 +96,10 @@ theory int.MinMax
end end
(* removed: Coq Zdiv is NOT true Euclidean division:
Zmod can be negative, in fact (Zmod x y) has the same sign as y,
which is not the usual convention of programming language either.
theory int.EuclideanDivision theory int.EuclideanDivision
prelude "Require Import Zdiv." prelude "Require Import Zdiv."
...@@ -110,9 +114,14 @@ theory int.EuclideanDivision ...@@ -110,9 +114,14 @@ theory int.EuclideanDivision
remove prop Div_1 remove prop Div_1
end end
*)
theory int.ComputerDivision theory int.ComputerDivision
(* Coq Z0div provides the division and modulo operators
with the same convention as mainstream programming language
such C, Java, OCaml *)
prelude "Require Import ZOdiv." prelude "Require Import ZOdiv."
syntax function div "(ZOdiv %1 %2)" syntax function div "(ZOdiv %1 %2)"
......
...@@ -10,7 +10,11 @@ Find the sum of all the multiples of 3 or 5 below 1000. ...@@ -10,7 +10,11 @@ Find the sum of all the multiples of 3 or 5 below 1000.
theory DivModHints theory DivModHints
use import int.Int use import int.Int
use import int.EuclideanDivision use import int.ComputerDivision
lemma mod_div_unique :
forall x y q r:int. y > 0 /\ x = q*y + r /\ 0 <= r < y ->
r = mod x y /\ q = div x y
lemma mod_succ_1 : lemma mod_succ_1 :
forall x y:int. x >= 0 /\ y > 0 -> forall x y:int. x >= 0 /\ y > 0 ->
...@@ -34,7 +38,7 @@ end ...@@ -34,7 +38,7 @@ end
theory SumMultiple theory SumMultiple
use import int.Int use import int.Int
use import int.EuclideanDivision use import int.ComputerDivision
(* [sum_multiple_3_5_lt n] is the sum of all the multiples (* [sum_multiple_3_5_lt n] is the sum of all the multiples
of 3 or 5 below n] *) of 3 or 5 below n] *)
...@@ -64,6 +68,10 @@ theory SumMultiple ...@@ -64,6 +68,10 @@ theory SumMultiple
use DivModHints use DivModHints
lemma mod_15:
forall n:int.
mod n 15 = 0 <-> mod n 3 = 0 /\ mod n 5 = 0
lemma Closed_formula_n: lemma Closed_formula_n:
forall n:int. n > 0 -> p (n-1) -> forall n:int. n > 0 -> p (n-1) ->
mod n 3 <> 0 /\ mod n 5 <> 0 -> p n mod n 3 <> 0 /\ mod n 5 <> 0 -> p n
...@@ -91,7 +99,7 @@ module Euler001 ...@@ -91,7 +99,7 @@ module Euler001
use import SumMultiple use import SumMultiple
use import int.Int use import int.Int
use import int.EuclideanDivision use import int.ComputerDivision
let solve n = let solve n =
{ n >= 1 } { n >= 1 }
......
This diff is collapsed.
...@@ -49,6 +49,9 @@ end ...@@ -49,6 +49,9 @@ end
theory EuclideanDivision theory EuclideanDivision
(* division and modulo operators with the convention that division
rounds down, and thus modulo is always non-negative *)
use import Int use import Int
use import Abs use import Abs
...@@ -72,6 +75,11 @@ end ...@@ -72,6 +75,11 @@ end
theory ComputerDivision theory ComputerDivision
(* division and modulo operators with the same conventions as
mainstream programming language such C, Java, OCaml, that is
division rounds towards zero, and thus (x mod y) as the same sign
as x *)
use import Int use import Int
use import Abs use import Abs
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment