aboutsummaryrefslogtreecommitdiffhomepage
path: root/theories/Arith/Div.v
blob: 24f4ba36c7ed50c5c837786faf76a0f6da6e71ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
(***********************************************************************)
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team    *)
(* <O___,, *        INRIA-Rocquencourt  &  LRI-CNRS-Orsay              *)
(*   \VV/  *************************************************************)
(*    //   *      This file is distributed under the terms of the      *)
(*         *       GNU Lesser General Public License Version 2.1       *)
(***********************************************************************)

(* $Id$ *)

(* Euclidean division *)

Require Le.
Require Euclid_def.
Require Compare_dec.

Fixpoint inf_dec [n:nat] : nat->bool :=
      [m:nat] Cases n m of
                  O     _     => true
              | (S n')  O     => false
              | (S n') (S m') => (inf_dec n' m')
             end.

Theorem div1 : (b:nat)(gt b O)->(a:nat)(diveucl a b).
Realizer Fix div1 {div1/2: nat->nat->diveucl :=
  [b,a]Cases a of
         O     => (O,O)
       | (S n) =>
           let (q,r) = (div1 b n) in
             if (le_gt_dec b (S r)) then ((S q),O)
	     else (q,(S r))
       end}.
Program_all.
Rewrite e.
Replace b with (S r).
Simpl.
Elim plus_n_O; Auto with arith.
Apply le_antisym; Auto with arith.
Elim plus_n_Sm; Auto with arith.
Save.

Theorem div2 : (b:nat)(gt b O)->(a:nat)(diveucl a b).
Realizer Fix div1 {div1/2: nat->nat->diveucl :=
  [b,a]Cases a of
         O     => (O,O)
       | (S n) =>
           let (q,r) = (div1 b n) in
             if (inf_dec b (S r)) :: :: { {(le b (S r))}+{(gt b (S r))} }
             then ((S q),O)
	     else (q,(S r))
       end}.
Program_all.
Rewrite e.
Replace b with (S r).
Simpl.
Elim plus_n_O; Auto with arith.
Apply le_antisym; Auto with arith.
Elim plus_n_Sm; Auto with arith.
Save.