src/HOL/FixedPoint.thy
 author huffman Tue Aug 21 20:50:12 2007 +0200 (2007-08-21) changeset 24390 9b5073c79a0b parent 23878 bd651ecd4b8a child 24915 fc90277c0dd7 permissions -rw-r--r--
Isar-style proof for lfp_ordinal_induct
```     1 (*  Title:      HOL/FixedPoint.thy
```
```     2     ID:         \$Id\$
```
```     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
```
```     4     Author:     Stefan Berghofer, TU Muenchen
```
```     5     Copyright   1992  University of Cambridge
```
```     6 *)
```
```     7
```
```     8 header {* Fixed Points and the Knaster-Tarski Theorem*}
```
```     9
```
```    10 theory FixedPoint
```
```    11 imports Lattices
```
```    12 begin
```
```    13
```
```    14 subsection {* Least and greatest fixed points *}
```
```    15
```
```    16 definition
```
```    17   lfp :: "('a\<Colon>complete_lattice \<Rightarrow> 'a) \<Rightarrow> 'a" where
```
```    18   "lfp f = Inf {u. f u \<le> u}"    --{*least fixed point*}
```
```    19
```
```    20 definition
```
```    21   gfp :: "('a\<Colon>complete_lattice \<Rightarrow> 'a) \<Rightarrow> 'a" where
```
```    22   "gfp f = Sup {u. u \<le> f u}"    --{*greatest fixed point*}
```
```    23
```
```    24
```
```    25 subsection{* Proof of Knaster-Tarski Theorem using @{term lfp} *}
```
```    26
```
```    27 text{*@{term "lfp f"} is the least upper bound of
```
```    28       the set @{term "{u. f(u) \<le> u}"} *}
```
```    29
```
```    30 lemma lfp_lowerbound: "f A \<le> A ==> lfp f \<le> A"
```
```    31   by (auto simp add: lfp_def intro: Inf_lower)
```
```    32
```
```    33 lemma lfp_greatest: "(!!u. f u \<le> u ==> A \<le> u) ==> A \<le> lfp f"
```
```    34   by (auto simp add: lfp_def intro: Inf_greatest)
```
```    35
```
```    36 lemma lfp_lemma2: "mono f ==> f (lfp f) \<le> lfp f"
```
```    37   by (iprover intro: lfp_greatest order_trans monoD lfp_lowerbound)
```
```    38
```
```    39 lemma lfp_lemma3: "mono f ==> lfp f \<le> f (lfp f)"
```
```    40   by (iprover intro: lfp_lemma2 monoD lfp_lowerbound)
```
```    41
```
```    42 lemma lfp_unfold: "mono f ==> lfp f = f (lfp f)"
```
```    43   by (iprover intro: order_antisym lfp_lemma2 lfp_lemma3)
```
```    44
```
```    45 lemma lfp_const: "lfp (\<lambda>x. t) = t"
```
```    46   by (rule lfp_unfold) (simp add:mono_def)
```
```    47
```
```    48
```
```    49 subsection {* General induction rules for least fixed points *}
```
```    50
```
```    51 theorem lfp_induct:
```
```    52   assumes mono: "mono f" and ind: "f (inf (lfp f) P) <= P"
```
```    53   shows "lfp f <= P"
```
```    54 proof -
```
```    55   have "inf (lfp f) P <= lfp f" by (rule inf_le1)
```
```    56   with mono have "f (inf (lfp f) P) <= f (lfp f)" ..
```
```    57   also from mono have "f (lfp f) = lfp f" by (rule lfp_unfold [symmetric])
```
```    58   finally have "f (inf (lfp f) P) <= lfp f" .
```
```    59   from this and ind have "f (inf (lfp f) P) <= inf (lfp f) P" by (rule le_infI)
```
```    60   hence "lfp f <= inf (lfp f) P" by (rule lfp_lowerbound)
```
```    61   also have "inf (lfp f) P <= P" by (rule inf_le2)
```
```    62   finally show ?thesis .
```
```    63 qed
```
```    64
```
```    65 lemma lfp_induct_set:
```
```    66   assumes lfp: "a: lfp(f)"
```
```    67       and mono: "mono(f)"
```
```    68       and indhyp: "!!x. [| x: f(lfp(f) Int {x. P(x)}) |] ==> P(x)"
```
```    69   shows "P(a)"
```
```    70   by (rule lfp_induct [THEN subsetD, THEN CollectD, OF mono _ lfp])
```
```    71     (auto simp: inf_set_eq intro: indhyp)
```
```    72
```
```    73 lemma lfp_ordinal_induct:
```
```    74   assumes mono: "mono f"
```
```    75   and P_f: "!!S. P S ==> P(f S)"
```
```    76   and P_Union: "!!M. !S:M. P S ==> P(Union M)"
```
```    77   shows "P(lfp f)"
```
```    78 proof -
```
```    79   let ?M = "{S. S \<subseteq> lfp f & P S}"
```
```    80   have "P (Union ?M)" using P_Union by simp
```
```    81   also have "Union ?M = lfp f"
```
```    82   proof
```
```    83     show "Union ?M \<subseteq> lfp f" by blast
```
```    84     hence "f (Union ?M) \<subseteq> f (lfp f)" by (rule mono [THEN monoD])
```
```    85     hence "f (Union ?M) \<subseteq> lfp f" using mono [THEN lfp_unfold] by simp
```
```    86     hence "f (Union ?M) \<in> ?M" using P_f P_Union by simp
```
```    87     hence "f (Union ?M) \<subseteq> Union ?M" by (rule Union_upper)
```
```    88     thus "lfp f \<subseteq> Union ?M" by (rule lfp_lowerbound)
```
```    89   qed
```
```    90   finally show ?thesis .
```
```    91 qed
```
```    92
```
```    93
```
```    94 text{*Definition forms of @{text lfp_unfold} and @{text lfp_induct},
```
```    95     to control unfolding*}
```
```    96
```
```    97 lemma def_lfp_unfold: "[| h==lfp(f);  mono(f) |] ==> h = f(h)"
```
```    98 by (auto intro!: lfp_unfold)
```
```    99
```
```   100 lemma def_lfp_induct:
```
```   101     "[| A == lfp(f); mono(f);
```
```   102         f (inf A P) \<le> P
```
```   103      |] ==> A \<le> P"
```
```   104   by (blast intro: lfp_induct)
```
```   105
```
```   106 lemma def_lfp_induct_set:
```
```   107     "[| A == lfp(f);  mono(f);   a:A;
```
```   108         !!x. [| x: f(A Int {x. P(x)}) |] ==> P(x)
```
```   109      |] ==> P(a)"
```
```   110   by (blast intro: lfp_induct_set)
```
```   111
```
```   112 (*Monotonicity of lfp!*)
```
```   113 lemma lfp_mono: "(!!Z. f Z \<le> g Z) ==> lfp f \<le> lfp g"
```
```   114   by (rule lfp_lowerbound [THEN lfp_greatest], blast intro: order_trans)
```
```   115
```
```   116
```
```   117 subsection {* Proof of Knaster-Tarski Theorem using @{term gfp} *}
```
```   118
```
```   119 text{*@{term "gfp f"} is the greatest lower bound of
```
```   120       the set @{term "{u. u \<le> f(u)}"} *}
```
```   121
```
```   122 lemma gfp_upperbound: "X \<le> f X ==> X \<le> gfp f"
```
```   123   by (auto simp add: gfp_def intro: Sup_upper)
```
```   124
```
```   125 lemma gfp_least: "(!!u. u \<le> f u ==> u \<le> X) ==> gfp f \<le> X"
```
```   126   by (auto simp add: gfp_def intro: Sup_least)
```
```   127
```
```   128 lemma gfp_lemma2: "mono f ==> gfp f \<le> f (gfp f)"
```
```   129   by (iprover intro: gfp_least order_trans monoD gfp_upperbound)
```
```   130
```
```   131 lemma gfp_lemma3: "mono f ==> f (gfp f) \<le> gfp f"
```
```   132   by (iprover intro: gfp_lemma2 monoD gfp_upperbound)
```
```   133
```
```   134 lemma gfp_unfold: "mono f ==> gfp f = f (gfp f)"
```
```   135   by (iprover intro: order_antisym gfp_lemma2 gfp_lemma3)
```
```   136
```
```   137
```
```   138 subsection {* Coinduction rules for greatest fixed points *}
```
```   139
```
```   140 text{*weak version*}
```
```   141 lemma weak_coinduct: "[| a: X;  X \<subseteq> f(X) |] ==> a : gfp(f)"
```
```   142 by (rule gfp_upperbound [THEN subsetD], auto)
```
```   143
```
```   144 lemma weak_coinduct_image: "!!X. [| a : X; g`X \<subseteq> f (g`X) |] ==> g a : gfp f"
```
```   145 apply (erule gfp_upperbound [THEN subsetD])
```
```   146 apply (erule imageI)
```
```   147 done
```
```   148
```
```   149 lemma coinduct_lemma:
```
```   150      "[| X \<le> f (sup X (gfp f));  mono f |] ==> sup X (gfp f) \<le> f (sup X (gfp f))"
```
```   151   apply (frule gfp_lemma2)
```
```   152   apply (drule mono_sup)
```
```   153   apply (rule le_supI)
```
```   154   apply assumption
```
```   155   apply (rule order_trans)
```
```   156   apply (rule order_trans)
```
```   157   apply assumption
```
```   158   apply (rule sup_ge2)
```
```   159   apply assumption
```
```   160   done
```
```   161
```
```   162 text{*strong version, thanks to Coen and Frost*}
```
```   163 lemma coinduct_set: "[| mono(f);  a: X;  X \<subseteq> f(X Un gfp(f)) |] ==> a : gfp(f)"
```
```   164 by (blast intro: weak_coinduct [OF _ coinduct_lemma, simplified sup_set_eq])
```
```   165
```
```   166 lemma coinduct: "[| mono(f); X \<le> f (sup X (gfp f)) |] ==> X \<le> gfp(f)"
```
```   167   apply (rule order_trans)
```
```   168   apply (rule sup_ge1)
```
```   169   apply (erule gfp_upperbound [OF coinduct_lemma])
```
```   170   apply assumption
```
```   171   done
```
```   172
```
```   173 lemma gfp_fun_UnI2: "[| mono(f);  a: gfp(f) |] ==> a: f(X Un gfp(f))"
```
```   174 by (blast dest: gfp_lemma2 mono_Un)
```
```   175
```
```   176
```
```   177 subsection {* Even Stronger Coinduction Rule, by Martin Coen *}
```
```   178
```
```   179 text{* Weakens the condition @{term "X \<subseteq> f(X)"} to one expressed using both
```
```   180   @{term lfp} and @{term gfp}*}
```
```   181
```
```   182 lemma coinduct3_mono_lemma: "mono(f) ==> mono(%x. f(x) Un X Un B)"
```
```   183 by (iprover intro: subset_refl monoI Un_mono monoD)
```
```   184
```
```   185 lemma coinduct3_lemma:
```
```   186      "[| X \<subseteq> f(lfp(%x. f(x) Un X Un gfp(f)));  mono(f) |]
```
```   187       ==> lfp(%x. f(x) Un X Un gfp(f)) \<subseteq> f(lfp(%x. f(x) Un X Un gfp(f)))"
```
```   188 apply (rule subset_trans)
```
```   189 apply (erule coinduct3_mono_lemma [THEN lfp_lemma3])
```
```   190 apply (rule Un_least [THEN Un_least])
```
```   191 apply (rule subset_refl, assumption)
```
```   192 apply (rule gfp_unfold [THEN equalityD1, THEN subset_trans], assumption)
```
```   193 apply (rule monoD, assumption)
```
```   194 apply (subst coinduct3_mono_lemma [THEN lfp_unfold], auto)
```
```   195 done
```
```   196
```
```   197 lemma coinduct3:
```
```   198   "[| mono(f);  a:X;  X \<subseteq> f(lfp(%x. f(x) Un X Un gfp(f))) |] ==> a : gfp(f)"
```
```   199 apply (rule coinduct3_lemma [THEN  weak_coinduct])
```
```   200 apply (rule coinduct3_mono_lemma [THEN lfp_unfold, THEN ssubst], auto)
```
```   201 done
```
```   202
```
```   203
```
```   204 text{*Definition forms of @{text gfp_unfold} and @{text coinduct},
```
```   205     to control unfolding*}
```
```   206
```
```   207 lemma def_gfp_unfold: "[| A==gfp(f);  mono(f) |] ==> A = f(A)"
```
```   208 by (auto intro!: gfp_unfold)
```
```   209
```
```   210 lemma def_coinduct:
```
```   211      "[| A==gfp(f);  mono(f);  X \<le> f(sup X A) |] ==> X \<le> A"
```
```   212 by (iprover intro!: coinduct)
```
```   213
```
```   214 lemma def_coinduct_set:
```
```   215      "[| A==gfp(f);  mono(f);  a:X;  X \<subseteq> f(X Un A) |] ==> a: A"
```
```   216 by (auto intro!: coinduct_set)
```
```   217
```
```   218 (*The version used in the induction/coinduction package*)
```
```   219 lemma def_Collect_coinduct:
```
```   220     "[| A == gfp(%w. Collect(P(w)));  mono(%w. Collect(P(w)));
```
```   221         a: X;  !!z. z: X ==> P (X Un A) z |] ==>
```
```   222      a : A"
```
```   223 apply (erule def_coinduct_set, auto)
```
```   224 done
```
```   225
```
```   226 lemma def_coinduct3:
```
```   227     "[| A==gfp(f); mono(f);  a:X;  X \<subseteq> f(lfp(%x. f(x) Un X Un A)) |] ==> a: A"
```
```   228 by (auto intro!: coinduct3)
```
```   229
```
```   230 text{*Monotonicity of @{term gfp}!*}
```
```   231 lemma gfp_mono: "(!!Z. f Z \<le> g Z) ==> gfp f \<le> gfp g"
```
```   232   by (rule gfp_upperbound [THEN gfp_least], blast intro: order_trans)
```
```   233
```
```   234 ML
```
```   235 {*
```
```   236 val lfp_def = thm "lfp_def";
```
```   237 val lfp_lowerbound = thm "lfp_lowerbound";
```
```   238 val lfp_greatest = thm "lfp_greatest";
```
```   239 val lfp_unfold = thm "lfp_unfold";
```
```   240 val lfp_induct = thm "lfp_induct";
```
```   241 val lfp_ordinal_induct = thm "lfp_ordinal_induct";
```
```   242 val def_lfp_unfold = thm "def_lfp_unfold";
```
```   243 val def_lfp_induct = thm "def_lfp_induct";
```
```   244 val def_lfp_induct_set = thm "def_lfp_induct_set";
```
```   245 val lfp_mono = thm "lfp_mono";
```
```   246 val gfp_def = thm "gfp_def";
```
```   247 val gfp_upperbound = thm "gfp_upperbound";
```
```   248 val gfp_least = thm "gfp_least";
```
```   249 val gfp_unfold = thm "gfp_unfold";
```
```   250 val weak_coinduct = thm "weak_coinduct";
```
```   251 val weak_coinduct_image = thm "weak_coinduct_image";
```
```   252 val coinduct = thm "coinduct";
```
```   253 val gfp_fun_UnI2 = thm "gfp_fun_UnI2";
```
```   254 val coinduct3 = thm "coinduct3";
```
```   255 val def_gfp_unfold = thm "def_gfp_unfold";
```
```   256 val def_coinduct = thm "def_coinduct";
```
```   257 val def_Collect_coinduct = thm "def_Collect_coinduct";
```
```   258 val def_coinduct3 = thm "def_coinduct3";
```
```   259 val gfp_mono = thm "gfp_mono";
```
```   260 val le_funI = thm "le_funI";
```
```   261 val le_boolI = thm "le_boolI";
```
```   262 val le_boolI' = thm "le_boolI'";
```
```   263 val inf_fun_eq = thm "inf_fun_eq";
```
```   264 val inf_bool_eq = thm "inf_bool_eq";
```
```   265 val le_funE = thm "le_funE";
```
```   266 val le_funD = thm "le_funD";
```
```   267 val le_boolE = thm "le_boolE";
```
```   268 val le_boolD = thm "le_boolD";
```
```   269 val le_bool_def = thm "le_bool_def";
```
```   270 val le_fun_def = thm "le_fun_def";
```
```   271 *}
```
```   272
```
```   273 end
```