src/ZF/ex/Primes.thy
author chaieb
Thu, 23 Jul 2009 22:25:09 +0200
changeset 32162 c6a045559ce6
parent 24893 b8ef7afe3a6b
child 32960 69916a850301
permissions -rw-r--r--
fixed proof --- fact_setprod removed for fact_altdef_nat
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.thy
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
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
     5
*)
1792
75c54074cd8c The "divides" relation, the greatest common divisor and Euclid's algorithm
paulson
parents:
diff changeset
     6
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
     7
header{*The Divides Relation and Euclid's algorithm for the GCD*}
1792
75c54074cd8c The "divides" relation, the greatest common divisor and Euclid's algorithm
paulson
parents:
diff changeset
     8
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 15863
diff changeset
     9
theory Primes imports Main begin
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    10
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    11
definition
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    12
  divides :: "[i,i]=>o"              (infixl "dvd" 50)  where
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    13
    "m dvd n == m \<in> nat & n \<in> nat & (\<exists>k \<in> nat. n = m#*k)"
1792
75c54074cd8c The "divides" relation, the greatest common divisor and Euclid's algorithm
paulson
parents:
diff changeset
    14
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    15
definition
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    16
  is_gcd  :: "[i,i,i]=>o"     --{*definition of great common divisor*}  where
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    17
    "is_gcd(p,m,n) == ((p dvd m) & (p dvd n))   &
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    18
                       (\<forall>d\<in>nat. (d dvd m) & (d dvd n) --> d dvd p)"
1792
75c54074cd8c The "divides" relation, the greatest common divisor and Euclid's algorithm
paulson
parents:
diff changeset
    19
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    20
definition
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    21
  gcd     :: "[i,i]=>i"       --{*Euclid's algorithm for the gcd*}  where
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    22
    "gcd(m,n) == transrec(natify(n),
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    23
			%n f. \<lambda>m \<in> nat.
11382
a816fead971a now more like the HOL versions, and with the Square Root example added
paulson
parents: 11316
diff changeset
    24
			        if n=0 then m else f`(m mod n)`n) ` natify(m)"
1792
75c54074cd8c The "divides" relation, the greatest common divisor and Euclid's algorithm
paulson
parents:
diff changeset
    25
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    26
definition
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    27
  coprime :: "[i,i]=>o"       --{*the coprime relation*}  where
11382
a816fead971a now more like the HOL versions, and with the Square Root example added
paulson
parents: 11316
diff changeset
    28
    "coprime(m,n) == gcd(m,n) = 1"
a816fead971a now more like the HOL versions, and with the Square Root example added
paulson
parents: 11316
diff changeset
    29
  
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    30
definition
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    31
  prime   :: i                --{*the set of prime numbers*}  where
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    32
   "prime == {p \<in> nat. 1<p & (\<forall>m \<in> nat. m dvd p --> m=1 | m=p)}"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    33
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
    34
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
    35
subsection{*The Divides Relation*}
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    36
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    37
lemma dvdD: "m dvd n ==> m \<in> nat & n \<in> nat & (\<exists>k \<in> nat. n = m#*k)"
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
    38
by (unfold divides_def, assumption)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    39
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    40
lemma dvdE:
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    41
     "[|m dvd n;  !!k. [|m \<in> nat; n \<in> nat; k \<in> nat; n = m#*k|] ==> P|] ==> P"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    42
by (blast dest!: dvdD)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    43
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    44
lemmas dvd_imp_nat1 = dvdD [THEN conjunct1, standard]
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    45
lemmas dvd_imp_nat2 = dvdD [THEN conjunct2, THEN conjunct1, standard]
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    46
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    47
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    48
lemma dvd_0_right [simp]: "m \<in> nat ==> m dvd 0"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
    49
apply (simp add: divides_def)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    50
apply (fast intro: nat_0I mult_0_right [symmetric])
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    51
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    52
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    53
lemma dvd_0_left: "0 dvd m ==> m = 0"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
    54
by (simp add: divides_def)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    55
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    56
lemma dvd_refl [simp]: "m \<in> nat ==> m dvd m"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
    57
apply (simp add: divides_def)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    58
apply (fast intro: nat_1I mult_1_right [symmetric])
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    59
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    60
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    61
lemma dvd_trans: "[| m dvd n; n dvd p |] ==> m dvd p"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
    62
by (auto simp add: divides_def intro: mult_assoc mult_type)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    63
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    64
lemma dvd_anti_sym: "[| m dvd n; n dvd m |] ==> m=n"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
    65
apply (simp add: divides_def)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    66
apply (force dest: mult_eq_self_implies_10
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    67
             simp add: mult_assoc mult_eq_1_iff)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    68
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    69
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    70
lemma dvd_mult_left: "[|(i#*j) dvd k; i \<in> nat|] ==> i dvd k"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
    71
by (auto simp add: divides_def mult_assoc)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    72
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    73
lemma dvd_mult_right: "[|(i#*j) dvd k; j \<in> nat|] ==> j dvd k"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
    74
apply (simp add: divides_def, clarify)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    75
apply (rule_tac x = "i#*k" in bexI)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    76
apply (simp add: mult_ac)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    77
apply (rule mult_type)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    78
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    79
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    80
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
    81
subsection{*Euclid's Algorithm for the GCD*}
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    82
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    83
lemma gcd_0 [simp]: "gcd(m,0) = natify(m)"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
    84
apply (simp add: gcd_def)
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
    85
apply (subst transrec, simp)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    86
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    87
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    88
lemma gcd_natify1 [simp]: "gcd(natify(m),n) = gcd(m,n)"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    89
by (simp add: gcd_def)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    90
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    91
lemma gcd_natify2 [simp]: "gcd(m, natify(n)) = gcd(m,n)"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    92
by (simp add: gcd_def)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    93
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    94
lemma gcd_non_0_raw: 
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    95
    "[| 0<n;  n \<in> nat |] ==> gcd(m,n) = gcd(n, m mod n)"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
    96
apply (simp add: gcd_def)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    97
apply (rule_tac P = "%z. ?left (z) = ?right" in transrec [THEN ssubst])
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    98
apply (simp add: ltD [THEN mem_imp_not_eq, THEN not_sym] 
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
    99
                 mod_less_divisor [THEN ltD])
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   100
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   101
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   102
lemma gcd_non_0: "0 < natify(n) ==> gcd(m,n) = gcd(n, m mod n)"
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
   103
apply (cut_tac m = m and n = "natify (n) " in gcd_non_0_raw)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   104
apply auto
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   105
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   106
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   107
lemma gcd_1 [simp]: "gcd(m,1) = 1"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   108
by (simp (no_asm_simp) add: gcd_non_0)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   109
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   110
lemma dvd_add: "[| k dvd a; k dvd b |] ==> k dvd (a #+ b)"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   111
apply (simp add: divides_def)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   112
apply (fast intro: add_mult_distrib_left [symmetric] add_type)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   113
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   114
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   115
lemma dvd_mult: "k dvd n ==> k dvd (m #* n)"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   116
apply (simp add: divides_def)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   117
apply (fast intro: mult_left_commute mult_type)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   118
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   119
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   120
lemma dvd_mult2: "k dvd m ==> k dvd (m #* n)"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   121
apply (subst mult_commute)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   122
apply (blast intro: dvd_mult)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   123
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   124
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   125
(* k dvd (m*k) *)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   126
lemmas dvdI1 [simp] = dvd_refl [THEN dvd_mult, standard]
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   127
lemmas dvdI2 [simp] = dvd_refl [THEN dvd_mult2, standard]
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   128
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   129
lemma dvd_mod_imp_dvd_raw:
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   130
     "[| a \<in> nat; b \<in> nat; k dvd b; k dvd (a mod b) |] ==> k dvd a"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   131
apply (case_tac "b=0") 
13259
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 12867
diff changeset
   132
 apply (simp add: DIVISION_BY_ZERO_MOD)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   133
apply (blast intro: mod_div_equality [THEN subst]
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   134
             elim: dvdE 
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   135
             intro!: dvd_add dvd_mult mult_type mod_type div_type)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   136
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   137
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   138
lemma dvd_mod_imp_dvd: "[| k dvd (a mod b); k dvd b; a \<in> nat |] ==> k dvd a"
13259
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 12867
diff changeset
   139
apply (cut_tac b = "natify (b)" in dvd_mod_imp_dvd_raw)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   140
apply auto
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   141
apply (simp add: divides_def)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   142
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   143
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   144
(*Imitating TFL*)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   145
lemma gcd_induct_lemma [rule_format (no_asm)]: "[| n \<in> nat;  
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   146
         \<forall>m \<in> nat. P(m,0);  
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   147
         \<forall>m \<in> nat. \<forall>n \<in> nat. 0<n --> P(n, m mod n) --> P(m,n) |]  
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   148
      ==> \<forall>m \<in> nat. P (m,n)"
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
   149
apply (erule_tac i = n in complete_induct)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   150
apply (case_tac "x=0")
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   151
apply (simp (no_asm_simp))
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   152
apply clarify
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
   153
apply (drule_tac x1 = m and x = x in bspec [THEN bspec])
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   154
apply (simp_all add: Ord_0_lt_iff)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   155
apply (blast intro: mod_less_divisor [THEN ltD])
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   156
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   157
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   158
lemma gcd_induct: "!!P. [| m \<in> nat; n \<in> nat;  
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   159
         !!m. m \<in> nat ==> P(m,0);  
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   160
         !!m n. [|m \<in> nat; n \<in> nat; 0<n; P(n, m mod n)|] ==> P(m,n) |]  
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   161
      ==> P (m,n)"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   162
by (blast intro: gcd_induct_lemma)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   163
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   164
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   165
subsection{*Basic Properties of @{term gcd}*}
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   166
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   167
text{*type of gcd*}
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   168
lemma gcd_type [simp,TC]: "gcd(m, n) \<in> nat"
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
   169
apply (subgoal_tac "gcd (natify (m), natify (n)) \<in> nat")
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   170
apply simp
13259
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 12867
diff changeset
   171
apply (rule_tac m = "natify (m)" and n = "natify (n)" in gcd_induct)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   172
apply auto
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   173
apply (simp add: gcd_non_0)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   174
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   175
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   176
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   177
text{* Property 1: gcd(a,b) divides a and b *}
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   178
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   179
lemma gcd_dvd_both:
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   180
     "[| m \<in> nat; n \<in> nat |] ==> gcd (m, n) dvd m & gcd (m, n) dvd n"
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
   181
apply (rule_tac m = m and n = n in gcd_induct)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   182
apply (simp_all add: gcd_non_0)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   183
apply (blast intro: dvd_mod_imp_dvd_raw nat_into_Ord [THEN Ord_0_lt])
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   184
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   185
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   186
lemma gcd_dvd1 [simp]: "m \<in> nat ==> gcd(m,n) dvd m"
13259
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 12867
diff changeset
   187
apply (cut_tac m = "natify (m)" and n = "natify (n)" in gcd_dvd_both)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   188
apply auto
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   189
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   190
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   191
lemma gcd_dvd2 [simp]: "n \<in> nat ==> gcd(m,n) dvd n"
13259
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 12867
diff changeset
   192
apply (cut_tac m = "natify (m)" and n = "natify (n)" in gcd_dvd_both)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   193
apply auto
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   194
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   195
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   196
text{* if f divides a and b then f divides gcd(a,b) *}
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   197
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   198
lemma dvd_mod: "[| f dvd a; f dvd b |] ==> f dvd (a mod b)"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   199
apply (simp add: divides_def)
13259
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 12867
diff changeset
   200
apply (case_tac "b=0")
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
   201
 apply (simp add: DIVISION_BY_ZERO_MOD, auto)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   202
apply (blast intro: mod_mult_distrib2 [symmetric])
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   203
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   204
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   205
text{* Property 2: for all a,b,f naturals, 
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   206
               if f divides a and f divides b then f divides gcd(a,b)*}
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   207
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   208
lemma gcd_greatest_raw [rule_format]:
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   209
     "[| m \<in> nat; n \<in> nat; f \<in> nat |]    
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   210
      ==> (f dvd m) --> (f dvd n) --> f dvd gcd(m,n)"
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
   211
apply (rule_tac m = m and n = n in gcd_induct)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   212
apply (simp_all add: gcd_non_0 dvd_mod)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   213
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   214
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   215
lemma gcd_greatest: "[| f dvd m;  f dvd n;  f \<in> nat |] ==> f dvd gcd(m,n)"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   216
apply (rule gcd_greatest_raw)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   217
apply (auto simp add: divides_def)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   218
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   219
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   220
lemma gcd_greatest_iff [simp]: "[| k \<in> nat; m \<in> nat; n \<in> nat |]  
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   221
      ==> (k dvd gcd (m, n)) <-> (k dvd m & k dvd n)"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   222
by (blast intro!: gcd_greatest gcd_dvd1 gcd_dvd2 intro: dvd_trans)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   223
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   224
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   225
subsection{*The Greatest Common Divisor*}
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   226
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   227
text{*The GCD exists and function gcd computes it.*}
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   228
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   229
lemma is_gcd: "[| m \<in> nat; n \<in> nat |] ==> is_gcd(gcd(m,n), m, n)"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   230
by (simp add: is_gcd_def)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   231
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   232
text{*The GCD is unique*}
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   233
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   234
lemma is_gcd_unique: "[|is_gcd(m,a,b); is_gcd(n,a,b); m\<in>nat; n\<in>nat|] ==> m=n"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   235
apply (simp add: is_gcd_def)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   236
apply (blast intro: dvd_anti_sym)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   237
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   238
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   239
lemma is_gcd_commute: "is_gcd(k,m,n) <-> is_gcd(k,n,m)"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   240
by (simp add: is_gcd_def, blast)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   241
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   242
lemma gcd_commute_raw: "[| m \<in> nat; n \<in> nat |] ==> gcd(m,n) = gcd(n,m)"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   243
apply (rule is_gcd_unique)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   244
apply (rule is_gcd)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   245
apply (rule_tac [3] is_gcd_commute [THEN iffD1])
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
   246
apply (rule_tac [3] is_gcd, auto)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   247
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   248
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   249
lemma gcd_commute: "gcd(m,n) = gcd(n,m)"
13259
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 12867
diff changeset
   250
apply (cut_tac m = "natify (m)" and n = "natify (n)" in gcd_commute_raw)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   251
apply auto
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   252
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   253
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   254
lemma gcd_assoc_raw: "[| k \<in> nat; m \<in> nat; n \<in> nat |]  
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   255
      ==> gcd (gcd (k, m), n) = gcd (k, gcd (m, n))"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   256
apply (rule is_gcd_unique)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   257
apply (rule is_gcd)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   258
apply (simp_all add: is_gcd_def)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   259
apply (blast intro: gcd_dvd1 gcd_dvd2 gcd_type intro: dvd_trans)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   260
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   261
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   262
lemma gcd_assoc: "gcd (gcd (k, m), n) = gcd (k, gcd (m, n))"
13259
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 12867
diff changeset
   263
apply (cut_tac k = "natify (k)" and m = "natify (m)" and n = "natify (n) " 
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   264
       in gcd_assoc_raw)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   265
apply auto
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   266
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   267
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   268
lemma gcd_0_left [simp]: "gcd (0, m) = natify(m)"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   269
by (simp add: gcd_commute [of 0])
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   270
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   271
lemma gcd_1_left [simp]: "gcd (1, m) = 1"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   272
by (simp add: gcd_commute [of 1])
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   273
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   274
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   275
subsection{*Addition laws*}
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   276
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   277
lemma gcd_add1 [simp]: "gcd (m #+ n, n) = gcd (m, n)"
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   278
apply (subgoal_tac "gcd (m #+ natify (n), natify (n)) = gcd (m, natify (n))")
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   279
apply simp
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   280
apply (case_tac "natify (n) = 0")
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   281
apply (auto simp add: Ord_0_lt_iff gcd_non_0)
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   282
done
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   283
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   284
lemma gcd_add2 [simp]: "gcd (m, m #+ n) = gcd (m, n)"
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   285
apply (rule gcd_commute [THEN trans])
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   286
apply (subst add_commute, simp)
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   287
apply (rule gcd_commute)
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   288
done
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   289
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   290
lemma gcd_add2' [simp]: "gcd (m, n #+ m) = gcd (m, n)"
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   291
by (subst add_commute, rule gcd_add2)
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   292
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   293
lemma gcd_add_mult_raw: "k \<in> nat ==> gcd (m, k #* m #+ n) = gcd (m, n)"
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   294
apply (erule nat_induct)
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   295
apply (auto simp add: gcd_add2 add_assoc)
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   296
done
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   297
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   298
lemma gcd_add_mult: "gcd (m, k #* m #+ n) = gcd (m, n)"
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   299
apply (cut_tac k = "natify (k)" in gcd_add_mult_raw)
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   300
apply auto
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   301
done
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   302
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   303
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   304
subsection{* Multiplication Laws*}
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   305
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   306
lemma gcd_mult_distrib2_raw:
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   307
     "[| k \<in> nat; m \<in> nat; n \<in> nat |]  
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   308
      ==> k #* gcd (m, n) = gcd (k #* m, k #* n)"
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
   309
apply (erule_tac m = m and n = n in gcd_induct, assumption)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   310
apply simp
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
   311
apply (case_tac "k = 0", simp)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   312
apply (simp add: mod_geq gcd_non_0 mod_mult_distrib2 Ord_0_lt_iff)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   313
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   314
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   315
lemma gcd_mult_distrib2: "k #* gcd (m, n) = gcd (k #* m, k #* n)"
13259
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 12867
diff changeset
   316
apply (cut_tac k = "natify (k)" and m = "natify (m)" and n = "natify (n) " 
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   317
       in gcd_mult_distrib2_raw)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   318
apply auto
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   319
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   320
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   321
lemma gcd_mult [simp]: "gcd (k, k #* n) = natify(k)"
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
   322
by (cut_tac k = k and m = 1 and n = n in gcd_mult_distrib2, auto)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   323
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   324
lemma gcd_self [simp]: "gcd (k, k) = natify(k)"
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
   325
by (cut_tac k = k and n = 1 in gcd_mult, auto)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   326
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   327
lemma relprime_dvd_mult:
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   328
     "[| gcd (k,n) = 1;  k dvd (m #* n);  m \<in> nat |] ==> k dvd m"
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
   329
apply (cut_tac k = m and m = k and n = n in gcd_mult_distrib2, auto)
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
   330
apply (erule_tac b = m in ssubst)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   331
apply (simp add: dvd_imp_nat1)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   332
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   333
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   334
lemma relprime_dvd_mult_iff:
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   335
     "[| gcd (k,n) = 1;  m \<in> nat |] ==> k dvd (m #* n) <-> k dvd m"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   336
by (blast intro: dvdI2 relprime_dvd_mult dvd_trans)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   337
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   338
lemma prime_imp_relprime: 
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   339
     "[| p \<in> prime;  ~ (p dvd n);  n \<in> nat |] ==> gcd (p, n) = 1"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   340
apply (simp add: prime_def, clarify)
13259
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 12867
diff changeset
   341
apply (drule_tac x = "gcd (p,n)" in bspec)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   342
apply auto
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
   343
apply (cut_tac m = p and n = n in gcd_dvd2, auto)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   344
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   345
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   346
lemma prime_into_nat: "p \<in> prime ==> p \<in> nat"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   347
by (simp add: prime_def)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   348
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   349
lemma prime_nonzero: "p \<in> prime \<Longrightarrow> p\<noteq>0"
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   350
by (auto simp add: prime_def)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   351
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   352
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   353
text{*This theorem leads immediately to a proof of the uniqueness of
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   354
  factorization.  If @{term p} divides a product of primes then it is
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   355
  one of those primes.*}
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   356
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   357
lemma prime_dvd_mult:
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   358
     "[|p dvd m #* n; p \<in> prime; m \<in> nat; n \<in> nat |] ==> p dvd m \<or> p dvd n"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   359
by (blast intro: relprime_dvd_mult prime_imp_relprime prime_into_nat)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   360
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   361
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   362
lemma gcd_mult_cancel_raw:
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   363
     "[|gcd (k,n) = 1; m \<in> nat; n \<in> nat|] ==> gcd (k #* m, n) = gcd (m, n)"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   364
apply (rule dvd_anti_sym)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   365
 apply (rule gcd_greatest)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   366
  apply (rule relprime_dvd_mult [of _ k])
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   367
apply (simp add: gcd_assoc)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   368
apply (simp add: gcd_commute)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   369
apply (simp_all add: mult_commute)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   370
apply (blast intro: dvdI1 gcd_dvd1 dvd_trans)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   371
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   372
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   373
lemma gcd_mult_cancel: "gcd (k,n) = 1 ==> gcd (k #* m, n) = gcd (m, n)"
13259
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 12867
diff changeset
   374
apply (cut_tac m = "natify (m)" and n = "natify (n)" in gcd_mult_cancel_raw)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   375
apply auto
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   376
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   377
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   378
15863
78db9506cc78 minor tidying
paulson
parents: 13339
diff changeset
   379
subsection{*The Square Root of a Prime is Irrational: Key Lemma*}
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   380
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   381
lemma prime_dvd_other_side:
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   382
     "\<lbrakk>n#*n = p#*(k#*k); p \<in> prime; n \<in> nat\<rbrakk> \<Longrightarrow> p dvd n"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   383
apply (subgoal_tac "p dvd n#*n")
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   384
 apply (blast dest: prime_dvd_mult)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   385
apply (rule_tac j = "k#*k" in dvd_mult_left)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   386
 apply (auto simp add: prime_def)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   387
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   388
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   389
lemma reduction:
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   390
     "\<lbrakk>k#*k = p#*(j#*j); p \<in> prime; 0 < k; j \<in> nat; k \<in> nat\<rbrakk>  
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   391
      \<Longrightarrow> k < p#*j & 0 < j"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   392
apply (rule ccontr)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   393
apply (simp add: not_lt_iff_le prime_into_nat)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   394
apply (erule disjE)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   395
 apply (frule mult_le_mono, assumption+)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   396
apply (simp add: mult_ac)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   397
apply (auto dest!: natify_eqE 
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   398
            simp add: not_lt_iff_le prime_into_nat mult_le_cancel_le1)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   399
apply (simp add: prime_def)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   400
apply (blast dest: lt_trans1)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   401
done
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   402
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   403
lemma rearrange: "j #* (p#*j) = k#*k \<Longrightarrow> k#*k = p#*(j#*j)"
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   404
by (simp add: mult_ac)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   405
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   406
lemma prime_not_square:
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   407
     "\<lbrakk>m \<in> nat; p \<in> prime\<rbrakk> \<Longrightarrow> \<forall>k \<in> nat. 0<k \<longrightarrow> m#*m \<noteq> p#*(k#*k)"
13339
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
   408
apply (erule complete_induct, clarify)
0f89104dd377 Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents: 13259
diff changeset
   409
apply (frule prime_dvd_other_side, assumption)
12867
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   410
apply assumption
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   411
apply (erule dvdE)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   412
apply (simp add: mult_assoc mult_cancel1 prime_nonzero prime_into_nat)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   413
apply (blast dest: rearrange reduction ltD)
5c900a821a7c New-style versions of these old examples
paulson
parents: 11382
diff changeset
   414
done
1792
75c54074cd8c The "divides" relation, the greatest common divisor and Euclid's algorithm
paulson
parents:
diff changeset
   415
75c54074cd8c The "divides" relation, the greatest common divisor and Euclid's algorithm
paulson
parents:
diff changeset
   416
end