author Andreas Lochbihler
Mon Sep 02 16:28:11 2013 +0200 (2013-09-02)
changeset 53361 1cb7d3c0cf31
parent 46041 1e3ff542e83e
child 54630 9061af4d5ebc
permissions -rw-r--r--
move admissible out of class ccpo to avoid unnecessary class predicate in foundational theorems
     1 (* Title:    HOL/Complete_Partial_Order.thy
     2    Author:   Brian Huffman, Portland State University
     3    Author:   Alexander Krauss, TU Muenchen
     4 *)
     6 header {* Chain-complete partial orders and their fixpoints *}
     8 theory Complete_Partial_Order
     9 imports Product_Type
    10 begin
    12 subsection {* Monotone functions *}
    14 text {* Dictionary-passing version of @{const Orderings.mono}. *}
    16 definition monotone :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> bool"
    17 where "monotone orda ordb f \<longleftrightarrow> (\<forall>x y. orda x y \<longrightarrow> ordb (f x) (f y))"
    19 lemma monotoneI[intro?]: "(\<And>x y. orda x y \<Longrightarrow> ordb (f x) (f y))
    20  \<Longrightarrow> monotone orda ordb f"
    21 unfolding monotone_def by iprover
    23 lemma monotoneD[dest?]: "monotone orda ordb f \<Longrightarrow> orda x y \<Longrightarrow> ordb (f x) (f y)"
    24 unfolding monotone_def by iprover
    27 subsection {* Chains *}
    29 text {* A chain is a totally-ordered set. Chains are parameterized over
    30   the order for maximal flexibility, since type classes are not enough.
    31 *}
    33 definition
    34   chain :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> bool"
    35 where
    36   "chain ord S \<longleftrightarrow> (\<forall>x\<in>S. \<forall>y\<in>S. ord x y \<or> ord y x)"
    38 lemma chainI:
    39   assumes "\<And>x y. x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> ord x y \<or> ord y x"
    40   shows "chain ord S"
    41 using assms unfolding chain_def by fast
    43 lemma chainD:
    44   assumes "chain ord S" and "x \<in> S" and "y \<in> S"
    45   shows "ord x y \<or> ord y x"
    46 using assms unfolding chain_def by fast
    48 lemma chainE:
    49   assumes "chain ord S" and "x \<in> S" and "y \<in> S"
    50   obtains "ord x y" | "ord y x"
    51 using assms unfolding chain_def by fast
    53 subsection {* Chain-complete partial orders *}
    55 text {*
    56   A ccpo has a least upper bound for any chain.  In particular, the
    57   empty set is a chain, so every ccpo must have a bottom element.
    58 *}
    60 class ccpo = order + Sup +
    61   assumes ccpo_Sup_upper: "\<lbrakk>chain (op \<le>) A; x \<in> A\<rbrakk> \<Longrightarrow> x \<le> Sup A"
    62   assumes ccpo_Sup_least: "\<lbrakk>chain (op \<le>) A; \<And>x. x \<in> A \<Longrightarrow> x \<le> z\<rbrakk> \<Longrightarrow> Sup A \<le> z"
    63 begin
    65 subsection {* Transfinite iteration of a function *}
    67 inductive_set iterates :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a set"
    68 for f :: "'a \<Rightarrow> 'a"
    69 where
    70   step: "x \<in> iterates f \<Longrightarrow> f x \<in> iterates f"
    71 | Sup: "chain (op \<le>) M \<Longrightarrow> \<forall>x\<in>M. x \<in> iterates f \<Longrightarrow> Sup M \<in> iterates f"
    73 lemma iterates_le_f:
    74   "x \<in> iterates f \<Longrightarrow> monotone (op \<le>) (op \<le>) f \<Longrightarrow> x \<le> f x"
    75 by (induct x rule: iterates.induct)
    76   (force dest: monotoneD intro!: ccpo_Sup_upper ccpo_Sup_least)+
    78 lemma chain_iterates:
    79   assumes f: "monotone (op \<le>) (op \<le>) f"
    80   shows "chain (op \<le>) (iterates f)" (is "chain _ ?C")
    81 proof (rule chainI)
    82   fix x y assume "x \<in> ?C" "y \<in> ?C"
    83   then show "x \<le> y \<or> y \<le> x"
    84   proof (induct x arbitrary: y rule: iterates.induct)
    85     fix x y assume y: "y \<in> ?C"
    86     and IH: "\<And>z. z \<in> ?C \<Longrightarrow> x \<le> z \<or> z \<le> x"
    87     from y show "f x \<le> y \<or> y \<le> f x"
    88     proof (induct y rule: iterates.induct)
    89       case (step y) with IH f show ?case by (auto dest: monotoneD)
    90     next
    91       case (Sup M)
    92       then have chM: "chain (op \<le>) M"
    93         and IH': "\<And>z. z \<in> M \<Longrightarrow> f x \<le> z \<or> z \<le> f x" by auto
    94       show "f x \<le> Sup M \<or> Sup M \<le> f x"
    95       proof (cases "\<exists>z\<in>M. f x \<le> z")
    96         case True then have "f x \<le> Sup M"
    97           apply rule
    98           apply (erule order_trans)
    99           by (rule ccpo_Sup_upper[OF chM])
   100         thus ?thesis ..
   101       next
   102         case False with IH'
   103         show ?thesis by (auto intro: ccpo_Sup_least[OF chM])
   104       qed
   105     qed
   106   next
   107     case (Sup M y)
   108     show ?case
   109     proof (cases "\<exists>x\<in>M. y \<le> x")
   110       case True then have "y \<le> Sup M"
   111         apply rule
   112         apply (erule order_trans)
   113         by (rule ccpo_Sup_upper[OF Sup(1)])
   114       thus ?thesis ..
   115     next
   116       case False with Sup
   117       show ?thesis by (auto intro: ccpo_Sup_least)
   118     qed
   119   qed
   120 qed
   122 subsection {* Fixpoint combinator *}
   124 definition
   125   fixp :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a"
   126 where
   127   "fixp f = Sup (iterates f)"
   129 lemma iterates_fixp:
   130   assumes f: "monotone (op \<le>) (op \<le>) f" shows "fixp f \<in> iterates f"
   131 unfolding fixp_def
   132 by (simp add: iterates.Sup chain_iterates f)
   134 lemma fixp_unfold:
   135   assumes f: "monotone (op \<le>) (op \<le>) f"
   136   shows "fixp f = f (fixp f)"
   137 proof (rule antisym)
   138   show "fixp f \<le> f (fixp f)"
   139     by (intro iterates_le_f iterates_fixp f)
   140   have "f (fixp f) \<le> Sup (iterates f)"
   141     by (intro ccpo_Sup_upper chain_iterates f iterates.step iterates_fixp)
   142   thus "f (fixp f) \<le> fixp f"
   143     unfolding fixp_def .
   144 qed
   146 lemma fixp_lowerbound:
   147   assumes f: "monotone (op \<le>) (op \<le>) f" and z: "f z \<le> z" shows "fixp f \<le> z"
   148 unfolding fixp_def
   149 proof (rule ccpo_Sup_least[OF chain_iterates[OF f]])
   150   fix x assume "x \<in> iterates f"
   151   thus "x \<le> z"
   152   proof (induct x rule: iterates.induct)
   153     fix x assume "x \<le> z" with f have "f x \<le> f z" by (rule monotoneD)
   154     also note z finally show "f x \<le> z" .
   155   qed (auto intro: ccpo_Sup_least)
   156 qed
   158 end
   160 subsection {* Fixpoint induction *}
   162 setup {* Sign.map_naming (Name_Space.mandatory_path "ccpo") *}
   164 definition admissible :: "('a set \<Rightarrow> 'a) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool"
   165 where "admissible lub ord P = (\<forall>A. chain ord A \<longrightarrow> (\<forall>x\<in>A. P x) \<longrightarrow> P (lub A))"
   167 lemma admissibleI:
   168   assumes "\<And>A. chain ord A \<Longrightarrow> \<forall>x\<in>A. P x \<Longrightarrow> P (lub A)"
   169   shows "ccpo.admissible lub ord P"
   170 using assms unfolding ccpo.admissible_def by fast
   172 lemma admissibleD:
   173   assumes "ccpo.admissible lub ord P"
   174   assumes "chain ord A"
   175   assumes "\<And>x. x \<in> A \<Longrightarrow> P x"
   176   shows "P (lub A)"
   177 using assms by (auto simp: ccpo.admissible_def)
   179 setup {* Sign.map_naming Name_Space.parent_path *}
   181 lemma (in ccpo) fixp_induct:
   182   assumes adm: "ccpo.admissible Sup (op \<le>) P"
   183   assumes mono: "monotone (op \<le>) (op \<le>) f"
   184   assumes step: "\<And>x. P x \<Longrightarrow> P (f x)"
   185   shows "P (fixp f)"
   186 unfolding fixp_def using adm chain_iterates[OF mono]
   187 proof (rule ccpo.admissibleD)
   188   fix x assume "x \<in> iterates f"
   189   thus "P x"
   190     by (induct rule: iterates.induct)
   191       (auto intro: step ccpo.admissibleD adm)
   192 qed
   194 lemma admissible_True: "ccpo.admissible lub ord (\<lambda>x. True)"
   195 unfolding ccpo.admissible_def by simp
   197 lemma admissible_False: "\<not> ccpo.admissible lub ord (\<lambda>x. False)"
   198 unfolding ccpo.admissible_def chain_def by simp
   200 lemma admissible_const: "ccpo.admissible lub ord (\<lambda>x. t) = t"
   201 by (cases t, simp_all add: admissible_True admissible_False)
   203 lemma admissible_conj:
   204   assumes "ccpo.admissible lub ord (\<lambda>x. P x)"
   205   assumes "ccpo.admissible lub ord (\<lambda>x. Q x)"
   206   shows "ccpo.admissible lub ord (\<lambda>x. P x \<and> Q x)"
   207 using assms unfolding ccpo.admissible_def by simp
   209 lemma admissible_all:
   210   assumes "\<And>y. ccpo.admissible lub ord (\<lambda>x. P x y)"
   211   shows "ccpo.admissible lub ord (\<lambda>x. \<forall>y. P x y)"
   212 using assms unfolding ccpo.admissible_def by fast
   214 lemma admissible_ball:
   215   assumes "\<And>y. y \<in> A \<Longrightarrow> ccpo.admissible lub ord (\<lambda>x. P x y)"
   216   shows "ccpo.admissible lub ord (\<lambda>x. \<forall>y\<in>A. P x y)"
   217 using assms unfolding ccpo.admissible_def by fast
   219 lemma chain_compr: "chain ord A \<Longrightarrow> chain ord {x \<in> A. P x}"
   220 unfolding chain_def by fast
   222 context ccpo begin
   224 lemma admissible_disj_lemma:
   225   assumes A: "chain (op \<le>)A"
   226   assumes P: "\<forall>x\<in>A. \<exists>y\<in>A. x \<le> y \<and> P y"
   227   shows "Sup A = Sup {x \<in> A. P x}"
   228 proof (rule antisym)
   229   have *: "chain (op \<le>) {x \<in> A. P x}"
   230     by (rule chain_compr [OF A])
   231   show "Sup A \<le> Sup {x \<in> A. P x}"
   232     apply (rule ccpo_Sup_least [OF A])
   233     apply (drule P [rule_format], clarify)
   234     apply (erule order_trans)
   235     apply (simp add: ccpo_Sup_upper [OF *])
   236     done
   237   show "Sup {x \<in> A. P x} \<le> Sup A"
   238     apply (rule ccpo_Sup_least [OF *])
   239     apply clarify
   240     apply (simp add: ccpo_Sup_upper [OF A])
   241     done
   242 qed
   244 lemma admissible_disj:
   245   fixes P Q :: "'a \<Rightarrow> bool"
   246   assumes P: "ccpo.admissible Sup (op \<le>) (\<lambda>x. P x)"
   247   assumes Q: "ccpo.admissible Sup (op \<le>) (\<lambda>x. Q x)"
   248   shows "ccpo.admissible Sup (op \<le>) (\<lambda>x. P x \<or> Q x)"
   249 proof (rule ccpo.admissibleI)
   250   fix A :: "'a set" assume A: "chain (op \<le>) A"
   251   assume "\<forall>x\<in>A. P x \<or> Q x"
   252   hence "(\<forall>x\<in>A. \<exists>y\<in>A. x \<le> y \<and> P y) \<or> (\<forall>x\<in>A. \<exists>y\<in>A. x \<le> y \<and> Q y)"
   253     using chainD[OF A] by blast
   254   hence "Sup A = Sup {x \<in> A. P x} \<or> Sup A = Sup {x \<in> A. Q x}"
   255     using admissible_disj_lemma [OF A] by fast
   256   thus "P (Sup A) \<or> Q (Sup A)"
   257     apply (rule disjE, simp_all)
   258     apply (rule disjI1, rule ccpo.admissibleD [OF P chain_compr [OF A]], simp)
   259     apply (rule disjI2, rule ccpo.admissibleD [OF Q chain_compr [OF A]], simp)
   260     done
   261 qed
   263 end
   265 instance complete_lattice \<subseteq> ccpo
   266   by default (fast intro: Sup_upper Sup_least)+
   268 lemma lfp_eq_fixp:
   269   assumes f: "mono f" shows "lfp f = fixp f"
   270 proof (rule antisym)
   271   from f have f': "monotone (op \<le>) (op \<le>) f"
   272     unfolding mono_def monotone_def .
   273   show "lfp f \<le> fixp f"
   274     by (rule lfp_lowerbound, subst fixp_unfold [OF f'], rule order_refl)
   275   show "fixp f \<le> lfp f"
   276     by (rule fixp_lowerbound [OF f'], subst lfp_unfold [OF f], rule order_refl)
   277 qed
   279 hide_const (open) iterates fixp
   281 end