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