author | paulson |
Mon, 22 Oct 2001 11:54:22 +0200 | |
changeset 11868 | 56db9f3a6b3e |
parent 11704 | 3c50a2cd6f00 |
permissions | -rw-r--r-- |
11594 | 1 |
(* Title: HOL/Real/ex/Sqrt_Irrational.thy |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
|
5 |
*) |
|
6 |
||
7 |
header {* Square roots of primes are irrational *} |
|
8 |
||
9 |
theory Sqrt_Irrational = Real + Primes: |
|
10 |
||
11 |
syntax (xsymbols) (* FIXME move to main HOL (!?) *) |
|
11607 | 12 |
"_square" :: "'a => 'a" ("(_\<twosuperior>)" [1000] 999) |
11594 | 13 |
syntax (HTML output) |
11607 | 14 |
"_square" :: "'a => 'a" ("(_\<twosuperior>)" [1000] 999) |
11594 | 15 |
syntax (output) |
11607 | 16 |
"_square" :: "'a => 'a" ("(_^2)" [1000] 999) |
11594 | 17 |
translations |
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11607
diff
changeset
|
18 |
"x\<twosuperior>" == "x^Suc (Suc 0)" |
11594 | 19 |
|
20 |
||
21 |
subsection {* The set of rational numbers *} |
|
22 |
||
23 |
constdefs |
|
24 |
rationals :: "real set" ("\<rat>") |
|
11607 | 25 |
"\<rat> == {x. \<exists>m n. n \<noteq> 0 \<and> \<bar>x\<bar> = real (m::nat) / real (n::nat)}" |
11594 | 26 |
|
11607 | 27 |
theorem rationals_rep: "x \<in> \<rat> ==> |
11594 | 28 |
\<exists>m n. n \<noteq> 0 \<and> \<bar>x\<bar> = real m / real n \<and> gcd (m, n) = 1" |
29 |
proof - |
|
30 |
assume "x \<in> \<rat>" |
|
31 |
then obtain m n :: nat where n: "n \<noteq> 0" and x_rat: "\<bar>x\<bar> = real m / real n" |
|
32 |
by (unfold rationals_def) blast |
|
33 |
let ?gcd = "gcd (m, n)" |
|
34 |
from n have gcd: "?gcd \<noteq> 0" by (simp add: gcd_zero) |
|
35 |
let ?k = "m div ?gcd" |
|
36 |
let ?l = "n div ?gcd" |
|
37 |
let ?gcd' = "gcd (?k, ?l)" |
|
38 |
have "?gcd dvd m" .. hence gcd_k: "?gcd * ?k = m" |
|
39 |
by (rule dvd_mult_div_cancel) |
|
40 |
have "?gcd dvd n" .. hence gcd_l: "?gcd * ?l = n" |
|
41 |
by (rule dvd_mult_div_cancel) |
|
42 |
||
43 |
from n gcd_l have "?l \<noteq> 0" |
|
44 |
by (auto iff del: neq0_conv) |
|
45 |
moreover |
|
46 |
have "\<bar>x\<bar> = real ?k / real ?l" |
|
47 |
proof - |
|
48 |
from gcd have "real ?k / real ?l = real (?gcd * ?k) / real (?gcd * ?l)" |
|
49 |
by (simp add: real_mult_div_cancel1) |
|
11607 | 50 |
also from gcd_k gcd_l have "... = real m / real n" by simp |
51 |
also from x_rat have "... = \<bar>x\<bar>" .. |
|
11594 | 52 |
finally show ?thesis .. |
53 |
qed |
|
54 |
moreover |
|
55 |
have "?gcd' = 1" |
|
56 |
proof - |
|
57 |
have "?gcd * ?gcd' = gcd (?gcd * ?k, ?gcd * ?l)" |
|
58 |
by (rule gcd_mult_distrib2) |
|
59 |
with gcd_k gcd_l have "?gcd * ?gcd' = ?gcd" by simp |
|
60 |
with gcd show ?thesis by simp |
|
61 |
qed |
|
62 |
ultimately show ?thesis by blast |
|
63 |
qed |
|
64 |
||
11607 | 65 |
lemma [elim?]: "r \<in> \<rat> ==> |
66 |
(!!m n. n \<noteq> 0 ==> \<bar>r\<bar> = real m / real n ==> gcd (m, n) = 1 ==> C) ==> C" |
|
11594 | 67 |
by (insert rationals_rep) blast |
68 |
||
69 |
||
70 |
subsection {* Main theorem *} |
|
71 |
||
72 |
text {* |
|
73 |
The square root of any prime number (including @{text 2}) is |
|
74 |
irrational. |
|
75 |
*} |
|
76 |
||
11607 | 77 |
theorem sqrt_prime_irrational: "x\<twosuperior> = real p ==> p \<in> prime ==> x \<notin> \<rat>" |
11594 | 78 |
proof |
79 |
assume x_sqrt: "x\<twosuperior> = real p" |
|
80 |
assume p_prime: "p \<in> prime" |
|
81 |
hence p: "1 < p" by (simp add: prime_def) |
|
82 |
assume "x \<in> \<rat>" |
|
83 |
then obtain m n where |
|
84 |
n: "n \<noteq> 0" and x_rat: "\<bar>x\<bar> = real m / real n" and gcd: "gcd (m, n) = 1" .. |
|
85 |
have eq: "m\<twosuperior> = p * n\<twosuperior>" |
|
86 |
proof - |
|
87 |
from n x_rat have "real m = \<bar>x\<bar> * real n" by simp |
|
88 |
hence "real (m\<twosuperior>) = x\<twosuperior> * real (n\<twosuperior>)" by (simp split: abs_split) |
|
11607 | 89 |
also from x_sqrt have "... = real (p * n\<twosuperior>)" by simp |
11594 | 90 |
finally show ?thesis .. |
91 |
qed |
|
92 |
have "p dvd m \<and> p dvd n" |
|
93 |
proof |
|
94 |
from eq have "p dvd m\<twosuperior>" .. |
|
95 |
with p_prime show "p dvd m" by (rule prime_dvd_square) |
|
96 |
then obtain k where "m = p * k" .. |
|
97 |
with eq have "p * n\<twosuperior> = p\<twosuperior> * k\<twosuperior>" by (auto simp add: mult_ac) |
|
98 |
with p have "n\<twosuperior> = p * k\<twosuperior>" by simp |
|
99 |
hence "p dvd n\<twosuperior>" .. |
|
100 |
with p_prime show "p dvd n" by (rule prime_dvd_square) |
|
101 |
qed |
|
102 |
hence "p dvd gcd (m, n)" .. |
|
103 |
with gcd have "p dvd 1" by simp |
|
104 |
hence "p \<le> 1" by (simp add: dvd_imp_le) |
|
105 |
with p show False by simp |
|
106 |
qed |
|
107 |
||
108 |
||
109 |
subsection {* Variations *} |
|
110 |
||
111 |
text {* |
|
112 |
Just for the record: we instantiate the main theorem for the |
|
113 |
specific prime number @{text 2} (real mathematicians would never do |
|
114 |
this formally :-). |
|
115 |
*} |
|
116 |
||
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
117 |
theorem "x\<twosuperior> = real (2::nat) ==> x \<notin> \<rat>" |
11594 | 118 |
proof (rule sqrt_prime_irrational) |
119 |
{ |
|
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
120 |
fix m :: nat assume dvd: "m dvd 2" |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
121 |
hence "m \<le> 2" by (simp add: dvd_imp_le) |
11868
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents:
11704
diff
changeset
|
122 |
moreover from dvd have "m \<noteq> 0" by (auto iff del: neq0_conv) |
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
123 |
ultimately have "m = 1 \<or> m = 2" by arith |
11594 | 124 |
} |
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
125 |
thus "2 \<in> prime" by (simp add: prime_def) |
11594 | 126 |
qed |
127 |
||
128 |
text {* |
|
129 |
\medskip An alternative version of the main proof, using mostly |
|
130 |
linear forward-reasoning. While this results in less top-down |
|
131 |
structure, it is probably closer to proofs seen in mathematics. |
|
132 |
*} |
|
133 |
||
11607 | 134 |
theorem "x\<twosuperior> = real p ==> p \<in> prime ==> x \<notin> \<rat>" |
11594 | 135 |
proof |
136 |
assume x_sqrt: "x\<twosuperior> = real p" |
|
137 |
assume p_prime: "p \<in> prime" |
|
138 |
hence p: "1 < p" by (simp add: prime_def) |
|
139 |
assume "x \<in> \<rat>" |
|
140 |
then obtain m n where |
|
141 |
n: "n \<noteq> 0" and x_rat: "\<bar>x\<bar> = real m / real n" and gcd: "gcd (m, n) = 1" .. |
|
142 |
from n x_rat have "real m = \<bar>x\<bar> * real n" by simp |
|
143 |
hence "real (m\<twosuperior>) = x\<twosuperior> * real (n\<twosuperior>)" by (simp split: abs_split) |
|
11607 | 144 |
also from x_sqrt have "... = real (p * n\<twosuperior>)" by simp |
11594 | 145 |
finally have eq: "m\<twosuperior> = p * n\<twosuperior>" .. |
146 |
hence "p dvd m\<twosuperior>" .. |
|
147 |
with p_prime have dvd_m: "p dvd m" by (rule prime_dvd_square) |
|
148 |
then obtain k where "m = p * k" .. |
|
149 |
with eq have "p * n\<twosuperior> = p\<twosuperior> * k\<twosuperior>" by (auto simp add: mult_ac) |
|
150 |
with p have "n\<twosuperior> = p * k\<twosuperior>" by simp |
|
151 |
hence "p dvd n\<twosuperior>" .. |
|
152 |
with p_prime have "p dvd n" by (rule prime_dvd_square) |
|
153 |
with dvd_m have "p dvd gcd (m, n)" by (rule gcd_greatest) |
|
154 |
with gcd have "p dvd 1" by simp |
|
155 |
hence "p \<le> 1" by (simp add: dvd_imp_le) |
|
156 |
with p show False by simp |
|
157 |
qed |
|
158 |
||
159 |
end |