src/HOL/Complex/ex/Sqrt_Script.thy
author haftmann
Fri, 18 Jul 2008 18:25:53 +0200
changeset 27651 16a26996c30e
parent 21404 eb85850d3eb7
child 28001 4642317e0deb
permissions -rw-r--r--
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
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_Script.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:     Lawrence C Paulson, Cambridge University Computer Laboratory
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
     4
    Copyright   2001  University of Cambridge
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 (script version) *}
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
     8
15149
c5c4884634b7 new import syntax
nipkow
parents: 14288
diff changeset
     9
theory Sqrt_Script
c5c4884634b7 new import syntax
nipkow
parents: 14288
diff changeset
    10
imports Primes Complex_Main
c5c4884634b7 new import syntax
nipkow
parents: 14288
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
text {*
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    14
  \medskip Contrast this linear Isabelle/Isar script with Markus
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    15
  Wenzel's more mathematical version.
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    16
*}
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    17
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    18
subsection {* Preliminaries *}
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    19
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 15149
diff changeset
    20
lemma prime_nonzero:  "prime p \<Longrightarrow> p \<noteq> 0"
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    21
  by (force simp add: prime_def)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    22
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    23
lemma prime_dvd_other_side:
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 15149
diff changeset
    24
    "n * n = p * (k * k) \<Longrightarrow> prime p \<Longrightarrow> p dvd n"
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    25
  apply (subgoal_tac "p dvd n * n", blast dest: prime_dvd_mult)
27651
16a26996c30e moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents: 21404
diff changeset
    26
  apply auto
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    27
  done
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    28
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 15149
diff changeset
    29
lemma reduction: "prime p \<Longrightarrow>
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    30
    0 < k \<Longrightarrow> k * k = p * (j * j) \<Longrightarrow> k < p * j \<and> 0 < j"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    31
  apply (rule ccontr)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    32
  apply (simp add: linorder_not_less)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    33
  apply (erule disjE)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    34
   apply (frule mult_le_mono, assumption)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    35
   apply auto
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    36
  apply (force simp add: prime_def)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    37
  done
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    38
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    39
lemma rearrange: "(j::nat) * (p * j) = k * k \<Longrightarrow> k * k = p * (j * j)"
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    40
  by (simp add: mult_ac)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    41
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    42
lemma prime_not_square:
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 15149
diff changeset
    43
    "prime p \<Longrightarrow> (\<And>k. 0 < k \<Longrightarrow> m * m \<noteq> p * (k * k))"
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    44
  apply (induct m rule: nat_less_induct)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    45
  apply clarify
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    46
  apply (frule prime_dvd_other_side, assumption)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    47
  apply (erule dvdE)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    48
  apply (simp add: nat_mult_eq_cancel_disj prime_nonzero)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    49
  apply (blast dest: rearrange reduction)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    50
  done
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    51
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
subsection {* The set of rational numbers *}
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    54
19736
wenzelm
parents: 16663
diff changeset
    55
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 19736
diff changeset
    56
  rationals :: "real set"    ("\<rat>") where
19736
wenzelm
parents: 16663
diff changeset
    57
  "\<rat> = {x. \<exists>m n. n \<noteq> 0 \<and> \<bar>x\<bar> = real (m::nat) / real (n::nat)}"
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    58
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    59
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    60
subsection {* Main theorem *}
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    61
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    62
text {*
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    63
  The square root of any prime number (including @{text 2}) is
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    64
  irrational.
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    65
*}
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    66
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    67
theorem prime_sqrt_irrational:
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 15149
diff changeset
    68
    "prime p \<Longrightarrow> x * x = real p \<Longrightarrow> 0 \<le> x \<Longrightarrow> x \<notin> \<rat>"
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    69
  apply (simp add: rationals_def real_abs_def)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    70
  apply clarify
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    71
  apply (erule_tac P = "real m / real n * ?x = ?y" in rev_mp)
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    72
  apply (simp del: real_of_nat_mult
14288
d149e3cbdb39 Moving some theorems from Real/RealArith0.ML
paulson
parents: 14051
diff changeset
    73
              add: divide_eq_eq prime_not_square real_of_nat_mult [symmetric])
13957
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    74
  done
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
lemmas two_sqrt_irrational =
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    77
  prime_sqrt_irrational [OF two_is_prime]
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    78
10dbf16be15f new session Complex for the complex numbers
paulson
parents:
diff changeset
    79
end