src/HOL/ex/Sqrt_Script.thy
 author wenzelm Wed Jun 22 10:09:20 2016 +0200 (2016-06-22) changeset 63343 fb5d8a50c641 parent 61933 cf58b5b794b2 child 63534 523b488b15c9 permissions -rw-r--r--
bundle lifting_syntax;
```     1 (*  Title:      HOL/ex/Sqrt_Script.thy
```
```     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
```
```     3     Copyright   2001  University of Cambridge
```
```     4 *)
```
```     5
```
```     6 section \<open>Square roots of primes are irrational (script version)\<close>
```
```     7
```
```     8 theory Sqrt_Script
```
```     9 imports Complex_Main "~~/src/HOL/Number_Theory/Primes"
```
```    10 begin
```
```    11
```
```    12 text \<open>
```
```    13   \medskip Contrast this linear Isabelle/Isar script with Markus
```
```    14   Wenzel's more mathematical version.
```
```    15 \<close>
```
```    16
```
```    17 subsection \<open>Preliminaries\<close>
```
```    18
```
```    19 lemma prime_nonzero:  "prime (p::nat) \<Longrightarrow> p \<noteq> 0"
```
```    20   by (force simp add: prime_def)
```
```    21
```
```    22 lemma prime_dvd_other_side:
```
```    23     "(n::nat) * n = p * (k * k) \<Longrightarrow> prime p \<Longrightarrow> p dvd n"
```
```    24   apply (subgoal_tac "p dvd n * n", blast dest: prime_dvd_mult_nat)
```
```    25   apply auto
```
```    26   done
```
```    27
```
```    28 lemma reduction: "prime (p::nat) \<Longrightarrow>
```
```    29     0 < k \<Longrightarrow> k * k = p * (j * j) \<Longrightarrow> k < p * j \<and> 0 < j"
```
```    30   apply (rule ccontr)
```
```    31   apply (simp add: linorder_not_less)
```
```    32   apply (erule disjE)
```
```    33    apply (frule mult_le_mono, assumption)
```
```    34    apply auto
```
```    35   apply (force simp add: prime_def)
```
```    36   done
```
```    37
```
```    38 lemma rearrange: "(j::nat) * (p * j) = k * k \<Longrightarrow> k * k = p * (j * j)"
```
```    39   by (simp add: ac_simps)
```
```    40
```
```    41 lemma prime_not_square:
```
```    42     "prime (p::nat) \<Longrightarrow> (\<And>k. 0 < k \<Longrightarrow> m * m \<noteq> p * (k * k))"
```
```    43   apply (induct m rule: nat_less_induct)
```
```    44   apply clarify
```
```    45   apply (frule prime_dvd_other_side, assumption)
```
```    46   apply (erule dvdE)
```
```    47   apply (simp add: nat_mult_eq_cancel_disj prime_nonzero)
```
```    48   apply (blast dest: rearrange reduction)
```
```    49   done
```
```    50
```
```    51
```
```    52 subsection \<open>Main theorem\<close>
```
```    53
```
```    54 text \<open>
```
```    55   The square root of any prime number (including \<open>2\<close>) is
```
```    56   irrational.
```
```    57 \<close>
```
```    58
```
```    59 theorem prime_sqrt_irrational:
```
```    60     "prime (p::nat) \<Longrightarrow> x * x = real p \<Longrightarrow> 0 \<le> x \<Longrightarrow> x \<notin> \<rat>"
```
```    61   apply (rule notI)
```
```    62   apply (erule Rats_abs_nat_div_natE)
```
```    63   apply (simp del: of_nat_mult
```
```    64               add: abs_if divide_eq_eq prime_not_square of_nat_mult [symmetric])
```
```    65   done
```
```    66
```
```    67 lemmas two_sqrt_irrational =
```
```    68   prime_sqrt_irrational [OF two_is_prime_nat]
```
```    69
```
```    70 end
```