| 17456 |      1 | (*  Title:      CCL/Lfp.ML
 | 
| 0 |      2 |     ID:         $Id$
 | 
|  |      3 | *)
 | 
|  |      4 | 
 | 
|  |      5 | (*** Proof of Knaster-Tarski Theorem ***)
 | 
|  |      6 | 
 | 
|  |      7 | (* lfp(f) is the greatest lower bound of {u. f(u) <= u} *)
 | 
|  |      8 | 
 | 
| 17456 |      9 | val prems = goalw (the_context ()) [lfp_def] "[| f(A) <= A |] ==> lfp(f) <= A";
 | 
| 0 |     10 | by (rtac (CollectI RS Inter_lower) 1);
 | 
|  |     11 | by (resolve_tac prems 1);
 | 
| 757 |     12 | qed "lfp_lowerbound";
 | 
| 0 |     13 | 
 | 
| 17456 |     14 | val prems = goalw (the_context ()) [lfp_def]
 | 
| 0 |     15 |     "[| !!u. f(u) <= u ==> A<=u |] ==> A <= lfp(f)";
 | 
|  |     16 | by (REPEAT (ares_tac ([Inter_greatest]@prems) 1));
 | 
|  |     17 | by (etac CollectD 1);
 | 
| 757 |     18 | qed "lfp_greatest";
 | 
| 0 |     19 | 
 | 
| 17456 |     20 | val [mono] = goal (the_context ()) "mono(f) ==> f(lfp(f)) <= lfp(f)";
 | 
| 0 |     21 | by (EVERY1 [rtac lfp_greatest, rtac subset_trans,
 | 
| 1459 |     22 |             rtac (mono RS monoD), rtac lfp_lowerbound, atac, atac]);
 | 
| 757 |     23 | qed "lfp_lemma2";
 | 
| 0 |     24 | 
 | 
| 17456 |     25 | val [mono] = goal (the_context ()) "mono(f) ==> lfp(f) <= f(lfp(f))";
 | 
|  |     26 | by (EVERY1 [rtac lfp_lowerbound, rtac (mono RS monoD),
 | 
| 1459 |     27 |             rtac lfp_lemma2, rtac mono]);
 | 
| 757 |     28 | qed "lfp_lemma3";
 | 
| 0 |     29 | 
 | 
| 17456 |     30 | val [mono] = goal (the_context ()) "mono(f) ==> lfp(f) = f(lfp(f))";
 | 
| 0 |     31 | by (REPEAT (resolve_tac [equalityI,lfp_lemma2,lfp_lemma3,mono] 1));
 | 
| 757 |     32 | qed "lfp_Tarski";
 | 
| 0 |     33 | 
 | 
|  |     34 | 
 | 
|  |     35 | (*** General induction rule for least fixed points ***)
 | 
|  |     36 | 
 | 
| 17456 |     37 | val [lfp,mono,indhyp] = goal (the_context ())
 | 
| 1459 |     38 |     "[| a: lfp(f);  mono(f);                            \
 | 
| 3837 |     39 | \       !!x. [| x: f(lfp(f) Int {x. P(x)}) |] ==> P(x)   \
 | 
| 0 |     40 | \    |] ==> P(a)";
 | 
|  |     41 | by (res_inst_tac [("a","a")] (Int_lower2 RS subsetD RS CollectD) 1);
 | 
|  |     42 | by (rtac (lfp RSN (2, lfp_lowerbound RS subsetD)) 1);
 | 
| 17456 |     43 | by (EVERY1 [rtac Int_greatest, rtac subset_trans,
 | 
| 1459 |     44 |             rtac (Int_lower1 RS (mono RS monoD)),
 | 
|  |     45 |             rtac (mono RS lfp_lemma2),
 | 
|  |     46 |             rtac (CollectI RS subsetI), rtac indhyp, atac]);
 | 
| 757 |     47 | qed "induct";
 | 
| 0 |     48 | 
 | 
|  |     49 | (** Definition forms of lfp_Tarski and induct, to control unfolding **)
 | 
|  |     50 | 
 | 
| 17456 |     51 | val [rew,mono] = goal (the_context ()) "[| h==lfp(f);  mono(f) |] ==> h = f(h)";
 | 
| 0 |     52 | by (rewtac rew);
 | 
|  |     53 | by (rtac (mono RS lfp_Tarski) 1);
 | 
| 757 |     54 | qed "def_lfp_Tarski";
 | 
| 0 |     55 | 
 | 
| 17456 |     56 | val rew::prems = goal (the_context ())
 | 
| 1459 |     57 |     "[| A == lfp(f);  a:A;  mono(f);                    \
 | 
| 3837 |     58 | \       !!x. [| x: f(A Int {x. P(x)}) |] ==> P(x)        \
 | 
| 0 |     59 | \    |] ==> P(a)";
 | 
| 1459 |     60 | by (EVERY1 [rtac induct,        (*backtracking to force correct induction*)
 | 
|  |     61 |             REPEAT1 o (ares_tac (map (rewrite_rule [rew]) prems))]);
 | 
| 757 |     62 | qed "def_induct";
 | 
| 0 |     63 | 
 | 
|  |     64 | (*Monotonicity of lfp!*)
 | 
| 17456 |     65 | val prems = goal (the_context ())
 | 
| 0 |     66 |     "[| mono(g);  !!Z. f(Z)<=g(Z) |] ==> lfp(f) <= lfp(g)";
 | 
|  |     67 | by (rtac lfp_lowerbound 1);
 | 
|  |     68 | by (rtac subset_trans 1);
 | 
|  |     69 | by (resolve_tac prems 1);
 | 
|  |     70 | by (rtac lfp_lemma2 1);
 | 
|  |     71 | by (resolve_tac prems 1);
 | 
| 757 |     72 | qed "lfp_mono";
 |