src/HOL/Library/Bourbaki_Witt_Fixpoint.thy
changeset 61766 507b39df1a57
child 62058 1cfd5d604937
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Library/Bourbaki_Witt_Fixpoint.thy	Tue Dec 01 12:35:11 2015 +0100
     1.3 @@ -0,0 +1,252 @@
     1.4 +(* Title: Bourbaki_Witt_Fixpoint.thy
     1.5 +   Author: Andreas Lochbihler, ETH Zurich *)
     1.6 +
     1.7 +section \<open>The Bourbaki-Witt tower construction for transfinite iteration\<close>
     1.8 +
     1.9 +theory Bourbaki_Witt_Fixpoint imports Main begin
    1.10 +
    1.11 +lemma ChainsI [intro?]:
    1.12 +  "(\<And>a b. \<lbrakk> a \<in> Y; b \<in> Y \<rbrakk> \<Longrightarrow> (a, b) \<in> r \<or> (b, a) \<in> r) \<Longrightarrow> Y \<in> Chains r"
    1.13 +unfolding Chains_def by blast
    1.14 +
    1.15 +lemma in_Chains_subset: "\<lbrakk> M \<in> Chains r; M' \<subseteq> M \<rbrakk> \<Longrightarrow> M' \<in> Chains r"
    1.16 +by(auto simp add: Chains_def)
    1.17 +
    1.18 +lemma FieldI1: "(i, j) \<in> R \<Longrightarrow> i \<in> Field R"
    1.19 +  unfolding Field_def by auto
    1.20 +
    1.21 +lemma Chains_FieldD: "\<lbrakk> M \<in> Chains r; x \<in> M \<rbrakk> \<Longrightarrow> x \<in> Field r"
    1.22 +by(auto simp add: Chains_def intro: FieldI1 FieldI2)
    1.23 +
    1.24 +lemma partial_order_on_trans:
    1.25 +  "\<lbrakk> partial_order_on A r; (x, y) \<in> r; (y, z) \<in> r \<rbrakk> \<Longrightarrow> (x, z) \<in> r"
    1.26 +by(auto simp add: order_on_defs dest: transD)
    1.27 +
    1.28 +locale bourbaki_witt_fixpoint =
    1.29 +  fixes lub :: "'a set \<Rightarrow> 'a"
    1.30 +  and leq :: "('a \<times> 'a) set"
    1.31 +  and f :: "'a \<Rightarrow> 'a"
    1.32 +  assumes po: "Partial_order leq"
    1.33 +  and lub_least: "\<lbrakk> M \<in> Chains leq; M \<noteq> {}; \<And>x. x \<in> M \<Longrightarrow> (x, z) \<in> leq \<rbrakk> \<Longrightarrow> (lub M, z) \<in> leq"
    1.34 +  and lub_upper: "\<lbrakk> M \<in> Chains leq; x \<in> M \<rbrakk> \<Longrightarrow> (x, lub M) \<in> leq"
    1.35 +  and lub_in_Field: "\<lbrakk> M \<in> Chains leq; M \<noteq> {} \<rbrakk> \<Longrightarrow> lub M \<in> Field leq"
    1.36 +  and increasing: "\<And>x. x \<in> Field leq \<Longrightarrow> (x, f x) \<in> leq"
    1.37 +begin
    1.38 +
    1.39 +lemma leq_trans: "\<lbrakk> (x, y) \<in> leq; (y, z) \<in> leq \<rbrakk> \<Longrightarrow> (x, z) \<in> leq"
    1.40 +by(rule partial_order_on_trans[OF po])
    1.41 +
    1.42 +lemma leq_refl: "x \<in> Field leq \<Longrightarrow> (x, x) \<in> leq"
    1.43 +using po by(simp add: order_on_defs refl_on_def)
    1.44 +
    1.45 +lemma leq_antisym: "\<lbrakk> (x, y) \<in> leq; (y, x) \<in> leq \<rbrakk> \<Longrightarrow> x = y"
    1.46 +using po by(simp add: order_on_defs antisym_def)
    1.47 +
    1.48 +inductive_set iterates_above :: "'a \<Rightarrow> 'a set"
    1.49 +  for a
    1.50 +where
    1.51 +  base: "a \<in> iterates_above a"
    1.52 +| step: "x \<in> iterates_above a \<Longrightarrow> f x \<in> iterates_above a"
    1.53 +| Sup: "\<lbrakk> M \<in> Chains leq; M \<noteq> {}; \<And>x. x \<in> M \<Longrightarrow> x \<in> iterates_above a \<rbrakk> \<Longrightarrow> lub M \<in> iterates_above a"
    1.54 +
    1.55 +definition fixp_above :: "'a \<Rightarrow> 'a"
    1.56 +where "fixp_above a = lub (iterates_above a)"
    1.57 +
    1.58 +context 
    1.59 +  notes leq_refl [intro!, simp]
    1.60 +  and base [intro]
    1.61 +  and step [intro]
    1.62 +  and Sup [intro]
    1.63 +  and leq_trans [trans]
    1.64 +begin
    1.65 +
    1.66 +lemma iterates_above_le_f: "\<lbrakk> x \<in> iterates_above a; a \<in> Field leq \<rbrakk> \<Longrightarrow> (x, f x) \<in> leq"
    1.67 +by(induction x rule: iterates_above.induct)(blast intro: increasing FieldI2 lub_in_Field)+
    1.68 +
    1.69 +lemma iterates_above_Field: "\<lbrakk> x \<in> iterates_above a; a \<in> Field leq \<rbrakk> \<Longrightarrow> x \<in> Field leq"
    1.70 +by(drule (1) iterates_above_le_f)(rule FieldI1)
    1.71 +
    1.72 +lemma iterates_above_ge:
    1.73 +  assumes y: "y \<in> iterates_above a"
    1.74 +  and a: "a \<in> Field leq"
    1.75 +  shows "(a, y) \<in> leq"
    1.76 +using y by(induction)(auto intro: a increasing iterates_above_le_f leq_trans leq_trans[OF _ lub_upper])
    1.77 +
    1.78 +lemma iterates_above_lub:
    1.79 +  assumes M: "M \<in> Chains leq"
    1.80 +  and nempty: "M \<noteq> {}"
    1.81 +  and upper: "\<And>y. y \<in> M \<Longrightarrow> \<exists>z \<in> M. (y, z) \<in> leq \<and> z \<in> iterates_above a"
    1.82 +  shows "lub M \<in> iterates_above a"
    1.83 +proof -
    1.84 +  let ?M = "M \<inter> iterates_above a"
    1.85 +  from M have M': "?M \<in> Chains leq" by(rule in_Chains_subset)simp
    1.86 +  have "?M \<noteq> {}" using nempty by(auto dest: upper)
    1.87 +  with M' have "lub ?M \<in> iterates_above a" by(rule Sup) blast
    1.88 +  also have "lub ?M = lub M" using nempty
    1.89 +    by(intro leq_antisym)(blast intro!: lub_least[OF M] lub_least[OF M'] intro: lub_upper[OF M'] lub_upper[OF M] leq_trans dest: upper)+
    1.90 +  finally show ?thesis .
    1.91 +qed
    1.92 +
    1.93 +lemma iterates_above_successor:
    1.94 +  assumes y: "y \<in> iterates_above a"
    1.95 +  and a: "a \<in> Field leq"
    1.96 +  shows "y = a \<or> y \<in> iterates_above (f a)"
    1.97 +using y
    1.98 +proof induction
    1.99 +  case base thus ?case by simp
   1.100 +next
   1.101 +  case (step x) thus ?case by auto
   1.102 +next
   1.103 +  case (Sup M)
   1.104 +  show ?case
   1.105 +  proof(cases "\<exists>x. M \<subseteq> {x}")
   1.106 +    case True
   1.107 +    with \<open>M \<noteq> {}\<close> obtain y where M: "M = {y}" by auto
   1.108 +    have "lub M = y"
   1.109 +      by(rule leq_antisym)(auto intro!: lub_upper Sup lub_least ChainsI simp add: a M Sup.hyps(3)[of y, THEN iterates_above_Field] dest: iterates_above_Field)
   1.110 +    with Sup.IH[of y] M show ?thesis by simp
   1.111 +  next
   1.112 +    case False
   1.113 +    from Sup(1-2) have "lub M \<in> iterates_above (f a)"
   1.114 +    proof(rule iterates_above_lub)
   1.115 +      fix y
   1.116 +      assume y: "y \<in> M"
   1.117 +      from Sup.IH[OF this] show "\<exists>z\<in>M. (y, z) \<in> leq \<and> z \<in> iterates_above (f a)"
   1.118 +      proof
   1.119 +        assume "y = a"
   1.120 +        from y False obtain z where z: "z \<in> M" and neq: "y \<noteq> z" by (metis insertI1 subsetI)
   1.121 +        with Sup.IH[OF z] \<open>y = a\<close> Sup.hyps(3)[OF z]
   1.122 +        show ?thesis by(auto dest: iterates_above_ge intro: a)
   1.123 +      next
   1.124 +        assume "y \<in> iterates_above (f a)"
   1.125 +        moreover with increasing[OF a] have "y \<in> Field leq"
   1.126 +          by(auto dest!: iterates_above_Field intro: FieldI2)
   1.127 +        ultimately show ?thesis using y by(auto)
   1.128 +      qed
   1.129 +    qed
   1.130 +    thus ?thesis by simp
   1.131 +  qed
   1.132 +qed
   1.133 +
   1.134 +lemma iterates_above_Sup_aux:
   1.135 +  assumes M: "M \<in> Chains leq" "M \<noteq> {}"
   1.136 +  and M': "M' \<in> Chains leq" "M' \<noteq> {}"
   1.137 +  and comp: "\<And>x. x \<in> M \<Longrightarrow> x \<in> iterates_above (lub M') \<or> lub M' \<in> iterates_above x"
   1.138 +  shows "(lub M, lub M') \<in> leq \<or> lub M \<in> iterates_above (lub M')"
   1.139 +proof(cases "\<exists>x \<in> M. x \<in> iterates_above (lub M')")
   1.140 +  case True
   1.141 +  then obtain x where x: "x \<in> M" "x \<in> iterates_above (lub M')" by blast
   1.142 +  have lub_M': "lub M' \<in> Field leq" using M' by(rule lub_in_Field)
   1.143 +  have "lub M \<in> iterates_above (lub M')" using M
   1.144 +  proof(rule iterates_above_lub)
   1.145 +    fix y
   1.146 +    assume y: "y \<in> M"
   1.147 +    from comp[OF y] show "\<exists>z\<in>M. (y, z) \<in> leq \<and> z \<in> iterates_above (lub M')"
   1.148 +    proof
   1.149 +      assume "y \<in> iterates_above (lub M')"
   1.150 +      from this iterates_above_Field[OF this] y lub_M' show ?thesis by blast
   1.151 +    next
   1.152 +      assume "lub M' \<in> iterates_above y"
   1.153 +      hence "(y, lub M') \<in> leq" using Chains_FieldD[OF M(1) y] by(rule iterates_above_ge)
   1.154 +      also have "(lub M', x) \<in> leq" using x(2) lub_M' by(rule iterates_above_ge)
   1.155 +      finally show ?thesis using x by blast
   1.156 +    qed
   1.157 +  qed
   1.158 +  thus ?thesis ..
   1.159 +next
   1.160 +  case False
   1.161 +  have "(lub M, lub M') \<in> leq" using M
   1.162 +  proof(rule lub_least)
   1.163 +    fix x
   1.164 +    assume x: "x \<in> M"
   1.165 +    from comp[OF x] x False have "lub M' \<in> iterates_above x" by auto
   1.166 +    moreover from M(1) x have "x \<in> Field leq" by(rule Chains_FieldD)
   1.167 +    ultimately show "(x, lub M') \<in> leq" by(rule iterates_above_ge)
   1.168 +  qed
   1.169 +  thus ?thesis ..
   1.170 +qed
   1.171 +
   1.172 +lemma iterates_above_triangle:
   1.173 +  assumes x: "x \<in> iterates_above a"
   1.174 +  and y: "y \<in> iterates_above a"
   1.175 +  and a: "a \<in> Field leq"
   1.176 +  shows "x \<in> iterates_above y \<or> y \<in> iterates_above x"
   1.177 +using x y
   1.178 +proof(induction arbitrary: y)
   1.179 +  case base then show ?case by simp
   1.180 +next
   1.181 +  case (step x) thus ?case using a
   1.182 +    by(auto dest: iterates_above_successor intro: iterates_above_Field)
   1.183 +next
   1.184 +  case x: (Sup M)
   1.185 +  hence lub: "lub M \<in> iterates_above a" by blast
   1.186 +  from \<open>y \<in> iterates_above a\<close> show ?case
   1.187 +  proof(induction)
   1.188 +    case base show ?case using lub by simp
   1.189 +  next
   1.190 +    case (step y) thus ?case using a
   1.191 +      by(auto dest: iterates_above_successor intro: iterates_above_Field)
   1.192 +  next
   1.193 +    case y: (Sup M')
   1.194 +    hence lub': "lub M' \<in> iterates_above a" by blast
   1.195 +    have *: "x \<in> iterates_above (lub M') \<or> lub M' \<in> iterates_above x" if "x \<in> M" for x
   1.196 +      using that lub' by(rule x.IH)
   1.197 +    with x(1-2) y(1-2) have "(lub M, lub M') \<in> leq \<or> lub M \<in> iterates_above (lub M')"
   1.198 +      by(rule iterates_above_Sup_aux)
   1.199 +    moreover from y(1-2) x(1-2) have "(lub M', lub M) \<in> leq \<or> lub M' \<in> iterates_above (lub M)"
   1.200 +      by(rule iterates_above_Sup_aux)(blast dest: y.IH)
   1.201 +    ultimately show ?case by(auto 4 3 dest: leq_antisym)
   1.202 +  qed
   1.203 +qed
   1.204 +
   1.205 +lemma chain_iterates_above: 
   1.206 +  assumes a: "a \<in> Field leq"
   1.207 +  shows "iterates_above a \<in> Chains leq" (is "?C \<in> _")
   1.208 +proof (rule ChainsI)
   1.209 +  fix x y
   1.210 +  assume "x \<in> ?C" "y \<in> ?C"
   1.211 +  hence "x \<in> iterates_above y \<or> y \<in> iterates_above x" using a by(rule iterates_above_triangle)
   1.212 +  moreover from \<open>x \<in> ?C\<close> a have "x \<in> Field leq" by(rule iterates_above_Field)
   1.213 +  moreover from \<open>y \<in> ?C\<close> a have "y \<in> Field leq" by(rule iterates_above_Field)
   1.214 +  ultimately show "(x, y) \<in> leq \<or> (y, x) \<in> leq" by(auto dest: iterates_above_ge)
   1.215 +qed
   1.216 +
   1.217 +lemma fixp_iterates_above: "a \<in> Field leq \<Longrightarrow> fixp_above a \<in> iterates_above a"
   1.218 +unfolding fixp_above_def by(rule iterates_above.Sup)(blast intro: chain_iterates_above)+
   1.219 +
   1.220 +lemma
   1.221 +  assumes b: "b \<in> iterates_above a"
   1.222 +  and fb: "f b = b"
   1.223 +  and x: "x \<in> iterates_above a"
   1.224 +  and a: "a \<in> Field leq"
   1.225 +  shows "b \<in> iterates_above x"
   1.226 +using x
   1.227 +proof(induction)
   1.228 +  case base show ?case using b by simp
   1.229 +next
   1.230 +  case (step x)
   1.231 +  from step.hyps a have "x \<in> Field leq" by(rule iterates_above_Field)
   1.232 +  from iterates_above_successor[OF step.IH this] fb
   1.233 +  show ?case by(auto)
   1.234 +next
   1.235 +  case (Sup M)
   1.236 +  oops
   1.237 +
   1.238 +lemma fixp_above_Field: "a \<in> Field leq \<Longrightarrow> fixp_above a \<in> Field leq"
   1.239 +using fixp_iterates_above by(rule iterates_above_Field)
   1.240 +
   1.241 +lemma fixp_above_unfold:
   1.242 +  assumes a: "a \<in> Field leq"
   1.243 +  shows "fixp_above a = f (fixp_above a)" (is "?a = f ?a")
   1.244 +proof(rule leq_antisym)
   1.245 +  show "(?a, f ?a) \<in> leq" using fixp_above_Field[OF a] by(rule increasing)
   1.246 +  
   1.247 +  have "f ?a \<in> iterates_above a" using fixp_iterates_above[OF a] by(rule iterates_above.step)
   1.248 +  with chain_iterates_above[OF a] show "(f ?a, ?a) \<in> leq" unfolding fixp_above_def by(rule lub_upper)
   1.249 +qed
   1.250 +
   1.251 +end
   1.252 +
   1.253 +end
   1.254 +
   1.255 +end
   1.256 \ No newline at end of file