src/HOL/MicroJava/BV/LBVJVM.thy
author blanchet
Sun, 16 Feb 2014 21:33:28 +0100
changeset 55524 f41ef840f09d
parent 42463 f270e3e18be5
child 58886 8a6cac7c7247
permissions -rw-r--r--
folded 'list_all2' with the relator generated by 'datatype_new'
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42150
b0c0638c4aad tuned headers;
wenzelm
parents: 35416
diff changeset
     1
(*  Title:      HOL/MicroJava/BV/LBVJVM.thy
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
     2
    Author:     Tobias Nipkow, Gerwin Klein
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
     3
    Copyright   2000 TUM
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
     4
*)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
     5
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
     6
header {* \isaheader{LBV for the JVM}\label{sec:JVM} *}
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
     7
17090
603f23d71ada small mods to code lemmas
nipkow
parents: 16417
diff changeset
     8
theory LBVJVM
33954
1bc3b688548c backported parts of abstract byte code verifier from AFP/Jinja
haftmann
parents: 33639
diff changeset
     9
imports Typing_Framework_JVM
17090
603f23d71ada small mods to code lemmas
nipkow
parents: 16417
diff changeset
    10
begin
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    11
42463
f270e3e18be5 modernized specifications;
wenzelm
parents: 42150
diff changeset
    12
type_synonym prog_cert = "cname \<Rightarrow> sig \<Rightarrow> JVMType.state list"
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    13
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 34227
diff changeset
    14
definition check_cert :: "jvm_prog \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> JVMType.state list \<Rightarrow> bool" where
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    15
  "check_cert G mxs mxr n cert \<equiv> check_types G mxs mxr cert \<and> length cert = n+1 \<and>
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    16
                                 (\<forall>i<n. cert!i \<noteq> Err) \<and> cert!n = OK None"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    17
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 34227
diff changeset
    18
definition lbvjvm :: "jvm_prog \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> ty \<Rightarrow> exception_table \<Rightarrow> 
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 34227
diff changeset
    19
             JVMType.state list \<Rightarrow> instr list \<Rightarrow> JVMType.state \<Rightarrow> JVMType.state" where
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    20
  "lbvjvm G maxs maxr rT et cert bs \<equiv>
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    21
  wtl_inst_list bs cert  (JVMType.sup G maxs maxr) (JVMType.le G maxs maxr) Err (OK None) (exec G maxs rT et bs) 0"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    22
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 34227
diff changeset
    23
definition wt_lbv :: "jvm_prog \<Rightarrow> cname \<Rightarrow> ty list \<Rightarrow> ty \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> 
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 34227
diff changeset
    24
             exception_table \<Rightarrow> JVMType.state list \<Rightarrow> instr list \<Rightarrow> bool" where
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    25
  "wt_lbv G C pTs rT mxs mxl et cert ins \<equiv>
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    26
   check_bounded ins et \<and> 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    27
   check_cert G mxs (1+size pTs+mxl) (length ins) cert \<and>
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    28
   0 < size ins \<and> 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    29
   (let start  = Some ([],(OK (Class C))#((map OK pTs))@(replicate mxl Err));
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    30
        result = lbvjvm G mxs (1+size pTs+mxl) rT et cert ins (OK start)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    31
    in result \<noteq> Err)"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    32
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 34227
diff changeset
    33
definition wt_jvm_prog_lbv :: "jvm_prog \<Rightarrow> prog_cert \<Rightarrow> bool" where
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    34
  "wt_jvm_prog_lbv G cert \<equiv>
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    35
  wf_prog (\<lambda>G C (sig,rT,(maxs,maxl,b,et)). wt_lbv G C (snd sig) rT maxs maxl et (cert C sig) b) G"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    36
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 34227
diff changeset
    37
definition mk_cert :: "jvm_prog \<Rightarrow> nat \<Rightarrow> ty \<Rightarrow> exception_table \<Rightarrow> instr list 
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 34227
diff changeset
    38
              \<Rightarrow> method_type \<Rightarrow> JVMType.state list" where
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    39
  "mk_cert G maxs rT et bs phi \<equiv> make_cert (exec G maxs rT et bs) (map OK phi) (OK None)"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    40
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 34227
diff changeset
    41
definition prg_cert :: "jvm_prog \<Rightarrow> prog_type \<Rightarrow> prog_cert" where
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    42
  "prg_cert G phi C sig \<equiv> let (C,rT,(maxs,maxl,ins,et)) = the (method (G,C) sig) in 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    43
                           mk_cert G maxs rT et ins (phi C sig)"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    44
 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    45
  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    46
lemma wt_method_def2:
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    47
  fixes pTs and mxl and G and mxs and rT and et and bs and phi 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    48
  defines [simp]: "mxr   \<equiv> 1 + length pTs + mxl"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    49
  defines [simp]: "r     \<equiv> sup_state_opt G"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    50
  defines [simp]: "app0  \<equiv> \<lambda>pc. app (bs!pc) G mxs rT pc et"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    51
  defines [simp]: "step0 \<equiv> \<lambda>pc. eff (bs!pc) G pc et"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    52
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    53
  shows
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    54
  "wt_method G C pTs rT mxs mxl bs et phi = 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    55
  (bs \<noteq> [] \<and> 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    56
   length phi = length bs \<and>
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    57
   check_bounded bs et \<and> 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    58
   check_types G mxs mxr (map OK phi) \<and>   
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    59
   wt_start G C pTs mxl phi \<and> 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    60
   wt_app_eff r app0 step0 phi)"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    61
  by (auto simp add: wt_method_def wt_app_eff_def wt_instr_def lesub_def
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    62
           dest: check_bounded_is_bounded boundedD)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    63
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    64
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
    65
lemma check_certD:
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
    66
  "check_cert G mxs mxr n cert \<Longrightarrow> cert_ok cert n Err (OK None) (states G mxs mxr)"
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
    67
  apply (unfold cert_ok_def check_cert_def check_types_def)
17090
603f23d71ada small mods to code lemmas
nipkow
parents: 16417
diff changeset
    68
  apply (auto simp add: list_all_iff)
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
    69
  done
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
    70
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    71
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    72
lemma wt_lbv_wt_step:
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    73
  assumes wf:  "wf_prog wf_mb G"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    74
  assumes lbv: "wt_lbv G C pTs rT mxs mxl et cert ins"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    75
  assumes C:   "is_class G C" 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    76
  assumes pTs: "set pTs \<subseteq> types G"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    77
  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    78
  defines [simp]: "mxr \<equiv> 1+length pTs+mxl"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    79
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    80
  shows "\<exists>ts \<in> list (size ins) (states G mxs mxr). 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    81
            wt_step (JVMType.le G mxs mxr) Err (exec G mxs rT et ins) ts
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    82
          \<and> OK (Some ([],(OK (Class C))#((map OK pTs))@(replicate mxl Err))) <=_(JVMType.le G mxs mxr) ts!0"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    83
proof -
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    84
  let ?step = "exec G mxs rT et ins"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    85
  let ?r    = "JVMType.le G mxs mxr"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    86
  let ?f    = "JVMType.sup G mxs mxr"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    87
  let ?A    = "states G mxs mxr"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    88
14045
a34d89ce6097 Introduced distinction wf_prog vs. ws_prog
streckem
parents: 13601
diff changeset
    89
  have "semilat (JVMType.sl G mxs mxr)" 
23467
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 19437
diff changeset
    90
    by (rule semilat_JVM_slI, rule wf_prog_ws_prog, rule wf)
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    91
  hence "semilat (?A, ?r, ?f)" by (unfold sl_triple_conv)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    92
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    93
  have "top ?r Err"  by (simp add: JVM_le_unfold)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    94
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    95
  have "Err \<in> ?A" by (simp add: JVM_states_unfold)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    96
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    97
  have "bottom ?r (OK None)" 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    98
    by (simp add: JVM_le_unfold bottom_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    99
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   100
  have "OK None \<in> ?A" by (simp add: JVM_states_unfold)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   101
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   102
  from lbv
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   103
  have "bounded ?step (length ins)" 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   104
    by (clarsimp simp add: wt_lbv_def exec_def) 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   105
       (intro bounded_lift check_bounded_is_bounded) 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   106
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   107
  from lbv
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   108
  have "cert_ok cert (length ins) Err (OK None) ?A" 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   109
    by (unfold wt_lbv_def) (auto dest: check_certD)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   110
  moreover
23467
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 19437
diff changeset
   111
  from wf have "pres_type ?step (length ins) ?A" by (rule exec_pres_type)
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   112
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   113
  let ?start = "OK (Some ([],(OK (Class C))#(map OK pTs)@(replicate mxl Err)))"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   114
  from lbv
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   115
  have "wtl_inst_list ins cert ?f ?r Err (OK None) ?step 0 ?start \<noteq> Err"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   116
    by (simp add: wt_lbv_def lbvjvm_def)    
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   117
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   118
  from C pTs have "?start \<in> ?A"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   119
    by (unfold JVM_states_unfold) (auto intro: list_appendI, force)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   120
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   121
  from lbv have "0 < length ins" by (simp add: wt_lbv_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   122
  ultimately
27681
8cedebf55539 dropped locale (open)
haftmann
parents: 26450
diff changeset
   123
  show ?thesis by (rule lbvs.wtl_sound_strong [OF lbvs.intro, OF lbv.intro lbvs_axioms.intro, OF Semilat.intro lbv_axioms.intro])
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   124
qed
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   125
  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   126
lemma wt_lbv_wt_method:
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   127
  assumes wf:  "wf_prog wf_mb G"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   128
  assumes lbv: "wt_lbv G C pTs rT mxs mxl et cert ins"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   129
  assumes C:   "is_class G C" 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   130
  assumes pTs: "set pTs \<subseteq> types G"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   131
  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   132
  shows "\<exists>phi. wt_method G C pTs rT mxs mxl ins et phi"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   133
proof -
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   134
  let ?mxr   = "1 + length pTs + mxl"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   135
  let ?step  = "exec G mxs rT et ins"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   136
  let ?r     = "JVMType.le G mxs ?mxr"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   137
  let ?f     = "JVMType.sup G mxs ?mxr"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   138
  let ?A     = "states G mxs ?mxr"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   139
  let ?start = "OK (Some ([],(OK (Class C))#(map OK pTs)@(replicate mxl Err)))"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   140
  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   141
  from lbv have l: "ins \<noteq> []" by (simp add: wt_lbv_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   142
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   143
  from wf lbv C pTs
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   144
  obtain phi where 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   145
    list:  "phi \<in> list (length ins) ?A" and
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   146
    step:  "wt_step ?r Err ?step phi" and    
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   147
    start: "?start <=_?r phi!0" 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   148
    by (blast dest: wt_lbv_wt_step)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   149
  from list have [simp]: "length phi = length ins" by simp
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   150
  have "length (map ok_val phi) = length ins" by simp  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   151
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   152
  from l have 0: "0 < length phi" by simp
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   153
  with step obtain phi0 where "phi!0 = OK phi0"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   154
    by (unfold wt_step_def) blast
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   155
  with start 0
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   156
  have "wt_start G C pTs mxl (map ok_val phi)"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   157
    by (simp add: wt_start_def JVM_le_Err_conv lesub_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   158
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   159
  from lbv  have chk_bounded: "check_bounded ins et"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   160
    by (simp add: wt_lbv_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   161
  moreover {
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   162
    from list
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   163
    have "check_types G mxs ?mxr phi"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   164
      by (simp add: check_types_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   165
    also from step
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   166
    have [symmetric]: "map OK (map ok_val phi) = phi" 
33639
603320b93668 New list theorems; added map_map to simpset, this is the prefered direction; allow sorting by a key
hoelzl
parents: 27681
diff changeset
   167
      by (auto intro!: nth_equalityI simp add: wt_step_def)
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   168
    finally have "check_types G mxs ?mxr (map OK (map ok_val phi))" .
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   169
  }
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   170
  moreover {  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   171
    let ?app = "\<lambda>pc. app (ins!pc) G mxs rT pc et"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   172
    let ?eff = "\<lambda>pc. eff (ins!pc) G pc et"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   173
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   174
    from chk_bounded
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   175
    have "bounded (err_step (length ins) ?app ?eff) (length ins)"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   176
      by (blast dest: check_bounded_is_bounded boundedD intro: bounded_err_stepI)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   177
    moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   178
    from step
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   179
    have "wt_err_step (sup_state_opt G) ?step phi"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   180
      by (simp add: wt_err_step_def JVM_le_Err_conv)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   181
    ultimately
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   182
    have "wt_app_eff (sup_state_opt G) ?app ?eff (map ok_val phi)"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   183
      by (auto intro: wt_err_imp_wt_app_eff simp add: exec_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   184
  }    
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   185
  ultimately
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   186
  have "wt_method G C pTs rT mxs mxl ins et (map ok_val phi)"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   187
    by - (rule wt_method_def2 [THEN iffD2], simp)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   188
  thus ?thesis ..
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   189
qed
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   190
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   191
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   192
lemma wt_method_wt_lbv:
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   193
  assumes wf:  "wf_prog wf_mb G"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   194
  assumes wt:  "wt_method G C pTs rT mxs mxl ins et phi"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   195
  assumes C:   "is_class G C" 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   196
  assumes pTs: "set pTs \<subseteq> types G"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   197
  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   198
  defines [simp]: "cert \<equiv> mk_cert G mxs rT et ins phi"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   199
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   200
  shows "wt_lbv G C pTs rT mxs mxl et cert ins"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   201
proof -
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   202
  let ?mxr  = "1 + length pTs + mxl"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   203
  let ?step = "exec G mxs rT et ins"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   204
  let ?app  = "\<lambda>pc. app (ins!pc) G mxs rT pc et"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   205
  let ?eff  = "\<lambda>pc. eff (ins!pc) G pc et"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   206
  let ?r    = "JVMType.le G mxs ?mxr"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   207
  let ?f    = "JVMType.sup G mxs ?mxr"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   208
  let ?A    = "states G mxs ?mxr"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   209
  let ?phi  = "map OK phi"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   210
  let ?cert = "make_cert ?step ?phi (OK None)"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   211
34227
33d44b1520c0 another legacy "asm_lr"
nipkow
parents: 33954
diff changeset
   212
  from wt have
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   213
    0:          "0 < length ins" and
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   214
    length:     "length ins = length ?phi" and
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   215
    ck_bounded: "check_bounded ins et" and
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   216
    ck_types:   "check_types G mxs ?mxr ?phi" and
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   217
    wt_start:   "wt_start G C pTs mxl phi" and
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   218
    app_eff:    "wt_app_eff (sup_state_opt G) ?app ?eff phi"
34227
33d44b1520c0 another legacy "asm_lr"
nipkow
parents: 33954
diff changeset
   219
    by (simp_all add: wt_method_def2)
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   220
  
14045
a34d89ce6097 Introduced distinction wf_prog vs. ws_prog
streckem
parents: 13601
diff changeset
   221
  have "semilat (JVMType.sl G mxs ?mxr)" 
23467
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 19437
diff changeset
   222
    by (rule semilat_JVM_slI) (rule wf_prog_ws_prog [OF wf])
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   223
  hence "semilat (?A, ?r, ?f)" by (unfold sl_triple_conv)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   224
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   225
  have "top ?r Err"  by (simp add: JVM_le_unfold)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   226
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   227
  have "Err \<in> ?A" by (simp add: JVM_states_unfold)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   228
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   229
  have "bottom ?r (OK None)" 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   230
    by (simp add: JVM_le_unfold bottom_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   231
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   232
  have "OK None \<in> ?A" by (simp add: JVM_states_unfold)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   233
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   234
  from ck_bounded
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   235
  have bounded: "bounded ?step (length ins)" 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   236
    by (clarsimp simp add: exec_def) 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   237
       (intro bounded_lift check_bounded_is_bounded)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   238
  with wf
14045
a34d89ce6097 Introduced distinction wf_prog vs. ws_prog
streckem
parents: 13601
diff changeset
   239
  have "mono ?r ?step (length ins) ?A"
a34d89ce6097 Introduced distinction wf_prog vs. ws_prog
streckem
parents: 13601
diff changeset
   240
    by (rule wf_prog_ws_prog [THEN exec_mono])
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   241
  hence "mono ?r ?step (length ?phi) ?A" by (simp add: length)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   242
  moreover
23467
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 19437
diff changeset
   243
  from wf have "pres_type ?step (length ins) ?A" by (rule exec_pres_type)
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   244
  hence "pres_type ?step (length ?phi) ?A" by (simp add: length)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   245
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   246
  from ck_types
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   247
  have "set ?phi \<subseteq> ?A" by (simp add: check_types_def) 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   248
  hence "\<forall>pc. pc < length ?phi \<longrightarrow> ?phi!pc \<in> ?A \<and> ?phi!pc \<noteq> Err" by auto
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   249
  moreover 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   250
  from bounded 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   251
  have "bounded (exec G mxs rT et ins) (length ?phi)" by (simp add: length)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   252
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   253
  have "OK None \<noteq> Err" by simp
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   254
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   255
  from bounded length app_eff
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   256
  have "wt_err_step (sup_state_opt G) ?step ?phi"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   257
    by (auto intro: wt_app_eff_imp_wt_err simp add: exec_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   258
  hence "wt_step ?r Err ?step ?phi"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   259
    by (simp add: wt_err_step_def JVM_le_Err_conv)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   260
  moreover 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   261
  let ?start = "OK (Some ([],(OK (Class C))#(map OK pTs)@(replicate mxl Err)))"  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   262
  from 0 length have "0 < length phi" by auto
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   263
  hence "?phi!0 = OK (phi!0)" by simp
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   264
  with wt_start have "?start <=_?r ?phi!0"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   265
    by (clarsimp simp add: wt_start_def lesub_def JVM_le_Err_conv)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   266
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   267
  from C pTs have "?start \<in> ?A"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   268
    by (unfold JVM_states_unfold) (auto intro: list_appendI, force)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   269
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   270
  have "?start \<noteq> Err" by simp
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   271
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   272
  note length 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   273
  ultimately
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   274
  have "wtl_inst_list ins ?cert ?f ?r Err (OK None) ?step 0 ?start \<noteq> Err"
27681
8cedebf55539 dropped locale (open)
haftmann
parents: 26450
diff changeset
   275
    by (rule lbvc.wtl_complete [OF lbvc.intro, OF lbv.intro lbvc_axioms.intro, OF Semilat.intro lbv_axioms.intro])
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   276
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   277
  from 0 length have "phi \<noteq> []" by auto
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   278
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   279
  from ck_types
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   280
  have "check_types G mxs ?mxr ?cert"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   281
    by (auto simp add: make_cert_def check_types_def JVM_states_unfold)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   282
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   283
  note ck_bounded 0 length
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   284
  ultimately 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   285
  show ?thesis 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   286
    by (simp add: wt_lbv_def lbvjvm_def mk_cert_def 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   287
      check_cert_def make_cert_def nth_append)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   288
qed  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   289
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   290
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   291
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   292
theorem jvm_lbv_correct:
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   293
  "wt_jvm_prog_lbv G Cert \<Longrightarrow> \<exists>Phi. wt_jvm_prog G Phi"
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   294
proof -  
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   295
  let ?Phi = "\<lambda>C sig. let (C,rT,(maxs,maxl,ins,et)) = the (method (G,C) sig) in 
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   296
              SOME phi. wt_method G C (snd sig) rT maxs maxl ins et phi"
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   297
    
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   298
  assume "wt_jvm_prog_lbv G Cert"
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   299
  hence "wt_jvm_prog G ?Phi"
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   300
    apply (unfold wt_jvm_prog_def wt_jvm_prog_lbv_def)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   301
    apply (erule jvm_prog_lift)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   302
    apply (auto dest: wt_lbv_wt_method intro: someI)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   303
    done
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   304
  thus ?thesis by blast
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   305
qed
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   306
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   307
theorem jvm_lbv_complete:
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   308
  "wt_jvm_prog G Phi \<Longrightarrow> wt_jvm_prog_lbv G (prg_cert G Phi)"
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   309
  apply (unfold wt_jvm_prog_def wt_jvm_prog_lbv_def)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   310
  apply (erule jvm_prog_lift)
19437
77b19ffc175e fixed typo in method invocation;
wenzelm
parents: 17090
diff changeset
   311
  apply (auto simp add: prg_cert_def intro: wt_method_wt_lbv)
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   312
  done  
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   313
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   314
end