0
|
1 |
(* Title: CCL/fix
|
|
2 |
ID: $Id$
|
|
3 |
Author: Martin Coen, Cambridge University Computer Laboratory
|
|
4 |
Copyright 1993 University of Cambridge
|
|
5 |
|
|
6 |
For fix.thy.
|
|
7 |
*)
|
|
8 |
|
|
9 |
open Fix;
|
|
10 |
|
|
11 |
val prems = goalw Fix.thy [INCL_def]
|
|
12 |
"[| !!x.P(x) <-> Q(x) |] ==> INCL(%x.P(x)) <-> INCL(%x.Q(x))";
|
|
13 |
by (REPEAT (ares_tac ([refl] @ FOL_congs @ set_congs @ prems) 1));
|
|
14 |
val INCL_cong = result();
|
|
15 |
|
|
16 |
val fix_congs = [INCL_cong] @ ccl_mk_congs Fix.thy ["napply"];
|
|
17 |
|
|
18 |
(*** Fixed Point Induction ***)
|
|
19 |
|
|
20 |
val [base,step,incl] = goalw Fix.thy [INCL_def]
|
|
21 |
"[| P(bot); !!x.P(x) ==> P(f(x)); INCL(P) |] ==> P(fix(f))";
|
|
22 |
br (incl RS spec RS mp) 1;
|
|
23 |
by (rtac (Nat_ind RS ballI) 1 THEN atac 1);
|
|
24 |
by (ALLGOALS (SIMP_TAC term_ss));
|
|
25 |
by (REPEAT (ares_tac [base,step] 1));
|
|
26 |
val fix_ind = result();
|
|
27 |
|
|
28 |
(*** Inclusive Predicates ***)
|
|
29 |
|
|
30 |
val prems = goalw Fix.thy [INCL_def]
|
|
31 |
"INCL(P) <-> (ALL f. (ALL n:Nat. P(f ^ n ` bot)) --> P(fix(f)))";
|
|
32 |
br iff_refl 1;
|
|
33 |
val inclXH = result();
|
|
34 |
|
|
35 |
val prems = goal Fix.thy
|
|
36 |
"[| !!f.ALL n:Nat.P(f^n`bot) ==> P(fix(f)) |] ==> INCL(%x.P(x))";
|
|
37 |
by (fast_tac (term_cs addIs (prems @ [XH_to_I inclXH])) 1);
|
|
38 |
val inclI = result();
|
|
39 |
|
|
40 |
val incl::prems = goal Fix.thy
|
|
41 |
"[| INCL(P); !!n.n:Nat ==> P(f^n`bot) |] ==> P(fix(f))";
|
|
42 |
by (fast_tac (term_cs addIs ([ballI RS (incl RS (XH_to_D inclXH) RS spec RS mp)]
|
|
43 |
@ prems)) 1);
|
|
44 |
val inclD = result();
|
|
45 |
|
|
46 |
val incl::prems = goal Fix.thy
|
|
47 |
"[| INCL(P); (ALL n:Nat.P(f^n`bot))-->P(fix(f)) ==> R |] ==> R";
|
|
48 |
by (fast_tac (term_cs addIs ([incl RS inclD] @ prems)) 1);
|
|
49 |
val inclE = result();
|
|
50 |
|
|
51 |
val fix_ss = term_ss addcongs fix_congs;
|
|
52 |
|
|
53 |
(*** Lemmas for Inclusive Predicates ***)
|
|
54 |
|
|
55 |
goal Fix.thy "INCL(%x.~ a(x) [= t)";
|
|
56 |
br inclI 1;
|
|
57 |
bd bspec 1;
|
|
58 |
br zeroT 1;
|
|
59 |
be contrapos 1;
|
|
60 |
br po_trans 1;
|
|
61 |
ba 2;
|
|
62 |
br (napplyBzero RS ssubst) 1;
|
|
63 |
by (rtac po_cong 1 THEN rtac po_bot 1);
|
|
64 |
val npo_INCL = result();
|
|
65 |
|
|
66 |
val prems = goal Fix.thy "[| INCL(P); INCL(Q) |] ==> INCL(%x.P(x) & Q(x))";
|
|
67 |
by (fast_tac (set_cs addSIs ([inclI] @ (prems RL [inclD]))) 1);;
|
|
68 |
val conj_INCL = result();
|
|
69 |
|
|
70 |
val prems = goal Fix.thy "[| !!a.INCL(P(a)) |] ==> INCL(%x.ALL a.P(a,x))";
|
|
71 |
by (fast_tac (set_cs addSIs ([inclI] @ (prems RL [inclD]))) 1);;
|
|
72 |
val all_INCL = result();
|
|
73 |
|
|
74 |
val prems = goal Fix.thy "[| !!a.a:A ==> INCL(P(a)) |] ==> INCL(%x.ALL a:A.P(a,x))";
|
|
75 |
by (fast_tac (set_cs addSIs ([inclI] @ (prems RL [inclD]))) 1);;
|
|
76 |
val ball_INCL = result();
|
|
77 |
|
|
78 |
goal Fix.thy "INCL(%x.a(x) = b(x)::'a::prog)";
|
|
79 |
by (SIMP_TAC (fix_ss addrews [eq_iff]) 1);
|
|
80 |
by (REPEAT (resolve_tac [conj_INCL,po_INCL] 1));
|
|
81 |
val eq_INCL = result();
|
|
82 |
|
|
83 |
(*** Derivation of Reachability Condition ***)
|
|
84 |
|
|
85 |
(* Fixed points of idgen *)
|
|
86 |
|
|
87 |
goal Fix.thy "idgen(fix(idgen)) = fix(idgen)";
|
|
88 |
br (fixB RS sym) 1;
|
|
89 |
val fix_idgenfp = result();
|
|
90 |
|
|
91 |
goalw Fix.thy [idgen_def] "idgen(lam x.x) = lam x.x";
|
|
92 |
by (SIMP_TAC term_ss 1);
|
|
93 |
br (term_case RS allI) 1;
|
|
94 |
by (ALLGOALS (SIMP_TAC term_ss));
|
|
95 |
val id_idgenfp = result();
|
|
96 |
|
|
97 |
(* All fixed points are lam-expressions *)
|
|
98 |
|
|
99 |
val [prem] = goal Fix.thy "idgen(d) = d ==> d = lam x.?f(x)";
|
|
100 |
br (prem RS subst) 1;
|
|
101 |
bw idgen_def;
|
|
102 |
br refl 1;
|
|
103 |
val idgenfp_lam = result();
|
|
104 |
|
|
105 |
(* Lemmas for rewriting fixed points of idgen *)
|
|
106 |
|
|
107 |
val prems = goalw Fix.thy [idgen_def]
|
|
108 |
"[| a = b; a ` t = u |] ==> b ` t = u";
|
|
109 |
by (SIMP_TAC (term_ss addrews (prems RL [sym])) 1);
|
|
110 |
val l_lemma= result();
|
|
111 |
|
|
112 |
val idgen_lemmas =
|
|
113 |
let fun mk_thm s = prove_goalw Fix.thy [idgen_def] s
|
|
114 |
(fn [prem] => [rtac (prem RS l_lemma) 1,SIMP_TAC term_ss 1])
|
|
115 |
in map mk_thm
|
|
116 |
[ "idgen(d) = d ==> d ` bot = bot",
|
|
117 |
"idgen(d) = d ==> d ` true = true",
|
|
118 |
"idgen(d) = d ==> d ` false = false",
|
|
119 |
"idgen(d) = d ==> d ` <a,b> = <d ` a,d ` b>",
|
|
120 |
"idgen(d) = d ==> d ` (lam x.f(x)) = lam x.d ` f(x)"]
|
|
121 |
end;
|
|
122 |
|
|
123 |
(* Proof of Reachability law - show that fix and lam x.x both give LEAST fixed points
|
|
124 |
of idgen and hence are they same *)
|
|
125 |
|
|
126 |
val [p1,p2,p3] = goal CCL.thy
|
|
127 |
"[| ALL x.t ` x [= u ` x; EX f.t=lam x.f(x); EX f.u=lam x.f(x) |] ==> t [= u";
|
|
128 |
br (p2 RS cond_eta RS ssubst) 1;
|
|
129 |
br (p3 RS cond_eta RS ssubst) 1;
|
|
130 |
br (p1 RS (po_lam RS iffD2)) 1;
|
|
131 |
val po_eta = result();
|
|
132 |
|
|
133 |
val [prem] = goalw Fix.thy [idgen_def] "idgen(d) = d ==> d = lam x.?f(x)";
|
|
134 |
br (prem RS subst) 1;
|
|
135 |
br refl 1;
|
|
136 |
val po_eta_lemma = result();
|
|
137 |
|
|
138 |
val [prem] = goal Fix.thy
|
|
139 |
"idgen(d) = d ==> \
|
|
140 |
\ {p.EX a b.p=<a,b> & (EX t.a=fix(idgen) ` t & b = d ` t)} <= \
|
|
141 |
\ POgen({p.EX a b.p=<a,b> & (EX t.a=fix(idgen) ` t & b = d ` t)})";
|
|
142 |
by (REPEAT (step_tac term_cs 1));
|
|
143 |
by (term_case_tac "t" 1);
|
|
144 |
by (ALLGOALS (SIMP_TAC (term_ss addrews (POgenXH::([prem,fix_idgenfp] RL idgen_lemmas)))));
|
|
145 |
by (ALLGOALS (fast_tac set_cs));
|
|
146 |
val lemma1 = result();
|
|
147 |
|
|
148 |
val [prem] = goal Fix.thy
|
|
149 |
"idgen(d) = d ==> fix(idgen) [= d";
|
|
150 |
br (allI RS po_eta) 1;
|
|
151 |
br (lemma1 RSN(2,po_coinduct)) 1;
|
|
152 |
by (ALLGOALS (fast_tac (term_cs addIs [prem,po_eta_lemma,fix_idgenfp])));
|
|
153 |
val fix_least_idgen = result();
|
|
154 |
|
|
155 |
val [prem] = goal Fix.thy
|
|
156 |
"idgen(d) = d ==> \
|
|
157 |
\ {p.EX a b.p=<a,b> & b = d ` a} <= POgen({p.EX a b.p=<a,b> & b = d ` a})";
|
|
158 |
by (REPEAT (step_tac term_cs 1));
|
|
159 |
by (term_case_tac "a" 1);
|
|
160 |
by (ALLGOALS (SIMP_TAC (term_ss addrews (POgenXH::([prem] RL idgen_lemmas)))));
|
|
161 |
by (ALLGOALS (fast_tac set_cs));
|
|
162 |
val lemma2 = result();
|
|
163 |
|
|
164 |
val [prem] = goal Fix.thy
|
|
165 |
"idgen(d) = d ==> lam x.x [= d";
|
|
166 |
br (allI RS po_eta) 1;
|
|
167 |
br (lemma2 RSN(2,po_coinduct)) 1;
|
|
168 |
by (SIMP_TAC term_ss 1);
|
|
169 |
by (ALLGOALS (fast_tac (term_cs addIs [prem,po_eta_lemma,fix_idgenfp])));
|
|
170 |
val id_least_idgen = result();
|
|
171 |
|
|
172 |
goal Fix.thy "fix(idgen) = lam x.x";
|
|
173 |
by (fast_tac (term_cs addIs [eq_iff RS iffD2,
|
|
174 |
id_idgenfp RS fix_least_idgen,
|
|
175 |
fix_idgenfp RS id_least_idgen]) 1);
|
|
176 |
val reachability = result();
|
|
177 |
|
|
178 |
(********)
|
|
179 |
|
|
180 |
val [prem] = goal Fix.thy "f = lam x.x ==> f`t = t";
|
|
181 |
br (prem RS sym RS subst) 1;
|
|
182 |
br applyB 1;
|
|
183 |
val id_apply = result();
|
|
184 |
|
|
185 |
val prems = goal Fix.thy
|
|
186 |
"[| P(bot); P(true); P(false); \
|
|
187 |
\ !!x y.[| P(x); P(y) |] ==> P(<x,y>); \
|
|
188 |
\ !!u.(!!x.P(u(x))) ==> P(lam x.u(x)); INCL(P) |] ==> \
|
|
189 |
\ P(t)";
|
|
190 |
br (reachability RS id_apply RS subst) 1;
|
|
191 |
by (res_inst_tac [("x","t")] spec 1);
|
|
192 |
br fix_ind 1;
|
|
193 |
bw idgen_def;
|
|
194 |
by (REPEAT_SOME (ares_tac [allI]));
|
|
195 |
br (applyBbot RS ssubst) 1;
|
|
196 |
brs prems 1;
|
|
197 |
br (applyB RS ssubst )1;
|
|
198 |
by (res_inst_tac [("t","xa")] term_case 1);
|
|
199 |
by (ALLGOALS (SIMP_TAC term_ss));
|
|
200 |
by (ALLGOALS (fast_tac (term_cs addIs ([all_INCL,INCL_subst] @ prems))));
|
|
201 |
val term_ind = result();
|
|
202 |
|