# HG changeset patch # User huffman # Date 1200335161 -3600 # Node ID 5e59af604d4f67978c222dd013822fb030953e6a # Parent c00823ce7288116ab67dbfc0bf17a73edf01ecc2 new theory of bifinite domains diff -r c00823ce7288 -r 5e59af604d4f src/HOLCF/Bifinite.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOLCF/Bifinite.thy Mon Jan 14 19:26:01 2008 +0100 @@ -0,0 +1,198 @@ +(* Title: HOLCF/Bifinite.thy + ID: $Id$ + Author: Brian Huffman +*) + +header {* Bifinite domains and approximation *} + +theory Bifinite +imports Cfun +begin + +subsection {* Bifinite domains *} + +axclass approx < pcpo + +consts approx :: "nat \ 'a::approx \ 'a" + +axclass bifinite < approx + chain_approx_app: "chain (\i. approx i\x)" + lub_approx_app [simp]: "(\i. approx i\x) = x" + approx_idem: "approx i\(approx i\x) = approx i\x" + finite_fixes_approx: "finite {x. approx i\x = x}" + +lemma finite_range_imp_finite_fixes: + "finite {x. \y. x = f y} \ finite {x. f x = x}" +apply (subgoal_tac "{x. f x = x} \ {x. \y. x = f y}") +apply (erule (1) finite_subset) +apply (clarify, erule subst, rule exI, rule refl) +done + +lemma chain_approx [simp]: + "chain (approx :: nat \ 'a::bifinite \ 'a)" +apply (rule chainI) +apply (rule less_cfun_ext) +apply (rule chainE) +apply (rule chain_approx_app) +done + +lemma lub_approx [simp]: "(\i. approx i) = (\(x::'a::bifinite). x)" +by (rule ext_cfun, simp add: contlub_cfun_fun) + +lemma approx_less: "approx i\x \ (x::'a::bifinite)" +apply (subgoal_tac "approx i\x \ (\i. approx i\x)", simp) +apply (rule is_ub_thelub, simp) +done + +lemma approx_strict [simp]: "approx i\(\::'a::bifinite) = \" +by (rule UU_I, rule approx_less) + +lemma approx_approx1: + "i \ j \ approx i\(approx j\x) = approx i\(x::'a::bifinite)" +apply (rule antisym_less) +apply (rule monofun_cfun_arg [OF approx_less]) +apply (rule sq_ord_eq_less_trans [OF approx_idem [symmetric]]) +apply (rule monofun_cfun_arg) +apply (rule monofun_cfun_fun) +apply (erule chain_mono3 [OF chain_approx]) +done + +lemma approx_approx2: + "j \ i \ approx i\(approx j\x) = approx j\(x::'a::bifinite)" +apply (rule antisym_less) +apply (rule approx_less) +apply (rule sq_ord_eq_less_trans [OF approx_idem [symmetric]]) +apply (rule monofun_cfun_fun) +apply (erule chain_mono3 [OF chain_approx]) +done + +lemma approx_approx [simp]: + "approx i\(approx j\x) = approx (min i j)\(x::'a::bifinite)" +apply (rule_tac x=i and y=j in linorder_le_cases) +apply (simp add: approx_approx1 min_def) +apply (simp add: approx_approx2 min_def) +done + +lemma idem_fixes_eq_range: + "\x. f (f x) = f x \ {x. f x = x} = {y. \x. y = f x}" +by (auto simp add: eq_sym_conv) + +lemma finite_approx: "finite {y::'a::bifinite. \x. y = approx n\x}" +using finite_fixes_approx by (simp add: idem_fixes_eq_range) + +lemma finite_range_approx: + "finite (range (\x::'a::bifinite. approx n\x))" +by (simp add: image_def finite_approx) + +lemma compact_approx [simp]: + fixes x :: "'a::bifinite" + shows "compact (approx n\x)" +proof (rule compactI2) + fix Y::"nat \ 'a" + assume Y: "chain Y" + have "finite_chain (\i. approx n\(Y i))" + proof (rule finite_range_imp_finch) + show "chain (\i. approx n\(Y i))" + using Y by simp + have "range (\i. approx n\(Y i)) \ {x. approx n\x = x}" + by clarsimp + thus "finite (range (\i. approx n\(Y i)))" + using finite_fixes_approx by (rule finite_subset) + qed + hence "\j. (\i. approx n\(Y i)) = approx n\(Y j)" + by (simp add: finite_chain_def maxinch_is_thelub Y) + then obtain j where j: "(\i. approx n\(Y i)) = approx n\(Y j)" .. + + assume "approx n\x \ (\i. Y i)" + hence "approx n\(approx n\x) \ approx n\(\i. Y i)" + by (rule monofun_cfun_arg) + hence "approx n\x \ (\i. approx n\(Y i))" + by (simp add: contlub_cfun_arg Y) + hence "approx n\x \ approx n\(Y j)" + using j by simp + hence "approx n\x \ Y j" + using approx_less by (rule trans_less) + thus "\j. approx n\x \ Y j" .. +qed + +lemma bifinite_compact_eq_approx: + fixes x :: "'a::bifinite" + assumes x: "compact x" + shows "\i. approx i\x = x" +proof - + have chain: "chain (\i. approx i\x)" by simp + have less: "x \ (\i. approx i\x)" by simp + obtain i where i: "x \ approx i\x" + using compactD2 [OF x chain less] .. + with approx_less have "approx i\x = x" + by (rule antisym_less) + thus "\i. approx i\x = x" .. +qed + +lemma bifinite_compact_iff: + "compact (x::'a::bifinite) = (\n. approx n\x = x)" + apply (rule iffI) + apply (erule bifinite_compact_eq_approx) + apply (erule exE) + apply (erule subst) + apply (rule compact_approx) +done + +lemma approx_induct: + assumes adm: "adm P" and P: "\n x. P (approx n\x)" + shows "P (x::'a::bifinite)" +proof - + have "P (\n. approx n\x)" + by (rule admD [OF adm], simp, simp add: P) + thus "P x" by simp +qed + +lemma bifinite_less_ext: + fixes x y :: "'a::bifinite" + shows "(\i. approx i\x \ approx i\y) \ x \ y" +apply (subgoal_tac "(\i. approx i\x) \ (\i. approx i\y)", simp) +apply (rule lub_mono [rule_format], simp, simp, simp) +done + +subsection {* Instance for continuous function space *} + +lemma finite_range_lemma: + fixes h :: "'a::cpo \ 'b::cpo" + fixes k :: "'c::cpo \ 'd::cpo" + shows "\finite {y. \x. y = h\x}; finite {y. \x. y = k\x}\ + \ finite {g. \f. g = (\ x. k\(f\(h\x)))}" + apply (rule_tac f="\g. {(h\x, y) |x y. y = g\x}" in finite_imageD) + apply (rule_tac B="Pow ({y. \x. y = h\x} \ {y. \x. y = k\x})" + in finite_subset) + apply (rule image_subsetI) + apply (clarsimp, fast) + apply simp + apply (rule inj_onI) + apply (clarsimp simp add: expand_set_eq) + apply (rule ext_cfun, simp) + apply (drule_tac x="h\x" in spec) + apply (drule_tac x="k\(f\(h\x))" in spec) + apply (drule iffD1, fast) + apply clarsimp +done + +instance "->" :: (bifinite, bifinite) approx .. + +defs (overloaded) + approx_cfun_def: + "approx \ \n. \ f x. approx n\(f\(approx n\x))" + +instance "->" :: (bifinite, bifinite) bifinite + apply (intro_classes, unfold approx_cfun_def) + apply simp + apply (simp add: lub_distribs eta_cfun) + apply simp + apply simp + apply (rule finite_range_imp_finite_fixes) + apply (intro finite_range_lemma finite_approx) +done + +lemma approx_cfun: "approx n\f\x = approx n\(f\(approx n\x))" +by (simp add: approx_cfun_def) + +end