1 (* Title: HOL/Real/ex/Sqrt.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 = Primes + Real: |
|
10 |
|
11 subsection {* The set of rational numbers *} |
|
12 |
|
13 constdefs |
|
14 rationals :: "real set" ("\<rat>") |
|
15 "\<rat> == {x. \<exists>m n. n \<noteq> 0 \<and> \<bar>x\<bar> = real (m::nat) / real (n::nat)}" |
|
16 |
|
17 theorem rationals_rep: "x \<in> \<rat> ==> |
|
18 \<exists>m n. n \<noteq> 0 \<and> \<bar>x\<bar> = real m / real n \<and> gcd (m, n) = 1" |
|
19 proof - |
|
20 assume "x \<in> \<rat>" |
|
21 then obtain m n :: nat where n: "n \<noteq> 0" and x_rat: "\<bar>x\<bar> = real m / real n" |
|
22 by (unfold rationals_def) blast |
|
23 let ?gcd = "gcd (m, n)" |
|
24 from n have gcd: "?gcd \<noteq> 0" by (simp add: gcd_zero) |
|
25 let ?k = "m div ?gcd" |
|
26 let ?l = "n div ?gcd" |
|
27 let ?gcd' = "gcd (?k, ?l)" |
|
28 have "?gcd dvd m" .. hence gcd_k: "?gcd * ?k = m" |
|
29 by (rule dvd_mult_div_cancel) |
|
30 have "?gcd dvd n" .. hence gcd_l: "?gcd * ?l = n" |
|
31 by (rule dvd_mult_div_cancel) |
|
32 |
|
33 from n gcd_l have "?l \<noteq> 0" |
|
34 by (auto iff del: neq0_conv) |
|
35 moreover |
|
36 have "\<bar>x\<bar> = real ?k / real ?l" |
|
37 proof - |
|
38 from gcd have "real ?k / real ?l = real (?gcd * ?k) / real (?gcd * ?l)" |
|
39 by (simp add: real_mult_div_cancel1) |
|
40 also from gcd_k gcd_l have "... = real m / real n" by simp |
|
41 also from x_rat have "... = \<bar>x\<bar>" .. |
|
42 finally show ?thesis .. |
|
43 qed |
|
44 moreover |
|
45 have "?gcd' = 1" |
|
46 proof - |
|
47 have "?gcd * ?gcd' = gcd (?gcd * ?k, ?gcd * ?l)" |
|
48 by (rule gcd_mult_distrib2) |
|
49 with gcd_k gcd_l have "?gcd * ?gcd' = ?gcd" by simp |
|
50 with gcd show ?thesis by simp |
|
51 qed |
|
52 ultimately show ?thesis by blast |
|
53 qed |
|
54 |
|
55 lemma [elim?]: "r \<in> \<rat> ==> |
|
56 (!!m n. n \<noteq> 0 ==> \<bar>r\<bar> = real m / real n ==> gcd (m, n) = 1 ==> C) |
|
57 ==> C" |
|
58 by (insert rationals_rep) blast |
|
59 |
|
60 |
|
61 subsection {* Main theorem *} |
|
62 |
|
63 text {* |
|
64 The square root of any prime number (including @{text 2}) is |
|
65 irrational. |
|
66 *} |
|
67 |
|
68 theorem sqrt_prime_irrational: "x\<twosuperior> = real p ==> p \<in> prime ==> x \<notin> \<rat>" |
|
69 proof |
|
70 assume x_sqrt: "x\<twosuperior> = real p" |
|
71 assume p_prime: "p \<in> prime" |
|
72 hence p: "1 < p" by (simp add: prime_def) |
|
73 assume "x \<in> \<rat>" |
|
74 then obtain m n where |
|
75 n: "n \<noteq> 0" and x_rat: "\<bar>x\<bar> = real m / real n" and gcd: "gcd (m, n) = 1" .. |
|
76 have eq: "m\<twosuperior> = p * n\<twosuperior>" |
|
77 proof - |
|
78 from n x_rat have "real m = \<bar>x\<bar> * real n" by simp |
|
79 hence "real (m\<twosuperior>) = x\<twosuperior> * real (n\<twosuperior>)" |
|
80 by (simp add: power_two real_power_two split: abs_split) |
|
81 also from x_sqrt have "... = real (p * n\<twosuperior>)" by simp |
|
82 finally show ?thesis .. |
|
83 qed |
|
84 have "p dvd m \<and> p dvd n" |
|
85 proof |
|
86 from eq have "p dvd m\<twosuperior>" .. |
|
87 with p_prime show "p dvd m" by (rule prime_dvd_power_two) |
|
88 then obtain k where "m = p * k" .. |
|
89 with eq have "p * n\<twosuperior> = p\<twosuperior> * k\<twosuperior>" by (auto simp add: power_two mult_ac) |
|
90 with p have "n\<twosuperior> = p * k\<twosuperior>" by (simp add: power_two) |
|
91 hence "p dvd n\<twosuperior>" .. |
|
92 with p_prime show "p dvd n" by (rule prime_dvd_power_two) |
|
93 qed |
|
94 hence "p dvd gcd (m, n)" .. |
|
95 with gcd have "p dvd 1" by simp |
|
96 hence "p \<le> 1" by (simp add: dvd_imp_le) |
|
97 with p show False by simp |
|
98 qed |
|
99 |
|
100 |
|
101 subsection {* Variations *} |
|
102 |
|
103 text {* |
|
104 Just for the record: we instantiate the main theorem for the |
|
105 specific prime number @{text 2} (real mathematicians would never do |
|
106 this formally :-). |
|
107 *} |
|
108 |
|
109 theorem "x\<twosuperior> = real (2::nat) ==> x \<notin> \<rat>" |
|
110 proof (rule sqrt_prime_irrational) |
|
111 { |
|
112 fix m :: nat assume dvd: "m dvd 2" |
|
113 hence "m \<le> 2" by (simp add: dvd_imp_le) |
|
114 moreover from dvd have "m \<noteq> 0" by (auto iff del: neq0_conv) |
|
115 ultimately have "m = 1 \<or> m = 2" by arith |
|
116 } |
|
117 thus "2 \<in> prime" by (simp add: prime_def) |
|
118 qed |
|
119 |
|
120 text {* |
|
121 \medskip An alternative version of the main proof, using mostly |
|
122 linear forward-reasoning. While this results in less top-down |
|
123 structure, it is probably closer to proofs seen in mathematics. |
|
124 *} |
|
125 |
|
126 theorem "x\<twosuperior> = real p ==> p \<in> prime ==> x \<notin> \<rat>" |
|
127 proof |
|
128 assume x_sqrt: "x\<twosuperior> = real p" |
|
129 assume p_prime: "p \<in> prime" |
|
130 hence p: "1 < p" by (simp add: prime_def) |
|
131 assume "x \<in> \<rat>" |
|
132 then obtain m n where |
|
133 n: "n \<noteq> 0" and x_rat: "\<bar>x\<bar> = real m / real n" and gcd: "gcd (m, n) = 1" .. |
|
134 from n x_rat have "real m = \<bar>x\<bar> * real n" by simp |
|
135 hence "real (m\<twosuperior>) = x\<twosuperior> * real (n\<twosuperior>)" |
|
136 by (simp add: power_two real_power_two split: abs_split) |
|
137 also from x_sqrt have "... = real (p * n\<twosuperior>)" by simp |
|
138 finally have eq: "m\<twosuperior> = p * n\<twosuperior>" .. |
|
139 hence "p dvd m\<twosuperior>" .. |
|
140 with p_prime have dvd_m: "p dvd m" by (rule prime_dvd_power_two) |
|
141 then obtain k where "m = p * k" .. |
|
142 with eq have "p * n\<twosuperior> = p\<twosuperior> * k\<twosuperior>" by (auto simp add: power_two mult_ac) |
|
143 with p have "n\<twosuperior> = p * k\<twosuperior>" by (simp add: power_two) |
|
144 hence "p dvd n\<twosuperior>" .. |
|
145 with p_prime have "p dvd n" by (rule prime_dvd_power_two) |
|
146 with dvd_m have "p dvd gcd (m, n)" by (rule gcd_greatest) |
|
147 with gcd have "p dvd 1" by simp |
|
148 hence "p \<le> 1" by (simp add: dvd_imp_le) |
|
149 with p show False by simp |
|
150 qed |
|
151 |
|
152 end |
|