Up to index of Isabelle/HOLCF
theory Pcpodef(* Title: HOLCF/Pcpodef.thy
ID: $Id: Pcpodef.thy,v 1.13 2008/03/26 23:27:16 huffman Exp $
Author: Brian Huffman
*)
header {* Subtypes of pcpos *}
theory Pcpodef
imports Adm
uses ("Tools/pcpodef_package.ML")
begin
subsection {* Proving a subtype is a partial order *}
text {*
A subtype of a partial order is itself a partial order,
if the ordering is defined in the standard way.
*}
theorem typedef_po:
fixes Abs :: "'a::po => 'b::sq_ord"
assumes type: "type_definition Rep Abs A"
and less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
shows "OFCLASS('b, po_class)"
apply (intro_classes, unfold less)
apply (rule refl_less)
apply (erule (1) trans_less)
apply (rule type_definition.Rep_inject [OF type, THEN iffD1])
apply (erule (1) antisym_less)
done
subsection {* Proving a subtype is finite *}
context type_definition
begin
lemma Abs_image:
shows "Abs ` A = UNIV"
proof
show "Abs ` A <= UNIV" by simp
show "UNIV <= Abs ` A"
proof
fix x
have "x = Abs (Rep x)" by (rule Rep_inverse [symmetric])
thus "x : Abs ` A" using Rep by (rule image_eqI)
qed
qed
lemma finite_UNIV: "finite A ==> finite (UNIV :: 'b set)"
proof -
assume "finite A"
hence "finite (Abs ` A)" by (rule finite_imageI)
thus "finite (UNIV :: 'b set)" by (simp only: Abs_image)
qed
end
theorem typedef_finite_po:
fixes Abs :: "'a::finite_po => 'b::po"
assumes type: "type_definition Rep Abs A"
shows "OFCLASS('b, finite_po_class)"
apply (intro_classes)
apply (rule type_definition.finite_UNIV [OF type])
apply (rule finite)
done
subsection {* Proving a subtype is chain-finite *}
lemma monofun_Rep:
assumes less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
shows "monofun Rep"
by (rule monofunI, unfold less)
lemmas ch2ch_Rep = ch2ch_monofun [OF monofun_Rep]
lemmas ub2ub_Rep = ub2ub_monofun [OF monofun_Rep]
theorem typedef_chfin:
fixes Abs :: "'a::chfin => 'b::po"
assumes type: "type_definition Rep Abs A"
and less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
shows "OFCLASS('b, chfin_class)"
apply intro_classes
apply (drule ch2ch_Rep [OF less])
apply (drule chfin)
apply (unfold max_in_chain_def)
apply (simp add: type_definition.Rep_inject [OF type])
done
subsection {* Proving a subtype is complete *}
text {*
A subtype of a cpo is itself a cpo if the ordering is
defined in the standard way, and the defining subset
is closed with respect to limits of chains. A set is
closed if and only if membership in the set is an
admissible predicate.
*}
lemma Abs_inverse_lub_Rep:
fixes Abs :: "'a::cpo => 'b::po"
assumes type: "type_definition Rep Abs A"
and less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
and adm: "adm (λx. x ∈ A)"
shows "chain S ==> Rep (Abs (\<Squnion>i. Rep (S i))) = (\<Squnion>i. Rep (S i))"
apply (rule type_definition.Abs_inverse [OF type])
apply (erule admD [OF adm ch2ch_Rep [OF less]])
apply (rule type_definition.Rep [OF type])
done
theorem typedef_lub:
fixes Abs :: "'a::cpo => 'b::po"
assumes type: "type_definition Rep Abs A"
and less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
and adm: "adm (λx. x ∈ A)"
shows "chain S ==> range S <<| Abs (\<Squnion>i. Rep (S i))"
apply (frule ch2ch_Rep [OF less])
apply (rule is_lubI)
apply (rule ub_rangeI)
apply (simp only: less Abs_inverse_lub_Rep [OF type less adm])
apply (erule is_ub_thelub)
apply (simp only: less Abs_inverse_lub_Rep [OF type less adm])
apply (erule is_lub_thelub)
apply (erule ub2ub_Rep [OF less])
done
lemmas typedef_thelub = typedef_lub [THEN thelubI, standard]
theorem typedef_cpo:
fixes Abs :: "'a::cpo => 'b::po"
assumes type: "type_definition Rep Abs A"
and less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
and adm: "adm (λx. x ∈ A)"
shows "OFCLASS('b, cpo_class)"
proof
fix S::"nat => 'b" assume "chain S"
hence "range S <<| Abs (\<Squnion>i. Rep (S i))"
by (rule typedef_lub [OF type less adm])
thus "∃x. range S <<| x" ..
qed
subsubsection {* Continuity of @{term Rep} and @{term Abs} *}
text {* For any sub-cpo, the @{term Rep} function is continuous. *}
theorem typedef_cont_Rep:
fixes Abs :: "'a::cpo => 'b::cpo"
assumes type: "type_definition Rep Abs A"
and less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
and adm: "adm (λx. x ∈ A)"
shows "cont Rep"
apply (rule contI)
apply (simp only: typedef_thelub [OF type less adm])
apply (simp only: Abs_inverse_lub_Rep [OF type less adm])
apply (rule cpo_lubI)
apply (erule ch2ch_Rep [OF less])
done
text {*
For a sub-cpo, we can make the @{term Abs} function continuous
only if we restrict its domain to the defining subset by
composing it with another continuous function.
*}
theorem typedef_is_lubI:
assumes less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
shows "range (λi. Rep (S i)) <<| Rep x ==> range S <<| x"
apply (rule is_lubI)
apply (rule ub_rangeI)
apply (subst less)
apply (erule is_ub_lub)
apply (subst less)
apply (erule is_lub_lub)
apply (erule ub2ub_Rep [OF less])
done
theorem typedef_cont_Abs:
fixes Abs :: "'a::cpo => 'b::cpo"
fixes f :: "'c::cpo => 'a::cpo"
assumes type: "type_definition Rep Abs A"
and less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
and adm: "adm (λx. x ∈ A)" (* not used *)
and f_in_A: "!!x. f x ∈ A"
and cont_f: "cont f"
shows "cont (λx. Abs (f x))"
apply (rule contI)
apply (rule typedef_is_lubI [OF less])
apply (simp only: type_definition.Abs_inverse [OF type f_in_A])
apply (erule cont_f [THEN contE])
done
subsection {* Proving subtype elements are compact *}
theorem typedef_compact:
fixes Abs :: "'a::cpo => 'b::cpo"
assumes type: "type_definition Rep Abs A"
and less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
and adm: "adm (λx. x ∈ A)"
shows "compact (Rep k) ==> compact k"
proof (unfold compact_def)
have cont_Rep: "cont Rep"
by (rule typedef_cont_Rep [OF type less adm])
assume "adm (λx. ¬ Rep k \<sqsubseteq> x)"
with cont_Rep have "adm (λx. ¬ Rep k \<sqsubseteq> Rep x)" by (rule adm_subst)
thus "adm (λx. ¬ k \<sqsubseteq> x)" by (unfold less)
qed
subsection {* Proving a subtype is pointed *}
text {*
A subtype of a cpo has a least element if and only if
the defining subset has a least element.
*}
theorem typedef_pcpo_generic:
fixes Abs :: "'a::cpo => 'b::cpo"
assumes type: "type_definition Rep Abs A"
and less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
and z_in_A: "z ∈ A"
and z_least: "!!x. x ∈ A ==> z \<sqsubseteq> x"
shows "OFCLASS('b, pcpo_class)"
apply (intro_classes)
apply (rule_tac x="Abs z" in exI, rule allI)
apply (unfold less)
apply (subst type_definition.Abs_inverse [OF type z_in_A])
apply (rule z_least [OF type_definition.Rep [OF type]])
done
text {*
As a special case, a subtype of a pcpo has a least element
if the defining subset contains @{term ⊥}.
*}
theorem typedef_pcpo:
fixes Abs :: "'a::pcpo => 'b::cpo"
assumes type: "type_definition Rep Abs A"
and less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
and UU_in_A: "⊥ ∈ A"
shows "OFCLASS('b, pcpo_class)"
by (rule typedef_pcpo_generic [OF type less UU_in_A], rule minimal)
subsubsection {* Strictness of @{term Rep} and @{term Abs} *}
text {*
For a sub-pcpo where @{term ⊥} is a member of the defining
subset, @{term Rep} and @{term Abs} are both strict.
*}
theorem typedef_Abs_strict:
assumes type: "type_definition Rep Abs A"
and less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
and UU_in_A: "⊥ ∈ A"
shows "Abs ⊥ = ⊥"
apply (rule UU_I, unfold less)
apply (simp add: type_definition.Abs_inverse [OF type UU_in_A])
done
theorem typedef_Rep_strict:
assumes type: "type_definition Rep Abs A"
and less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
and UU_in_A: "⊥ ∈ A"
shows "Rep ⊥ = ⊥"
apply (rule typedef_Abs_strict [OF type less UU_in_A, THEN subst])
apply (rule type_definition.Abs_inverse [OF type UU_in_A])
done
theorem typedef_Abs_strict_iff:
assumes type: "type_definition Rep Abs A"
and less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
and UU_in_A: "⊥ ∈ A"
shows "x ∈ A ==> (Abs x = ⊥) = (x = ⊥)"
apply (rule typedef_Abs_strict [OF type less UU_in_A, THEN subst])
apply (simp add: type_definition.Abs_inject [OF type] UU_in_A)
done
theorem typedef_Rep_strict_iff:
assumes type: "type_definition Rep Abs A"
and less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
and UU_in_A: "⊥ ∈ A"
shows "(Rep x = ⊥) = (x = ⊥)"
apply (rule typedef_Rep_strict [OF type less UU_in_A, THEN subst])
apply (simp add: type_definition.Rep_inject [OF type])
done
theorem typedef_Abs_defined:
assumes type: "type_definition Rep Abs A"
and less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
and UU_in_A: "⊥ ∈ A"
shows "[|x ≠ ⊥; x ∈ A|] ==> Abs x ≠ ⊥"
by (simp add: typedef_Abs_strict_iff [OF type less UU_in_A])
theorem typedef_Rep_defined:
assumes type: "type_definition Rep Abs A"
and less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
and UU_in_A: "⊥ ∈ A"
shows "x ≠ ⊥ ==> Rep x ≠ ⊥"
by (simp add: typedef_Rep_strict_iff [OF type less UU_in_A])
subsection {* Proving a subtype is flat *}
theorem typedef_flat:
fixes Abs :: "'a::flat => 'b::pcpo"
assumes type: "type_definition Rep Abs A"
and less: "op \<sqsubseteq> ≡ λx y. Rep x \<sqsubseteq> Rep y"
and UU_in_A: "⊥ ∈ A"
shows "OFCLASS('b, flat_class)"
apply (intro_classes)
apply (unfold less)
apply (simp add: type_definition.Rep_inject [OF type, symmetric])
apply (simp add: typedef_Rep_strict [OF type less UU_in_A])
apply (simp add: ax_flat)
done
subsection {* HOLCF type definition package *}
use "Tools/pcpodef_package.ML"
end
theorem typedef_po:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y |]
==> OFCLASS('b, po_class)
lemma Abs_image:
Abs ` A = UNIV
lemma finite_UNIV:
finite A ==> finite UNIV
theorem typedef_finite_po:
type_definition Rep Abs A ==> OFCLASS('b, finite_po_class)
lemma monofun_Rep:
op << == λx y. Rep x << Rep y ==> monofun Rep
lemma ch2ch_Rep:
[| op << == λx y. f x << f y; chain Y |] ==> chain (λi. f (Y i))
lemma ub2ub_Rep:
[| op << == λx y. f x << f y; range Y <| u |] ==> range (λi. f (Y i)) <| f u
theorem typedef_chfin:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y |]
==> OFCLASS('b, chfin_class)
lemma Abs_inverse_lub_Rep:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y; adm (λx. x ∈ A);
chain S |]
==> Rep (Abs (LUB i. Rep (S i))) = (LUB i. Rep (S i))
theorem typedef_lub:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y; adm (λx. x ∈ A);
chain S |]
==> range S <<| Abs (LUB i. Rep (S i))
lemma typedef_thelub:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y; adm (λx. x ∈ A);
chain S |]
==> Lub S = Abs (LUB i. Rep (S i))
theorem typedef_cpo:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y; adm (λx. x ∈ A) |]
==> OFCLASS('b, cpo_class)
theorem typedef_cont_Rep:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y; adm (λx. x ∈ A) |]
==> cont Rep
theorem typedef_is_lubI:
[| op << == λx y. Rep x << Rep y; range (λi. Rep (S i)) <<| Rep x |]
==> range S <<| x
theorem typedef_cont_Abs:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y; adm (λx. x ∈ A);
!!x. f x ∈ A; cont f |]
==> cont (λx. Abs (f x))
theorem typedef_compact:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y; adm (λx. x ∈ A);
compact (Rep k) |]
==> compact k
theorem typedef_pcpo_generic:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y; z ∈ A;
!!x. x ∈ A ==> z << x |]
==> OFCLASS('b, pcpo_class)
theorem typedef_pcpo:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y; UU ∈ A |]
==> OFCLASS('b, pcpo_class)
theorem typedef_Abs_strict:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y; UU ∈ A |]
==> Abs UU = UU
theorem typedef_Rep_strict:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y; UU ∈ A |]
==> Rep UU = UU
theorem typedef_Abs_strict_iff:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y; UU ∈ A; x ∈ A |]
==> (Abs x = UU) = (x = UU)
theorem typedef_Rep_strict_iff:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y; UU ∈ A |]
==> (Rep x = UU) = (x = UU)
theorem typedef_Abs_defined:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y; UU ∈ A; x ≠ UU;
x ∈ A |]
==> Abs x ≠ UU
theorem typedef_Rep_defined:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y; UU ∈ A; x ≠ UU |]
==> Rep x ≠ UU
theorem typedef_flat:
[| type_definition Rep Abs A; op << == λx y. Rep x << Rep y; UU ∈ A |]
==> OFCLASS('b, flat_class)