author krauss Sat Oct 23 23:39:37 2010 +0200 (2010-10-23) changeset 40106 c58951943cba parent 40105 0d579da1902a child 40107 374f3ef9f940
Complete_Partial_Order.thy: complete partial orders over arbitrary chains, with fixpoint theorem
```     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/HOL/Complete_Partial_Order.thy	Sat Oct 23 23:39:37 2010 +0200
1.3 @@ -0,0 +1,263 @@
1.4 +(* Title:    HOL/Complete_Partial_Order.thy
1.5 +   Author:   Brian Huffman, Portland State University
1.6 +   Author:   Alexander Krauss, TU Muenchen
1.7 +*)
1.8 +
1.9 +header {* Chain-complete partial orders and their fixpoints *}
1.10 +
1.11 +theory Complete_Partial_Order
1.12 +imports Product_Type
1.13 +begin
1.14 +
1.15 +subsection {* Monotone functions *}
1.16 +
1.17 +text {* Dictionary-passing version of @{const Orderings.mono}. *}
1.18 +
1.19 +definition monotone :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> bool"
1.20 +where "monotone orda ordb f \<longleftrightarrow> (\<forall>x y. orda x y \<longrightarrow> ordb (f x) (f y))"
1.21 +
1.22 +lemma monotoneI[intro?]: "(\<And>x y. orda x y \<Longrightarrow> ordb (f x) (f y))
1.23 + \<Longrightarrow> monotone orda ordb f"
1.24 +unfolding monotone_def by iprover
1.25 +
1.26 +lemma monotoneD[dest?]: "monotone orda ordb f \<Longrightarrow> orda x y \<Longrightarrow> ordb (f x) (f y)"
1.27 +unfolding monotone_def by iprover
1.28 +
1.29 +
1.30 +subsection {* Chains *}
1.31 +
1.32 +text {* A chain is a totally-ordered set. Chains are parameterized over
1.33 +  the order for maximal flexibility, since type classes are not enough.
1.34 +*}
1.35 +
1.36 +definition
1.37 +  chain :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> bool"
1.38 +where
1.39 +  "chain ord S \<longleftrightarrow> (\<forall>x\<in>S. \<forall>y\<in>S. ord x y \<or> ord y x)"
1.40 +
1.41 +lemma chainI:
1.42 +  assumes "\<And>x y. x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> ord x y \<or> ord y x"
1.43 +  shows "chain ord S"
1.44 +using assms unfolding chain_def by fast
1.45 +
1.46 +lemma chainD:
1.47 +  assumes "chain ord S" and "x \<in> S" and "y \<in> S"
1.48 +  shows "ord x y \<or> ord y x"
1.49 +using assms unfolding chain_def by fast
1.50 +
1.51 +lemma chainE:
1.52 +  assumes "chain ord S" and "x \<in> S" and "y \<in> S"
1.53 +  obtains "ord x y" | "ord y x"
1.54 +using assms unfolding chain_def by fast
1.55 +
1.56 +subsection {* Chain-complete partial orders *}
1.57 +
1.58 +text {*
1.59 +  A ccpo has a least upper bound for any chain.  In particular, the
1.60 +  empty set is a chain, so every ccpo must have a bottom element.
1.61 +*}
1.62 +
1.63 +class ccpo = order +
1.64 +  fixes lub :: "'a set \<Rightarrow> 'a"
1.65 +  assumes lub_upper: "chain (op \<le>) A \<Longrightarrow> x \<in> A \<Longrightarrow> x \<le> lub A"
1.66 +  assumes lub_least: "chain (op \<le>) A \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> x \<le> z) \<Longrightarrow> lub A \<le> z"
1.67 +begin
1.68 +
1.69 +subsection {* Transfinite iteration of a function *}
1.70 +
1.71 +inductive_set iterates :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a set"
1.72 +for f :: "'a \<Rightarrow> 'a"
1.73 +where
1.74 +  step: "x \<in> iterates f \<Longrightarrow> f x \<in> iterates f"
1.75 +| lub: "chain (op \<le>) M \<Longrightarrow> \<forall>x\<in>M. x \<in> iterates f \<Longrightarrow> lub M \<in> iterates f"
1.76 +
1.77 +lemma iterates_le_f:
1.78 +  "x \<in> iterates f \<Longrightarrow> monotone (op \<le>) (op \<le>) f \<Longrightarrow> x \<le> f x"
1.79 +by (induct x rule: iterates.induct)
1.80 +  (force dest: monotoneD intro!: lub_upper lub_least)+
1.81 +
1.82 +lemma chain_iterates:
1.83 +  assumes f: "monotone (op \<le>) (op \<le>) f"
1.84 +  shows "chain (op \<le>) (iterates f)" (is "chain _ ?C")
1.85 +proof (rule chainI)
1.86 +  fix x y assume "x \<in> ?C" "y \<in> ?C"
1.87 +  then show "x \<le> y \<or> y \<le> x"
1.88 +  proof (induct x arbitrary: y rule: iterates.induct)
1.89 +    fix x y assume y: "y \<in> ?C"
1.90 +    and IH: "\<And>z. z \<in> ?C \<Longrightarrow> x \<le> z \<or> z \<le> x"
1.91 +    from y show "f x \<le> y \<or> y \<le> f x"
1.92 +    proof (induct y rule: iterates.induct)
1.93 +      case (step y) with IH f show ?case by (auto dest: monotoneD)
1.94 +    next
1.95 +      case (lub M)
1.96 +      then have chM: "chain (op \<le>) M"
1.97 +        and IH': "\<And>z. z \<in> M \<Longrightarrow> f x \<le> z \<or> z \<le> f x" by auto
1.98 +      show "f x \<le> lub M \<or> lub M \<le> f x"
1.99 +      proof (cases "\<exists>z\<in>M. f x \<le> z")
1.100 +        case True then have "f x \<le> lub M"
1.101 +          apply rule
1.102 +          apply (erule order_trans)
1.103 +          by (rule lub_upper[OF chM])
1.104 +        thus ?thesis ..
1.105 +      next
1.106 +        case False with IH'
1.107 +        show ?thesis by (auto intro: lub_least[OF chM])
1.108 +      qed
1.109 +    qed
1.110 +  next
1.111 +    case (lub M y)
1.112 +    show ?case
1.113 +    proof (cases "\<exists>x\<in>M. y \<le> x")
1.114 +      case True then have "y \<le> lub M"
1.115 +        apply rule
1.116 +        apply (erule order_trans)
1.117 +        by (rule lub_upper[OF lub(1)])
1.118 +      thus ?thesis ..
1.119 +    next
1.120 +      case False with lub
1.121 +      show ?thesis by (auto intro: lub_least)
1.122 +    qed
1.123 +  qed
1.124 +qed
1.125 +
1.126 +subsection {* Fixpoint combinator *}
1.127 +
1.128 +definition
1.129 +  fixp :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a"
1.130 +where
1.131 +  "fixp f = lub (iterates f)"
1.132 +
1.133 +lemma iterates_fixp:
1.134 +  assumes f: "monotone (op \<le>) (op \<le>) f" shows "fixp f \<in> iterates f"
1.135 +unfolding fixp_def
1.136 +by (simp add: iterates.lub chain_iterates f)
1.137 +
1.138 +lemma fixp_unfold:
1.139 +  assumes f: "monotone (op \<le>) (op \<le>) f"
1.140 +  shows "fixp f = f (fixp f)"
1.141 +proof (rule antisym)
1.142 +  show "fixp f \<le> f (fixp f)"
1.143 +    by (intro iterates_le_f iterates_fixp f)
1.144 +  have "f (fixp f) \<le> lub (iterates f)"
1.145 +    by (intro lub_upper chain_iterates f iterates.step iterates_fixp)
1.146 +  thus "f (fixp f) \<le> fixp f"
1.147 +    unfolding fixp_def .
1.148 +qed
1.149 +
1.150 +lemma fixp_lowerbound:
1.151 +  assumes f: "monotone (op \<le>) (op \<le>) f" and z: "f z \<le> z" shows "fixp f \<le> z"
1.152 +unfolding fixp_def
1.153 +proof (rule lub_least[OF chain_iterates[OF f]])
1.154 +  fix x assume "x \<in> iterates f"
1.155 +  thus "x \<le> z"
1.156 +  proof (induct x rule: iterates.induct)
1.157 +    fix x assume "x \<le> z" with f have "f x \<le> f z" by (rule monotoneD)
1.158 +    also note z finally show "f x \<le> z" .
1.159 +  qed (auto intro: lub_least)
1.160 +qed
1.161 +
1.162 +
1.163 +subsection {* Fixpoint induction *}
1.164 +
1.165 +definition
1.166 +  admissible :: "('a \<Rightarrow> bool) \<Rightarrow> bool"
1.167 +where
1.168 +  "admissible P = (\<forall>A. chain (op \<le>) A \<longrightarrow> (\<forall>x\<in>A. P x) \<longrightarrow> P (lub A))"
1.169 +
1.171 +  assumes "\<And>A. chain (op \<le>) A \<Longrightarrow> \<forall>x\<in>A. P x \<Longrightarrow> P (lub A)"
1.173 +using assms unfolding admissible_def by fast
1.174 +
1.177 +  assumes "chain (op \<le>) A"
1.178 +  assumes "\<And>x. x \<in> A \<Longrightarrow> P x"
1.179 +  shows "P (lub A)"
1.180 +using assms by (auto simp: admissible_def)
1.181 +
1.182 +lemma fixp_induct:
1.184 +  assumes mono: "monotone (op \<le>) (op \<le>) f"
1.185 +  assumes step: "\<And>x. P x \<Longrightarrow> P (f x)"
1.186 +  shows "P (fixp f)"
1.187 +unfolding fixp_def using adm chain_iterates[OF mono]
1.189 +  fix x assume "x \<in> iterates f"
1.190 +  thus "P x"
1.191 +    by (induct rule: iterates.induct)
1.193 +qed
1.194 +
1.197 +
1.199 +unfolding admissible_def chain_def by simp
1.200 +
1.203 +
1.205 +  assumes "admissible (\<lambda>x. P x)"
1.206 +  assumes "admissible (\<lambda>x. Q x)"
1.207 +  shows "admissible (\<lambda>x. P x \<and> Q x)"
1.208 +using assms unfolding admissible_def by simp
1.209 +
1.211 +  assumes "\<And>y. admissible (\<lambda>x. P x y)"
1.212 +  shows "admissible (\<lambda>x. \<forall>y. P x y)"
1.213 +using assms unfolding admissible_def by fast
1.214 +
1.216 +  assumes "\<And>y. y \<in> A \<Longrightarrow> admissible (\<lambda>x. P x y)"
1.217 +  shows "admissible (\<lambda>x. \<forall>y\<in>A. P x y)"
1.218 +using assms unfolding admissible_def by fast
1.219 +
1.220 +lemma chain_compr: "chain (op \<le>) A \<Longrightarrow> chain (op \<le>) {x \<in> A. P x}"
1.221 +unfolding chain_def by fast
1.222 +
1.224 +  assumes A: "chain (op \<le>)A"
1.225 +  assumes P: "\<forall>x\<in>A. \<exists>y\<in>A. x \<le> y \<and> P y"
1.226 +  shows "lub A = lub {x \<in> A. P x}"
1.227 +proof (rule antisym)
1.228 +  have *: "chain (op \<le>) {x \<in> A. P x}"
1.229 +    by (rule chain_compr [OF A])
1.230 +  show "lub A \<le> lub {x \<in> A. P x}"
1.231 +    apply (rule lub_least [OF A])
1.232 +    apply (drule P [rule_format], clarify)
1.233 +    apply (erule order_trans)
1.234 +    apply (simp add: lub_upper [OF *])
1.235 +    done
1.236 +  show "lub {x \<in> A. P x} \<le> lub A"
1.237 +    apply (rule lub_least [OF *])
1.238 +    apply clarify
1.239 +    apply (simp add: lub_upper [OF A])
1.240 +    done
1.241 +qed
1.242 +
1.244 +  fixes P Q :: "'a \<Rightarrow> bool"
1.245 +  assumes P: "admissible (\<lambda>x. P x)"
1.246 +  assumes Q: "admissible (\<lambda>x. Q x)"
1.247 +  shows "admissible (\<lambda>x. P x \<or> Q x)"
1.249 +  fix A :: "'a set" assume A: "chain (op \<le>) A"
1.250 +  assume "\<forall>x\<in>A. P x \<or> Q x"
1.251 +  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)"
1.252 +    using chainD[OF A] by blast
1.253 +  hence "lub A = lub {x \<in> A. P x} \<or> lub A = lub {x \<in> A. Q x}"
1.254 +    using admissible_disj_lemma [OF A] by fast
1.255 +  thus "P (lub A) \<or> Q (lub A)"
1.256 +    apply (rule disjE, simp_all)
1.257 +    apply (rule disjI1, rule admissibleD [OF P chain_compr [OF A]], simp)
1.258 +    apply (rule disjI2, rule admissibleD [OF Q chain_compr [OF A]], simp)
1.259 +    done
1.260 +qed
1.261 +
1.262 +end
1.263 +
1.264 +
1.265 +
1.266 +end
```