src/HOL/Real/ex/Sqrt_Irrational.thy
author paulson
Mon, 22 Oct 2001 11:54:22 +0200
changeset 11868 56db9f3a6b3e
parent 11704 3c50a2cd6f00
permissions -rw-r--r--
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite to their abstract counterparts, while other binary numerals work correctly.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11594
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Real/ex/Sqrt_Irrational.thy
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
     5
*)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
     6
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
     7
header {*  Square roots of primes are irrational *}
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
     8
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
     9
theory Sqrt_Irrational = Real + Primes:
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    10
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    11
syntax (xsymbols)                        (* FIXME move to main HOL (!?) *)
11607
c7e1db87b98a unsymbolize;
wenzelm
parents: 11594
diff changeset
    12
  "_square" :: "'a => 'a"  ("(_\<twosuperior>)" [1000] 999)
11594
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    13
syntax (HTML output)
11607
c7e1db87b98a unsymbolize;
wenzelm
parents: 11594
diff changeset
    14
  "_square" :: "'a => 'a"  ("(_\<twosuperior>)" [1000] 999)
11594
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    15
syntax (output)
11607
c7e1db87b98a unsymbolize;
wenzelm
parents: 11594
diff changeset
    16
  "_square" :: "'a => 'a"  ("(_^2)" [1000] 999)
11594
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    17
translations
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11607
diff changeset
    18
  "x\<twosuperior>" == "x^Suc (Suc 0)"
11594
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    19
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    20
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    21
subsection {* The set of rational numbers *}
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    22
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    23
constdefs
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    24
  rationals :: "real set"    ("\<rat>")
11607
c7e1db87b98a unsymbolize;
wenzelm
parents: 11594
diff changeset
    25
  "\<rat> == {x. \<exists>m n. n \<noteq> 0 \<and> \<bar>x\<bar> = real (m::nat) / real (n::nat)}"
11594
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    26
11607
c7e1db87b98a unsymbolize;
wenzelm
parents: 11594
diff changeset
    27
theorem rationals_rep: "x \<in> \<rat> ==>
11594
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    28
  \<exists>m n. n \<noteq> 0 \<and> \<bar>x\<bar> = real m / real n \<and> gcd (m, n) = 1"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    29
proof -
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    30
  assume "x \<in> \<rat>"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    31
  then obtain m n :: nat where n: "n \<noteq> 0" and x_rat: "\<bar>x\<bar> = real m / real n"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    32
    by (unfold rationals_def) blast
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    33
  let ?gcd = "gcd (m, n)"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    34
  from n have gcd: "?gcd \<noteq> 0" by (simp add: gcd_zero)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    35
  let ?k = "m div ?gcd"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    36
  let ?l = "n div ?gcd"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    37
  let ?gcd' = "gcd (?k, ?l)"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    38
  have "?gcd dvd m" .. hence gcd_k: "?gcd * ?k = m"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    39
    by (rule dvd_mult_div_cancel)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    40
  have "?gcd dvd n" .. hence gcd_l: "?gcd * ?l = n"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    41
    by (rule dvd_mult_div_cancel)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    42
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    43
  from n gcd_l have "?l \<noteq> 0"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    44
    by (auto iff del: neq0_conv)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    45
  moreover
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    46
  have "\<bar>x\<bar> = real ?k / real ?l"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    47
  proof -
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    48
    from gcd have "real ?k / real ?l = real (?gcd * ?k) / real (?gcd * ?l)"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    49
      by (simp add: real_mult_div_cancel1)
11607
c7e1db87b98a unsymbolize;
wenzelm
parents: 11594
diff changeset
    50
    also from gcd_k gcd_l have "... = real m / real n" by simp
c7e1db87b98a unsymbolize;
wenzelm
parents: 11594
diff changeset
    51
    also from x_rat have "... = \<bar>x\<bar>" ..
11594
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    52
    finally show ?thesis ..
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    53
  qed
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    54
  moreover
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    55
  have "?gcd' = 1"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    56
  proof -
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    57
    have "?gcd * ?gcd' = gcd (?gcd * ?k, ?gcd * ?l)"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    58
      by (rule gcd_mult_distrib2)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    59
    with gcd_k gcd_l have "?gcd * ?gcd' = ?gcd" by simp
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    60
    with gcd show ?thesis by simp
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    61
  qed
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    62
  ultimately show ?thesis by blast
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    63
qed
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    64
11607
c7e1db87b98a unsymbolize;
wenzelm
parents: 11594
diff changeset
    65
lemma [elim?]: "r \<in> \<rat> ==>
c7e1db87b98a unsymbolize;
wenzelm
parents: 11594
diff changeset
    66
    (!!m n. n \<noteq> 0 ==> \<bar>r\<bar> = real m / real n ==> gcd (m, n) = 1 ==> C) ==> C"
11594
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    67
  by (insert rationals_rep) blast
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    68
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    69
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    70
subsection {* Main theorem *}
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    71
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    72
text {*
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    73
  The square root of any prime number (including @{text 2}) is
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    74
  irrational.
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    75
*}
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    76
11607
c7e1db87b98a unsymbolize;
wenzelm
parents: 11594
diff changeset
    77
theorem sqrt_prime_irrational: "x\<twosuperior> = real p ==> p \<in> prime ==> x \<notin> \<rat>"
11594
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    78
proof
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    79
  assume x_sqrt: "x\<twosuperior> = real p"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    80
  assume p_prime: "p \<in> prime"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    81
  hence p: "1 < p" by (simp add: prime_def)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    82
  assume "x \<in> \<rat>"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    83
  then obtain m n where
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    84
    n: "n \<noteq> 0" and x_rat: "\<bar>x\<bar> = real m / real n" and gcd: "gcd (m, n) = 1" ..
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    85
  have eq: "m\<twosuperior> = p * n\<twosuperior>"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    86
  proof -
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    87
    from n x_rat have "real m = \<bar>x\<bar> * real n" by simp
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    88
    hence "real (m\<twosuperior>) = x\<twosuperior> * real (n\<twosuperior>)" by (simp split: abs_split)
11607
c7e1db87b98a unsymbolize;
wenzelm
parents: 11594
diff changeset
    89
    also from x_sqrt have "... = real (p * n\<twosuperior>)" by simp
11594
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    90
    finally show ?thesis ..
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    91
  qed
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    92
  have "p dvd m \<and> p dvd n"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    93
  proof
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    94
    from eq have "p dvd m\<twosuperior>" ..
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    95
    with p_prime show "p dvd m" by (rule prime_dvd_square)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    96
    then obtain k where "m = p * k" ..
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    97
    with eq have "p * n\<twosuperior> = p\<twosuperior> * k\<twosuperior>" by (auto simp add: mult_ac)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    98
    with p have "n\<twosuperior> = p * k\<twosuperior>" by simp
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
    99
    hence "p dvd n\<twosuperior>" ..
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   100
    with p_prime show "p dvd n" by (rule prime_dvd_square)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   101
  qed
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   102
  hence "p dvd gcd (m, n)" ..
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   103
  with gcd have "p dvd 1" by simp
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   104
  hence "p \<le> 1" by (simp add: dvd_imp_le)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   105
  with p show False by simp
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   106
qed
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   107
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   108
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   109
subsection {* Variations *}
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   110
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   111
text {*
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   112
  Just for the record: we instantiate the main theorem for the
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   113
  specific prime number @{text 2} (real mathematicians would never do
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   114
  this formally :-).
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   115
*}
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   116
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   117
theorem "x\<twosuperior> = real (2::nat) ==> x \<notin> \<rat>"
11594
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   118
proof (rule sqrt_prime_irrational)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   119
  {
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   120
    fix m :: nat assume dvd: "m dvd 2"
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   121
    hence "m \<le> 2" by (simp add: dvd_imp_le)
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   122
    moreover from dvd have "m \<noteq> 0" by (auto iff del: neq0_conv)
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   123
    ultimately have "m = 1 \<or> m = 2" by arith
11594
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   124
  }
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   125
  thus "2 \<in> prime" by (simp add: prime_def)
11594
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   126
qed
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   127
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   128
text {*
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   129
  \medskip An alternative version of the main proof, using mostly
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   130
  linear forward-reasoning.  While this results in less top-down
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   131
  structure, it is probably closer to proofs seen in mathematics.
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   132
*}
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   133
11607
c7e1db87b98a unsymbolize;
wenzelm
parents: 11594
diff changeset
   134
theorem "x\<twosuperior> = real p ==> p \<in> prime ==> x \<notin> \<rat>"
11594
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   135
proof
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   136
  assume x_sqrt: "x\<twosuperior> = real p"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   137
  assume p_prime: "p \<in> prime"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   138
  hence p: "1 < p" by (simp add: prime_def)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   139
  assume "x \<in> \<rat>"
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   140
  then obtain m n where
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   141
    n: "n \<noteq> 0" and x_rat: "\<bar>x\<bar> = real m / real n" and gcd: "gcd (m, n) = 1" ..
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   142
  from n x_rat have "real m = \<bar>x\<bar> * real n" by simp
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   143
  hence "real (m\<twosuperior>) = x\<twosuperior> * real (n\<twosuperior>)" by (simp split: abs_split)
11607
c7e1db87b98a unsymbolize;
wenzelm
parents: 11594
diff changeset
   144
  also from x_sqrt have "... = real (p * n\<twosuperior>)" by simp
11594
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   145
  finally have eq: "m\<twosuperior> = p * n\<twosuperior>" ..
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   146
  hence "p dvd m\<twosuperior>" ..
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   147
  with p_prime have dvd_m: "p dvd m" by (rule prime_dvd_square)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   148
  then obtain k where "m = p * k" ..
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   149
  with eq have "p * n\<twosuperior> = p\<twosuperior> * k\<twosuperior>" by (auto simp add: mult_ac)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   150
  with p have "n\<twosuperior> = p * k\<twosuperior>" by simp
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   151
  hence "p dvd n\<twosuperior>" ..
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   152
  with p_prime have "p dvd n" by (rule prime_dvd_square)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   153
  with dvd_m have "p dvd gcd (m, n)" by (rule gcd_greatest)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   154
  with gcd have "p dvd 1" by simp
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   155
  hence "p \<le> 1" by (simp add: dvd_imp_le)
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   156
  with p show False by simp
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   157
qed
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   158
3ccea743e5e7 Square roots of primes are irrational;
wenzelm
parents:
diff changeset
   159
end