src/HOL/Complex/ex/Sqrt_Script.thy
author nipkow
Tue Aug 26 12:07:06 2008 +0200 (2008-08-26)
changeset 28001 4642317e0deb
parent 27651 16a26996c30e
permissions -rw-r--r--
Defined rationals (Rats) globally in Rational.
Chractarized them with a few lemmas in RealDef, one of them from Sqrt.
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
nipkow@15149
     9
theory Sqrt_Script
nipkow@15149
    10
imports Primes Complex_Main
nipkow@15149
    11
begin
paulson@13957
    12
paulson@13957
    13
text {*
paulson@13957
    14
  \medskip Contrast this linear Isabelle/Isar script with Markus
paulson@13957
    15
  Wenzel's more mathematical version.
paulson@13957
    16
*}
paulson@13957
    17
paulson@13957
    18
subsection {* Preliminaries *}
paulson@13957
    19
nipkow@16663
    20
lemma prime_nonzero:  "prime p \<Longrightarrow> p \<noteq> 0"
paulson@13957
    21
  by (force simp add: prime_def)
paulson@13957
    22
paulson@13957
    23
lemma prime_dvd_other_side:
nipkow@16663
    24
    "n * n = p * (k * k) \<Longrightarrow> prime p \<Longrightarrow> p dvd n"
paulson@13957
    25
  apply (subgoal_tac "p dvd n * n", blast dest: prime_dvd_mult)
haftmann@27651
    26
  apply auto
paulson@13957
    27
  done
paulson@13957
    28
nipkow@16663
    29
lemma reduction: "prime p \<Longrightarrow>
paulson@13957
    30
    0 < k \<Longrightarrow> k * k = p * (j * j) \<Longrightarrow> k < p * j \<and> 0 < j"
paulson@13957
    31
  apply (rule ccontr)
paulson@13957
    32
  apply (simp add: linorder_not_less)
paulson@13957
    33
  apply (erule disjE)
paulson@13957
    34
   apply (frule mult_le_mono, assumption)
paulson@13957
    35
   apply auto
paulson@13957
    36
  apply (force simp add: prime_def)
paulson@13957
    37
  done
paulson@13957
    38
paulson@13957
    39
lemma rearrange: "(j::nat) * (p * j) = k * k \<Longrightarrow> k * k = p * (j * j)"
paulson@13957
    40
  by (simp add: mult_ac)
paulson@13957
    41
paulson@13957
    42
lemma prime_not_square:
nipkow@16663
    43
    "prime p \<Longrightarrow> (\<And>k. 0 < k \<Longrightarrow> m * m \<noteq> p * (k * k))"
paulson@13957
    44
  apply (induct m rule: nat_less_induct)
paulson@13957
    45
  apply clarify
paulson@13957
    46
  apply (frule prime_dvd_other_side, assumption)
paulson@13957
    47
  apply (erule dvdE)
paulson@13957
    48
  apply (simp add: nat_mult_eq_cancel_disj prime_nonzero)
paulson@13957
    49
  apply (blast dest: rearrange reduction)
paulson@13957
    50
  done
paulson@13957
    51
paulson@13957
    52
paulson@13957
    53
subsection {* Main theorem *}
paulson@13957
    54
paulson@13957
    55
text {*
paulson@13957
    56
  The square root of any prime number (including @{text 2}) is
paulson@13957
    57
  irrational.
paulson@13957
    58
*}
paulson@13957
    59
paulson@13957
    60
theorem prime_sqrt_irrational:
nipkow@16663
    61
    "prime p \<Longrightarrow> x * x = real p \<Longrightarrow> 0 \<le> x \<Longrightarrow> x \<notin> \<rat>"
nipkow@28001
    62
  apply (rule notI)
nipkow@28001
    63
  apply (erule Rats_abs_nat_div_natE)
paulson@13957
    64
  apply (simp del: real_of_nat_mult
nipkow@28001
    65
              add: real_abs_def divide_eq_eq prime_not_square real_of_nat_mult [symmetric])
paulson@13957
    66
  done
paulson@13957
    67
paulson@13957
    68
lemmas two_sqrt_irrational =
paulson@13957
    69
  prime_sqrt_irrational [OF two_is_prime]
paulson@13957
    70
paulson@13957
    71
end