src/HOL/ex/Sqrt.thy
author wenzelm
Tue, 10 Mar 2009 16:48:27 +0100
changeset 30411 9c9b6511ad1b
parent 28952 15a4b2cf8c34
child 31712 6f8aa9aea693
permissions -rw-r--r--
tuned proofs; tuned document;
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
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
     2
    Author:     Markus Wenzel, TU Muenchen
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
28952
15a4b2cf8c34 made repository layout more coherent with logical distribution structure; stripped some $Id$s
haftmann
parents: 28001
diff changeset
     8
imports Complex_Main 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
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    11
text {*
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    12
  The square root of any prime number (including @{text 2}) is
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    13
  irrational.
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
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 16663
diff changeset
    16
theorem sqrt_prime_irrational:
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 16663
diff changeset
    17
  assumes "prime p"
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 16663
diff changeset
    18
  shows "sqrt (real p) \<notin> \<rat>"
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    19
proof
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 16663
diff changeset
    20
  from `prime p` have p: "1 < p" by (simp add: prime_def)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    21
  assume "sqrt (real p) \<in> \<rat>"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    22
  then obtain m n where
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    23
      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
    24
    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
    25
  have eq: "m\<twosuperior> = p * n\<twosuperior>"
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
    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
    28
    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
    29
      by (auto simp add: power2_eq_square)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    30
    also have "(sqrt (real p))\<twosuperior> = real p" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    31
    also have "\<dots> * real (n\<twosuperior>) = real (p * n\<twosuperior>)" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    32
    finally show ?thesis ..
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    33
  qed
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    34
  have "p dvd m \<and> p dvd n"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    35
  proof
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    36
    from eq have "p dvd m\<twosuperior>" ..
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 16663
diff changeset
    37
    with `prime p` show "p dvd m" by (rule prime_dvd_power_two)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    38
    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
    39
    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
    40
    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
    41
    then have "p dvd n\<twosuperior>" ..
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 16663
diff changeset
    42
    with `prime p` show "p dvd n" by (rule prime_dvd_power_two)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    43
  qed
27556
292098f2efdf unified curried gcd, lcm, zgcd, zlcm
haftmann
parents: 23413
diff changeset
    44
  then have "p dvd gcd m n" ..
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    45
  with gcd have "p dvd 1" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    46
  then have "p \<le> 1" by (simp add: dvd_imp_le)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    47
  with p show False by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    48
qed
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
corollary "sqrt (real (2::nat)) \<notin> \<rat>"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    51
  by (rule sqrt_prime_irrational) (rule two_is_prime)
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
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    54
subsection {* Variations *}
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    55
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    56
text {*
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    57
  Here is an alternative version of the main proof, using mostly
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    58
  linear forward-reasoning.  While this results in less top-down
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    59
  structure, it is probably closer to proofs seen in mathematics.
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    60
*}
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    61
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 16663
diff changeset
    62
theorem
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 16663
diff changeset
    63
  assumes "prime p"
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 16663
diff changeset
    64
  shows "sqrt (real p) \<notin> \<rat>"
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    65
proof
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 16663
diff changeset
    66
  from `prime p` have p: "1 < p" by (simp add: prime_def)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    67
  assume "sqrt (real p) \<in> \<rat>"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    68
  then obtain m n where
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    69
      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
    70
    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
    71
  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
    72
  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
    73
    by (auto simp add: power2_eq_square)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    74
  also have "(sqrt (real p))\<twosuperior> = real p" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    75
  also have "\<dots> * real (n\<twosuperior>) = real (p * n\<twosuperior>)" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    76
  finally have eq: "m\<twosuperior> = p * n\<twosuperior>" ..
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    77
  then have "p dvd m\<twosuperior>" ..
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 16663
diff changeset
    78
  with `prime p` have dvd_m: "p dvd m" by (rule prime_dvd_power_two)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    79
  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
    80
  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
    81
  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
    82
  then have "p dvd n\<twosuperior>" ..
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 16663
diff changeset
    83
  with `prime p` have "p dvd n" by (rule prime_dvd_power_two)
27556
292098f2efdf unified curried gcd, lcm, zgcd, zlcm
haftmann
parents: 23413
diff changeset
    84
  with dvd_m have "p dvd gcd m n" by (rule gcd_greatest)
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    85
  with gcd have "p dvd 1" by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    86
  then have "p \<le> 1" by (simp add: dvd_imp_le)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    87
  with p show False by simp
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    88
qed
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    89
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    90
end