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