| author | wenzelm | 
| Sat, 12 Oct 2019 18:41:12 +0200 | |
| changeset 70849 | ef77ddd9cc6a | 
| parent 66453 | cc19f7ca2ed6 | 
| child 73809 | ce9529a616fd | 
| 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  | 
||
| 59031 | 5  | 
section \<open>Square roots of primes are irrational\<close>  | 
| 13957 | 6  | 
|
| 15149 | 7  | 
theory Sqrt  | 
| 
66453
 
cc19f7ca2ed6
session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
 
wenzelm 
parents: 
65417 
diff
changeset
 | 
8  | 
imports Complex_Main "HOL-Computational_Algebra.Primes"  | 
| 15149 | 9  | 
begin  | 
| 13957 | 10  | 
|
| 59031 | 11  | 
text \<open>The square root of any prime number (including 2) is irrational.\<close>  | 
| 13957 | 12  | 
|
| 19086 | 13  | 
theorem sqrt_prime_irrational:  | 
| 31712 | 14  | 
assumes "prime (p::nat)"  | 
| 51708 | 15  | 
shows "sqrt p \<notin> \<rat>"  | 
| 13957 | 16  | 
proof  | 
| 63635 | 17  | 
from \<open>prime p\<close> have p: "1 < p" by (simp add: prime_nat_iff)  | 
| 51708 | 18  | 
assume "sqrt p \<in> \<rat>"  | 
| 31712 | 19  | 
then obtain m n :: nat where  | 
| 51708 | 20  | 
n: "n \<noteq> 0" and sqrt_rat: "\<bar>sqrt p\<bar> = m / n"  | 
| 60690 | 21  | 
and "coprime m n" by (rule Rats_abs_nat_div_natE)  | 
| 
53015
 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 
wenzelm 
parents: 
51708 
diff
changeset
 | 
22  | 
have eq: "m\<^sup>2 = p * n\<^sup>2"  | 
| 13957 | 23  | 
proof -  | 
| 51708 | 24  | 
from n and sqrt_rat have "m = \<bar>sqrt p\<bar> * n" by simp  | 
| 
53015
 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 
wenzelm 
parents: 
51708 
diff
changeset
 | 
25  | 
then have "m\<^sup>2 = (sqrt p)\<^sup>2 * n\<^sup>2"  | 
| 
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)  | 
| 
53015
 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 
wenzelm 
parents: 
51708 
diff
changeset
 | 
27  | 
also have "(sqrt p)\<^sup>2 = p" by simp  | 
| 
 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 
wenzelm 
parents: 
51708 
diff
changeset
 | 
28  | 
also have "\<dots> * n\<^sup>2 = p * n\<^sup>2" by simp  | 
| 
61649
 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 
paulson <lp15@cam.ac.uk> 
parents: 
60690 
diff
changeset
 | 
29  | 
finally show ?thesis using of_nat_eq_iff by blast  | 
| 13957 | 30  | 
qed  | 
31  | 
have "p dvd m \<and> p dvd n"  | 
|
32  | 
proof  | 
|
| 
53015
 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 
wenzelm 
parents: 
51708 
diff
changeset
 | 
33  | 
from eq have "p dvd m\<^sup>2" ..  | 
| 59031 | 34  | 
with \<open>prime p\<close> show "p dvd m" by (rule prime_dvd_power_nat)  | 
| 13957 | 35  | 
then obtain k where "m = p * k" ..  | 
| 
57514
 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 
haftmann 
parents: 
53598 
diff
changeset
 | 
36  | 
with eq have "p * n\<^sup>2 = p\<^sup>2 * k\<^sup>2" by (auto simp add: power2_eq_square ac_simps)  | 
| 
53015
 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 
wenzelm 
parents: 
51708 
diff
changeset
 | 
37  | 
with p have "n\<^sup>2 = p * k\<^sup>2" by (simp add: power2_eq_square)  | 
| 
 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 
wenzelm 
parents: 
51708 
diff
changeset
 | 
38  | 
then have "p dvd n\<^sup>2" ..  | 
| 59031 | 39  | 
with \<open>prime p\<close> show "p dvd n" by (rule prime_dvd_power_nat)  | 
| 13957 | 40  | 
qed  | 
| 60690 | 41  | 
then have "p dvd gcd m n" by simp  | 
42  | 
with \<open>coprime m n\<close> have "p = 1" by simp  | 
|
| 13957 | 43  | 
with p show False by simp  | 
44  | 
qed  | 
|
45  | 
||
| 51708 | 46  | 
corollary sqrt_2_not_rat: "sqrt 2 \<notin> \<rat>"  | 
47  | 
using sqrt_prime_irrational[of 2] by simp  | 
|
| 13957 | 48  | 
|
49  | 
||
| 59031 | 50  | 
subsection \<open>Variations\<close>  | 
51  | 
||
52  | 
text \<open>  | 
|
| 13957 | 53  | 
Here is an alternative version of the main proof, using mostly  | 
54  | 
linear forward-reasoning. While this results in less top-down  | 
|
55  | 
structure, it is probably closer to proofs seen in mathematics.  | 
|
| 59031 | 56  | 
\<close>  | 
| 13957 | 57  | 
|
| 19086 | 58  | 
theorem  | 
| 31712 | 59  | 
assumes "prime (p::nat)"  | 
| 51708 | 60  | 
shows "sqrt p \<notin> \<rat>"  | 
| 13957 | 61  | 
proof  | 
| 63635 | 62  | 
from \<open>prime p\<close> have p: "1 < p" by (simp add: prime_nat_iff)  | 
| 51708 | 63  | 
assume "sqrt p \<in> \<rat>"  | 
| 31712 | 64  | 
then obtain m n :: nat where  | 
| 51708 | 65  | 
n: "n \<noteq> 0" and sqrt_rat: "\<bar>sqrt p\<bar> = m / n"  | 
| 60690 | 66  | 
and "coprime m n" by (rule Rats_abs_nat_div_natE)  | 
| 51708 | 67  | 
from n and sqrt_rat have "m = \<bar>sqrt p\<bar> * n" by simp  | 
| 
53015
 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 
wenzelm 
parents: 
51708 
diff
changeset
 | 
68  | 
then have "m\<^sup>2 = (sqrt p)\<^sup>2 * n\<^sup>2"  | 
| 
14353
 
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
 
paulson 
parents: 
14305 
diff
changeset
 | 
69  | 
by (auto simp add: power2_eq_square)  | 
| 
53015
 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 
wenzelm 
parents: 
51708 
diff
changeset
 | 
70  | 
also have "(sqrt p)\<^sup>2 = p" by simp  | 
| 
 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 
wenzelm 
parents: 
51708 
diff
changeset
 | 
71  | 
also have "\<dots> * n\<^sup>2 = p * n\<^sup>2" by simp  | 
| 
61649
 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 
paulson <lp15@cam.ac.uk> 
parents: 
60690 
diff
changeset
 | 
72  | 
finally have eq: "m\<^sup>2 = p * n\<^sup>2" using of_nat_eq_iff by blast  | 
| 
53015
 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 
wenzelm 
parents: 
51708 
diff
changeset
 | 
73  | 
then have "p dvd m\<^sup>2" ..  | 
| 59031 | 74  | 
with \<open>prime p\<close> have dvd_m: "p dvd m" by (rule prime_dvd_power_nat)  | 
| 13957 | 75  | 
then obtain k where "m = p * k" ..  | 
| 
57514
 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 
haftmann 
parents: 
53598 
diff
changeset
 | 
76  | 
with eq have "p * n\<^sup>2 = p\<^sup>2 * k\<^sup>2" by (auto simp add: power2_eq_square ac_simps)  | 
| 
53015
 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 
wenzelm 
parents: 
51708 
diff
changeset
 | 
77  | 
with p have "n\<^sup>2 = p * k\<^sup>2" by (simp add: power2_eq_square)  | 
| 
 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 
wenzelm 
parents: 
51708 
diff
changeset
 | 
78  | 
then have "p dvd n\<^sup>2" ..  | 
| 59031 | 79  | 
with \<open>prime p\<close> have "p dvd n" by (rule prime_dvd_power_nat)  | 
| 62348 | 80  | 
with dvd_m have "p dvd gcd m n" by (rule gcd_greatest)  | 
| 60690 | 81  | 
with \<open>coprime m n\<close> have "p = 1" by simp  | 
| 13957 | 82  | 
with p show False by simp  | 
83  | 
qed  | 
|
84  | 
||
| 45917 | 85  | 
|
| 59031 | 86  | 
text \<open>Another old chestnut, which is a consequence of the irrationality of 2.\<close>  | 
| 45917 | 87  | 
|
| 59031 | 88  | 
lemma "\<exists>a b::real. a \<notin> \<rat> \<and> b \<notin> \<rat> \<and> a powr b \<in> \<rat>" (is "\<exists>a b. ?P a b")  | 
| 45917 | 89  | 
proof cases  | 
90  | 
assume "sqrt 2 powr sqrt 2 \<in> \<rat>"  | 
|
| 46495 | 91  | 
then have "?P (sqrt 2) (sqrt 2)"  | 
| 51708 | 92  | 
by (metis sqrt_2_not_rat)  | 
| 46495 | 93  | 
then show ?thesis by blast  | 
| 45917 | 94  | 
next  | 
95  | 
assume 1: "sqrt 2 powr sqrt 2 \<notin> \<rat>"  | 
|
96  | 
have "(sqrt 2 powr sqrt 2) powr sqrt 2 = 2"  | 
|
| 46495 | 97  | 
using powr_realpow [of _ 2]  | 
98  | 
by (simp add: powr_powr power2_eq_square [symmetric])  | 
|
99  | 
then have "?P (sqrt 2 powr sqrt 2) (sqrt 2)"  | 
|
| 51708 | 100  | 
by (metis 1 Rats_number_of sqrt_2_not_rat)  | 
| 46495 | 101  | 
then show ?thesis by blast  | 
| 45917 | 102  | 
qed  | 
103  | 
||
| 13957 | 104  | 
end  |