header {* Bifinite domains and approximation *}
theory Bifinite
imports Deflation
begin
subsection {* Omega-profinite and bifinite domains *}
class profinite =
fixes approx :: "nat => 'a -> 'a"
assumes chain_approx [simp]: "chain approx"
assumes lub_approx_app [simp]: "(\<Squnion>i. approx i·x) = x"
assumes approx_idem: "approx i·(approx i·x) = approx i·x"
assumes finite_fixes_approx: "finite {x. approx i·x = x}"
class bifinite = profinite + pcpo
lemma approx_below: "approx i·x \<sqsubseteq> x"
proof -
have "chain (λi. approx i·x)" by simp
hence "approx i·x \<sqsubseteq> (\<Squnion>i. approx i·x)" by (rule is_ub_thelub)
thus "approx i·x \<sqsubseteq> x" by simp
qed
lemma finite_deflation_approx: "finite_deflation (approx i)"
proof
fix x :: 'a
show "approx i·(approx i·x) = approx i·x"
by (rule approx_idem)
show "approx i·x \<sqsubseteq> x"
by (rule approx_below)
show "finite {x. approx i·x = x}"
by (rule finite_fixes_approx)
qed
interpretation approx: finite_deflation "approx i"
by (rule finite_deflation_approx)
lemma (in deflation) deflation: "deflation d" ..
lemma deflation_approx: "deflation (approx i)"
by (rule approx.deflation)
lemma lub_approx [simp]: "(\<Squnion>i. approx i) = (Λ x. x)"
by (rule ext_cfun, simp add: contlub_cfun_fun)
lemma approx_strict [simp]: "approx i·⊥ = ⊥"
by (rule UU_I, rule approx_below)
lemma approx_approx1:
"i ≤ j ==> approx i·(approx j·x) = approx i·x"
apply (rule deflation_below_comp1 [OF deflation_approx deflation_approx])
apply (erule chain_mono [OF chain_approx])
done
lemma approx_approx2:
"j ≤ i ==> approx i·(approx j·x) = approx j·x"
apply (rule deflation_below_comp2 [OF deflation_approx deflation_approx])
apply (erule chain_mono [OF chain_approx])
done
lemma approx_approx [simp]:
"approx i·(approx j·x) = approx (min i j)·x"
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 finite_image_approx: "finite ((λx. approx n·x) ` A)"
by (rule approx.finite_image)
lemma finite_range_approx: "finite (range (λx. approx i·x))"
by (rule approx.finite_range)
lemma compact_approx [simp]: "compact (approx n·x)"
by (rule approx.compact)
lemma profinite_compact_eq_approx: "compact x ==> ∃i. approx i·x = x"
by (rule admD2, simp_all)
lemma profinite_compact_iff: "compact x <-> (∃n. approx n·x = x)"
apply (rule iffI)
apply (erule profinite_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"
proof -
have "P (\<Squnion>n. approx n·x)"
by (rule admD [OF adm], simp, simp add: P)
thus "P x" by simp
qed
lemma profinite_below_ext: "(!!i. approx i·x \<sqsubseteq> approx i·y) ==> x \<sqsubseteq> y"
apply (subgoal_tac "(\<Squnion>i. approx i·x) \<sqsubseteq> (\<Squnion>i. approx i·y)", simp)
apply (rule lub_mono, simp, simp, simp)
done
subsection {* Instance for product type *}
definition
cprod_map :: "('a -> 'b) -> ('c -> 'd) -> 'a × 'c -> 'b × 'd"
where
"cprod_map = (Λ f g p. (f·(fst p), g·(snd p)))"
lemma cprod_map_Pair [simp]: "cprod_map·f·g·(x, y) = (f·x, g·y)"
unfolding cprod_map_def by simp
lemma cprod_map_ID: "cprod_map·ID·ID = ID"
unfolding expand_cfun_eq by auto
lemma cprod_map_map:
"cprod_map·f1·g1·(cprod_map·f2·g2·p) =
cprod_map·(Λ x. f1·(f2·x))·(Λ x. g1·(g2·x))·p"
by (induct p) simp
lemma ep_pair_cprod_map:
assumes "ep_pair e1 p1" and "ep_pair e2 p2"
shows "ep_pair (cprod_map·e1·e2) (cprod_map·p1·p2)"
proof
interpret e1p1: ep_pair e1 p1 by fact
interpret e2p2: ep_pair e2 p2 by fact
fix x show "cprod_map·p1·p2·(cprod_map·e1·e2·x) = x"
by (induct x) simp
fix y show "cprod_map·e1·e2·(cprod_map·p1·p2·y) \<sqsubseteq> y"
by (induct y) (simp add: e1p1.e_p_below e2p2.e_p_below)
qed
lemma deflation_cprod_map:
assumes "deflation d1" and "deflation d2"
shows "deflation (cprod_map·d1·d2)"
proof
interpret d1: deflation d1 by fact
interpret d2: deflation d2 by fact
fix x
show "cprod_map·d1·d2·(cprod_map·d1·d2·x) = cprod_map·d1·d2·x"
by (induct x) (simp add: d1.idem d2.idem)
show "cprod_map·d1·d2·x \<sqsubseteq> x"
by (induct x) (simp add: d1.below d2.below)
qed
lemma finite_deflation_cprod_map:
assumes "finite_deflation d1" and "finite_deflation d2"
shows "finite_deflation (cprod_map·d1·d2)"
proof (intro finite_deflation.intro finite_deflation_axioms.intro)
interpret d1: finite_deflation d1 by fact
interpret d2: finite_deflation d2 by fact
have "deflation d1" and "deflation d2" by fact+
thus "deflation (cprod_map·d1·d2)" by (rule deflation_cprod_map)
have "{p. cprod_map·d1·d2·p = p} ⊆ {x. d1·x = x} × {y. d2·y = y}"
by clarsimp
thus "finite {p. cprod_map·d1·d2·p = p}"
by (rule finite_subset, simp add: d1.finite_fixes d2.finite_fixes)
qed
instantiation "*" :: (profinite, profinite) profinite
begin
definition
approx_prod_def:
"approx = (λn. cprod_map·(approx n)·(approx n))"
instance proof
fix i :: nat and x :: "'a × 'b"
show "chain (approx :: nat => 'a × 'b -> 'a × 'b)"
unfolding approx_prod_def by simp
show "(\<Squnion>i. approx i·x) = x"
unfolding approx_prod_def cprod_map_def
by (simp add: lub_distribs thelub_Pair)
show "approx i·(approx i·x) = approx i·x"
unfolding approx_prod_def cprod_map_def by simp
have "{x::'a × 'b. approx i·x = x} ⊆
{x::'a. approx i·x = x} × {x::'b. approx i·x = x}"
unfolding approx_prod_def by clarsimp
thus "finite {x::'a × 'b. approx i·x = x}"
by (rule finite_subset,
intro finite_cartesian_product finite_fixes_approx)
qed
end
instance "*" :: (bifinite, bifinite) bifinite ..
lemma approx_Pair [simp]:
"approx i·(x, y) = (approx i·x, approx i·y)"
unfolding approx_prod_def by simp
lemma fst_approx: "fst (approx i·p) = approx i·(fst p)"
by (induct p, simp)
lemma snd_approx: "snd (approx i·p) = approx i·(snd p)"
by (induct p, simp)
subsection {* Instance for continuous function space *}
definition
cfun_map :: "('b -> 'a) -> ('c -> 'd) -> ('a -> 'c) -> ('b -> 'd)"
where
"cfun_map = (Λ a b f x. b·(f·(a·x)))"
lemma cfun_map_beta [simp]: "cfun_map·a·b·f·x = b·(f·(a·x))"
unfolding cfun_map_def by simp
lemma cfun_map_ID: "cfun_map·ID·ID = ID"
unfolding expand_cfun_eq by simp
lemma cfun_map_map:
"cfun_map·f1·g1·(cfun_map·f2·g2·p) =
cfun_map·(Λ x. f2·(f1·x))·(Λ x. g1·(g2·x))·p"
by (rule ext_cfun) simp
lemma ep_pair_cfun_map:
assumes "ep_pair e1 p1" and "ep_pair e2 p2"
shows "ep_pair (cfun_map·p1·e2) (cfun_map·e1·p2)"
proof
interpret e1p1: ep_pair e1 p1 by fact
interpret e2p2: ep_pair e2 p2 by fact
fix f show "cfun_map·e1·p2·(cfun_map·p1·e2·f) = f"
by (simp add: expand_cfun_eq)
fix g show "cfun_map·p1·e2·(cfun_map·e1·p2·g) \<sqsubseteq> g"
apply (rule below_cfun_ext, simp)
apply (rule below_trans [OF e2p2.e_p_below])
apply (rule monofun_cfun_arg)
apply (rule e1p1.e_p_below)
done
qed
lemma deflation_cfun_map:
assumes "deflation d1" and "deflation d2"
shows "deflation (cfun_map·d1·d2)"
proof
interpret d1: deflation d1 by fact
interpret d2: deflation d2 by fact
fix f
show "cfun_map·d1·d2·(cfun_map·d1·d2·f) = cfun_map·d1·d2·f"
by (simp add: expand_cfun_eq d1.idem d2.idem)
show "cfun_map·d1·d2·f \<sqsubseteq> f"
apply (rule below_cfun_ext, simp)
apply (rule below_trans [OF d2.below])
apply (rule monofun_cfun_arg)
apply (rule d1.below)
done
qed
lemma finite_range_cfun_map:
assumes a: "finite (range (λx. a·x))"
assumes b: "finite (range (λy. b·y))"
shows "finite (range (λf. cfun_map·a·b·f))" (is "finite (range ?h)")
proof (rule finite_imageD)
let ?f = "λg. range (λx. (a·x, g·x))"
show "finite (?f ` range ?h)"
proof (rule finite_subset)
let ?B = "Pow (range (λx. a·x) × range (λy. b·y))"
show "?f ` range ?h ⊆ ?B"
by clarsimp
show "finite ?B"
by (simp add: a b)
qed
show "inj_on ?f (range ?h)"
proof (rule inj_onI, rule ext_cfun, clarsimp)
fix x f g
assume "range (λx. (a·x, b·(f·(a·x)))) = range (λx. (a·x, b·(g·(a·x))))"
hence "range (λx. (a·x, b·(f·(a·x)))) ⊆ range (λx. (a·x, b·(g·(a·x))))"
by (rule equalityD1)
hence "(a·x, b·(f·(a·x))) ∈ range (λx. (a·x, b·(g·(a·x))))"
by (simp add: subset_eq)
then obtain y where "(a·x, b·(f·(a·x))) = (a·y, b·(g·(a·y)))"
by (rule rangeE)
thus "b·(f·(a·x)) = b·(g·(a·x))"
by clarsimp
qed
qed
lemma finite_deflation_cfun_map:
assumes "finite_deflation d1" and "finite_deflation d2"
shows "finite_deflation (cfun_map·d1·d2)"
proof (intro finite_deflation.intro finite_deflation_axioms.intro)
interpret d1: finite_deflation d1 by fact
interpret d2: finite_deflation d2 by fact
have "deflation d1" and "deflation d2" by fact+
thus "deflation (cfun_map·d1·d2)" by (rule deflation_cfun_map)
have "finite (range (λf. cfun_map·d1·d2·f))"
using d1.finite_range d2.finite_range
by (rule finite_range_cfun_map)
thus "finite {f. cfun_map·d1·d2·f = f}"
by (rule finite_range_imp_finite_fixes)
qed
instantiation cfun :: (profinite, profinite) profinite
begin
definition
approx_cfun_def:
"approx = (λn. cfun_map·(approx n)·(approx n))"
instance proof
show "chain (approx :: nat => ('a -> 'b) -> ('a -> 'b))"
unfolding approx_cfun_def by simp
next
fix x :: "'a -> 'b"
show "(\<Squnion>i. approx i·x) = x"
unfolding approx_cfun_def cfun_map_def
by (simp add: lub_distribs eta_cfun)
next
fix i :: nat and x :: "'a -> 'b"
show "approx i·(approx i·x) = approx i·x"
unfolding approx_cfun_def cfun_map_def by simp
next
fix i :: nat
show "finite {x::'a -> 'b. approx i·x = x}"
unfolding approx_cfun_def
by (intro finite_deflation.finite_fixes
finite_deflation_cfun_map
finite_deflation_approx)
qed
end
instance cfun :: (profinite, bifinite) bifinite ..
lemma approx_cfun: "approx n·f·x = approx n·(f·(approx n·x))"
by (simp add: approx_cfun_def)
end