doc-src/TutorialI/Rules/Primes.thy
author paulson
Fri, 05 Jan 2001 18:32:57 +0100
changeset 10795 9e888d60d3e5
parent 10790 520dd8696927
child 10846 623141a08705
permissions -rw-r--r--
minor edits to Chapters 1-3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10341
6eb91805a012 added the $Id:$ line
paulson
parents: 10300
diff changeset
     1
(* ID:         $Id$ *)
10295
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
     2
(* EXTRACT from HOL/ex/Primes.thy*)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
     3
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
     4
theory Primes = Main:
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
     5
consts
10300
b247e62520ec X-symbol
paulson
parents: 10295
diff changeset
     6
  gcd     :: "nat*nat \<Rightarrow> nat"               (*Euclid's algorithm *)
10295
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
     7
10300
b247e62520ec X-symbol
paulson
parents: 10295
diff changeset
     8
recdef gcd "measure ((\<lambda>(m,n).n) ::nat*nat \<Rightarrow> nat)"
10295
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
     9
    "gcd (m, n) = (if n=0 then m else gcd(n, m mod n))"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    10
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    11
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    12
ML "Pretty.setmargin 64"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    13
ML "IsarOutput.indent := 5"  (*that is, Doc/TutorialI/settings.ML*)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    14
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    15
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    16
text {*
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    17
\begin{quote}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    18
@{thm[display]"dvd_def"}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    19
\rulename{dvd_def}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    20
\end{quote}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    21
*};
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    22
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    23
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    24
(*** Euclid's Algorithm ***)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    25
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    26
lemma gcd_0 [simp]: "gcd(m,0) = m"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    27
  apply (simp);
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    28
  done
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    29
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    30
lemma gcd_non_0 [simp]: "0<n \<Longrightarrow> gcd(m,n) = gcd (n, m mod n)"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    31
  apply (simp)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    32
  done;
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    33
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    34
declare gcd.simps [simp del];
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    35
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    36
(*gcd(m,n) divides m and n.  The conjunctions don't seem provable separately*)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    37
lemma gcd_dvd_both: "(gcd(m,n) dvd m) \<and> (gcd(m,n) dvd n)"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    38
  apply (induct_tac m n rule: gcd.induct)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    39
  apply (case_tac "n=0")
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    40
  apply (simp_all)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    41
  apply (blast dest: dvd_mod_imp_dvd)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    42
  done
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    43
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    44
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    45
text {*
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    46
@{thm[display] dvd_mod_imp_dvd}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    47
\rulename{dvd_mod_imp_dvd}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    48
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    49
@{thm[display] dvd_trans}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    50
\rulename{dvd_trans}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    51
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    52
\begin{isabelle}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    53
proof\ (prove):\ step\ 3\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    54
\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    55
goal\ (lemma\ gcd_dvd_both):\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    56
gcd\ (m,\ n)\ dvd\ m\ \isasymand \ gcd\ (m,\ n)\ dvd\ n\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    57
\ 1.\ \isasymAnd m\ n.\ \isasymlbrakk 0\ <\ n;\ gcd\ (n,\ m\ mod\ n)\ dvd\ n\ \isasymand \ gcd\ (n,\ m\ mod\ n)\ dvd\ (m\ mod\ n)\isasymrbrakk \isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    58
\ \ \ \ \ \ \ \ \ \ \isasymLongrightarrow \ gcd\ (n,\ m\ mod\ n)\ dvd\ m
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    59
\end{isabelle}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    60
*};
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    61
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    62
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    63
lemmas gcd_dvd1 [iff] = gcd_dvd_both [THEN conjunct1]
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    64
lemmas gcd_dvd2 [iff] = gcd_dvd_both [THEN conjunct2];
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    65
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    66
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    67
text {*
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    68
\begin{quote}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    69
@{thm[display] gcd_dvd1}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    70
\rulename{gcd_dvd1}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    71
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    72
@{thm[display] gcd_dvd2}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    73
\rulename{gcd_dvd2}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    74
\end{quote}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    75
*};
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    76
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    77
(*Maximality: for all m,n,k naturals, 
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    78
                if k divides m and k divides n then k divides gcd(m,n)*)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    79
lemma gcd_greatest [rule_format]:
10790
520dd8696927 *** empty log message ***
nipkow
parents: 10341
diff changeset
    80
      "k dvd m \<longrightarrow> k dvd n \<longrightarrow> k dvd gcd(m,n)"
10295
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    81
  apply (induct_tac m n rule: gcd.induct)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    82
  apply (case_tac "n=0")
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    83
  apply (simp_all add: dvd_mod);
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    84
  done;
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    85
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    86
theorem gcd_greatest_iff [iff]: 
10795
9e888d60d3e5 minor edits to Chapters 1-3
paulson
parents: 10790
diff changeset
    87
        "(k dvd gcd(m,n)) = (k dvd m \<and> k dvd n)"
10295
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    88
  apply (blast intro!: gcd_greatest intro: dvd_trans);
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    89
  done;
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    90
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    91
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    92
constdefs
10300
b247e62520ec X-symbol
paulson
parents: 10295
diff changeset
    93
  is_gcd  :: "[nat,nat,nat] \<Rightarrow> bool"        (*gcd as a relation*)
10295
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    94
    "is_gcd p m n == p dvd m  \<and>  p dvd n  \<and>
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    95
                     (ALL d. d dvd m \<and> d dvd n \<longrightarrow> d dvd p)"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    96
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    97
(*Function gcd yields the Greatest Common Divisor*)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    98
lemma is_gcd: "is_gcd (gcd(m,n)) m n"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
    99
  apply (simp add: is_gcd_def gcd_greatest);
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   100
  done
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   101
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   102
(*uniqueness of GCDs*)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   103
lemma is_gcd_unique: "\<lbrakk> is_gcd m a b; is_gcd n a b \<rbrakk> \<Longrightarrow> m=n"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   104
  apply (simp add: is_gcd_def);
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   105
  apply (blast intro: dvd_anti_sym)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   106
  done
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   107
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   108
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   109
text {*
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   110
@{thm[display] dvd_anti_sym}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   111
\rulename{dvd_anti_sym}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   112
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   113
\begin{isabelle}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   114
proof\ (prove):\ step\ 1\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   115
\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   116
goal\ (lemma\ is_gcd_unique):\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   117
\isasymlbrakk is_gcd\ m\ a\ b;\ is_gcd\ n\ a\ b\isasymrbrakk \ \isasymLongrightarrow \ m\ =\ n\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   118
\ 1.\ \isasymlbrakk m\ dvd\ a\ \isasymand \ m\ dvd\ b\ \isasymand \ (\isasymforall d.\ d\ dvd\ a\ \isasymand \ d\ dvd\ b\ \isasymlongrightarrow \ d\ dvd\ m);\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   119
\ \ \ \ \ \ \ n\ dvd\ a\ \isasymand \ n\ dvd\ b\ \isasymand \ (\isasymforall d.\ d\ dvd\ a\ \isasymand \ d\ dvd\ b\ \isasymlongrightarrow \ d\ dvd\ n)\isasymrbrakk \isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   120
\ \ \ \ \isasymLongrightarrow \ m\ =\ n
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   121
\end{isabelle}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   122
*};
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   123
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   124
lemma gcd_assoc: "gcd(gcd(k,m),n) = gcd(k,gcd(m,n))"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   125
  apply (rule is_gcd_unique)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   126
  apply (rule is_gcd)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   127
  apply (simp add: is_gcd_def);
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   128
  apply (blast intro: dvd_trans);
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   129
  done 
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   130
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   131
text{*
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   132
\begin{isabelle}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   133
proof\ (prove):\ step\ 3\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   134
\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   135
goal\ (lemma\ gcd_assoc):\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   136
gcd\ (gcd\ (k,\ m),\ n)\ =\ gcd\ (k,\ gcd\ (m,\ n))\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   137
\ 1.\ gcd\ (k,\ gcd\ (m,\ n))\ dvd\ k\ \isasymand \isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   138
\ \ \ \ gcd\ (k,\ gcd\ (m,\ n))\ dvd\ m\ \isasymand \ gcd\ (k,\ gcd\ (m,\ n))\ dvd\ n
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   139
\end{isabelle}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   140
*}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   141
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   142
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   143
lemma gcd_dvd_gcd_mult: "gcd(m,n) dvd gcd(k*m, n)"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   144
  apply (blast intro: dvd_trans);
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   145
  done
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   146
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   147
(*This is half of the proof (by dvd_anti_sym) of*)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   148
lemma gcd_mult_cancel: "gcd(k,n) = 1 \<Longrightarrow> gcd(k*m, n) = gcd(m,n)"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   149
  oops
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   150
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   151
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   152
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   153
text{*\noindent
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   154
Forward proof material: of, OF, THEN, simplify.
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   155
*}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   156
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   157
text{*\noindent
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   158
SKIP most developments...
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   159
*}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   160
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   161
(** Commutativity **)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   162
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   163
lemma is_gcd_commute: "is_gcd k m n = is_gcd k n m"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   164
  apply (auto simp add: is_gcd_def);
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   165
  done
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   166
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   167
lemma gcd_commute: "gcd(m,n) = gcd(n,m)"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   168
  apply (rule is_gcd_unique)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   169
  apply (rule is_gcd)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   170
  apply (subst is_gcd_commute)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   171
  apply (simp add: is_gcd)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   172
  done
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   173
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   174
lemma gcd_1 [simp]: "gcd(m,1) = 1"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   175
  apply (simp)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   176
  done
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   177
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   178
lemma gcd_1_left [simp]: "gcd(1,m) = 1"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   179
  apply (simp add: gcd_commute [of 1])
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   180
  done
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   181
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   182
text{*\noindent
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   183
as far as HERE.
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   184
*}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   185
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   186
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   187
text {*
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   188
@{thm[display] gcd_1}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   189
\rulename{gcd_1}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   190
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   191
@{thm[display] gcd_1_left}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   192
\rulename{gcd_1_left}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   193
*};
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   194
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   195
text{*\noindent
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   196
SKIP THIS PROOF
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   197
*}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   198
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   199
lemma gcd_mult_distrib2: "k * gcd(m,n) = gcd(k*m, k*n)"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   200
  apply (induct_tac m n rule: gcd.induct)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   201
  apply (case_tac "n=0")
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   202
  apply (simp)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   203
  apply (case_tac "k=0")
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   204
  apply (simp_all add: mod_geq gcd_non_0 mod_mult_distrib2)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   205
  done
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   206
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   207
text {*
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   208
@{thm[display] gcd_mult_distrib2}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   209
\rulename{gcd_mult_distrib2}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   210
*};
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   211
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   212
text{*\noindent
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   213
of, simplified
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   214
*}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   215
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   216
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   217
lemmas gcd_mult_0 = gcd_mult_distrib2 [of k 1];
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   218
lemmas gcd_mult_1 = gcd_mult_0 [simplified];
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   219
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   220
text {*
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   221
@{thm[display] gcd_mult_distrib2 [of _ 1]}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   222
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   223
@{thm[display] gcd_mult_0}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   224
\rulename{gcd_mult_0}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   225
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   226
@{thm[display] gcd_mult_1}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   227
\rulename{gcd_mult_1}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   228
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   229
@{thm[display] sym}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   230
\rulename{sym}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   231
*};
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   232
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   233
lemmas gcd_mult = gcd_mult_1 [THEN sym];
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   234
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   235
lemmas gcd_mult = gcd_mult_distrib2 [of k 1, simplified, THEN sym];
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   236
      (*better in one step!*)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   237
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   238
text {*
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   239
more legible
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   240
*};
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   241
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   242
lemma gcd_mult [simp]: "gcd(k, k*n) = k"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   243
  apply (rule gcd_mult_distrib2 [of k 1, simplified, THEN sym])
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   244
  done
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   245
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   246
lemmas gcd_self = gcd_mult [of k 1, simplified];
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   247
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   248
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   249
text {*
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   250
Rules handy with THEN
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   251
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   252
@{thm[display] iffD1}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   253
\rulename{iffD1}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   254
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   255
@{thm[display] iffD2}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   256
\rulename{iffD2}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   257
*};
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   258
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   259
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   260
text {*
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   261
again: more legible
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   262
*};
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   263
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   264
lemma gcd_self [simp]: "gcd(k,k) = k"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   265
  apply (rule gcd_mult [of k 1, simplified])
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   266
  done
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   267
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   268
lemma relprime_dvd_mult: 
10790
520dd8696927 *** empty log message ***
nipkow
parents: 10341
diff changeset
   269
      "\<lbrakk> gcd(k,n)=1; k dvd m*n \<rbrakk> \<Longrightarrow> k dvd m";
10295
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   270
  apply (insert gcd_mult_distrib2 [of m k n])
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   271
  apply (simp)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   272
  apply (erule_tac t="m" in ssubst);
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   273
  apply (simp)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   274
  done
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   275
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   276
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   277
text {*
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   278
Another example of "insert"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   279
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   280
@{thm[display] mod_div_equality}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   281
\rulename{mod_div_equality}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   282
*};
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   283
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   284
lemma div_mult_self_is_m: 
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   285
      "0<n \<Longrightarrow> (m*n) div n = (m::nat)"
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   286
  apply (insert mod_div_equality [of "m*n" n])
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   287
  apply (simp)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   288
  done
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   289
10790
520dd8696927 *** empty log message ***
nipkow
parents: 10341
diff changeset
   290
lemma relprime_dvd_mult_iff: "gcd(k,n)=1 \<Longrightarrow> (k dvd m*n) = (k dvd m)";
10295
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   291
  apply (blast intro: relprime_dvd_mult dvd_trans)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   292
  done
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   293
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   294
lemma relprime_20_81: "gcd(#20,#81) = 1";
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   295
  apply (simp add: gcd.simps)
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   296
  done
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   297
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   298
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   299
text {*
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   300
Examples of 'OF'
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   301
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   302
@{thm[display] relprime_dvd_mult}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   303
\rulename{relprime_dvd_mult}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   304
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   305
@{thm[display] relprime_dvd_mult [OF relprime_20_81]}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   306
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   307
@{thm[display] dvd_refl}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   308
\rulename{dvd_refl}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   309
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   310
@{thm[display] dvd_add}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   311
\rulename{dvd_add}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   312
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   313
@{thm[display] dvd_add [OF dvd_refl dvd_refl]}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   314
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   315
@{thm[display] dvd_add [OF _ dvd_refl]}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   316
*};
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   317
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   318
lemma "\<lbrakk>(z::int) < #37; #66 < #2*z; z*z \<noteq> #1225; Q(#34); Q(#36)\<rbrakk> \<Longrightarrow> Q(z)";
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   319
apply (subgoal_tac "z = #34 \<or> z = #36")
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   320
apply blast
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   321
apply (subgoal_tac "z \<noteq> #35")
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   322
apply arith
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   323
apply force
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   324
done
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   325
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   326
text
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   327
{*
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   328
proof\ (prove):\ step\ 1\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   329
\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   330
goal\ (lemma):\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   331
\isasymlbrakk z\ <\ \#37;\ \#66\ <\ \#2\ *\ z;\ z\ *\ z\ \isasymnoteq \ \#1225;\ Q\ \#34;\ Q\ \#36\isasymrbrakk \ \isasymLongrightarrow \ Q\ z\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   332
\ 1.\ \isasymlbrakk z\ <\ \#37;\ \#66\ <\ \#2\ *\ z;\ z\ *\ z\ \isasymnoteq \ \#1225;\ Q\ \#34;\ Q\ \#36;\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   333
\ \ \ \ \ \ \ z\ =\ \#34\ \isasymor \ z\ =\ \#36\isasymrbrakk \isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   334
\ \ \ \ \isasymLongrightarrow \ Q\ z\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   335
\ 2.\ \isasymlbrakk z\ <\ \#37;\ \#66\ <\ \#2\ *\ z;\ z\ *\ z\ \isasymnoteq \ \#1225;\ Q\ \#34;\ Q\ \#36\isasymrbrakk \isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   336
\ \ \ \ \isasymLongrightarrow \ z\ =\ \#34\ \isasymor \ z\ =\ \#36
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   337
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   338
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   339
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   340
proof\ (prove):\ step\ 3\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   341
\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   342
goal\ (lemma):\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   343
\isasymlbrakk z\ <\ \#37;\ \#66\ <\ \#2\ *\ z;\ z\ *\ z\ \isasymnoteq \ \#1225;\ Q\ \#34;\ Q\ \#36\isasymrbrakk \ \isasymLongrightarrow \ Q\ z\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   344
\ 1.\ \isasymlbrakk z\ <\ \#37;\ \#66\ <\ \#2\ *\ z;\ z\ *\ z\ \isasymnoteq \ \#1225;\ Q\ \#34;\ Q\ \#36;\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   345
\ \ \ \ \ \ \ z\ \isasymnoteq \ \#35\isasymrbrakk \isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   346
\ \ \ \ \isasymLongrightarrow \ z\ =\ \#34\ \isasymor \ z\ =\ \#36\isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   347
\ 2.\ \isasymlbrakk z\ <\ \#37;\ \#66\ <\ \#2\ *\ z;\ z\ *\ z\ \isasymnoteq \ \#1225;\ Q\ \#34;\ Q\ \#36\isasymrbrakk \isanewline
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   348
\ \ \ \ \isasymLongrightarrow \ z\ \isasymnoteq \ \#35
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   349
*}
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   350
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   351
8eb12693cead the Rules chapter and theories
paulson
parents:
diff changeset
   352
end