src/HOL/Bali/Trans.thy
author berghofe
Wed Jul 11 11:16:34 2007 +0200 (2007-07-11)
changeset 23747 b07cff284683
parent 21765 89275a3ed7be
child 28524 644b62cf678f
permissions -rw-r--r--
Renamed inductive2 to inductive.
     1 (*  Title:      HOL/Bali/Trans.thy
     2     ID:         $Id$
     3     Author:     David von Oheimb and Norbert Schirmer
     4 
     5 Operational transition (small-step) semantics of the 
     6 execution of Java expressions and statements
     7 
     8 PRELIMINARY!!!!!!!!
     9 *)
    10 
    11 theory Trans imports Evaln begin
    12 
    13 constdefs groundVar:: "var \<Rightarrow> bool"
    14 "groundVar v \<equiv> (case v of
    15                    LVar ln \<Rightarrow> True
    16                  | {accC,statDeclC,stat}e..fn \<Rightarrow> \<exists> a. e=Lit a
    17                  | e1.[e2] \<Rightarrow> \<exists> a i. e1= Lit a \<and> e2 = Lit i
    18                  | InsInitV c v \<Rightarrow> False)"
    19 
    20 lemma groundVar_cases [consumes 1, case_names LVar FVar AVar]:
    21   assumes ground: "groundVar v" and
    22           LVar: "\<And> ln. \<lbrakk>v=LVar ln\<rbrakk> \<Longrightarrow> P" and
    23           FVar: "\<And> accC statDeclC stat a fn. 
    24                     \<lbrakk>v={accC,statDeclC,stat}(Lit a)..fn\<rbrakk> \<Longrightarrow> P" and
    25           AVar: "\<And> a i. \<lbrakk>v=(Lit a).[Lit i]\<rbrakk> \<Longrightarrow> P"
    26   shows "P"
    27 proof -
    28   from ground LVar FVar AVar
    29   show ?thesis
    30     apply (cases v)
    31     apply (simp add: groundVar_def)
    32     apply (simp add: groundVar_def,blast)
    33     apply (simp add: groundVar_def,blast)
    34     apply (simp add: groundVar_def)
    35     done
    36 qed
    37 
    38 constdefs groundExprs:: "expr list \<Rightarrow> bool"
    39 "groundExprs es \<equiv> list_all (\<lambda> e. \<exists> v. e=Lit v) es"
    40   
    41 consts the_val:: "expr \<Rightarrow> val"
    42 primrec
    43 "the_val (Lit v) = v"
    44 
    45 consts the_var:: "prog \<Rightarrow> state \<Rightarrow> var \<Rightarrow> (vvar \<times> state)"
    46 primrec
    47 "the_var G s (LVar ln)                    =(lvar ln (store s),s)"
    48 the_var_FVar_def:
    49 "the_var G s ({accC,statDeclC,stat}a..fn) =fvar statDeclC stat fn (the_val a) s"
    50 the_var_AVar_def:
    51 "the_var G s(a.[i])                       =avar G (the_val i) (the_val a) s"
    52 
    53 lemma the_var_FVar_simp[simp]:
    54 "the_var G s ({accC,statDeclC,stat}(Lit a)..fn) = fvar statDeclC stat fn a s"
    55 by (simp)
    56 declare the_var_FVar_def [simp del]
    57 
    58 lemma the_var_AVar_simp:
    59 "the_var G s ((Lit a).[Lit i]) = avar G i a s"
    60 by (simp)
    61 declare the_var_AVar_def [simp del]
    62 
    63 syntax (xsymbols)
    64   Ref  :: "loc \<Rightarrow> expr"
    65   SKIP :: "expr"
    66 
    67 translations
    68   "Ref a" == "Lit (Addr a)"
    69   "SKIP"  == "Lit Unit"
    70 
    71 inductive
    72   step :: "[prog,term \<times> state,term \<times> state] \<Rightarrow> bool" ("_\<turnstile>_ \<mapsto>1 _"[61,82,82] 81)
    73   for G :: prog
    74 where
    75 
    76 (* evaluation of expression *)
    77   (* cf. 15.5 *)
    78   Abrupt:       "\<lbrakk>\<forall>v. t \<noteq> \<langle>Lit v\<rangle>;
    79                   \<forall> t. t \<noteq> \<langle>l\<bullet> Skip\<rangle>;
    80                   \<forall> C vn c.  t \<noteq> \<langle>Try Skip Catch(C vn) c\<rangle>;
    81                   \<forall> x c. t \<noteq> \<langle>Skip Finally c\<rangle> \<and> xc \<noteq> Xcpt x;
    82                   \<forall> a c. t \<noteq> \<langle>FinA a c\<rangle>\<rbrakk> 
    83                 \<Longrightarrow> 
    84                   G\<turnstile>(t,Some xc,s) \<mapsto>1 (\<langle>Lit arbitrary\<rangle>,Some xc,s)"
    85 
    86 | InsInitE: "\<lbrakk>G\<turnstile>(\<langle>c\<rangle>,Norm s) \<mapsto>1 (\<langle>c'\<rangle>, s')\<rbrakk>
    87              \<Longrightarrow> 
    88              G\<turnstile>(\<langle>InsInitE c e\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitE c' e\<rangle>, s')"
    89 
    90 (* SeqE: "G\<turnstile>(\<langle>Seq Skip e\<rangle>,Norm s) \<mapsto>1 (\<langle>e\<rangle>, Norm s)" *)
    91 (* Specialised rules to evaluate: 
    92    InsInitE Skip (NewC C), InisInitE Skip (NewA T[e]) *)
    93  
    94   (* cf. 15.8.1 *)
    95 | NewC: "G\<turnstile>(\<langle>NewC C\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitE (Init C) (NewC C)\<rangle>, Norm s)"
    96 | NewCInited: "\<lbrakk>G\<turnstile> Norm s \<midarrow>halloc (CInst C)\<succ>a\<rightarrow> s'\<rbrakk> 
    97                \<Longrightarrow> 
    98                G\<turnstile>(\<langle>InsInitE Skip (NewC C)\<rangle>,Norm s) \<mapsto>1 (\<langle>Ref a\<rangle>, s')"
    99 
   100 
   101 
   102 (* Alternative when rule SeqE is present 
   103 NewCInited: "\<lbrakk>inited C (globs s); 
   104               G\<turnstile> Norm s \<midarrow>halloc (CInst C)\<succ>a\<rightarrow> s'\<rbrakk> 
   105              \<Longrightarrow> 
   106               G\<turnstile>(\<langle>NewC C\<rangle>,Norm s) \<mapsto>1 (\<langle>Ref a\<rangle>, s')"
   107 
   108 NewC:
   109      "\<lbrakk>\<not> inited C (globs s)\<rbrakk> 
   110      \<Longrightarrow> 
   111       G\<turnstile>(\<langle>NewC C\<rangle>,Norm s) \<mapsto>1 (\<langle>Seq (Init C) (NewC C)\<rangle>, Norm s)"
   112 
   113 *)
   114   (* cf. 15.9.1 *)
   115 | NewA: 
   116    "G\<turnstile>(\<langle>New T[e]\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitE (init_comp_ty T) (New T[e])\<rangle>,Norm s)"
   117 | InsInitNewAIdx: 
   118    "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>, s')\<rbrakk>
   119     \<Longrightarrow>  
   120     G\<turnstile>(\<langle>InsInitE Skip (New T[e])\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitE Skip (New T[e'])\<rangle>,s')"
   121 | InsInitNewA: 
   122    "\<lbrakk>G\<turnstile>abupd (check_neg i) (Norm s) \<midarrow>halloc (Arr T (the_Intg i))\<succ>a\<rightarrow> s' \<rbrakk>
   123     \<Longrightarrow>
   124     G\<turnstile>(\<langle>InsInitE Skip (New T[Lit i])\<rangle>,Norm s) \<mapsto>1 (\<langle>Ref a\<rangle>,s')"
   125  
   126   (* cf. 15.15 *)
   127 | CastE:	
   128    "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> 
   129     \<Longrightarrow>
   130     G\<turnstile>(\<langle>Cast T e\<rangle>,None,s) \<mapsto>1 (\<langle>Cast T e'\<rangle>,s')" 
   131 | Cast:	
   132    "\<lbrakk>s' = abupd (raise_if (\<not>G,s\<turnstile>v fits T)  ClassCast) (Norm s)\<rbrakk> 
   133     \<Longrightarrow> 
   134     G\<turnstile>(\<langle>Cast T (Lit v)\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit v\<rangle>,s')"
   135   (* can be written without abupd, since we know Norm s *)
   136 
   137 
   138 | InstE: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'::expr\<rangle>,s')\<rbrakk> 
   139         \<Longrightarrow> 
   140         G\<turnstile>(\<langle>e InstOf T\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')" 
   141 | Inst:  "\<lbrakk>b = (v\<noteq>Null \<and> G,s\<turnstile>v fits RefT T)\<rbrakk> 
   142           \<Longrightarrow> 
   143           G\<turnstile>(\<langle>(Lit v) InstOf T\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit (Bool b)\<rangle>,s')"
   144 
   145   (* cf. 15.7.1 *)
   146 (*Lit				"G\<turnstile>(Lit v,None,s) \<mapsto>1 (Lit v,None,s)"*)
   147 
   148 | UnOpE:  "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s') \<rbrakk>
   149            \<Longrightarrow> 
   150            G\<turnstile>(\<langle>UnOp unop e\<rangle>,Norm s) \<mapsto>1 (\<langle>UnOp unop e'\<rangle>,s')"
   151 | UnOp:   "G\<turnstile>(\<langle>UnOp unop (Lit v)\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit (eval_unop unop v)\<rangle>,Norm s)"
   152 
   153 | BinOpE1:  "\<lbrakk>G\<turnstile>(\<langle>e1\<rangle>,Norm s) \<mapsto>1 (\<langle>e1'\<rangle>,s') \<rbrakk>
   154              \<Longrightarrow> 
   155              G\<turnstile>(\<langle>BinOp binop e1 e2\<rangle>,Norm s) \<mapsto>1 (\<langle>BinOp binop e1' e2\<rangle>,s')"
   156 | BinOpE2:  "\<lbrakk>need_second_arg binop v1; G\<turnstile>(\<langle>e2\<rangle>,Norm s) \<mapsto>1 (\<langle>e2'\<rangle>,s') \<rbrakk>
   157              \<Longrightarrow> 
   158              G\<turnstile>(\<langle>BinOp binop (Lit v1) e2\<rangle>,Norm s) 
   159               \<mapsto>1 (\<langle>BinOp binop (Lit v1) e2'\<rangle>,s')"
   160 | BinOpTerm:  "\<lbrakk>\<not> need_second_arg binop v1\<rbrakk>
   161                \<Longrightarrow> 
   162                G\<turnstile>(\<langle>BinOp binop (Lit v1) e2\<rangle>,Norm s) 
   163                 \<mapsto>1 (\<langle>Lit v1\<rangle>,Norm s)"
   164 | BinOp:    "G\<turnstile>(\<langle>BinOp binop (Lit v1) (Lit v2)\<rangle>,Norm s) 
   165               \<mapsto>1 (\<langle>Lit (eval_binop binop v1 v2)\<rangle>,Norm s)"
   166 (* Maybe its more convenient to add: need_second_arg as precondition to BinOp 
   167    to make the choice between BinOpTerm and BinOp deterministic *)
   168    
   169 | Super: "G\<turnstile>(\<langle>Super\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit (val_this s)\<rangle>,Norm s)"
   170 
   171 | AccVA: "\<lbrakk>G\<turnstile>(\<langle>va\<rangle>,Norm s) \<mapsto>1 (\<langle>va'\<rangle>,s') \<rbrakk>
   172           \<Longrightarrow> 
   173           G\<turnstile>(\<langle>Acc va\<rangle>,Norm s) \<mapsto>1 (\<langle>Acc va'\<rangle>,s')"
   174 | Acc:  "\<lbrakk>groundVar va; ((v,vf),s') = the_var G (Norm s) va\<rbrakk>
   175          \<Longrightarrow>  
   176          G\<turnstile>(\<langle>Acc va\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit v\<rangle>,s')"
   177 
   178 (*
   179 AccLVar: "G\<turnstile>(\<langle>Acc (LVar vn)\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit (fst (lvar vn s))\<rangle>,Norm s)"
   180 AccFVar: "\<lbrakk>((v,vf),s') = fvar statDeclC stat fn a (Norm s)\<rbrakk>
   181           \<Longrightarrow>  
   182           G\<turnstile>(\<langle>Acc ({accC,statDeclC,stat}(Lit a)..fn)\<rangle>,Norm s) 
   183            \<mapsto>1 (\<langle>Lit v\<rangle>,s')"
   184 AccAVar: "\<lbrakk>((v,vf),s') = avar G i a (Norm s)\<rbrakk>
   185           \<Longrightarrow>  
   186           G\<turnstile>(\<langle>Acc ((Lit a).[Lit i])\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit v\<rangle>,s')"
   187 *) 
   188 | AssVA:  "\<lbrakk>G\<turnstile>(\<langle>va\<rangle>,Norm s) \<mapsto>1 (\<langle>va'\<rangle>,s')\<rbrakk> 
   189            \<Longrightarrow> 
   190            G\<turnstile>(\<langle>va:=e\<rangle>,Norm s) \<mapsto>1 (\<langle>va':=e\<rangle>,s')"
   191 | AssE:   "\<lbrakk>groundVar va; G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> 
   192            \<Longrightarrow> 
   193            G\<turnstile>(\<langle>va:=e\<rangle>,Norm s) \<mapsto>1 (\<langle>va:=e'\<rangle>,s')"
   194 | Ass:    "\<lbrakk>groundVar va; ((w,f),s') = the_var G (Norm s) va\<rbrakk> 
   195            \<Longrightarrow> 
   196            G\<turnstile>(\<langle>va:=(Lit v)\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit v\<rangle>,assign f v s')"
   197 
   198 | CondC: "\<lbrakk>G\<turnstile>(\<langle>e0\<rangle>,Norm s) \<mapsto>1 (\<langle>e0'\<rangle>,s')\<rbrakk> 
   199           \<Longrightarrow> 
   200           G\<turnstile>(\<langle>e0? e1:e2\<rangle>,Norm s) \<mapsto>1 (\<langle>e0'? e1:e2\<rangle>,s')"
   201 | Cond:  "G\<turnstile>(\<langle>Lit b? e1:e2\<rangle>,Norm s) \<mapsto>1 (\<langle>if the_Bool b then e1 else e2\<rangle>,Norm s)"
   202 
   203 
   204 | CallTarget: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> 
   205                \<Longrightarrow>
   206                G\<turnstile>(\<langle>{accC,statT,mode}e\<cdot>mn({pTs}args)\<rangle>,Norm s) 
   207                 \<mapsto>1 (\<langle>{accC,statT,mode}e'\<cdot>mn({pTs}args)\<rangle>,s')"
   208 | CallArgs:   "\<lbrakk>G\<turnstile>(\<langle>args\<rangle>,Norm s) \<mapsto>1 (\<langle>args'\<rangle>,s')\<rbrakk> 
   209                \<Longrightarrow>
   210                G\<turnstile>(\<langle>{accC,statT,mode}Lit a\<cdot>mn({pTs}args)\<rangle>,Norm s) 
   211                 \<mapsto>1 (\<langle>{accC,statT,mode}Lit a\<cdot>mn({pTs}args')\<rangle>,s')"
   212 | Call:       "\<lbrakk>groundExprs args; vs = map the_val args;
   213                 D = invocation_declclass G mode s a statT \<lparr>name=mn,parTs=pTs\<rparr>;
   214                 s'=init_lvars G D \<lparr>name=mn,parTs=pTs\<rparr> mode a' vs (Norm s)\<rbrakk> 
   215                \<Longrightarrow> 
   216                G\<turnstile>(\<langle>{accC,statT,mode}Lit a\<cdot>mn({pTs}args)\<rangle>,Norm s) 
   217                 \<mapsto>1 (\<langle>Callee (locals s) (Methd D \<lparr>name=mn,parTs=pTs\<rparr>)\<rangle>,s')"
   218            
   219 | Callee:     "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'::expr\<rangle>,s')\<rbrakk>
   220                \<Longrightarrow> 
   221                G\<turnstile>(\<langle>Callee lcls_caller e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')"
   222 
   223 | CalleeRet:   "G\<turnstile>(\<langle>Callee lcls_caller (Lit v)\<rangle>,Norm s) 
   224                  \<mapsto>1 (\<langle>Lit v\<rangle>,(set_lvars lcls_caller (Norm s)))"
   225 
   226 | Methd: "G\<turnstile>(\<langle>Methd D sig\<rangle>,Norm s) \<mapsto>1 (\<langle>body G D sig\<rangle>,Norm s)"
   227 
   228 | Body: "G\<turnstile>(\<langle>Body D c\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitE (Init D) (Body D c)\<rangle>,Norm s)"
   229 
   230 | InsInitBody: 
   231     "\<lbrakk>G\<turnstile>(\<langle>c\<rangle>,Norm s) \<mapsto>1 (\<langle>c'\<rangle>,s')\<rbrakk>
   232      \<Longrightarrow> 
   233      G\<turnstile>(\<langle>InsInitE Skip (Body D c)\<rangle>,Norm s) \<mapsto>1(\<langle>InsInitE Skip (Body D c')\<rangle>,s')"
   234 | InsInitBodyRet: 
   235      "G\<turnstile>(\<langle>InsInitE Skip (Body D Skip)\<rangle>,Norm s)
   236        \<mapsto>1 (\<langle>Lit (the ((locals s) Result))\<rangle>,abupd (absorb Ret) (Norm s))"
   237 
   238 (*   LVar: "G\<turnstile>(LVar vn,Norm s)" is already evaluated *)
   239   
   240 | FVar: "\<lbrakk>\<not> inited statDeclC (globs s)\<rbrakk>
   241          \<Longrightarrow> 
   242          G\<turnstile>(\<langle>{accC,statDeclC,stat}e..fn\<rangle>,Norm s) 
   243           \<mapsto>1 (\<langle>InsInitV (Init statDeclC) ({accC,statDeclC,stat}e..fn)\<rangle>,Norm s)"
   244 | InsInitFVarE:
   245       "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk>
   246        \<Longrightarrow>
   247        G\<turnstile>(\<langle>InsInitV Skip ({accC,statDeclC,stat}e..fn)\<rangle>,Norm s) 
   248         \<mapsto>1 (\<langle>InsInitV Skip ({accC,statDeclC,stat}e'..fn)\<rangle>,s')"
   249 | InsInitFVar:
   250       "G\<turnstile>(\<langle>InsInitV Skip ({accC,statDeclC,stat}Lit a..fn)\<rangle>,Norm s) 
   251         \<mapsto>1 (\<langle>{accC,statDeclC,stat}Lit a..fn\<rangle>,Norm s)"
   252 --  {* Notice, that we do not have literal values for @{text vars}. 
   253 The rules for accessing variables (@{text Acc}) and assigning to variables 
   254 (@{text Ass}), test this with the predicate @{text groundVar}.  After 
   255 initialisation is done and the @{text FVar} is evaluated, we can't just 
   256 throw away the @{text InsInitFVar} term and return a literal value, as in the 
   257 cases of @{text New}  or @{text NewC}. Instead we just return the evaluated 
   258 @{text FVar} and test for initialisation in the rule @{text FVar}. 
   259 *}
   260 
   261 
   262 | AVarE1: "\<lbrakk>G\<turnstile>(\<langle>e1\<rangle>,Norm s) \<mapsto>1 (\<langle>e1'\<rangle>,s')\<rbrakk> 
   263            \<Longrightarrow> 
   264            G\<turnstile>(\<langle>e1.[e2]\<rangle>,Norm s) \<mapsto>1 (\<langle>e1'.[e2]\<rangle>,s')"
   265 
   266 | AVarE2: "G\<turnstile>(\<langle>e2\<rangle>,Norm s) \<mapsto>1 (\<langle>e2'\<rangle>,s') 
   267            \<Longrightarrow> 
   268            G\<turnstile>(\<langle>Lit a.[e2]\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit a.[e2']\<rangle>,s')"
   269 
   270 (* AVar: \<langle>(Lit a).[Lit i]\<rangle> is fully evaluated *)
   271 
   272 (* evaluation of expression lists *)
   273 
   274   -- {* @{text Nil}  is fully evaluated *}
   275 
   276 | ConsHd: "\<lbrakk>G\<turnstile>(\<langle>e::expr\<rangle>,Norm s) \<mapsto>1 (\<langle>e'::expr\<rangle>,s')\<rbrakk> 
   277            \<Longrightarrow>
   278            G\<turnstile>(\<langle>e#es\<rangle>,Norm s) \<mapsto>1 (\<langle>e'#es\<rangle>,s')"
   279   
   280 | ConsTl: "\<lbrakk>G\<turnstile>(\<langle>es\<rangle>,Norm s) \<mapsto>1 (\<langle>es'\<rangle>,s')\<rbrakk> 
   281            \<Longrightarrow>
   282            G\<turnstile>(\<langle>(Lit v)#es\<rangle>,Norm s) \<mapsto>1 (\<langle>(Lit v)#es'\<rangle>,s')"
   283 
   284 (* execution of statements *)
   285 
   286   (* cf. 14.5 *)
   287 | Skip: "G\<turnstile>(\<langle>Skip\<rangle>,Norm s) \<mapsto>1 (\<langle>SKIP\<rangle>,Norm s)"
   288 
   289 | ExprE: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> 
   290           \<Longrightarrow> 
   291           G\<turnstile>(\<langle>Expr e\<rangle>,Norm s) \<mapsto>1 (\<langle>Expr e'\<rangle>,s')"
   292 | Expr:  "G\<turnstile>(\<langle>Expr (Lit v)\<rangle>,Norm s) \<mapsto>1 (\<langle>Skip\<rangle>,Norm s)"
   293 
   294 
   295 | LabC: "\<lbrakk>G\<turnstile>(\<langle>c\<rangle>,Norm s) \<mapsto>1 (\<langle>c'\<rangle>,s')\<rbrakk> 
   296          \<Longrightarrow>  
   297          G\<turnstile>(\<langle>l\<bullet> c\<rangle>,Norm s) \<mapsto>1 (\<langle>l\<bullet> c'\<rangle>,s')"
   298 | Lab:  "G\<turnstile>(\<langle>l\<bullet> Skip\<rangle>,s) \<mapsto>1 (\<langle>Skip\<rangle>, abupd (absorb l) s)"
   299 
   300   (* cf. 14.2 *)
   301 | CompC1: "\<lbrakk>G\<turnstile>(\<langle>c1\<rangle>,Norm s) \<mapsto>1 (\<langle>c1'\<rangle>,s')\<rbrakk> 
   302            \<Longrightarrow> 
   303            G\<turnstile>(\<langle>c1;; c2\<rangle>,Norm s) \<mapsto>1 (\<langle>c1';; c2\<rangle>,s')"
   304 
   305 | Comp:   "G\<turnstile>(\<langle>Skip;; c2\<rangle>,Norm s) \<mapsto>1 (\<langle>c2\<rangle>,Norm s)"
   306 
   307   (* cf. 14.8.2 *)
   308 | IfE: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle> ,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> 
   309         \<Longrightarrow>
   310         G\<turnstile>(\<langle>If(e) s1 Else s2\<rangle>,Norm s) \<mapsto>1 (\<langle>If(e') s1 Else s2\<rangle>,s')"
   311 | If:  "G\<turnstile>(\<langle>If(Lit v) s1 Else s2\<rangle>,Norm s) 
   312          \<mapsto>1 (\<langle>if the_Bool v then s1 else s2\<rangle>,Norm s)"
   313 
   314   (* cf. 14.10, 14.10.1 *)
   315 | Loop: "G\<turnstile>(\<langle>l\<bullet> While(e) c\<rangle>,Norm s) 
   316           \<mapsto>1 (\<langle>If(e) (Cont l\<bullet>c;; l\<bullet> While(e) c) Else Skip\<rangle>,Norm s)"
   317 
   318 | Jmp: "G\<turnstile>(\<langle>Jmp j\<rangle>,Norm s) \<mapsto>1 (\<langle>Skip\<rangle>,(Some (Jump j), s))"
   319 
   320 | ThrowE: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> 
   321            \<Longrightarrow>
   322            G\<turnstile>(\<langle>Throw e\<rangle>,Norm s) \<mapsto>1 (\<langle>Throw e'\<rangle>,s')"
   323 | Throw:  "G\<turnstile>(\<langle>Throw (Lit a)\<rangle>,Norm s) \<mapsto>1 (\<langle>Skip\<rangle>,abupd (throw a) (Norm s))"
   324 
   325 | TryC1: "\<lbrakk>G\<turnstile>(\<langle>c1\<rangle>,Norm s) \<mapsto>1 (\<langle>c1'\<rangle>,s')\<rbrakk> 
   326           \<Longrightarrow>
   327           G\<turnstile>(\<langle>Try c1 Catch(C vn) c2\<rangle>, Norm s) \<mapsto>1 (\<langle>Try c1' Catch(C vn) c2\<rangle>,s')"
   328 | Try:   "\<lbrakk>G\<turnstile>s \<midarrow>sxalloc\<rightarrow> s'\<rbrakk>
   329           \<Longrightarrow>
   330           G\<turnstile>(\<langle>Try Skip Catch(C vn) c2\<rangle>, s) 
   331            \<mapsto>1 (if G,s'\<turnstile>catch C then (\<langle>c2\<rangle>,new_xcpt_var vn s')
   332                                 else (\<langle>Skip\<rangle>,s'))"
   333 
   334 | FinC1: "\<lbrakk>G\<turnstile>(\<langle>c1\<rangle>,Norm s) \<mapsto>1 (\<langle>c1'\<rangle>,s')\<rbrakk> 
   335           \<Longrightarrow>
   336           G\<turnstile>(\<langle>c1 Finally c2\<rangle>,Norm s) \<mapsto>1 (\<langle>c1' Finally c2\<rangle>,s')"
   337 
   338 | Fin:    "G\<turnstile>(\<langle>Skip Finally c2\<rangle>,(a,s)) \<mapsto>1 (\<langle>FinA a c2\<rangle>,Norm s)"
   339 
   340 | FinAC: "\<lbrakk>G\<turnstile>(\<langle>c\<rangle>,s) \<mapsto>1 (\<langle>c'\<rangle>,s')\<rbrakk>
   341           \<Longrightarrow>
   342           G\<turnstile>(\<langle>FinA a c\<rangle>,s) \<mapsto>1 (\<langle>FinA a c'\<rangle>,s')"
   343 | FinA: "G\<turnstile>(\<langle>FinA a Skip\<rangle>,s) \<mapsto>1 (\<langle>Skip\<rangle>,abupd (abrupt_if (a\<noteq>None) a) s)"
   344 
   345 
   346 | Init1: "\<lbrakk>inited C (globs s)\<rbrakk> 
   347           \<Longrightarrow> 
   348           G\<turnstile>(\<langle>Init C\<rangle>,Norm s) \<mapsto>1 (\<langle>Skip\<rangle>,Norm s)"
   349 | Init: "\<lbrakk>the (class G C)=c; \<not> inited C (globs s)\<rbrakk>  
   350          \<Longrightarrow> 
   351          G\<turnstile>(\<langle>Init C\<rangle>,Norm s) 
   352           \<mapsto>1 (\<langle>(if C = Object then Skip else (Init (super c)));;
   353                 Expr (Callee (locals s) (InsInitE (init c) SKIP))\<rangle>
   354                ,Norm (init_class_obj G C s))"
   355 -- {* @{text InsInitE} is just used as trick to embed the statement 
   356 @{text "init c"} into an expression*} 
   357 | InsInitESKIP:
   358     "G\<turnstile>(\<langle>InsInitE Skip SKIP\<rangle>,Norm s) \<mapsto>1 (\<langle>SKIP\<rangle>,Norm s)"
   359 
   360 abbreviation
   361   stepn:: "[prog, term \<times> state,nat,term \<times> state] \<Rightarrow> bool" ("_\<turnstile>_ \<mapsto>_ _"[61,82,82] 81)
   362   where "G\<turnstile>p \<mapsto>n p' \<equiv> (p,p') \<in> {(x, y). step G x y}^n"
   363 
   364 abbreviation
   365   steptr:: "[prog,term \<times> state,term \<times> state] \<Rightarrow> bool" ("_\<turnstile>_ \<mapsto>* _"[61,82,82] 81)
   366   where "G\<turnstile>p \<mapsto>* p' \<equiv> (p,p') \<in> {(x, y). step G x y}\<^sup>*"
   367          
   368 (* Equivalenzen:
   369   Bigstep zu Smallstep komplett.
   370   Smallstep zu Bigstep, nur wenn nicht die Ausdrücke Callee, FinA ,\<dots>
   371 *)
   372 
   373 lemma rtrancl_imp_rel_pow: "p \<in> R^* \<Longrightarrow> \<exists>n. p \<in> R^n"
   374 proof -
   375   assume "p \<in> R\<^sup>*"
   376   moreover obtain x y where p: "p = (x,y)" by (cases p)
   377   ultimately have "(x,y) \<in> R\<^sup>*" by hypsubst
   378   hence "\<exists>n. (x,y) \<in> R^n"
   379   proof induct
   380     fix a have "(a,a) \<in> R^0" by simp
   381     thus "\<exists>n. (a,a) \<in> R ^ n" ..
   382   next
   383     fix a b c assume "\<exists>n. (a,b) \<in> R ^ n"
   384     then obtain n where "(a,b) \<in> R^n" ..
   385     moreover assume "(b,c) \<in> R"
   386     ultimately have "(a,c) \<in> R^(Suc n)" by auto
   387     thus "\<exists>n. (a,c) \<in> R^n" ..
   388   qed
   389   with p show ?thesis by hypsubst
   390 qed  
   391 
   392 (*
   393 lemma imp_eval_trans:
   394   assumes eval: "G\<turnstile>s0 \<midarrow>t\<succ>\<rightarrow> (v,s1)" 
   395     shows trans: "G\<turnstile>(t,s0) \<mapsto>* (\<langle>Lit v\<rangle>,s1)"
   396 *)
   397 (* Jetzt muss man bei trans natürlich wieder unterscheiden: Stmt, Expr, Var!
   398    Sowas blödes:
   399    Am besten den Terminus ground auf Var,Stmt,Expr hochziehen und dann
   400    the_vals definieren\<dots>
   401   G\<turnstile>(t,s0) \<mapsto>* (t',s1) \<and> the_vals t' = v
   402 *)
   403 
   404 
   405 end