src/HOL/ex/Sqrt.thy
author huffman
Wed, 18 Apr 2012 15:48:32 +0200
changeset 47544 e455cdaac479
parent 46495 8e8a339e176f
child 51708 5188a18c33b1
permissions -rw-r--r--
move constant 'Respects' into Lifting.thy; add quantifier transfer rules for quotients
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
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
     5
header {*  Square roots of primes are irrational *}
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
46495
8e8a339e176f uniform Isar source formatting for this file;
wenzelm
parents: 45917
diff changeset
    11
text {* The square root of any prime number (including 2) is irrational. *}
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)"
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 16663
diff changeset
    15
  shows "sqrt (real p) \<notin> \<rat>"
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    16
proof
31712
6f8aa9aea693 update ex/Sqrt.thy to use new GCD library
huffman
parents: 30411
diff changeset
    17
  from `prime p` have p: "1 < p" by (simp add: prime_nat_def)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    18
  assume "sqrt (real 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
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    20
      n: "n \<noteq> 0" and sqrt_rat: "\<bar>sqrt (real p)\<bar> = real m / real n"
30411
9c9b6511ad1b tuned proofs;
wenzelm
parents: 28952
diff changeset
    21
    and gcd: "gcd m n = 1" by (rule Rats_abs_nat_div_natE)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    22
  have eq: "m\<twosuperior> = p * n\<twosuperior>"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    23
  proof -
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    24
    from n and sqrt_rat have "real m = \<bar>sqrt (real p)\<bar> * real n" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    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
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    27
    also have "(sqrt (real p))\<twosuperior> = real p" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    28
    also have "\<dots> * real (n\<twosuperior>) = real (p * n\<twosuperior>)" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    29
    finally show ?thesis ..
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
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    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
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    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
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    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
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    40
  qed
27556
292098f2efdf unified curried gcd, lcm, zgcd, zlcm
haftmann
parents: 23413
diff changeset
    41
  then have "p dvd gcd m n" ..
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    42
  with gcd have "p dvd 1" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    43
  then have "p \<le> 1" by (simp add: dvd_imp_le)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    44
  with p show False by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    45
qed
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    46
45917
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
    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
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    49
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    50
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    51
subsection {* Variations *}
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    52
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    53
text {*
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    54
  Here is an alternative version of the main proof, using mostly
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    55
  linear forward-reasoning.  While this results in less top-down
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    56
  structure, it is probably closer to proofs seen in mathematics.
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    57
*}
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    58
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 16663
diff changeset
    59
theorem
31712
6f8aa9aea693 update ex/Sqrt.thy to use new GCD library
huffman
parents: 30411
diff changeset
    60
  assumes "prime (p::nat)"
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 16663
diff changeset
    61
  shows "sqrt (real p) \<notin> \<rat>"
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    62
proof
31712
6f8aa9aea693 update ex/Sqrt.thy to use new GCD library
huffman
parents: 30411
diff changeset
    63
  from `prime p` have p: "1 < p" by (simp add: prime_nat_def)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    64
  assume "sqrt (real p) \<in> \<rat>"
31712
6f8aa9aea693 update ex/Sqrt.thy to use new GCD library
huffman
parents: 30411
diff changeset
    65
  then obtain m n :: nat where
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    66
      n: "n \<noteq> 0" and sqrt_rat: "\<bar>sqrt (real p)\<bar> = real m / real n"
30411
9c9b6511ad1b tuned proofs;
wenzelm
parents: 28952
diff changeset
    67
    and gcd: "gcd m n = 1" by (rule Rats_abs_nat_div_natE)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    68
  from n and sqrt_rat have "real m = \<bar>sqrt (real p)\<bar> * real n" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    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
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    71
  also have "(sqrt (real p))\<twosuperior> = real p" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    72
  also have "\<dots> * real (n\<twosuperior>) = real (p * n\<twosuperior>)" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    73
  finally have eq: "m\<twosuperior> = p * n\<twosuperior>" ..
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    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
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    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
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    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
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    82
  with gcd have "p dvd 1" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    83
  then have "p \<le> 1" by (simp add: dvd_imp_le)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    84
  with p show False by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    85
qed
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    86
45917
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
    87
46495
8e8a339e176f uniform Isar source formatting for this file;
wenzelm
parents: 45917
diff changeset
    88
text {* Another old chestnut, which is a consequence of the irrationality of 2. *}
45917
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
    89
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
    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")
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
    91
proof cases
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
    92
  assume "sqrt 2 powr sqrt 2 \<in> \<rat>"
46495
8e8a339e176f uniform Isar source formatting for this file;
wenzelm
parents: 45917
diff changeset
    93
  then have "?P (sqrt 2) (sqrt 2)"
8e8a339e176f uniform Isar source formatting for this file;
wenzelm
parents: 45917
diff changeset
    94
    by (metis sqrt_real_2_not_rat [simplified])
8e8a339e176f uniform Isar source formatting for this file;
wenzelm
parents: 45917
diff changeset
    95
  then show ?thesis by blast
45917
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
    96
next
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
    97
  assume 1: "sqrt 2 powr sqrt 2 \<notin> \<rat>"
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
    98
  have "(sqrt 2 powr sqrt 2) powr sqrt 2 = 2"
46495
8e8a339e176f uniform Isar source formatting for this file;
wenzelm
parents: 45917
diff changeset
    99
    using powr_realpow [of _ 2]
8e8a339e176f uniform Isar source formatting for this file;
wenzelm
parents: 45917
diff changeset
   100
    by (simp add: powr_powr power2_eq_square [symmetric])
8e8a339e176f uniform Isar source formatting for this file;
wenzelm
parents: 45917
diff changeset
   101
  then have "?P (sqrt 2 powr sqrt 2) (sqrt 2)"
8e8a339e176f uniform Isar source formatting for this file;
wenzelm
parents: 45917
diff changeset
   102
    by (metis 1 Rats_number_of sqrt_real_2_not_rat [simplified])
8e8a339e176f uniform Isar source formatting for this file;
wenzelm
parents: 45917
diff changeset
   103
  then show ?thesis by blast
45917
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
   104
qed
1ce1bc9ff64a added old chestnut
nipkow
parents: 32479
diff changeset
   105
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   106
end