| author | chaieb | 
| Wed, 27 Feb 2008 14:39:51 +0100 | |
| changeset 26157 | 4d9d0a26c32a | 
| parent 23413 | 5caa2710dd5b | 
| child 27556 | 292098f2efdf | 
| permissions | -rw-r--r-- | 
| 13957 | 1 | (* Title: HOL/Hyperreal/ex/Sqrt.thy | 
| 2 | ID: $Id$ | |
| 3 | Author: Markus Wenzel, TU Muenchen | |
| 14981 | 4 | |
| 13957 | 5 | *) | 
| 6 | ||
| 7 | header {*  Square roots of primes are irrational *}
 | |
| 8 | ||
| 15149 | 9 | theory Sqrt | 
| 10 | imports Primes Complex_Main | |
| 11 | begin | |
| 13957 | 12 | |
| 13 | subsection {* Preliminaries *}
 | |
| 14 | ||
| 15 | text {*
 | |
| 16 | The set of rational numbers, including the key representation | |
| 17 | theorem. | |
| 18 | *} | |
| 19 | ||
| 19086 | 20 | definition | 
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
19086diff
changeset | 21 |   rationals  ("\<rat>") where
 | 
| 19086 | 22 |   "\<rat> = {x. \<exists>m n. n \<noteq> 0 \<and> \<bar>x\<bar> = real (m::nat) / real (n::nat)}"
 | 
| 13957 | 23 | |
| 19086 | 24 | theorem rationals_rep [elim?]: | 
| 25 | assumes "x \<in> \<rat>" | |
| 26 | obtains m n where "n \<noteq> 0" and "\<bar>x\<bar> = real m / real n" and "gcd (m, n) = 1" | |
| 13957 | 27 | proof - | 
| 19086 | 28 | from `x \<in> \<rat>` obtain m n :: nat where | 
| 13957 | 29 | n: "n \<noteq> 0" and x_rat: "\<bar>x\<bar> = real m / real n" | 
| 19086 | 30 | unfolding rationals_def by blast | 
| 13957 | 31 | let ?gcd = "gcd (m, n)" | 
| 32 | from n have gcd: "?gcd \<noteq> 0" by (simp add: gcd_zero) | |
| 33 | let ?k = "m div ?gcd" | |
| 34 | let ?l = "n div ?gcd" | |
| 35 | let ?gcd' = "gcd (?k, ?l)" | |
| 36 | have "?gcd dvd m" .. then have gcd_k: "?gcd * ?k = m" | |
| 37 | by (rule dvd_mult_div_cancel) | |
| 38 | have "?gcd dvd n" .. then have gcd_l: "?gcd * ?l = n" | |
| 39 | by (rule dvd_mult_div_cancel) | |
| 40 | ||
| 41 | from n and gcd_l have "?l \<noteq> 0" | |
| 42 | by (auto iff del: neq0_conv) | |
| 43 | moreover | |
| 44 | have "\<bar>x\<bar> = real ?k / real ?l" | |
| 45 | proof - | |
| 46 | from gcd have "real ?k / real ?l = | |
| 23413 
5caa2710dd5b
tuned laws for cancellation in divisions for fields.
 nipkow parents: 
21404diff
changeset | 47 | real (?gcd * ?k) / real (?gcd * ?l)" by simp | 
| 13957 | 48 | also from gcd_k and gcd_l have "\<dots> = real m / real n" by simp | 
| 49 | also from x_rat have "\<dots> = \<bar>x\<bar>" .. | |
| 50 | finally show ?thesis .. | |
| 51 | qed | |
| 52 | moreover | |
| 53 | have "?gcd' = 1" | |
| 54 | proof - | |
| 55 | have "?gcd * ?gcd' = gcd (?gcd * ?k, ?gcd * ?l)" | |
| 56 | by (rule gcd_mult_distrib2) | |
| 57 | with gcd_k gcd_l have "?gcd * ?gcd' = ?gcd" by simp | |
| 58 | with gcd show ?thesis by simp | |
| 59 | qed | |
| 19086 | 60 | ultimately show ?thesis .. | 
| 13957 | 61 | qed | 
| 62 | ||
| 63 | ||
| 64 | subsection {* Main theorem *}
 | |
| 65 | ||
| 66 | text {*
 | |
| 67 |   The square root of any prime number (including @{text 2}) is
 | |
| 68 | irrational. | |
| 69 | *} | |
| 70 | ||
| 19086 | 71 | theorem sqrt_prime_irrational: | 
| 72 | assumes "prime p" | |
| 73 | shows "sqrt (real p) \<notin> \<rat>" | |
| 13957 | 74 | proof | 
| 19086 | 75 | from `prime p` have p: "1 < p" by (simp add: prime_def) | 
| 13957 | 76 | assume "sqrt (real p) \<in> \<rat>" | 
| 77 | then obtain m n where | |
| 78 | n: "n \<noteq> 0" and sqrt_rat: "\<bar>sqrt (real p)\<bar> = real m / real n" | |
| 79 | and gcd: "gcd (m, n) = 1" .. | |
| 80 | have eq: "m\<twosuperior> = p * n\<twosuperior>" | |
| 81 | proof - | |
| 82 | from n and sqrt_rat have "real m = \<bar>sqrt (real p)\<bar> * real n" by simp | |
| 83 | 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: 
14305diff
changeset | 84 | by (auto simp add: power2_eq_square) | 
| 13957 | 85 | also have "(sqrt (real p))\<twosuperior> = real p" by simp | 
| 86 | also have "\<dots> * real (n\<twosuperior>) = real (p * n\<twosuperior>)" by simp | |
| 87 | finally show ?thesis .. | |
| 88 | qed | |
| 89 | have "p dvd m \<and> p dvd n" | |
| 90 | proof | |
| 91 | from eq have "p dvd m\<twosuperior>" .. | |
| 19086 | 92 | with `prime p` show "p dvd m" by (rule prime_dvd_power_two) | 
| 13957 | 93 | then obtain k where "m = p * k" .. | 
| 14353 
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
 paulson parents: 
14305diff
changeset | 94 | 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: 
14305diff
changeset | 95 | with p have "n\<twosuperior> = p * k\<twosuperior>" by (simp add: power2_eq_square) | 
| 13957 | 96 | then have "p dvd n\<twosuperior>" .. | 
| 19086 | 97 | with `prime p` show "p dvd n" by (rule prime_dvd_power_two) | 
| 13957 | 98 | qed | 
| 99 | then have "p dvd gcd (m, n)" .. | |
| 100 | with gcd have "p dvd 1" by simp | |
| 101 | then have "p \<le> 1" by (simp add: dvd_imp_le) | |
| 102 | with p show False by simp | |
| 103 | qed | |
| 104 | ||
| 105 | corollary "sqrt (real (2::nat)) \<notin> \<rat>" | |
| 106 | by (rule sqrt_prime_irrational) (rule two_is_prime) | |
| 107 | ||
| 108 | ||
| 109 | subsection {* Variations *}
 | |
| 110 | ||
| 111 | text {*
 | |
| 112 | Here is an alternative version of the main proof, using mostly | |
| 113 | linear forward-reasoning. While this results in less top-down | |
| 114 | structure, it is probably closer to proofs seen in mathematics. | |
| 115 | *} | |
| 116 | ||
| 19086 | 117 | theorem | 
| 118 | assumes "prime p" | |
| 119 | shows "sqrt (real p) \<notin> \<rat>" | |
| 13957 | 120 | proof | 
| 19086 | 121 | from `prime p` have p: "1 < p" by (simp add: prime_def) | 
| 13957 | 122 | assume "sqrt (real p) \<in> \<rat>" | 
| 123 | then obtain m n where | |
| 124 | n: "n \<noteq> 0" and sqrt_rat: "\<bar>sqrt (real p)\<bar> = real m / real n" | |
| 125 | and gcd: "gcd (m, n) = 1" .. | |
| 126 | from n and sqrt_rat have "real m = \<bar>sqrt (real p)\<bar> * real n" by simp | |
| 127 | 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: 
14305diff
changeset | 128 | by (auto simp add: power2_eq_square) | 
| 13957 | 129 | also have "(sqrt (real p))\<twosuperior> = real p" by simp | 
| 130 | also have "\<dots> * real (n\<twosuperior>) = real (p * n\<twosuperior>)" by simp | |
| 131 | finally have eq: "m\<twosuperior> = p * n\<twosuperior>" .. | |
| 132 | then have "p dvd m\<twosuperior>" .. | |
| 19086 | 133 | with `prime p` have dvd_m: "p dvd m" by (rule prime_dvd_power_two) | 
| 13957 | 134 | then obtain k where "m = p * k" .. | 
| 14353 
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
 paulson parents: 
14305diff
changeset | 135 | 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: 
14305diff
changeset | 136 | with p have "n\<twosuperior> = p * k\<twosuperior>" by (simp add: power2_eq_square) | 
| 13957 | 137 | then have "p dvd n\<twosuperior>" .. | 
| 19086 | 138 | with `prime p` have "p dvd n" by (rule prime_dvd_power_two) | 
| 13957 | 139 | with dvd_m have "p dvd gcd (m, n)" by (rule gcd_greatest) | 
| 140 | with gcd have "p dvd 1" by simp | |
| 141 | then have "p \<le> 1" by (simp add: dvd_imp_le) | |
| 142 | with p show False by simp | |
| 143 | qed | |
| 144 | ||
| 145 | end |