src/ZF/ex/Primes.ML
author wenzelm
Tue, 04 Apr 2000 18:08:08 +0200
changeset 8666 6c21e6f91804
parent 5147 825877190618
child 9491 1a36151ee2fc
permissions -rw-r--r--
case_tac / induct_tac: optional rule;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
09fff2f0d727 New example of GCDs and divides relation
paulson
parents: 1792
diff changeset
    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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
    17
Goalw [dvd_def] "m dvd n ==> m:nat & n:nat & (EX k:nat. n = m#*k)";
1793
09fff2f0d727 New example of GCDs and divides relation
paulson
parents: 1792
diff changeset
    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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
    25
Goalw [dvd_def] "m:nat ==> m dvd 0";
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
    29
Goalw [dvd_def] "0 dvd m ==> m = 0";
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
    33
Goalw [dvd_def] "m:nat ==> m dvd m";
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
    37
Goalw [dvd_def] "[| m dvd n; n dvd p |] ==> m dvd p";
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
    41
Goalw [dvd_def] "[| m dvd n; n dvd m |] ==> m=n";
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    42
by (fast_tac (claset() addDs [mult_eq_self_implies_10]
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
    53
Goalw [egcd_def] "m:nat ==> egcd(m,0) = m";
2034
5079fdf938dd Ran expandshort; used stac instead of ssubst
paulson
parents: 1793
diff changeset
    54
by (stac transrec 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2034
diff changeset
    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
fb28eaa07e01 isatool fixgoal;
wenzelm
parents: 4152
diff changeset
    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
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
    65
Goal "m:nat ==> egcd(m,0) dvd m";
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
    69
Goal "m:nat ==> egcd(m,0) dvd 0";
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
    73
Goalw [dvd_def] "[| k dvd a; k dvd b |] ==> k dvd (a #+ b)";
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
    77
Goalw [dvd_def] "[| k dvd a; q:nat |] ==> k dvd (q #* a)";
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
    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
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    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
09fff2f0d727 New example of GCDs and divides relation
paulson
parents: 1792
diff changeset
    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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
    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
09fff2f0d727 New example of GCDs and divides relation
paulson
parents: 1792
diff changeset
    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
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    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
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    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
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2034
diff changeset
   100
by (Asm_simp_tac 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
   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
09fff2f0d727 New example of GCDs and divides relation
paulson
parents: 1792
diff changeset
   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
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   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
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   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
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2034
diff changeset
   118
by (Asm_simp_tac 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   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
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
   127
Goalw [dvd_def] "[| f dvd a; f dvd b; 0<b |] ==> f dvd (a mod b)";
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   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
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   135
by (asm_simp_tac (simpset() addsimps [diff_mult_distrib2, div_cancel,
1793
09fff2f0d727 New example of GCDs and divides relation
paulson
parents: 1792
diff changeset
   136
                                     mult_mod_distrib, add_mult_distrib_left,
09fff2f0d727 New example of GCDs and divides relation
paulson
parents: 1792
diff changeset
   137
                                     diff_add_inverse]) 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2034
diff changeset
   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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
   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
09fff2f0d727 New example of GCDs and divides relation
paulson
parents: 1792
diff changeset
   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
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   150
by (asm_simp_tac (simpset() addsimps [egcd_0,dvd_refl,dvd_0_right,
1793
09fff2f0d727 New example of GCDs and divides relation
paulson
parents: 1792
diff changeset
   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
451104c223e2 Ran expandshort, especially to introduce Safe_tac
paulson
parents: 4091
diff changeset
   153
by Safe_tac;
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   154
by (asm_simp_tac (simpset() addsimps [egcd_lt_0, nat_into_Ord RS Ord_0_lt,
1793
09fff2f0d727 New example of GCDs and divides relation
paulson
parents: 1792
diff changeset
   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
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   158
    (simpset() addsimps [mod_less_divisor RS ltD, dvd_imp_nat2, 
1793
09fff2f0d727 New example of GCDs and divides relation
paulson
parents: 1792
diff changeset
   159
                        nat_into_Ord RS Ord_0_lt, egcd_lt_0]) 2);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
   165
Goalw [gcd_def] "[| a: nat; b:nat |] ==> gcd(egcd(a,b), a, b)";
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   166
by (asm_simp_tac (simpset() addsimps [egcd_prop1]) 1);
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   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
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
   172
Goalw [gcd_def] "gcd(m,a,b) & gcd(n,a,b) --> m=n";
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   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