src/HOL/Complete_Partial_Order.thy
 author Andreas Lochbihler Tue Apr 14 11:32:01 2015 +0200 (2015-04-14) changeset 60057 86fa63ce8156 parent 58889 5b7a9633cfa8 child 60061 279472fa0b1d permissions -rw-r--r--
```     1 (* Title:    HOL/Complete_Partial_Order.thy
```
```     2    Author:   Brian Huffman, Portland State University
```
```     3    Author:   Alexander Krauss, TU Muenchen
```
```     4 *)
```
```     5
```
```     6 section {* 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 lemma chain_empty: "chain ord {}"
```
```    54 by(simp add: chain_def)
```
```    55
```
```    56 lemma chain_equality: "chain op = A \<longleftrightarrow> (\<forall>x\<in>A. \<forall>y\<in>A. x = y)"
```
```    57 by(auto simp add: chain_def)
```
```    58
```
```    59 subsection {* Chain-complete partial orders *}
```
```    60
```
```    61 text {*
```
```    62   A ccpo has a least upper bound for any chain.  In particular, the
```
```    63   empty set is a chain, so every ccpo must have a bottom element.
```
```    64 *}
```
```    65
```
```    66 class ccpo = order + Sup +
```
```    67   assumes ccpo_Sup_upper: "\<lbrakk>chain (op \<le>) A; x \<in> A\<rbrakk> \<Longrightarrow> x \<le> Sup A"
```
```    68   assumes ccpo_Sup_least: "\<lbrakk>chain (op \<le>) A; \<And>x. x \<in> A \<Longrightarrow> x \<le> z\<rbrakk> \<Longrightarrow> Sup A \<le> z"
```
```    69 begin
```
```    70
```
```    71 subsection {* Transfinite iteration of a function *}
```
```    72
```
```    73 inductive_set iterates :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a set"
```
```    74 for f :: "'a \<Rightarrow> 'a"
```
```    75 where
```
```    76   step: "x \<in> iterates f \<Longrightarrow> f x \<in> iterates f"
```
```    77 | Sup: "chain (op \<le>) M \<Longrightarrow> \<forall>x\<in>M. x \<in> iterates f \<Longrightarrow> Sup M \<in> iterates f"
```
```    78
```
```    79 lemma iterates_le_f:
```
```    80   "x \<in> iterates f \<Longrightarrow> monotone (op \<le>) (op \<le>) f \<Longrightarrow> x \<le> f x"
```
```    81 by (induct x rule: iterates.induct)
```
```    82   (force dest: monotoneD intro!: ccpo_Sup_upper ccpo_Sup_least)+
```
```    83
```
```    84 lemma chain_iterates:
```
```    85   assumes f: "monotone (op \<le>) (op \<le>) f"
```
```    86   shows "chain (op \<le>) (iterates f)" (is "chain _ ?C")
```
```    87 proof (rule chainI)
```
```    88   fix x y assume "x \<in> ?C" "y \<in> ?C"
```
```    89   then show "x \<le> y \<or> y \<le> x"
```
```    90   proof (induct x arbitrary: y rule: iterates.induct)
```
```    91     fix x y assume y: "y \<in> ?C"
```
```    92     and IH: "\<And>z. z \<in> ?C \<Longrightarrow> x \<le> z \<or> z \<le> x"
```
```    93     from y show "f x \<le> y \<or> y \<le> f x"
```
```    94     proof (induct y rule: iterates.induct)
```
```    95       case (step y) with IH f show ?case by (auto dest: monotoneD)
```
```    96     next
```
```    97       case (Sup M)
```
```    98       then have chM: "chain (op \<le>) M"
```
```    99         and IH': "\<And>z. z \<in> M \<Longrightarrow> f x \<le> z \<or> z \<le> f x" by auto
```
```   100       show "f x \<le> Sup M \<or> Sup M \<le> f x"
```
```   101       proof (cases "\<exists>z\<in>M. f x \<le> z")
```
```   102         case True then have "f x \<le> Sup M"
```
```   103           apply rule
```
```   104           apply (erule order_trans)
```
```   105           by (rule ccpo_Sup_upper[OF chM])
```
```   106         thus ?thesis ..
```
```   107       next
```
```   108         case False with IH'
```
```   109         show ?thesis by (auto intro: ccpo_Sup_least[OF chM])
```
```   110       qed
```
```   111     qed
```
```   112   next
```
```   113     case (Sup M y)
```
```   114     show ?case
```
```   115     proof (cases "\<exists>x\<in>M. y \<le> x")
```
```   116       case True then have "y \<le> Sup M"
```
```   117         apply rule
```
```   118         apply (erule order_trans)
```
```   119         by (rule ccpo_Sup_upper[OF Sup(1)])
```
```   120       thus ?thesis ..
```
```   121     next
```
```   122       case False with Sup
```
```   123       show ?thesis by (auto intro: ccpo_Sup_least)
```
```   124     qed
```
```   125   qed
```
```   126 qed
```
```   127
```
```   128 lemma bot_in_iterates: "Sup {} \<in> iterates f"
```
```   129 by(auto intro: iterates.Sup simp add: chain_empty)
```
```   130
```
```   131 subsection {* Fixpoint combinator *}
```
```   132
```
```   133 definition
```
```   134   fixp :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a"
```
```   135 where
```
```   136   "fixp f = Sup (iterates f)"
```
```   137
```
```   138 lemma iterates_fixp:
```
```   139   assumes f: "monotone (op \<le>) (op \<le>) f" shows "fixp f \<in> iterates f"
```
```   140 unfolding fixp_def
```
```   141 by (simp add: iterates.Sup chain_iterates f)
```
```   142
```
```   143 lemma fixp_unfold:
```
```   144   assumes f: "monotone (op \<le>) (op \<le>) f"
```
```   145   shows "fixp f = f (fixp f)"
```
```   146 proof (rule antisym)
```
```   147   show "fixp f \<le> f (fixp f)"
```
```   148     by (intro iterates_le_f iterates_fixp f)
```
```   149   have "f (fixp f) \<le> Sup (iterates f)"
```
```   150     by (intro ccpo_Sup_upper chain_iterates f iterates.step iterates_fixp)
```
```   151   thus "f (fixp f) \<le> fixp f"
```
```   152     unfolding fixp_def .
```
```   153 qed
```
```   154
```
```   155 lemma fixp_lowerbound:
```
```   156   assumes f: "monotone (op \<le>) (op \<le>) f" and z: "f z \<le> z" shows "fixp f \<le> z"
```
```   157 unfolding fixp_def
```
```   158 proof (rule ccpo_Sup_least[OF chain_iterates[OF f]])
```
```   159   fix x assume "x \<in> iterates f"
```
```   160   thus "x \<le> z"
```
```   161   proof (induct x rule: iterates.induct)
```
```   162     fix x assume "x \<le> z" with f have "f x \<le> f z" by (rule monotoneD)
```
```   163     also note z finally show "f x \<le> z" .
```
```   164   qed (auto intro: ccpo_Sup_least)
```
```   165 qed
```
```   166
```
```   167 end
```
```   168
```
```   169 subsection {* Fixpoint induction *}
```
```   170
```
```   171 setup {* Sign.map_naming (Name_Space.mandatory_path "ccpo") *}
```
```   172
```
```   173 definition admissible :: "('a set \<Rightarrow> 'a) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool"
```
```   174 where "admissible lub ord P = (\<forall>A. chain ord A \<longrightarrow> (A \<noteq> {}) \<longrightarrow> (\<forall>x\<in>A. P x) \<longrightarrow> P (lub A))"
```
```   175
```
```   176 lemma admissibleI:
```
```   177   assumes "\<And>A. chain ord A \<Longrightarrow> A \<noteq> {} \<Longrightarrow> \<forall>x\<in>A. P x \<Longrightarrow> P (lub A)"
```
```   178   shows "ccpo.admissible lub ord P"
```
```   179 using assms unfolding ccpo.admissible_def by fast
```
```   180
```
```   181 lemma admissibleD:
```
```   182   assumes "ccpo.admissible lub ord P"
```
```   183   assumes "chain ord A"
```
```   184   assumes "A \<noteq> {}"
```
```   185   assumes "\<And>x. x \<in> A \<Longrightarrow> P x"
```
```   186   shows "P (lub A)"
```
```   187 using assms by (auto simp: ccpo.admissible_def)
```
```   188
```
```   189 setup {* Sign.map_naming Name_Space.parent_path *}
```
```   190
```
```   191 lemma (in ccpo) fixp_induct:
```
```   192   assumes adm: "ccpo.admissible Sup (op \<le>) P"
```
```   193   assumes mono: "monotone (op \<le>) (op \<le>) f"
```
```   194   assumes bot: "P (Sup {})"
```
```   195   assumes step: "\<And>x. P x \<Longrightarrow> P (f x)"
```
```   196   shows "P (fixp f)"
```
```   197 unfolding fixp_def using adm chain_iterates[OF mono]
```
```   198 proof (rule ccpo.admissibleD)
```
```   199   show "iterates f \<noteq> {}" using bot_in_iterates by auto
```
```   200   fix x assume "x \<in> iterates f"
```
```   201   thus "P x"
```
```   202     by (induct rule: iterates.induct)
```
```   203       (case_tac "M = {}", auto intro: step bot ccpo.admissibleD adm)
```
```   204 qed
```
```   205
```
```   206 lemma admissible_True: "ccpo.admissible lub ord (\<lambda>x. True)"
```
```   207 unfolding ccpo.admissible_def by simp
```
```   208
```
```   209 (*lemma admissible_False: "\<not> ccpo.admissible lub ord (\<lambda>x. False)"
```
```   210 unfolding ccpo.admissible_def chain_def by simp
```
```   211 *)
```
```   212 lemma admissible_const: "ccpo.admissible lub ord (\<lambda>x. t)"
```
```   213 by(auto intro: ccpo.admissibleI)
```
```   214
```
```   215 lemma admissible_conj:
```
```   216   assumes "ccpo.admissible lub ord (\<lambda>x. P x)"
```
```   217   assumes "ccpo.admissible lub ord (\<lambda>x. Q x)"
```
```   218   shows "ccpo.admissible lub ord (\<lambda>x. P x \<and> Q x)"
```
```   219 using assms unfolding ccpo.admissible_def by simp
```
```   220
```
```   221 lemma admissible_all:
```
```   222   assumes "\<And>y. ccpo.admissible lub ord (\<lambda>x. P x y)"
```
```   223   shows "ccpo.admissible lub ord (\<lambda>x. \<forall>y. P x y)"
```
```   224 using assms unfolding ccpo.admissible_def by fast
```
```   225
```
```   226 lemma admissible_ball:
```
```   227   assumes "\<And>y. y \<in> A \<Longrightarrow> ccpo.admissible lub ord (\<lambda>x. P x y)"
```
```   228   shows "ccpo.admissible lub ord (\<lambda>x. \<forall>y\<in>A. P x y)"
```
```   229 using assms unfolding ccpo.admissible_def by fast
```
```   230
```
```   231 lemma chain_compr: "chain ord A \<Longrightarrow> chain ord {x \<in> A. P x}"
```
```   232 unfolding chain_def by fast
```
```   233
```
```   234 context ccpo begin
```
```   235
```
```   236 lemma admissible_disj_lemma:
```
```   237   assumes A: "chain (op \<le>)A"
```
```   238   assumes P: "\<forall>x\<in>A. \<exists>y\<in>A. x \<le> y \<and> P y"
```
```   239   shows "Sup A = Sup {x \<in> A. P x}"
```
```   240 proof (rule antisym)
```
```   241   have *: "chain (op \<le>) {x \<in> A. P x}"
```
```   242     by (rule chain_compr [OF A])
```
```   243   show "Sup A \<le> Sup {x \<in> A. P x}"
```
```   244     apply (rule ccpo_Sup_least [OF A])
```
```   245     apply (drule P [rule_format], clarify)
```
```   246     apply (erule order_trans)
```
```   247     apply (simp add: ccpo_Sup_upper [OF *])
```
```   248     done
```
```   249   show "Sup {x \<in> A. P x} \<le> Sup A"
```
```   250     apply (rule ccpo_Sup_least [OF *])
```
```   251     apply clarify
```
```   252     apply (simp add: ccpo_Sup_upper [OF A])
```
```   253     done
```
```   254 qed
```
```   255
```
```   256 lemma admissible_disj:
```
```   257   fixes P Q :: "'a \<Rightarrow> bool"
```
```   258   assumes P: "ccpo.admissible Sup (op \<le>) (\<lambda>x. P x)"
```
```   259   assumes Q: "ccpo.admissible Sup (op \<le>) (\<lambda>x. Q x)"
```
```   260   shows "ccpo.admissible Sup (op \<le>) (\<lambda>x. P x \<or> Q x)"
```
```   261 proof (rule ccpo.admissibleI)
```
```   262   fix A :: "'a set" assume A: "chain (op \<le>) A"
```
```   263   assume "A \<noteq> {}"
```
```   264     and "\<forall>x\<in>A. P x \<or> Q x"
```
```   265   hence "(\<exists>x\<in>A. P x) \<and> (\<forall>x\<in>A. \<exists>y\<in>A. x \<le> y \<and> P y) \<or> (\<exists>x\<in>A. Q x) \<and> (\<forall>x\<in>A. \<exists>y\<in>A. x \<le> y \<and> Q y)"
```
```   266     using chainD[OF A] by blast
```
```   267   hence "(\<exists>x. x \<in> A \<and> P x) \<and> Sup A = Sup {x \<in> A. P x} \<or> (\<exists>x. x \<in> A \<and> Q x) \<and> Sup A = Sup {x \<in> A. Q x}"
```
```   268     using admissible_disj_lemma [OF A] by blast
```
```   269   thus "P (Sup A) \<or> Q (Sup A)"
```
```   270     apply (rule disjE, simp_all)
```
```   271     apply (rule disjI1, rule ccpo.admissibleD [OF P chain_compr [OF A]], simp, simp)
```
```   272     apply (rule disjI2, rule ccpo.admissibleD [OF Q chain_compr [OF A]], simp, simp)
```
```   273     done
```
```   274 qed
```
```   275
```
```   276 end
```
```   277
```
```   278 instance complete_lattice \<subseteq> ccpo
```
```   279   by default (fast intro: Sup_upper Sup_least)+
```
```   280
```
```   281 lemma lfp_eq_fixp:
```
```   282   assumes f: "mono f" shows "lfp f = fixp f"
```
```   283 proof (rule antisym)
```
```   284   from f have f': "monotone (op \<le>) (op \<le>) f"
```
```   285     unfolding mono_def monotone_def .
```
```   286   show "lfp f \<le> fixp f"
```
```   287     by (rule lfp_lowerbound, subst fixp_unfold [OF f'], rule order_refl)
```
```   288   show "fixp f \<le> lfp f"
```
```   289     by (rule fixp_lowerbound [OF f'], subst lfp_unfold [OF f], rule order_refl)
```
```   290 qed
```
```   291
```
```   292 hide_const (open) iterates fixp
```
```   293
```
```   294 end
```