src/HOL/Complete_Partial_Order.thy
 author haftmann Sun Jun 23 21:16:07 2013 +0200 (2013-06-23) changeset 52435 6646bb548c6b parent 46041 1e3ff542e83e child 53361 1cb7d3c0cf31 permissions -rw-r--r--
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
```     1 (* Title:    HOL/Complete_Partial_Order.thy
```
```     2    Author:   Brian Huffman, Portland State University
```
```     3    Author:   Alexander Krauss, TU Muenchen
```
```     4 *)
```
```     5
```
```     6 header {* Chain-complete partial orders and their fixpoints *}
```
```     7
```
```     8 theory Complete_Partial_Order
```
```     9 imports Product_Type
```
```    10 begin
```
```    11
```
```    12 subsection {* Monotone functions *}
```
```    13
```
```    14 text {* Dictionary-passing version of @{const Orderings.mono}. *}
```
```    15
```
```    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))"
```
```    18
```
```    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
```
```    22
```
```    23 lemma monotoneD[dest?]: "monotone orda ordb f \<Longrightarrow> orda x y \<Longrightarrow> ordb (f x) (f y)"
```
```    24 unfolding monotone_def by iprover
```
```    25
```
```    26
```
```    27 subsection {* Chains *}
```
```    28
```
```    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 *}
```
```    32
```
```    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)"
```
```    37
```
```    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
```
```    42
```
```    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
```
```    47
```
```    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
```
```    52
```
```    53 subsection {* Chain-complete partial orders *}
```
```    54
```
```    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 *}
```
```    59
```
```    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
```
```    64
```
```    65 subsection {* Transfinite iteration of a function *}
```
```    66
```
```    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"
```
```    72
```
```    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)+
```
```    77
```
```    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
```
```   121
```
```   122 subsection {* Fixpoint combinator *}
```
```   123
```
```   124 definition
```
```   125   fixp :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a"
```
```   126 where
```
```   127   "fixp f = Sup (iterates f)"
```
```   128
```
```   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)
```
```   133
```
```   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
```
```   145
```
```   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
```
```   157
```
```   158
```
```   159 subsection {* Fixpoint induction *}
```
```   160
```
```   161 definition
```
```   162   admissible :: "('a \<Rightarrow> bool) \<Rightarrow> bool"
```
```   163 where
```
```   164   "admissible P = (\<forall>A. chain (op \<le>) A \<longrightarrow> (\<forall>x\<in>A. P x) \<longrightarrow> P (Sup A))"
```
```   165
```
```   166 lemma admissibleI:
```
```   167   assumes "\<And>A. chain (op \<le>) A \<Longrightarrow> \<forall>x\<in>A. P x \<Longrightarrow> P (Sup A)"
```
```   168   shows "admissible P"
```
```   169 using assms unfolding admissible_def by fast
```
```   170
```
```   171 lemma admissibleD:
```
```   172   assumes "admissible P"
```
```   173   assumes "chain (op \<le>) A"
```
```   174   assumes "\<And>x. x \<in> A \<Longrightarrow> P x"
```
```   175   shows "P (Sup A)"
```
```   176 using assms by (auto simp: admissible_def)
```
```   177
```
```   178 lemma fixp_induct:
```
```   179   assumes adm: "admissible P"
```
```   180   assumes mono: "monotone (op \<le>) (op \<le>) f"
```
```   181   assumes step: "\<And>x. P x \<Longrightarrow> P (f x)"
```
```   182   shows "P (fixp f)"
```
```   183 unfolding fixp_def using adm chain_iterates[OF mono]
```
```   184 proof (rule admissibleD)
```
```   185   fix x assume "x \<in> iterates f"
```
```   186   thus "P x"
```
```   187     by (induct rule: iterates.induct)
```
```   188       (auto intro: step admissibleD adm)
```
```   189 qed
```
```   190
```
```   191 lemma admissible_True: "admissible (\<lambda>x. True)"
```
```   192 unfolding admissible_def by simp
```
```   193
```
```   194 lemma admissible_False: "\<not> admissible (\<lambda>x. False)"
```
```   195 unfolding admissible_def chain_def by simp
```
```   196
```
```   197 lemma admissible_const: "admissible (\<lambda>x. t) = t"
```
```   198 by (cases t, simp_all add: admissible_True admissible_False)
```
```   199
```
```   200 lemma admissible_conj:
```
```   201   assumes "admissible (\<lambda>x. P x)"
```
```   202   assumes "admissible (\<lambda>x. Q x)"
```
```   203   shows "admissible (\<lambda>x. P x \<and> Q x)"
```
```   204 using assms unfolding admissible_def by simp
```
```   205
```
```   206 lemma admissible_all:
```
```   207   assumes "\<And>y. admissible (\<lambda>x. P x y)"
```
```   208   shows "admissible (\<lambda>x. \<forall>y. P x y)"
```
```   209 using assms unfolding admissible_def by fast
```
```   210
```
```   211 lemma admissible_ball:
```
```   212   assumes "\<And>y. y \<in> A \<Longrightarrow> admissible (\<lambda>x. P x y)"
```
```   213   shows "admissible (\<lambda>x. \<forall>y\<in>A. P x y)"
```
```   214 using assms unfolding admissible_def by fast
```
```   215
```
```   216 lemma chain_compr: "chain (op \<le>) A \<Longrightarrow> chain (op \<le>) {x \<in> A. P x}"
```
```   217 unfolding chain_def by fast
```
```   218
```
```   219 lemma admissible_disj_lemma:
```
```   220   assumes A: "chain (op \<le>)A"
```
```   221   assumes P: "\<forall>x\<in>A. \<exists>y\<in>A. x \<le> y \<and> P y"
```
```   222   shows "Sup A = Sup {x \<in> A. P x}"
```
```   223 proof (rule antisym)
```
```   224   have *: "chain (op \<le>) {x \<in> A. P x}"
```
```   225     by (rule chain_compr [OF A])
```
```   226   show "Sup A \<le> Sup {x \<in> A. P x}"
```
```   227     apply (rule ccpo_Sup_least [OF A])
```
```   228     apply (drule P [rule_format], clarify)
```
```   229     apply (erule order_trans)
```
```   230     apply (simp add: ccpo_Sup_upper [OF *])
```
```   231     done
```
```   232   show "Sup {x \<in> A. P x} \<le> Sup A"
```
```   233     apply (rule ccpo_Sup_least [OF *])
```
```   234     apply clarify
```
```   235     apply (simp add: ccpo_Sup_upper [OF A])
```
```   236     done
```
```   237 qed
```
```   238
```
```   239 lemma admissible_disj:
```
```   240   fixes P Q :: "'a \<Rightarrow> bool"
```
```   241   assumes P: "admissible (\<lambda>x. P x)"
```
```   242   assumes Q: "admissible (\<lambda>x. Q x)"
```
```   243   shows "admissible (\<lambda>x. P x \<or> Q x)"
```
```   244 proof (rule admissibleI)
```
```   245   fix A :: "'a set" assume A: "chain (op \<le>) A"
```
```   246   assume "\<forall>x\<in>A. P x \<or> Q x"
```
```   247   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)"
```
```   248     using chainD[OF A] by blast
```
```   249   hence "Sup A = Sup {x \<in> A. P x} \<or> Sup A = Sup {x \<in> A. Q x}"
```
```   250     using admissible_disj_lemma [OF A] by fast
```
```   251   thus "P (Sup A) \<or> Q (Sup A)"
```
```   252     apply (rule disjE, simp_all)
```
```   253     apply (rule disjI1, rule admissibleD [OF P chain_compr [OF A]], simp)
```
```   254     apply (rule disjI2, rule admissibleD [OF Q chain_compr [OF A]], simp)
```
```   255     done
```
```   256 qed
```
```   257
```
```   258 end
```
```   259
```
```   260 instance complete_lattice \<subseteq> ccpo
```
```   261   by default (fast intro: Sup_upper Sup_least)+
```
```   262
```
```   263 lemma lfp_eq_fixp:
```
```   264   assumes f: "mono f" shows "lfp f = fixp f"
```
```   265 proof (rule antisym)
```
```   266   from f have f': "monotone (op \<le>) (op \<le>) f"
```
```   267     unfolding mono_def monotone_def .
```
```   268   show "lfp f \<le> fixp f"
```
```   269     by (rule lfp_lowerbound, subst fixp_unfold [OF f'], rule order_refl)
```
```   270   show "fixp f \<le> lfp f"
```
```   271     by (rule fixp_lowerbound [OF f'], subst lfp_unfold [OF f], rule order_refl)
```
```   272 qed
```
```   273
```
```   274 hide_const (open) iterates fixp admissible
```
```   275
```
```   276 end
```