src/HOL/ex/Sqrt.thy
author paulson <lp15@cam.ac.uk>
Tue, 01 Dec 2015 14:09:10 +0000
changeset 61762 d50b993b4fb9
parent 61649 268d88ec9087
child 62348 9a5f43dac883
permissions -rw-r--r--
Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
     2
    Author:     Markus Wenzel, Tobias Nipkow, TU Muenchen
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
     3
*)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
     4
59031
4c3bb56b8ce7 misc tuning and modernization;
wenzelm
parents: 58889
diff changeset
     5
section \<open>Square roots of primes are irrational\<close>
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
     6
15149
c5c4884634b7 new import syntax
nipkow
parents: 14981
diff changeset
     7
theory Sqrt
32479
521cc9bf2958 some reorganization of number theory
haftmann
parents: 31952
diff changeset
     8
imports Complex_Main "~~/src/HOL/Number_Theory/Primes"
15149
c5c4884634b7 new import syntax
nipkow
parents: 14981
diff changeset
     9
begin
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    10
59031
4c3bb56b8ce7 misc tuning and modernization;
wenzelm
parents: 58889
diff changeset
    11
text \<open>The square root of any prime number (including 2) is irrational.\<close>
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    12
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 16663
diff changeset
    13
theorem sqrt_prime_irrational:
31712
6f8aa9aea693 update ex/Sqrt.thy to use new GCD library
huffman
parents: 30411
diff changeset
    14
  assumes "prime (p::nat)"
51708
5188a18c33b1 use automatic type coerctions in Sqrt example
hoelzl
parents: 46495
diff changeset
    15
  shows "sqrt p \<notin> \<rat>"
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    16
proof
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 61649
diff changeset
    17
  from \<open>prime p\<close> have p: "1 < p" by (simp add: prime_def)
51708
5188a18c33b1 use automatic type coerctions in Sqrt example
hoelzl
parents: 46495
diff changeset
    18
  assume "sqrt p \<in> \<rat>"
31712
6f8aa9aea693 update ex/Sqrt.thy to use new GCD library
huffman
parents: 30411
diff changeset
    19
  then obtain m n :: nat where
51708
5188a18c33b1 use automatic type coerctions in Sqrt example
hoelzl
parents: 46495
diff changeset
    20
      n: "n \<noteq> 0" and sqrt_rat: "\<bar>sqrt p\<bar> = m / n"
60690
a9e45c9588c3 tuned facts
haftmann
parents: 59031
diff changeset
    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
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    23
  proof -
51708
5188a18c33b1 use automatic type coerctions in Sqrt example
hoelzl
parents: 46495
diff changeset
    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
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    30
  qed
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    31
  have "p dvd m \<and> p dvd n"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    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
4c3bb56b8ce7 misc tuning and modernization;
wenzelm
parents: 58889
diff changeset
    34
    with \<open>prime p\<close> show "p dvd m" by (rule prime_dvd_power_nat)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    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
4c3bb56b8ce7 misc tuning and modernization;
wenzelm
parents: 58889
diff changeset
    39
    with \<open>prime p\<close> show "p dvd n" by (rule prime_dvd_power_nat)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    40
  qed
60690
a9e45c9588c3 tuned facts
haftmann
parents: 59031
diff changeset
    41
  then have "p dvd gcd m n" by simp
a9e45c9588c3 tuned facts
haftmann
parents: 59031
diff changeset
    42
  with \<open>coprime m n\<close> have "p = 1" by simp
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    43
  with p show False by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    44
qed
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    45
51708
5188a18c33b1 use automatic type coerctions in Sqrt example
hoelzl
parents: 46495
diff changeset
    46
corollary sqrt_2_not_rat: "sqrt 2 \<notin> \<rat>"
5188a18c33b1 use automatic type coerctions in Sqrt example
hoelzl
parents: 46495
diff changeset
    47
  using sqrt_prime_irrational[of 2] by simp
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    48
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    49
59031
4c3bb56b8ce7 misc tuning and modernization;
wenzelm
parents: 58889
diff changeset
    50
subsection \<open>Variations\<close>
4c3bb56b8ce7 misc tuning and modernization;
wenzelm
parents: 58889
diff changeset
    51
4c3bb56b8ce7 misc tuning and modernization;
wenzelm
parents: 58889
diff changeset
    52
text \<open>
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    53
  Here is an alternative version of the main proof, using mostly
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    54
  linear forward-reasoning.  While this results in less top-down
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    55
  structure, it is probably closer to proofs seen in mathematics.
59031
4c3bb56b8ce7 misc tuning and modernization;
wenzelm
parents: 58889
diff changeset
    56
\<close>
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    57
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 16663
diff changeset
    58
theorem
31712
6f8aa9aea693 update ex/Sqrt.thy to use new GCD library
huffman
parents: 30411
diff changeset
    59
  assumes "prime (p::nat)"
51708
5188a18c33b1 use automatic type coerctions in Sqrt example
hoelzl
parents: 46495
diff changeset
    60
  shows "sqrt p \<notin> \<rat>"
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    61
proof
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 61649
diff changeset
    62
  from \<open>prime p\<close> have p: "1 < p" by (simp add: prime_def)
51708
5188a18c33b1 use automatic type coerctions in Sqrt example
hoelzl
parents: 46495
diff changeset
    63
  assume "sqrt p \<in> \<rat>"
31712
6f8aa9aea693 update ex/Sqrt.thy to use new GCD library
huffman
parents: 30411
diff changeset
    64
  then obtain m n :: nat where
51708
5188a18c33b1 use automatic type coerctions in Sqrt example
hoelzl
parents: 46495
diff changeset
    65
      n: "n \<noteq> 0" and sqrt_rat: "\<bar>sqrt p\<bar> = m / n"
60690
a9e45c9588c3 tuned facts
haftmann
parents: 59031
diff changeset
    66
    and "coprime m n" by (rule Rats_abs_nat_div_natE)
51708
5188a18c33b1 use automatic type coerctions in Sqrt example
hoelzl
parents: 46495
diff changeset
    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
4c3bb56b8ce7 misc tuning and modernization;
wenzelm
parents: 58889
diff changeset
    74
  with \<open>prime p\<close> have dvd_m: "p dvd m" by (rule prime_dvd_power_nat)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    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
4c3bb56b8ce7 misc tuning and modernization;
wenzelm
parents: 58889
diff changeset
    79
  with \<open>prime p\<close> have "p dvd n" by (rule prime_dvd_power_nat)
31952
40501bb2d57c renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents: 31712
diff changeset
    80
  with dvd_m have "p dvd gcd m n" by (rule gcd_greatest_nat)
60690
a9e45c9588c3 tuned facts
haftmann
parents: 59031
diff changeset
    81
  with \<open>coprime m n\<close> have "p = 1" by simp
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    82
  with p show False by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    83
qed
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    84
45917
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
    85
59031
4c3bb56b8ce7 misc tuning and modernization;
wenzelm
parents: 58889
diff changeset
    86
text \<open>Another old chestnut, which is a consequence of the irrationality of 2.\<close>
45917
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
    87
59031
4c3bb56b8ce7 misc tuning and modernization;
wenzelm
parents: 58889
diff changeset
    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
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
    89
proof cases
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
    90
  assume "sqrt 2 powr sqrt 2 \<in> \<rat>"
46495
8e8a339e176f uniform Isar source formatting for this file;
wenzelm
parents: 45917
diff changeset
    91
  then have "?P (sqrt 2) (sqrt 2)"
51708
5188a18c33b1 use automatic type coerctions in Sqrt example
hoelzl
parents: 46495
diff changeset
    92
    by (metis sqrt_2_not_rat)
46495
8e8a339e176f uniform Isar source formatting for this file;
wenzelm
parents: 45917
diff changeset
    93
  then show ?thesis by blast
45917
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
    94
next
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
    95
  assume 1: "sqrt 2 powr sqrt 2 \<notin> \<rat>"
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
    96
  have "(sqrt 2 powr sqrt 2) powr sqrt 2 = 2"
46495
8e8a339e176f uniform Isar source formatting for this file;
wenzelm
parents: 45917
diff changeset
    97
    using powr_realpow [of _ 2]
8e8a339e176f uniform Isar source formatting for this file;
wenzelm
parents: 45917
diff changeset
    98
    by (simp add: powr_powr power2_eq_square [symmetric])
8e8a339e176f uniform Isar source formatting for this file;
wenzelm
parents: 45917
diff changeset
    99
  then have "?P (sqrt 2 powr sqrt 2) (sqrt 2)"
51708
5188a18c33b1 use automatic type coerctions in Sqrt example
hoelzl
parents: 46495
diff changeset
   100
    by (metis 1 Rats_number_of sqrt_2_not_rat)
46495
8e8a339e176f uniform Isar source formatting for this file;
wenzelm
parents: 45917
diff changeset
   101
  then show ?thesis by blast
45917
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
   102
qed
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
   103
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   104
end