| 
9422
 | 
     1  | 
(*  Title:      HOL/Lfp.ML
  | 
| 
923
 | 
     2  | 
    ID:         $Id$
  | 
| 
1465
 | 
     3  | 
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
  | 
| 
923
 | 
     4  | 
    Copyright   1992  University of Cambridge
  | 
| 
 | 
     5  | 
  | 
| 
9422
 | 
     6  | 
The Knaster-Tarski Theorem.
  | 
| 
923
 | 
     7  | 
*)
  | 
| 
 | 
     8  | 
  | 
| 
 | 
     9  | 
(*** Proof of Knaster-Tarski Theorem ***)
  | 
| 
 | 
    10  | 
  | 
| 
14169
 | 
    11  | 
val lfp_def = thm "lfp_def";
  | 
| 
 | 
    12  | 
  | 
| 
923
 | 
    13  | 
(* lfp(f) is the greatest lower bound of {u. f(u) <= u} *)
 | 
| 
 | 
    14  | 
  | 
| 
5316
 | 
    15  | 
Goalw [lfp_def] "f(A) <= A ==> lfp(f) <= A";
  | 
| 
923
 | 
    16  | 
by (rtac (CollectI RS Inter_lower) 1);
  | 
| 
5316
 | 
    17  | 
by (assume_tac 1);
  | 
| 
923
 | 
    18  | 
qed "lfp_lowerbound";
  | 
| 
 | 
    19  | 
  | 
| 
5316
 | 
    20  | 
val prems = Goalw [lfp_def]
  | 
| 
923
 | 
    21  | 
    "[| !!u. f(u) <= u ==> A<=u |] ==> A <= lfp(f)";
  | 
| 
 | 
    22  | 
by (REPEAT (ares_tac ([Inter_greatest]@prems) 1));
  | 
| 
 | 
    23  | 
by (etac CollectD 1);
  | 
| 
 | 
    24  | 
qed "lfp_greatest";
  | 
| 
 | 
    25  | 
  | 
| 
5316
 | 
    26  | 
Goal "mono(f) ==> f(lfp(f)) <= lfp(f)";
  | 
| 
923
 | 
    27  | 
by (EVERY1 [rtac lfp_greatest, rtac subset_trans,
  | 
| 
5316
 | 
    28  | 
            etac monoD, rtac lfp_lowerbound, atac, atac]);
  | 
| 
923
 | 
    29  | 
qed "lfp_lemma2";
  | 
| 
 | 
    30  | 
  | 
| 
5316
 | 
    31  | 
Goal "mono(f) ==> lfp(f) <= f(lfp(f))";
  | 
| 
 | 
    32  | 
by (EVERY1 [rtac lfp_lowerbound, rtac monoD, assume_tac,
  | 
| 
 | 
    33  | 
            etac lfp_lemma2]);
  | 
| 
923
 | 
    34  | 
qed "lfp_lemma3";
  | 
| 
 | 
    35  | 
  | 
| 
5316
 | 
    36  | 
Goal "mono(f) ==> lfp(f) = f(lfp(f))";
  | 
| 
 | 
    37  | 
by (REPEAT (ares_tac [equalityI,lfp_lemma2,lfp_lemma3] 1));
  | 
| 
10186
 | 
    38  | 
qed "lfp_unfold";
  | 
| 
923
 | 
    39  | 
  | 
| 
 | 
    40  | 
(*** General induction rule for least fixed points ***)
  | 
| 
 | 
    41  | 
  | 
| 
5316
 | 
    42  | 
val [lfp,mono,indhyp] = Goal
  | 
| 
1465
 | 
    43  | 
    "[| a: lfp(f);  mono(f);                            \
  | 
| 
3842
 | 
    44  | 
\       !!x. [| x: f(lfp(f) Int {x. P(x)}) |] ==> P(x)   \
 | 
| 
923
 | 
    45  | 
\    |] ==> P(a)";
  | 
| 
 | 
    46  | 
by (res_inst_tac [("a","a")] (Int_lower2 RS subsetD RS CollectD) 1);
 | 
| 
 | 
    47  | 
by (rtac (lfp RSN (2, lfp_lowerbound RS subsetD)) 1);
  | 
| 
 | 
    48  | 
by (EVERY1 [rtac Int_greatest, rtac subset_trans, 
  | 
| 
1465
 | 
    49  | 
            rtac (Int_lower1 RS (mono RS monoD)),
  | 
| 
 | 
    50  | 
            rtac (mono RS lfp_lemma2),
  | 
| 
 | 
    51  | 
            rtac (CollectI RS subsetI), rtac indhyp, atac]);
  | 
| 
10202
 | 
    52  | 
qed "lfp_induct";
  | 
| 
923
 | 
    53  | 
  | 
| 
10202
 | 
    54  | 
bind_thm ("lfp_induct2",
 | 
| 
 | 
    55  | 
  split_rule (read_instantiate [("a","(a,b)")] lfp_induct));
 | 
| 
1114
 | 
    56  | 
  | 
| 
1125
 | 
    57  | 
  | 
| 
14892
 | 
    58  | 
val major::prems = Goal
  | 
| 
 | 
    59  | 
 "[| mono f; !!S. P S ==> P(f S); !!M. !S:M. P S ==> P(Union M) |] ==> \
  | 
| 
 | 
    60  | 
\ P(lfp f)";
  | 
| 
 | 
    61  | 
by(subgoal_tac "lfp f = Union{S. S <= lfp f & P S}" 1);
 | 
| 
 | 
    62  | 
 by(etac ssubst 1);
  | 
| 
 | 
    63  | 
 by(simp_tac (simpset() addsimps prems) 1);
  | 
| 
 | 
    64  | 
by(subgoal_tac "Union{S. S <= lfp f & P S} <= lfp f" 1);
 | 
| 
 | 
    65  | 
 by(Blast_tac 2);
  | 
| 
 | 
    66  | 
by(rtac equalityI 1);
  | 
| 
 | 
    67  | 
 by(atac 2);
  | 
| 
 | 
    68  | 
by(dtac (major RS monoD) 1);
  | 
| 
 | 
    69  | 
by(cut_facts_tac [major RS lfp_unfold] 1);
  | 
| 
 | 
    70  | 
by(Asm_full_simp_tac 1);
  | 
| 
 | 
    71  | 
by(rtac lfp_lowerbound 1);
  | 
| 
 | 
    72  | 
by(blast_tac (claset() addSIs prems) 1);
  | 
| 
 | 
    73  | 
qed "lfp_ordinal_induct";
  | 
| 
 | 
    74  | 
  | 
| 
 | 
    75  | 
  | 
| 
10202
 | 
    76  | 
(** Definition forms of lfp_unfold and lfp_induct, to control unfolding **)
  | 
| 
923
 | 
    77  | 
  | 
| 
10067
 | 
    78  | 
Goal "[| h==lfp(f);  mono(f) |] ==> h = f(h)";
  | 
| 
10186
 | 
    79  | 
by (auto_tac (claset() addSIs [lfp_unfold], simpset()));  
  | 
| 
 | 
    80  | 
qed "def_lfp_unfold";
  | 
| 
923
 | 
    81  | 
  | 
| 
5316
 | 
    82  | 
val rew::prems = Goal
  | 
| 
1465
 | 
    83  | 
    "[| A == lfp(f);  mono(f);   a:A;                   \
  | 
| 
3842
 | 
    84  | 
\       !!x. [| x: f(A Int {x. P(x)}) |] ==> P(x)        \
 | 
| 
923
 | 
    85  | 
\    |] ==> P(a)";
  | 
| 
10202
 | 
    86  | 
by (EVERY1 [rtac lfp_induct,        (*backtracking to force correct induction*)
  | 
| 
1465
 | 
    87  | 
            REPEAT1 o (ares_tac (map (rewrite_rule [rew]) prems))]);
  | 
| 
10202
 | 
    88  | 
qed "def_lfp_induct";
  | 
| 
923
 | 
    89  | 
  | 
| 
 | 
    90  | 
(*Monotonicity of lfp!*)
  | 
| 
5316
 | 
    91  | 
val [prem] = Goal "[| !!Z. f(Z)<=g(Z) |] ==> lfp(f) <= lfp(g)";
  | 
| 
1465
 | 
    92  | 
by (rtac (lfp_lowerbound RS lfp_greatest) 1);
  | 
| 
 | 
    93  | 
by (etac (prem RS subset_trans) 1);
  | 
| 
923
 | 
    94  | 
qed "lfp_mono";
  |