src/HOL/NanoJava/OpSem.thy
author wenzelm
Sun Sep 18 20:33:48 2016 +0200 (2016-09-18)
changeset 63915 bab633745c7f
parent 62390 842917225d56
permissions -rw-r--r--
tuned proofs;
oheimb@11376
     1
(*  Title:      HOL/NanoJava/OpSem.thy
oheimb@11376
     2
    Author:     David von Oheimb
oheimb@11376
     3
    Copyright   2001 Technische Universitaet Muenchen
oheimb@11376
     4
*)
oheimb@11376
     5
wenzelm@58889
     6
section "Operational Evaluation Semantics"
oheimb@11376
     7
haftmann@16417
     8
theory OpSem imports State begin
oheimb@11376
     9
berghofe@23755
    10
inductive
berghofe@23755
    11
  exec :: "[state,stmt,    nat,state] => bool" ("_ -_-_\<rightarrow> _"  [98,90,   65,98] 89)
berghofe@23755
    12
  and eval :: "[state,expr,val,nat,state] => bool" ("_ -_\<succ>_-_\<rightarrow> _"[98,95,99,65,98] 89)
berghofe@23755
    13
where
berghofe@23755
    14
  Skip: "   s -Skip-n\<rightarrow> s"
berghofe@23755
    15
berghofe@23755
    16
| Comp: "[| s0 -c1-n\<rightarrow> s1; s1 -c2-n\<rightarrow> s2 |] ==>
berghofe@23755
    17
            s0 -c1;; c2-n\<rightarrow> s2"
oheimb@11376
    18
berghofe@23755
    19
| Cond: "[| s0 -e\<succ>v-n\<rightarrow> s1; s1 -(if v\<noteq>Null then c1 else c2)-n\<rightarrow> s2 |] ==>
berghofe@23755
    20
            s0 -If(e) c1 Else c2-n\<rightarrow> s2"
oheimb@11376
    21
berghofe@23755
    22
| LoopF:"   s0<x> = Null ==>
berghofe@23755
    23
            s0 -While(x) c-n\<rightarrow> s0"
berghofe@23755
    24
| LoopT:"[| s0<x> \<noteq> Null; s0 -c-n\<rightarrow> s1; s1 -While(x) c-n\<rightarrow> s2 |] ==>
berghofe@23755
    25
            s0 -While(x) c-n\<rightarrow> s2"
oheimb@11476
    26
berghofe@23755
    27
| LAcc: "   s -LAcc x\<succ>s<x>-n\<rightarrow> s"
berghofe@23755
    28
berghofe@23755
    29
| LAss: "   s -e\<succ>v-n\<rightarrow> s' ==>
berghofe@23755
    30
            s -x:==e-n\<rightarrow> lupd(x\<mapsto>v) s'"
oheimb@11376
    31
berghofe@23755
    32
| FAcc: "   s -e\<succ>Addr a-n\<rightarrow> s' ==>
berghofe@23755
    33
            s -e..f\<succ>get_field s' a f-n\<rightarrow> s'"
oheimb@11476
    34
berghofe@23755
    35
| FAss: "[| s0 -e1\<succ>Addr a-n\<rightarrow> s1;  s1 -e2\<succ>v-n\<rightarrow> s2 |] ==>
berghofe@23755
    36
            s0 -e1..f:==e2-n\<rightarrow> upd_obj a f v s2"
oheimb@11476
    37
berghofe@23755
    38
| NewC: "   new_Addr s = Addr a ==>
berghofe@23755
    39
            s -new C\<succ>Addr a-n\<rightarrow> new_obj a C s"
oheimb@11376
    40
berghofe@23755
    41
| Cast: "[| s -e\<succ>v-n\<rightarrow> s';
oheimb@11476
    42
            case v of Null => True | Addr a => obj_class s' a \<preceq>C C |] ==>
berghofe@23755
    43
            s -Cast C e\<succ>v-n\<rightarrow> s'"
oheimb@11376
    44
berghofe@23755
    45
| Call: "[| s0 -e1\<succ>a-n\<rightarrow> s1; s1 -e2\<succ>p-n\<rightarrow> s2; 
berghofe@23755
    46
            lupd(This\<mapsto>a)(lupd(Par\<mapsto>p)(del_locs s2)) -Meth (C,m)-n\<rightarrow> s3
berghofe@23755
    47
     |] ==> s0 -{C}e1..m(e2)\<succ>s3<Res>-n\<rightarrow> set_locs s2 s3"
oheimb@11376
    48
berghofe@23755
    49
| Meth: "[| s<This> = Addr a; D = obj_class s a; D\<preceq>C C;
berghofe@23755
    50
            init_locs D m s -Impl (D,m)-n\<rightarrow> s' |] ==>
berghofe@23755
    51
            s -Meth (C,m)-n\<rightarrow> s'"
oheimb@11376
    52
berghofe@23755
    53
| Impl: "   s -body Cm-    n\<rightarrow> s' ==>
berghofe@23755
    54
            s -Impl Cm-Suc n\<rightarrow> s'"
oheimb@11376
    55
oheimb@11476
    56
oheimb@11376
    57
inductive_cases exec_elim_cases':
wenzelm@32960
    58
                                  "s -Skip            -n\<rightarrow> t"
wenzelm@32960
    59
                                  "s -c1;; c2         -n\<rightarrow> t"
wenzelm@32960
    60
                                  "s -If(e) c1 Else c2-n\<rightarrow> t"
wenzelm@32960
    61
                                  "s -While(x) c      -n\<rightarrow> t"
wenzelm@32960
    62
                                  "s -x:==e           -n\<rightarrow> t"
wenzelm@32960
    63
                                  "s -e1..f:==e2      -n\<rightarrow> t"
oheimb@11508
    64
inductive_cases Meth_elim_cases:  "s -Meth Cm         -n\<rightarrow> t"
oheimb@11508
    65
inductive_cases Impl_elim_cases:  "s -Impl Cm         -n\<rightarrow> t"
oheimb@11376
    66
lemmas exec_elim_cases = exec_elim_cases' Meth_elim_cases Impl_elim_cases
oheimb@11476
    67
inductive_cases eval_elim_cases:
wenzelm@32960
    68
                                  "s -new C         \<succ>v-n\<rightarrow> t"
wenzelm@32960
    69
                                  "s -Cast C e      \<succ>v-n\<rightarrow> t"
wenzelm@32960
    70
                                  "s -LAcc x        \<succ>v-n\<rightarrow> t"
wenzelm@32960
    71
                                  "s -e..f          \<succ>v-n\<rightarrow> t"
wenzelm@32960
    72
                                  "s -{C}e1..m(e2)  \<succ>v-n\<rightarrow> t"
oheimb@11376
    73
oheimb@11476
    74
lemma exec_eval_mono [rule_format]: 
oheimb@11476
    75
  "(s -c  -n\<rightarrow> t \<longrightarrow> (\<forall>m. n \<le> m \<longrightarrow> s -c  -m\<rightarrow> t)) \<and>
oheimb@11476
    76
   (s -e\<succ>v-n\<rightarrow> t \<longrightarrow> (\<forall>m. n \<le> m \<longrightarrow> s -e\<succ>v-m\<rightarrow> t))"
oheimb@11476
    77
apply (rule exec_eval.induct)
oheimb@11476
    78
prefer 14 (* Impl *)
oheimb@11376
    79
apply clarify
oheimb@11376
    80
apply (rename_tac n)
oheimb@11376
    81
apply (case_tac n)
oheimb@11508
    82
apply (blast intro:exec_eval.intros)+
oheimb@11376
    83
done
oheimb@11476
    84
lemmas exec_mono = exec_eval_mono [THEN conjunct1, rule_format]
oheimb@11476
    85
lemmas eval_mono = exec_eval_mono [THEN conjunct2, rule_format]
oheimb@11476
    86
oheimb@11476
    87
lemma exec_exec_max: "\<lbrakk>s1 -c1-    n1   \<rightarrow> t1 ; s2 -c2-       n2\<rightarrow> t2\<rbrakk> \<Longrightarrow> 
oheimb@11476
    88
                       s1 -c1-max n1 n2\<rightarrow> t1 \<and> s2 -c2-max n1 n2\<rightarrow> t2"
haftmann@54863
    89
by (fast intro: exec_mono max.cobounded1 max.cobounded2)
oheimb@11376
    90
oheimb@11476
    91
lemma eval_exec_max: "\<lbrakk>s1 -c-    n1   \<rightarrow> t1 ; s2 -e\<succ>v-       n2\<rightarrow> t2\<rbrakk> \<Longrightarrow> 
oheimb@11476
    92
                       s1 -c-max n1 n2\<rightarrow> t1 \<and> s2 -e\<succ>v-max n1 n2\<rightarrow> t2"
haftmann@54863
    93
by (fast intro: eval_mono exec_mono max.cobounded1 max.cobounded2)
oheimb@11476
    94
oheimb@11476
    95
lemma eval_eval_max: "\<lbrakk>s1 -e1\<succ>v1-    n1   \<rightarrow> t1 ; s2 -e2\<succ>v2-       n2\<rightarrow> t2\<rbrakk> \<Longrightarrow> 
oheimb@11476
    96
                       s1 -e1\<succ>v1-max n1 n2\<rightarrow> t1 \<and> s2 -e2\<succ>v2-max n1 n2\<rightarrow> t2"
haftmann@54863
    97
by (fast intro: eval_mono max.cobounded1 max.cobounded2)
oheimb@11476
    98
oheimb@11476
    99
lemma eval_eval_exec_max: 
oheimb@11476
   100
 "\<lbrakk>s1 -e1\<succ>v1-n1\<rightarrow> t1; s2 -e2\<succ>v2-n2\<rightarrow> t2; s3 -c-n3\<rightarrow> t3\<rbrakk> \<Longrightarrow> 
oheimb@11476
   101
   s1 -e1\<succ>v1-max (max n1 n2) n3\<rightarrow> t1 \<and> 
oheimb@11476
   102
   s2 -e2\<succ>v2-max (max n1 n2) n3\<rightarrow> t2 \<and> 
oheimb@11476
   103
   s3 -c    -max (max n1 n2) n3\<rightarrow> t3"
oheimb@11476
   104
apply (drule (1) eval_eval_max, erule thin_rl)
haftmann@54863
   105
by (fast intro: exec_mono eval_mono max.cobounded1 max.cobounded2)
oheimb@11376
   106
oheimb@11565
   107
lemma Impl_body_eq: "(\<lambda>t. \<exists>n. Z -Impl M-n\<rightarrow> t) = (\<lambda>t. \<exists>n. Z -body M-n\<rightarrow> t)"
oheimb@11376
   108
apply (rule ext)
oheimb@11476
   109
apply (fast elim: exec_elim_cases intro: exec_eval.Impl)
oheimb@11376
   110
done
oheimb@11376
   111
nipkow@62390
   112
end