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