| author | wenzelm | 
| Sun, 21 May 2000 14:37:17 +0200 | |
| changeset 8899 | 99266fe189a1 | 
| parent 5147 | 825877190618 | 
| child 9491 | 1a36151ee2fc | 
| permissions | -rw-r--r-- | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
1  | 
(* Title: ZF/ex/Primes.ML  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
2  | 
ID: $Id$  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
3  | 
Author: Christophe Tabacznyj and Lawrence C Paulson  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
4  | 
Copyright 1996 University of Cambridge  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
5  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
6  | 
The "divides" relation, the greatest common divisor and Euclid's algorithm  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
7  | 
*)  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
8  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
9  | 
eta_contract:=false;  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
10  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
11  | 
open Primes;  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
12  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
13  | 
(************************************************)  | 
| 1793 | 14  | 
(** Divides Relation **)  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
15  | 
(************************************************)  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
16  | 
|
| 5137 | 17  | 
Goalw [dvd_def] "m dvd n ==> m:nat & n:nat & (EX k:nat. n = m#*k)";  | 
| 1793 | 18  | 
by (assume_tac 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
19  | 
qed "dvdD";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
20  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
21  | 
bind_thm ("dvd_imp_nat1", dvdD RS conjunct1);
 | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
22  | 
bind_thm ("dvd_imp_nat2", dvdD RS conjunct2 RS conjunct1);
 | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
23  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
24  | 
|
| 5137 | 25  | 
Goalw [dvd_def] "m:nat ==> m dvd 0";  | 
| 4091 | 26  | 
by (fast_tac (claset() addIs [nat_0I, mult_0_right RS sym]) 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
27  | 
qed "dvd_0_right";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
28  | 
|
| 5137 | 29  | 
Goalw [dvd_def] "0 dvd m ==> m = 0";  | 
| 4091 | 30  | 
by (fast_tac (claset() addss (simpset())) 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
31  | 
qed "dvd_0_left";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
32  | 
|
| 5137 | 33  | 
Goalw [dvd_def] "m:nat ==> m dvd m";  | 
| 4091 | 34  | 
by (fast_tac (claset() addIs [nat_1I, mult_1_right RS sym]) 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
35  | 
qed "dvd_refl";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
36  | 
|
| 5137 | 37  | 
Goalw [dvd_def] "[| m dvd n; n dvd p |] ==> m dvd p";  | 
| 4091 | 38  | 
by (fast_tac (claset() addIs [mult_assoc, mult_type] ) 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
39  | 
qed "dvd_trans";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
40  | 
|
| 5137 | 41  | 
Goalw [dvd_def] "[| m dvd n; n dvd m |] ==> m=n";  | 
| 4091 | 42  | 
by (fast_tac (claset() addDs [mult_eq_self_implies_10]  | 
43  | 
addss (simpset() addsimps [mult_assoc, mult_eq_1_iff])) 1);  | 
|
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
44  | 
qed "dvd_anti_sym";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
45  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
46  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
47  | 
(************************************************)  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
48  | 
(** Greatest Common Divisor **)  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
49  | 
(************************************************)  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
50  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
51  | 
(* GCD by Euclid's Algorithm *)  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
52  | 
|
| 5137 | 53  | 
Goalw [egcd_def] "m:nat ==> egcd(m,0) = m";  | 
| 2034 | 54  | 
by (stac transrec 1);  | 
| 2469 | 55  | 
by (Asm_simp_tac 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
56  | 
qed "egcd_0";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
57  | 
|
| 5068 | 58  | 
Goalw [egcd_def]  | 
| 
5147
 
825877190618
More tidying and removal of "\!\!... from Goal commands
 
paulson 
parents: 
5137 
diff
changeset
 | 
59  | 
"[| 0<n; m:nat; n:nat |] ==> egcd(m,n) = egcd(n, m mod n)";  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
60  | 
by (res_inst_tac [("P", "%z. ?left(z) = ?right")] (transrec RS ssubst) 1);
 | 
| 4091 | 61  | 
by (asm_simp_tac (simpset() addsimps [ltD RS mem_imp_not_eq RS not_sym,  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
62  | 
mod_less_divisor RS ltD]) 1);  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
63  | 
qed "egcd_lt_0";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
64  | 
|
| 5137 | 65  | 
Goal "m:nat ==> egcd(m,0) dvd m";  | 
| 4091 | 66  | 
by (asm_simp_tac (simpset() addsimps [egcd_0,dvd_refl]) 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
67  | 
qed "egcd_0_dvd_m";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
68  | 
|
| 5137 | 69  | 
Goal "m:nat ==> egcd(m,0) dvd 0";  | 
| 4091 | 70  | 
by (asm_simp_tac (simpset() addsimps [egcd_0,dvd_0_right]) 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
71  | 
qed "egcd_0_dvd_0";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
72  | 
|
| 5137 | 73  | 
Goalw [dvd_def] "[| k dvd a; k dvd b |] ==> k dvd (a #+ b)";  | 
| 4091 | 74  | 
by (fast_tac (claset() addIs [add_mult_distrib_left RS sym, add_type]) 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
75  | 
qed "dvd_add";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
76  | 
|
| 5137 | 77  | 
Goalw [dvd_def] "[| k dvd a; q:nat |] ==> k dvd (q #* a)";  | 
| 4091 | 78  | 
by (fast_tac (claset() addIs [mult_left_commute, mult_type]) 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
79  | 
qed "dvd_mult";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
80  | 
|
| 5137 | 81  | 
Goal "[| k dvd b; k dvd (a mod b); 0 < b; a:nat |] ==> k dvd a";  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
82  | 
by (deepen_tac  | 
| 4091 | 83  | 
(claset() addIs [mod_div_equality RS subst]  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
84  | 
addDs [dvdD]  | 
| 1793 | 85  | 
addSIs [dvd_add, dvd_mult, mult_type,mod_type,div_type]) 0 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
86  | 
qed "gcd_ind";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
87  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
88  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
89  | 
(* egcd type *)  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
90  | 
|
| 5137 | 91  | 
Goal "b:nat ==> ALL a:nat. egcd(a,b):nat";  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
92  | 
by (etac complete_induct 1);  | 
| 1793 | 93  | 
by (rtac ballI 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
94  | 
by (excluded_middle_tac "x=0" 1);  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
95  | 
(* case x = 0 *)  | 
| 4091 | 96  | 
by (asm_simp_tac (simpset() addsimps [egcd_0]) 2);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
97  | 
(* case x > 0 *)  | 
| 4091 | 98  | 
by (asm_simp_tac (simpset() addsimps [egcd_lt_0, nat_into_Ord RS Ord_0_lt]) 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
99  | 
by (eres_inst_tac [("x","a mod x")] ballE 1);
 | 
| 2469 | 100  | 
by (Asm_simp_tac 1);  | 
| 4091 | 101  | 
by (asm_full_simp_tac (simpset() addsimps [mod_less_divisor RS ltD,  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
102  | 
nat_into_Ord RS Ord_0_lt]) 1);  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
103  | 
qed "egcd_type";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
104  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
105  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
106  | 
(* Property 1: egcd(a,b) divides a and b *)  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
107  | 
|
| 5137 | 108  | 
Goal "b:nat ==> ALL a: nat. (egcd(a,b) dvd a) & (egcd(a,b) dvd b)";  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
109  | 
by (res_inst_tac [("i","b")] complete_induct 1);
 | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
110  | 
by (assume_tac 1);  | 
| 1793 | 111  | 
by (rtac ballI 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
112  | 
by (excluded_middle_tac "x=0" 1);  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
113  | 
(* case x = 0 *)  | 
| 4091 | 114  | 
by (asm_simp_tac (simpset() addsimps [egcd_0,dvd_refl,dvd_0_right]) 2);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
115  | 
(* case x > 0 *)  | 
| 4091 | 116  | 
by (asm_simp_tac (simpset() addsimps [egcd_lt_0, nat_into_Ord RS Ord_0_lt]) 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
117  | 
by (eres_inst_tac [("x","a mod x")] ballE 1);
 | 
| 2469 | 118  | 
by (Asm_simp_tac 1);  | 
| 4091 | 119  | 
by (asm_full_simp_tac (simpset() addsimps [mod_less_divisor RS ltD,  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
120  | 
nat_into_Ord RS Ord_0_lt]) 2);  | 
| 4091 | 121  | 
by (best_tac (claset() addIs [gcd_ind, nat_into_Ord RS Ord_0_lt]) 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
122  | 
qed "egcd_prop1";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
123  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
124  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
125  | 
(* if f divides a and b then f divides egcd(a,b) *)  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
126  | 
|
| 5137 | 127  | 
Goalw [dvd_def] "[| f dvd a; f dvd b; 0<b |] ==> f dvd (a mod b)";  | 
| 4091 | 128  | 
by (safe_tac (claset() addSIs [mult_type, mod_type]));  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
129  | 
ren "m n" 1;  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
130  | 
by (rtac (zero_lt_mult_iff RS iffD1 RS conjE) 1);  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
131  | 
by (REPEAT_SOME assume_tac);  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
132  | 
by (res_inst_tac  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
133  | 
    [("x", "(((m div n)#*n #+ m mod n) #- ((f#*m) div (f#*n)) #* n)")] 
 | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
134  | 
bexI 1);  | 
| 4091 | 135  | 
by (asm_simp_tac (simpset() addsimps [diff_mult_distrib2, div_cancel,  | 
| 1793 | 136  | 
mult_mod_distrib, add_mult_distrib_left,  | 
137  | 
diff_add_inverse]) 1);  | 
|
| 2469 | 138  | 
by (Asm_simp_tac 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
139  | 
qed "dvd_mod";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
140  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
141  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
142  | 
(* Property 2: for all a,b,f naturals,  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
143  | 
if f divides a and f divides b then f divides egcd(a,b)*)  | 
| 5137 | 144  | 
Goal "[| b:nat; f:nat |] ==> \  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
145  | 
\ ALL a. (f dvd a) & (f dvd b) --> f dvd egcd(a,b)";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
146  | 
by (etac complete_induct 1);  | 
| 1793 | 147  | 
by (rtac allI 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
148  | 
by (excluded_middle_tac "x=0" 1);  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
149  | 
(* case x = 0 *)  | 
| 4091 | 150  | 
by (asm_simp_tac (simpset() addsimps [egcd_0,dvd_refl,dvd_0_right,  | 
| 1793 | 151  | 
dvd_imp_nat2]) 2);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
152  | 
(* case x > 0 *)  | 
| 4152 | 153  | 
by Safe_tac;  | 
| 4091 | 154  | 
by (asm_simp_tac (simpset() addsimps [egcd_lt_0, nat_into_Ord RS Ord_0_lt,  | 
| 1793 | 155  | 
dvd_imp_nat2]) 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
156  | 
by (eres_inst_tac [("x","a mod x")] ballE 1);
 | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
157  | 
by (asm_full_simp_tac  | 
| 4091 | 158  | 
(simpset() addsimps [mod_less_divisor RS ltD, dvd_imp_nat2,  | 
| 1793 | 159  | 
nat_into_Ord RS Ord_0_lt, egcd_lt_0]) 2);  | 
| 4091 | 160  | 
by (fast_tac (claset() addSIs [dvd_mod, nat_into_Ord RS Ord_0_lt]) 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
161  | 
qed "egcd_prop2";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
162  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
163  | 
(* GCD PROOF : GCD exists and egcd fits the definition *)  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
164  | 
|
| 5137 | 165  | 
Goalw [gcd_def] "[| a: nat; b:nat |] ==> gcd(egcd(a,b), a, b)";  | 
| 4091 | 166  | 
by (asm_simp_tac (simpset() addsimps [egcd_prop1]) 1);  | 
167  | 
by (fast_tac (claset() addIs [egcd_prop2 RS spec RS mp, dvd_imp_nat1]) 1);  | 
|
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
168  | 
qed "gcd";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
169  | 
|
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
170  | 
(* GCD is unique *)  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
171  | 
|
| 5137 | 172  | 
Goalw [gcd_def] "gcd(m,a,b) & gcd(n,a,b) --> m=n";  | 
| 4091 | 173  | 
by (fast_tac (claset() addIs [dvd_anti_sym]) 1);  | 
| 
1792
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
174  | 
qed "gcd_unique";  | 
| 
 
75c54074cd8c
The "divides" relation, the greatest common divisor and Euclid's algorithm
 
paulson 
parents:  
diff
changeset
 | 
175  |