author | haftmann |
Mon, 13 Sep 2021 14:18:24 +0000 | |
changeset 74309 | 42523fbf643b |
parent 73811 | f143d0a4cb6a |
permissions | -rw-r--r-- |
73811 | 1 |
(* Title: HOL/Examples/Sqrt.thy |
73810 | 2 |
Author: Makarius |
3 |
Author: Tobias Nipkow, TU Muenchen |
|
13957 | 4 |
*) |
5 |
||
59031 | 6 |
section \<open>Square roots of primes are irrational\<close> |
13957 | 7 |
|
15149 | 8 |
theory Sqrt |
73810 | 9 |
imports Complex_Main "HOL-Computational_Algebra.Primes" |
15149 | 10 |
begin |
13957 | 11 |
|
73810 | 12 |
text \<open> |
13 |
The square root of any prime number (including 2) is irrational. |
|
14 |
\<close> |
|
13957 | 15 |
|
19086 | 16 |
theorem sqrt_prime_irrational: |
73810 | 17 |
fixes p :: nat |
18 |
assumes "prime p" |
|
51708 | 19 |
shows "sqrt p \<notin> \<rat>" |
13957 | 20 |
proof |
73810 | 21 |
from \<open>prime p\<close> have p: "p > 1" by (rule prime_gt_1_nat) |
51708 | 22 |
assume "sqrt p \<in> \<rat>" |
73810 | 23 |
then obtain m n :: nat |
24 |
where n: "n \<noteq> 0" |
|
25 |
and sqrt_rat: "\<bar>sqrt p\<bar> = m / n" |
|
26 |
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
|
27 |
have eq: "m\<^sup>2 = p * n\<^sup>2" |
13957 | 28 |
proof - |
51708 | 29 |
from n and sqrt_rat have "m = \<bar>sqrt p\<bar> * n" by simp |
73810 | 30 |
then have "m\<^sup>2 = (sqrt p)\<^sup>2 * n\<^sup>2" by (simp add: power_mult_distrib) |
53015
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents:
51708
diff
changeset
|
31 |
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
|
32 |
also have "\<dots> * n\<^sup>2 = p * n\<^sup>2" by simp |
73810 | 33 |
finally show ?thesis by linarith |
13957 | 34 |
qed |
35 |
have "p dvd m \<and> p dvd n" |
|
36 |
proof |
|
53015
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents:
51708
diff
changeset
|
37 |
from eq have "p dvd m\<^sup>2" .. |
73810 | 38 |
with \<open>prime p\<close> show "p dvd m" by (rule prime_dvd_power) |
13957 | 39 |
then obtain k where "m = p * k" .. |
73810 | 40 |
with eq have "p * n\<^sup>2 = p\<^sup>2 * k\<^sup>2" by algebra |
53015
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents:
51708
diff
changeset
|
41 |
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
|
42 |
then have "p dvd n\<^sup>2" .. |
73810 | 43 |
with \<open>prime p\<close> show "p dvd n" by (rule prime_dvd_power) |
13957 | 44 |
qed |
60690 | 45 |
then have "p dvd gcd m n" by simp |
46 |
with \<open>coprime m n\<close> have "p = 1" by simp |
|
13957 | 47 |
with p show False by simp |
48 |
qed |
|
49 |
||
51708 | 50 |
corollary sqrt_2_not_rat: "sqrt 2 \<notin> \<rat>" |
73810 | 51 |
using sqrt_prime_irrational [of 2] by simp |
59031 | 52 |
|
53 |
text \<open> |
|
73810 | 54 |
Here is an alternative version of the main proof, using mostly linear |
55 |
forward-reasoning. While this results in less top-down structure, it is |
|
56 |
probably closer to proofs seen in mathematics. |
|
59031 | 57 |
\<close> |
13957 | 58 |
|
19086 | 59 |
theorem |
73810 | 60 |
fixes p :: nat |
61 |
assumes "prime p" |
|
51708 | 62 |
shows "sqrt p \<notin> \<rat>" |
13957 | 63 |
proof |
73810 | 64 |
from \<open>prime p\<close> have p: "p > 1" by (rule prime_gt_1_nat) |
51708 | 65 |
assume "sqrt p \<in> \<rat>" |
73810 | 66 |
then obtain m n :: nat |
67 |
where n: "n \<noteq> 0" |
|
68 |
and sqrt_rat: "\<bar>sqrt p\<bar> = m / n" |
|
69 |
and "coprime m n" by (rule Rats_abs_nat_div_natE) |
|
51708 | 70 |
from n and sqrt_rat have "m = \<bar>sqrt p\<bar> * n" by simp |
73810 | 71 |
then have "m\<^sup>2 = (sqrt p)\<^sup>2 * n\<^sup>2" 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
|
72 |
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
|
73 |
also have "\<dots> * n\<^sup>2 = p * n\<^sup>2" by simp |
73810 | 74 |
finally have eq: "m\<^sup>2 = p * n\<^sup>2" by linarith |
53015
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents:
51708
diff
changeset
|
75 |
then have "p dvd m\<^sup>2" .. |
73810 | 76 |
with \<open>prime p\<close> have dvd_m: "p dvd m" by (rule prime_dvd_power) |
13957 | 77 |
then obtain k where "m = p * k" .. |
73810 | 78 |
with eq have "p * n\<^sup>2 = p\<^sup>2 * k\<^sup>2" by algebra |
53015
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents:
51708
diff
changeset
|
79 |
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
|
80 |
then have "p dvd n\<^sup>2" .. |
73810 | 81 |
with \<open>prime p\<close> have "p dvd n" by (rule prime_dvd_power) |
62348 | 82 |
with dvd_m have "p dvd gcd m n" by (rule gcd_greatest) |
60690 | 83 |
with \<open>coprime m n\<close> have "p = 1" by simp |
13957 | 84 |
with p show False by simp |
85 |
qed |
|
86 |
||
45917 | 87 |
|
73810 | 88 |
text \<open> |
89 |
Another old chestnut, which is a consequence of the irrationality of |
|
90 |
\<^term>\<open>sqrt 2\<close>. |
|
91 |
\<close> |
|
45917 | 92 |
|
59031 | 93 |
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") |
73809
ce9529a616fd
misc tuning --- following hints by Jørgen Villadsen (see also 1ce1bc9ff64a);
wenzelm
parents:
66453
diff
changeset
|
94 |
proof (cases "sqrt 2 powr sqrt 2 \<in> \<rat>") |
ce9529a616fd
misc tuning --- following hints by Jørgen Villadsen (see also 1ce1bc9ff64a);
wenzelm
parents:
66453
diff
changeset
|
95 |
case True |
ce9529a616fd
misc tuning --- following hints by Jørgen Villadsen (see also 1ce1bc9ff64a);
wenzelm
parents:
66453
diff
changeset
|
96 |
with sqrt_2_not_rat have "?P (sqrt 2) (sqrt 2)" by simp |
46495 | 97 |
then show ?thesis by blast |
45917 | 98 |
next |
73809
ce9529a616fd
misc tuning --- following hints by Jørgen Villadsen (see also 1ce1bc9ff64a);
wenzelm
parents:
66453
diff
changeset
|
99 |
case False |
ce9529a616fd
misc tuning --- following hints by Jørgen Villadsen (see also 1ce1bc9ff64a);
wenzelm
parents:
66453
diff
changeset
|
100 |
with sqrt_2_not_rat powr_powr have "?P (sqrt 2 powr sqrt 2) (sqrt 2)" by simp |
46495 | 101 |
then show ?thesis by blast |
45917 | 102 |
qed |
103 |
||
13957 | 104 |
end |