src/HOLCF/Pcpodef.thy
author huffman
Thu Mar 27 00:27:16 2008 +0100 (2008-03-27)
changeset 26420 57a626f64875
parent 26027 87cb69d27558
child 27296 eec7a1889ca5
permissions -rw-r--r--
make preorder locale into a superclass of class po
     1 (*  Title:      HOLCF/Pcpodef.thy
     2     ID:         $Id$
     3     Author:     Brian Huffman
     4 *)
     5 
     6 header {* Subtypes of pcpos *}
     7 
     8 theory Pcpodef
     9 imports Adm
    10 uses ("Tools/pcpodef_package.ML")
    11 begin
    12 
    13 subsection {* Proving a subtype is a partial order *}
    14 
    15 text {*
    16   A subtype of a partial order is itself a partial order,
    17   if the ordering is defined in the standard way.
    18 *}
    19 
    20 theorem typedef_po:
    21   fixes Abs :: "'a::po \<Rightarrow> 'b::sq_ord"
    22   assumes type: "type_definition Rep Abs A"
    23     and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
    24   shows "OFCLASS('b, po_class)"
    25  apply (intro_classes, unfold less)
    26    apply (rule refl_less)
    27   apply (erule (1) trans_less)
    28  apply (rule type_definition.Rep_inject [OF type, THEN iffD1])
    29  apply (erule (1) antisym_less)
    30 done
    31 
    32 subsection {* Proving a subtype is finite *}
    33 
    34 context type_definition
    35 begin
    36 
    37 lemma Abs_image:
    38   shows "Abs ` A = UNIV"
    39 proof
    40   show "Abs ` A <= UNIV" by simp
    41   show "UNIV <= Abs ` A"
    42   proof
    43     fix x
    44     have "x = Abs (Rep x)" by (rule Rep_inverse [symmetric])
    45     thus "x : Abs ` A" using Rep by (rule image_eqI)
    46   qed
    47 qed
    48 
    49 lemma finite_UNIV: "finite A \<Longrightarrow> finite (UNIV :: 'b set)"
    50 proof -
    51   assume "finite A"
    52   hence "finite (Abs ` A)" by (rule finite_imageI)
    53   thus "finite (UNIV :: 'b set)" by (simp only: Abs_image)
    54 qed
    55 
    56 end
    57 
    58 theorem typedef_finite_po:
    59   fixes Abs :: "'a::finite_po \<Rightarrow> 'b::po"
    60   assumes type: "type_definition Rep Abs A"
    61   shows "OFCLASS('b, finite_po_class)"
    62  apply (intro_classes)
    63  apply (rule type_definition.finite_UNIV [OF type])
    64  apply (rule finite)
    65 done
    66 
    67 subsection {* Proving a subtype is chain-finite *}
    68 
    69 lemma monofun_Rep:
    70   assumes less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
    71   shows "monofun Rep"
    72 by (rule monofunI, unfold less)
    73 
    74 lemmas ch2ch_Rep = ch2ch_monofun [OF monofun_Rep]
    75 lemmas ub2ub_Rep = ub2ub_monofun [OF monofun_Rep]
    76 
    77 theorem typedef_chfin:
    78   fixes Abs :: "'a::chfin \<Rightarrow> 'b::po"
    79   assumes type: "type_definition Rep Abs A"
    80     and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
    81   shows "OFCLASS('b, chfin_class)"
    82  apply intro_classes
    83  apply (drule ch2ch_Rep [OF less])
    84  apply (drule chfin)
    85  apply (unfold max_in_chain_def)
    86  apply (simp add: type_definition.Rep_inject [OF type])
    87 done
    88 
    89 subsection {* Proving a subtype is complete *}
    90 
    91 text {*
    92   A subtype of a cpo is itself a cpo if the ordering is
    93   defined in the standard way, and the defining subset
    94   is closed with respect to limits of chains.  A set is
    95   closed if and only if membership in the set is an
    96   admissible predicate.
    97 *}
    98 
    99 lemma Abs_inverse_lub_Rep:
   100   fixes Abs :: "'a::cpo \<Rightarrow> 'b::po"
   101   assumes type: "type_definition Rep Abs A"
   102     and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
   103     and adm:  "adm (\<lambda>x. x \<in> A)"
   104   shows "chain S \<Longrightarrow> Rep (Abs (\<Squnion>i. Rep (S i))) = (\<Squnion>i. Rep (S i))"
   105  apply (rule type_definition.Abs_inverse [OF type])
   106  apply (erule admD [OF adm ch2ch_Rep [OF less]])
   107  apply (rule type_definition.Rep [OF type])
   108 done
   109 
   110 theorem typedef_lub:
   111   fixes Abs :: "'a::cpo \<Rightarrow> 'b::po"
   112   assumes type: "type_definition Rep Abs A"
   113     and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
   114     and adm: "adm (\<lambda>x. x \<in> A)"
   115   shows "chain S \<Longrightarrow> range S <<| Abs (\<Squnion>i. Rep (S i))"
   116  apply (frule ch2ch_Rep [OF less])
   117  apply (rule is_lubI)
   118   apply (rule ub_rangeI)
   119   apply (simp only: less Abs_inverse_lub_Rep [OF type less adm])
   120   apply (erule is_ub_thelub)
   121  apply (simp only: less Abs_inverse_lub_Rep [OF type less adm])
   122  apply (erule is_lub_thelub)
   123  apply (erule ub2ub_Rep [OF less])
   124 done
   125 
   126 lemmas typedef_thelub = typedef_lub [THEN thelubI, standard]
   127 
   128 theorem typedef_cpo:
   129   fixes Abs :: "'a::cpo \<Rightarrow> 'b::po"
   130   assumes type: "type_definition Rep Abs A"
   131     and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
   132     and adm: "adm (\<lambda>x. x \<in> A)"
   133   shows "OFCLASS('b, cpo_class)"
   134 proof
   135   fix S::"nat \<Rightarrow> 'b" assume "chain S"
   136   hence "range S <<| Abs (\<Squnion>i. Rep (S i))"
   137     by (rule typedef_lub [OF type less adm])
   138   thus "\<exists>x. range S <<| x" ..
   139 qed
   140 
   141 subsubsection {* Continuity of @{term Rep} and @{term Abs} *}
   142 
   143 text {* For any sub-cpo, the @{term Rep} function is continuous. *}
   144 
   145 theorem typedef_cont_Rep:
   146   fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo"
   147   assumes type: "type_definition Rep Abs A"
   148     and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
   149     and adm: "adm (\<lambda>x. x \<in> A)"
   150   shows "cont Rep"
   151  apply (rule contI)
   152  apply (simp only: typedef_thelub [OF type less adm])
   153  apply (simp only: Abs_inverse_lub_Rep [OF type less adm])
   154  apply (rule cpo_lubI)
   155  apply (erule ch2ch_Rep [OF less])
   156 done
   157 
   158 text {*
   159   For a sub-cpo, we can make the @{term Abs} function continuous
   160   only if we restrict its domain to the defining subset by
   161   composing it with another continuous function.
   162 *}
   163 
   164 theorem typedef_is_lubI:
   165   assumes less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
   166   shows "range (\<lambda>i. Rep (S i)) <<| Rep x \<Longrightarrow> range S <<| x"
   167  apply (rule is_lubI)
   168   apply (rule ub_rangeI)
   169   apply (subst less)
   170   apply (erule is_ub_lub)
   171  apply (subst less)
   172  apply (erule is_lub_lub)
   173  apply (erule ub2ub_Rep [OF less])
   174 done
   175 
   176 theorem typedef_cont_Abs:
   177   fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo"
   178   fixes f :: "'c::cpo \<Rightarrow> 'a::cpo"
   179   assumes type: "type_definition Rep Abs A"
   180     and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
   181     and adm: "adm (\<lambda>x. x \<in> A)" (* not used *)
   182     and f_in_A: "\<And>x. f x \<in> A"
   183     and cont_f: "cont f"
   184   shows "cont (\<lambda>x. Abs (f x))"
   185  apply (rule contI)
   186  apply (rule typedef_is_lubI [OF less])
   187  apply (simp only: type_definition.Abs_inverse [OF type f_in_A])
   188  apply (erule cont_f [THEN contE])
   189 done
   190 
   191 subsection {* Proving subtype elements are compact *}
   192 
   193 theorem typedef_compact:
   194   fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo"
   195   assumes type: "type_definition Rep Abs A"
   196     and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
   197     and adm: "adm (\<lambda>x. x \<in> A)"
   198   shows "compact (Rep k) \<Longrightarrow> compact k"
   199 proof (unfold compact_def)
   200   have cont_Rep: "cont Rep"
   201     by (rule typedef_cont_Rep [OF type less adm])
   202   assume "adm (\<lambda>x. \<not> Rep k \<sqsubseteq> x)"
   203   with cont_Rep have "adm (\<lambda>x. \<not> Rep k \<sqsubseteq> Rep x)" by (rule adm_subst)
   204   thus "adm (\<lambda>x. \<not> k \<sqsubseteq> x)" by (unfold less)
   205 qed
   206 
   207 subsection {* Proving a subtype is pointed *}
   208 
   209 text {*
   210   A subtype of a cpo has a least element if and only if
   211   the defining subset has a least element.
   212 *}
   213 
   214 theorem typedef_pcpo_generic:
   215   fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo"
   216   assumes type: "type_definition Rep Abs A"
   217     and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
   218     and z_in_A: "z \<in> A"
   219     and z_least: "\<And>x. x \<in> A \<Longrightarrow> z \<sqsubseteq> x"
   220   shows "OFCLASS('b, pcpo_class)"
   221  apply (intro_classes)
   222  apply (rule_tac x="Abs z" in exI, rule allI)
   223  apply (unfold less)
   224  apply (subst type_definition.Abs_inverse [OF type z_in_A])
   225  apply (rule z_least [OF type_definition.Rep [OF type]])
   226 done
   227 
   228 text {*
   229   As a special case, a subtype of a pcpo has a least element
   230   if the defining subset contains @{term \<bottom>}.
   231 *}
   232 
   233 theorem typedef_pcpo:
   234   fixes Abs :: "'a::pcpo \<Rightarrow> 'b::cpo"
   235   assumes type: "type_definition Rep Abs A"
   236     and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
   237     and UU_in_A: "\<bottom> \<in> A"
   238   shows "OFCLASS('b, pcpo_class)"
   239 by (rule typedef_pcpo_generic [OF type less UU_in_A], rule minimal)
   240 
   241 subsubsection {* Strictness of @{term Rep} and @{term Abs} *}
   242 
   243 text {*
   244   For a sub-pcpo where @{term \<bottom>} is a member of the defining
   245   subset, @{term Rep} and @{term Abs} are both strict.
   246 *}
   247 
   248 theorem typedef_Abs_strict:
   249   assumes type: "type_definition Rep Abs A"
   250     and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
   251     and UU_in_A: "\<bottom> \<in> A"
   252   shows "Abs \<bottom> = \<bottom>"
   253  apply (rule UU_I, unfold less)
   254  apply (simp add: type_definition.Abs_inverse [OF type UU_in_A])
   255 done
   256 
   257 theorem typedef_Rep_strict:
   258   assumes type: "type_definition Rep Abs A"
   259     and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
   260     and UU_in_A: "\<bottom> \<in> A"
   261   shows "Rep \<bottom> = \<bottom>"
   262  apply (rule typedef_Abs_strict [OF type less UU_in_A, THEN subst])
   263  apply (rule type_definition.Abs_inverse [OF type UU_in_A])
   264 done
   265 
   266 theorem typedef_Abs_strict_iff:
   267   assumes type: "type_definition Rep Abs A"
   268     and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
   269     and UU_in_A: "\<bottom> \<in> A"
   270   shows "x \<in> A \<Longrightarrow> (Abs x = \<bottom>) = (x = \<bottom>)"
   271  apply (rule typedef_Abs_strict [OF type less UU_in_A, THEN subst])
   272  apply (simp add: type_definition.Abs_inject [OF type] UU_in_A)
   273 done
   274 
   275 theorem typedef_Rep_strict_iff:
   276   assumes type: "type_definition Rep Abs A"
   277     and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
   278     and UU_in_A: "\<bottom> \<in> A"
   279   shows "(Rep x = \<bottom>) = (x = \<bottom>)"
   280  apply (rule typedef_Rep_strict [OF type less UU_in_A, THEN subst])
   281  apply (simp add: type_definition.Rep_inject [OF type])
   282 done
   283 
   284 theorem typedef_Abs_defined:
   285   assumes type: "type_definition Rep Abs A"
   286     and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
   287     and UU_in_A: "\<bottom> \<in> A"
   288   shows "\<lbrakk>x \<noteq> \<bottom>; x \<in> A\<rbrakk> \<Longrightarrow> Abs x \<noteq> \<bottom>"
   289 by (simp add: typedef_Abs_strict_iff [OF type less UU_in_A])
   290 
   291 theorem typedef_Rep_defined:
   292   assumes type: "type_definition Rep Abs A"
   293     and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
   294     and UU_in_A: "\<bottom> \<in> A"
   295   shows "x \<noteq> \<bottom> \<Longrightarrow> Rep x \<noteq> \<bottom>"
   296 by (simp add: typedef_Rep_strict_iff [OF type less UU_in_A])
   297 
   298 subsection {* Proving a subtype is flat *}
   299 
   300 theorem typedef_flat:
   301   fixes Abs :: "'a::flat \<Rightarrow> 'b::pcpo"
   302   assumes type: "type_definition Rep Abs A"
   303     and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
   304     and UU_in_A: "\<bottom> \<in> A"
   305   shows "OFCLASS('b, flat_class)"
   306  apply (intro_classes)
   307  apply (unfold less)
   308  apply (simp add: type_definition.Rep_inject [OF type, symmetric])
   309  apply (simp add: typedef_Rep_strict [OF type less UU_in_A])
   310  apply (simp add: ax_flat)
   311 done
   312 
   313 subsection {* HOLCF type definition package *}
   314 
   315 use "Tools/pcpodef_package.ML"
   316 
   317 end