src/HOL/Complex/ex/Sqrt_Script.thy
author paulson
Thu Jul 01 12:29:53 2004 +0200 (2004-07-01)
changeset 15013 34264f5e4691
parent 14288 d149e3cbdb39
child 15149 c5c4884634b7
permissions -rw-r--r--
new treatment of binary numerals
paulson@13957
     1
(*  Title:      HOL/Hyperreal/ex/Sqrt_Script.thy
paulson@13957
     2
    ID:         $Id$
paulson@13957
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@13957
     4
    Copyright   2001  University of Cambridge
paulson@13957
     5
*)
paulson@13957
     6
paulson@13957
     7
header {* Square roots of primes are irrational (script version) *}
paulson@13957
     8
paulson@14051
     9
theory Sqrt_Script = Primes + Complex_Main:
paulson@13957
    10
paulson@13957
    11
text {*
paulson@13957
    12
  \medskip Contrast this linear Isabelle/Isar script with Markus
paulson@13957
    13
  Wenzel's more mathematical version.
paulson@13957
    14
*}
paulson@13957
    15
paulson@13957
    16
subsection {* Preliminaries *}
paulson@13957
    17
paulson@13957
    18
lemma prime_nonzero:  "p \<in> prime \<Longrightarrow> p \<noteq> 0"
paulson@13957
    19
  by (force simp add: prime_def)
paulson@13957
    20
paulson@13957
    21
lemma prime_dvd_other_side:
paulson@13957
    22
    "n * n = p * (k * k) \<Longrightarrow> p \<in> prime \<Longrightarrow> p dvd n"
paulson@13957
    23
  apply (subgoal_tac "p dvd n * n", blast dest: prime_dvd_mult)
paulson@13957
    24
  apply (rule_tac j = "k * k" in dvd_mult_left, simp)
paulson@13957
    25
  done
paulson@13957
    26
paulson@13957
    27
lemma reduction: "p \<in> prime \<Longrightarrow>
paulson@13957
    28
    0 < k \<Longrightarrow> k * k = p * (j * j) \<Longrightarrow> k < p * j \<and> 0 < j"
paulson@13957
    29
  apply (rule ccontr)
paulson@13957
    30
  apply (simp add: linorder_not_less)
paulson@13957
    31
  apply (erule disjE)
paulson@13957
    32
   apply (frule mult_le_mono, assumption)
paulson@13957
    33
   apply auto
paulson@13957
    34
  apply (force simp add: prime_def)
paulson@13957
    35
  done
paulson@13957
    36
paulson@13957
    37
lemma rearrange: "(j::nat) * (p * j) = k * k \<Longrightarrow> k * k = p * (j * j)"
paulson@13957
    38
  by (simp add: mult_ac)
paulson@13957
    39
paulson@13957
    40
lemma prime_not_square:
paulson@13957
    41
    "p \<in> prime \<Longrightarrow> (\<And>k. 0 < k \<Longrightarrow> m * m \<noteq> p * (k * k))"
paulson@13957
    42
  apply (induct m rule: nat_less_induct)
paulson@13957
    43
  apply clarify
paulson@13957
    44
  apply (frule prime_dvd_other_side, assumption)
paulson@13957
    45
  apply (erule dvdE)
paulson@13957
    46
  apply (simp add: nat_mult_eq_cancel_disj prime_nonzero)
paulson@13957
    47
  apply (blast dest: rearrange reduction)
paulson@13957
    48
  done
paulson@13957
    49
paulson@13957
    50
paulson@13957
    51
subsection {* The set of rational numbers *}
paulson@13957
    52
paulson@13957
    53
constdefs
paulson@13957
    54
  rationals :: "real set"    ("\<rat>")
paulson@13957
    55
  "\<rat> \<equiv> {x. \<exists>m n. n \<noteq> 0 \<and> \<bar>x\<bar> = real (m::nat) / real (n::nat)}"
paulson@13957
    56
paulson@13957
    57
paulson@13957
    58
subsection {* Main theorem *}
paulson@13957
    59
paulson@13957
    60
text {*
paulson@13957
    61
  The square root of any prime number (including @{text 2}) is
paulson@13957
    62
  irrational.
paulson@13957
    63
*}
paulson@13957
    64
paulson@13957
    65
theorem prime_sqrt_irrational:
paulson@13957
    66
    "p \<in> prime \<Longrightarrow> x * x = real p \<Longrightarrow> 0 \<le> x \<Longrightarrow> x \<notin> \<rat>"
paulson@13957
    67
  apply (simp add: rationals_def real_abs_def)
paulson@13957
    68
  apply clarify
paulson@13957
    69
  apply (erule_tac P = "real m / real n * ?x = ?y" in rev_mp)
paulson@13957
    70
  apply (simp del: real_of_nat_mult
paulson@14288
    71
              add: divide_eq_eq prime_not_square real_of_nat_mult [symmetric])
paulson@13957
    72
  done
paulson@13957
    73
paulson@13957
    74
lemmas two_sqrt_irrational =
paulson@13957
    75
  prime_sqrt_irrational [OF two_is_prime]
paulson@13957
    76
paulson@13957
    77
end