# HG changeset patch # User kleing # Date 1140383550 -3600 # Node ID 6f8c1343341bd96288c4e87536e48f34a4b65319 # Parent b16a45c538848b93a88eb0e74fd0ab84d7791faa * denumerability of rationals by Benjamin Porter, based on NatPair (by Stefan Richter) #3 in http://www.cs.ru.nl/~freek/100/ diff -r b16a45c53884 -r 6f8c1343341b src/HOL/Complex/ex/DenumRat.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Complex/ex/DenumRat.thy Sun Feb 19 22:12:30 2006 +0100 @@ -0,0 +1,108 @@ +(* Title: HOL/Library/DenumRat.thy + ID: $Id$ + 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 \ No newline at end of file diff -r b16a45c53884 -r 6f8c1343341b src/HOL/Complex/ex/ROOT.ML --- a/src/HOL/Complex/ex/ROOT.ML Sun Feb 19 17:18:39 2006 +0100 +++ b/src/HOL/Complex/ex/ROOT.ML Sun Feb 19 22:12:30 2006 +0100 @@ -17,3 +17,4 @@ use_thy "ASeries_Complex"; use_thy "HarmonicSeries"; +use_thy "DenumRat";