author | wenzelm |
Tue, 24 Jul 2012 23:01:55 +0200 | |
changeset 48494 | 00eb5be9e76b |
parent 46495 | 8e8a339e176f |
child 51708 | 5188a18c33b1 |
permissions | -rw-r--r-- |
28952
15a4b2cf8c34
made repository layout more coherent with logical distribution structure; stripped some $Id$s
haftmann
parents:
28001
diff
changeset
|
1 |
(* Title: HOL/ex/Sqrt.thy |
45917 | 2 |
Author: Markus Wenzel, Tobias Nipkow, TU Muenchen |
13957 | 3 |
*) |
4 |
||
5 |
header {* Square roots of primes are irrational *} |
|
6 |
||
15149 | 7 |
theory Sqrt |
32479 | 8 |
imports Complex_Main "~~/src/HOL/Number_Theory/Primes" |
15149 | 9 |
begin |
13957 | 10 |
|
46495 | 11 |
text {* The square root of any prime number (including 2) is irrational. *} |
13957 | 12 |
|
19086 | 13 |
theorem sqrt_prime_irrational: |
31712 | 14 |
assumes "prime (p::nat)" |
19086 | 15 |
shows "sqrt (real p) \<notin> \<rat>" |
13957 | 16 |
proof |
31712 | 17 |
from `prime p` have p: "1 < p" by (simp add: prime_nat_def) |
13957 | 18 |
assume "sqrt (real p) \<in> \<rat>" |
31712 | 19 |
then obtain m n :: nat where |
13957 | 20 |
n: "n \<noteq> 0" and sqrt_rat: "\<bar>sqrt (real p)\<bar> = real m / real n" |
30411 | 21 |
and gcd: "gcd m n = 1" by (rule Rats_abs_nat_div_natE) |
13957 | 22 |
have eq: "m\<twosuperior> = p * n\<twosuperior>" |
23 |
proof - |
|
24 |
from n and sqrt_rat have "real m = \<bar>sqrt (real p)\<bar> * real n" by simp |
|
25 |
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
|
26 |
by (auto simp add: power2_eq_square) |
13957 | 27 |
also have "(sqrt (real p))\<twosuperior> = real p" by simp |
28 |
also have "\<dots> * real (n\<twosuperior>) = real (p * n\<twosuperior>)" by simp |
|
29 |
finally show ?thesis .. |
|
30 |
qed |
|
31 |
have "p dvd m \<and> p dvd n" |
|
32 |
proof |
|
33 |
from eq have "p dvd m\<twosuperior>" .. |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31712
diff
changeset
|
34 |
with `prime p` pos2 show "p dvd m" by (rule prime_dvd_power_nat) |
13957 | 35 |
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
|
36 |
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
|
37 |
with p have "n\<twosuperior> = p * k\<twosuperior>" by (simp add: power2_eq_square) |
13957 | 38 |
then have "p dvd n\<twosuperior>" .. |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31712
diff
changeset
|
39 |
with `prime p` pos2 show "p dvd n" by (rule prime_dvd_power_nat) |
13957 | 40 |
qed |
27556 | 41 |
then have "p dvd gcd m n" .. |
13957 | 42 |
with gcd have "p dvd 1" by simp |
43 |
then have "p \<le> 1" by (simp add: dvd_imp_le) |
|
44 |
with p show False by simp |
|
45 |
qed |
|
46 |
||
45917 | 47 |
corollary sqrt_real_2_not_rat: "sqrt (real (2::nat)) \<notin> \<rat>" |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31712
diff
changeset
|
48 |
by (rule sqrt_prime_irrational) (rule two_is_prime_nat) |
13957 | 49 |
|
50 |
||
51 |
subsection {* Variations *} |
|
52 |
||
53 |
text {* |
|
54 |
Here is an alternative version of the main proof, using mostly |
|
55 |
linear forward-reasoning. While this results in less top-down |
|
56 |
structure, it is probably closer to proofs seen in mathematics. |
|
57 |
*} |
|
58 |
||
19086 | 59 |
theorem |
31712 | 60 |
assumes "prime (p::nat)" |
19086 | 61 |
shows "sqrt (real p) \<notin> \<rat>" |
13957 | 62 |
proof |
31712 | 63 |
from `prime p` have p: "1 < p" by (simp add: prime_nat_def) |
13957 | 64 |
assume "sqrt (real p) \<in> \<rat>" |
31712 | 65 |
then obtain m n :: nat where |
13957 | 66 |
n: "n \<noteq> 0" and sqrt_rat: "\<bar>sqrt (real p)\<bar> = real m / real n" |
30411 | 67 |
and gcd: "gcd m n = 1" by (rule Rats_abs_nat_div_natE) |
13957 | 68 |
from n and sqrt_rat have "real m = \<bar>sqrt (real p)\<bar> * real n" by simp |
69 |
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
|
70 |
by (auto simp add: power2_eq_square) |
13957 | 71 |
also have "(sqrt (real p))\<twosuperior> = real p" by simp |
72 |
also have "\<dots> * real (n\<twosuperior>) = real (p * n\<twosuperior>)" by simp |
|
73 |
finally have eq: "m\<twosuperior> = p * n\<twosuperior>" .. |
|
74 |
then have "p dvd m\<twosuperior>" .. |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31712
diff
changeset
|
75 |
with `prime p` pos2 have dvd_m: "p dvd m" by (rule prime_dvd_power_nat) |
13957 | 76 |
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
|
77 |
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
|
78 |
with p have "n\<twosuperior> = p * k\<twosuperior>" by (simp add: power2_eq_square) |
13957 | 79 |
then have "p dvd n\<twosuperior>" .. |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31712
diff
changeset
|
80 |
with `prime p` pos2 have "p dvd n" by (rule prime_dvd_power_nat) |
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31712
diff
changeset
|
81 |
with dvd_m have "p dvd gcd m n" by (rule gcd_greatest_nat) |
13957 | 82 |
with gcd have "p dvd 1" by simp |
83 |
then have "p \<le> 1" by (simp add: dvd_imp_le) |
|
84 |
with p show False by simp |
|
85 |
qed |
|
86 |
||
45917 | 87 |
|
46495 | 88 |
text {* Another old chestnut, which is a consequence of the irrationality of 2. *} |
45917 | 89 |
|
90 |
lemma "\<exists>a b::real. a \<notin> \<rat> \<and> b \<notin> \<rat> \<and> a powr b \<in> \<rat>" (is "EX a b. ?P a b") |
|
91 |
proof cases |
|
92 |
assume "sqrt 2 powr sqrt 2 \<in> \<rat>" |
|
46495 | 93 |
then have "?P (sqrt 2) (sqrt 2)" |
94 |
by (metis sqrt_real_2_not_rat [simplified]) |
|
95 |
then show ?thesis by blast |
|
45917 | 96 |
next |
97 |
assume 1: "sqrt 2 powr sqrt 2 \<notin> \<rat>" |
|
98 |
have "(sqrt 2 powr sqrt 2) powr sqrt 2 = 2" |
|
46495 | 99 |
using powr_realpow [of _ 2] |
100 |
by (simp add: powr_powr power2_eq_square [symmetric]) |
|
101 |
then have "?P (sqrt 2 powr sqrt 2) (sqrt 2)" |
|
102 |
by (metis 1 Rats_number_of sqrt_real_2_not_rat [simplified]) |
|
103 |
then show ?thesis by blast |
|
45917 | 104 |
qed |
105 |
||
13957 | 106 |
end |