src/HOL/Complex/ex/Sqrt.thy
author urbanc
Tue, 13 Dec 2005 18:11:21 +0100
changeset 18396 b3e7da94b51f
parent 16663 13e9c402308b
child 19086 1b3780be6cc2
permissions -rw-r--r--
added a fresh_left lemma that contains all instantiation for the various atom-types.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
     1
(*  Title:      HOL/Hyperreal/ex/Sqrt.thy
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
     2
    ID:         $Id$
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
14981
e73f8140af78 Merged in license change from Isabelle2004
kleing
parents: 14353
diff changeset
     4
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
     5
*)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
     6
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
     7
header {*  Square roots of primes are irrational *}
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
     8
15149
c5c4884634b7 new import syntax
nipkow
parents: 14981
diff changeset
     9
theory Sqrt
c5c4884634b7 new import syntax
nipkow
parents: 14981
diff changeset
    10
imports Primes Complex_Main
c5c4884634b7 new import syntax
nipkow
parents: 14981
diff changeset
    11
begin
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    12
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    13
subsection {* Preliminaries *}
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    14
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    15
text {*
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    16
  The set of rational numbers, including the key representation
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    17
  theorem.
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    18
*}
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    19
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    20
constdefs
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    21
  rationals :: "real set"    ("\<rat>")
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    22
  "\<rat> \<equiv> {x. \<exists>m n. n \<noteq> 0 \<and> \<bar>x\<bar> = real (m::nat) / real (n::nat)}"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    23
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    24
theorem rationals_rep: "x \<in> \<rat> \<Longrightarrow>
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    25
  \<exists>m n. n \<noteq> 0 \<and> \<bar>x\<bar> = real m / real n \<and> gcd (m, n) = 1"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    26
proof -
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    27
  assume "x \<in> \<rat>"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    28
  then obtain m n :: nat where
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    29
      n: "n \<noteq> 0" and x_rat: "\<bar>x\<bar> = real m / real n"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    30
    by (unfold rationals_def) blast
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    31
  let ?gcd = "gcd (m, n)"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    32
  from n have gcd: "?gcd \<noteq> 0" by (simp add: gcd_zero)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    33
  let ?k = "m div ?gcd"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    34
  let ?l = "n div ?gcd"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    35
  let ?gcd' = "gcd (?k, ?l)"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    36
  have "?gcd dvd m" .. then have gcd_k: "?gcd * ?k = m"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    37
    by (rule dvd_mult_div_cancel)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    38
  have "?gcd dvd n" .. then have gcd_l: "?gcd * ?l = n"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    39
    by (rule dvd_mult_div_cancel)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    40
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    41
  from n and gcd_l have "?l \<noteq> 0"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    42
    by (auto iff del: neq0_conv)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    43
  moreover
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    44
  have "\<bar>x\<bar> = real ?k / real ?l"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    45
  proof -
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    46
    from gcd have "real ?k / real ?l =
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    47
        real (?gcd * ?k) / real (?gcd * ?l)"
14305
f17ca9f6dc8c tidying first part of HyperArith0.ML, using generic lemmas
paulson
parents: 14051
diff changeset
    48
      by (simp add: mult_divide_cancel_left)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    49
    also from gcd_k and gcd_l have "\<dots> = real m / real n" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    50
    also from x_rat have "\<dots> = \<bar>x\<bar>" ..
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    51
    finally show ?thesis ..
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    52
  qed
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    53
  moreover
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    54
  have "?gcd' = 1"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    55
  proof -
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    56
    have "?gcd * ?gcd' = gcd (?gcd * ?k, ?gcd * ?l)"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    57
      by (rule gcd_mult_distrib2)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    58
    with gcd_k gcd_l have "?gcd * ?gcd' = ?gcd" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    59
    with gcd show ?thesis by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    60
  qed
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    61
  ultimately show ?thesis by blast
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    62
qed
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    63
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    64
lemma [elim?]: "r \<in> \<rat> \<Longrightarrow>
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    65
  (\<And>m n. n \<noteq> 0 \<Longrightarrow> \<bar>r\<bar> = real m / real n \<Longrightarrow> gcd (m, n) = 1 \<Longrightarrow> C)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    66
    \<Longrightarrow> C"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    67
  using rationals_rep by blast
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    68
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    69
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    70
subsection {* Main theorem *}
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    71
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    72
text {*
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    73
  The square root of any prime number (including @{text 2}) is
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    74
  irrational.
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    75
*}
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    76
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 15149
diff changeset
    77
theorem sqrt_prime_irrational: "prime p \<Longrightarrow> sqrt (real p) \<notin> \<rat>"
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    78
proof
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 15149
diff changeset
    79
  assume p_prime: "prime p"
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    80
  then have p: "1 < p" by (simp add: prime_def)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    81
  assume "sqrt (real p) \<in> \<rat>"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    82
  then obtain m n where
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    83
      n: "n \<noteq> 0" and sqrt_rat: "\<bar>sqrt (real p)\<bar> = real m / real n"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    84
    and gcd: "gcd (m, n) = 1" ..
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    85
  have eq: "m\<twosuperior> = p * n\<twosuperior>"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    86
  proof -
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    87
    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
    88
    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
    89
      by (auto simp add: power2_eq_square)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    90
    also have "(sqrt (real p))\<twosuperior> = real p" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    91
    also have "\<dots> * real (n\<twosuperior>) = real (p * n\<twosuperior>)" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    92
    finally show ?thesis ..
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    93
  qed
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    94
  have "p dvd m \<and> p dvd n"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    95
  proof
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    96
    from eq have "p dvd m\<twosuperior>" ..
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    97
    with p_prime show "p dvd m" by (rule prime_dvd_power_two)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    98
    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
    99
    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
   100
    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
   101
    then have "p dvd n\<twosuperior>" ..
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   102
    with p_prime show "p dvd n" by (rule prime_dvd_power_two)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   103
  qed
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   104
  then have "p dvd gcd (m, n)" ..
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   105
  with gcd have "p dvd 1" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   106
  then have "p \<le> 1" by (simp add: dvd_imp_le)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   107
  with p show False by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   108
qed
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   109
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   110
corollary "sqrt (real (2::nat)) \<notin> \<rat>"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   111
  by (rule sqrt_prime_irrational) (rule two_is_prime)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   112
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   113
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   114
subsection {* Variations *}
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   115
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   116
text {*
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   117
  Here is an alternative version of the main proof, using mostly
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   118
  linear forward-reasoning.  While this results in less top-down
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   119
  structure, it is probably closer to proofs seen in mathematics.
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   120
*}
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   121
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 15149
diff changeset
   122
theorem "prime p \<Longrightarrow> sqrt (real p) \<notin> \<rat>"
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   123
proof
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 15149
diff changeset
   124
  assume p_prime: "prime p"
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   125
  then have p: "1 < p" by (simp add: prime_def)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   126
  assume "sqrt (real p) \<in> \<rat>"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   127
  then obtain m n where
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   128
      n: "n \<noteq> 0" and sqrt_rat: "\<bar>sqrt (real p)\<bar> = real m / real n"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   129
    and gcd: "gcd (m, n) = 1" ..
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   130
  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
   131
  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
   132
    by (auto simp add: power2_eq_square)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   133
  also have "(sqrt (real p))\<twosuperior> = real p" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   134
  also have "\<dots> * real (n\<twosuperior>) = real (p * n\<twosuperior>)" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   135
  finally have eq: "m\<twosuperior> = p * n\<twosuperior>" ..
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   136
  then have "p dvd m\<twosuperior>" ..
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   137
  with p_prime have dvd_m: "p dvd m" by (rule prime_dvd_power_two)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   138
  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
   139
  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
   140
  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
   141
  then have "p dvd n\<twosuperior>" ..
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   142
  with p_prime have "p dvd n" by (rule prime_dvd_power_two)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   143
  with dvd_m have "p dvd gcd (m, n)" by (rule gcd_greatest)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   144
  with gcd have "p dvd 1" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   145
  then have "p \<le> 1" by (simp add: dvd_imp_le)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   146
  with p show False by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   147
qed
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   148
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
   149
end