src/HOL/Bali/State.thy
author wenzelm
Fri Feb 18 16:36:42 2011 +0100 (2011-02-18)
changeset 41778 5f79a9e42507
parent 40607 30d512bf47a7
child 55417 01fbfb60c33e
permissions -rw-r--r--
modernized specifications;
wenzelm@12857
     1
(*  Title:      HOL/Bali/State.thy
schirmer@12854
     2
    Author:     David von Oheimb
schirmer@12854
     3
*)
schirmer@12854
     4
header {* State for evaluation of Java expressions and statements *}
schirmer@12854
     5
haftmann@33965
     6
theory State
haftmann@33965
     7
imports DeclConcepts
haftmann@33965
     8
begin
schirmer@12854
     9
schirmer@12854
    10
text {*
schirmer@12854
    11
design issues:
schirmer@12854
    12
\begin{itemize}
schirmer@12854
    13
\item all kinds of objects (class instances, arrays, and class objects)
schirmer@12854
    14
  are handeled via a general object abstraction
schirmer@12854
    15
\item the heap and the map for class objects are combined into a single table
schirmer@12854
    16
  @{text "(recall (loc, obj) table \<times> (qtname, obj) table  ~=  (loc + qtname, obj) table)"}
schirmer@12854
    17
\end{itemize}
schirmer@12854
    18
*}
schirmer@12854
    19
schirmer@12854
    20
section "objects"
schirmer@12854
    21
schirmer@13688
    22
datatype  obj_tag =     --{* tag for generic object   *}
wenzelm@32960
    23
          CInst qtname  --{* class instance           *}
wenzelm@32960
    24
        | Arr  ty int   --{* array with component type and length *}
schirmer@13688
    25
    --{* | CStat qtname   the tag is irrelevant for a class object,
wenzelm@32960
    26
                           i.e. the static fields of a class,
schirmer@12925
    27
                           since its type is given already by the reference to 
schirmer@13688
    28
                           it (see below) *}
schirmer@12854
    29
wenzelm@41778
    30
type_synonym vn = "fspec + int"                 --{* variable name      *}
wenzelm@32960
    31
record  obj  = 
schirmer@13688
    32
          tag :: "obj_tag"                      --{* generalized object *}
haftmann@31127
    33
          "values" :: "(vn, val) table"      
schirmer@12854
    34
schirmer@12854
    35
translations 
wenzelm@35431
    36
  (type) "fspec" <= (type) "vname \<times> qtname" 
wenzelm@35431
    37
  (type) "vn"    <= (type) "fspec + int"
wenzelm@35431
    38
  (type) "obj"   <= (type) "\<lparr>tag::obj_tag, values::vn \<Rightarrow> val option\<rparr>"
wenzelm@35431
    39
  (type) "obj"   <= (type) "\<lparr>tag::obj_tag, values::vn \<Rightarrow> val option,\<dots>::'a\<rparr>"
schirmer@12854
    40
wenzelm@37956
    41
definition
wenzelm@37956
    42
  the_Arr :: "obj option \<Rightarrow> ty \<times> int \<times> (vn, val) table"
wenzelm@37956
    43
  where "the_Arr obj = (SOME (T,k,t). obj = Some \<lparr>tag=Arr T k,values=t\<rparr>)"
schirmer@12854
    44
schirmer@12854
    45
lemma the_Arr_Arr [simp]: "the_Arr (Some \<lparr>tag=Arr T k,values=cs\<rparr>) = (T,k,cs)"
schirmer@12854
    46
apply (auto simp: the_Arr_def)
schirmer@12854
    47
done
schirmer@12854
    48
schirmer@12854
    49
lemma the_Arr_Arr1 [simp,intro,dest]:
schirmer@12854
    50
 "\<lbrakk>tag obj = Arr T k\<rbrakk> \<Longrightarrow> the_Arr (Some obj) = (T,k,values obj)"
schirmer@12854
    51
apply (auto simp add: the_Arr_def)
schirmer@12854
    52
done
schirmer@12854
    53
wenzelm@37956
    54
definition
wenzelm@37956
    55
  upd_obj :: "vn \<Rightarrow> val \<Rightarrow> obj \<Rightarrow> obj"
wenzelm@37956
    56
  where "upd_obj n v = (\<lambda>obj. obj \<lparr>values:=(values obj)(n\<mapsto>v)\<rparr>)"
schirmer@12854
    57
schirmer@12854
    58
lemma upd_obj_def2 [simp]: 
schirmer@12854
    59
  "upd_obj n v obj = obj \<lparr>values:=(values obj)(n\<mapsto>v)\<rparr>" 
schirmer@12854
    60
apply (auto simp: upd_obj_def)
schirmer@12854
    61
done
schirmer@12854
    62
wenzelm@37956
    63
definition
wenzelm@37956
    64
  obj_ty :: "obj \<Rightarrow> ty" where
wenzelm@37956
    65
  "obj_ty obj = (case tag obj of 
wenzelm@37956
    66
                  CInst C \<Rightarrow> Class C 
wenzelm@37956
    67
                | Arr T k \<Rightarrow> T.[])"
schirmer@12854
    68
schirmer@12854
    69
lemma obj_ty_eq [intro!]: "obj_ty \<lparr>tag=oi,values=x\<rparr> = obj_ty \<lparr>tag=oi,values=y\<rparr>" 
schirmer@12854
    70
by (simp add: obj_ty_def)
schirmer@12854
    71
schirmer@12854
    72
schirmer@12854
    73
lemma obj_ty_eq1 [intro!,dest]: 
schirmer@12854
    74
  "tag obj = tag obj' \<Longrightarrow> obj_ty obj = obj_ty obj'" 
schirmer@12854
    75
by (simp add: obj_ty_def)
schirmer@12854
    76
schirmer@12854
    77
lemma obj_ty_cong [simp]: 
schirmer@12854
    78
  "obj_ty (obj \<lparr>values:=vs\<rparr>) = obj_ty obj" 
schirmer@12854
    79
by auto
schirmer@13688
    80
schirmer@12854
    81
lemma obj_ty_CInst [simp]: 
schirmer@12854
    82
 "obj_ty \<lparr>tag=CInst C,values=vs\<rparr> = Class C" 
schirmer@12854
    83
by (simp add: obj_ty_def)
schirmer@12854
    84
schirmer@12854
    85
lemma obj_ty_CInst1 [simp,intro!,dest]: 
schirmer@12854
    86
 "\<lbrakk>tag obj = CInst C\<rbrakk> \<Longrightarrow> obj_ty obj = Class C" 
schirmer@12854
    87
by (simp add: obj_ty_def)
schirmer@12854
    88
schirmer@12854
    89
lemma obj_ty_Arr [simp]: 
schirmer@12854
    90
 "obj_ty \<lparr>tag=Arr T i,values=vs\<rparr> = T.[]"
schirmer@12854
    91
by (simp add: obj_ty_def)
schirmer@12854
    92
schirmer@12854
    93
lemma obj_ty_Arr1 [simp,intro!,dest]: 
schirmer@12854
    94
 "\<lbrakk>tag obj = Arr T i\<rbrakk> \<Longrightarrow> obj_ty obj = T.[]"
schirmer@12854
    95
by (simp add: obj_ty_def)
schirmer@12854
    96
schirmer@12854
    97
lemma obj_ty_widenD: 
schirmer@12854
    98
 "G\<turnstile>obj_ty obj\<preceq>RefT t \<Longrightarrow> (\<exists>C. tag obj = CInst C) \<or> (\<exists>T k. tag obj = Arr T k)"
schirmer@12854
    99
apply (unfold obj_ty_def)
schirmer@12854
   100
apply (auto split add: obj_tag.split_asm)
schirmer@12854
   101
done
schirmer@12854
   102
wenzelm@37956
   103
definition
wenzelm@37956
   104
  obj_class :: "obj \<Rightarrow> qtname" where
wenzelm@37956
   105
  "obj_class obj = (case tag obj of 
wenzelm@37956
   106
                     CInst C \<Rightarrow> C 
wenzelm@37956
   107
                   | Arr T k \<Rightarrow> Object)"
schirmer@12854
   108
schirmer@12854
   109
schirmer@12854
   110
lemma obj_class_CInst [simp]: "obj_class \<lparr>tag=CInst C,values=vs\<rparr> = C" 
schirmer@12854
   111
by (auto simp: obj_class_def)
schirmer@12854
   112
schirmer@12854
   113
lemma obj_class_CInst1 [simp,intro!,dest]: 
schirmer@12854
   114
  "tag obj = CInst C \<Longrightarrow> obj_class obj = C" 
schirmer@12854
   115
by (auto simp: obj_class_def)
schirmer@12854
   116
schirmer@12854
   117
lemma obj_class_Arr [simp]: "obj_class \<lparr>tag=Arr T k,values=vs\<rparr> = Object" 
schirmer@12854
   118
by (auto simp: obj_class_def)
schirmer@12854
   119
schirmer@12854
   120
lemma obj_class_Arr1 [simp,intro!,dest]: 
schirmer@12854
   121
 "tag obj = Arr T k \<Longrightarrow> obj_class obj = Object" 
schirmer@12854
   122
by (auto simp: obj_class_def)
schirmer@12854
   123
schirmer@12854
   124
lemma obj_ty_obj_class: "G\<turnstile>obj_ty obj\<preceq> Class statC = G\<turnstile>obj_class obj \<preceq>\<^sub>C statC"
schirmer@12854
   125
apply (case_tac "tag obj")
schirmer@12854
   126
apply (auto simp add: obj_ty_def obj_class_def)
schirmer@12854
   127
apply (case_tac "statC = Object")
schirmer@12854
   128
apply (auto dest: widen_Array_Class)
schirmer@12854
   129
done
schirmer@12854
   130
schirmer@12854
   131
section "object references"
schirmer@12854
   132
wenzelm@41778
   133
type_synonym oref = "loc + qtname"         --{* generalized object reference *}
schirmer@12854
   134
syntax
schirmer@12854
   135
  Heap  :: "loc   \<Rightarrow> oref"
schirmer@12854
   136
  Stat  :: "qtname \<Rightarrow> oref"
schirmer@12854
   137
schirmer@12854
   138
translations
haftmann@33965
   139
  "Heap" => "CONST Inl"
haftmann@33965
   140
  "Stat" => "CONST Inr"
wenzelm@35431
   141
  (type) "oref" <= (type) "loc + qtname"
schirmer@12854
   142
wenzelm@37956
   143
definition
wenzelm@37956
   144
  fields_table :: "prog \<Rightarrow> qtname \<Rightarrow> (fspec \<Rightarrow> field \<Rightarrow> bool)  \<Rightarrow> (fspec, ty) table" where
wenzelm@37956
   145
  "fields_table G C P =
wenzelm@37956
   146
    Option.map type \<circ> table_of (filter (split P) (DeclConcepts.fields G C))"
schirmer@12854
   147
schirmer@12854
   148
lemma fields_table_SomeI: 
schirmer@12854
   149
"\<lbrakk>table_of (DeclConcepts.fields G C) n = Some f; P n f\<rbrakk> 
schirmer@12854
   150
 \<Longrightarrow> fields_table G C P n = Some (type f)"
schirmer@12854
   151
apply (unfold fields_table_def)
schirmer@12854
   152
apply clarsimp
schirmer@12854
   153
apply (rule exI)
schirmer@12854
   154
apply (rule conjI)
schirmer@12854
   155
apply (erule map_of_filter_in)
schirmer@12854
   156
apply assumption
schirmer@12854
   157
apply simp
schirmer@12854
   158
done
schirmer@12854
   159
schirmer@12854
   160
(* unused *)
schirmer@12854
   161
lemma fields_table_SomeD': "fields_table G C P fn = Some T \<Longrightarrow>  
schirmer@12854
   162
  \<exists>f. (fn,f)\<in>set(DeclConcepts.fields G C) \<and> type f = T"
schirmer@12854
   163
apply (unfold fields_table_def)
schirmer@12854
   164
apply clarsimp
schirmer@12854
   165
apply (drule map_of_SomeD)
schirmer@12854
   166
apply auto
schirmer@12854
   167
done
schirmer@12854
   168
schirmer@12854
   169
lemma fields_table_SomeD: 
schirmer@12854
   170
"\<lbrakk>fields_table G C P fn = Some T; unique (DeclConcepts.fields G C)\<rbrakk> \<Longrightarrow>  
schirmer@12854
   171
  \<exists>f. table_of (DeclConcepts.fields G C) fn = Some f \<and> type f = T"
schirmer@12854
   172
apply (unfold fields_table_def)
schirmer@12854
   173
apply clarsimp
schirmer@12854
   174
apply (rule exI)
schirmer@12854
   175
apply (rule conjI)
schirmer@12854
   176
apply (erule table_of_filter_unique_SomeD)
schirmer@12854
   177
apply assumption
schirmer@12854
   178
apply simp
schirmer@12854
   179
done
schirmer@12854
   180
wenzelm@37956
   181
definition
wenzelm@37956
   182
  in_bounds :: "int \<Rightarrow> int \<Rightarrow> bool" ("(_/ in'_bounds _)" [50, 51] 50)
wenzelm@37956
   183
  where "i in_bounds k = (0 \<le> i \<and> i < k)"
schirmer@12854
   184
wenzelm@37956
   185
definition
wenzelm@37956
   186
  arr_comps :: "'a \<Rightarrow> int \<Rightarrow> int \<Rightarrow> 'a option"
wenzelm@37956
   187
  where "arr_comps T k = (\<lambda>i. if i in_bounds k then Some T else None)"
schirmer@12854
   188
  
wenzelm@37956
   189
definition
wenzelm@37956
   190
  var_tys :: "prog \<Rightarrow> obj_tag \<Rightarrow> oref \<Rightarrow> (vn, ty) table" where
wenzelm@37956
   191
  "var_tys G oi r =
wenzelm@37956
   192
    (case r of 
schirmer@12854
   193
      Heap a \<Rightarrow> (case oi of 
schirmer@12854
   194
                   CInst C \<Rightarrow> fields_table G C (\<lambda>n f. \<not>static f) (+) empty
schirmer@12854
   195
                 | Arr T k \<Rightarrow> empty (+) arr_comps T k)
schirmer@12854
   196
    | Stat C \<Rightarrow> fields_table G C (\<lambda>fn f. declclassf fn = C \<and> static f) 
wenzelm@37956
   197
                (+) empty)"
schirmer@12854
   198
schirmer@12854
   199
lemma var_tys_Some_eq: 
schirmer@12854
   200
 "var_tys G oi r n = Some T 
schirmer@12854
   201
  = (case r of 
schirmer@12854
   202
       Inl a \<Rightarrow> (case oi of  
schirmer@12854
   203
                   CInst C \<Rightarrow> (\<exists>nt. n = Inl nt \<and> fields_table G C (\<lambda>n f. 
schirmer@12854
   204
                               \<not>static f) nt = Some T)  
schirmer@12854
   205
                 | Arr t k \<Rightarrow> (\<exists> i. n = Inr i  \<and> i in_bounds k \<and> t = T))  
schirmer@12854
   206
     | Inr C \<Rightarrow> (\<exists>nt. n = Inl nt \<and> 
schirmer@12854
   207
                 fields_table G C (\<lambda>fn f. declclassf fn = C \<and> static f) nt 
schirmer@12854
   208
                  = Some T))"
schirmer@12854
   209
apply (unfold var_tys_def arr_comps_def)
schirmer@12854
   210
apply (force split add: sum.split_asm sum.split obj_tag.split)
schirmer@12854
   211
done
schirmer@12854
   212
schirmer@12854
   213
schirmer@12854
   214
section "stores"
schirmer@12854
   215
wenzelm@41778
   216
type_synonym globs               --{* global variables: heap and static variables *}
wenzelm@32960
   217
        = "(oref , obj) table"
wenzelm@41778
   218
type_synonym heap
wenzelm@32960
   219
        = "(loc  , obj) table"
wenzelm@41778
   220
(* type_synonym locals                   
wenzelm@32960
   221
        = "(lname, val) table" *) (* defined in Value.thy local variables *)
schirmer@12854
   222
schirmer@12854
   223
translations
wenzelm@35431
   224
 (type) "globs"  <= (type) "(oref , obj) table"
wenzelm@35431
   225
 (type) "heap"   <= (type) "(loc  , obj) table"
wenzelm@35431
   226
(*  (type) "locals" <= (type) "(lname, val) table" *)
schirmer@12854
   227
schirmer@12854
   228
datatype st = (* pure state, i.e. contents of all variables *)
wenzelm@32960
   229
         st globs locals
schirmer@12854
   230
schirmer@12854
   231
subsection "access"
schirmer@12854
   232
wenzelm@37956
   233
definition
wenzelm@37956
   234
  globs :: "st \<Rightarrow> globs"
wenzelm@37956
   235
  where "globs = st_case (\<lambda>g l. g)"
schirmer@12854
   236
  
wenzelm@37956
   237
definition
wenzelm@37956
   238
  locals :: "st \<Rightarrow> locals"
wenzelm@37956
   239
  where "locals = st_case (\<lambda>g l. l)"
schirmer@12854
   240
wenzelm@37956
   241
definition heap :: "st \<Rightarrow> heap" where
wenzelm@37956
   242
 "heap s = globs s \<circ> Heap"
schirmer@12854
   243
schirmer@12854
   244
schirmer@12854
   245
lemma globs_def2 [simp]: " globs (st g l) = g"
schirmer@12854
   246
by (simp add: globs_def)
schirmer@12854
   247
schirmer@12854
   248
lemma locals_def2 [simp]: "locals (st g l) = l"
schirmer@12854
   249
by (simp add: locals_def)
schirmer@12854
   250
schirmer@12854
   251
lemma heap_def2 [simp]:  "heap s a=globs s (Heap a)"
schirmer@12854
   252
by (simp add: heap_def)
schirmer@12854
   253
schirmer@12854
   254
wenzelm@35067
   255
abbreviation val_this :: "st \<Rightarrow> val"
wenzelm@35067
   256
  where "val_this s == the (locals s This)"
schirmer@12854
   257
wenzelm@35067
   258
abbreviation lookup_obj :: "st \<Rightarrow> val \<Rightarrow> obj"
wenzelm@35067
   259
  where "lookup_obj s a' == the (heap s (the_Addr a'))"
schirmer@12854
   260
schirmer@12854
   261
subsection "memory allocation"
schirmer@12854
   262
wenzelm@37956
   263
definition
wenzelm@37956
   264
  new_Addr :: "heap \<Rightarrow> loc option" where
wenzelm@37956
   265
  "new_Addr h = (if (\<forall>a. h a \<noteq> None) then None else Some (SOME a. h a = None))"
schirmer@12854
   266
schirmer@12854
   267
lemma new_AddrD: "new_Addr h = Some a \<Longrightarrow> h a = None"
nipkow@18576
   268
apply (auto simp add: new_Addr_def)
paulson@18447
   269
apply (erule someI) 
schirmer@12854
   270
done
schirmer@12854
   271
schirmer@12854
   272
lemma new_AddrD2: "new_Addr h = Some a \<Longrightarrow> \<forall>b. h b \<noteq> None \<longrightarrow> b \<noteq> a"
schirmer@12854
   273
apply (drule new_AddrD)
schirmer@12854
   274
apply auto
schirmer@12854
   275
done
schirmer@12854
   276
schirmer@12854
   277
lemma new_Addr_SomeI: "h a = None \<Longrightarrow> \<exists>b. new_Addr h = Some b \<and> h b = None"
nipkow@18576
   278
apply (simp add: new_Addr_def)
paulson@18447
   279
apply (fast intro: someI2)
schirmer@12854
   280
done
schirmer@12854
   281
schirmer@12854
   282
schirmer@12854
   283
subsection "initialization"
schirmer@12854
   284
wenzelm@35067
   285
abbreviation init_vals :: "('a, ty) table \<Rightarrow> ('a, val) table"
wenzelm@35067
   286
  where "init_vals vs == Option.map default_val \<circ> vs"
schirmer@12854
   287
schirmer@12854
   288
lemma init_arr_comps_base [simp]: "init_vals (arr_comps T 0) = empty"
schirmer@12854
   289
apply (unfold arr_comps_def in_bounds_def)
schirmer@12854
   290
apply (rule ext)
schirmer@12854
   291
apply auto
schirmer@12854
   292
done
schirmer@12854
   293
schirmer@12854
   294
lemma init_arr_comps_step [simp]: 
schirmer@12854
   295
"0 < j \<Longrightarrow> init_vals (arr_comps T  j    ) =  
schirmer@12854
   296
           init_vals (arr_comps T (j - 1))(j - 1\<mapsto>default_val T)"
schirmer@12854
   297
apply (unfold arr_comps_def in_bounds_def)
schirmer@12854
   298
apply (rule ext)
schirmer@12854
   299
apply auto
schirmer@12854
   300
done
schirmer@12854
   301
schirmer@12854
   302
subsection "update"
schirmer@12854
   303
wenzelm@37956
   304
definition
wenzelm@37956
   305
  gupd :: "oref  \<Rightarrow> obj \<Rightarrow> st \<Rightarrow> st" ("gupd'(_\<mapsto>_')" [10, 10] 1000)
wenzelm@37956
   306
  where "gupd r obj = st_case (\<lambda>g l. st (g(r\<mapsto>obj)) l)"
schirmer@12854
   307
wenzelm@37956
   308
definition
wenzelm@37956
   309
  lupd :: "lname \<Rightarrow> val \<Rightarrow> st \<Rightarrow> st" ("lupd'(_\<mapsto>_')" [10, 10] 1000)
wenzelm@37956
   310
  where "lupd vn v = st_case (\<lambda>g l. st g (l(vn\<mapsto>v)))"
schirmer@12854
   311
wenzelm@37956
   312
definition
wenzelm@37956
   313
  upd_gobj :: "oref \<Rightarrow> vn \<Rightarrow> val \<Rightarrow> st \<Rightarrow> st"
wenzelm@37956
   314
  where "upd_gobj r n v = st_case (\<lambda>g l. st (chg_map (upd_obj n v) r g) l)"
schirmer@12854
   315
wenzelm@37956
   316
definition
wenzelm@37956
   317
  set_locals  :: "locals \<Rightarrow> st \<Rightarrow> st"
wenzelm@37956
   318
  where "set_locals l = st_case (\<lambda>g l'. st g l)"
nipkow@30235
   319
wenzelm@37956
   320
definition
wenzelm@37956
   321
  init_obj :: "prog \<Rightarrow> obj_tag \<Rightarrow> oref \<Rightarrow> st \<Rightarrow> st"
wenzelm@37956
   322
  where "init_obj G oi r = gupd(r\<mapsto>\<lparr>tag=oi, values=init_vals (var_tys G oi r)\<rparr>)"
schirmer@12854
   323
wenzelm@35067
   324
abbreviation
schirmer@12854
   325
  init_class_obj :: "prog \<Rightarrow> qtname \<Rightarrow> st \<Rightarrow> st"
wenzelm@35067
   326
  where "init_class_obj G C == init_obj G undefined (Inr C)"
schirmer@12854
   327
schirmer@12854
   328
lemma gupd_def2 [simp]: "gupd(r\<mapsto>obj) (st g l) = st (g(r\<mapsto>obj)) l"
schirmer@12854
   329
apply (unfold gupd_def)
schirmer@12854
   330
apply (simp (no_asm))
schirmer@12854
   331
done
schirmer@12854
   332
schirmer@12854
   333
lemma lupd_def2 [simp]: "lupd(vn\<mapsto>v) (st g l) = st g (l(vn\<mapsto>v))"
schirmer@12854
   334
apply (unfold lupd_def)
schirmer@12854
   335
apply (simp (no_asm))
schirmer@12854
   336
done
schirmer@12854
   337
schirmer@12854
   338
lemma globs_gupd [simp]: "globs  (gupd(r\<mapsto>obj) s) = globs s(r\<mapsto>obj)"
schirmer@12854
   339
apply (induct "s")
schirmer@12854
   340
by (simp add: gupd_def)
schirmer@12854
   341
schirmer@12854
   342
lemma globs_lupd [simp]: "globs  (lupd(vn\<mapsto>v ) s) = globs  s"
schirmer@12854
   343
apply (induct "s")
schirmer@12854
   344
by (simp add: lupd_def)
schirmer@12854
   345
schirmer@12854
   346
lemma locals_gupd [simp]: "locals (gupd(r\<mapsto>obj) s) = locals s"
schirmer@12854
   347
apply (induct "s")
schirmer@12854
   348
by (simp add: gupd_def)
schirmer@12854
   349
schirmer@12854
   350
lemma locals_lupd [simp]: "locals (lupd(vn\<mapsto>v ) s) = locals s(vn\<mapsto>v )"
schirmer@12854
   351
apply (induct "s")
schirmer@12854
   352
by (simp add: lupd_def)
schirmer@12854
   353
schirmer@12854
   354
lemma globs_upd_gobj_new [rule_format (no_asm), simp]: 
schirmer@12854
   355
  "globs s r = None \<longrightarrow> globs (upd_gobj r n v s) = globs s"
schirmer@12854
   356
apply (unfold upd_gobj_def)
schirmer@12854
   357
apply (induct "s")
schirmer@12854
   358
apply auto
schirmer@12854
   359
done
schirmer@12854
   360
schirmer@12854
   361
lemma globs_upd_gobj_upd [rule_format (no_asm), simp]: 
schirmer@12854
   362
"globs s r=Some obj\<longrightarrow> globs (upd_gobj r n v s) = globs s(r\<mapsto>upd_obj n v obj)"
schirmer@12854
   363
apply (unfold upd_gobj_def)
schirmer@12854
   364
apply (induct "s")
schirmer@12854
   365
apply auto
schirmer@12854
   366
done
schirmer@12854
   367
schirmer@12854
   368
lemma locals_upd_gobj [simp]: "locals (upd_gobj r n v s) = locals s"
schirmer@12854
   369
apply (induct "s")
schirmer@12854
   370
by (simp add: upd_gobj_def) 
schirmer@12854
   371
schirmer@12854
   372
schirmer@12854
   373
lemma globs_init_obj [simp]: "globs (init_obj G oi r s) t =  
schirmer@12854
   374
  (if t=r then Some \<lparr>tag=oi,values=init_vals (var_tys G oi r)\<rparr> else globs s t)"
schirmer@12854
   375
apply (unfold init_obj_def)
schirmer@12854
   376
apply (simp (no_asm))
schirmer@12854
   377
done
schirmer@12854
   378
schirmer@12854
   379
lemma locals_init_obj [simp]: "locals (init_obj G oi r s) = locals s"
schirmer@12854
   380
by (simp add: init_obj_def)
schirmer@12854
   381
  
schirmer@12854
   382
lemma surjective_st [simp]: "st (globs s) (locals s) = s"
schirmer@12854
   383
apply (induct "s")
schirmer@12854
   384
by auto
schirmer@12854
   385
schirmer@12854
   386
lemma surjective_st_init_obj: 
schirmer@12854
   387
 "st (globs (init_obj G oi r s)) (locals s) = init_obj G oi r s"
schirmer@12854
   388
apply (subst locals_init_obj [THEN sym])
schirmer@12854
   389
apply (rule surjective_st)
schirmer@12854
   390
done
schirmer@12854
   391
schirmer@12854
   392
lemma heap_heap_upd [simp]: 
schirmer@12854
   393
  "heap (st (g(Inl a\<mapsto>obj)) l) = heap (st g l)(a\<mapsto>obj)"
schirmer@12854
   394
apply (rule ext)
schirmer@12854
   395
apply (simp (no_asm))
schirmer@12854
   396
done
schirmer@12854
   397
lemma heap_stat_upd [simp]: "heap (st (g(Inr C\<mapsto>obj)) l) = heap (st g l)"
schirmer@12854
   398
apply (rule ext)
schirmer@12854
   399
apply (simp (no_asm))
schirmer@12854
   400
done
schirmer@12854
   401
lemma heap_local_upd [simp]: "heap (st g (l(vn\<mapsto>v))) = heap (st g l)"
schirmer@12854
   402
apply (rule ext)
schirmer@12854
   403
apply (simp (no_asm))
schirmer@12854
   404
done
schirmer@12854
   405
schirmer@12854
   406
lemma heap_gupd_Heap [simp]: "heap (gupd(Heap a\<mapsto>obj) s) = heap s(a\<mapsto>obj)"
schirmer@12854
   407
apply (rule ext)
schirmer@12854
   408
apply (simp (no_asm))
schirmer@12854
   409
done
schirmer@12854
   410
lemma heap_gupd_Stat [simp]: "heap (gupd(Stat C\<mapsto>obj) s) = heap s"
schirmer@12854
   411
apply (rule ext)
schirmer@12854
   412
apply (simp (no_asm))
schirmer@12854
   413
done
schirmer@12854
   414
lemma heap_lupd [simp]: "heap (lupd(vn\<mapsto>v) s) = heap s"
schirmer@12854
   415
apply (rule ext)
schirmer@12854
   416
apply (simp (no_asm))
schirmer@12854
   417
done
schirmer@12854
   418
schirmer@12854
   419
lemma heap_upd_gobj_Stat [simp]: "heap (upd_gobj (Stat C) n v s) = heap s"
schirmer@12854
   420
apply (rule ext)
schirmer@12854
   421
apply (simp (no_asm))
schirmer@12854
   422
apply (case_tac "globs s (Stat C)")
schirmer@12854
   423
apply  auto
schirmer@12854
   424
done
schirmer@12854
   425
schirmer@12854
   426
lemma set_locals_def2 [simp]: "set_locals l (st g l') = st g l"
schirmer@12854
   427
apply (unfold set_locals_def)
schirmer@12854
   428
apply (simp (no_asm))
schirmer@12854
   429
done
schirmer@12854
   430
schirmer@12854
   431
lemma set_locals_id [simp]: "set_locals (locals s) s = s"
schirmer@12854
   432
apply (unfold set_locals_def)
schirmer@12854
   433
apply (induct_tac "s")
schirmer@12854
   434
apply (simp (no_asm))
schirmer@12854
   435
done
schirmer@12854
   436
schirmer@12854
   437
lemma set_set_locals [simp]: "set_locals l (set_locals l' s) = set_locals l s"
schirmer@12854
   438
apply (unfold set_locals_def)
schirmer@12854
   439
apply (induct_tac "s")
schirmer@12854
   440
apply (simp (no_asm))
schirmer@12854
   441
done
schirmer@12854
   442
schirmer@12854
   443
lemma locals_set_locals [simp]: "locals (set_locals l s) = l"
schirmer@12854
   444
apply (unfold set_locals_def)
schirmer@12854
   445
apply (induct_tac "s")
schirmer@12854
   446
apply (simp (no_asm))
schirmer@12854
   447
done
schirmer@12854
   448
schirmer@12854
   449
lemma globs_set_locals [simp]: "globs (set_locals l s) = globs s"
schirmer@12854
   450
apply (unfold set_locals_def)
schirmer@12854
   451
apply (induct_tac "s")
schirmer@12854
   452
apply (simp (no_asm))
schirmer@12854
   453
done
schirmer@12854
   454
schirmer@12854
   455
lemma heap_set_locals [simp]: "heap (set_locals l s) = heap s"
schirmer@12854
   456
apply (unfold heap_def)
schirmer@12854
   457
apply (induct_tac "s")
schirmer@12854
   458
apply (simp (no_asm))
schirmer@12854
   459
done
schirmer@12854
   460
schirmer@12854
   461
schirmer@12854
   462
section "abrupt completion"
schirmer@12854
   463
schirmer@12854
   464
schirmer@12854
   465
wenzelm@37956
   466
primrec the_Xcpt :: "abrupt \<Rightarrow> xcpt"
wenzelm@37956
   467
  where "the_Xcpt (Xcpt x) = x"
schirmer@12854
   468
wenzelm@37956
   469
primrec the_Jump :: "abrupt => jump"
wenzelm@37956
   470
  where "the_Jump (Jump j) = j"
schirmer@12854
   471
wenzelm@37956
   472
primrec the_Loc :: "xcpt \<Rightarrow> loc"
wenzelm@37956
   473
  where "the_Loc (Loc a) = a"
schirmer@12854
   474
wenzelm@37956
   475
primrec the_Std :: "xcpt \<Rightarrow> xname"
wenzelm@37956
   476
  where "the_Std (Std x) = x"
wenzelm@32960
   477
        
schirmer@12854
   478
wenzelm@37956
   479
definition
wenzelm@37956
   480
  abrupt_if :: "bool \<Rightarrow> abopt \<Rightarrow> abopt \<Rightarrow> abopt"
wenzelm@37956
   481
  where "abrupt_if c x' x = (if c \<and> (x = None) then x' else x)"
schirmer@12854
   482
schirmer@12854
   483
lemma abrupt_if_True_None [simp]: "abrupt_if True x None = x"
schirmer@12854
   484
by (simp add: abrupt_if_def)
schirmer@12854
   485
schirmer@12854
   486
lemma abrupt_if_True_not_None [simp]: "x \<noteq> None \<Longrightarrow> abrupt_if True x y \<noteq> None"
schirmer@12854
   487
by (simp add: abrupt_if_def)
schirmer@12854
   488
schirmer@12854
   489
lemma abrupt_if_False [simp]: "abrupt_if False x y = y"
schirmer@12854
   490
by (simp add: abrupt_if_def)
schirmer@12854
   491
schirmer@12854
   492
lemma abrupt_if_Some [simp]: "abrupt_if c x (Some y) = Some y"
schirmer@12854
   493
by (simp add: abrupt_if_def)
schirmer@12854
   494
schirmer@12854
   495
lemma abrupt_if_not_None [simp]: "y \<noteq> None \<Longrightarrow> abrupt_if c x y = y"
schirmer@12854
   496
apply (simp add: abrupt_if_def)
schirmer@12854
   497
by auto
schirmer@12854
   498
schirmer@12854
   499
schirmer@12854
   500
lemma split_abrupt_if: 
schirmer@12854
   501
"P (abrupt_if c x' x) = 
schirmer@12854
   502
      ((c \<and> x = None \<longrightarrow> P x') \<and> (\<not> (c \<and> x = None) \<longrightarrow> P x))"
schirmer@12854
   503
apply (unfold abrupt_if_def)
schirmer@12854
   504
apply (split split_if)
schirmer@12854
   505
apply auto
schirmer@12854
   506
done
schirmer@12854
   507
wenzelm@35067
   508
abbreviation raise_if :: "bool \<Rightarrow> xname \<Rightarrow> abopt \<Rightarrow> abopt"
wenzelm@35067
   509
  where "raise_if c xn == abrupt_if c (Some (Xcpt (Std xn)))"
wenzelm@35067
   510
wenzelm@35067
   511
abbreviation np :: "val \<Rightarrow> abopt \<Rightarrow> abopt"
wenzelm@35067
   512
  where "np v == raise_if (v = Null) NullPointer"
schirmer@12854
   513
wenzelm@35067
   514
abbreviation check_neg :: "val \<Rightarrow> abopt \<Rightarrow> abopt"
wenzelm@35067
   515
  where "check_neg i' == raise_if (the_Intg i'<0) NegArrSize"
schirmer@12854
   516
wenzelm@35067
   517
abbreviation error_if :: "bool \<Rightarrow> error \<Rightarrow> abopt \<Rightarrow> abopt"
wenzelm@35067
   518
  where "error_if c e == abrupt_if c (Some (Error e))"
schirmer@12854
   519
schirmer@12854
   520
lemma raise_if_None [simp]: "(raise_if c x y = None) = (\<not>c \<and> y = None)"
schirmer@12854
   521
apply (simp add: abrupt_if_def)
schirmer@12854
   522
by auto
schirmer@12854
   523
declare raise_if_None [THEN iffD1, dest!]
schirmer@12854
   524
schirmer@12854
   525
lemma if_raise_if_None [simp]: 
schirmer@12854
   526
  "((if b then y else raise_if c x y) = None) = ((c \<longrightarrow> b) \<and> y = None)"
schirmer@12854
   527
apply (simp add: abrupt_if_def)
schirmer@12854
   528
apply auto
schirmer@12854
   529
done
schirmer@12854
   530
schirmer@12854
   531
lemma raise_if_SomeD [dest!]:
schirmer@12854
   532
  "raise_if c x y = Some z \<Longrightarrow> c \<and> z=(Xcpt (Std x)) \<and> y=None \<or> (y=Some z)"
schirmer@12854
   533
apply (case_tac y)
schirmer@12854
   534
apply (case_tac c)
schirmer@12854
   535
apply (simp add: abrupt_if_def)
schirmer@12854
   536
apply (simp add: abrupt_if_def)
schirmer@12854
   537
apply auto
schirmer@12854
   538
done
schirmer@12854
   539
schirmer@12925
   540
lemma error_if_None [simp]: "(error_if c e y = None) = (\<not>c \<and> y = None)"
schirmer@12925
   541
apply (simp add: abrupt_if_def)
schirmer@12925
   542
by auto
schirmer@12925
   543
declare error_if_None [THEN iffD1, dest!]
schirmer@12925
   544
schirmer@12925
   545
lemma if_error_if_None [simp]: 
schirmer@12925
   546
  "((if b then y else error_if c e y) = None) = ((c \<longrightarrow> b) \<and> y = None)"
schirmer@12925
   547
apply (simp add: abrupt_if_def)
schirmer@12925
   548
apply auto
schirmer@12925
   549
done
schirmer@12925
   550
wenzelm@13524
   551
lemma error_if_SomeD [dest!]:
schirmer@12925
   552
  "error_if c e y = Some z \<Longrightarrow> c \<and> z=(Error e) \<and> y=None \<or> (y=Some z)"
schirmer@12925
   553
apply (case_tac y)
schirmer@12925
   554
apply (case_tac c)
schirmer@12925
   555
apply (simp add: abrupt_if_def)
schirmer@12925
   556
apply (simp add: abrupt_if_def)
schirmer@12925
   557
apply auto
schirmer@12925
   558
done
schirmer@12925
   559
wenzelm@37956
   560
definition
wenzelm@37956
   561
  absorb :: "jump \<Rightarrow> abopt \<Rightarrow> abopt"
wenzelm@37956
   562
  where "absorb j a = (if a=Some (Jump j) then None else a)"
schirmer@12854
   563
schirmer@12854
   564
lemma absorb_SomeD [dest!]: "absorb j a = Some x \<Longrightarrow> a = Some x"
schirmer@12854
   565
by (auto simp add: absorb_def)
schirmer@12854
   566
schirmer@12854
   567
lemma absorb_same [simp]: "absorb j (Some (Jump j)) = None"
schirmer@12854
   568
by (auto simp add: absorb_def)
schirmer@12854
   569
schirmer@12854
   570
lemma absorb_other [simp]: "a \<noteq> Some (Jump j) \<Longrightarrow> absorb j a = a"
schirmer@12854
   571
by (auto simp add: absorb_def)
schirmer@12854
   572
schirmer@13688
   573
lemma absorb_Some_NoneD: "absorb j (Some abr) = None \<Longrightarrow> abr = Jump j"
schirmer@13688
   574
  by (simp add: absorb_def)
schirmer@13688
   575
schirmer@13688
   576
lemma absorb_Some_JumpD: "absorb j s = Some (Jump j') \<Longrightarrow> j'\<noteq>j"
schirmer@13688
   577
  by (simp add: absorb_def)
schirmer@13688
   578
schirmer@12854
   579
schirmer@12854
   580
section "full program state"
schirmer@12854
   581
wenzelm@41778
   582
type_synonym
schirmer@13688
   583
  state = "abopt \<times> st"          --{* state including abruption information *}
schirmer@12854
   584
schirmer@12854
   585
translations
wenzelm@35431
   586
  (type) "abopt" <= (type) "abrupt option"
wenzelm@35431
   587
  (type) "state" <= (type) "abopt \<times> st"
schirmer@12854
   588
wenzelm@35067
   589
abbreviation
wenzelm@35067
   590
  Norm :: "st \<Rightarrow> state"
wenzelm@35067
   591
  where "Norm s == (None, s)"
schirmer@12854
   592
wenzelm@35067
   593
abbreviation (input)
wenzelm@35067
   594
  abrupt :: "state \<Rightarrow> abopt"
wenzelm@35067
   595
  where "abrupt == fst"
wenzelm@35067
   596
wenzelm@35067
   597
abbreviation (input)
wenzelm@35067
   598
  store :: "state \<Rightarrow> st"
wenzelm@35067
   599
  where "store == snd"
schirmer@12854
   600
schirmer@12854
   601
lemma single_stateE: "\<forall>Z. Z = (s::state) \<Longrightarrow> False"
schirmer@12854
   602
apply (erule_tac x = "(Some k,y)" in all_dupE)
schirmer@12854
   603
apply (erule_tac x = "(None,y)" in allE)
schirmer@12854
   604
apply clarify
schirmer@12854
   605
done
schirmer@12854
   606
schirmer@12854
   607
lemma state_not_single: "All (op = (x::state)) \<Longrightarrow> R"
schirmer@12854
   608
apply (drule_tac x = "(if abrupt x = None then Some ?x else None,?y)" in spec)
schirmer@12854
   609
apply clarsimp
schirmer@12854
   610
done
schirmer@12854
   611
wenzelm@37956
   612
definition
wenzelm@37956
   613
  normal :: "state \<Rightarrow> bool"
wenzelm@37956
   614
  where "normal = (\<lambda>s. abrupt s = None)"
schirmer@12854
   615
schirmer@12854
   616
lemma normal_def2 [simp]: "normal s = (abrupt s = None)"
schirmer@12854
   617
apply (unfold normal_def)
schirmer@12854
   618
apply (simp (no_asm))
schirmer@12854
   619
done
schirmer@12854
   620
wenzelm@37956
   621
definition
wenzelm@37956
   622
  heap_free :: "nat \<Rightarrow> state \<Rightarrow> bool"
wenzelm@37956
   623
  where "heap_free n = (\<lambda>s. atleast_free (heap (store s)) n)"
schirmer@12854
   624
schirmer@12854
   625
lemma heap_free_def2 [simp]: "heap_free n s = atleast_free (heap (store s)) n"
schirmer@12854
   626
apply (unfold heap_free_def)
schirmer@12854
   627
apply simp
schirmer@12854
   628
done
schirmer@12854
   629
schirmer@12854
   630
subsection "update"
schirmer@12854
   631
wenzelm@37956
   632
definition
wenzelm@37956
   633
  abupd :: "(abopt \<Rightarrow> abopt) \<Rightarrow> state \<Rightarrow> state"
haftmann@40607
   634
  where "abupd f = map_pair f id"
schirmer@12854
   635
wenzelm@37956
   636
definition
wenzelm@37956
   637
  supd :: "(st \<Rightarrow> st) \<Rightarrow> state \<Rightarrow> state"
haftmann@40607
   638
  where "supd = map_pair id"
schirmer@12854
   639
  
schirmer@12854
   640
lemma abupd_def2 [simp]: "abupd f (x,s) = (f x,s)"
schirmer@12854
   641
by (simp add: abupd_def)
schirmer@12854
   642
schirmer@12854
   643
lemma abupd_abrupt_if_False [simp]: "\<And> s. abupd (abrupt_if False xo) s = s"
schirmer@12854
   644
by simp
schirmer@12854
   645
schirmer@12854
   646
lemma supd_def2 [simp]: "supd f (x,s) = (x,f s)"
schirmer@12854
   647
by (simp add: supd_def)
schirmer@12854
   648
schirmer@12854
   649
lemma supd_lupd [simp]: 
schirmer@12854
   650
 "\<And> s. supd (lupd vn v ) s = (abrupt s,lupd vn v (store s))"
schirmer@12854
   651
apply (simp (no_asm_simp) only: split_tupled_all)
schirmer@12854
   652
apply (simp (no_asm))
schirmer@12854
   653
done
schirmer@12854
   654
schirmer@12854
   655
schirmer@12854
   656
lemma supd_gupd [simp]: 
schirmer@12854
   657
 "\<And> s. supd (gupd r obj) s = (abrupt s,gupd r obj (store s))"
schirmer@12854
   658
apply (simp (no_asm_simp) only: split_tupled_all)
schirmer@12854
   659
apply (simp (no_asm))
schirmer@12854
   660
done
schirmer@12854
   661
schirmer@12854
   662
lemma supd_init_obj [simp]: 
schirmer@12854
   663
 "supd (init_obj G oi r) s = (abrupt s,init_obj G oi r (store s))"
schirmer@12854
   664
apply (unfold init_obj_def)
schirmer@12854
   665
apply (simp (no_asm))
schirmer@12854
   666
done
schirmer@12854
   667
schirmer@13688
   668
lemma abupd_store_invariant [simp]: "store (abupd f s) = store s"
schirmer@13688
   669
  by (cases s) simp
schirmer@13688
   670
schirmer@13688
   671
lemma supd_abrupt_invariant [simp]: "abrupt (supd f s) = abrupt s"
schirmer@13688
   672
  by (cases s) simp
schirmer@13688
   673
wenzelm@35067
   674
abbreviation set_lvars :: "locals \<Rightarrow> state \<Rightarrow> state"
wenzelm@35067
   675
  where "set_lvars l == supd (set_locals l)"
schirmer@12854
   676
wenzelm@35067
   677
abbreviation restore_lvars :: "state  \<Rightarrow> state \<Rightarrow> state"
wenzelm@35067
   678
  where "restore_lvars s' s == set_lvars (locals (store s')) s"
schirmer@12854
   679
schirmer@12854
   680
lemma set_set_lvars [simp]: "\<And> s. set_lvars l (set_lvars l' s) = set_lvars l s"
schirmer@12854
   681
apply (simp (no_asm_simp) only: split_tupled_all)
schirmer@12854
   682
apply (simp (no_asm))
schirmer@12854
   683
done
schirmer@12854
   684
schirmer@12854
   685
lemma set_lvars_id [simp]: "\<And> s. set_lvars (locals (store s)) s = s"
schirmer@12854
   686
apply (simp (no_asm_simp) only: split_tupled_all)
schirmer@12854
   687
apply (simp (no_asm))
schirmer@12854
   688
done
schirmer@12854
   689
schirmer@12854
   690
section "initialisation test"
schirmer@12854
   691
wenzelm@37956
   692
definition
wenzelm@37956
   693
  inited :: "qtname \<Rightarrow> globs \<Rightarrow> bool"
wenzelm@37956
   694
  where "inited C g = (g (Stat C) \<noteq> None)"
schirmer@12854
   695
wenzelm@37956
   696
definition
wenzelm@37956
   697
  initd :: "qtname \<Rightarrow> state \<Rightarrow> bool"
wenzelm@37956
   698
  where "initd C = inited C \<circ> globs \<circ> store"
schirmer@12854
   699
schirmer@12854
   700
lemma not_inited_empty [simp]: "\<not>inited C empty"
schirmer@12854
   701
apply (unfold inited_def)
schirmer@12854
   702
apply (simp (no_asm))
schirmer@12854
   703
done
schirmer@12854
   704
schirmer@12854
   705
lemma inited_gupdate [simp]: "inited C (g(r\<mapsto>obj)) = (inited C g \<or> r = Stat C)"
schirmer@12854
   706
apply (unfold inited_def)
schirmer@12854
   707
apply (auto split add: st.split)
schirmer@12854
   708
done
schirmer@12854
   709
schirmer@12854
   710
lemma inited_init_class_obj [intro!]: "inited C (globs (init_class_obj G C s))"
schirmer@12854
   711
apply (unfold inited_def)
schirmer@12854
   712
apply (simp (no_asm))
schirmer@12854
   713
done
schirmer@12854
   714
schirmer@12854
   715
lemma not_initedD: "\<not> inited C g \<Longrightarrow> g (Stat C) = None"
schirmer@12854
   716
apply (unfold inited_def)
schirmer@12854
   717
apply (erule notnotD)
schirmer@12854
   718
done
schirmer@12854
   719
schirmer@12854
   720
lemma initedD: "inited C g \<Longrightarrow> \<exists> obj. g (Stat C) = Some obj"
schirmer@12854
   721
apply (unfold inited_def)
schirmer@12854
   722
apply auto
schirmer@12854
   723
done
schirmer@12854
   724
schirmer@12854
   725
lemma initd_def2 [simp]: "initd C s = inited C (globs (store s))"
schirmer@12854
   726
apply (unfold initd_def)
schirmer@12854
   727
apply (simp (no_asm))
schirmer@12854
   728
done
schirmer@12854
   729
schirmer@12925
   730
section {* @{text error_free} *}
wenzelm@37956
   731
wenzelm@37956
   732
definition
wenzelm@37956
   733
  error_free :: "state \<Rightarrow> bool"
wenzelm@37956
   734
  where "error_free s = (\<not> (\<exists> err. abrupt s = Some (Error err)))"
schirmer@12854
   735
schirmer@12925
   736
lemma error_free_Norm [simp,intro]: "error_free (Norm s)"
schirmer@12925
   737
by (simp add: error_free_def)
schirmer@12925
   738
schirmer@12925
   739
lemma error_free_normal [simp,intro]: "normal s \<Longrightarrow> error_free s"
schirmer@12925
   740
by (simp add: error_free_def)
schirmer@12925
   741
schirmer@12925
   742
lemma error_free_Xcpt [simp]: "error_free (Some (Xcpt x),s)"
schirmer@12925
   743
by (simp add: error_free_def)
schirmer@12925
   744
schirmer@12925
   745
lemma error_free_Jump [simp,intro]: "error_free (Some (Jump j),s)"
schirmer@12925
   746
by (simp add: error_free_def)
schirmer@12925
   747
schirmer@12925
   748
lemma error_free_Error [simp]: "error_free (Some (Error e),s) = False"
schirmer@12925
   749
by (simp add: error_free_def)  
schirmer@12925
   750
schirmer@12925
   751
lemma error_free_Some [simp,intro]: 
schirmer@12925
   752
 "\<not> (\<exists> err. x=Error err) \<Longrightarrow> error_free ((Some x),s)"
schirmer@12925
   753
by (auto simp add: error_free_def)
schirmer@12925
   754
wenzelm@13524
   755
lemma error_free_abupd_absorb [simp,intro]: 
schirmer@12925
   756
 "error_free s \<Longrightarrow> error_free (abupd (absorb j) s)"
schirmer@12925
   757
by (cases s) 
schirmer@12925
   758
   (auto simp add: error_free_def absorb_def
schirmer@12925
   759
         split: split_if_asm)
schirmer@12925
   760
schirmer@12925
   761
lemma error_free_absorb [simp,intro]: 
schirmer@12925
   762
 "error_free (a,s) \<Longrightarrow> error_free (absorb j a, s)"
schirmer@12925
   763
by (auto simp add: error_free_def absorb_def
schirmer@12925
   764
            split: split_if_asm)
schirmer@12925
   765
schirmer@12925
   766
lemma error_free_abrupt_if [simp,intro]:
schirmer@12925
   767
"\<lbrakk>error_free s; \<not> (\<exists> err. x=Error err)\<rbrakk>
schirmer@12925
   768
 \<Longrightarrow> error_free (abupd (abrupt_if p (Some x)) s)"
schirmer@12925
   769
by (cases s)
schirmer@12925
   770
   (auto simp add: abrupt_if_def
schirmer@12925
   771
            split: split_if)
schirmer@12925
   772
schirmer@12925
   773
lemma error_free_abrupt_if1 [simp,intro]:
schirmer@12925
   774
"\<lbrakk>error_free (a,s); \<not> (\<exists> err. x=Error err)\<rbrakk>
schirmer@12925
   775
 \<Longrightarrow> error_free (abrupt_if p (Some x) a, s)"
schirmer@12925
   776
by  (auto simp add: abrupt_if_def
schirmer@12925
   777
            split: split_if)
schirmer@12925
   778
schirmer@12925
   779
lemma error_free_abrupt_if_Xcpt [simp,intro]:
schirmer@12925
   780
 "error_free s 
schirmer@12925
   781
  \<Longrightarrow> error_free (abupd (abrupt_if p (Some (Xcpt x))) s)"
schirmer@12925
   782
by simp 
schirmer@12925
   783
schirmer@12925
   784
lemma error_free_abrupt_if_Xcpt1 [simp,intro]:
schirmer@12925
   785
 "error_free (a,s) 
schirmer@12925
   786
  \<Longrightarrow> error_free (abrupt_if p (Some (Xcpt x)) a, s)" 
schirmer@12925
   787
by simp 
schirmer@12925
   788
schirmer@12925
   789
lemma error_free_abrupt_if_Jump [simp,intro]:
schirmer@12925
   790
 "error_free s 
schirmer@12925
   791
  \<Longrightarrow> error_free (abupd (abrupt_if p (Some (Jump j))) s)" 
schirmer@12925
   792
by simp
schirmer@12925
   793
schirmer@12925
   794
lemma error_free_abrupt_if_Jump1 [simp,intro]:
schirmer@12925
   795
 "error_free (a,s) 
schirmer@12925
   796
  \<Longrightarrow> error_free (abrupt_if p (Some (Jump j)) a, s)" 
schirmer@12925
   797
by simp
schirmer@12925
   798
schirmer@12925
   799
lemma error_free_raise_if [simp,intro]:
schirmer@12925
   800
 "error_free s \<Longrightarrow> error_free (abupd (raise_if p x) s)"
schirmer@12925
   801
by simp 
schirmer@12925
   802
schirmer@12925
   803
lemma error_free_raise_if1 [simp,intro]:
schirmer@12925
   804
 "error_free (a,s) \<Longrightarrow> error_free ((raise_if p x a), s)"
schirmer@12925
   805
by simp 
schirmer@12925
   806
schirmer@12925
   807
lemma error_free_supd [simp,intro]:
schirmer@12925
   808
 "error_free s \<Longrightarrow> error_free (supd f s)"
schirmer@12925
   809
by (cases s) (simp add: error_free_def)
schirmer@12925
   810
schirmer@12925
   811
lemma error_free_supd1 [simp,intro]:
schirmer@12925
   812
 "error_free (a,s) \<Longrightarrow> error_free (a,f s)"
schirmer@12925
   813
by (simp add: error_free_def)
schirmer@12925
   814
schirmer@12925
   815
lemma error_free_set_lvars [simp,intro]:
schirmer@12925
   816
"error_free s \<Longrightarrow> error_free ((set_lvars l) s)"
schirmer@12925
   817
by (cases s) simp
schirmer@12925
   818
schirmer@12925
   819
lemma error_free_set_locals [simp,intro]: 
schirmer@12925
   820
"error_free (x, s)
schirmer@12925
   821
       \<Longrightarrow> error_free (x, set_locals l s')"
schirmer@12925
   822
by (simp add: error_free_def)
schirmer@12854
   823
schirmer@13688
   824
schirmer@12854
   825
end
schirmer@12854
   826