Up to index of Isabelle/HOL/HOL-Complex/ex
theory DenumRat(* Title: HOL/Library/DenumRat.thy ID: $Id: DenumRat.thy,v 1.1 2006/02/19 21:12:30 kleing Exp $ Author: Benjamin Porter, 2006 *) header "Denumerability of the Rationals" theory DenumRat imports Complex_Main NatPair begin lemma nat_to_int_surj: "∃f::nat=>int. surj f" proof let ?f = "λn. if (n mod 2 = 0) then - int (n div 2) else int ((n - 1) div 2 + 1)" have "∀y. ∃x. y = ?f x" proof fix y::int { assume yl0: "y ≤ 0" then obtain n where ndef: "n = nat (- y * 2)" by simp from yl0 have g0: "- y * 2 ≥ 0" by simp hence "nat (- y * 2) mod (nat 2) = nat ((-y * 2) mod 2)" by (subst nat_mod_distrib, auto) moreover have "(-y * 2) mod 2 = 0" by arith ultimately have "nat (- y * 2) mod 2 = 0" by simp with ndef have "n mod 2 = 0" by simp hence "?f n = - int (n div 2)" by simp also with ndef have "… = - int (nat (-y * 2) div 2)" by simp also with g0 have "… = - int (nat (((-y) * 2) div 2))" using nat_div_distrib by auto also have "… = - int (nat (-y))" using zdiv_zmult_self1 [of "2" "- y"] by simp also from yl0 have "… = y" using nat_0_le by auto finally have "?f n = y" . hence "∃x. y = ?f x" by blast } moreover { assume "¬(y ≤ 0)" hence yg0: "y > 0" by simp hence yn0: "y ≠ 0" by simp from yg0 have g0: "y*2 + -2 ≥ 0" by arith from yg0 obtain n where ndef: "n = nat (y * 2 - 1)" by simp from yg0 have "nat (y*2 - 1) mod 2 = nat ((y*2 - 1) mod 2)" using nat_mod_distrib by auto also have "… = nat ((y*2 + - 1) mod 2)" by (auto simp add: diff_int_def) also have "… = nat (1)" by (auto simp add: zmod_zadd_left_eq) finally have "n mod 2 = 1" using ndef by auto hence "?f n = int ((n - 1) div 2 + 1)" by simp also with ndef have "… = int ((nat (y*2 - 1) - 1) div 2 + 1)" by simp also with yg0 have "… = int (nat (y*2 - 2) div 2 + 1)" by arith also have "… = int (nat (y*2 + -2) div 2 + 1)" by (simp add: diff_int_def) also have "… = int (nat (y*2 + -2) div (nat 2) + 1)" by auto also from g0 have "… = int (nat ((y*2 + -2) div 2) + 1)" using nat_div_distrib by auto also have "… = int (nat ((y*2) div 2 + (-2) div 2 + ((y*2) mod 2 + (-2) mod 2) div 2) + 1)" by (auto simp add: zdiv_zadd1_eq) also from yg0 g0 have "… = int (nat (y))" by (auto) finally have "?f n = y" using yg0 by auto hence "∃x. y = ?f x" by blast } ultimately show "∃x. y = ?f x" by (rule case_split) qed thus "surj ?f" by (fold surj_def) qed lemma nat2_to_int2_surj: "∃f::(nat*nat)=>(int*int). surj f" proof - from nat_to_int_surj obtain g::"nat=>int" where "surj g" .. hence aux: "∀y. ∃x. y = g x" by (unfold surj_def) let ?f = "λn. (g (fst n), g (snd n))" { fix y::"(int*int)" from aux have "∃x1 x2. fst y = g x1 ∧ snd y = g x2" by auto hence "∃x. fst y = g (fst x) ∧ snd y = g (snd x)" by auto hence "∃x. (fst y, snd y) = (g (fst x), g (snd x))" by blast hence "∃x. y = ?f x" by auto } hence "∀y. ∃x. y = ?f x" by auto hence "surj ?f" by (fold surj_def) thus ?thesis by auto qed lemma rat_denum: "∃f::nat=>rat. surj f" proof - have "inj nat2_to_nat" by (rule nat2_to_nat_inj) hence "surj (inv nat2_to_nat)" by (rule inj_imp_surj_inv) moreover from nat2_to_int2_surj obtain h::"(nat*nat)=>(int*int)" where "surj h" .. ultimately have "surj (h o (inv nat2_to_nat))" by (rule comp_surj) hence "∃f::nat=>(int*int). surj f" by auto then obtain g::"nat=>(int*int)" where "surj g" by auto hence gdef: "∀y. ∃x. y = g x" by (unfold surj_def) { fix y obtain a b where y: "y = Fract a b" by (cases y) from gdef obtain x where "(a,b) = g x" by blast hence "g x = (a,b)" .. with y have "y = (split Fract o g) x" by simp hence "∃x. y = (split Fract o g) x" .. } hence "surj (split Fract o g)" by (simp add: surj_def) thus ?thesis by blast qed end
lemma nat_to_int_surj:
∃f. surj f
lemma nat2_to_int2_surj:
∃f. surj f
lemma rat_denum:
∃f. surj f