author | urbanc |
Tue, 13 Dec 2005 18:11:21 +0100 | |
changeset 18396 | b3e7da94b51f |
parent 16663 | 13e9c402308b |
child 19086 | 1b3780be6cc2 |
permissions | -rw-r--r-- |
13957 | 1 |
(* Title: HOL/Hyperreal/ex/Sqrt.thy |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
14981 | 4 |
|
13957 | 5 |
*) |
6 |
||
7 |
header {* Square roots of primes are irrational *} |
|
8 |
||
15149 | 9 |
theory Sqrt |
10 |
imports Primes Complex_Main |
|
11 |
begin |
|
13957 | 12 |
|
13 |
subsection {* Preliminaries *} |
|
14 |
||
15 |
text {* |
|
16 |
The set of rational numbers, including the key representation |
|
17 |
theorem. |
|
18 |
*} |
|
19 |
||
20 |
constdefs |
|
21 |
rationals :: "real set" ("\<rat>") |
|
22 |
"\<rat> \<equiv> {x. \<exists>m n. n \<noteq> 0 \<and> \<bar>x\<bar> = real (m::nat) / real (n::nat)}" |
|
23 |
||
24 |
theorem rationals_rep: "x \<in> \<rat> \<Longrightarrow> |
|
25 |
\<exists>m n. n \<noteq> 0 \<and> \<bar>x\<bar> = real m / real n \<and> gcd (m, n) = 1" |
|
26 |
proof - |
|
27 |
assume "x \<in> \<rat>" |
|
28 |
then obtain m n :: nat where |
|
29 |
n: "n \<noteq> 0" and x_rat: "\<bar>x\<bar> = real m / real n" |
|
30 |
by (unfold rationals_def) blast |
|
31 |
let ?gcd = "gcd (m, n)" |
|
32 |
from n have gcd: "?gcd \<noteq> 0" by (simp add: gcd_zero) |
|
33 |
let ?k = "m div ?gcd" |
|
34 |
let ?l = "n div ?gcd" |
|
35 |
let ?gcd' = "gcd (?k, ?l)" |
|
36 |
have "?gcd dvd m" .. then have gcd_k: "?gcd * ?k = m" |
|
37 |
by (rule dvd_mult_div_cancel) |
|
38 |
have "?gcd dvd n" .. then have gcd_l: "?gcd * ?l = n" |
|
39 |
by (rule dvd_mult_div_cancel) |
|
40 |
||
41 |
from n and gcd_l have "?l \<noteq> 0" |
|
42 |
by (auto iff del: neq0_conv) |
|
43 |
moreover |
|
44 |
have "\<bar>x\<bar> = real ?k / real ?l" |
|
45 |
proof - |
|
46 |
from gcd have "real ?k / real ?l = |
|
47 |
real (?gcd * ?k) / real (?gcd * ?l)" |
|
14305
f17ca9f6dc8c
tidying first part of HyperArith0.ML, using generic lemmas
paulson
parents:
14051
diff
changeset
|
48 |
by (simp add: mult_divide_cancel_left) |
13957 | 49 |
also from gcd_k and gcd_l have "\<dots> = real m / real n" by simp |
50 |
also from x_rat have "\<dots> = \<bar>x\<bar>" .. |
|
51 |
finally show ?thesis .. |
|
52 |
qed |
|
53 |
moreover |
|
54 |
have "?gcd' = 1" |
|
55 |
proof - |
|
56 |
have "?gcd * ?gcd' = gcd (?gcd * ?k, ?gcd * ?l)" |
|
57 |
by (rule gcd_mult_distrib2) |
|
58 |
with gcd_k gcd_l have "?gcd * ?gcd' = ?gcd" by simp |
|
59 |
with gcd show ?thesis by simp |
|
60 |
qed |
|
61 |
ultimately show ?thesis by blast |
|
62 |
qed |
|
63 |
||
64 |
lemma [elim?]: "r \<in> \<rat> \<Longrightarrow> |
|
65 |
(\<And>m n. n \<noteq> 0 \<Longrightarrow> \<bar>r\<bar> = real m / real n \<Longrightarrow> gcd (m, n) = 1 \<Longrightarrow> C) |
|
66 |
\<Longrightarrow> C" |
|
67 |
using rationals_rep by 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 |
||
16663 | 77 |
theorem sqrt_prime_irrational: "prime p \<Longrightarrow> sqrt (real p) \<notin> \<rat>" |
13957 | 78 |
proof |
16663 | 79 |
assume p_prime: "prime p" |
13957 | 80 |
then have p: "1 < p" by (simp add: prime_def) |
81 |
assume "sqrt (real p) \<in> \<rat>" |
|
82 |
then obtain m n where |
|
83 |
n: "n \<noteq> 0" and sqrt_rat: "\<bar>sqrt (real p)\<bar> = real m / real n" |
|
84 |
and gcd: "gcd (m, n) = 1" .. |
|
85 |
have eq: "m\<twosuperior> = p * n\<twosuperior>" |
|
86 |
proof - |
|
87 |
from n and sqrt_rat have "real m = \<bar>sqrt (real p)\<bar> * real n" by simp |
|
88 |
then have "real (m\<twosuperior>) = (sqrt (real p))\<twosuperior> * real (n\<twosuperior>)" |
|
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14305
diff
changeset
|
89 |
by (auto simp add: power2_eq_square) |
13957 | 90 |
also have "(sqrt (real p))\<twosuperior> = real p" by simp |
91 |
also have "\<dots> * real (n\<twosuperior>) = real (p * n\<twosuperior>)" by simp |
|
92 |
finally show ?thesis .. |
|
93 |
qed |
|
94 |
have "p dvd m \<and> p dvd n" |
|
95 |
proof |
|
96 |
from eq have "p dvd m\<twosuperior>" .. |
|
97 |
with p_prime show "p dvd m" by (rule prime_dvd_power_two) |
|
98 |
then obtain k where "m = p * k" .. |
|
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14305
diff
changeset
|
99 |
with eq have "p * n\<twosuperior> = p\<twosuperior> * k\<twosuperior>" by (auto simp add: power2_eq_square mult_ac) |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14305
diff
changeset
|
100 |
with p have "n\<twosuperior> = p * k\<twosuperior>" by (simp add: power2_eq_square) |
13957 | 101 |
then have "p dvd n\<twosuperior>" .. |
102 |
with p_prime show "p dvd n" by (rule prime_dvd_power_two) |
|
103 |
qed |
|
104 |
then have "p dvd gcd (m, n)" .. |
|
105 |
with gcd have "p dvd 1" by simp |
|
106 |
then have "p \<le> 1" by (simp add: dvd_imp_le) |
|
107 |
with p show False by simp |
|
108 |
qed |
|
109 |
||
110 |
corollary "sqrt (real (2::nat)) \<notin> \<rat>" |
|
111 |
by (rule sqrt_prime_irrational) (rule two_is_prime) |
|
112 |
||
113 |
||
114 |
subsection {* Variations *} |
|
115 |
||
116 |
text {* |
|
117 |
Here is an alternative version of the main proof, using mostly |
|
118 |
linear forward-reasoning. While this results in less top-down |
|
119 |
structure, it is probably closer to proofs seen in mathematics. |
|
120 |
*} |
|
121 |
||
16663 | 122 |
theorem "prime p \<Longrightarrow> sqrt (real p) \<notin> \<rat>" |
13957 | 123 |
proof |
16663 | 124 |
assume p_prime: "prime p" |
13957 | 125 |
then have p: "1 < p" by (simp add: prime_def) |
126 |
assume "sqrt (real p) \<in> \<rat>" |
|
127 |
then obtain m n where |
|
128 |
n: "n \<noteq> 0" and sqrt_rat: "\<bar>sqrt (real p)\<bar> = real m / real n" |
|
129 |
and gcd: "gcd (m, n) = 1" .. |
|
130 |
from n and sqrt_rat have "real m = \<bar>sqrt (real p)\<bar> * real n" by simp |
|
131 |
then have "real (m\<twosuperior>) = (sqrt (real p))\<twosuperior> * real (n\<twosuperior>)" |
|
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14305
diff
changeset
|
132 |
by (auto simp add: power2_eq_square) |
13957 | 133 |
also have "(sqrt (real p))\<twosuperior> = real p" by simp |
134 |
also have "\<dots> * real (n\<twosuperior>) = real (p * n\<twosuperior>)" by simp |
|
135 |
finally have eq: "m\<twosuperior> = p * n\<twosuperior>" .. |
|
136 |
then have "p dvd m\<twosuperior>" .. |
|
137 |
with p_prime have dvd_m: "p dvd m" by (rule prime_dvd_power_two) |
|
138 |
then obtain k where "m = p * k" .. |
|
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14305
diff
changeset
|
139 |
with eq have "p * n\<twosuperior> = p\<twosuperior> * k\<twosuperior>" by (auto simp add: power2_eq_square mult_ac) |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14305
diff
changeset
|
140 |
with p have "n\<twosuperior> = p * k\<twosuperior>" by (simp add: power2_eq_square) |
13957 | 141 |
then have "p dvd n\<twosuperior>" .. |
142 |
with p_prime have "p dvd n" by (rule prime_dvd_power_two) |
|
143 |
with dvd_m have "p dvd gcd (m, n)" by (rule gcd_greatest) |
|
144 |
with gcd have "p dvd 1" by simp |
|
145 |
then have "p \<le> 1" by (simp add: dvd_imp_le) |
|
146 |
with p show False by simp |
|
147 |
qed |
|
148 |
||
149 |
end |