10943
|
1 |
(* Title: HOL/Library/Nested_Environment.thy
|
|
2 |
ID: $Id$
|
|
3 |
Author: Markus Wenzel, TU Muenchen
|
|
4 |
License: GPL (GNU GENERAL PUBLIC LICENSE)
|
|
5 |
*)
|
|
6 |
|
|
7 |
header {*
|
|
8 |
\title{Nested environments}
|
|
9 |
\author{Markus Wenzel}
|
|
10 |
*}
|
|
11 |
|
|
12 |
theory Nested_Environment = Main:
|
|
13 |
|
|
14 |
text {*
|
|
15 |
Consider a partial function @{term [source] "e :: 'a => 'b option"};
|
|
16 |
this may be understood as an \emph{environment} mapping indexes
|
|
17 |
@{typ 'a} to optional entry values @{typ 'b} (cf.\ the basic theory
|
10948
|
18 |
@{text Map} of Isabelle/HOL). This basic idea is easily generalized
|
|
19 |
to that of a \emph{nested environment}, where entries may be either
|
|
20 |
basic values or again proper environments. Then each entry is
|
|
21 |
accessed by a \emph{path}, i.e.\ a list of indexes leading to its
|
|
22 |
position within the structure.
|
10943
|
23 |
*}
|
|
24 |
|
|
25 |
datatype ('a, 'b, 'c) env =
|
|
26 |
Val 'a
|
|
27 |
| Env 'b "'c => ('a, 'b, 'c) env option"
|
|
28 |
|
|
29 |
text {*
|
|
30 |
\medskip In the type @{typ "('a, 'b, 'c) env"} the parameter @{typ
|
|
31 |
'a} refers to basic values (occurring in terminal positions), type
|
|
32 |
@{typ 'b} to values associated with proper (inner) environments, and
|
|
33 |
type @{typ 'c} with the index type for branching. Note that there
|
|
34 |
is no restriction on any of these types. In particular, arbitrary
|
|
35 |
branching may yield rather large (transfinite) tree structures.
|
|
36 |
*}
|
|
37 |
|
|
38 |
|
|
39 |
subsection {* The lookup operation *}
|
|
40 |
|
|
41 |
text {*
|
|
42 |
Lookup in nested environments works by following a given path of
|
|
43 |
index elements, leading to an optional result (a terminal value or
|
|
44 |
nested environment). A \emph{defined position} within a nested
|
|
45 |
environment is one where @{term lookup} at its path does not yield
|
|
46 |
@{term None}.
|
|
47 |
*}
|
|
48 |
|
|
49 |
consts
|
|
50 |
lookup :: "('a, 'b, 'c) env => 'c list => ('a, 'b, 'c) env option"
|
|
51 |
lookup_option :: "('a, 'b, 'c) env option => 'c list => ('a, 'b, 'c) env option"
|
|
52 |
|
|
53 |
primrec (lookup)
|
|
54 |
"lookup (Val a) xs = (if xs = [] then Some (Val a) else None)"
|
|
55 |
"lookup (Env b es) xs =
|
|
56 |
(case xs of
|
|
57 |
[] => Some (Env b es)
|
|
58 |
| y # ys => lookup_option (es y) ys)"
|
|
59 |
"lookup_option None xs = None"
|
|
60 |
"lookup_option (Some e) xs = lookup e xs"
|
|
61 |
|
|
62 |
hide const lookup_option
|
|
63 |
|
|
64 |
text {*
|
|
65 |
\medskip The characteristic cases of @{term lookup} are expressed by
|
|
66 |
the following equalities.
|
|
67 |
*}
|
|
68 |
|
|
69 |
theorem lookup_nil: "lookup e [] = Some e"
|
|
70 |
by (cases e) simp_all
|
|
71 |
|
|
72 |
theorem lookup_val_cons: "lookup (Val a) (x # xs) = None"
|
|
73 |
by simp
|
|
74 |
|
|
75 |
theorem lookup_env_cons:
|
|
76 |
"lookup (Env b es) (x # xs) =
|
|
77 |
(case es x of
|
|
78 |
None => None
|
|
79 |
| Some e => lookup e xs)"
|
|
80 |
by (cases "es x") simp_all
|
|
81 |
|
|
82 |
lemmas lookup.simps [simp del]
|
|
83 |
and lookup_simps [simp] = lookup_nil lookup_val_cons lookup_env_cons
|
|
84 |
|
|
85 |
theorem lookup_eq:
|
|
86 |
"lookup env xs =
|
|
87 |
(case xs of
|
|
88 |
[] => Some env
|
|
89 |
| x # xs =>
|
|
90 |
(case env of
|
|
91 |
Val a => None
|
|
92 |
| Env b es =>
|
|
93 |
(case es x of
|
|
94 |
None => None
|
|
95 |
| Some e => lookup e xs)))"
|
|
96 |
by (simp split: list.split env.split)
|
|
97 |
|
|
98 |
text {*
|
|
99 |
\medskip Displaced @{term lookup} operations, relative to a certain
|
|
100 |
base path prefix, may be reduced as follows. There are two cases,
|
|
101 |
depending whether the environment actually extends far enough to
|
|
102 |
follow the base path.
|
|
103 |
*}
|
|
104 |
|
|
105 |
theorem lookup_append_none:
|
|
106 |
"!!env. lookup env xs = None ==> lookup env (xs @ ys) = None"
|
|
107 |
(is "PROP ?P xs")
|
|
108 |
proof (induct xs)
|
|
109 |
fix env :: "('a, 'b, 'c) env"
|
|
110 |
{
|
|
111 |
assume "lookup env [] = None"
|
|
112 |
hence False by simp
|
|
113 |
thus "lookup env ([] @ ys) = None" ..
|
|
114 |
next
|
|
115 |
fix x xs
|
|
116 |
assume hyp: "PROP ?P xs"
|
|
117 |
assume asm: "lookup env (x # xs) = None"
|
|
118 |
show "lookup env ((x # xs) @ ys) = None"
|
|
119 |
proof (cases env)
|
|
120 |
case Val
|
|
121 |
thus ?thesis by simp
|
|
122 |
next
|
|
123 |
fix b es assume env: "env = Env b es"
|
|
124 |
show ?thesis
|
|
125 |
proof (cases "es x")
|
|
126 |
assume "es x = None"
|
|
127 |
with env show ?thesis by simp
|
|
128 |
next
|
|
129 |
fix e assume es: "es x = Some e"
|
|
130 |
show ?thesis
|
|
131 |
proof (cases "lookup e xs")
|
|
132 |
case None
|
|
133 |
hence "lookup e (xs @ ys) = None" by (rule hyp)
|
|
134 |
with env es show ?thesis by simp
|
|
135 |
next
|
|
136 |
case Some
|
|
137 |
with asm env es have False by simp
|
|
138 |
thus ?thesis ..
|
|
139 |
qed
|
|
140 |
qed
|
|
141 |
qed
|
|
142 |
}
|
|
143 |
qed
|
|
144 |
|
|
145 |
theorem lookup_append_some:
|
|
146 |
"!!env e. lookup env xs = Some e ==> lookup env (xs @ ys) = lookup e ys"
|
|
147 |
(is "PROP ?P xs")
|
|
148 |
proof (induct xs)
|
|
149 |
fix env e :: "('a, 'b, 'c) env"
|
|
150 |
{
|
|
151 |
assume "lookup env [] = Some e"
|
|
152 |
hence "env = e" by simp
|
|
153 |
thus "lookup env ([] @ ys) = lookup e ys" by simp
|
|
154 |
next
|
|
155 |
fix x xs
|
|
156 |
assume hyp: "PROP ?P xs"
|
|
157 |
assume asm: "lookup env (x # xs) = Some e"
|
|
158 |
show "lookup env ((x # xs) @ ys) = lookup e ys"
|
|
159 |
proof (cases env)
|
|
160 |
fix a assume "env = Val a"
|
|
161 |
with asm have False by simp
|
|
162 |
thus ?thesis ..
|
|
163 |
next
|
|
164 |
fix b es assume env: "env = Env b es"
|
|
165 |
show ?thesis
|
|
166 |
proof (cases "es x")
|
|
167 |
assume "es x = None"
|
|
168 |
with asm env have False by simp
|
|
169 |
thus ?thesis ..
|
|
170 |
next
|
|
171 |
fix e' assume es: "es x = Some e'"
|
|
172 |
show ?thesis
|
|
173 |
proof (cases "lookup e' xs")
|
|
174 |
case None
|
|
175 |
with asm env es have False by simp
|
|
176 |
thus ?thesis ..
|
|
177 |
next
|
|
178 |
case Some
|
|
179 |
with asm env es have "lookup e' xs = Some e"
|
|
180 |
by simp
|
|
181 |
hence "lookup e' (xs @ ys) = lookup e ys" by (rule hyp)
|
|
182 |
with env es show ?thesis by simp
|
|
183 |
qed
|
|
184 |
qed
|
|
185 |
qed
|
|
186 |
}
|
|
187 |
qed
|
|
188 |
|
|
189 |
text {*
|
|
190 |
\medskip Successful @{term lookup} deeper down an environment
|
|
191 |
structure means we are able to peek further up as well. Note that
|
|
192 |
this is basically just the contrapositive statement of @{thm
|
|
193 |
[source] lookup_append_none} above.
|
|
194 |
*}
|
|
195 |
|
|
196 |
theorem lookup_some_append:
|
|
197 |
"lookup env (xs @ ys) = Some e ==> \<exists>e. lookup env xs = Some e"
|
|
198 |
proof -
|
|
199 |
assume "lookup env (xs @ ys) = Some e"
|
|
200 |
hence "lookup env (xs @ ys) \<noteq> None" by simp
|
|
201 |
hence "lookup env xs \<noteq> None"
|
|
202 |
by (rule contrapos_nn) (simp only: lookup_append_none)
|
|
203 |
thus ?thesis by simp
|
|
204 |
qed
|
|
205 |
|
|
206 |
text {*
|
|
207 |
The subsequent statement describes in more detail how a successful
|
|
208 |
@{term lookup} with a non-empty path results in a certain situation
|
|
209 |
at any upper position.
|
|
210 |
*}
|
|
211 |
|
|
212 |
theorem lookup_some_upper: "!!env e.
|
|
213 |
lookup env (xs @ y # ys) = Some e ==>
|
|
214 |
\<exists>b' es' env'.
|
|
215 |
lookup env xs = Some (Env b' es') \<and>
|
|
216 |
es' y = Some env' \<and>
|
|
217 |
lookup env' ys = Some e"
|
|
218 |
(is "PROP ?P xs" is "!!env e. ?A env e xs ==> ?C env e xs")
|
11809
|
219 |
proof (induct xs)
|
10948
|
220 |
fix env e let ?A = "?A env e" and ?C = "?C env e"
|
10943
|
221 |
{
|
|
222 |
assume "?A []"
|
|
223 |
hence "lookup env (y # ys) = Some e" by simp
|
|
224 |
then obtain b' es' env' where
|
10948
|
225 |
env: "env = Env b' es'" and
|
|
226 |
es': "es' y = Some env'" and
|
|
227 |
look': "lookup env' ys = Some e"
|
10943
|
228 |
by (auto simp add: lookup_eq split: option.splits env.splits)
|
|
229 |
from env have "lookup env [] = Some (Env b' es')" by simp
|
|
230 |
with es' look' show "?C []" by blast
|
|
231 |
next
|
|
232 |
fix x xs
|
|
233 |
assume hyp: "PROP ?P xs"
|
|
234 |
assume "?A (x # xs)"
|
|
235 |
then obtain b' es' env' where
|
10948
|
236 |
env: "env = Env b' es'" and
|
|
237 |
es': "es' x = Some env'" and
|
|
238 |
look': "lookup env' (xs @ y # ys) = Some e"
|
10943
|
239 |
by (auto simp add: lookup_eq split: option.splits env.splits)
|
|
240 |
from hyp [OF look'] obtain b'' es'' env'' where
|
10948
|
241 |
upper': "lookup env' xs = Some (Env b'' es'')" and
|
|
242 |
es'': "es'' y = Some env''" and
|
|
243 |
look'': "lookup env'' ys = Some e"
|
10943
|
244 |
by blast
|
|
245 |
from env es' upper' have "lookup env (x # xs) = Some (Env b'' es'')"
|
|
246 |
by simp
|
|
247 |
with es'' look'' show "?C (x # xs)" by blast
|
|
248 |
}
|
|
249 |
qed
|
|
250 |
|
|
251 |
|
|
252 |
subsection {* The update operation *}
|
|
253 |
|
|
254 |
text {*
|
|
255 |
Update at a certain position in a nested environment may either
|
|
256 |
delete an existing entry, or overwrite an existing one. Note that
|
|
257 |
update at undefined positions is simple absorbed, i.e.\ the
|
|
258 |
environment is left unchanged.
|
|
259 |
*}
|
|
260 |
|
|
261 |
consts
|
|
262 |
update :: "'c list => ('a, 'b, 'c) env option
|
|
263 |
=> ('a, 'b, 'c) env => ('a, 'b, 'c) env"
|
|
264 |
update_option :: "'c list => ('a, 'b, 'c) env option
|
|
265 |
=> ('a, 'b, 'c) env option => ('a, 'b, 'c) env option"
|
|
266 |
|
|
267 |
primrec (update)
|
|
268 |
"update xs opt (Val a) =
|
|
269 |
(if xs = [] then (case opt of None => Val a | Some e => e)
|
|
270 |
else Val a)"
|
|
271 |
"update xs opt (Env b es) =
|
|
272 |
(case xs of
|
|
273 |
[] => (case opt of None => Env b es | Some e => e)
|
|
274 |
| y # ys => Env b (es (y := update_option ys opt (es y))))"
|
|
275 |
"update_option xs opt None =
|
|
276 |
(if xs = [] then opt else None)"
|
|
277 |
"update_option xs opt (Some e) =
|
|
278 |
(if xs = [] then opt else Some (update xs opt e))"
|
|
279 |
|
|
280 |
hide const update_option
|
|
281 |
|
|
282 |
text {*
|
|
283 |
\medskip The characteristic cases of @{term update} are expressed by
|
|
284 |
the following equalities.
|
|
285 |
*}
|
|
286 |
|
|
287 |
theorem update_nil_none: "update [] None env = env"
|
|
288 |
by (cases env) simp_all
|
|
289 |
|
|
290 |
theorem update_nil_some: "update [] (Some e) env = e"
|
|
291 |
by (cases env) simp_all
|
|
292 |
|
|
293 |
theorem update_cons_val: "update (x # xs) opt (Val a) = Val a"
|
|
294 |
by simp
|
|
295 |
|
|
296 |
theorem update_cons_nil_env:
|
|
297 |
"update [x] opt (Env b es) = Env b (es (x := opt))"
|
|
298 |
by (cases "es x") simp_all
|
|
299 |
|
|
300 |
theorem update_cons_cons_env:
|
|
301 |
"update (x # y # ys) opt (Env b es) =
|
|
302 |
Env b (es (x :=
|
|
303 |
(case es x of
|
|
304 |
None => None
|
|
305 |
| Some e => Some (update (y # ys) opt e))))"
|
|
306 |
by (cases "es x") simp_all
|
|
307 |
|
|
308 |
lemmas update.simps [simp del]
|
|
309 |
and update_simps [simp] = update_nil_none update_nil_some
|
|
310 |
update_cons_val update_cons_nil_env update_cons_cons_env
|
|
311 |
|
|
312 |
lemma update_eq:
|
|
313 |
"update xs opt env =
|
|
314 |
(case xs of
|
|
315 |
[] =>
|
|
316 |
(case opt of
|
|
317 |
None => env
|
|
318 |
| Some e => e)
|
|
319 |
| x # xs =>
|
|
320 |
(case env of
|
|
321 |
Val a => Val a
|
|
322 |
| Env b es =>
|
|
323 |
(case xs of
|
|
324 |
[] => Env b (es (x := opt))
|
|
325 |
| y # ys =>
|
|
326 |
Env b (es (x :=
|
|
327 |
(case es x of
|
|
328 |
None => None
|
|
329 |
| Some e => Some (update (y # ys) opt e)))))))"
|
|
330 |
by (simp split: list.split env.split option.split)
|
|
331 |
|
|
332 |
text {*
|
|
333 |
\medskip The most basic correspondence of @{term lookup} and @{term
|
|
334 |
update} states that after @{term update} at a defined position,
|
|
335 |
subsequent @{term lookup} operations would yield the new value.
|
|
336 |
*}
|
|
337 |
|
|
338 |
theorem lookup_update_some:
|
|
339 |
"!!env e. lookup env xs = Some e ==>
|
|
340 |
lookup (update xs (Some env') env) xs = Some env'"
|
|
341 |
(is "PROP ?P xs")
|
|
342 |
proof (induct xs)
|
|
343 |
fix env e :: "('a, 'b, 'c) env"
|
|
344 |
{
|
|
345 |
assume "lookup env [] = Some e"
|
|
346 |
hence "env = e" by simp
|
|
347 |
thus "lookup (update [] (Some env') env) [] = Some env'"
|
|
348 |
by simp
|
|
349 |
next
|
|
350 |
fix x xs
|
|
351 |
assume hyp: "PROP ?P xs"
|
|
352 |
assume asm: "lookup env (x # xs) = Some e"
|
|
353 |
show "lookup (update (x # xs) (Some env') env) (x # xs) = Some env'"
|
|
354 |
proof (cases env)
|
|
355 |
fix a assume "env = Val a"
|
|
356 |
with asm have False by simp
|
|
357 |
thus ?thesis ..
|
|
358 |
next
|
|
359 |
fix b es assume env: "env = Env b es"
|
|
360 |
show ?thesis
|
|
361 |
proof (cases "es x")
|
|
362 |
assume "es x = None"
|
|
363 |
with asm env have False by simp
|
|
364 |
thus ?thesis ..
|
|
365 |
next
|
|
366 |
fix e' assume es: "es x = Some e'"
|
|
367 |
show ?thesis
|
|
368 |
proof (cases xs)
|
|
369 |
assume "xs = []"
|
|
370 |
with env show ?thesis by simp
|
|
371 |
next
|
|
372 |
fix x' xs' assume xs: "xs = x' # xs'"
|
|
373 |
from asm env es have "lookup e' xs = Some e" by simp
|
|
374 |
hence "lookup (update xs (Some env') e') xs = Some env'" by (rule hyp)
|
|
375 |
with env es xs show ?thesis by simp
|
|
376 |
qed
|
|
377 |
qed
|
|
378 |
qed
|
|
379 |
}
|
|
380 |
qed
|
|
381 |
|
|
382 |
text {*
|
|
383 |
\medskip The properties of displaced @{term update} operations are
|
|
384 |
analogous to those of @{term lookup} above. There are two cases:
|
|
385 |
below an undefined position @{term update} is absorbed altogether,
|
|
386 |
and below a defined positions @{term update} affects subsequent
|
|
387 |
@{term lookup} operations in the obvious way.
|
|
388 |
*}
|
|
389 |
|
|
390 |
theorem update_append_none:
|
|
391 |
"!!env. lookup env xs = None ==> update (xs @ y # ys) opt env = env"
|
|
392 |
(is "PROP ?P xs")
|
|
393 |
proof (induct xs)
|
|
394 |
fix env :: "('a, 'b, 'c) env"
|
|
395 |
{
|
|
396 |
assume "lookup env [] = None"
|
|
397 |
hence False by simp
|
|
398 |
thus "update ([] @ y # ys) opt env = env" ..
|
|
399 |
next
|
|
400 |
fix x xs
|
|
401 |
assume hyp: "PROP ?P xs"
|
|
402 |
assume asm: "lookup env (x # xs) = None"
|
|
403 |
show "update ((x # xs) @ y # ys) opt env = env"
|
|
404 |
proof (cases env)
|
|
405 |
fix a assume "env = Val a"
|
|
406 |
thus ?thesis by simp
|
|
407 |
next
|
|
408 |
fix b es assume env: "env = Env b es"
|
|
409 |
show ?thesis
|
|
410 |
proof (cases "es x")
|
|
411 |
assume es: "es x = None"
|
|
412 |
show ?thesis
|
|
413 |
by (cases xs) (simp_all add: es env fun_upd_idem_iff)
|
|
414 |
next
|
|
415 |
fix e assume es: "es x = Some e"
|
|
416 |
show ?thesis
|
|
417 |
proof (cases xs)
|
|
418 |
assume "xs = []"
|
|
419 |
with asm env es have False by simp
|
|
420 |
thus ?thesis ..
|
|
421 |
next
|
|
422 |
fix x' xs' assume xs: "xs = x' # xs'"
|
|
423 |
from asm env es have "lookup e xs = None" by simp
|
|
424 |
hence "update (xs @ y # ys) opt e = e" by (rule hyp)
|
|
425 |
with env es xs show "update ((x # xs) @ y # ys) opt env = env"
|
|
426 |
by (simp add: fun_upd_idem_iff)
|
|
427 |
qed
|
|
428 |
qed
|
|
429 |
qed
|
|
430 |
}
|
|
431 |
qed
|
|
432 |
|
|
433 |
theorem update_append_some:
|
|
434 |
"!!env e. lookup env xs = Some e ==>
|
|
435 |
lookup (update (xs @ y # ys) opt env) xs = Some (update (y # ys) opt e)"
|
|
436 |
(is "PROP ?P xs")
|
|
437 |
proof (induct xs)
|
|
438 |
fix env e :: "('a, 'b, 'c) env"
|
|
439 |
{
|
|
440 |
assume "lookup env [] = Some e"
|
|
441 |
hence "env = e" by simp
|
|
442 |
thus "lookup (update ([] @ y # ys) opt env) [] = Some (update (y # ys) opt e)"
|
|
443 |
by simp
|
|
444 |
next
|
|
445 |
fix x xs
|
|
446 |
assume hyp: "PROP ?P xs"
|
|
447 |
assume asm: "lookup env (x # xs) = Some e"
|
|
448 |
show "lookup (update ((x # xs) @ y # ys) opt env) (x # xs)
|
|
449 |
= Some (update (y # ys) opt e)"
|
|
450 |
proof (cases env)
|
|
451 |
fix a assume "env = Val a"
|
|
452 |
with asm have False by simp
|
|
453 |
thus ?thesis ..
|
|
454 |
next
|
|
455 |
fix b es assume env: "env = Env b es"
|
|
456 |
show ?thesis
|
|
457 |
proof (cases "es x")
|
|
458 |
assume "es x = None"
|
|
459 |
with asm env have False by simp
|
|
460 |
thus ?thesis ..
|
|
461 |
next
|
|
462 |
fix e' assume es: "es x = Some e'"
|
|
463 |
show ?thesis
|
|
464 |
proof (cases xs)
|
|
465 |
assume xs: "xs = []"
|
|
466 |
from asm env es xs have "e = e'" by simp
|
|
467 |
with env es xs show ?thesis by simp
|
|
468 |
next
|
|
469 |
fix x' xs' assume xs: "xs = x' # xs'"
|
|
470 |
from asm env es have "lookup e' xs = Some e" by simp
|
|
471 |
hence "lookup (update (xs @ y # ys) opt e') xs =
|
|
472 |
Some (update (y # ys) opt e)" by (rule hyp)
|
|
473 |
with env es xs show ?thesis by simp
|
|
474 |
qed
|
|
475 |
qed
|
|
476 |
qed
|
|
477 |
}
|
|
478 |
qed
|
|
479 |
|
|
480 |
text {*
|
|
481 |
\medskip Apparently, @{term update} does not affect the result of
|
|
482 |
subsequent @{term lookup} operations at independent positions, i.e.\
|
|
483 |
in case that the paths for @{term update} and @{term lookup} fork at
|
|
484 |
a certain point.
|
|
485 |
*}
|
|
486 |
|
|
487 |
theorem lookup_update_other:
|
|
488 |
"!!env. y \<noteq> (z::'c) ==> lookup (update (xs @ z # zs) opt env) (xs @ y # ys) =
|
|
489 |
lookup env (xs @ y # ys)"
|
|
490 |
(is "PROP ?P xs")
|
|
491 |
proof (induct xs)
|
|
492 |
fix env :: "('a, 'b, 'c) env"
|
|
493 |
assume neq: "y \<noteq> z"
|
|
494 |
{
|
|
495 |
show "lookup (update ([] @ z # zs) opt env) ([] @ y # ys) =
|
|
496 |
lookup env ([] @ y # ys)"
|
|
497 |
proof (cases env)
|
|
498 |
case Val
|
|
499 |
thus ?thesis by simp
|
|
500 |
next
|
|
501 |
case Env
|
|
502 |
show ?thesis
|
|
503 |
proof (cases zs)
|
|
504 |
case Nil
|
|
505 |
with neq Env show ?thesis by simp
|
|
506 |
next
|
|
507 |
case Cons
|
|
508 |
with neq Env show ?thesis by simp
|
|
509 |
qed
|
|
510 |
qed
|
|
511 |
next
|
|
512 |
fix x xs
|
|
513 |
assume hyp: "PROP ?P xs"
|
|
514 |
show "lookup (update ((x # xs) @ z # zs) opt env) ((x # xs) @ y # ys) =
|
|
515 |
lookup env ((x # xs) @ y # ys)"
|
|
516 |
proof (cases env)
|
|
517 |
case Val
|
|
518 |
thus ?thesis by simp
|
|
519 |
next
|
|
520 |
fix y es assume env: "env = Env y es"
|
|
521 |
show ?thesis
|
|
522 |
proof (cases xs)
|
|
523 |
assume xs: "xs = []"
|
|
524 |
show ?thesis
|
|
525 |
proof (cases "es x")
|
|
526 |
case None
|
|
527 |
with env xs show ?thesis by simp
|
|
528 |
next
|
|
529 |
case Some
|
|
530 |
with hyp env xs and neq show ?thesis by simp
|
|
531 |
qed
|
|
532 |
next
|
|
533 |
fix x' xs' assume xs: "xs = x' # xs'"
|
|
534 |
show ?thesis
|
|
535 |
proof (cases "es x")
|
|
536 |
case None
|
|
537 |
with env xs show ?thesis by simp
|
|
538 |
next
|
|
539 |
case Some
|
|
540 |
with hyp env xs neq show ?thesis by simp
|
|
541 |
qed
|
|
542 |
qed
|
|
543 |
qed
|
|
544 |
}
|
|
545 |
qed
|
|
546 |
|
|
547 |
end
|