src/HOL/MicroJava/BV/LBVJVM.thy
author kleing
Tue, 13 May 2003 08:59:21 +0200
changeset 14024 213dcc39358f
parent 13601 fd3e3d6b37b2
child 14045 a34d89ce6097
permissions -rw-r--r--
HOL-Real -> HOL-Complex
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
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
     9
theory LBVJVM = LBVCorrect + LBVComplete + Typing_Framework_JVM:
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    10
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    11
types prog_cert = "cname \<Rightarrow> sig \<Rightarrow> state list"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    12
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    13
constdefs
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    14
  check_cert :: "jvm_prog \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> state list \<Rightarrow> bool"
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
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    18
  lbvjvm :: "jvm_prog \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> ty \<Rightarrow> exception_table \<Rightarrow> 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    19
             state list \<Rightarrow> instr list \<Rightarrow> state \<Rightarrow> state"
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
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    23
  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
    24
             exception_table \<Rightarrow> state list \<Rightarrow> instr list \<Rightarrow> bool"
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
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    33
  wt_jvm_prog_lbv :: "jvm_prog \<Rightarrow> prog_cert \<Rightarrow> bool"
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
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    37
  mk_cert :: "jvm_prog \<Rightarrow> nat \<Rightarrow> ty \<Rightarrow> exception_table \<Rightarrow> instr list 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    38
              \<Rightarrow> method_type \<Rightarrow> state list"
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
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    41
  prg_cert :: "jvm_prog \<Rightarrow> prog_type \<Rightarrow> prog_cert"
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)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
    68
  apply (auto simp add: list_all_ball)
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
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
    89
  have "semilat (JVMType.sl G mxs mxr)" by (rule semilat_JVM_slI)
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    90
  hence "semilat (?A, ?r, ?f)" by (unfold sl_triple_conv)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    91
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    92
  have "top ?r Err"  by (simp add: JVM_le_unfold)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    93
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    94
  have "Err \<in> ?A" by (simp add: JVM_states_unfold)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    95
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    96
  have "bottom ?r (OK None)" 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    97
    by (simp add: JVM_le_unfold bottom_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    98
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
    99
  have "OK None \<in> ?A" by (simp add: JVM_states_unfold)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   100
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   101
  from lbv
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   102
  have "bounded ?step (length ins)" 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   103
    by (clarsimp simp add: wt_lbv_def exec_def) 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   104
       (intro bounded_lift check_bounded_is_bounded) 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   105
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   106
  from lbv
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   107
  have "cert_ok cert (length ins) Err (OK None) ?A" 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   108
    by (unfold wt_lbv_def) (auto dest: check_certD)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   109
  moreover
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   110
  have "pres_type ?step (length ins) ?A" by (rule exec_pres_type)
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   111
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   112
  let ?start = "OK (Some ([],(OK (Class C))#(map OK pTs)@(replicate mxl Err)))"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   113
  from lbv
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   114
  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
   115
    by (simp add: wt_lbv_def lbvjvm_def)    
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   116
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   117
  from C pTs have "?start \<in> ?A"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   118
    by (unfold JVM_states_unfold) (auto intro: list_appendI, force)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   119
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   120
  from lbv have "0 < length ins" by (simp add: wt_lbv_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   121
  ultimately
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   122
  show ?thesis by (rule lbvs.wtl_sound_strong)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   123
qed
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   124
  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   125
lemma wt_lbv_wt_method:
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   126
  assumes wf:  "wf_prog wf_mb G"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   127
  assumes lbv: "wt_lbv G C pTs rT mxs mxl et cert ins"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   128
  assumes C:   "is_class G C" 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   129
  assumes pTs: "set pTs \<subseteq> types G"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   130
  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   131
  shows "\<exists>phi. wt_method G C pTs rT mxs mxl ins et phi"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   132
proof -
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   133
  let ?mxr   = "1 + length pTs + mxl"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   134
  let ?step  = "exec G mxs rT et ins"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   135
  let ?r     = "JVMType.le G mxs ?mxr"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   136
  let ?f     = "JVMType.sup G mxs ?mxr"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   137
  let ?A     = "states G mxs ?mxr"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   138
  let ?start = "OK (Some ([],(OK (Class C))#(map OK pTs)@(replicate mxl Err)))"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   139
  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   140
  from lbv have l: "ins \<noteq> []" by (simp add: wt_lbv_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   141
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   142
  from wf lbv C pTs
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   143
  obtain phi where 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   144
    list:  "phi \<in> list (length ins) ?A" and
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   145
    step:  "wt_step ?r Err ?step phi" and    
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   146
    start: "?start <=_?r phi!0" 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   147
    by (blast dest: wt_lbv_wt_step)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   148
  from list have [simp]: "length phi = length ins" by simp
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   149
  have "length (map ok_val phi) = length ins" by simp  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   150
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   151
  from l have 0: "0 < length phi" by simp
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   152
  with step obtain phi0 where "phi!0 = OK phi0"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   153
    by (unfold wt_step_def) blast
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   154
  with start 0
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   155
  have "wt_start G C pTs mxl (map ok_val phi)"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   156
    by (simp add: wt_start_def JVM_le_Err_conv lesub_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   157
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   158
  from lbv  have chk_bounded: "check_bounded ins et"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   159
    by (simp add: wt_lbv_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   160
  moreover {
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   161
    from list
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   162
    have "check_types G mxs ?mxr phi"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   163
      by (simp add: check_types_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   164
    also from step
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   165
    have [symmetric]: "map OK (map ok_val phi) = phi" 
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   166
      by (auto intro!: map_id simp add: wt_step_def)
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   167
    finally have "check_types G mxs ?mxr (map OK (map ok_val phi))" .
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   168
  }
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   169
  moreover {  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   170
    let ?app = "\<lambda>pc. app (ins!pc) G mxs rT pc et"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   171
    let ?eff = "\<lambda>pc. eff (ins!pc) G pc et"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   172
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   173
    from chk_bounded
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   174
    have "bounded (err_step (length ins) ?app ?eff) (length ins)"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   175
      by (blast dest: check_bounded_is_bounded boundedD intro: bounded_err_stepI)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   176
    moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   177
    from step
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   178
    have "wt_err_step (sup_state_opt G) ?step phi"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   179
      by (simp add: wt_err_step_def JVM_le_Err_conv)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   180
    ultimately
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   181
    have "wt_app_eff (sup_state_opt G) ?app ?eff (map ok_val phi)"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   182
      by (auto intro: wt_err_imp_wt_app_eff simp add: exec_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   183
  }    
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   184
  ultimately
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   185
  have "wt_method G C pTs rT mxs mxl ins et (map ok_val phi)"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   186
    by - (rule wt_method_def2 [THEN iffD2], simp)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   187
  thus ?thesis ..
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   188
qed
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   189
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   190
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   191
lemma wt_method_wt_lbv:
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   192
  assumes wf:  "wf_prog wf_mb G"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   193
  assumes wt:  "wt_method G C pTs rT mxs mxl ins et phi"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   194
  assumes C:   "is_class G C" 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   195
  assumes pTs: "set pTs \<subseteq> types G"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   196
  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   197
  defines [simp]: "cert \<equiv> mk_cert G mxs rT et ins phi"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   198
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   199
  shows "wt_lbv G C pTs rT mxs mxl et cert ins"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   200
proof -
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   201
  let ?mxr  = "1 + length pTs + mxl"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   202
  let ?step = "exec G mxs rT et ins"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   203
  let ?app  = "\<lambda>pc. app (ins!pc) G mxs rT pc et"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   204
  let ?eff  = "\<lambda>pc. eff (ins!pc) G pc et"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   205
  let ?r    = "JVMType.le G mxs ?mxr"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   206
  let ?f    = "JVMType.sup G mxs ?mxr"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   207
  let ?A    = "states G mxs ?mxr"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   208
  let ?phi  = "map OK phi"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   209
  let ?cert = "make_cert ?step ?phi (OK None)"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   210
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   211
  from wt obtain 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   212
    0:          "0 < length ins" and
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   213
    length:     "length ins = length ?phi" and
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   214
    ck_bounded: "check_bounded ins et" and
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   215
    ck_types:   "check_types G mxs ?mxr ?phi" and
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   216
    wt_start:   "wt_start G C pTs mxl phi" and
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   217
    app_eff:    "wt_app_eff (sup_state_opt G) ?app ?eff phi"
13601
fd3e3d6b37b2 Adapted to new simplifier.
berghofe
parents: 13224
diff changeset
   218
    by (simp (asm_lr) add: wt_method_def2)
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   219
  
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   220
  have "semilat (JVMType.sl G mxs ?mxr)" by (rule semilat_JVM_slI)
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   221
  hence "semilat (?A, ?r, ?f)" by (unfold sl_triple_conv)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   222
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   223
  have "top ?r Err"  by (simp add: JVM_le_unfold)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   224
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   225
  have "Err \<in> ?A" by (simp add: JVM_states_unfold)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   226
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   227
  have "bottom ?r (OK None)" 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   228
    by (simp add: JVM_le_unfold bottom_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   229
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   230
  have "OK None \<in> ?A" by (simp add: JVM_states_unfold)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   231
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   232
  from ck_bounded
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   233
  have bounded: "bounded ?step (length ins)" 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   234
    by (clarsimp simp add: exec_def) 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   235
       (intro bounded_lift check_bounded_is_bounded)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   236
  with wf
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   237
  have "mono ?r ?step (length ins) ?A" by (rule exec_mono)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   238
  hence "mono ?r ?step (length ?phi) ?A" by (simp add: length)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   239
  moreover
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   240
  have "pres_type ?step (length ins) ?A" by (rule exec_pres_type)
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   241
  hence "pres_type ?step (length ?phi) ?A" by (simp add: length)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   242
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   243
  from ck_types
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   244
  have "set ?phi \<subseteq> ?A" by (simp add: check_types_def) 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   245
  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
   246
  moreover 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   247
  from bounded 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   248
  have "bounded (exec G mxs rT et ins) (length ?phi)" by (simp add: length)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   249
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   250
  have "OK None \<noteq> Err" by simp
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   251
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   252
  from bounded length app_eff
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   253
  have "wt_err_step (sup_state_opt G) ?step ?phi"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   254
    by (auto intro: wt_app_eff_imp_wt_err simp add: exec_def)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   255
  hence "wt_step ?r Err ?step ?phi"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   256
    by (simp add: wt_err_step_def JVM_le_Err_conv)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   257
  moreover 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   258
  let ?start = "OK (Some ([],(OK (Class C))#(map OK pTs)@(replicate mxl Err)))"  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   259
  from 0 length have "0 < length phi" by auto
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   260
  hence "?phi!0 = OK (phi!0)" by simp
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   261
  with wt_start have "?start <=_?r ?phi!0"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   262
    by (clarsimp simp add: wt_start_def lesub_def JVM_le_Err_conv)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   263
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   264
  from C pTs have "?start \<in> ?A"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   265
    by (unfold JVM_states_unfold) (auto intro: list_appendI, force)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   266
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   267
  have "?start \<noteq> Err" by simp
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   268
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   269
  note length 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   270
  ultimately
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   271
  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
   272
    by (rule lbvc.wtl_complete)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   273
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   274
  from 0 length have "phi \<noteq> []" by auto
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   275
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   276
  from ck_types
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   277
  have "check_types G mxs ?mxr ?cert"
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   278
    by (auto simp add: make_cert_def check_types_def JVM_states_unfold)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   279
  moreover
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   280
  note ck_bounded 0 length
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   281
  ultimately 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   282
  show ?thesis 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   283
    by (simp add: wt_lbv_def lbvjvm_def mk_cert_def 
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   284
      check_cert_def make_cert_def nth_append)
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   285
qed  
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   286
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   287
13224
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   288
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   289
theorem jvm_lbv_correct:
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   290
  "wt_jvm_prog_lbv G Cert \<Longrightarrow> \<exists>Phi. wt_jvm_prog G Phi"
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   291
proof -  
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   292
  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
   293
              SOME phi. wt_method G C (snd sig) rT maxs maxl ins et phi"
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   294
    
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   295
  assume "wt_jvm_prog_lbv G Cert"
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   296
  hence "wt_jvm_prog G ?Phi"
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   297
    apply (unfold wt_jvm_prog_def wt_jvm_prog_lbv_def)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   298
    apply (erule jvm_prog_lift)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   299
    apply (auto dest: wt_lbv_wt_method intro: someI)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   300
    done
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   301
  thus ?thesis by blast
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   302
qed
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   303
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   304
theorem jvm_lbv_complete:
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   305
  "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
   306
  apply (unfold wt_jvm_prog_def wt_jvm_prog_lbv_def)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   307
  apply (erule jvm_prog_lift)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   308
  apply (auto simp add: prg_cert_def intro wt_method_wt_lbv)
6f0928a942d1 LBV instantiantion refactored, streamlined
kleing
parents: 13215
diff changeset
   309
  done  
13215
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   310
072a77989ce0 LBV instantiated for JVM
kleing
parents:
diff changeset
   311
end