src/HOL/MicroJava/BV/LBVComplete.thy
author wenzelm
Mon, 21 Aug 2000 19:17:07 +0200
changeset 9673 1b2d4f995b13
parent 9664 4cae97480a6d
child 9757 1024a2d80ac0
permissions -rw-r--r--
updated;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
     1
(*  Title:      HOL/MicroJava/BV/LBVComplete.thy
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
     2
    ID:         $Id$
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
     3
    Author:     Gerwin Klein
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
     4
    Copyright   2000 Technische Universitaet Muenchen
9054
0e48e7d4d4f9 minor tuning for pdf documents
kleing
parents: 9012
diff changeset
     5
*)
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
     6
9054
0e48e7d4d4f9 minor tuning for pdf documents
kleing
parents: 9012
diff changeset
     7
header {* Completeness of the LBV *}
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
     8
9559
kleing
parents: 9549
diff changeset
     9
theory LBVComplete = BVSpec + LBVSpec + StepMono:
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
    10
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    11
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    12
constdefs
9580
kleing
parents: 9559
diff changeset
    13
  is_approx :: "['a option list, 'a list] \<Rightarrow> bool"
kleing
parents: 9559
diff changeset
    14
  "is_approx a b \<equiv> length a = length b \<and> (\<forall> n. n < length a \<longrightarrow>
kleing
parents: 9559
diff changeset
    15
                   (a!n = None \<or> a!n = Some (b!n)))"
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    16
  
9580
kleing
parents: 9559
diff changeset
    17
  contains_dead :: "[instr list, certificate, method_type, p_count] \<Rightarrow> bool"
kleing
parents: 9559
diff changeset
    18
  "contains_dead ins cert phi pc \<equiv>
kleing
parents: 9559
diff changeset
    19
     Suc pc \<notin> succs (ins!pc) pc \<and> Suc pc < length phi \<longrightarrow>
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
    20
     cert ! (Suc pc) = Some (phi ! Suc pc)"
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    21
9580
kleing
parents: 9559
diff changeset
    22
  contains_targets :: "[instr list, certificate, method_type, p_count] \<Rightarrow> bool"
kleing
parents: 9559
diff changeset
    23
  "contains_targets ins cert phi pc \<equiv> (
kleing
parents: 9559
diff changeset
    24
     \<forall> pc' \<in> succs (ins!pc) pc. pc' \<noteq> Suc pc \<and> pc' < length phi \<longrightarrow> 
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
    25
     cert!pc' = Some (phi!pc'))" 
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
    26
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    27
9580
kleing
parents: 9559
diff changeset
    28
  fits :: "[instr list, certificate, method_type] \<Rightarrow> bool"
kleing
parents: 9559
diff changeset
    29
  "fits ins cert phi \<equiv> is_approx cert phi \<and> length ins < length phi \<and>
kleing
parents: 9559
diff changeset
    30
                            (\<forall> pc. pc < length ins \<longrightarrow>
kleing
parents: 9559
diff changeset
    31
                                   contains_dead ins cert phi pc \<and> 
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    32
                                   contains_targets ins cert phi pc)"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    33
9580
kleing
parents: 9559
diff changeset
    34
  is_target :: "[instr list, p_count] \<Rightarrow> bool" 
kleing
parents: 9559
diff changeset
    35
  "is_target ins pc \<equiv> \<exists> pc'. pc' < length ins \<and> pc \<in> succs (ins!pc') pc'"
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
    36
9580
kleing
parents: 9559
diff changeset
    37
  maybe_dead :: "[instr list, p_count] \<Rightarrow> bool"
kleing
parents: 9559
diff changeset
    38
  "maybe_dead ins pc \<equiv> \<exists> pc'. pc = pc'+1 \<and> pc \<notin> succs (ins!pc') pc'"
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    39
9580
kleing
parents: 9559
diff changeset
    40
  mdot :: "[instr list, p_count] \<Rightarrow> bool"
kleing
parents: 9559
diff changeset
    41
  "mdot ins pc \<equiv> maybe_dead ins pc \<or> is_target ins pc"
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    42
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    43
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    44
consts
9580
kleing
parents: 9559
diff changeset
    45
  option_filter_n :: "['a list, nat \<Rightarrow> bool, nat] \<Rightarrow> 'a option list"
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    46
primrec 
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    47
  "option_filter_n []    P n = []"  
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    48
  "option_filter_n (h#t) P n = (if (P n) then Some h # option_filter_n t P (n+1) 
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
    49
                                         else None   # option_filter_n t P (n+1))"  
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    50
  
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    51
constdefs 
9580
kleing
parents: 9559
diff changeset
    52
  option_filter :: "['a list, nat \<Rightarrow> bool] \<Rightarrow> 'a option list" 
kleing
parents: 9559
diff changeset
    53
  "option_filter l P \<equiv> option_filter_n l P 0" 
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    54
  
9580
kleing
parents: 9559
diff changeset
    55
  make_cert :: "[instr list, method_type] \<Rightarrow> certificate"
kleing
parents: 9559
diff changeset
    56
  "make_cert ins phi \<equiv> option_filter phi (mdot ins)"
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    57
  
9580
kleing
parents: 9559
diff changeset
    58
  make_Cert :: "[jvm_prog, prog_type] \<Rightarrow> prog_certificate"
kleing
parents: 9559
diff changeset
    59
  "make_Cert G Phi \<equiv>  \<lambda> C sig.
kleing
parents: 9559
diff changeset
    60
    let (C,x,y,mdecls) = \<epsilon> (Cl,x,y,mdecls). (Cl,x,y,mdecls) \<in> set G \<and> Cl = C in
kleing
parents: 9559
diff changeset
    61
      let (sig,rT,maxl,b) = \<epsilon> (sg,rT,maxl,b). (sg,rT,maxl,b) \<in> set mdecls \<and> sg = sig in
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
    62
        make_cert b (Phi C sig)"
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    63
  
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    64
9559
kleing
parents: 9549
diff changeset
    65
lemmas [simp del] = split_paired_Ex
kleing
parents: 9549
diff changeset
    66
9580
kleing
parents: 9559
diff changeset
    67
lemma length_ofn [rulify]: "\<forall>n. length (option_filter_n l P n) = length l"
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
    68
  by (induct l) auto
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    69
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    70
9559
kleing
parents: 9549
diff changeset
    71
lemma is_approx_option_filter: "is_approx (option_filter l P) l" 
kleing
parents: 9549
diff changeset
    72
proof -
kleing
parents: 9549
diff changeset
    73
  {
kleing
parents: 9549
diff changeset
    74
    fix a n
9580
kleing
parents: 9559
diff changeset
    75
    have "\<forall>n. is_approx (option_filter_n a P n) a" (is "?P a")
9559
kleing
parents: 9549
diff changeset
    76
    proof (induct a)
kleing
parents: 9549
diff changeset
    77
      show "?P []" by (auto simp add: is_approx_def)
kleing
parents: 9549
diff changeset
    78
    
kleing
parents: 9549
diff changeset
    79
      fix l ls
kleing
parents: 9549
diff changeset
    80
      assume Cons: "?P ls"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    81
    
9559
kleing
parents: 9549
diff changeset
    82
      show "?P (l#ls)"
kleing
parents: 9549
diff changeset
    83
      proof (unfold is_approx_def, intro allI conjI impI)
kleing
parents: 9549
diff changeset
    84
        fix n
kleing
parents: 9549
diff changeset
    85
        show "length (option_filter_n (l # ls) P n) = length (l # ls)" 
kleing
parents: 9549
diff changeset
    86
          by (simp only: length_ofn)
kleing
parents: 9549
diff changeset
    87
      
kleing
parents: 9549
diff changeset
    88
        fix m
kleing
parents: 9549
diff changeset
    89
        assume "m < length (option_filter_n (l # ls) P n)"
kleing
parents: 9549
diff changeset
    90
        hence m: "m < Suc (length ls)" by (simp only: length_ofn) simp
kleing
parents: 9549
diff changeset
    91
      
9580
kleing
parents: 9559
diff changeset
    92
        show "option_filter_n (l # ls) P n ! m = None \<or>
9559
kleing
parents: 9549
diff changeset
    93
              option_filter_n (l # ls) P n ! m = Some ((l # ls) ! m)" 
kleing
parents: 9549
diff changeset
    94
        proof (cases "m")
kleing
parents: 9549
diff changeset
    95
          assume "m = 0"
kleing
parents: 9549
diff changeset
    96
          with m show ?thesis by simp
kleing
parents: 9549
diff changeset
    97
        next
kleing
parents: 9549
diff changeset
    98
          fix m' assume Suc: "m = Suc m'"
kleing
parents: 9549
diff changeset
    99
          from Cons
kleing
parents: 9549
diff changeset
   100
          show ?thesis
kleing
parents: 9549
diff changeset
   101
          proof (unfold is_approx_def, elim allE impE conjE)
kleing
parents: 9549
diff changeset
   102
            from m Suc
kleing
parents: 9549
diff changeset
   103
            show "m' < length (option_filter_n ls P (Suc n))" by (simp add: length_ofn)
kleing
parents: 9549
diff changeset
   104
          
9580
kleing
parents: 9559
diff changeset
   105
            assume "option_filter_n ls P (Suc n) ! m' = None \<or> 
9559
kleing
parents: 9549
diff changeset
   106
                    option_filter_n ls P (Suc n) ! m' = Some (ls ! m')"
kleing
parents: 9549
diff changeset
   107
            with m Suc
kleing
parents: 9549
diff changeset
   108
            show ?thesis by auto
kleing
parents: 9549
diff changeset
   109
          qed
kleing
parents: 9549
diff changeset
   110
        qed
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   111
      qed
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   112
    qed
9559
kleing
parents: 9549
diff changeset
   113
  }
kleing
parents: 9549
diff changeset
   114
  
kleing
parents: 9549
diff changeset
   115
  thus ?thesis    
kleing
parents: 9549
diff changeset
   116
    by (auto simp add: option_filter_def)
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   117
qed
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   118
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   119
lemma option_filter_Some:
9580
kleing
parents: 9559
diff changeset
   120
"\<lbrakk>n < length l; P n\<rbrakk> \<Longrightarrow> option_filter l P ! n = Some (l!n)"
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   121
proof -
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   122
  
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   123
  assume 1: "n < length l" "P n"
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   124
9580
kleing
parents: 9559
diff changeset
   125
  have "\<forall>n n'. n < length l \<longrightarrow> P (n+n') \<longrightarrow>  option_filter_n l P n' ! n = Some (l!n)"
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   126
    (is "?P l")
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   127
  proof (induct l)
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   128
    show "?P []" by simp
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   129
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   130
    fix l ls assume Cons: "?P ls"
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   131
    show "?P (l#ls)"
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   132
    proof (intro)
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   133
      fix n n'
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   134
      assume l: "n < length (l # ls)"
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   135
      assume P: "P (n + n')"
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   136
      show "option_filter_n (l # ls) P n' ! n = Some ((l # ls) ! n)"
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   137
      proof (cases "n")
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   138
        assume "n=0"
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   139
        with P show ?thesis by simp
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   140
      next
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   141
        fix m assume "n = Suc m"
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   142
        with l P Cons
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   143
        show ?thesis by simp
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   144
      qed
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   145
    qed
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   146
  qed
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   147
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   148
  with 1
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   149
  show ?thesis by (auto simp add: option_filter_def)
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   150
qed
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   151
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   152
lemma option_filter_contains_dead:
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   153
"contains_dead ins (option_filter phi (mdot ins)) phi pc" 
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   154
  by (auto intro: option_filter_Some simp add: contains_dead_def mdot_def maybe_dead_def)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   155
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   156
lemma option_filter_contains_targets:
9580
kleing
parents: 9559
diff changeset
   157
"pc < length ins \<Longrightarrow> contains_targets ins (option_filter phi (mdot ins)) phi pc"
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   158
proof (unfold contains_targets_def, clarsimp)
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   159
 
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   160
  fix pc'
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   161
  assume "pc < length ins" 
9580
kleing
parents: 9559
diff changeset
   162
         "pc' \<in> succs (ins ! pc) pc" 
kleing
parents: 9559
diff changeset
   163
         "pc' \<noteq> Suc pc" and
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   164
    pc': "pc' < length phi"
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   165
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   166
  hence "is_target ins pc'" by (auto simp add: is_target_def)
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   167
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   168
  with pc'
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   169
  show "option_filter phi (mdot ins) ! pc' = Some (phi ! pc')"
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   170
    by (auto intro: option_filter_Some simp add: mdot_def)
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   171
qed
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   172
  
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   173
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   174
lemma fits_make_cert:
9580
kleing
parents: 9559
diff changeset
   175
  "length ins < length phi \<Longrightarrow> fits ins (make_cert ins phi) phi"
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   176
proof -
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   177
  assume l: "length ins < length phi"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   178
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   179
  thus "fits ins (make_cert ins phi) phi"
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   180
  proof (unfold fits_def make_cert_def, intro conjI allI impI)
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   181
    show "is_approx (option_filter phi (mdot ins)) phi" 
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   182
      by (rule is_approx_option_filter)
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   183
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   184
    show "length ins < length phi" .
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   185
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   186
    fix pc
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   187
    show "contains_dead ins (option_filter phi (mdot ins)) phi pc" 
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   188
      by (rule option_filter_contains_dead)
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   189
    
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   190
    assume "pc < length ins" 
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   191
    thus "contains_targets ins (option_filter phi (mdot ins)) phi pc" 
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   192
      by (rule option_filter_contains_targets)
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   193
  qed
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   194
qed
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   195
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   196
lemma fitsD: 
9580
kleing
parents: 9559
diff changeset
   197
"\<lbrakk>fits ins cert phi; pc' \<in> succs (ins!pc) pc; pc' \<noteq> Suc pc; pc < length ins; pc' < length ins\<rbrakk> 
kleing
parents: 9559
diff changeset
   198
  \<Longrightarrow> cert!pc' = Some (phi!pc')"
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   199
by (clarsimp simp add: fits_def contains_dead_def contains_targets_def)
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   200
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   201
lemma fitsD2:
9580
kleing
parents: 9559
diff changeset
   202
"\<lbrakk>fits ins cert phi; Suc pc \<notin> succs (ins!pc) pc;  pc < length ins\<rbrakk> 
kleing
parents: 9559
diff changeset
   203
  \<Longrightarrow> cert ! Suc pc = Some (phi ! Suc pc)"
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   204
by (clarsimp simp add: fits_def contains_dead_def contains_targets_def)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   205
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   206
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   207
lemma wtl_inst_mono:
9580
kleing
parents: 9559
diff changeset
   208
"\<lbrakk>wtl_inst i G rT s1 s1' cert mpc pc; fits ins cert phi; pc < length ins; 
kleing
parents: 9559
diff changeset
   209
  G \<turnstile> s2 <=s s1; i = ins!pc\<rbrakk> \<Longrightarrow> 
kleing
parents: 9559
diff changeset
   210
 \<exists> s2'. wtl_inst (ins!pc) G rT s2 s2' cert mpc pc \<and> (G \<turnstile> s2' <=s s1')"
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   211
proof -
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   212
  assume pc:   "pc < length ins" "i = ins!pc"
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   213
  assume wtl:  "wtl_inst i G rT s1 s1' cert mpc pc"
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   214
  assume fits: "fits ins cert phi"
9580
kleing
parents: 9559
diff changeset
   215
  assume G:    "G \<turnstile> s2 <=s s1"
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   216
  
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   217
  let "?step s" = "step (i, G, s)"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   218
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   219
  from wtl G
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   220
  have app: "app (i, G, rT, s2)" by (auto simp add: wtl_inst_def app_mono)
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   221
  
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   222
  from wtl G
9580
kleing
parents: 9559
diff changeset
   223
  have step: "succs i pc \<noteq> {} \<Longrightarrow> G \<turnstile> the (?step s2) <=s the (?step s1)" 
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   224
    by - (drule step_mono, auto simp add: wtl_inst_def)
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   225
  
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   226
  with app
9580
kleing
parents: 9559
diff changeset
   227
  have some: "succs i pc \<noteq> {} \<Longrightarrow> ?step s2 \<noteq> None" by (simp add: app_step_some)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   228
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   229
  {
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   230
    fix pc'
9580
kleing
parents: 9559
diff changeset
   231
    assume 0: "pc' \<in> succs i pc" "pc' \<noteq> pc+1"
kleing
parents: 9559
diff changeset
   232
    hence "succs i pc \<noteq> {}" by auto
kleing
parents: 9559
diff changeset
   233
    hence "G \<turnstile> the (?step s2) <=s the (?step s1)" by (rule step)
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   234
    also 
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   235
    from wtl 0
9580
kleing
parents: 9559
diff changeset
   236
    have "G \<turnstile> the (?step s1) <=s the (cert!pc')"
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   237
      by (auto simp add: wtl_inst_def) 
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   238
    finally
9580
kleing
parents: 9559
diff changeset
   239
    have "G\<turnstile> the (?step s2) <=s the (cert!pc')" .
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   240
  } note cert = this
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   241
    
9580
kleing
parents: 9559
diff changeset
   242
  have "\<exists>s2'. wtl_inst i G rT s2 s2' cert mpc pc \<and> G \<turnstile> s2' <=s s1'"
kleing
parents: 9559
diff changeset
   243
  proof (cases "pc+1 \<in> succs i pc")
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   244
    case True
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   245
    with wtl
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   246
    have s1': "s1' = the (?step s1)" by (simp add: wtl_inst_def)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   247
9580
kleing
parents: 9559
diff changeset
   248
    have "wtl_inst i G rT s2 (the (?step s2)) cert mpc pc \<and> G \<turnstile> (the (?step s2)) <=s s1'" 
kleing
parents: 9559
diff changeset
   249
      (is "?wtl \<and> ?G")
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   250
    proof
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   251
      from True s1'
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   252
      show ?G by (auto intro: step)
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   253
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   254
      from True app wtl
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   255
      show ?wtl
9580
kleing
parents: 9559
diff changeset
   256
        by (clarsimp intro!: cert simp add: wtl_inst_def)
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   257
    qed
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   258
    thus ?thesis by blast
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   259
  next
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   260
    case False
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   261
    with wtl
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   262
    have "s1' = the (cert ! Suc pc)" by (simp add: wtl_inst_def)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   263
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   264
    with False app wtl
9580
kleing
parents: 9559
diff changeset
   265
    have "wtl_inst i G rT s2 s1' cert mpc pc \<and> G \<turnstile> s1' <=s s1'"
kleing
parents: 9559
diff changeset
   266
      by (clarsimp intro!: cert simp add: wtl_inst_def)
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   267
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   268
    thus ?thesis by blast
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   269
  qed
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   270
  
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   271
  with pc show ?thesis by simp
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   272
qed
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   273
    
9559
kleing
parents: 9549
diff changeset
   274
kleing
parents: 9549
diff changeset
   275
lemma wtl_option_mono:
9580
kleing
parents: 9559
diff changeset
   276
"\<lbrakk>wtl_inst_option i G rT s1 s1' cert mpc pc; fits ins cert phi; 
kleing
parents: 9559
diff changeset
   277
  pc < length ins; G \<turnstile> s2 <=s s1; i = ins!pc\<rbrakk> \<Longrightarrow> 
kleing
parents: 9559
diff changeset
   278
 \<exists> s2'. wtl_inst_option (ins!pc) G rT s2 s2' cert mpc pc \<and> (G \<turnstile> s2' <=s s1')"
9559
kleing
parents: 9549
diff changeset
   279
proof -
kleing
parents: 9549
diff changeset
   280
  assume wtl:  "wtl_inst_option i G rT s1 s1' cert mpc pc" and
kleing
parents: 9549
diff changeset
   281
         fits: "fits ins cert phi" "pc < length ins"
9580
kleing
parents: 9559
diff changeset
   282
               "G \<turnstile> s2 <=s s1" "i = ins!pc"
9559
kleing
parents: 9549
diff changeset
   283
kleing
parents: 9549
diff changeset
   284
  show ?thesis
9664
4cae97480a6d open cases;
wenzelm
parents: 9594
diff changeset
   285
  proof (cases (open) "cert!pc")
9559
kleing
parents: 9549
diff changeset
   286
    case None
9580
kleing
parents: 9559
diff changeset
   287
    with wtl fits
kleing
parents: 9559
diff changeset
   288
    show ?thesis 
kleing
parents: 9559
diff changeset
   289
      by - (rule wtl_inst_mono [elimify], (simp add: wtl_inst_option_def)+)
9559
kleing
parents: 9549
diff changeset
   290
  next
kleing
parents: 9549
diff changeset
   291
    case Some
9580
kleing
parents: 9559
diff changeset
   292
    with wtl fits
9559
kleing
parents: 9549
diff changeset
   293
9580
kleing
parents: 9559
diff changeset
   294
    have G: "G \<turnstile> s2 <=s a"
9559
kleing
parents: 9549
diff changeset
   295
     by - (rule sup_state_trans, (simp add: wtl_inst_option_def)+)
kleing
parents: 9549
diff changeset
   296
kleing
parents: 9549
diff changeset
   297
    from Some wtl
9580
kleing
parents: 9559
diff changeset
   298
    have "wtl_inst i G rT a s1' cert mpc pc" by (simp add: wtl_inst_option_def)
9559
kleing
parents: 9549
diff changeset
   299
kleing
parents: 9549
diff changeset
   300
    with G fits
9580
kleing
parents: 9559
diff changeset
   301
    have "\<exists> s2'. wtl_inst (ins!pc) G rT a s2' cert mpc pc \<and> (G \<turnstile> s2' <=s s1')"
kleing
parents: 9559
diff changeset
   302
      by - (rule wtl_inst_mono, (simp add: wtl_inst_option_def)+)
9559
kleing
parents: 9549
diff changeset
   303
    
9580
kleing
parents: 9559
diff changeset
   304
    with Some G
kleing
parents: 9559
diff changeset
   305
    show ?thesis by (simp add: wtl_inst_option_def)
9559
kleing
parents: 9549
diff changeset
   306
  qed
kleing
parents: 9549
diff changeset
   307
qed
kleing
parents: 9549
diff changeset
   308
kleing
parents: 9549
diff changeset
   309
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   310
    
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   311
lemma wt_instr_imp_wtl_inst:
9580
kleing
parents: 9559
diff changeset
   312
"\<lbrakk>wt_instr (ins!pc) G rT phi max_pc pc; fits ins cert phi;
kleing
parents: 9559
diff changeset
   313
  pc < length ins; length ins = max_pc\<rbrakk> \<Longrightarrow> 
kleing
parents: 9559
diff changeset
   314
  \<exists> s. wtl_inst (ins!pc) G rT (phi!pc) s cert max_pc pc \<and> G \<turnstile> s <=s phi ! Suc pc"
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   315
proof -
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   316
  assume wt:   "wt_instr (ins!pc) G rT phi max_pc pc" 
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   317
  assume fits: "fits ins cert phi"
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   318
  assume pc:   "pc < length ins" "length ins = max_pc"
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   319
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   320
  from wt 
9580
kleing
parents: 9559
diff changeset
   321
  have app: "app (ins!pc, G, rT, phi!pc)" by (simp add: wt_instr_def)
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   322
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   323
  from wt pc
9580
kleing
parents: 9559
diff changeset
   324
  have pc': "!!pc'. pc' \<in> succs (ins!pc) pc \<Longrightarrow> pc' < length ins"
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   325
    by (simp add: wt_instr_def)
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   326
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   327
  let ?s' = "the (step (ins!pc,G, phi!pc))"
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   328
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   329
  from wt
9580
kleing
parents: 9559
diff changeset
   330
  have G: "!!pc'. pc' \<in> succs (ins!pc) pc \<Longrightarrow> G \<turnstile> ?s' <=s phi ! pc'"
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   331
    by (simp add: wt_instr_def)
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   332
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   333
  from wt fits pc
9580
kleing
parents: 9559
diff changeset
   334
  have cert: "!!pc'. \<lbrakk>pc' \<in> succs (ins!pc) pc; pc' < max_pc; pc' \<noteq> pc+1\<rbrakk> 
kleing
parents: 9559
diff changeset
   335
    \<Longrightarrow> cert!pc' \<noteq> None \<and> G \<turnstile> ?s' <=s the (cert!pc')"
9559
kleing
parents: 9549
diff changeset
   336
    by (auto dest: fitsD simp add: wt_instr_def)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   337
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   338
  show ?thesis
9580
kleing
parents: 9559
diff changeset
   339
  proof (cases "pc+1 \<in> succs (ins!pc) pc")
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   340
    case True
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   341
9580
kleing
parents: 9559
diff changeset
   342
    have "wtl_inst (ins!pc) G rT (phi!pc) ?s' cert max_pc pc \<and> G \<turnstile> ?s' <=s phi ! Suc pc" (is "?wtl \<and> ?G")
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   343
    proof 
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   344
      from True
9580
kleing
parents: 9559
diff changeset
   345
      show "G \<turnstile> ?s' <=s phi ! Suc pc"  by (simp add: G)
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   346
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   347
      from True fits app pc cert pc'
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   348
      show "?wtl"
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   349
        by (auto simp add: wtl_inst_def)
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   350
    qed
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   351
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   352
    thus ?thesis by blast
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   353
    
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   354
  next    
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   355
    let ?s'' = "the (cert ! Suc pc)"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   356
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   357
    case False
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   358
    with fits app pc cert pc'
9580
kleing
parents: 9559
diff changeset
   359
    have "wtl_inst (ins ! pc) G rT (phi ! pc) ?s'' cert max_pc pc \<and> G \<turnstile> ?s'' <=s phi ! Suc pc" 
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   360
      by (auto dest: fitsD2 simp add: wtl_inst_def)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   361
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   362
    thus ?thesis by blast
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   363
  qed
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   364
qed
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   365
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   366
  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   367
lemma wt_instr_imp_wtl_option:
9580
kleing
parents: 9559
diff changeset
   368
"\<lbrakk>fits ins cert phi; pc < length ins; wt_instr (ins!pc) G rT phi max_pc pc;  max_pc = length ins\<rbrakk> \<Longrightarrow> 
kleing
parents: 9559
diff changeset
   369
 \<exists> s. wtl_inst_option (ins!pc) G rT (phi!pc) s cert max_pc pc \<and> G \<turnstile> s <=s phi ! Suc pc"
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   370
proof -
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   371
  assume fits : "fits ins cert phi" "pc < length ins" 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   372
         and "wt_instr (ins!pc) G rT phi max_pc pc" 
9580
kleing
parents: 9559
diff changeset
   373
             "max_pc = length ins"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   374
9580
kleing
parents: 9559
diff changeset
   375
  hence * : "\<exists> s. wtl_inst (ins!pc) G rT (phi!pc) s cert max_pc pc \<and> G \<turnstile> s <=s phi ! Suc pc"
kleing
parents: 9559
diff changeset
   376
    by - (rule wt_instr_imp_wtl_inst, simp+)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   377
  
9580
kleing
parents: 9559
diff changeset
   378
  show ?thesis
kleing
parents: 9559
diff changeset
   379
  proof (cases "cert ! pc")
kleing
parents: 9559
diff changeset
   380
    case None
kleing
parents: 9559
diff changeset
   381
    with *
kleing
parents: 9559
diff changeset
   382
    show ?thesis by (simp add: wtl_inst_option_def)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   383
9580
kleing
parents: 9559
diff changeset
   384
  next
kleing
parents: 9559
diff changeset
   385
    case Some
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   386
9580
kleing
parents: 9559
diff changeset
   387
    from fits 
kleing
parents: 9559
diff changeset
   388
    have "pc < length phi" by (clarsimp simp add: fits_def)
kleing
parents: 9559
diff changeset
   389
    with fits Some
kleing
parents: 9559
diff changeset
   390
    have "cert ! pc = Some (phi!pc)" by (auto simp add: fits_def is_approx_def)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   391
     
9580
kleing
parents: 9559
diff changeset
   392
    with * 
kleing
parents: 9559
diff changeset
   393
    show ?thesis by (simp add: wtl_inst_option_def)
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   394
  qed
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   395
qed
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   396
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   397
9559
kleing
parents: 9549
diff changeset
   398
text {*
kleing
parents: 9549
diff changeset
   399
  \medskip
kleing
parents: 9549
diff changeset
   400
  Main induction over the instruction list.
kleing
parents: 9549
diff changeset
   401
*}
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   402
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   403
theorem wt_imp_wtl_inst_list:
9580
kleing
parents: 9559
diff changeset
   404
"\<forall> pc. (\<forall>pc'. pc' < length all_ins \<longrightarrow> wt_instr (all_ins ! pc') G rT phi (length all_ins) pc') \<longrightarrow>   
kleing
parents: 9559
diff changeset
   405
       fits all_ins cert phi \<longrightarrow> 
kleing
parents: 9559
diff changeset
   406
       (\<exists>l. pc = length l \<and> all_ins = l@ins) \<longrightarrow>  
kleing
parents: 9559
diff changeset
   407
       pc < length all_ins \<longrightarrow>      
kleing
parents: 9559
diff changeset
   408
       (\<forall> s. (G \<turnstile> s <=s (phi!pc)) \<longrightarrow> 
kleing
parents: 9559
diff changeset
   409
             (\<exists>s'. wtl_inst_list ins G rT s s' cert (length all_ins) pc))" 
kleing
parents: 9559
diff changeset
   410
(is "\<forall>pc. ?wt \<longrightarrow> ?fits \<longrightarrow> ?l pc ins \<longrightarrow> ?len pc \<longrightarrow> ?wtl pc ins" is "\<forall>pc. ?C pc ins" is "?P ins") 
9559
kleing
parents: 9549
diff changeset
   411
proof (induct "?P" "ins")
kleing
parents: 9549
diff changeset
   412
  case Nil
kleing
parents: 9549
diff changeset
   413
  show "?P []" by simp
kleing
parents: 9549
diff changeset
   414
next
kleing
parents: 9549
diff changeset
   415
  fix i ins'
kleing
parents: 9549
diff changeset
   416
  assume Cons: "?P ins'"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   417
9559
kleing
parents: 9549
diff changeset
   418
  show "?P (i#ins')" 
kleing
parents: 9549
diff changeset
   419
  proof (intro allI impI, elim exE conjE)
kleing
parents: 9549
diff changeset
   420
    fix pc s l
9580
kleing
parents: 9559
diff changeset
   421
    assume wt  : "\<forall>pc'. pc' < length all_ins \<longrightarrow> 
9559
kleing
parents: 9549
diff changeset
   422
                        wt_instr (all_ins ! pc') G rT phi (length all_ins) pc'"
kleing
parents: 9549
diff changeset
   423
    assume fits: "fits all_ins cert phi"
9580
kleing
parents: 9559
diff changeset
   424
    assume G   : "G \<turnstile> s <=s phi ! pc"
9559
kleing
parents: 9549
diff changeset
   425
    assume l   : "pc < length all_ins"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   426
9559
kleing
parents: 9549
diff changeset
   427
    assume pc  : "all_ins = l@i#ins'" "pc = length l"
kleing
parents: 9549
diff changeset
   428
    hence  i   : "all_ins ! pc = i"
kleing
parents: 9549
diff changeset
   429
      by (simp add: nth_append)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   430
9559
kleing
parents: 9549
diff changeset
   431
    from l wt
kleing
parents: 9549
diff changeset
   432
    have "wt_instr (all_ins!pc) G rT phi (length all_ins) pc" by blast
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   433
9559
kleing
parents: 9549
diff changeset
   434
    with fits l 
kleing
parents: 9549
diff changeset
   435
    obtain s1 where
kleing
parents: 9549
diff changeset
   436
          "wtl_inst_option (all_ins!pc) G rT (phi!pc) s1 cert (length all_ins) pc" and
9580
kleing
parents: 9559
diff changeset
   437
      s1: "G \<turnstile> s1 <=s phi ! (Suc pc)"
9559
kleing
parents: 9549
diff changeset
   438
      by - (drule wt_instr_imp_wtl_option, assumption+, simp, elim exE conjE, simp) 
kleing
parents: 9549
diff changeset
   439
    
kleing
parents: 9549
diff changeset
   440
    with fits l
kleing
parents: 9549
diff changeset
   441
    obtain s2 where
kleing
parents: 9549
diff changeset
   442
      o:  "wtl_inst_option (all_ins!pc) G rT s s2 cert (length all_ins) pc" 
9580
kleing
parents: 9559
diff changeset
   443
      and "G \<turnstile> s2 <=s s1"
9559
kleing
parents: 9549
diff changeset
   444
      by - (drule wtl_option_mono, assumption+, simp, elim exE conjE, rule that) 
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   445
9559
kleing
parents: 9549
diff changeset
   446
    with s1
9580
kleing
parents: 9559
diff changeset
   447
    have G': "G \<turnstile> s2 <=s phi ! (Suc pc)"
9559
kleing
parents: 9549
diff changeset
   448
      by - (rule sup_state_trans, auto)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   449
9559
kleing
parents: 9549
diff changeset
   450
    from Cons
kleing
parents: 9549
diff changeset
   451
    have "?C (Suc pc) ins'" by blast
kleing
parents: 9549
diff changeset
   452
    with wt fits pc
9580
kleing
parents: 9559
diff changeset
   453
    have IH: "?len (Suc pc) \<longrightarrow> ?wtl (Suc pc) ins'" by auto
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   454
9580
kleing
parents: 9559
diff changeset
   455
    show "\<exists>s'. wtl_inst_list (i#ins') G rT s s' cert (length all_ins) pc"
9559
kleing
parents: 9549
diff changeset
   456
    proof (cases "?len (Suc pc)")
kleing
parents: 9549
diff changeset
   457
      case False
kleing
parents: 9549
diff changeset
   458
      with pc
kleing
parents: 9549
diff changeset
   459
      have "ins' = []" by simp
kleing
parents: 9549
diff changeset
   460
      with i o 
kleing
parents: 9549
diff changeset
   461
      show ?thesis by auto
kleing
parents: 9549
diff changeset
   462
    next
kleing
parents: 9549
diff changeset
   463
      case True
kleing
parents: 9549
diff changeset
   464
      with IH
kleing
parents: 9549
diff changeset
   465
      have "?wtl (Suc pc) ins'" by blast
kleing
parents: 9549
diff changeset
   466
      with G'
kleing
parents: 9549
diff changeset
   467
      obtain s' where
kleing
parents: 9549
diff changeset
   468
        "wtl_inst_list ins' G rT s2 s' cert (length all_ins) (Suc pc)"
kleing
parents: 9549
diff changeset
   469
        by - (elim allE impE, auto)        
kleing
parents: 9549
diff changeset
   470
      with i o
kleing
parents: 9549
diff changeset
   471
      show ?thesis by auto
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   472
    qed
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   473
  qed
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   474
qed
9559
kleing
parents: 9549
diff changeset
   475
  
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   476
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   477
lemma fits_imp_wtl_method_complete:
9594
42d11e0a7a8b Convert.thy now in Isar, tuned
kleing
parents: 9580
diff changeset
   478
"\<lbrakk>wt_method G C pTs rT mxl ins phi; fits ins cert phi; wf_prog wf_mb G\<rbrakk> 
42d11e0a7a8b Convert.thy now in Isar, tuned
kleing
parents: 9580
diff changeset
   479
  \<Longrightarrow> wtl_method G C pTs rT mxl ins cert"
42d11e0a7a8b Convert.thy now in Isar, tuned
kleing
parents: 9580
diff changeset
   480
by (simp add: wt_method_def wtl_method_def)
42d11e0a7a8b Convert.thy now in Isar, tuned
kleing
parents: 9580
diff changeset
   481
   (rule wt_imp_wtl_inst_list [rulify, elimify], auto simp add: wt_start_def) 
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   482
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   483
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   484
lemma wtl_method_complete:
9594
42d11e0a7a8b Convert.thy now in Isar, tuned
kleing
parents: 9580
diff changeset
   485
"\<lbrakk>wt_method G C pTs rT mxl ins phi; wf_prog wf_mb G\<rbrakk> 
42d11e0a7a8b Convert.thy now in Isar, tuned
kleing
parents: 9580
diff changeset
   486
  \<Longrightarrow> wtl_method G C pTs rT mxl ins (make_cert ins phi)"
9580
kleing
parents: 9559
diff changeset
   487
proof -
kleing
parents: 9559
diff changeset
   488
  assume * : "wt_method G C pTs rT mxl ins phi" "wf_prog wf_mb G"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   489
  
9580
kleing
parents: 9559
diff changeset
   490
  hence "fits ins (make_cert ins phi) phi"
kleing
parents: 9559
diff changeset
   491
    by - (rule fits_make_cert, simp add: wt_method_def)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   492
9580
kleing
parents: 9559
diff changeset
   493
  with *
kleing
parents: 9559
diff changeset
   494
  show ?thesis by - (rule fits_imp_wtl_method_complete)
kleing
parents: 9559
diff changeset
   495
qed
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   496
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   497
lemma unique_set:
9580
kleing
parents: 9559
diff changeset
   498
"(a,b,c,d)\<in>set l \<longrightarrow> unique l \<longrightarrow> (a',b',c',d') \<in> set l \<longrightarrow> a = a' \<longrightarrow> b=b' \<and> c=c' \<and> d=d'"
kleing
parents: 9559
diff changeset
   499
  by (induct "l") auto
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   500
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   501
lemma unique_epsilon:
9580
kleing
parents: 9559
diff changeset
   502
"(a,b,c,d)\<in>set l \<longrightarrow> unique l \<longrightarrow> (\<epsilon> (a',b',c',d'). (a',b',c',d') \<in> set l \<and> a'=a) = (a,b,c,d)"
kleing
parents: 9559
diff changeset
   503
  by (auto simp add: unique_set)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   504
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   505
9580
kleing
parents: 9559
diff changeset
   506
theorem wtl_complete: "\<lbrakk>wt_jvm_prog G Phi\<rbrakk> \<Longrightarrow> wtl_jvm_prog G (make_Cert G Phi)"
kleing
parents: 9559
diff changeset
   507
proof (simp only: wt_jvm_prog_def)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   508
9580
kleing
parents: 9559
diff changeset
   509
  assume wfprog: "wf_prog (\<lambda>G C (sig,rT,maxl,b). wt_method G C (snd sig) rT maxl b (Phi C sig)) G"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   510
9580
kleing
parents: 9559
diff changeset
   511
  thus ?thesis 
kleing
parents: 9559
diff changeset
   512
  proof (simp add: wtl_jvm_prog_def wf_prog_def wf_cdecl_def wf_mdecl_def, auto)
kleing
parents: 9559
diff changeset
   513
    fix a aa ab b ac ba ad ae bb 
kleing
parents: 9559
diff changeset
   514
    assume 1 : "\<forall>(C,sc,fs,ms)\<in>set G.
kleing
parents: 9559
diff changeset
   515
             Ball (set fs) (wf_fdecl G) \<and>
kleing
parents: 9559
diff changeset
   516
             unique fs \<and>
kleing
parents: 9559
diff changeset
   517
             (\<forall>(sig,rT,mb)\<in>set ms. wf_mhead G sig rT \<and> (\<lambda>(maxl,b). wt_method G C (snd sig) rT maxl b (Phi C sig)) mb) \<and>
kleing
parents: 9559
diff changeset
   518
             unique ms \<and>
kleing
parents: 9559
diff changeset
   519
             (case sc of None \<Rightarrow> C = Object
kleing
parents: 9559
diff changeset
   520
              | Some D \<Rightarrow>
kleing
parents: 9559
diff changeset
   521
                  is_class G D \<and>
kleing
parents: 9559
diff changeset
   522
                  (D, C) \<notin> (subcls1 G)^* \<and>
kleing
parents: 9559
diff changeset
   523
                  (\<forall>(sig,rT,b)\<in>set ms. \<forall>D' rT' b'. method (G, D) sig = Some (D', rT', b') \<longrightarrow> G\<turnstile>rT\<preceq>rT'))"
kleing
parents: 9559
diff changeset
   524
             "(a, aa, ab, b) \<in> set G"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   525
  
9580
kleing
parents: 9559
diff changeset
   526
    assume uG : "unique G" 
kleing
parents: 9559
diff changeset
   527
    assume b  : "((ac, ba), ad, ae, bb) \<in> set b"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   528
9580
kleing
parents: 9559
diff changeset
   529
    from 1
kleing
parents: 9559
diff changeset
   530
    show "wtl_method G a ba ad ae bb (make_Cert G Phi a (ac, ba))"
kleing
parents: 9559
diff changeset
   531
    proof (rule bspec [elimify], clarsimp)
kleing
parents: 9559
diff changeset
   532
      assume ub : "unique b"
kleing
parents: 9559
diff changeset
   533
      assume m: "\<forall>(sig,rT,mb)\<in>set b. wf_mhead G sig rT \<and> (\<lambda>(maxl,b). wt_method G a (snd sig) rT maxl b (Phi a sig)) mb" 
kleing
parents: 9559
diff changeset
   534
      from m b
kleing
parents: 9559
diff changeset
   535
      show ?thesis
kleing
parents: 9559
diff changeset
   536
      proof (rule bspec [elimify], clarsimp)
kleing
parents: 9559
diff changeset
   537
        assume "wt_method G a ba ad ae bb (Phi a (ac, ba))"         
kleing
parents: 9559
diff changeset
   538
        with wfprog uG ub b 1
kleing
parents: 9559
diff changeset
   539
        show ?thesis
kleing
parents: 9559
diff changeset
   540
          by - (rule wtl_method_complete [elimify], assumption+, simp add: make_Cert_def unique_epsilon)
kleing
parents: 9559
diff changeset
   541
      qed 
kleing
parents: 9559
diff changeset
   542
    qed
kleing
parents: 9559
diff changeset
   543
  qed
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   544
qed
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   545
9559
kleing
parents: 9549
diff changeset
   546
lemmas [simp] = split_paired_Ex
9549
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   547
40d64cb4f4e6 BV and LBV specified in terms of app and step functions
kleing
parents: 9376
diff changeset
   548
end