3071
|
1 |
(* Title: HOLCF/IOA/meta_theory/Sequence.ML
|
3275
|
2 |
ID: $Id$
|
3071
|
3 |
Author: Olaf M"uller
|
|
4 |
Copyright 1996 TU Muenchen
|
|
5 |
|
|
6 |
Theorems about Sequences over flat domains with lifted elements
|
|
7 |
|
|
8 |
*)
|
|
9 |
|
|
10 |
|
|
11 |
Addsimps [andalso_and,andalso_or];
|
|
12 |
|
|
13 |
(* ----------------------------------------------------------------------------------- *)
|
|
14 |
|
|
15 |
section "recursive equations of operators";
|
|
16 |
|
|
17 |
(* ---------------------------------------------------------------- *)
|
|
18 |
(* Map *)
|
|
19 |
(* ---------------------------------------------------------------- *)
|
|
20 |
|
|
21 |
goal thy "Map f`UU =UU";
|
|
22 |
by (simp_tac (!simpset addsimps [Map_def]) 1);
|
|
23 |
qed"Map_UU";
|
|
24 |
|
|
25 |
goal thy "Map f`nil =nil";
|
|
26 |
by (simp_tac (!simpset addsimps [Map_def]) 1);
|
|
27 |
qed"Map_nil";
|
|
28 |
|
|
29 |
goal thy "Map f`(x>>xs)=(f x) >> Map f`xs";
|
|
30 |
by (simp_tac (!simpset addsimps [Map_def, Cons_def,flift2_def]) 1);
|
|
31 |
qed"Map_cons";
|
|
32 |
|
|
33 |
(* ---------------------------------------------------------------- *)
|
|
34 |
(* Filter *)
|
|
35 |
(* ---------------------------------------------------------------- *)
|
|
36 |
|
|
37 |
goal thy "Filter P`UU =UU";
|
|
38 |
by (simp_tac (!simpset addsimps [Filter_def]) 1);
|
|
39 |
qed"Filter_UU";
|
|
40 |
|
|
41 |
goal thy "Filter P`nil =nil";
|
|
42 |
by (simp_tac (!simpset addsimps [Filter_def]) 1);
|
|
43 |
qed"Filter_nil";
|
|
44 |
|
|
45 |
goal thy "Filter P`(x>>xs)= (if P x then x>>(Filter P`xs) else Filter P`xs)";
|
|
46 |
by (simp_tac (!simpset addsimps [Filter_def, Cons_def,flift2_def,If_and_if]) 1);
|
|
47 |
qed"Filter_cons";
|
|
48 |
|
|
49 |
(* ---------------------------------------------------------------- *)
|
|
50 |
(* Forall *)
|
|
51 |
(* ---------------------------------------------------------------- *)
|
|
52 |
|
|
53 |
goal thy "Forall P UU";
|
|
54 |
by (simp_tac (!simpset addsimps [Forall_def,sforall_def]) 1);
|
|
55 |
qed"Forall_UU";
|
|
56 |
|
|
57 |
goal thy "Forall P nil";
|
|
58 |
by (simp_tac (!simpset addsimps [Forall_def,sforall_def]) 1);
|
|
59 |
qed"Forall_nil";
|
|
60 |
|
|
61 |
goal thy "Forall P (x>>xs)= (P x & Forall P xs)";
|
|
62 |
by (simp_tac (!simpset addsimps [Forall_def, sforall_def,
|
|
63 |
Cons_def,flift2_def]) 1);
|
|
64 |
qed"Forall_cons";
|
|
65 |
|
|
66 |
(* ---------------------------------------------------------------- *)
|
|
67 |
(* Conc *)
|
|
68 |
(* ---------------------------------------------------------------- *)
|
|
69 |
|
|
70 |
|
|
71 |
goal thy "(x>>xs) @@ y = x>>(xs @@y)";
|
|
72 |
by (simp_tac (!simpset addsimps [Cons_def]) 1);
|
|
73 |
qed"Conc_cons";
|
|
74 |
|
|
75 |
(* ---------------------------------------------------------------- *)
|
|
76 |
(* Takewhile *)
|
|
77 |
(* ---------------------------------------------------------------- *)
|
|
78 |
|
|
79 |
goal thy "Takewhile P`UU =UU";
|
|
80 |
by (simp_tac (!simpset addsimps [Takewhile_def]) 1);
|
|
81 |
qed"Takewhile_UU";
|
|
82 |
|
|
83 |
goal thy "Takewhile P`nil =nil";
|
|
84 |
by (simp_tac (!simpset addsimps [Takewhile_def]) 1);
|
|
85 |
qed"Takewhile_nil";
|
|
86 |
|
|
87 |
goal thy "Takewhile P`(x>>xs)= (if P x then x>>(Takewhile P`xs) else nil)";
|
|
88 |
by (simp_tac (!simpset addsimps [Takewhile_def, Cons_def,flift2_def,If_and_if]) 1);
|
|
89 |
qed"Takewhile_cons";
|
|
90 |
|
|
91 |
(* ---------------------------------------------------------------- *)
|
|
92 |
(* Dropwhile *)
|
|
93 |
(* ---------------------------------------------------------------- *)
|
|
94 |
|
|
95 |
goal thy "Dropwhile P`UU =UU";
|
|
96 |
by (simp_tac (!simpset addsimps [Dropwhile_def]) 1);
|
|
97 |
qed"Dropwhile_UU";
|
|
98 |
|
|
99 |
goal thy "Dropwhile P`nil =nil";
|
|
100 |
by (simp_tac (!simpset addsimps [Dropwhile_def]) 1);
|
|
101 |
qed"Dropwhile_nil";
|
|
102 |
|
|
103 |
goal thy "Dropwhile P`(x>>xs)= (if P x then Dropwhile P`xs else x>>xs)";
|
|
104 |
by (simp_tac (!simpset addsimps [Dropwhile_def, Cons_def,flift2_def,If_and_if]) 1);
|
|
105 |
qed"Dropwhile_cons";
|
|
106 |
|
|
107 |
(* ---------------------------------------------------------------- *)
|
|
108 |
(* Last *)
|
|
109 |
(* ---------------------------------------------------------------- *)
|
|
110 |
|
|
111 |
|
|
112 |
goal thy "Last`UU =UU";
|
|
113 |
by (simp_tac (!simpset addsimps [Last_def]) 1);
|
|
114 |
qed"Last_UU";
|
|
115 |
|
|
116 |
goal thy "Last`nil =UU";
|
|
117 |
by (simp_tac (!simpset addsimps [Last_def]) 1);
|
|
118 |
qed"Last_nil";
|
|
119 |
|
|
120 |
goal thy "Last`(x>>xs)= (if xs=nil then Def x else Last`xs)";
|
|
121 |
by (simp_tac (!simpset addsimps [Last_def, Cons_def]) 1);
|
|
122 |
by (res_inst_tac [("x","xs")] seq.cases 1);
|
|
123 |
by (asm_simp_tac (!simpset setloop split_tac [expand_if]) 1);
|
|
124 |
by (REPEAT (Asm_simp_tac 1));
|
|
125 |
qed"Last_cons";
|
|
126 |
|
|
127 |
|
|
128 |
(* ---------------------------------------------------------------- *)
|
|
129 |
(* Flat *)
|
|
130 |
(* ---------------------------------------------------------------- *)
|
|
131 |
|
|
132 |
goal thy "Flat`UU =UU";
|
|
133 |
by (simp_tac (!simpset addsimps [Flat_def]) 1);
|
|
134 |
qed"Flat_UU";
|
|
135 |
|
|
136 |
goal thy "Flat`nil =nil";
|
|
137 |
by (simp_tac (!simpset addsimps [Flat_def]) 1);
|
|
138 |
qed"Flat_nil";
|
|
139 |
|
|
140 |
goal thy "Flat`(x##xs)= x @@ (Flat`xs)";
|
|
141 |
by (simp_tac (!simpset addsimps [Flat_def, Cons_def]) 1);
|
|
142 |
qed"Flat_cons";
|
|
143 |
|
|
144 |
|
|
145 |
(* ---------------------------------------------------------------- *)
|
|
146 |
(* Zip *)
|
|
147 |
(* ---------------------------------------------------------------- *)
|
|
148 |
|
|
149 |
goal thy "Zip = (LAM t1 t2. case t1 of \
|
|
150 |
\ nil => nil \
|
|
151 |
\ | x##xs => (case t2 of \
|
|
152 |
\ nil => UU \
|
|
153 |
\ | y##ys => (case x of \
|
|
154 |
\ Undef => UU \
|
|
155 |
\ | Def a => (case y of \
|
|
156 |
\ Undef => UU \
|
|
157 |
\ | Def b => Def (a,b)##(Zip`xs`ys)))))";
|
|
158 |
by (rtac trans 1);
|
|
159 |
br fix_eq2 1;
|
|
160 |
br Zip_def 1;
|
|
161 |
br beta_cfun 1;
|
|
162 |
by (Simp_tac 1);
|
|
163 |
qed"Zip_unfold";
|
|
164 |
|
|
165 |
goal thy "Zip`UU`y =UU";
|
|
166 |
by (stac Zip_unfold 1);
|
|
167 |
by (Simp_tac 1);
|
|
168 |
qed"Zip_UU1";
|
|
169 |
|
|
170 |
goal thy "!! x. x~=nil ==> Zip`x`UU =UU";
|
|
171 |
by (stac Zip_unfold 1);
|
|
172 |
by (Simp_tac 1);
|
|
173 |
by (res_inst_tac [("x","x")] seq.cases 1);
|
|
174 |
by (REPEAT (Asm_full_simp_tac 1));
|
|
175 |
qed"Zip_UU2";
|
|
176 |
|
|
177 |
goal thy "Zip`nil`y =nil";
|
|
178 |
by (stac Zip_unfold 1);
|
|
179 |
by (Simp_tac 1);
|
|
180 |
qed"Zip_nil";
|
|
181 |
|
|
182 |
goal thy "Zip`(x>>xs)`nil= UU";
|
|
183 |
by (stac Zip_unfold 1);
|
|
184 |
by (simp_tac (!simpset addsimps [Cons_def]) 1);
|
|
185 |
qed"Zip_cons_nil";
|
|
186 |
|
|
187 |
goal thy "Zip`(x>>xs)`(y>>ys)= (x,y) >> Zip`xs`ys";
|
|
188 |
br trans 1;
|
|
189 |
by (stac Zip_unfold 1);
|
|
190 |
by (Simp_tac 1);
|
|
191 |
(* FIX: Why Simp_tac 2 times. Does continuity in simpflication make job sometimes not
|
|
192 |
completely ready ? *)
|
|
193 |
by (simp_tac (!simpset addsimps [Cons_def]) 1);
|
|
194 |
qed"Zip_cons";
|
|
195 |
|
|
196 |
|
|
197 |
Delsimps [sfilter_UU,sfilter_nil,sfilter_cons,
|
|
198 |
smap_UU,smap_nil,smap_cons,
|
|
199 |
sforall2_UU,sforall2_nil,sforall2_cons,
|
|
200 |
slast_UU,slast_nil,slast_cons,
|
|
201 |
stakewhile_UU, stakewhile_nil, stakewhile_cons,
|
|
202 |
sdropwhile_UU, sdropwhile_nil, sdropwhile_cons,
|
|
203 |
sflat_UU,sflat_nil,sflat_cons,
|
|
204 |
szip_UU1,szip_UU2,szip_nil,szip_cons_nil,szip_cons];
|
|
205 |
|
|
206 |
|
|
207 |
Addsimps [Filter_UU,Filter_nil,Filter_cons,
|
|
208 |
Map_UU,Map_nil,Map_cons,
|
|
209 |
Forall_UU,Forall_nil,Forall_cons,
|
|
210 |
Last_UU,Last_nil,Last_cons,
|
3275
|
211 |
Conc_cons,
|
3071
|
212 |
Takewhile_UU, Takewhile_nil, Takewhile_cons,
|
|
213 |
Dropwhile_UU, Dropwhile_nil, Dropwhile_cons,
|
|
214 |
Zip_UU1,Zip_UU2,Zip_nil,Zip_cons_nil,Zip_cons];
|
|
215 |
|
|
216 |
|
|
217 |
(*
|
|
218 |
|
|
219 |
Can Filter with HOL predicate directly be defined as fixpoint ?
|
|
220 |
|
|
221 |
goal thy "Filter2 P = (LAM tr. case tr of \
|
|
222 |
\ nil => nil \
|
|
223 |
\ | x##xs => (case x of Undef => UU | Def y => \
|
|
224 |
\ (if P y then y>>(Filter2 P`xs) else Filter2 P`xs)))";
|
|
225 |
by (rtac trans 1);
|
|
226 |
br fix_eq2 1;
|
|
227 |
br Filter2_def 1;
|
|
228 |
br beta_cfun 1;
|
|
229 |
by (Simp_tac 1);
|
|
230 |
|
|
231 |
is also possible, if then else has to be proven continuous and it would be nice if a case for
|
|
232 |
Seq would be available.
|
|
233 |
|
|
234 |
*)
|
|
235 |
|
|
236 |
|
|
237 |
(* ------------------------------------------------------------------------------------- *)
|
|
238 |
|
|
239 |
|
|
240 |
section "Cons";
|
|
241 |
|
|
242 |
goal thy "a>>s = (Def a)##s";
|
|
243 |
by (simp_tac (!simpset addsimps [Cons_def]) 1);
|
|
244 |
qed"Cons_def2";
|
|
245 |
|
|
246 |
goal thy "x = UU | x = nil | (? a s. x = a >> s)";
|
|
247 |
by (simp_tac (!simpset addsimps [Cons_def2]) 1);
|
|
248 |
by (cut_facts_tac [seq.exhaust] 1);
|
|
249 |
by (fast_tac (HOL_cs addDs [not_Undef_is_Def RS iffD1]) 1);
|
|
250 |
qed"Seq_exhaust";
|
|
251 |
|
|
252 |
|
|
253 |
goal thy "!!P. [| x = UU ==> P; x = nil ==> P; !!a s. x = a >> s ==> P |] ==> P";
|
|
254 |
by (cut_inst_tac [("x","x")] Seq_exhaust 1);
|
|
255 |
be disjE 1;
|
|
256 |
by (Asm_full_simp_tac 1);
|
|
257 |
be disjE 1;
|
|
258 |
by (Asm_full_simp_tac 1);
|
|
259 |
by (REPEAT (etac exE 1));
|
|
260 |
by (Asm_full_simp_tac 1);
|
|
261 |
qed"Seq_cases";
|
|
262 |
|
|
263 |
fun Seq_case_tac s i = res_inst_tac [("x",s)] Seq_cases i
|
|
264 |
THEN hyp_subst_tac i THEN hyp_subst_tac (i+1) THEN hyp_subst_tac (i+2);
|
|
265 |
|
|
266 |
(* on a>>s only simp_tac, as full_simp_tac is uncomplete and often causes errors *)
|
|
267 |
fun Seq_case_simp_tac s i = Seq_case_tac s i THEN Asm_simp_tac (i+2)
|
|
268 |
THEN Asm_full_simp_tac (i+1)
|
|
269 |
THEN Asm_full_simp_tac i;
|
|
270 |
|
|
271 |
goal thy "a>>s ~= UU";
|
|
272 |
by (stac Cons_def2 1);
|
|
273 |
by (resolve_tac seq.con_rews 1);
|
|
274 |
br Def_not_UU 1;
|
|
275 |
qed"Cons_not_UU";
|
|
276 |
|
3275
|
277 |
|
3071
|
278 |
goal thy "~(a>>x) << UU";
|
|
279 |
by (rtac notI 1);
|
|
280 |
by (dtac antisym_less 1);
|
|
281 |
by (Simp_tac 1);
|
|
282 |
by (asm_full_simp_tac (!simpset addsimps [Cons_not_UU]) 1);
|
|
283 |
qed"Cons_not_less_UU";
|
|
284 |
|
|
285 |
goal thy "~a>>s << nil";
|
|
286 |
by (stac Cons_def2 1);
|
|
287 |
by (resolve_tac seq.rews 1);
|
|
288 |
br Def_not_UU 1;
|
|
289 |
qed"Cons_not_less_nil";
|
|
290 |
|
|
291 |
goal thy "a>>s ~= nil";
|
|
292 |
by (stac Cons_def2 1);
|
|
293 |
by (resolve_tac seq.rews 1);
|
|
294 |
qed"Cons_not_nil";
|
|
295 |
|
3275
|
296 |
goal thy "nil ~= a>>s";
|
|
297 |
by (simp_tac (!simpset addsimps [Cons_def2]) 1);
|
|
298 |
qed"Cons_not_nil2";
|
|
299 |
|
3071
|
300 |
goal thy "(a>>s = b>>t) = (a = b & s = t)";
|
|
301 |
by (simp_tac (HOL_ss addsimps [Cons_def2]) 1);
|
|
302 |
by (stac (hd lift.inject RS sym) 1);
|
|
303 |
back(); back();
|
|
304 |
by (rtac scons_inject_eq 1);
|
|
305 |
by (REPEAT(rtac Def_not_UU 1));
|
|
306 |
qed"Cons_inject_eq";
|
|
307 |
|
|
308 |
goal thy "(a>>s<<b>>t) = (a = b & s<<t)";
|
|
309 |
by (simp_tac (!simpset addsimps [Cons_def2]) 1);
|
|
310 |
by (stac (Def_inject_less_eq RS sym) 1);
|
|
311 |
back();
|
|
312 |
by (rtac iffI 1);
|
|
313 |
(* 1 *)
|
|
314 |
by (etac (hd seq.inverts) 1);
|
|
315 |
by (REPEAT(rtac Def_not_UU 1));
|
|
316 |
(* 2 *)
|
|
317 |
by (Asm_full_simp_tac 1);
|
|
318 |
by (etac conjE 1);
|
|
319 |
by (etac monofun_cfun_arg 1);
|
|
320 |
qed"Cons_inject_less_eq";
|
|
321 |
|
|
322 |
goal thy "seq_take (Suc n)`(a>>x) = a>> (seq_take n`x)";
|
|
323 |
by (simp_tac (!simpset addsimps [Cons_def]) 1);
|
|
324 |
qed"seq_take_Cons";
|
|
325 |
|
3275
|
326 |
Addsimps [Cons_not_nil2,Cons_inject_eq,Cons_inject_less_eq,seq_take_Cons,
|
3071
|
327 |
Cons_not_UU,Cons_not_less_UU,Cons_not_less_nil,Cons_not_nil];
|
|
328 |
|
3275
|
329 |
(* Instead of adding UU_neq_Cons every equation UU~=x could be changed to x~=UU *)
|
|
330 |
goal thy "UU ~= x>>xs";
|
|
331 |
by (res_inst_tac [("s1","UU"),("t1","x>>xs")] (sym RS rev_contrapos) 1);
|
|
332 |
by (REPEAT (Simp_tac 1));
|
|
333 |
qed"UU_neq_Cons";
|
|
334 |
|
|
335 |
Addsimps [UU_neq_Cons];
|
|
336 |
|
3071
|
337 |
|
|
338 |
(* ----------------------------------------------------------------------------------- *)
|
|
339 |
|
|
340 |
section "induction";
|
|
341 |
|
|
342 |
goal thy "!! P. [| adm P; P UU; P nil; !! a s. P s ==> P (a>>s)|] ==> P x";
|
|
343 |
be seq.ind 1;
|
|
344 |
by (REPEAT (atac 1));
|
|
345 |
by (def_tac 1);
|
|
346 |
by (asm_full_simp_tac (!simpset addsimps [Cons_def]) 1);
|
|
347 |
qed"Seq_induct";
|
|
348 |
|
|
349 |
goal thy "!! P.[|P UU;P nil; !! a s. P s ==> P(a>>s) |] \
|
|
350 |
\ ==> seq_finite x --> P x";
|
|
351 |
be seq_finite_ind 1;
|
|
352 |
by (REPEAT (atac 1));
|
|
353 |
by (def_tac 1);
|
|
354 |
by (asm_full_simp_tac (!simpset addsimps [Cons_def]) 1);
|
|
355 |
qed"Seq_FinitePartial_ind";
|
|
356 |
|
|
357 |
goal thy "!! P.[| Finite x; P nil; !! a s. [| Finite s; P s|] ==> P (a>>s) |] ==> P x";
|
|
358 |
be sfinite.induct 1;
|
|
359 |
ba 1;
|
|
360 |
by (def_tac 1);
|
|
361 |
by (asm_full_simp_tac (!simpset addsimps [Cons_def]) 1);
|
|
362 |
qed"Seq_Finite_ind";
|
|
363 |
|
|
364 |
|
|
365 |
(* rws are definitions to be unfolded for admissibility check *)
|
|
366 |
fun Seq_induct_tac s rws i = res_inst_tac [("x",s)] Seq_induct i
|
|
367 |
THEN (REPEAT_DETERM (CHANGED (Asm_simp_tac (i+1))))
|
|
368 |
THEN simp_tac (!simpset addsimps rws) i;
|
|
369 |
|
|
370 |
fun Seq_Finite_induct_tac i = etac Seq_Finite_ind i
|
|
371 |
THEN (REPEAT_DETERM (CHANGED (Asm_simp_tac i)));
|
|
372 |
|
|
373 |
fun pair_tac s = res_inst_tac [("p",s)] PairE
|
|
374 |
THEN' hyp_subst_tac THEN' Asm_full_simp_tac;
|
|
375 |
|
|
376 |
(* induction on a sequence of pairs with pairsplitting and simplification *)
|
|
377 |
fun pair_induct_tac s rws i =
|
|
378 |
res_inst_tac [("x",s)] Seq_induct i
|
|
379 |
THEN pair_tac "a" (i+3)
|
|
380 |
THEN (REPEAT_DETERM (CHANGED (Simp_tac (i+1))))
|
|
381 |
THEN simp_tac (!simpset addsimps rws) i;
|
|
382 |
|
|
383 |
|
|
384 |
|
|
385 |
(* ------------------------------------------------------------------------------------ *)
|
|
386 |
|
|
387 |
section "HD,TL";
|
|
388 |
|
|
389 |
goal thy "HD`(x>>y) = Def x";
|
|
390 |
by (simp_tac (!simpset addsimps [Cons_def]) 1);
|
|
391 |
qed"HD_Cons";
|
|
392 |
|
|
393 |
goal thy "TL`(x>>y) = y";
|
|
394 |
by (simp_tac (!simpset addsimps [Cons_def]) 1);
|
|
395 |
qed"TL_Cons";
|
|
396 |
|
|
397 |
Addsimps [HD_Cons,TL_Cons];
|
|
398 |
|
|
399 |
(* ------------------------------------------------------------------------------------ *)
|
|
400 |
|
|
401 |
section "Finite, Partial, Infinite";
|
|
402 |
|
|
403 |
goal thy "Finite (a>>xs) = Finite xs";
|
|
404 |
by (simp_tac (!simpset addsimps [Cons_def2,Finite_cons]) 1);
|
|
405 |
qed"Finite_Cons";
|
|
406 |
|
|
407 |
Addsimps [Finite_Cons];
|
3275
|
408 |
goal thy "!! x. Finite (x::'a Seq) ==> Finite y --> Finite (x@@y)";
|
|
409 |
by (Seq_Finite_induct_tac 1);
|
|
410 |
qed"FiniteConc_1";
|
|
411 |
|
|
412 |
goal thy "!! z. Finite (z::'a Seq) ==> !x y. z= x@@y --> (Finite x & Finite y)";
|
|
413 |
by (Seq_Finite_induct_tac 1);
|
|
414 |
(* nil*)
|
|
415 |
by (strip_tac 1);
|
|
416 |
by (Seq_case_simp_tac "x" 1);
|
|
417 |
by (hyp_subst_tac 1);
|
|
418 |
by (Asm_full_simp_tac 1);
|
|
419 |
by (Asm_full_simp_tac 1);
|
|
420 |
(* cons *)
|
|
421 |
by (strip_tac 1);
|
|
422 |
by (Seq_case_simp_tac "x" 1);
|
|
423 |
by (Seq_case_simp_tac "y" 1);
|
|
424 |
by (SELECT_GOAL (auto_tac (!claset,!simpset))1);
|
|
425 |
by (eres_inst_tac [("x","sa")] allE 1);
|
|
426 |
by (eres_inst_tac [("x","y")] allE 1);
|
|
427 |
by (Asm_full_simp_tac 1);
|
|
428 |
qed"FiniteConc_2";
|
|
429 |
|
|
430 |
goal thy "Finite(x@@y) = (Finite (x::'a Seq) & Finite y)";
|
|
431 |
by (rtac iffI 1);
|
|
432 |
be (FiniteConc_2 RS spec RS spec RS mp) 1;
|
|
433 |
br refl 1;
|
|
434 |
br (FiniteConc_1 RS mp) 1;
|
|
435 |
auto();
|
|
436 |
qed"FiniteConc";
|
|
437 |
|
|
438 |
Addsimps [FiniteConc];
|
|
439 |
|
|
440 |
|
|
441 |
goal thy "!! s. Finite s ==> Finite (Map f`s)";
|
|
442 |
by (Seq_Finite_induct_tac 1);
|
|
443 |
qed"FiniteMap1";
|
|
444 |
|
|
445 |
goal thy "!! s. Finite s ==> ! t. (s = Map f`t) --> Finite t";
|
|
446 |
by (Seq_Finite_induct_tac 1);
|
|
447 |
by (strip_tac 1);
|
|
448 |
by (Seq_case_simp_tac "t" 1);
|
|
449 |
by (Asm_full_simp_tac 1);
|
|
450 |
(* main case *)
|
|
451 |
auto();
|
|
452 |
by (Seq_case_simp_tac "t" 1);
|
|
453 |
by (Asm_full_simp_tac 1);
|
|
454 |
qed"FiniteMap2";
|
|
455 |
|
|
456 |
goal thy "Finite (Map f`s) = Finite s";
|
|
457 |
auto();
|
|
458 |
be (FiniteMap2 RS spec RS mp) 1;
|
|
459 |
br refl 1;
|
|
460 |
be FiniteMap1 1;
|
|
461 |
qed"Map2Finite";
|
|
462 |
|
3071
|
463 |
|
|
464 |
(* ------------------------------------------------------------------------------------ *)
|
|
465 |
|
|
466 |
section "Conc";
|
|
467 |
|
|
468 |
goal thy "!! x::'a Seq. Finite x ==> ((x @@ y) = (x @@ z)) = (y = z)";
|
|
469 |
by (Seq_Finite_induct_tac 1);
|
|
470 |
qed"Conc_cong";
|
|
471 |
|
3275
|
472 |
goal thy "(x @@ y) @@ z = (x::'a Seq) @@ y @@ z";
|
|
473 |
by (Seq_induct_tac "x" [] 1);
|
|
474 |
qed"Conc_assoc";
|
|
475 |
|
|
476 |
goal thy "s@@ nil = s";
|
|
477 |
by (res_inst_tac[("x","s")] seq.ind 1);
|
|
478 |
by (Simp_tac 1);
|
|
479 |
by (Simp_tac 1);
|
|
480 |
by (Simp_tac 1);
|
|
481 |
by (Asm_full_simp_tac 1);
|
|
482 |
qed"nilConc";
|
|
483 |
|
|
484 |
Addsimps [nilConc];
|
|
485 |
|
|
486 |
|
3071
|
487 |
(* ------------------------------------------------------------------------------------ *)
|
|
488 |
|
|
489 |
section "Last";
|
|
490 |
|
|
491 |
goal thy "!! s.Finite s ==> s~=nil --> Last`s~=UU";
|
|
492 |
by (Seq_Finite_induct_tac 1);
|
|
493 |
by (asm_simp_tac (!simpset setloop split_tac [expand_if]) 1);
|
|
494 |
qed"Finite_Last1";
|
|
495 |
|
|
496 |
goal thy "!! s. Finite s ==> Last`s=UU --> s=nil";
|
|
497 |
by (Seq_Finite_induct_tac 1);
|
|
498 |
by (asm_simp_tac (!simpset setloop split_tac [expand_if]) 1);
|
|
499 |
by (fast_tac HOL_cs 1);
|
|
500 |
qed"Finite_Last2";
|
|
501 |
|
|
502 |
|
|
503 |
(* ------------------------------------------------------------------------------------ *)
|
|
504 |
|
|
505 |
|
|
506 |
section "Filter, Conc";
|
|
507 |
|
|
508 |
|
|
509 |
goal thy "Filter P`(Filter Q`s) = Filter (%x. P x & Q x)`s";
|
|
510 |
by (Seq_induct_tac "s" [Filter_def] 1);
|
|
511 |
by (asm_full_simp_tac (!simpset setloop split_tac [expand_if] ) 1);
|
|
512 |
qed"FilterPQ";
|
|
513 |
|
|
514 |
goal thy "Filter P`(x @@ y) = (Filter P`x @@ Filter P`y)";
|
|
515 |
by (simp_tac (!simpset addsimps [Filter_def,sfiltersconc]) 1);
|
|
516 |
qed"FilterConc";
|
|
517 |
|
|
518 |
(* ------------------------------------------------------------------------------------ *)
|
|
519 |
|
|
520 |
section "Map";
|
|
521 |
|
|
522 |
goal thy "Map f`(Map g`s) = Map (f o g)`s";
|
|
523 |
by (Seq_induct_tac "s" [] 1);
|
|
524 |
qed"MapMap";
|
|
525 |
|
|
526 |
goal thy "Map f`(x@@y) = (Map f`x) @@ (Map f`y)";
|
|
527 |
by (Seq_induct_tac "x" [] 1);
|
|
528 |
qed"MapConc";
|
|
529 |
|
|
530 |
goal thy "Filter P`(Map f`x) = Map f`(Filter (P o f)`x)";
|
|
531 |
by (Seq_induct_tac "x" [] 1);
|
|
532 |
by (asm_full_simp_tac (!simpset setloop split_tac [expand_if] ) 1);
|
|
533 |
qed"MapFilter";
|
|
534 |
|
3275
|
535 |
goal thy "nil = (Map f`s) --> s= nil";
|
|
536 |
by (Seq_case_simp_tac "s" 1);
|
|
537 |
qed"nilMap";
|
|
538 |
|
|
539 |
goal thy "Forall P (Map f`s) --> Forall (P o f) s";
|
|
540 |
by (Seq_induct_tac "s" [Forall_def,sforall_def] 1);
|
|
541 |
auto();
|
|
542 |
qed"ForallMap1";
|
|
543 |
|
|
544 |
|
|
545 |
goal thy "Forall (P o f) s --> Forall P (Map f`s) ";
|
|
546 |
by (Seq_induct_tac "s" [Forall_def,sforall_def] 1);
|
|
547 |
auto();
|
|
548 |
qed"ForallMap2";
|
|
549 |
|
|
550 |
(* FIX: should be proved directly. Therefore adm lemma for equalitys on _bools_ has
|
|
551 |
to be added to !simpset *)
|
|
552 |
goal thy "Forall P (Map f`s) = Forall (P o f) s";
|
|
553 |
auto();
|
|
554 |
be (ForallMap1 RS mp) 1;
|
|
555 |
be (ForallMap2 RS mp) 1;
|
|
556 |
qed"ForallMap";
|
|
557 |
|
3071
|
558 |
|
|
559 |
(* ------------------------------------------------------------------------------------ *)
|
|
560 |
|
3275
|
561 |
section "Forall";
|
3071
|
562 |
|
|
563 |
|
|
564 |
goal thy "Forall P ys & (! x. P x --> Q x) \
|
|
565 |
\ --> Forall Q ys";
|
|
566 |
by (Seq_induct_tac "ys" [Forall_def,sforall_def] 1);
|
|
567 |
qed"ForallPForallQ1";
|
|
568 |
|
|
569 |
bind_thm ("ForallPForallQ",impI RSN (2,allI RSN (2,conjI RS (ForallPForallQ1 RS mp))));
|
|
570 |
|
|
571 |
goal thy "(Forall P x & Forall P y) --> Forall P (x @@ y)";
|
|
572 |
by (Seq_induct_tac "x" [Forall_def,sforall_def] 1);
|
|
573 |
qed"Forall_Conc_impl";
|
|
574 |
|
|
575 |
goal thy "!! x. Finite x ==> Forall P (x @@ y) = (Forall P x & Forall P y)";
|
|
576 |
by (Seq_Finite_induct_tac 1);
|
|
577 |
qed"Forall_Conc";
|
|
578 |
|
3275
|
579 |
Addsimps [Forall_Conc];
|
|
580 |
|
|
581 |
goal thy "Forall P s --> Forall P (TL`s)";
|
|
582 |
by (Seq_induct_tac "s" [Forall_def,sforall_def] 1);
|
|
583 |
qed"ForallTL1";
|
|
584 |
|
|
585 |
bind_thm ("ForallTL",ForallTL1 RS mp);
|
|
586 |
|
|
587 |
goal thy "Forall P s --> Forall P (Dropwhile Q`s)";
|
|
588 |
by (Seq_induct_tac "s" [Forall_def,sforall_def] 1);
|
|
589 |
by (asm_full_simp_tac (!simpset setloop (split_tac [expand_if])) 1);
|
|
590 |
qed"ForallDropwhile1";
|
|
591 |
|
|
592 |
bind_thm ("ForallDropwhile",ForallDropwhile1 RS mp);
|
|
593 |
|
|
594 |
|
|
595 |
(* only admissible in t, not if done in s *)
|
|
596 |
|
|
597 |
goal thy "! s. Forall P s --> t<<s --> Forall P t";
|
|
598 |
by (Seq_induct_tac "t" [Forall_def,sforall_def] 1);
|
|
599 |
by (strip_tac 1);
|
|
600 |
by (Seq_case_simp_tac "sa" 1);
|
|
601 |
by (Asm_full_simp_tac 1);
|
|
602 |
auto();
|
|
603 |
qed"Forall_prefix";
|
|
604 |
|
|
605 |
bind_thm ("Forall_prefixclosed",Forall_prefix RS spec RS mp RS mp);
|
|
606 |
|
|
607 |
|
|
608 |
goal thy "!! h. [| Finite h; Forall P s; s= h @@ t |] ==> Forall P t";
|
|
609 |
auto();
|
|
610 |
qed"Forall_postfixclosed";
|
|
611 |
|
|
612 |
|
|
613 |
goal thy "((! x. P x --> (Q x = R x)) & Forall P tr) --> Filter Q`tr = Filter R`tr";
|
|
614 |
by (Seq_induct_tac "tr" [Forall_def,sforall_def] 1);
|
|
615 |
qed"ForallPFilterQR1";
|
|
616 |
|
|
617 |
bind_thm("ForallPFilterQR",allI RS (conjI RS (ForallPFilterQR1 RS mp)));
|
|
618 |
|
3071
|
619 |
|
|
620 |
(* ------------------------------------------------------------------------------------- *)
|
|
621 |
|
|
622 |
section "Forall, Filter";
|
|
623 |
|
|
624 |
|
|
625 |
goal thy "Forall P (Filter P`x)";
|
|
626 |
by (simp_tac (!simpset addsimps [Filter_def,Forall_def,forallPsfilterP]) 1);
|
|
627 |
qed"ForallPFilterP";
|
|
628 |
|
3275
|
629 |
(* holds also in other direction, then equal to forallPfilterP *)
|
3071
|
630 |
goal thy "Forall P x --> Filter P`x = x";
|
|
631 |
by (Seq_induct_tac "x" [Forall_def,sforall_def,Filter_def] 1);
|
|
632 |
qed"ForallPFilterPid1";
|
|
633 |
|
3275
|
634 |
bind_thm(" ForallPFilterPid",ForallPFilterPid1 RS mp);
|
3071
|
635 |
|
|
636 |
|
3275
|
637 |
(* holds also in other direction *)
|
|
638 |
goal thy "!! ys . Finite ys ==> \
|
|
639 |
\ Forall (%x. ~P x) ys --> Filter P`ys = nil ";
|
|
640 |
by (Seq_Finite_induct_tac 1);
|
3071
|
641 |
qed"ForallnPFilterPnil1";
|
|
642 |
|
3275
|
643 |
bind_thm ("ForallnPFilterPnil",ForallnPFilterPnil1 RS mp);
|
3071
|
644 |
|
|
645 |
|
3275
|
646 |
(* holds also in other direction *)
|
3071
|
647 |
goal thy "!! P. ~Finite ys & Forall (%x. ~P x) ys \
|
|
648 |
\ --> Filter P`ys = UU ";
|
|
649 |
by (res_inst_tac[("x","ys")] Seq_induct 1);
|
|
650 |
(* adm *)
|
3275
|
651 |
(* FIX: cont ~Finite behandeln *)
|
3071
|
652 |
br adm_all 1;
|
|
653 |
(* base cases *)
|
|
654 |
by (Simp_tac 1);
|
|
655 |
by (Simp_tac 1);
|
|
656 |
(* main case *)
|
|
657 |
by (asm_full_simp_tac (!simpset setloop split_tac [expand_if] ) 1);
|
|
658 |
qed"ForallnPFilterPUU1";
|
|
659 |
|
3275
|
660 |
bind_thm ("ForallnPFilterPUU",conjI RS (ForallnPFilterPUU1 RS mp));
|
|
661 |
|
|
662 |
|
|
663 |
(* inverse of ForallnPFilterPnil *)
|
|
664 |
|
|
665 |
goal thy "!! ys . Filter P`ys = nil --> \
|
|
666 |
\ (Forall (%x. ~P x) ys & Finite ys)";
|
|
667 |
by (res_inst_tac[("x","ys")] Seq_induct 1);
|
|
668 |
(* adm *)
|
|
669 |
(* FIX: cont Finite behandeln *)
|
|
670 |
br adm_all 1;
|
|
671 |
(* base cases *)
|
|
672 |
by (Simp_tac 1);
|
|
673 |
by (Simp_tac 1);
|
|
674 |
(* main case *)
|
|
675 |
by (asm_full_simp_tac (!simpset setloop split_tac [expand_if] ) 1);
|
|
676 |
qed"FilternPnilForallP1";
|
|
677 |
|
|
678 |
bind_thm ("FilternPnilForallP",FilternPnilForallP1 RS mp);
|
|
679 |
|
|
680 |
(* inverse of ForallnPFilterPUU *)
|
|
681 |
(* FIX: will not be admissable, search other way of proof *)
|
|
682 |
|
|
683 |
goal thy "!! P. Filter P`ys = UU --> \
|
|
684 |
\ (Forall (%x. ~P x) ys & ~Finite ys)";
|
|
685 |
by (res_inst_tac[("x","ys")] Seq_induct 1);
|
|
686 |
(* adm *)
|
|
687 |
(* FIX: cont ~Finite behandeln *)
|
|
688 |
br adm_all 1;
|
|
689 |
(* base cases *)
|
|
690 |
by (Simp_tac 1);
|
|
691 |
by (Simp_tac 1);
|
|
692 |
(* main case *)
|
|
693 |
by (asm_full_simp_tac (!simpset setloop split_tac [expand_if] ) 1);
|
|
694 |
qed"FilternPUUForallP1";
|
|
695 |
|
|
696 |
bind_thm ("FilternPUUForallP",FilternPUUForallP1 RS mp);
|
3071
|
697 |
|
|
698 |
|
|
699 |
goal thy "!! Q P.[| Forall Q ys; Finite ys; !!x. Q x ==> ~P x|] \
|
|
700 |
\ ==> Filter P`ys = nil";
|
|
701 |
be ForallnPFilterPnil 1;
|
|
702 |
be ForallPForallQ 1;
|
|
703 |
auto();
|
|
704 |
qed"ForallQFilterPnil";
|
|
705 |
|
|
706 |
goal thy "!! Q P. [| ~Finite ys; Forall Q ys; !!x. Q x ==> ~P x|] \
|
|
707 |
\ ==> Filter P`ys = UU ";
|
|
708 |
be ForallnPFilterPUU 1;
|
|
709 |
be ForallPForallQ 1;
|
|
710 |
auto();
|
|
711 |
qed"ForallQFilterPUU";
|
|
712 |
|
|
713 |
|
|
714 |
|
|
715 |
(* ------------------------------------------------------------------------------------- *)
|
|
716 |
|
|
717 |
section "Takewhile, Forall, Filter";
|
|
718 |
|
|
719 |
|
|
720 |
goal thy "Forall P (Takewhile P`x)";
|
|
721 |
by (simp_tac (!simpset addsimps [Forall_def,Takewhile_def,sforallPstakewhileP]) 1);
|
|
722 |
qed"ForallPTakewhileP";
|
|
723 |
|
|
724 |
|
|
725 |
goal thy"!! P. [| !!x. Q x==> P x |] ==> Forall P (Takewhile Q`x)";
|
|
726 |
br ForallPForallQ 1;
|
|
727 |
br ForallPTakewhileP 1;
|
|
728 |
auto();
|
|
729 |
qed"ForallPTakewhileQ";
|
|
730 |
|
|
731 |
|
|
732 |
goal thy "!! Q P.[| Finite (Takewhile Q`ys); !!x. Q x ==> ~P x |] \
|
|
733 |
\ ==> Filter P`(Takewhile Q`ys) = nil";
|
|
734 |
be ForallnPFilterPnil 1;
|
|
735 |
br ForallPForallQ 1;
|
|
736 |
br ForallPTakewhileP 1;
|
|
737 |
auto();
|
|
738 |
qed"FilterPTakewhileQnil";
|
|
739 |
|
|
740 |
goal thy "!! Q P. [| !!x. Q x ==> P x |] ==> \
|
|
741 |
\ Filter P`(Takewhile Q`ys) = (Takewhile Q`ys)";
|
|
742 |
br ForallPFilterPid 1;
|
|
743 |
br ForallPForallQ 1;
|
|
744 |
br ForallPTakewhileP 1;
|
|
745 |
auto();
|
|
746 |
qed"FilterPTakewhileQid";
|
|
747 |
|
|
748 |
Addsimps [ForallPTakewhileP,ForallPTakewhileQ,
|
|
749 |
FilterPTakewhileQnil,FilterPTakewhileQid];
|
|
750 |
|
3275
|
751 |
goal thy "Takewhile P`(Takewhile P`s) = Takewhile P`s";
|
|
752 |
by (Seq_induct_tac "s" [Forall_def,sforall_def] 1);
|
|
753 |
by (asm_full_simp_tac (!simpset setloop (split_tac [expand_if])) 1);
|
|
754 |
qed"Takewhile_idempotent";
|
3071
|
755 |
|
3275
|
756 |
goal thy "Forall P s --> Takewhile (%x.Q x | (~P x))`s = Takewhile Q`s";
|
|
757 |
by (Seq_induct_tac "s" [Forall_def,sforall_def] 1);
|
|
758 |
qed"ForallPTakewhileQnP";
|
|
759 |
|
|
760 |
goal thy "Forall P s --> Dropwhile (%x.Q x | (~P x))`s = Dropwhile Q`s";
|
|
761 |
by (Seq_induct_tac "s" [Forall_def,sforall_def] 1);
|
|
762 |
qed"ForallPDropwhileQnP";
|
|
763 |
|
|
764 |
Addsimps [ForallPTakewhileQnP RS mp, ForallPDropwhileQnP RS mp];
|
|
765 |
|
|
766 |
|
|
767 |
goal thy "Forall P s --> Takewhile P`(s @@ t) = s @@ (Takewhile P`t)";
|
|
768 |
by (Seq_induct_tac "s" [Forall_def,sforall_def] 1);
|
|
769 |
qed"TakewhileConc1";
|
|
770 |
|
|
771 |
bind_thm("TakewhileConc",TakewhileConc1 RS mp);
|
|
772 |
|
|
773 |
goal thy "!! s.Finite s ==> Forall P s --> Dropwhile P`(s @@ t) = Dropwhile P`t";
|
|
774 |
by (Seq_Finite_induct_tac 1);
|
|
775 |
qed"DropwhileConc1";
|
|
776 |
|
|
777 |
bind_thm("DropwhileConc",DropwhileConc1 RS mp);
|
3071
|
778 |
|
|
779 |
(* ----------------------------------------------------------------------------------- *)
|
|
780 |
|
|
781 |
|
|
782 |
(*
|
|
783 |
section "admissibility";
|
|
784 |
|
3275
|
785 |
goal thy "adm(%x.Finite x)";
|
3071
|
786 |
br admI 1;
|
|
787 |
bd spec 1;
|
|
788 |
be contrapos 1;
|
|
789 |
|
|
790 |
*)
|
|
791 |
|
|
792 |
(* ----------------------------------------------------------------------------------- *)
|
|
793 |
|
|
794 |
section "coinductive characterizations of Filter";
|
|
795 |
|
|
796 |
|
|
797 |
goal thy "HD`(Filter P`y) = Def x \
|
|
798 |
\ --> y = ((Takewhile (%x. ~P x)`y) @@ (x >> TL`(Dropwhile (%a.~P a)`y))) \
|
|
799 |
\ & Finite (Takewhile (%x. ~ P x)`y) & P x";
|
|
800 |
|
|
801 |
(* FIX: pay attention: is only admissible with chain-finite package to be added to
|
|
802 |
adm test *)
|
|
803 |
by (Seq_induct_tac "y" [] 1);
|
|
804 |
br adm_all 1;
|
|
805 |
by (Asm_full_simp_tac 1);
|
|
806 |
by (case_tac "P a" 1);
|
|
807 |
by (Asm_full_simp_tac 1);
|
|
808 |
br impI 1;
|
|
809 |
by (hyp_subst_tac 1);
|
|
810 |
by (Asm_full_simp_tac 1);
|
|
811 |
(* ~ P a *)
|
|
812 |
by (Asm_full_simp_tac 1);
|
|
813 |
br impI 1;
|
|
814 |
by (rotate_tac ~1 1);
|
|
815 |
by (Asm_full_simp_tac 1);
|
|
816 |
by (REPEAT (etac conjE 1));
|
|
817 |
ba 1;
|
|
818 |
qed"divide_Seq_lemma";
|
|
819 |
|
|
820 |
goal thy "!! x. (x>>xs) << Filter P`y \
|
|
821 |
\ ==> y = ((Takewhile (%a. ~ P a)`y) @@ (x >> TL`(Dropwhile (%a.~P a)`y))) \
|
|
822 |
\ & Finite (Takewhile (%a. ~ P a)`y) & P x";
|
|
823 |
br (divide_Seq_lemma RS mp) 1;
|
|
824 |
by (dres_inst_tac [("fo","HD"),("xa","x>>xs")] monofun_cfun_arg 1);
|
|
825 |
by (Asm_full_simp_tac 1);
|
|
826 |
qed"divide_Seq";
|
|
827 |
|
|
828 |
|
|
829 |
goal thy "~Forall P y --> (? x. HD`(Filter (%a. ~P a)`y) = Def x)";
|
|
830 |
(* FIX: pay attention: is only admissible with chain-finite package to be added to
|
|
831 |
adm test *)
|
|
832 |
by (Seq_induct_tac "y" [] 1);
|
|
833 |
br adm_all 1;
|
|
834 |
by (case_tac "P a" 1);
|
|
835 |
by (Asm_full_simp_tac 1);
|
|
836 |
by (Asm_full_simp_tac 1);
|
|
837 |
qed"nForall_HDFilter";
|
|
838 |
|
|
839 |
|
|
840 |
goal thy "!!y. ~Forall P y \
|
|
841 |
\ ==> ? x. y= (Takewhile P`y @@ (x >> TL`(Dropwhile P`y))) & \
|
|
842 |
\ Finite (Takewhile P`y) & (~ P x)";
|
|
843 |
bd (nForall_HDFilter RS mp) 1;
|
|
844 |
by (safe_tac set_cs);
|
|
845 |
by (res_inst_tac [("x","x")] exI 1);
|
|
846 |
by (cut_inst_tac [("P1","%x. ~ P x")] (divide_Seq_lemma RS mp) 1);
|
|
847 |
auto();
|
|
848 |
qed"divide_Seq2";
|
|
849 |
|
|
850 |
|
|
851 |
goal thy "!! y. ~Forall P y \
|
|
852 |
\ ==> ? x bs rs. y= (bs @@ (x>>rs)) & Finite bs & Forall P bs & (~ P x)";
|
|
853 |
by (cut_inst_tac [] divide_Seq2 1);
|
|
854 |
auto();
|
|
855 |
qed"divide_Seq3";
|
|
856 |
|
3275
|
857 |
Addsimps [FilterPQ,FilterConc,Conc_cong];
|
3071
|
858 |
|
|
859 |
|
|
860 |
(* ------------------------------------------------------------------------------------- *)
|
|
861 |
|
|
862 |
|
|
863 |
section "take_lemma";
|
|
864 |
|
|
865 |
goal thy "(!n. seq_take n`x = seq_take n`x') = (x = x')";
|
|
866 |
by (rtac iffI 1);
|
|
867 |
br seq.take_lemma 1;
|
|
868 |
auto();
|
|
869 |
qed"seq_take_lemma";
|
|
870 |
|
3275
|
871 |
goal thy
|
|
872 |
" ! n. ((! k. k < n --> seq_take k`y1 = seq_take k`y2) \
|
|
873 |
\ --> seq_take n`(x @@ (t>>y1)) = seq_take n`(x @@ (t>>y2)))";
|
|
874 |
by (Seq_induct_tac "x" [] 1);
|
|
875 |
by (strip_tac 1);
|
|
876 |
by (res_inst_tac [("n","n")] natE 1);
|
|
877 |
auto();
|
|
878 |
by (res_inst_tac [("n","n")] natE 1);
|
|
879 |
auto();
|
|
880 |
qed"take_reduction1";
|
3071
|
881 |
|
|
882 |
|
3275
|
883 |
goal thy "!! n.[| x=y; s=t;!! k.k<n ==> seq_take k`y1 = seq_take k`y2|] \
|
|
884 |
\ ==> seq_take n`(x @@ (s>>y1)) = seq_take n`(y @@ (t>>y2))";
|
3071
|
885 |
|
3275
|
886 |
by (auto_tac (!claset addSIs [take_reduction1 RS spec RS mp],!simpset));
|
3071
|
887 |
qed"take_reduction";
|
3275
|
888 |
|
3071
|
889 |
|
|
890 |
goal thy "!! Q. [|!! s. [| Forall Q s; A s |] ==> (f s) = (g s) ; \
|
|
891 |
\ !! s1 s2 y. [| Forall Q s1; Finite s1; ~ Q y; A (s1 @@ y>>s2)|] \
|
|
892 |
\ ==> (f (s1 @@ y>>s2)) = (g (s1 @@ y>>s2)) |] \
|
|
893 |
\ ==> A x --> (f x)=(g x)";
|
|
894 |
by (case_tac "Forall Q x" 1);
|
|
895 |
by (auto_tac (!claset addSDs [divide_Seq3],!simpset));
|
|
896 |
qed"take_lemma_principle1";
|
|
897 |
|
|
898 |
goal thy "!! Q. [|!! s. [| Forall Q s; A s |] ==> (f s) = (g s) ; \
|
|
899 |
\ !! s1 s2 y. [| Forall Q s1; Finite s1; ~ Q y; A (s1 @@ y>>s2)|] \
|
|
900 |
\ ==> ! n. seq_take n`(f (s1 @@ y>>s2)) \
|
|
901 |
\ = seq_take n`(g (s1 @@ y>>s2)) |] \
|
|
902 |
\ ==> A x --> (f x)=(g x)";
|
|
903 |
by (case_tac "Forall Q x" 1);
|
|
904 |
by (auto_tac (!claset addSDs [divide_Seq3],!simpset));
|
|
905 |
br seq.take_lemma 1;
|
|
906 |
auto();
|
|
907 |
qed"take_lemma_principle2";
|
|
908 |
|
|
909 |
|
|
910 |
(* Note: in the following proofs the ordering of proof steps is very
|
|
911 |
important, as otherwise either (Forall Q s1) would be in the IH as
|
|
912 |
assumption (then rule useless) or it is not possible to strengthen
|
|
913 |
the IH by doing a forall closure of the sequence t (then rule also useless).
|
|
914 |
This is also the reason why the induction rule (less_induct or nat_induct) has to
|
|
915 |
to be imbuilt into the rule, as induction has to be done early and the take lemma
|
|
916 |
has to be used in the trivial direction afterwards for the (Forall Q x) case. *)
|
|
917 |
|
|
918 |
goal thy
|
|
919 |
"!! Q. [|!! s. [| Forall Q s; A s |] ==> (f s) = (g s) ; \
|
|
920 |
\ !! s1 s2 y n. [| ! t. A t --> seq_take n`(f t) = seq_take n`(g t);\
|
|
921 |
\ Forall Q s1; Finite s1; ~ Q y; A (s1 @@ y>>s2) |] \
|
|
922 |
\ ==> seq_take (Suc n)`(f (s1 @@ y>>s2)) \
|
|
923 |
\ = seq_take (Suc n)`(g (s1 @@ y>>s2)) |] \
|
|
924 |
\ ==> A x --> (f x)=(g x)";
|
|
925 |
br impI 1;
|
|
926 |
br seq.take_lemma 1;
|
|
927 |
br mp 1;
|
|
928 |
ba 2;
|
|
929 |
by (res_inst_tac [("x","x")] spec 1);
|
|
930 |
br nat_induct 1;
|
|
931 |
by (Simp_tac 1);
|
|
932 |
br allI 1;
|
|
933 |
by (case_tac "Forall Q xa" 1);
|
|
934 |
by (SELECT_GOAL (auto_tac (!claset addSIs [seq_take_lemma RS iffD2 RS spec],
|
|
935 |
!simpset)) 1);
|
|
936 |
by (auto_tac (!claset addSDs [divide_Seq3],!simpset));
|
|
937 |
qed"take_lemma_induct";
|
|
938 |
|
|
939 |
|
|
940 |
goal thy
|
|
941 |
"!! Q. [|!! s. [| Forall Q s; A s |] ==> (f s) = (g s) ; \
|
|
942 |
\ !! s1 s2 y n. [| ! t m. m < n --> A t --> seq_take m`(f t) = seq_take m`(g t);\
|
|
943 |
\ Forall Q s1; Finite s1; ~ Q y; A (s1 @@ y>>s2) |] \
|
|
944 |
\ ==> seq_take n`(f (s1 @@ y>>s2)) \
|
|
945 |
\ = seq_take n`(g (s1 @@ y>>s2)) |] \
|
|
946 |
\ ==> A x --> (f x)=(g x)";
|
|
947 |
br impI 1;
|
|
948 |
br seq.take_lemma 1;
|
|
949 |
br mp 1;
|
|
950 |
ba 2;
|
|
951 |
by (res_inst_tac [("x","x")] spec 1);
|
|
952 |
br less_induct 1;
|
|
953 |
br allI 1;
|
|
954 |
by (case_tac "Forall Q xa" 1);
|
|
955 |
by (SELECT_GOAL (auto_tac (!claset addSIs [seq_take_lemma RS iffD2 RS spec],
|
|
956 |
!simpset)) 1);
|
|
957 |
by (auto_tac (!claset addSDs [divide_Seq3],!simpset));
|
|
958 |
qed"take_lemma_less_induct";
|
|
959 |
|
3275
|
960 |
|
|
961 |
(*
|
|
962 |
|
|
963 |
goal thy
|
|
964 |
"!! Q. [|!! s h1 h2. [| Forall Q s; A s h1 h2|] ==> (f s h1 h2) = (g s h1 h2) ; \
|
|
965 |
\ !! s1 s2 y n. [| ! t h1 h2 m. m < n --> (A t h1 h2) --> seq_take m`(f t h1 h2) = seq_take m`(g t h1 h2);\
|
|
966 |
\ Forall Q s1; Finite s1; ~ Q y; A (s1 @@ y>>s2) h1 h2|] \
|
|
967 |
\ ==> seq_take n`(f (s1 @@ y>>s2) h1 h2) \
|
|
968 |
\ = seq_take n`(g (s1 @@ y>>s2) h1 h2) |] \
|
|
969 |
\ ==> ! h1 h2. (A x h1 h2) --> (f x h1 h2)=(g x h1 h2)";
|
|
970 |
by (strip_tac 1);
|
|
971 |
br seq.take_lemma 1;
|
|
972 |
br mp 1;
|
|
973 |
ba 2;
|
|
974 |
by (res_inst_tac [("x","h2a")] spec 1);
|
|
975 |
by (res_inst_tac [("x","h1a")] spec 1);
|
|
976 |
by (res_inst_tac [("x","x")] spec 1);
|
|
977 |
br less_induct 1;
|
|
978 |
br allI 1;
|
|
979 |
by (case_tac "Forall Q xa" 1);
|
|
980 |
by (SELECT_GOAL (auto_tac (!claset addSIs [seq_take_lemma RS iffD2 RS spec],
|
|
981 |
!simpset)) 1);
|
|
982 |
by (auto_tac (!claset addSDs [divide_Seq3],!simpset));
|
|
983 |
qed"take_lemma_less_induct";
|
|
984 |
|
|
985 |
|
|
986 |
|
|
987 |
goal thy
|
|
988 |
"!! Q. [|!! s. Forall Q s ==> P ((f s) = (g s)) ; \
|
|
989 |
\ !! s1 s2 y n. [| ! t m. m < n --> P (seq_take m`(f t) = seq_take m`(g t));\
|
|
990 |
\ Forall Q s1; Finite s1; ~ Q y|] \
|
|
991 |
\ ==> P (seq_take n`(f (s1 @@ y>>s2)) \
|
|
992 |
\ = seq_take n`(g (s1 @@ y>>s2))) |] \
|
|
993 |
\ ==> P ((f x)=(g x))";
|
|
994 |
|
|
995 |
by (res_inst_tac [("t","f x = g x"),
|
|
996 |
("s","!n. seq_take n`(f x) = seq_take n`(g x)")] subst 1);
|
|
997 |
br seq_take_lemma 1;
|
|
998 |
|
|
999 |
wie ziehe ich n durch P, d.h. evtl. ns in P muessen umbenannt werden.....
|
|
1000 |
|
|
1001 |
|
|
1002 |
FIX
|
|
1003 |
|
|
1004 |
br less_induct 1;
|
|
1005 |
br allI 1;
|
|
1006 |
by (case_tac "Forall Q xa" 1);
|
|
1007 |
by (SELECT_GOAL (auto_tac (!claset addSIs [seq_take_lemma RS iffD2 RS spec],
|
|
1008 |
!simpset)) 1);
|
|
1009 |
by (auto_tac (!claset addSDs [divide_Seq3],!simpset));
|
|
1010 |
qed"take_lemma_less_induct";
|
|
1011 |
|
|
1012 |
|
|
1013 |
*)
|
|
1014 |
|
|
1015 |
|
3071
|
1016 |
goal thy
|
|
1017 |
"!! Q. [| A UU ==> (f UU) = (g UU) ; \
|
|
1018 |
\ A nil ==> (f nil) = (g nil) ; \
|
|
1019 |
\ !! s y n. [| ! t. A t --> seq_take n`(f t) = seq_take n`(g t);\
|
|
1020 |
\ A (y>>s) |] \
|
|
1021 |
\ ==> seq_take (Suc n)`(f (y>>s)) \
|
|
1022 |
\ = seq_take (Suc n)`(g (y>>s)) |] \
|
|
1023 |
\ ==> A x --> (f x)=(g x)";
|
|
1024 |
br impI 1;
|
|
1025 |
br seq.take_lemma 1;
|
|
1026 |
br mp 1;
|
|
1027 |
ba 2;
|
|
1028 |
by (res_inst_tac [("x","x")] spec 1);
|
|
1029 |
br nat_induct 1;
|
|
1030 |
by (Simp_tac 1);
|
|
1031 |
br allI 1;
|
|
1032 |
by (Seq_case_simp_tac "xa" 1);
|
|
1033 |
qed"take_lemma_in_eq_out";
|
|
1034 |
|
|
1035 |
|
|
1036 |
(* ------------------------------------------------------------------------------------ *)
|
|
1037 |
|
|
1038 |
section "alternative take_lemma proofs";
|
|
1039 |
|
|
1040 |
|
|
1041 |
(* --------------------------------------------------------------- *)
|
|
1042 |
(* Alternative Proof of FilterPQ *)
|
|
1043 |
(* --------------------------------------------------------------- *)
|
|
1044 |
|
|
1045 |
Delsimps [FilterPQ];
|
|
1046 |
|
|
1047 |
|
|
1048 |
(* In general: How to do this case without the same adm problems
|
|
1049 |
as for the entire proof ? *)
|
|
1050 |
goal thy "Forall (%x.~(P x & Q x)) s \
|
|
1051 |
\ --> Filter P`(Filter Q`s) =\
|
|
1052 |
\ Filter (%x. P x & Q x)`s";
|
|
1053 |
|
|
1054 |
by (Seq_induct_tac "s" [Forall_def,sforall_def] 1);
|
|
1055 |
by (asm_full_simp_tac (!simpset setloop split_tac [expand_if] ) 1);
|
|
1056 |
qed"Filter_lemma1";
|
|
1057 |
|
|
1058 |
goal thy "!! s. Finite s ==> \
|
|
1059 |
\ (Forall (%x. (~P x) | (~ Q x)) s \
|
|
1060 |
\ --> Filter P`(Filter Q`s) = nil)";
|
|
1061 |
by (Seq_Finite_induct_tac 1);
|
|
1062 |
by (asm_full_simp_tac (!simpset setloop split_tac [expand_if] ) 1);
|
|
1063 |
qed"Filter_lemma2";
|
|
1064 |
|
|
1065 |
goal thy "!! s. Finite s ==> \
|
|
1066 |
\ Forall (%x. (~P x) | (~ Q x)) s \
|
|
1067 |
\ --> Filter (%x.P x & Q x)`s = nil";
|
|
1068 |
by (Seq_Finite_induct_tac 1);
|
|
1069 |
by (asm_full_simp_tac (!simpset setloop split_tac [expand_if] ) 1);
|
|
1070 |
qed"Filter_lemma3";
|
|
1071 |
|
|
1072 |
|
|
1073 |
goal thy "Filter P`(Filter Q`s) = Filter (%x. P x & Q x)`s";
|
|
1074 |
by (res_inst_tac [("A1","%x.True")
|
3275
|
1075 |
,("Q1","%x.~(P x & Q x)"),("x1","s")]
|
3071
|
1076 |
(take_lemma_induct RS mp) 1);
|
|
1077 |
(* FIX: better support for A = %.True *)
|
|
1078 |
by (Fast_tac 3);
|
|
1079 |
by (asm_full_simp_tac (!simpset addsimps [Filter_lemma1]) 1);
|
|
1080 |
by (asm_full_simp_tac (!simpset addsimps [Filter_lemma2,Filter_lemma3]
|
|
1081 |
setloop split_tac [expand_if]) 1);
|
|
1082 |
qed"FilterPQ_takelemma";
|
|
1083 |
|
|
1084 |
Addsimps [FilterPQ];
|
|
1085 |
|
|
1086 |
|
|
1087 |
(* --------------------------------------------------------------- *)
|
|
1088 |
(* Alternative Proof of MapConc *)
|
|
1089 |
(* --------------------------------------------------------------- *)
|
|
1090 |
|
3275
|
1091 |
|
3071
|
1092 |
|
|
1093 |
goal thy "Map f`(x@@y) = (Map f`x) @@ (Map f`y)";
|
|
1094 |
by (res_inst_tac [("A1","%x.True"),("x1","x")] (take_lemma_in_eq_out RS mp) 1);
|
|
1095 |
auto();
|
|
1096 |
qed"MapConc_takelemma";
|
|
1097 |
|
|
1098 |
|