src/HOL/FixedPoint.thy
author obua
Mon Apr 10 16:00:34 2006 +0200 (2006-04-10)
changeset 19404 9bf2cdc9e8e8
parent 17589 58eeffd73be1
child 21017 5693e4471c2b
permissions -rw-r--r--
Moved stuff from Ring_and_Field to Matrix
avigad@17006
     1
(*  Title:      HOL/FixedPoint.thy
avigad@17006
     2
    ID:         $Id$
avigad@17006
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
avigad@17006
     4
    Copyright   1992  University of Cambridge
avigad@17006
     5
*)
avigad@17006
     6
avigad@17006
     7
header{* Fixed Points and the Knaster-Tarski Theorem*}
avigad@17006
     8
avigad@17006
     9
theory FixedPoint
avigad@17006
    10
imports Product_Type
avigad@17006
    11
begin
avigad@17006
    12
avigad@17006
    13
constdefs
avigad@17006
    14
  lfp :: "['a set \<Rightarrow> 'a set] \<Rightarrow> 'a set"
avigad@17006
    15
    "lfp(f) == Inter({u. f(u) \<subseteq> u})"    --{*least fixed point*}
avigad@17006
    16
avigad@17006
    17
  gfp :: "['a set=>'a set] => 'a set"
avigad@17006
    18
    "gfp(f) == Union({u. u \<subseteq> f(u)})"
avigad@17006
    19
avigad@17006
    20
avigad@17006
    21
subsection{*Proof of Knaster-Tarski Theorem using @{term lfp}*}
avigad@17006
    22
avigad@17006
    23
avigad@17006
    24
text{*@{term "lfp f"} is the least upper bound of 
avigad@17006
    25
      the set @{term "{u. f(u) \<subseteq> u}"} *}
avigad@17006
    26
avigad@17006
    27
lemma lfp_lowerbound: "f(A) \<subseteq> A ==> lfp(f) \<subseteq> A"
avigad@17006
    28
by (auto simp add: lfp_def)
avigad@17006
    29
avigad@17006
    30
lemma lfp_greatest: "[| !!u. f(u) \<subseteq> u ==> A\<subseteq>u |] ==> A \<subseteq> lfp(f)"
avigad@17006
    31
by (auto simp add: lfp_def)
avigad@17006
    32
avigad@17006
    33
lemma lfp_lemma2: "mono(f) ==> f(lfp(f)) \<subseteq> lfp(f)"
nipkow@17589
    34
by (iprover intro: lfp_greatest subset_trans monoD lfp_lowerbound)
avigad@17006
    35
avigad@17006
    36
lemma lfp_lemma3: "mono(f) ==> lfp(f) \<subseteq> f(lfp(f))"
nipkow@17589
    37
by (iprover intro: lfp_lemma2 monoD lfp_lowerbound)
avigad@17006
    38
avigad@17006
    39
lemma lfp_unfold: "mono(f) ==> lfp(f) = f(lfp(f))"
nipkow@17589
    40
by (iprover intro: equalityI lfp_lemma2 lfp_lemma3)
avigad@17006
    41
avigad@17006
    42
subsection{*General induction rules for greatest fixed points*}
avigad@17006
    43
avigad@17006
    44
lemma lfp_induct: 
avigad@17006
    45
  assumes lfp: "a: lfp(f)"
avigad@17006
    46
      and mono: "mono(f)"
avigad@17006
    47
      and indhyp: "!!x. [| x: f(lfp(f) Int {x. P(x)}) |] ==> P(x)"
avigad@17006
    48
  shows "P(a)"
avigad@17006
    49
apply (rule_tac a=a in Int_lower2 [THEN subsetD, THEN CollectD]) 
avigad@17006
    50
apply (rule lfp [THEN [2] lfp_lowerbound [THEN subsetD]]) 
avigad@17006
    51
apply (rule Int_greatest)
avigad@17006
    52
 apply (rule subset_trans [OF Int_lower1 [THEN mono [THEN monoD]]
avigad@17006
    53
                              mono [THEN lfp_lemma2]]) 
avigad@17006
    54
apply (blast intro: indhyp) 
avigad@17006
    55
done
avigad@17006
    56
avigad@17006
    57
avigad@17006
    58
text{*Version of induction for binary relations*}
avigad@17006
    59
lemmas lfp_induct2 =  lfp_induct [of "(a,b)", split_format (complete)]
avigad@17006
    60
avigad@17006
    61
avigad@17006
    62
lemma lfp_ordinal_induct: 
avigad@17006
    63
  assumes mono: "mono f"
avigad@17006
    64
  shows "[| !!S. P S ==> P(f S); !!M. !S:M. P S ==> P(Union M) |] 
avigad@17006
    65
         ==> P(lfp f)"
avigad@17006
    66
apply(subgoal_tac "lfp f = Union{S. S \<subseteq> lfp f & P S}")
avigad@17006
    67
 apply (erule ssubst, simp) 
avigad@17006
    68
apply(subgoal_tac "Union{S. S \<subseteq> lfp f & P S} \<subseteq> lfp f")
avigad@17006
    69
 prefer 2 apply blast
avigad@17006
    70
apply(rule equalityI)
avigad@17006
    71
 prefer 2 apply assumption
avigad@17006
    72
apply(drule mono [THEN monoD])
avigad@17006
    73
apply (cut_tac mono [THEN lfp_unfold], simp)
avigad@17006
    74
apply (rule lfp_lowerbound, auto) 
avigad@17006
    75
done
avigad@17006
    76
avigad@17006
    77
avigad@17006
    78
text{*Definition forms of @{text lfp_unfold} and @{text lfp_induct}, 
avigad@17006
    79
    to control unfolding*}
avigad@17006
    80
avigad@17006
    81
lemma def_lfp_unfold: "[| h==lfp(f);  mono(f) |] ==> h = f(h)"
avigad@17006
    82
by (auto intro!: lfp_unfold)
avigad@17006
    83
avigad@17006
    84
lemma def_lfp_induct: 
avigad@17006
    85
    "[| A == lfp(f);  mono(f);   a:A;                    
avigad@17006
    86
        !!x. [| x: f(A Int {x. P(x)}) |] ==> P(x)         
avigad@17006
    87
     |] ==> P(a)"
avigad@17006
    88
by (blast intro: lfp_induct)
avigad@17006
    89
avigad@17006
    90
(*Monotonicity of lfp!*)
avigad@17006
    91
lemma lfp_mono: "[| !!Z. f(Z)\<subseteq>g(Z) |] ==> lfp(f) \<subseteq> lfp(g)"
avigad@17006
    92
by (rule lfp_lowerbound [THEN lfp_greatest], blast)
avigad@17006
    93
avigad@17006
    94
avigad@17006
    95
subsection{*Proof of Knaster-Tarski Theorem using @{term gfp}*}
avigad@17006
    96
avigad@17006
    97
avigad@17006
    98
text{*@{term "gfp f"} is the greatest lower bound of 
avigad@17006
    99
      the set @{term "{u. u \<subseteq> f(u)}"} *}
avigad@17006
   100
avigad@17006
   101
lemma gfp_upperbound: "[| X \<subseteq> f(X) |] ==> X \<subseteq> gfp(f)"
avigad@17006
   102
by (auto simp add: gfp_def)
avigad@17006
   103
avigad@17006
   104
lemma gfp_least: "[| !!u. u \<subseteq> f(u) ==> u\<subseteq>X |] ==> gfp(f) \<subseteq> X"
avigad@17006
   105
by (auto simp add: gfp_def)
avigad@17006
   106
avigad@17006
   107
lemma gfp_lemma2: "mono(f) ==> gfp(f) \<subseteq> f(gfp(f))"
nipkow@17589
   108
by (iprover intro: gfp_least subset_trans monoD gfp_upperbound)
avigad@17006
   109
avigad@17006
   110
lemma gfp_lemma3: "mono(f) ==> f(gfp(f)) \<subseteq> gfp(f)"
nipkow@17589
   111
by (iprover intro: gfp_lemma2 monoD gfp_upperbound)
avigad@17006
   112
avigad@17006
   113
lemma gfp_unfold: "mono(f) ==> gfp(f) = f(gfp(f))"
nipkow@17589
   114
by (iprover intro: equalityI gfp_lemma2 gfp_lemma3)
avigad@17006
   115
avigad@17006
   116
subsection{*Coinduction rules for greatest fixed points*}
avigad@17006
   117
avigad@17006
   118
text{*weak version*}
avigad@17006
   119
lemma weak_coinduct: "[| a: X;  X \<subseteq> f(X) |] ==> a : gfp(f)"
avigad@17006
   120
by (rule gfp_upperbound [THEN subsetD], auto)
avigad@17006
   121
avigad@17006
   122
lemma weak_coinduct_image: "!!X. [| a : X; g`X \<subseteq> f (g`X) |] ==> g a : gfp f"
avigad@17006
   123
apply (erule gfp_upperbound [THEN subsetD])
avigad@17006
   124
apply (erule imageI)
avigad@17006
   125
done
avigad@17006
   126
avigad@17006
   127
lemma coinduct_lemma:
avigad@17006
   128
     "[| X \<subseteq> f(X Un gfp(f));  mono(f) |] ==> X Un gfp(f) \<subseteq> f(X Un gfp(f))"
avigad@17006
   129
by (blast dest: gfp_lemma2 mono_Un)
avigad@17006
   130
avigad@17006
   131
text{*strong version, thanks to Coen and Frost*}
avigad@17006
   132
lemma coinduct: "[| mono(f);  a: X;  X \<subseteq> f(X Un gfp(f)) |] ==> a : gfp(f)"
avigad@17006
   133
by (blast intro: weak_coinduct [OF _ coinduct_lemma])
avigad@17006
   134
avigad@17006
   135
lemma gfp_fun_UnI2: "[| mono(f);  a: gfp(f) |] ==> a: f(X Un gfp(f))"
avigad@17006
   136
by (blast dest: gfp_lemma2 mono_Un)
avigad@17006
   137
avigad@17006
   138
subsection{*Even Stronger Coinduction Rule, by Martin Coen*}
avigad@17006
   139
avigad@17006
   140
text{* Weakens the condition @{term "X \<subseteq> f(X)"} to one expressed using both
avigad@17006
   141
  @{term lfp} and @{term gfp}*}
avigad@17006
   142
avigad@17006
   143
lemma coinduct3_mono_lemma: "mono(f) ==> mono(%x. f(x) Un X Un B)"
nipkow@17589
   144
by (iprover intro: subset_refl monoI Un_mono monoD)
avigad@17006
   145
avigad@17006
   146
lemma coinduct3_lemma:
avigad@17006
   147
     "[| X \<subseteq> f(lfp(%x. f(x) Un X Un gfp(f)));  mono(f) |]
avigad@17006
   148
      ==> lfp(%x. f(x) Un X Un gfp(f)) \<subseteq> f(lfp(%x. f(x) Un X Un gfp(f)))"
avigad@17006
   149
apply (rule subset_trans)
avigad@17006
   150
apply (erule coinduct3_mono_lemma [THEN lfp_lemma3])
avigad@17006
   151
apply (rule Un_least [THEN Un_least])
avigad@17006
   152
apply (rule subset_refl, assumption)
avigad@17006
   153
apply (rule gfp_unfold [THEN equalityD1, THEN subset_trans], assumption)
avigad@17006
   154
apply (rule monoD, assumption)
avigad@17006
   155
apply (subst coinduct3_mono_lemma [THEN lfp_unfold], auto)
avigad@17006
   156
done
avigad@17006
   157
avigad@17006
   158
lemma coinduct3: 
avigad@17006
   159
  "[| mono(f);  a:X;  X \<subseteq> f(lfp(%x. f(x) Un X Un gfp(f))) |] ==> a : gfp(f)"
avigad@17006
   160
apply (rule coinduct3_lemma [THEN [2] weak_coinduct])
avigad@17006
   161
apply (rule coinduct3_mono_lemma [THEN lfp_unfold, THEN ssubst], auto)
avigad@17006
   162
done
avigad@17006
   163
avigad@17006
   164
avigad@17006
   165
text{*Definition forms of @{text gfp_unfold} and @{text coinduct}, 
avigad@17006
   166
    to control unfolding*}
avigad@17006
   167
avigad@17006
   168
lemma def_gfp_unfold: "[| A==gfp(f);  mono(f) |] ==> A = f(A)"
avigad@17006
   169
by (auto intro!: gfp_unfold)
avigad@17006
   170
avigad@17006
   171
lemma def_coinduct:
avigad@17006
   172
     "[| A==gfp(f);  mono(f);  a:X;  X \<subseteq> f(X Un A) |] ==> a: A"
avigad@17006
   173
by (auto intro!: coinduct)
avigad@17006
   174
avigad@17006
   175
(*The version used in the induction/coinduction package*)
avigad@17006
   176
lemma def_Collect_coinduct:
avigad@17006
   177
    "[| A == gfp(%w. Collect(P(w)));  mono(%w. Collect(P(w)));   
avigad@17006
   178
        a: X;  !!z. z: X ==> P (X Un A) z |] ==>  
avigad@17006
   179
     a : A"
avigad@17006
   180
apply (erule def_coinduct, auto) 
avigad@17006
   181
done
avigad@17006
   182
avigad@17006
   183
lemma def_coinduct3:
avigad@17006
   184
    "[| A==gfp(f); mono(f);  a:X;  X \<subseteq> f(lfp(%x. f(x) Un X Un A)) |] ==> a: A"
avigad@17006
   185
by (auto intro!: coinduct3)
avigad@17006
   186
avigad@17006
   187
text{*Monotonicity of @{term gfp}!*}
avigad@17006
   188
lemma gfp_mono: "[| !!Z. f(Z)\<subseteq>g(Z) |] ==> gfp(f) \<subseteq> gfp(g)"
avigad@17006
   189
by (rule gfp_upperbound [THEN gfp_least], blast)
avigad@17006
   190
avigad@17006
   191
avigad@17006
   192
ML
avigad@17006
   193
{*
avigad@17006
   194
val lfp_def = thm "lfp_def";
avigad@17006
   195
val lfp_lowerbound = thm "lfp_lowerbound";
avigad@17006
   196
val lfp_greatest = thm "lfp_greatest";
avigad@17006
   197
val lfp_unfold = thm "lfp_unfold";
avigad@17006
   198
val lfp_induct = thm "lfp_induct";
avigad@17006
   199
val lfp_induct2 = thm "lfp_induct2";
avigad@17006
   200
val lfp_ordinal_induct = thm "lfp_ordinal_induct";
avigad@17006
   201
val def_lfp_unfold = thm "def_lfp_unfold";
avigad@17006
   202
val def_lfp_induct = thm "def_lfp_induct";
avigad@17006
   203
val lfp_mono = thm "lfp_mono";
avigad@17006
   204
val gfp_def = thm "gfp_def";
avigad@17006
   205
val gfp_upperbound = thm "gfp_upperbound";
avigad@17006
   206
val gfp_least = thm "gfp_least";
avigad@17006
   207
val gfp_unfold = thm "gfp_unfold";
avigad@17006
   208
val weak_coinduct = thm "weak_coinduct";
avigad@17006
   209
val weak_coinduct_image = thm "weak_coinduct_image";
avigad@17006
   210
val coinduct = thm "coinduct";
avigad@17006
   211
val gfp_fun_UnI2 = thm "gfp_fun_UnI2";
avigad@17006
   212
val coinduct3 = thm "coinduct3";
avigad@17006
   213
val def_gfp_unfold = thm "def_gfp_unfold";
avigad@17006
   214
val def_coinduct = thm "def_coinduct";
avigad@17006
   215
val def_Collect_coinduct = thm "def_Collect_coinduct";
avigad@17006
   216
val def_coinduct3 = thm "def_coinduct3";
avigad@17006
   217
val gfp_mono = thm "gfp_mono";
avigad@17006
   218
*}
avigad@17006
   219
avigad@17006
   220
end