src/HOL/Bali/AxExample.thy
author berghofe
Mon Sep 30 16:14:02 2002 +0200 (2002-09-30)
changeset 13601 fd3e3d6b37b2
parent 12925 99131847fb93
child 13688 a0b16d42d489
permissions -rw-r--r--
Adapted to new simplifier.
wenzelm@12857
     1
(*  Title:      HOL/Bali/AxExample.thy
schirmer@12854
     2
    ID:         $Id$
schirmer@12854
     3
    Author:     David von Oheimb
wenzelm@12859
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
schirmer@12854
     5
*)
schirmer@12925
     6
schirmer@12854
     7
header {* Example of a proof based on the Bali axiomatic semantics *}
schirmer@12854
     8
schirmer@12854
     9
theory AxExample = AxSem + Example:
schirmer@12854
    10
schirmer@12854
    11
constdefs
schirmer@12854
    12
  arr_inv :: "st \<Rightarrow> bool"
schirmer@12854
    13
 "arr_inv \<equiv> \<lambda>s. \<exists>obj a T el. globs s (Stat Base) = Some obj \<and>
schirmer@12854
    14
                              values obj (Inl (arr, Base)) = Some (Addr a) \<and>
schirmer@12854
    15
                              heap s a = Some \<lparr>tag=Arr T 2,values=el\<rparr>"
schirmer@12854
    16
schirmer@12854
    17
lemma arr_inv_new_obj: 
schirmer@12854
    18
"\<And>a. \<lbrakk>arr_inv s; new_Addr (heap s)=Some a\<rbrakk> \<Longrightarrow> arr_inv (gupd(Inl a\<mapsto>x) s)"
schirmer@12854
    19
apply (unfold arr_inv_def)
schirmer@12854
    20
apply (force dest!: new_AddrD2)
schirmer@12854
    21
done
schirmer@12854
    22
schirmer@12854
    23
lemma arr_inv_set_locals [simp]: "arr_inv (set_locals l s) = arr_inv s"
schirmer@12854
    24
apply (unfold arr_inv_def)
schirmer@12854
    25
apply (simp (no_asm))
schirmer@12854
    26
done
schirmer@12854
    27
schirmer@12854
    28
lemma arr_inv_gupd_Stat [simp]: 
schirmer@12854
    29
  "Base \<noteq> C \<Longrightarrow> arr_inv (gupd(Stat C\<mapsto>obj) s) = arr_inv s"
schirmer@12854
    30
apply (unfold arr_inv_def)
schirmer@12854
    31
apply (simp (no_asm_simp))
schirmer@12854
    32
done
schirmer@12854
    33
schirmer@12854
    34
lemma ax_inv_lupd [simp]: "arr_inv (lupd(x\<mapsto>y) s) = arr_inv s"
schirmer@12854
    35
apply (unfold arr_inv_def)
schirmer@12854
    36
apply (simp (no_asm))
schirmer@12854
    37
done
schirmer@12854
    38
schirmer@12854
    39
schirmer@12854
    40
declare split_if_asm [split del]
schirmer@12854
    41
declare lvar_def [simp]
schirmer@12854
    42
schirmer@12854
    43
ML {*
schirmer@12854
    44
fun inst1_tac s t = instantiate_tac [(s,t)];
schirmer@12854
    45
val ax_tac = REPEAT o rtac allI THEN'
schirmer@12854
    46
             resolve_tac(thm "ax_Skip"::thm "ax_StatRef"::thm "ax_MethdN"::
schirmer@12854
    47
                         thm "ax_Alloc"::thm "ax_Alloc_Arr"::
schirmer@12854
    48
                         thm "ax_SXAlloc_Normal"::
schirmer@12854
    49
                         funpow 7 tl (thms "ax_derivs.intros"))
schirmer@12854
    50
*}
schirmer@12854
    51
schirmer@12854
    52
schirmer@12854
    53
theorem ax_test: "tprg,({}::'a triple set)\<turnstile> 
schirmer@12854
    54
  {Normal (\<lambda>Y s Z::'a. heap_free four s \<and> \<not>initd Base s \<and> \<not> initd Ext s)} 
schirmer@12854
    55
  .test [Class Base]. {\<lambda>Y s Z. abrupt s = Some (Xcpt (Std IndOutBound))}"
schirmer@12854
    56
apply (unfold test_def arr_viewed_from_def)
schirmer@12854
    57
apply (tactic "ax_tac 1" (*;;*))
schirmer@12854
    58
defer
schirmer@12854
    59
apply  (tactic "ax_tac 1" (* Try *))
schirmer@12854
    60
defer
schirmer@12854
    61
apply    (tactic {* inst1_tac "Q1" 
schirmer@12854
    62
                 "\<lambda>Y s Z. arr_inv (snd s) \<and> tprg,s\<turnstile>catch SXcpt NullPointer" *})
schirmer@12854
    63
prefer 2
schirmer@12854
    64
apply    simp
schirmer@12854
    65
apply   (rule_tac P' = "Normal (\<lambda>Y s Z. arr_inv (snd s))" in conseq1)
schirmer@12854
    66
prefer 2
schirmer@12854
    67
apply    clarsimp
schirmer@12854
    68
apply   (rule_tac Q' = "(\<lambda>Y s Z. ?Q Y s Z)\<leftarrow>=False\<down>=\<diamondsuit>" in conseq2)
schirmer@12854
    69
prefer 2
schirmer@12854
    70
apply    simp
schirmer@12854
    71
apply   (tactic "ax_tac 1" (* While *))
schirmer@12854
    72
prefer 2
schirmer@12854
    73
apply    (rule ax_impossible [THEN conseq1], clarsimp)
schirmer@12854
    74
apply   (rule_tac P' = "Normal ?P" in conseq1)
schirmer@12854
    75
prefer 2
schirmer@12854
    76
apply    clarsimp
schirmer@12854
    77
apply   (tactic "ax_tac 1")
schirmer@12854
    78
apply   (tactic "ax_tac 1" (* AVar *))
schirmer@12854
    79
prefer 2
schirmer@12854
    80
apply    (rule ax_subst_Val_allI)
schirmer@12854
    81
apply    (tactic {* inst1_tac "P'21" "\<lambda>u a. Normal (?PP a\<leftarrow>?x) u" *})
schirmer@12854
    82
apply    (simp del: avar_def2 peek_and_def2)
schirmer@12854
    83
apply    (tactic "ax_tac 1")
schirmer@12854
    84
apply   (tactic "ax_tac 1")
schirmer@12854
    85
      (* just for clarification: *)
schirmer@12854
    86
apply   (rule_tac Q' = "Normal (\<lambda>Var:(v, f) u ua. fst (snd (avar tprg (Intg 2) v u)) = Some (Xcpt (Std IndOutBound)))" in conseq2)
schirmer@12854
    87
prefer 2
schirmer@12854
    88
apply    (clarsimp simp add: split_beta)
schirmer@12854
    89
apply   (tactic "ax_tac 1" (* FVar *))
schirmer@12854
    90
apply    (tactic "ax_tac 2" (* StatRef *))
schirmer@12854
    91
apply   (rule ax_derivs.Done [THEN conseq1])
schirmer@12854
    92
apply   (clarsimp simp add: arr_inv_def inited_def in_bounds_def)
schirmer@12854
    93
defer
schirmer@12854
    94
apply  (rule ax_SXAlloc_catch_SXcpt)
schirmer@12854
    95
apply  (rule_tac Q' = "(\<lambda>Y (x, s) Z. x = Some (Xcpt (Std NullPointer)) \<and> arr_inv s) \<and>. heap_free two" in conseq2)
schirmer@12854
    96
prefer 2
schirmer@12854
    97
apply   (simp add: arr_inv_new_obj)
schirmer@12854
    98
apply  (tactic "ax_tac 1") 
schirmer@12854
    99
apply  (rule_tac C = "Ext" in ax_Call_known_DynT)
schirmer@12854
   100
apply     (unfold DynT_prop_def)
schirmer@12854
   101
apply     (simp (no_asm))
schirmer@12854
   102
apply    (intro strip)
schirmer@12854
   103
apply    (rule_tac P' = "Normal ?P" in conseq1)
schirmer@12854
   104
apply     (tactic "ax_tac 1" (* Methd *))
schirmer@12854
   105
apply     (rule ax_thin [OF _ empty_subsetI])
schirmer@12854
   106
apply     (simp (no_asm) add: body_def2)
schirmer@12854
   107
apply     (tactic "ax_tac 1" (* Body *))
schirmer@12854
   108
(* apply       (rule_tac [2] ax_derivs.Abrupt) *)
schirmer@12854
   109
defer
schirmer@12854
   110
apply      (simp (no_asm))
schirmer@12854
   111
apply      (tactic "ax_tac 1")
schirmer@12854
   112
apply      (tactic "ax_tac 1") (* Ass *)
schirmer@12854
   113
prefer 2
schirmer@12854
   114
apply       (rule ax_subst_Var_allI)
schirmer@12854
   115
apply       (tactic {* inst1_tac "P'27" "\<lambda>a vs l vf. ?PP a vs l vf\<leftarrow>?x \<and>. ?p" *})
schirmer@12854
   116
apply       (rule allI)
schirmer@12854
   117
apply       (tactic {* simp_tac (simpset() delloop "split_all_tac" delsimps [thm "peek_and_def2"]) 1 *})
schirmer@12854
   118
apply       (rule ax_derivs.Abrupt)
schirmer@12854
   119
apply      (simp (no_asm))
schirmer@12854
   120
apply      (tactic "ax_tac 1" (* FVar *))
schirmer@12854
   121
apply       (tactic "ax_tac 2", tactic "ax_tac 2", tactic "ax_tac 2")
schirmer@12854
   122
apply      (tactic "ax_tac 1")
schirmer@12854
   123
apply     clarsimp
schirmer@12854
   124
apply     (tactic {* inst1_tac "R14" "\<lambda>a'. Normal ((\<lambda>Vals:vs (x, s) Z. arr_inv s \<and> inited Ext (globs s) \<and> a' \<noteq> Null \<and> hd vs = Null) \<and>. heap_free two)" *})
schirmer@12854
   125
prefer 5
schirmer@12854
   126
apply     (rule ax_derivs.Done [THEN conseq1], force)
schirmer@12854
   127
apply    force
schirmer@12854
   128
apply   (rule ax_subst_Val_allI)
schirmer@12854
   129
apply   (tactic {* inst1_tac "P'33" "\<lambda>u a. Normal (?PP a\<leftarrow>?x) u" *})
schirmer@12854
   130
apply   (simp (no_asm) del: peek_and_def2)
schirmer@12854
   131
apply   (tactic "ax_tac 1")
schirmer@12854
   132
prefer 2
schirmer@12854
   133
apply   (rule ax_subst_Val_allI)
schirmer@12854
   134
apply    (tactic {* inst1_tac "P'4" "\<lambda>aa v. Normal (?QQ aa v\<leftarrow>?y)" *})
schirmer@12854
   135
apply    (simp del: peek_and_def2)
schirmer@12854
   136
apply    (tactic "ax_tac 1")
schirmer@12854
   137
apply   (tactic "ax_tac 1")
schirmer@12854
   138
apply  (tactic "ax_tac 1")
schirmer@12854
   139
apply  (tactic "ax_tac 1")
schirmer@12854
   140
(* end method call *)
schirmer@12854
   141
apply (simp (no_asm))
schirmer@12854
   142
    (* just for clarification: *)
schirmer@12854
   143
apply (rule_tac Q' = "Normal ((\<lambda>Y (x, s) Z. arr_inv s \<and> (\<exists>a. the (locals s (VName e)) = Addr a \<and> obj_class (the (globs s (Inl a))) = Ext \<and> 
schirmer@12854
   144
 invocation_declclass tprg IntVir s (the (locals s (VName e))) (ClassT Base)  
schirmer@12854
   145
     \<lparr>name = foo, parTs = [Class Base]\<rparr> = Ext)) \<and>. initd Ext \<and>. heap_free two)"
schirmer@12854
   146
  in conseq2)
schirmer@12854
   147
prefer 2
schirmer@12854
   148
apply  clarsimp
schirmer@12854
   149
apply (tactic "ax_tac 1")
schirmer@12854
   150
apply (tactic "ax_tac 1")
schirmer@12854
   151
defer
schirmer@12854
   152
apply  (rule ax_subst_Var_allI)
schirmer@12854
   153
apply  (tactic {* inst1_tac "P'14" "\<lambda>u vf. Normal (?PP vf \<and>. ?p) u" *})
schirmer@12854
   154
apply  (simp (no_asm) del: split_paired_All peek_and_def2)
schirmer@12854
   155
apply  (tactic "ax_tac 1" (* NewC *))
schirmer@12854
   156
apply  (tactic "ax_tac 1" (* ax_Alloc *))
schirmer@12854
   157
     (* just for clarification: *)
schirmer@12854
   158
apply  (rule_tac Q' = "Normal ((\<lambda>Y s Z. arr_inv (store s) \<and> vf=lvar (VName e) (store s)) \<and>. heap_free tree \<and>. initd Ext)" in conseq2)
schirmer@12854
   159
prefer 2
schirmer@12854
   160
apply   (simp add: invocation_declclass_def dynmethd_def)
schirmer@12854
   161
apply   (unfold dynlookup_def)
schirmer@12854
   162
apply   (simp add: dynmethd_Ext_foo)
schirmer@12854
   163
apply   (force elim!: arr_inv_new_obj atleast_free_SucD atleast_free_weaken)
schirmer@12854
   164
     (* begin init *)
schirmer@12854
   165
apply  (rule ax_InitS)
schirmer@12854
   166
apply     force
schirmer@12854
   167
apply    (simp (no_asm))
schirmer@12854
   168
apply   (tactic {* simp_tac (simpset() delloop "split_all_tac") 1 *})
schirmer@12854
   169
apply   (rule ax_Init_Skip_lemma)
schirmer@12854
   170
apply  (tactic {* simp_tac (simpset() delloop "split_all_tac") 1 *})
schirmer@12854
   171
apply  (rule ax_InitS [THEN conseq1] (* init Base *))
schirmer@12854
   172
apply      force
schirmer@12854
   173
apply     (simp (no_asm))
schirmer@12854
   174
apply    (unfold arr_viewed_from_def)
schirmer@12854
   175
apply    (rule allI)
schirmer@12854
   176
apply    (rule_tac P' = "Normal ?P" in conseq1)
schirmer@12854
   177
apply     (tactic {* simp_tac (simpset() delloop "split_all_tac") 1 *})
schirmer@12854
   178
apply     (tactic "ax_tac 1")
schirmer@12854
   179
apply     (tactic "ax_tac 1")
schirmer@12854
   180
apply     (rule_tac [2] ax_subst_Var_allI)
schirmer@12854
   181
apply      (tactic {* inst1_tac "P'29" "\<lambda>vf l vfa. Normal (?P vf l vfa)" *})
schirmer@12854
   182
apply     (tactic {* simp_tac (simpset() delloop "split_all_tac" delsimps [split_paired_All, thm "peek_and_def2"]) 2 *})
schirmer@12854
   183
apply      (tactic "ax_tac 2" (* NewA *))
schirmer@12854
   184
apply       (tactic "ax_tac 3" (* ax_Alloc_Arr *))
schirmer@12854
   185
apply       (tactic "ax_tac 3")
schirmer@12854
   186
apply      (tactic {* inst1_tac "P" "\<lambda>vf l vfa. Normal (?P vf l vfa\<leftarrow>\<diamondsuit>)" *})
schirmer@12854
   187
apply      (tactic {* simp_tac (simpset() delloop "split_all_tac") 2 *})
schirmer@12854
   188
apply      (tactic "ax_tac 2")
schirmer@12854
   189
apply     (tactic "ax_tac 1" (* FVar *))
schirmer@12854
   190
apply      (tactic "ax_tac 2" (* StatRef *))
schirmer@12854
   191
apply     (rule ax_derivs.Done [THEN conseq1])
schirmer@12854
   192
apply     (tactic {* inst1_tac "Q22" "\<lambda>vf. Normal ((\<lambda>Y s Z. vf=lvar (VName e) (snd s)) \<and>. heap_free four \<and>. initd Base \<and>. initd Ext)" *})
schirmer@12854
   193
apply     (clarsimp split del: split_if)
schirmer@12854
   194
apply     (frule atleast_free_weaken [THEN atleast_free_weaken])
schirmer@12854
   195
apply     (drule initedD)
schirmer@12854
   196
apply     (clarsimp elim!: atleast_free_SucD simp add: arr_inv_def)
schirmer@12854
   197
apply    force
schirmer@12854
   198
apply   (tactic {* simp_tac (simpset() delloop "split_all_tac") 1 *})
schirmer@12854
   199
apply   (rule ax_triv_Init_Object [THEN peek_and_forget2, THEN conseq1])
schirmer@12854
   200
apply     (rule wf_tprg)
schirmer@12854
   201
apply    clarsimp
schirmer@12854
   202
apply   (tactic {* inst1_tac "P22" "\<lambda>vf. Normal ((\<lambda>Y s Z. vf = lvar (VName e) (snd s)) \<and>. heap_free four \<and>. initd Ext)" *})
schirmer@12854
   203
apply   clarsimp
schirmer@12854
   204
apply  (tactic {* inst1_tac "PP" "\<lambda>vf. Normal ((\<lambda>Y s Z. vf = lvar (VName e) (snd s)) \<and>. heap_free four \<and>. Not \<circ> initd Base)" *})
schirmer@12854
   205
apply  clarsimp
schirmer@12854
   206
     (* end init *)
schirmer@12854
   207
apply (rule conseq1)
schirmer@12854
   208
apply (tactic "ax_tac 1")
schirmer@12854
   209
apply clarsimp
schirmer@12854
   210
done
schirmer@12854
   211
schirmer@12854
   212
(*
schirmer@12854
   213
while (true) {
schirmer@12854
   214
  if (i) {throw xcpt;}
schirmer@12854
   215
  else i=j
schirmer@12854
   216
}
schirmer@12854
   217
*)
schirmer@12854
   218
lemma Loop_Xcpt_benchmark: 
schirmer@12854
   219
 "Q = (\<lambda>Y (x,s) Z. x \<noteq> None \<longrightarrow> the_Bool (the (locals s i))) \<Longrightarrow>  
schirmer@12854
   220
  G,({}::'a triple set)\<turnstile>{Normal (\<lambda>Y s Z::'a. True)}  
schirmer@12854
   221
  .lab1\<bullet> While(Lit (Bool True)) (If(Acc (LVar i)) (Throw (Acc (LVar xcpt))) Else
schirmer@12854
   222
        (Expr (Ass (LVar i) (Acc (LVar j))))). {Q}"
schirmer@12854
   223
apply (rule_tac P' = "Q" and Q' = "Q\<leftarrow>=False\<down>=\<diamondsuit>" in conseq12)
schirmer@12854
   224
apply  safe
schirmer@12854
   225
apply  (tactic "ax_tac 1" (* Loop *))
schirmer@12854
   226
apply   (rule ax_Normal_cases)
schirmer@12854
   227
prefer 2
schirmer@12854
   228
apply    (rule ax_derivs.Abrupt [THEN conseq1], clarsimp simp add: Let_def)
schirmer@12854
   229
apply   (rule conseq1)
schirmer@12854
   230
apply    (tactic "ax_tac 1")
schirmer@12854
   231
apply   clarsimp
schirmer@12854
   232
prefer 2
schirmer@12854
   233
apply  clarsimp
schirmer@12854
   234
apply (tactic "ax_tac 1" (* If *))
schirmer@12854
   235
apply  (tactic 
schirmer@12854
   236
  {* inst1_tac "P'21" "Normal (\<lambda>s.. (\<lambda>Y s Z. True)\<down>=Val (the (locals s i)))" *})
schirmer@12854
   237
apply  (tactic "ax_tac 1")
schirmer@12854
   238
apply  (rule conseq1)
schirmer@12854
   239
apply   (tactic "ax_tac 1")
schirmer@12854
   240
apply  clarsimp
schirmer@12854
   241
apply (rule allI)
schirmer@12854
   242
apply (rule ax_escape)
schirmer@12854
   243
apply auto
schirmer@12854
   244
apply  (rule conseq1)
schirmer@12854
   245
apply   (tactic "ax_tac 1" (* Throw *))
schirmer@12854
   246
apply   (tactic "ax_tac 1")
schirmer@12854
   247
apply   (tactic "ax_tac 1")
schirmer@12854
   248
apply  clarsimp
schirmer@12854
   249
apply (rule_tac Q' = "Normal (\<lambda>Y s Z. True)" in conseq2)
schirmer@12854
   250
prefer 2
schirmer@12854
   251
apply  clarsimp
schirmer@12854
   252
apply (rule conseq1)
schirmer@12854
   253
apply  (tactic "ax_tac 1")
schirmer@12854
   254
apply  (tactic "ax_tac 1")
schirmer@12854
   255
prefer 2
schirmer@12854
   256
apply   (rule ax_subst_Var_allI)
schirmer@12854
   257
apply   (tactic {* inst1_tac "P'29" "\<lambda>b Y ba Z vf. \<lambda>Y (x,s) Z. x=None \<and> snd vf = snd (lvar i s)" *})
schirmer@12854
   258
apply   (rule allI)
schirmer@12854
   259
apply   (rule_tac P' = "Normal ?P" in conseq1)
schirmer@12854
   260
prefer 2
schirmer@12854
   261
apply    clarsimp
schirmer@12854
   262
apply   (tactic "ax_tac 1")
schirmer@12854
   263
apply   (rule conseq1)
schirmer@12854
   264
apply    (tactic "ax_tac 1")
schirmer@12854
   265
apply   clarsimp
schirmer@12854
   266
apply  (tactic "ax_tac 1")
schirmer@12854
   267
apply clarsimp
schirmer@12854
   268
done
schirmer@12854
   269
schirmer@12854
   270
end
schirmer@12854
   271