author | paulson |
Wed, 05 Aug 1998 10:57:25 +0200 | |
changeset 5253 | 82a5ca6290aa |
parent 5148 | 74919e8f221c |
child 5316 | 7a8975451a89 |
permissions | -rw-r--r-- |
1465 | 1 |
(* Title: HOL/gfp |
923 | 2 |
ID: $Id$ |
1465 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
923 | 4 |
Copyright 1993 University of Cambridge |
5 |
||
5148
74919e8f221c
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5069
diff
changeset
|
6 |
The Knaster-Tarski Theorem for greatest fixed points. |
923 | 7 |
*) |
8 |
||
9 |
open Gfp; |
|
10 |
||
11 |
(*** Proof of Knaster-Tarski Theorem using gfp ***) |
|
12 |
||
13 |
(* gfp(f) is the least upper bound of {u. u <= f(u)} *) |
|
14 |
||
5148
74919e8f221c
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5069
diff
changeset
|
15 |
Goalw [gfp_def] "[| X <= f(X) |] ==> X <= gfp(f)"; |
74919e8f221c
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5069
diff
changeset
|
16 |
by (etac (CollectI RS Union_upper) 1); |
923 | 17 |
qed "gfp_upperbound"; |
18 |
||
19 |
val prems = goalw Gfp.thy [gfp_def] |
|
20 |
"[| !!u. u <= f(u) ==> u<=X |] ==> gfp(f) <= X"; |
|
21 |
by (REPEAT (ares_tac ([Union_least]@prems) 1)); |
|
22 |
by (etac CollectD 1); |
|
23 |
qed "gfp_least"; |
|
24 |
||
25 |
val [mono] = goal Gfp.thy "mono(f) ==> gfp(f) <= f(gfp(f))"; |
|
26 |
by (EVERY1 [rtac gfp_least, rtac subset_trans, atac, |
|
1465 | 27 |
rtac (mono RS monoD), rtac gfp_upperbound, atac]); |
923 | 28 |
qed "gfp_lemma2"; |
29 |
||
30 |
val [mono] = goal Gfp.thy "mono(f) ==> f(gfp(f)) <= gfp(f)"; |
|
31 |
by (EVERY1 [rtac gfp_upperbound, rtac (mono RS monoD), |
|
1465 | 32 |
rtac gfp_lemma2, rtac mono]); |
923 | 33 |
qed "gfp_lemma3"; |
34 |
||
35 |
val [mono] = goal Gfp.thy "mono(f) ==> gfp(f) = f(gfp(f))"; |
|
36 |
by (REPEAT (resolve_tac [equalityI,gfp_lemma2,gfp_lemma3,mono] 1)); |
|
37 |
qed "gfp_Tarski"; |
|
38 |
||
39 |
(*** Coinduction rules for greatest fixed points ***) |
|
40 |
||
41 |
(*weak version*) |
|
5148
74919e8f221c
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5069
diff
changeset
|
42 |
Goal "[| a: X; X <= f(X) |] ==> a : gfp(f)"; |
923 | 43 |
by (rtac (gfp_upperbound RS subsetD) 1); |
5148
74919e8f221c
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5069
diff
changeset
|
44 |
by Auto_tac; |
923 | 45 |
qed "weak_coinduct"; |
46 |
||
47 |
val [prem,mono] = goal Gfp.thy |
|
48 |
"[| X <= f(X Un gfp(f)); mono(f) |] ==> \ |
|
49 |
\ X Un gfp(f) <= f(X Un gfp(f))"; |
|
50 |
by (rtac (prem RS Un_least) 1); |
|
51 |
by (rtac (mono RS gfp_lemma2 RS subset_trans) 1); |
|
52 |
by (rtac (Un_upper2 RS subset_trans) 1); |
|
53 |
by (rtac (mono RS mono_Un) 1); |
|
54 |
qed "coinduct_lemma"; |
|
55 |
||
56 |
(*strong version, thanks to Coen & Frost*) |
|
5148
74919e8f221c
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5069
diff
changeset
|
57 |
Goal "[| mono(f); a: X; X <= f(X Un gfp(f)) |] ==> a : gfp(f)"; |
923 | 58 |
by (rtac (coinduct_lemma RSN (2, weak_coinduct)) 1); |
59 |
by (REPEAT (ares_tac [UnI1, Un_least] 1)); |
|
60 |
qed "coinduct"; |
|
61 |
||
62 |
val [mono,prem] = goal Gfp.thy |
|
63 |
"[| mono(f); a: gfp(f) |] ==> a: f(X Un gfp(f))"; |
|
1465 | 64 |
by (rtac (mono RS mono_Un RS subsetD) 1); |
65 |
by (rtac (mono RS gfp_lemma2 RS subsetD RS UnI2) 1); |
|
923 | 66 |
by (rtac prem 1); |
67 |
qed "gfp_fun_UnI2"; |
|
68 |
||
69 |
(*** Even Stronger version of coinduct [by Martin Coen] |
|
70 |
- instead of the condition X <= f(X) |
|
71 |
consider X <= (f(X) Un f(f(X)) ...) Un gfp(X) ***) |
|
72 |
||
3842 | 73 |
val [prem] = goal Gfp.thy "mono(f) ==> mono(%x. f(x) Un X Un B)"; |
923 | 74 |
by (REPEAT (ares_tac [subset_refl, monoI, Un_mono, prem RS monoD] 1)); |
75 |
qed "coinduct3_mono_lemma"; |
|
76 |
||
77 |
val [prem,mono] = goal Gfp.thy |
|
3842 | 78 |
"[| X <= f(lfp(%x. f(x) Un X Un gfp(f))); mono(f) |] ==> \ |
79 |
\ lfp(%x. f(x) Un X Un gfp(f)) <= f(lfp(%x. f(x) Un X Un gfp(f)))"; |
|
923 | 80 |
by (rtac subset_trans 1); |
81 |
by (rtac (mono RS coinduct3_mono_lemma RS lfp_lemma3) 1); |
|
82 |
by (rtac (Un_least RS Un_least) 1); |
|
83 |
by (rtac subset_refl 1); |
|
84 |
by (rtac prem 1); |
|
85 |
by (rtac (mono RS gfp_Tarski RS equalityD1 RS subset_trans) 1); |
|
86 |
by (rtac (mono RS monoD) 1); |
|
2036 | 87 |
by (stac (mono RS coinduct3_mono_lemma RS lfp_Tarski) 1); |
923 | 88 |
by (rtac Un_upper2 1); |
89 |
qed "coinduct3_lemma"; |
|
90 |
||
91 |
val prems = goal Gfp.thy |
|
3842 | 92 |
"[| mono(f); a:X; X <= f(lfp(%x. f(x) Un X Un gfp(f))) |] ==> a : gfp(f)"; |
923 | 93 |
by (rtac (coinduct3_lemma RSN (2,weak_coinduct)) 1); |
94 |
by (resolve_tac (prems RL [coinduct3_mono_lemma RS lfp_Tarski RS ssubst]) 1); |
|
95 |
by (rtac (UnI2 RS UnI1) 1); |
|
96 |
by (REPEAT (resolve_tac prems 1)); |
|
97 |
qed "coinduct3"; |
|
98 |
||
99 |
||
100 |
(** Definition forms of gfp_Tarski and coinduct, to control unfolding **) |
|
101 |
||
102 |
val [rew,mono] = goal Gfp.thy "[| A==gfp(f); mono(f) |] ==> A = f(A)"; |
|
103 |
by (rewtac rew); |
|
104 |
by (rtac (mono RS gfp_Tarski) 1); |
|
105 |
qed "def_gfp_Tarski"; |
|
106 |
||
107 |
val rew::prems = goal Gfp.thy |
|
108 |
"[| A==gfp(f); mono(f); a:X; X <= f(X Un A) |] ==> a: A"; |
|
109 |
by (rewtac rew); |
|
110 |
by (REPEAT (ares_tac (map (rewrite_rule [rew]) prems @ [coinduct]) 1)); |
|
111 |
qed "def_coinduct"; |
|
112 |
||
113 |
(*The version used in the induction/coinduction package*) |
|
114 |
val prems = goal Gfp.thy |
|
115 |
"[| A == gfp(%w. Collect(P(w))); mono(%w. Collect(P(w))); \ |
|
116 |
\ a: X; !!z. z: X ==> P (X Un A) z |] ==> \ |
|
117 |
\ a : A"; |
|
118 |
by (rtac def_coinduct 1); |
|
119 |
by (REPEAT (ares_tac (prems @ [subsetI,CollectI]) 1)); |
|
120 |
qed "def_Collect_coinduct"; |
|
121 |
||
122 |
val rew::prems = goal Gfp.thy |
|
3842 | 123 |
"[| A==gfp(f); mono(f); a:X; X <= f(lfp(%x. f(x) Un X Un A)) |] ==> a: A"; |
923 | 124 |
by (rewtac rew); |
125 |
by (REPEAT (ares_tac (map (rewrite_rule [rew]) prems @ [coinduct3]) 1)); |
|
126 |
qed "def_coinduct3"; |
|
127 |
||
128 |
(*Monotonicity of gfp!*) |
|
129 |
val [prem] = goal Gfp.thy "[| !!Z. f(Z)<=g(Z) |] ==> gfp(f) <= gfp(g)"; |
|
1465 | 130 |
by (rtac (gfp_upperbound RS gfp_least) 1); |
131 |
by (etac (prem RSN (2,subset_trans)) 1); |
|
923 | 132 |
qed "gfp_mono"; |