src/HOL/FixedPoint.thy
 author krauss Fri Nov 24 13:44:51 2006 +0100 (2006-11-24) changeset 21512 3786eb1b69d6 parent 21404 eb85850d3eb7 child 21547 9c9fdf4c2949 permissions -rw-r--r--
Lemma "fundef_default_value" uses predicate instead of set.
```     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 Product_Type LOrder
```
```    12 begin
```
```    13
```
```    14 subsection {* Complete lattices *}
```
```    15 (*FIXME Meet \<rightarrow> Inf *)
```
```    16 consts
```
```    17   Meet :: "'a::order set \<Rightarrow> 'a"
```
```    18   Sup :: "'a::order set \<Rightarrow> 'a"
```
```    19
```
```    20 defs Sup_def: "Sup A == Meet {b. \<forall>a \<in> A. a <= b}"
```
```    21
```
```    22 definition
```
```    23   SUP :: "('a \<Rightarrow> 'b::order) \<Rightarrow> 'b"  (binder "SUP " 10) where
```
```    24   "SUP x. f x == Sup (f ` UNIV)"
```
```    25
```
```    26 (*
```
```    27 abbreviation
```
```    28   bot :: "'a::order" where
```
```    29   "bot == Sup {}"
```
```    30 *)
```
```    31 axclass comp_lat < order
```
```    32   Meet_lower: "x \<in> A \<Longrightarrow> Meet A <= x"
```
```    33   Meet_greatest: "(\<And>x. x \<in> A \<Longrightarrow> z <= x) \<Longrightarrow> z <= Meet A"
```
```    34
```
```    35 theorem Sup_upper: "(x::'a::comp_lat) \<in> A \<Longrightarrow> x <= Sup A"
```
```    36   by (auto simp: Sup_def intro: Meet_greatest)
```
```    37
```
```    38 theorem Sup_least: "(\<And>x::'a::comp_lat. x \<in> A \<Longrightarrow> x <= z) \<Longrightarrow> Sup A <= z"
```
```    39   by (auto simp: Sup_def intro: Meet_lower)
```
```    40
```
```    41 text {* A complete lattice is a lattice *}
```
```    42
```
```    43 lemma is_meet_Meet: "is_meet (\<lambda>(x::'a::comp_lat) y. Meet {x, y})"
```
```    44   by (auto simp: is_meet_def intro: Meet_lower Meet_greatest)
```
```    45
```
```    46 lemma is_join_Sup: "is_join (\<lambda>(x::'a::comp_lat) y. Sup {x, y})"
```
```    47   by (auto simp: is_join_def intro: Sup_upper Sup_least)
```
```    48
```
```    49 instance comp_lat < lorder
```
```    50 proof
```
```    51   from is_meet_Meet show "\<exists>m::'a\<Rightarrow>'a\<Rightarrow>'a. is_meet m" by iprover
```
```    52   from is_join_Sup show "\<exists>j::'a\<Rightarrow>'a\<Rightarrow>'a. is_join j" by iprover
```
```    53 qed
```
```    54
```
```    55 subsubsection {* Properties *}
```
```    56
```
```    57 lemma mono_join: "mono f \<Longrightarrow> join (f A) (f B) <= f (join A B)"
```
```    58   by (auto simp add: mono_def)
```
```    59
```
```    60 lemma mono_meet: "mono f \<Longrightarrow> f (meet A B) <= meet (f A) (f B)"
```
```    61   by (auto simp add: mono_def)
```
```    62
```
```    63 lemma Sup_insert[simp]: "Sup (insert (a::'a::comp_lat) A) = join a (Sup A)"
```
```    64 apply(simp add:Sup_def)
```
```    65 apply(rule order_antisym)
```
```    66  apply(rule Meet_lower)
```
```    67  apply(clarsimp)
```
```    68  apply(rule le_joinI2)
```
```    69  apply(rule Meet_greatest)
```
```    70  apply blast
```
```    71 apply simp
```
```    72 apply rule
```
```    73  apply(rule Meet_greatest)apply blast
```
```    74 apply(rule Meet_greatest)
```
```    75 apply(rule Meet_lower)
```
```    76 apply blast
```
```    77 done
```
```    78
```
```    79 lemma bot_least[simp]: "Sup{} \<le> (x::'a::comp_lat)"
```
```    80 apply(simp add: Sup_def)
```
```    81 apply(rule Meet_lower)
```
```    82 apply blast
```
```    83 done
```
```    84 (*
```
```    85 lemma Meet_singleton[simp]: "Meet{a} = (a::'a::comp_lat)"
```
```    86 apply(rule order_antisym)
```
```    87  apply(simp add: Meet_lower)
```
```    88 apply(rule Meet_greatest)
```
```    89 apply(simp)
```
```    90 done
```
```    91 *)
```
```    92 lemma le_SupI: "(l::'a::comp_lat) : M \<Longrightarrow> l \<le> Sup M"
```
```    93 apply(simp add:Sup_def)
```
```    94 apply(rule Meet_greatest)
```
```    95 apply(simp)
```
```    96 done
```
```    97
```
```    98 lemma le_SUPI: "(l::'a::comp_lat) = M i \<Longrightarrow> l \<le> (SUP i. M i)"
```
```    99 apply(simp add:SUP_def)
```
```   100 apply(blast intro:le_SupI)
```
```   101 done
```
```   102
```
```   103 lemma Sup_leI: "(!!x. x:M \<Longrightarrow> x \<le> u) \<Longrightarrow> Sup M \<le> (u::'a::comp_lat)"
```
```   104 apply(simp add:Sup_def)
```
```   105 apply(rule Meet_lower)
```
```   106 apply(blast)
```
```   107 done
```
```   108
```
```   109
```
```   110 lemma SUP_leI: "(!!i. M i \<le> u) \<Longrightarrow> (SUP i. M i) \<le> (u::'a::comp_lat)"
```
```   111 apply(simp add:SUP_def)
```
```   112 apply(blast intro!:Sup_leI)
```
```   113 done
```
```   114
```
```   115 lemma SUP_const[simp]: "(SUP i. M) = (M::'a::comp_lat)"
```
```   116 by(simp add:SUP_def image_constant_conv join_absorp1)
```
```   117
```
```   118
```
```   119 subsection {* Some instances of the type class of complete lattices *}
```
```   120
```
```   121 subsubsection {* Booleans *}
```
```   122
```
```   123 instance bool :: ord ..
```
```   124
```
```   125 defs
```
```   126   le_bool_def: "P <= Q == P \<longrightarrow> Q"
```
```   127   less_bool_def: "P < Q == (P::bool) <= Q \<and> P \<noteq> Q"
```
```   128
```
```   129 theorem le_boolI: "(P \<Longrightarrow> Q) \<Longrightarrow> P <= Q"
```
```   130   by (simp add: le_bool_def)
```
```   131
```
```   132 theorem le_boolI': "P \<longrightarrow> Q \<Longrightarrow> P <= Q"
```
```   133   by (simp add: le_bool_def)
```
```   134
```
```   135 theorem le_boolE: "P <= Q \<Longrightarrow> P \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
```
```   136   by (simp add: le_bool_def)
```
```   137
```
```   138 theorem le_boolD: "P <= Q \<Longrightarrow> P \<longrightarrow> Q"
```
```   139   by (simp add: le_bool_def)
```
```   140
```
```   141 instance bool :: order
```
```   142   apply intro_classes
```
```   143   apply (unfold le_bool_def less_bool_def)
```
```   144   apply iprover+
```
```   145   done
```
```   146
```
```   147 defs Meet_bool_def: "Meet A == ALL x:A. x"
```
```   148
```
```   149 instance bool :: comp_lat
```
```   150   apply intro_classes
```
```   151   apply (unfold Meet_bool_def)
```
```   152   apply (iprover intro!: le_boolI elim: ballE)
```
```   153   apply (iprover intro!: ballI le_boolI elim: ballE le_boolE)
```
```   154   done
```
```   155
```
```   156 theorem meet_bool_eq: "meet P Q = (P \<and> Q)"
```
```   157   apply (rule order_antisym)
```
```   158   apply (rule le_boolI)
```
```   159   apply (rule conjI)
```
```   160   apply (rule le_boolE)
```
```   161   apply (rule meet_left_le)
```
```   162   apply assumption+
```
```   163   apply (rule le_boolE)
```
```   164   apply (rule meet_right_le)
```
```   165   apply assumption+
```
```   166   apply (rule le_meetI)
```
```   167   apply (rule le_boolI)
```
```   168   apply (erule conjunct1)
```
```   169   apply (rule le_boolI)
```
```   170   apply (erule conjunct2)
```
```   171   done
```
```   172
```
```   173 theorem join_bool_eq: "join P Q = (P \<or> Q)"
```
```   174   apply (rule order_antisym)
```
```   175   apply (rule join_leI)
```
```   176   apply (rule le_boolI)
```
```   177   apply (erule disjI1)
```
```   178   apply (rule le_boolI)
```
```   179   apply (erule disjI2)
```
```   180   apply (rule le_boolI)
```
```   181   apply (erule disjE)
```
```   182   apply (rule le_boolE)
```
```   183   apply (rule join_left_le)
```
```   184   apply assumption+
```
```   185   apply (rule le_boolE)
```
```   186   apply (rule join_right_le)
```
```   187   apply assumption+
```
```   188   done
```
```   189
```
```   190 theorem Sup_bool_eq: "Sup A = (EX x:A. x)"
```
```   191   apply (rule order_antisym)
```
```   192   apply (rule Sup_least)
```
```   193   apply (rule le_boolI)
```
```   194   apply (erule bexI, assumption)
```
```   195   apply (rule le_boolI)
```
```   196   apply (erule bexE)
```
```   197   apply (rule le_boolE)
```
```   198   apply (rule Sup_upper)
```
```   199   apply assumption+
```
```   200   done
```
```   201
```
```   202 subsubsection {* Functions *}
```
```   203
```
```   204 instance "fun" :: (type, ord) ord ..
```
```   205
```
```   206 defs
```
```   207   le_fun_def: "f <= g == \<forall>x. f x <= g x"
```
```   208   less_fun_def: "f < g == (f::'a\<Rightarrow>'b::ord) <= g \<and> f \<noteq> g"
```
```   209
```
```   210 theorem le_funI: "(\<And>x. f x <= g x) \<Longrightarrow> f <= g"
```
```   211   by (simp add: le_fun_def)
```
```   212
```
```   213 theorem le_funE: "f <= g \<Longrightarrow> (f x <= g x \<Longrightarrow> P) \<Longrightarrow> P"
```
```   214   by (simp add: le_fun_def)
```
```   215
```
```   216 theorem le_funD: "f <= g \<Longrightarrow> f x <= g x"
```
```   217   by (simp add: le_fun_def)
```
```   218
```
```   219 text {*
```
```   220 Handy introduction and elimination rules for @{text "\<le>"}
```
```   221 on unary and binary predicates
```
```   222 *}
```
```   223
```
```   224 lemma predicate1I [intro]:
```
```   225   assumes PQ: "\<And>x. P x \<Longrightarrow> Q x"
```
```   226   shows "P \<le> Q"
```
```   227   apply (rule le_funI)
```
```   228   apply (rule le_boolI)
```
```   229   apply (rule PQ)
```
```   230   apply assumption
```
```   231   done
```
```   232
```
```   233 lemma predicate1D [elim]: "P \<le> Q \<Longrightarrow> P x \<Longrightarrow> Q x"
```
```   234   apply (erule le_funE)
```
```   235   apply (erule le_boolE)
```
```   236   apply assumption+
```
```   237   done
```
```   238
```
```   239 lemma predicate2I [intro]:
```
```   240   assumes PQ: "\<And>x y. P x y \<Longrightarrow> Q x y"
```
```   241   shows "P \<le> Q"
```
```   242   apply (rule le_funI)+
```
```   243   apply (rule le_boolI)
```
```   244   apply (rule PQ)
```
```   245   apply assumption
```
```   246   done
```
```   247
```
```   248 lemma predicate2D [elim]: "P \<le> Q \<Longrightarrow> P x y \<Longrightarrow> Q x y"
```
```   249   apply (erule le_funE)+
```
```   250   apply (erule le_boolE)
```
```   251   apply assumption+
```
```   252   done
```
```   253
```
```   254 instance "fun" :: (type, order) order
```
```   255   apply intro_classes
```
```   256   apply (rule le_funI)
```
```   257   apply (rule order_refl)
```
```   258   apply (rule le_funI)
```
```   259   apply (erule le_funE)+
```
```   260   apply (erule order_trans)
```
```   261   apply assumption
```
```   262   apply (rule ext)
```
```   263   apply (erule le_funE)+
```
```   264   apply (erule order_antisym)
```
```   265   apply assumption
```
```   266   apply (simp add: less_fun_def)
```
```   267   done
```
```   268
```
```   269 defs Meet_fun_def: "Meet A == (\<lambda>x. Meet {y. EX f:A. y = f x})"
```
```   270
```
```   271 instance "fun" :: (type, comp_lat) comp_lat
```
```   272   apply intro_classes
```
```   273   apply (unfold Meet_fun_def)
```
```   274   apply (rule le_funI)
```
```   275   apply (rule Meet_lower)
```
```   276   apply (rule CollectI)
```
```   277   apply (rule bexI)
```
```   278   apply (rule refl)
```
```   279   apply assumption
```
```   280   apply (rule le_funI)
```
```   281   apply (rule Meet_greatest)
```
```   282   apply (erule CollectE)
```
```   283   apply (erule bexE)
```
```   284   apply (iprover elim: le_funE)
```
```   285   done
```
```   286
```
```   287 theorem meet_fun_eq: "meet f g = (\<lambda>x. meet (f x) (g x))"
```
```   288   apply (rule order_antisym)
```
```   289   apply (rule le_funI)
```
```   290   apply (rule le_meetI)
```
```   291   apply (rule le_funD [OF meet_left_le])
```
```   292   apply (rule le_funD [OF meet_right_le])
```
```   293   apply (rule le_meetI)
```
```   294   apply (rule le_funI)
```
```   295   apply (rule meet_left_le)
```
```   296   apply (rule le_funI)
```
```   297   apply (rule meet_right_le)
```
```   298   done
```
```   299
```
```   300 theorem join_fun_eq: "join f g = (\<lambda>x. join (f x) (g x))"
```
```   301   apply (rule order_antisym)
```
```   302   apply (rule join_leI)
```
```   303   apply (rule le_funI)
```
```   304   apply (rule join_left_le)
```
```   305   apply (rule le_funI)
```
```   306   apply (rule join_right_le)
```
```   307   apply (rule le_funI)
```
```   308   apply (rule join_leI)
```
```   309   apply (rule le_funD [OF join_left_le])
```
```   310   apply (rule le_funD [OF join_right_le])
```
```   311   done
```
```   312
```
```   313 theorem Sup_fun_eq: "Sup A = (\<lambda>x. Sup {y::'a::comp_lat. EX f:A. y = f x})"
```
```   314   apply (rule order_antisym)
```
```   315   apply (rule Sup_least)
```
```   316   apply (rule le_funI)
```
```   317   apply (rule Sup_upper)
```
```   318   apply fast
```
```   319   apply (rule le_funI)
```
```   320   apply (rule Sup_least)
```
```   321   apply (erule CollectE)
```
```   322   apply (erule bexE)
```
```   323   apply (drule le_funD [OF Sup_upper])
```
```   324   apply simp
```
```   325   done
```
```   326
```
```   327 subsubsection {* Sets *}
```
```   328
```
```   329 defs Meet_set_def: "Meet S == \<Inter>S"
```
```   330
```
```   331 instance set :: (type) comp_lat
```
```   332   by intro_classes (auto simp add: Meet_set_def)
```
```   333
```
```   334 theorem meet_set_eq: "meet A B = A \<inter> B"
```
```   335   apply (rule subset_antisym)
```
```   336   apply (rule Int_greatest)
```
```   337   apply (rule meet_left_le)
```
```   338   apply (rule meet_right_le)
```
```   339   apply (rule le_meetI)
```
```   340   apply (rule Int_lower1)
```
```   341   apply (rule Int_lower2)
```
```   342   done
```
```   343
```
```   344 theorem join_set_eq: "join A B = A \<union> B"
```
```   345   apply (rule subset_antisym)
```
```   346   apply (rule join_leI)
```
```   347   apply (rule Un_upper1)
```
```   348   apply (rule Un_upper2)
```
```   349   apply (rule Un_least)
```
```   350   apply (rule join_left_le)
```
```   351   apply (rule join_right_le)
```
```   352   done
```
```   353
```
```   354 theorem Sup_set_eq: "Sup S = \<Union>S"
```
```   355   apply (rule subset_antisym)
```
```   356   apply (rule Sup_least)
```
```   357   apply (erule Union_upper)
```
```   358   apply (rule Union_least)
```
```   359   apply (erule Sup_upper)
```
```   360   done
```
```   361
```
```   362
```
```   363 subsection {* Least and greatest fixed points *}
```
```   364
```
```   365 constdefs
```
```   366   lfp :: "(('a::comp_lat) => 'a) => 'a"
```
```   367   "lfp f == Meet {u. f u <= u}"    --{*least fixed point*}
```
```   368
```
```   369   gfp :: "(('a::comp_lat) => 'a) => 'a"
```
```   370   "gfp f == Sup {u. u <= f u}"    --{*greatest fixed point*}
```
```   371
```
```   372
```
```   373 subsection{*Proof of Knaster-Tarski Theorem using @{term lfp}*}
```
```   374
```
```   375
```
```   376 text{*@{term "lfp f"} is the least upper bound of
```
```   377       the set @{term "{u. f(u) \<le> u}"} *}
```
```   378
```
```   379 lemma lfp_lowerbound: "f A \<le> A ==> lfp f \<le> A"
```
```   380   by (auto simp add: lfp_def intro: Meet_lower)
```
```   381
```
```   382 lemma lfp_greatest: "(!!u. f u \<le> u ==> A \<le> u) ==> A \<le> lfp f"
```
```   383   by (auto simp add: lfp_def intro: Meet_greatest)
```
```   384
```
```   385 lemma lfp_lemma2: "mono f ==> f (lfp f) \<le> lfp f"
```
```   386   by (iprover intro: lfp_greatest order_trans monoD lfp_lowerbound)
```
```   387
```
```   388 lemma lfp_lemma3: "mono f ==> lfp f \<le> f (lfp f)"
```
```   389   by (iprover intro: lfp_lemma2 monoD lfp_lowerbound)
```
```   390
```
```   391 lemma lfp_unfold: "mono f ==> lfp f = f (lfp f)"
```
```   392   by (iprover intro: order_antisym lfp_lemma2 lfp_lemma3)
```
```   393
```
```   394 subsection{*General induction rules for least fixed points*}
```
```   395
```
```   396 theorem lfp_induct:
```
```   397   assumes mono: "mono f" and ind: "f (meet (lfp f) P) <= P"
```
```   398   shows "lfp f <= P"
```
```   399 proof -
```
```   400   have "meet (lfp f) P <= lfp f" by (rule meet_left_le)
```
```   401   with mono have "f (meet (lfp f) P) <= f (lfp f)" ..
```
```   402   also from mono have "f (lfp f) = lfp f" by (rule lfp_unfold [symmetric])
```
```   403   finally have "f (meet (lfp f) P) <= lfp f" .
```
```   404   from this and ind have "f (meet (lfp f) P) <= meet (lfp f) P" by (rule le_meetI)
```
```   405   hence "lfp f <= meet (lfp f) P" by (rule lfp_lowerbound)
```
```   406   also have "meet (lfp f) P <= P" by (rule meet_right_le)
```
```   407   finally show ?thesis .
```
```   408 qed
```
```   409
```
```   410 lemma lfp_induct_set:
```
```   411   assumes lfp: "a: lfp(f)"
```
```   412       and mono: "mono(f)"
```
```   413       and indhyp: "!!x. [| x: f(lfp(f) Int {x. P(x)}) |] ==> P(x)"
```
```   414   shows "P(a)"
```
```   415   by (rule lfp_induct [THEN subsetD, THEN CollectD, OF mono _ lfp])
```
```   416     (auto simp: meet_set_eq intro: indhyp)
```
```   417
```
```   418
```
```   419 text{*Version of induction for binary relations*}
```
```   420 lemmas lfp_induct2 =  lfp_induct_set [of "(a,b)", split_format (complete)]
```
```   421
```
```   422
```
```   423 lemma lfp_ordinal_induct:
```
```   424   assumes mono: "mono f"
```
```   425   shows "[| !!S. P S ==> P(f S); !!M. !S:M. P S ==> P(Union M) |]
```
```   426          ==> P(lfp f)"
```
```   427 apply(subgoal_tac "lfp f = Union{S. S \<subseteq> lfp f & P S}")
```
```   428  apply (erule ssubst, simp)
```
```   429 apply(subgoal_tac "Union{S. S \<subseteq> lfp f & P S} \<subseteq> lfp f")
```
```   430  prefer 2 apply blast
```
```   431 apply(rule equalityI)
```
```   432  prefer 2 apply assumption
```
```   433 apply(drule mono [THEN monoD])
```
```   434 apply (cut_tac mono [THEN lfp_unfold], simp)
```
```   435 apply (rule lfp_lowerbound, auto)
```
```   436 done
```
```   437
```
```   438
```
```   439 text{*Definition forms of @{text lfp_unfold} and @{text lfp_induct},
```
```   440     to control unfolding*}
```
```   441
```
```   442 lemma def_lfp_unfold: "[| h==lfp(f);  mono(f) |] ==> h = f(h)"
```
```   443 by (auto intro!: lfp_unfold)
```
```   444
```
```   445 lemma def_lfp_induct:
```
```   446     "[| A == lfp(f); mono(f);
```
```   447         f (meet A P) \<le> P
```
```   448      |] ==> A \<le> P"
```
```   449   by (blast intro: lfp_induct)
```
```   450
```
```   451 lemma def_lfp_induct_set:
```
```   452     "[| A == lfp(f);  mono(f);   a:A;
```
```   453         !!x. [| x: f(A Int {x. P(x)}) |] ==> P(x)
```
```   454      |] ==> P(a)"
```
```   455   by (blast intro: lfp_induct_set)
```
```   456
```
```   457 (*Monotonicity of lfp!*)
```
```   458 lemma lfp_mono: "(!!Z. f Z \<le> g Z) ==> lfp f \<le> lfp g"
```
```   459   by (rule lfp_lowerbound [THEN lfp_greatest], blast intro: order_trans)
```
```   460
```
```   461
```
```   462 subsection{*Proof of Knaster-Tarski Theorem using @{term gfp}*}
```
```   463
```
```   464
```
```   465 text{*@{term "gfp f"} is the greatest lower bound of
```
```   466       the set @{term "{u. u \<le> f(u)}"} *}
```
```   467
```
```   468 lemma gfp_upperbound: "X \<le> f X ==> X \<le> gfp f"
```
```   469   by (auto simp add: gfp_def intro: Sup_upper)
```
```   470
```
```   471 lemma gfp_least: "(!!u. u \<le> f u ==> u \<le> X) ==> gfp f \<le> X"
```
```   472   by (auto simp add: gfp_def intro: Sup_least)
```
```   473
```
```   474 lemma gfp_lemma2: "mono f ==> gfp f \<le> f (gfp f)"
```
```   475   by (iprover intro: gfp_least order_trans monoD gfp_upperbound)
```
```   476
```
```   477 lemma gfp_lemma3: "mono f ==> f (gfp f) \<le> gfp f"
```
```   478   by (iprover intro: gfp_lemma2 monoD gfp_upperbound)
```
```   479
```
```   480 lemma gfp_unfold: "mono f ==> gfp f = f (gfp f)"
```
```   481   by (iprover intro: order_antisym gfp_lemma2 gfp_lemma3)
```
```   482
```
```   483 subsection{*Coinduction rules for greatest fixed points*}
```
```   484
```
```   485 text{*weak version*}
```
```   486 lemma weak_coinduct: "[| a: X;  X \<subseteq> f(X) |] ==> a : gfp(f)"
```
```   487 by (rule gfp_upperbound [THEN subsetD], auto)
```
```   488
```
```   489 lemma weak_coinduct_image: "!!X. [| a : X; g`X \<subseteq> f (g`X) |] ==> g a : gfp f"
```
```   490 apply (erule gfp_upperbound [THEN subsetD])
```
```   491 apply (erule imageI)
```
```   492 done
```
```   493
```
```   494 lemma coinduct_lemma:
```
```   495      "[| X \<le> f (join X (gfp f));  mono f |] ==> join X (gfp f) \<le> f (join X (gfp f))"
```
```   496   apply (frule gfp_lemma2)
```
```   497   apply (drule mono_join)
```
```   498   apply (rule join_leI)
```
```   499   apply assumption
```
```   500   apply (rule order_trans)
```
```   501   apply (rule order_trans)
```
```   502   apply assumption
```
```   503   apply (rule join_right_le)
```
```   504   apply assumption
```
```   505   done
```
```   506
```
```   507 text{*strong version, thanks to Coen and Frost*}
```
```   508 lemma coinduct_set: "[| mono(f);  a: X;  X \<subseteq> f(X Un gfp(f)) |] ==> a : gfp(f)"
```
```   509 by (blast intro: weak_coinduct [OF _ coinduct_lemma, simplified join_set_eq])
```
```   510
```
```   511 lemma coinduct: "[| mono(f); X \<le> f (join X (gfp f)) |] ==> X \<le> gfp(f)"
```
```   512   apply (rule order_trans)
```
```   513   apply (rule join_left_le)
```
```   514   apply (erule gfp_upperbound [OF coinduct_lemma])
```
```   515   apply assumption
```
```   516   done
```
```   517
```
```   518 lemma gfp_fun_UnI2: "[| mono(f);  a: gfp(f) |] ==> a: f(X Un gfp(f))"
```
```   519 by (blast dest: gfp_lemma2 mono_Un)
```
```   520
```
```   521 subsection{*Even Stronger Coinduction Rule, by Martin Coen*}
```
```   522
```
```   523 text{* Weakens the condition @{term "X \<subseteq> f(X)"} to one expressed using both
```
```   524   @{term lfp} and @{term gfp}*}
```
```   525
```
```   526 lemma coinduct3_mono_lemma: "mono(f) ==> mono(%x. f(x) Un X Un B)"
```
```   527 by (iprover intro: subset_refl monoI Un_mono monoD)
```
```   528
```
```   529 lemma coinduct3_lemma:
```
```   530      "[| X \<subseteq> f(lfp(%x. f(x) Un X Un gfp(f)));  mono(f) |]
```
```   531       ==> lfp(%x. f(x) Un X Un gfp(f)) \<subseteq> f(lfp(%x. f(x) Un X Un gfp(f)))"
```
```   532 apply (rule subset_trans)
```
```   533 apply (erule coinduct3_mono_lemma [THEN lfp_lemma3])
```
```   534 apply (rule Un_least [THEN Un_least])
```
```   535 apply (rule subset_refl, assumption)
```
```   536 apply (rule gfp_unfold [THEN equalityD1, THEN subset_trans], assumption)
```
```   537 apply (rule monoD, assumption)
```
```   538 apply (subst coinduct3_mono_lemma [THEN lfp_unfold], auto)
```
```   539 done
```
```   540
```
```   541 lemma coinduct3:
```
```   542   "[| mono(f);  a:X;  X \<subseteq> f(lfp(%x. f(x) Un X Un gfp(f))) |] ==> a : gfp(f)"
```
```   543 apply (rule coinduct3_lemma [THEN [2] weak_coinduct])
```
```   544 apply (rule coinduct3_mono_lemma [THEN lfp_unfold, THEN ssubst], auto)
```
```   545 done
```
```   546
```
```   547
```
```   548 text{*Definition forms of @{text gfp_unfold} and @{text coinduct},
```
```   549     to control unfolding*}
```
```   550
```
```   551 lemma def_gfp_unfold: "[| A==gfp(f);  mono(f) |] ==> A = f(A)"
```
```   552 by (auto intro!: gfp_unfold)
```
```   553
```
```   554 lemma def_coinduct:
```
```   555      "[| A==gfp(f);  mono(f);  X \<le> f(join X A) |] ==> X \<le> A"
```
```   556 by (iprover intro!: coinduct)
```
```   557
```
```   558 lemma def_coinduct_set:
```
```   559      "[| A==gfp(f);  mono(f);  a:X;  X \<subseteq> f(X Un A) |] ==> a: A"
```
```   560 by (auto intro!: coinduct_set)
```
```   561
```
```   562 (*The version used in the induction/coinduction package*)
```
```   563 lemma def_Collect_coinduct:
```
```   564     "[| A == gfp(%w. Collect(P(w)));  mono(%w. Collect(P(w)));
```
```   565         a: X;  !!z. z: X ==> P (X Un A) z |] ==>
```
```   566      a : A"
```
```   567 apply (erule def_coinduct_set, auto)
```
```   568 done
```
```   569
```
```   570 lemma def_coinduct3:
```
```   571     "[| A==gfp(f); mono(f);  a:X;  X \<subseteq> f(lfp(%x. f(x) Un X Un A)) |] ==> a: A"
```
```   572 by (auto intro!: coinduct3)
```
```   573
```
```   574 text{*Monotonicity of @{term gfp}!*}
```
```   575 lemma gfp_mono: "(!!Z. f Z \<le> g Z) ==> gfp f \<le> gfp g"
```
```   576   by (rule gfp_upperbound [THEN gfp_least], blast intro: order_trans)
```
```   577
```
```   578
```
```   579
```
```   580 ML
```
```   581 {*
```
```   582 val lfp_def = thm "lfp_def";
```
```   583 val lfp_lowerbound = thm "lfp_lowerbound";
```
```   584 val lfp_greatest = thm "lfp_greatest";
```
```   585 val lfp_unfold = thm "lfp_unfold";
```
```   586 val lfp_induct = thm "lfp_induct";
```
```   587 val lfp_induct2 = thm "lfp_induct2";
```
```   588 val lfp_ordinal_induct = thm "lfp_ordinal_induct";
```
```   589 val def_lfp_unfold = thm "def_lfp_unfold";
```
```   590 val def_lfp_induct = thm "def_lfp_induct";
```
```   591 val def_lfp_induct_set = thm "def_lfp_induct_set";
```
```   592 val lfp_mono = thm "lfp_mono";
```
```   593 val gfp_def = thm "gfp_def";
```
```   594 val gfp_upperbound = thm "gfp_upperbound";
```
```   595 val gfp_least = thm "gfp_least";
```
```   596 val gfp_unfold = thm "gfp_unfold";
```
```   597 val weak_coinduct = thm "weak_coinduct";
```
```   598 val weak_coinduct_image = thm "weak_coinduct_image";
```
```   599 val coinduct = thm "coinduct";
```
```   600 val gfp_fun_UnI2 = thm "gfp_fun_UnI2";
```
```   601 val coinduct3 = thm "coinduct3";
```
```   602 val def_gfp_unfold = thm "def_gfp_unfold";
```
```   603 val def_coinduct = thm "def_coinduct";
```
```   604 val def_Collect_coinduct = thm "def_Collect_coinduct";
```
```   605 val def_coinduct3 = thm "def_coinduct3";
```
```   606 val gfp_mono = thm "gfp_mono";
```
```   607 val le_funI = thm "le_funI";
```
```   608 val le_boolI = thm "le_boolI";
```
```   609 val le_boolI' = thm "le_boolI'";
```
```   610 val meet_fun_eq = thm "meet_fun_eq";
```
```   611 val meet_bool_eq = thm "meet_bool_eq";
```
```   612 val le_funE = thm "le_funE";
```
```   613 val le_boolE = thm "le_boolE";
```
```   614 val le_boolD = thm "le_boolD";
```
```   615 val le_bool_def = thm "le_bool_def";
```
```   616 val le_fun_def = thm "le_fun_def";
```
```   617 *}
```
```   618
```
```   619 end
```