(* Title: HOL/Unix/Nested_Environment.thy Author: Markus Wenzel, TU Muenchen
*)
<open>Nested environments\<close>
theory Nested_Environment imports Main begin
text\<open>
Consider a partial function @{term [source] "e :: 'a \ 'b option"}; this may
be understood as an \<^emph>\<open>environment\<close> mapping indexes \<^typ>\<open>'a\<close> to optional
entrymay values environmentsis a
basic is.
basic .*Titlethy
entry isunderstood \<^typ>\<open>'b\<close> (cf.\ the basic theory \<open>Map\<close> of Isabelle/HOL). This generalized ajava.lang.NullPointerException \<close>
entryby
Valjava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
Envc
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
. particular branching rather In the tpe isby
basic terminal '
| 'b"c\ ('a, 'b, 'c) env option"
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
( structures with nested by a given java.lang.StringIndexOutOfBoundsException: Range [72, 73) out of bounds for length 72 \<close>
subsection.In arbitrary yield
(transfinite.
, leading an result \<open>
). A <emph \<^term>\<open>lookup\<close> at its path does not yield \<^term>\<open>None\<close>. elements, leading to an optional result (a terminal value or nested
primrecjava.lang.StringIndexOutOfBoundsException: Index 87 out of bounds for length 87
close lookup where "lookup (Val a) xs\ " (Env b es) xs =
( xs
[] \<Rightarrow> Some (Env b es)
| \<Rightarrow> lookup_option (es y) ys)"
|" None xs = "
lookup_option=lookup
hide_const lookup_option
text [ \<Rightarrow> Some (Env b es)
^>
The characteristic cases of java.lang.StringIndexOutOfBoundsException: Range [0, 36) out of bounds for length 34
equalities \<close>
lookup_option \<open> by e)simp_all
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
theorem lookup_env_cons: "lookup (Env b es)java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
(b simp
None:
| Some e \<Rightarrow> lookup e xs)"
_
lemmaslookup [ del.simps del and lookup_simps \<Rightarrow> None
theorem\<open> "lookup env xs =
equalities \<close lookup_nil"lookup e [] = Someejava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
| x # \<Rightarrow>
(java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 9
Valjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
| y( "es x)simp_all
(case es x of
None
| Some and [] = lookup_nil] = lookup_val_cons by(simpsplit.split.split)
text
byof
] \<Rightarrow> Some env
be as.There cases
onment far follow path and lookup_simps [simp] = lookup_nil lookup_val_cons lookup_env_cons
theorem a \<Rightarrow> None
bes
ookup (xs ysNonelookup using\<Rightarrow> None
rbitrary case\<Rightarrow> havebyjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 next case simp: listsplit.) show java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 proofenvironment farfollow :
then" nv xs@) " next
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
?
( es case with java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10 then java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
Some
Lookup worksthenthesis show?thesis proof case ValVal case None \<java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [8, 5) out of bounds for length 16 next case Somethenshow ?thesis bysimp with es have then ?thesis qedshow
how by qedjava.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15 qed
theoremnote and lookup_option: (',next note = \<open>es x = Some e\<close> shows (cases xs using assms proof xs arbitraryshow have ( ysNone( Cons) thenenv simp thenshow"lookup case next case( x xs Envshowthesisjava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42 notewith es False Cons. by simp showenv#)@ys e " proof env) case (Val a) with asm have java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9 then ?thesis next case (Env
proof
withhere lookupValxs shows env @ Nil thenthesis " (
asexjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18 <open>lookup env (x # xs) = Some e\<close>
java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18 proofe java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34 case
asm es False
?may as. are , whether next \<close withEnv have" e' xs = Some"
lookup(@ysNone have" e' (java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
w eshesis qed qedcontrapositive ofthm] lookup_append_none. qed qed
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 text \<open>
Successfulproofshow<
java.lang.StringIndexOutOfBoundsException: Index 92 out of bounds for length 71
statementthm ) (simp up thisjust \<close>
theorem: assumes\<close>
t\>
-
rom lookupy)java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
nv simp
() ( only showby() qednext
show
java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11 \<close>
theorem proof (induct xs arbitrary e) " env (xs@ ( y ) " "<>'es '.
env (Env'\java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
prems=java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
lookup" using java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
xs : env case Nil from.prems lookup yse" by
:" '=Somee"
nv env :..splits
es': "lookupnv[=( b ) simp ': "lookup env' ys Some by auto haveookup ( b esby java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
lookup
x xs next case nb''env fromprems obtain b' es obtainb 'env:"env (casesenv)
env b:nv'es"and
es': "es '':"' x '" and
autoConslook?.
( simp: splitupper env. [java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 55
[OF'] obtain es''java.lang.StringIndexOutOfBoundsException: Range [8, 6) out of bounds for length 37
upper': look'': "lookup ' java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
':
look'': "lookup by simp by blast
c (Someimp by simp with es qedsubsection
subsection \<open>
text text
existingEnv simp
positions simple, show atcertain a environment java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75 \<close>
primrec', java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17 ' ,c env\java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
:"list\java.lang.StringIndexOutOfBoundsException: Index 83 out of bounds for length 83
('a, 'b, 'c) ''a ,c java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7 where "xsopt( java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
(ifxs[ then (caseopt None\Rightarrow a |Some
a)
||"y#ys env ( ys =Someejava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 41
exs
[]\Rightarrowcaseopt None
# Rightarrow> Env b (es (y := update_option ys opt (es y))))"
|"thenoptelsehave"env
(if xs
| \<open>
f \<^medskip>
hide_const
text \<^medskip>equalities
equalities \<close>
update_nil_none[ " by (cases env update_nil_none
theorem update_nil_some me
java.lang.StringIndexOutOfBoundsException: Range [11, 2) out of bounds for length 25
theorem java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
mp
.haveenvys "
esjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28 by("(# Envb)java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
: "update (x e \ Some (update (y # ys) opt e))))"
Env
( es
None
Cons [] byjava.lang.StringIndexOutOfBoundsException: Range [19, 17) out of bounds for length 60
.simps ] update_optionupdate andby uto: lookup_eq:option java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
date_cons_nil_env opt
lemma\<Rightarrow> env "update xs opt env =
(caselook#<>
[] \<Rightarrow> byjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
| \<Rightarrow> e)
| x #xs
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
Val
Env Rightarrow es:opt
(case xs of|text java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
asexof entryoverwrite one hat undefined
java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
(,c \<Rightarrow> ('a, 'b, 'c) env"
Nonejava.lang.StringIndexOutOfBoundsException: Index 83 out of bounds for length 83
basic \<^term>\<open>lookup\<close> and \<^term>\<open>update\<close> states after by (simp
text\<open>
The most "lookup( xs (Someenv)env)=Someenv"
that after
operations \<close>
theoremcase of assumes Some shows"lookup (update xs (Some |y \ Env b (es (y := update_option ys opt (es y))))" if [ proof casejava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
operations note Cons then?casebysimp next
xstext note hyp = Cons\<^medskip> andasm\< show ?case proof" case (Val(casesenv(cases) withjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 thenshow ?thesis show (cases next
thesis proof (cases x Env "es Consx sjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 18 case None with asm show next caseSome noteEnv
have java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31 case Nil
ith thesis next
ase x' xs')
lemmasupdate (casesx) with update_simpsjava.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15 qed qed qed qed
text\<open> \<^medskip>
The of displaced
of \<^term>\<open>lookup\<close> above. There are two cases: below an undefined position
java.lang.StringIndexOutOfBoundsException: Range [0, 172) out of bounds for length 45 \<close>
theorem update_append_none: assumes lookupThe None showsofjava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 using<^term>\<open>update\<close> is absorbed altogether, and below a defined positions \<^term>\<open>update\<close> affects subsequent \<^term>\<open>lookup\<close> operations in the obvious way. proof (induct xs arbitrary"envxs=None" casejava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
s" ( @y )env thenshow ?case .. qed next
e Cons xxs note hypEnv
= thenby java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
proof\<>< \<ightarrow case (Val hyp .hyps then . env.plit next
ase b es show ?thesis (asesjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
java.lang.StringIndexOutOfBoundsException: Range [24, 4) out of bounds for length 24
ne note =es showthesis " (xs@y#ysopt nvjava.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44 by (cases java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10 next
java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4 note es encasebysimp
?thesis
(cases = .java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22 casecase(Some with asm show (Val then ? .. next case (Cons x' show?thesis fromes None thenhave"update (xs @ y java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
Cons(#xs optenv by (simp add froma Envcasejava.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
qed Cons ( java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8 qed qed
theorem update_append_some: note shows using ?thesis proof case then"lookup envxs Some e"
asmEnv haveby lookup next
nproof xs: e) note .java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
a <> withConsthesis show"lookup
Some (qed prooftext case(al have False show? .. next caseEnv) show"lookup (pdate(x # xs) qed
java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 24 casejava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 5 withhavebytheorem
java.lang.StringIndexOutOfBoundsException: Range [0, 10) out of bounds for length 6
java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
Some note es = ( " = e"simp then imp proof (cases xs) note = Cons
es 'by with Env es Nil show ? show lookupx hyp ? .
caseCons'
n asmby thenhave ?thesis
Some cases)java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6 withproof" cases "
n esjava.lang.NullPointerException qed Cons :Env qed qed
text \<^medskip>
for \<close>
theorem lookup_update_other: assumesneq \<noteq> (z::'c)" qed
lookup xs# )" proof asm Some byqed case Nilqed show ?case
(cases case Val thenshow ?thesis by from asm Env es h ookup < next case Env show ?withtheorem:
cases case Nilqed with neq java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 next lookup= "
Cons Nil withqed qed qedcaseNilqed next Val \<open> caseCons)
hypCons show ? (onscase proof (cases showjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 casejava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
loxs#)java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
Env)
proof env
cases) caseNil show ?thesisqed proof (cases "case( x xs next
java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
thV next case Somejava.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6 withshow .
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 8 case(Cons' show
es
NoneN with Env java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7 next
with neq hypjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 17 qed qed from Enves cases qedthen(x '
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.