src/HOL/Hyperreal/ex/Sqrt.thy
changeset 13035 d3be9be2b307
parent 13029 84e4ba7fb033
equal deleted inserted replaced
13034:d7bb6e4f5f82 13035:d3be9be2b307
    21 
    21 
    22 theorem rationals_rep: "x \<in> \<rat> \<Longrightarrow>
    22 theorem rationals_rep: "x \<in> \<rat> \<Longrightarrow>
    23   \<exists>m n. n \<noteq> 0 \<and> \<bar>x\<bar> = real m / real n \<and> gcd (m, n) = 1"
    23   \<exists>m n. n \<noteq> 0 \<and> \<bar>x\<bar> = real m / real n \<and> gcd (m, n) = 1"
    24 proof -
    24 proof -
    25   assume "x \<in> \<rat>"
    25   assume "x \<in> \<rat>"
    26   then obtain m n :: nat where n: "n \<noteq> 0" and x_rat: "\<bar>x\<bar> = real m / real n"
    26   then obtain m n :: nat where
       
    27       n: "n \<noteq> 0" and x_rat: "\<bar>x\<bar> = real m / real n"
    27     by (unfold rationals_def) blast
    28     by (unfold rationals_def) blast
    28   let ?gcd = "gcd (m, n)"
    29   let ?gcd = "gcd (m, n)"
    29   from n have gcd: "?gcd \<noteq> 0" by (simp add: gcd_zero)
    30   from n have gcd: "?gcd \<noteq> 0" by (simp add: gcd_zero)
    30   let ?k = "m div ?gcd"
    31   let ?k = "m div ?gcd"
    31   let ?l = "n div ?gcd"
    32   let ?l = "n div ?gcd"
    38   from n and gcd_l have "?l \<noteq> 0"
    39   from n and gcd_l have "?l \<noteq> 0"
    39     by (auto iff del: neq0_conv)
    40     by (auto iff del: neq0_conv)
    40   moreover
    41   moreover
    41   have "\<bar>x\<bar> = real ?k / real ?l"
    42   have "\<bar>x\<bar> = real ?k / real ?l"
    42   proof -
    43   proof -
    43     from gcd have "real ?k / real ?l = real (?gcd * ?k) / real (?gcd * ?l)"
    44     from gcd have "real ?k / real ?l =
       
    45         real (?gcd * ?k) / real (?gcd * ?l)"
    44       by (simp add: real_mult_div_cancel1)
    46       by (simp add: real_mult_div_cancel1)
    45     also from gcd_k and gcd_l have "\<dots> = real m / real n" by simp
    47     also from gcd_k and gcd_l have "\<dots> = real m / real n" by simp
    46     also from x_rat have "\<dots> = \<bar>x\<bar>" ..
    48     also from x_rat have "\<dots> = \<bar>x\<bar>" ..
    47     finally show ?thesis ..
    49     finally show ?thesis ..
    48   qed
    50   qed
   101   with gcd have "p dvd 1" by simp
   103   with gcd have "p dvd 1" by simp
   102   then have "p \<le> 1" by (simp add: dvd_imp_le)
   104   then have "p \<le> 1" by (simp add: dvd_imp_le)
   103   with p show False by simp
   105   with p show False by simp
   104 qed
   106 qed
   105 
   107 
   106 text {*
       
   107   Just for the record: we instantiate the main theorem for the
       
   108   specific prime number @{text 2} (real mathematicians would never do
       
   109   this formally :-).
       
   110 *}
       
   111 
       
   112 corollary "sqrt (real (2::nat)) \<notin> \<rat>"
   108 corollary "sqrt (real (2::nat)) \<notin> \<rat>"
   113   by (rule sqrt_prime_irrational) (rule two_is_prime)
   109   by (rule sqrt_prime_irrational) (rule two_is_prime)
   114 
   110 
   115 
   111 
   116 subsection {* Variations *}
   112 subsection {* Variations *}