summaryrefslogtreecommitdiff
path: root/theories/Arith/Euclid.v
blob: e50e3d70179f20c8798dff28f4c15b8d9ab0f18c (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
60
61
62
63
64
65
66
67
68
(************************************************************************)
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team     *)
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
(*   \VV/  **************************************************************)
(*    //   *      This file is distributed under the terms of the       *)
(*         *       GNU Lesser General Public License Version 2.1        *)
(************************************************************************)

(*i $Id: Euclid.v,v 1.7.2.1 2004/07/16 19:31:00 herbelin Exp $ i*)

Require Import Mult.
Require Import Compare_dec.
Require Import Wf_nat.

Open Local Scope nat_scope.

Implicit Types a b n q r : nat.

Inductive diveucl a b : Set :=
    divex : forall q r, b > r -> a = q * b + r -> diveucl a b.


Lemma eucl_dev : forall n, n > 0 -> forall m:nat, diveucl m n.
intros b H a; pattern a in |- *; apply gt_wf_rec; intros n H0.
elim (le_gt_dec b n).
intro lebn.
elim (H0 (n - b)); auto with arith.
intros q r g e.
apply divex with (S q) r; simpl in |- *; auto with arith.
elim plus_assoc.
elim e; auto with arith.
intros gtbn.
apply divex with 0 n; simpl in |- *; auto with arith.
Qed.

Lemma quotient :
 forall n,
   n > 0 ->
   forall m:nat, {q : nat |  exists r : nat, m = q * n + r /\ n > r}.
intros b H a; pattern a in |- *; apply gt_wf_rec; intros n H0.
elim (le_gt_dec b n).
intro lebn.
elim (H0 (n - b)); auto with arith.
intros q Hq; exists (S q).
elim Hq; intros r Hr.
exists r; simpl in |- *; elim Hr; intros.
elim plus_assoc.
elim H1; auto with arith.
intros gtbn.
exists 0; exists n; simpl in |- *; auto with arith.
Qed.

Lemma modulo :
 forall n,
   n > 0 ->
   forall m:nat, {r : nat |  exists q : nat, m = q * n + r /\ n > r}.
intros b H a; pattern a in |- *; apply gt_wf_rec; intros n H0.
elim (le_gt_dec b n).
intro lebn.
elim (H0 (n - b)); auto with arith.
intros r Hr; exists r.
elim Hr; intros q Hq.
elim Hq; intros; exists (S q); simpl in |- *.
elim plus_assoc.
elim H1; auto with arith.
intros gtbn.
exists n; exists 0; simpl in |- *; auto with arith.
Qed.