src/HOL/MicroJava/BV/LBVComplete.thy
author kleing
Wed, 07 Jun 2000 17:14:19 +0200
changeset 9054 0e48e7d4d4f9
parent 9012 d1bd2144ab5d
child 9182 9c443de2ba42
permissions -rw-r--r--
minor tuning for pdf documents
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
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
     9
theory LBVComplete = LBVSpec:;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    10
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    11
ML_setup {* bind_thm ("widen_RefT", widen_RefT) *};
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    12
ML_setup {* bind_thm ("widen_RefT2", widen_RefT2) *};
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    13
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    14
constdefs
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    15
  is_approx :: "['a option list, 'a list] \\<Rightarrow> bool"
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    16
  "is_approx a b \\<equiv> length a = length b \\<and> (\\<forall> n. n < length a \\<longrightarrow>
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    17
                   (a!n = None \\<or> a!n = Some (b!n)))"
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    18
  
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    19
  contains_dead :: "[instr list, certificate, method_type, p_count] \\<Rightarrow> bool"
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    20
  "contains_dead ins cert phi pc \\<equiv>
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    21
    (((\\<exists> branch. ins!pc = BR (Goto branch)) \\<or> ins!pc = MR Return) \\<or>
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    22
     (\\<exists>mi. ins!pc = MI mi)) \\<longrightarrow> Suc pc < length phi \\<longrightarrow>
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    23
      cert ! (Suc pc) = Some (phi ! Suc pc)"
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    24
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    25
  contains_targets :: "[instr list, certificate, method_type, p_count] \\<Rightarrow> bool"
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    26
  "contains_targets ins cert phi pc \\<equiv> 
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    27
    \\<forall> branch. (ins!pc = BR (Goto branch) \\<or> ins!pc = BR (Ifcmpeq branch)) \\<longrightarrow>
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    28
        (let pc' = nat (int pc+branch) in pc' < length phi \\<longrightarrow> cert!pc' = Some (phi!pc'))" 
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    29
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    30
  fits :: "[instr list, certificate, method_type] \\<Rightarrow> bool"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    31
  "fits ins cert phi \\<equiv> is_approx cert phi \\<and> length ins < length phi \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    32
                            (\\<forall> pc. pc < length ins \\<longrightarrow>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    33
                                   contains_dead ins cert phi pc \\<and> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    34
                                   contains_targets ins cert phi pc)"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    35
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    36
  is_target :: "[instr list, p_count] \\<Rightarrow> bool" 
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    37
  "is_target ins pc \\<equiv> 
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    38
     \\<exists> pc' branch. pc' < length ins \\<and> 
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    39
                   (ins ! pc' = (BR (Ifcmpeq branch)) \\<or> ins ! pc' = (BR (Goto branch))) \\<and> 
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    40
                   pc = (nat(int pc'+branch))"
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    41
  
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    42
  maybe_dead :: "[instr list, p_count] \\<Rightarrow> bool"
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    43
  "maybe_dead ins pc \\<equiv>
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    44
     \\<exists> pc'. pc = pc'+1 \\<and> ((\\<exists> branch. ins!pc' = BR (Goto branch)) \\<or>
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    45
                          ins!pc' = MR Return \\<or>
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    46
                          (\\<exists>mi. ins!pc' = MI mi))"
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    47
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    48
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    49
  mdot :: "[instr list, p_count] \\<Rightarrow> bool"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    50
  "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
    51
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    52
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    53
consts
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    54
  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
    55
primrec 
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    56
  "option_filter_n []    P n = []"  
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    57
  "option_filter_n (h#t) P n = (if (P n) then Some h # option_filter_n t P (n+1) 
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    58
                                         else None   # option_filter_n t P (n+1))";  
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    59
  
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    60
constdefs 
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    61
  option_filter :: "['a list, nat \\<Rightarrow> bool] \\<Rightarrow> 'a option list" 
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    62
  "option_filter l P \\<equiv> option_filter_n l P 0" 
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    63
  
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    64
  make_cert :: "[instr list, method_type] \\<Rightarrow> certificate"
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    65
  "make_cert ins phi \\<equiv> option_filter phi (mdot ins)"
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    66
  
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    67
  make_Cert :: "[jvm_prog, prog_type] \\<Rightarrow> prog_certificate"
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    68
  "make_Cert G Phi \\<equiv>  \\<lambda> C sig.
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    69
    let (C,x,y,mdecls) = \\<epsilon> (Cl,x,y,mdecls). (Cl,x,y,mdecls) \\<in> set G \\<and> Cl = C in
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    70
      let (sig,rT,maxl,b) = \\<epsilon> (sg,rT,maxl,b). (sg,rT,maxl,b) \\<in> set mdecls \\<and> sg = sig in
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    71
        make_cert b (Phi C sig)";
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    72
  
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    73
constdefs
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
    74
  wfprg :: "jvm_prog \\<Rightarrow> bool"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    75
  "wfprg G \\<equiv> \\<exists>wf_mb. wf_prog wf_mb G";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    76
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    77
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    78
lemma length_ofn: "\\<forall>n. length (option_filter_n l P n) = length l";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    79
  by (induct l) auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    80
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    81
lemma is_approx_option_filter_n:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    82
"\\<forall>n. is_approx (option_filter_n a P n) a" (is "?P a");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    83
proof (induct a);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    84
  show "?P []"; by (auto simp add: is_approx_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    85
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    86
  fix l ls;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    87
  assume Cons: "?P ls";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    88
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    89
  show "?P (l#ls)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    90
  proof (unfold is_approx_def, intro allI conjI impI);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    91
    fix n;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    92
    show "length (option_filter_n (l # ls) P n) = length (l # ls)"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    93
      by (simp only: length_ofn);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    94
    
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    95
    fix m;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    96
    assume "m < length (option_filter_n (l # ls) P n)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    97
    hence m: "m < Suc (length ls)"; by (simp only: length_ofn) simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    98
 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    99
    show "option_filter_n (l # ls) P n ! m = None \\<or>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   100
          option_filter_n (l # ls) P n ! m = Some ((l # ls) ! m)"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   101
    proof (cases "m");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   102
      assume "m = 0";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   103
      with m; show ?thesis; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   104
    next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   105
      fix m'; assume Suc: "m = Suc m'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   106
      from Cons;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   107
      show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   108
      proof (unfold is_approx_def, elim allE impE conjE);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   109
        from m Suc;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   110
        show "m' < length (option_filter_n ls P (Suc n))"; by (simp add: length_ofn);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   111
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   112
        assume "option_filter_n ls P (Suc n) ! m' = None \\<or> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   113
                option_filter_n ls P (Suc n) ! m' = Some (ls ! m')";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   114
        with m Suc;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   115
        show ?thesis; by auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   116
      qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   117
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   118
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   119
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   120
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   121
lemma is_approx_option_filter: "is_approx (option_filter l P) l"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   122
  by (simp add: option_filter_def is_approx_option_filter_n);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   123
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   124
lemma option_filter_Some:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   125
"\\<lbrakk>n < length l; P n\\<rbrakk> \\<Longrightarrow> option_filter l P ! n = Some (l!n)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   126
proof -;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   127
  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   128
  assume 1: "n < length l" "P n";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   129
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   130
  have "\\<forall>n n'. n < length l \\<longrightarrow> P (n+n') \\<longrightarrow>  option_filter_n l P n' ! n = Some (l!n)"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   131
    (is "?P l");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   132
  proof (induct l);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   133
    show "?P []"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   134
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   135
    fix l ls; assume Cons: "?P ls";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   136
    show "?P (l#ls)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   137
    proof (intro);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   138
      fix n n';
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   139
      assume l: "n < length (l # ls)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   140
      assume P: "P (n + n')";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   141
      show "option_filter_n (l # ls) P n' ! n = Some ((l # ls) ! n)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   142
      proof (cases "n");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   143
        assume "n=0";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   144
        with P; show ?thesis; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   145
      next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   146
        fix m; assume "n = Suc m";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   147
        with l P Cons;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   148
        show ?thesis; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   149
      qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   150
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   151
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   152
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   153
  with 1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   154
  show ?thesis; by (auto simp add: option_filter_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   155
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   156
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   157
lemma option_filter_contains_dead:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   158
"contains_dead ins (option_filter phi (mdot ins)) phi pc"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   159
  by (auto intro: option_filter_Some simp add: contains_dead_def mdot_def maybe_dead_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   160
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   161
lemma option_filter_contains_targets:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   162
"pc < length ins \\<Longrightarrow> contains_targets ins (option_filter phi (mdot ins)) phi pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   163
proof (simp add: contains_targets_def, intro allI impI conjI); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   164
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   165
  fix branch;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   166
  assume 1: "ins ! pc = BR (Goto branch)" 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   167
            "nat (int pc + branch) < length phi"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   168
            "pc < length ins";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   169
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   170
  show "option_filter phi (mdot ins) ! nat (int pc + branch) = Some (phi ! nat (int pc + branch))";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   171
  proof (rule option_filter_Some);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   172
    from 1; show "nat (int pc + branch) < length phi"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   173
    from 1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   174
    have "is_target ins (nat (int pc + branch))"; by (auto simp add: is_target_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   175
    thus "mdot ins (nat (int pc + branch))"; by (simp add: mdot_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   176
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   177
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   178
next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   179
  fix branch;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   180
  assume 2: "ins ! pc = BR (Ifcmpeq branch)" 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   181
            "nat (int pc + branch) < length phi"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   182
            "pc < length ins";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   183
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   184
  show "option_filter phi (mdot ins) ! nat (int pc + branch) = Some (phi ! nat (int pc + branch))";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   185
  proof (rule option_filter_Some);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   186
    from 2; show "nat (int pc + branch) < length phi"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   187
    from 2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   188
    have "is_target ins (nat (int pc + branch))"; by (auto simp add: is_target_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   189
    thus "mdot ins (nat (int pc + branch))"; by (simp add: mdot_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   190
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   191
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   192
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   193
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   194
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   195
lemma fits_make_cert:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   196
  "length ins < length phi \\<Longrightarrow> fits ins (make_cert ins phi) phi";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   197
proof -;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   198
  assume l: "length ins < length phi";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   199
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   200
  thus "fits ins (make_cert ins phi) phi";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   201
  proof (unfold fits_def make_cert_def, intro conjI allI impI);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   202
    show "is_approx (option_filter phi (mdot ins)) phi"; by (rule is_approx_option_filter);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   203
    show "length ins < length phi"; .;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   204
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   205
    fix pc;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   206
    show "contains_dead ins (option_filter phi (mdot ins)) phi pc"; by (rule option_filter_contains_dead);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   207
    
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   208
    assume "pc < length ins"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   209
    thus "contains_targets ins (option_filter phi (mdot ins)) phi pc"; by (rule option_filter_contains_targets);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   210
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   211
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   212
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   213
lemma rev_surj: "\\<exists>a'. a = rev a'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   214
proof (induct "a"); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   215
  show "\\<exists>a'. [] = rev a'"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   216
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   217
  fix l ls; assume "\\<exists>a''. ls = rev a''";  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   218
  thus "\\<exists>a'. l # ls = rev a'"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   219
  proof (elim exE);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   220
    fix a''; assume "ls = rev a''";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   221
    hence "l#ls = rev (a''@[l])"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   222
    thus ?thesis; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   223
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   224
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   225
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   226
lemma append_length_n: "\\<forall>n. n \\<le> length x \\<longrightarrow> (\\<exists>a b. x = a@b \\<and> length a = n)" (is "?P x");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   227
proof (induct "?P" "x");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   228
  show "?P []"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   229
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   230
  fix l ls; assume Cons: "?P ls";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   231
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   232
  show "?P (l#ls)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   233
  proof (intro allI impI);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   234
    fix n;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   235
    assume l: "n \\<le> length (l # ls)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   236
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   237
    show "\\<exists>a b. l # ls = a @ b \\<and> length a = n"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   238
    proof (cases n);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   239
      assume "n=0"; thus ?thesis; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   240
    next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   241
      fix "n'"; assume s: "n = Suc n'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   242
      with l; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   243
      have  "n' \\<le> length ls"; by simp; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   244
      hence "\\<exists>a b. ls = a @ b \\<and> length a = n'"; by (rule Cons [rulify]);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   245
      thus ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   246
      proof elim;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   247
        fix a b; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   248
        assume "ls = a @ b" "length a = n'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   249
        with s;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   250
        have "l # ls = (l#a) @ b \\<and> length (l#a) = n"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   251
        thus ?thesis; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   252
      qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   253
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   254
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   255
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   256
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   257
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   258
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   259
lemma rev_append_cons:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   260
"\\<lbrakk>n < length x\\<rbrakk> \\<Longrightarrow> \\<exists>a b c. x = (rev a) @ b # c \\<and> length a = n";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   261
proof -;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   262
  assume n: "n < length x";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   263
  hence "n \\<le> length x"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   264
  hence "\\<exists>a b. x = a @ b \\<and> length a = n"; by (rule append_length_n [rulify]);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   265
  thus ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   266
  proof elim;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   267
    fix r d; assume x: "x = r@d" "length r = n";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   268
    with n;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   269
    have bc: "\\<exists>b c. d = b#c"; by (simp add: neq_Nil_conv);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   270
    
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   271
    have "\\<exists>a. r = rev a"; by (rule rev_surj);    
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   272
    with bc;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   273
    show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   274
    proof elim;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   275
      fix a b c; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   276
      assume "r = rev a" "d = b#c";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   277
      with x;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   278
      have "x = (rev a) @ b # c \\<and> length a = n"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   279
      thus ?thesis; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   280
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   281
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   282
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   283
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   284
lemma widen_NT: "G \\<turnstile> b \\<preceq> NT \\<Longrightarrow> b = NT";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   285
proof (cases b); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   286
  case RefT;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   287
  thus "G\\<turnstile>b\\<preceq>NT \\<Longrightarrow> b = NT"; by - (cases ref_ty, auto);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   288
qed auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   289
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   290
lemma widen_Class: "G \\<turnstile> b \\<preceq> Class C \\<Longrightarrow> \\<exists>r. b = RefT r";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   291
by (cases b) auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   292
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   293
lemma all_widen_is_sup_loc:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   294
"\\<forall>b. length a = length b \\<longrightarrow> (\\<forall>x\\<in>set (zip a b). x \\<in> widen G) = (G \\<turnstile> (map Some a) <=l (map Some b))" 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   295
 (is "\\<forall>b. length a = length b \\<longrightarrow> ?Q a b" is "?P a");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   296
proof (induct "a");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   297
  show "?P []"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   298
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   299
  fix l ls; assume Cons: "?P ls";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   300
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   301
  show "?P (l#ls)"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   302
  proof (intro allI impI);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   303
    fix b; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   304
    assume "length (l # ls) = length (b::ty list)"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   305
    with Cons;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   306
    show "?Q (l # ls) b"; by - (cases b, auto);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   307
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   308
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   309
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   310
lemma method_inv_pseudo_mono:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   311
"\\<lbrakk>fits ins cert phi; i = ins!pc; i = MI meth_inv; pc < length ins; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   312
  wf_prog wf_mb G;   G \\<turnstile> (x, y) <=s s1; wtl_inst (ins!pc) G rT s1 s1' cert mpc pc\\<rbrakk> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   313
 \\<Longrightarrow> \\<exists>s2'. wtl_inst i G rT (x, y) s2' cert mpc pc \\<and> \
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   314
          ((G \\<turnstile> s2' <=s s1') \\<or> (\\<exists> s. cert ! (Suc pc) = Some s \\<and> (G \\<turnstile> s2' <=s s)))";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   315
proof (cases meth_inv); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   316
  case Invoke; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   317
  assume fits: "fits ins cert phi" and
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   318
         i: "i = ins ! pc" "i = MI meth_inv" and
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   319
         pc: "pc < length ins" and
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   320
         wfp: "wf_prog wf_mb G" and
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   321
         "wtl_inst (ins!pc) G rT s1 s1' cert mpc pc" and
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   322
         lt: "G \\<turnstile> (x, y) <=s s1";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   323
 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   324
  with Invoke; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   325
  show ?thesis; (* (is "\\<exists>s2'. ?wtl s2' \\<and> (?lt s2' s1' \\<or> ?cert s2')" is "\\<exists>s2'. ?P s2'"); *)
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   326
  proof (clarsimp_tac simp del: split_paired_Ex);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   327
    fix apTs X  ST' y' s;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   328
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   329
    assume G: "G \\<turnstile> (x, y) <=s (rev apTs @ X # ST', y')";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   330
    assume lapTs: "length apTs = length list";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   331
    assume "cert ! Suc pc = Some s"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   332
    assume wtl: "s = s1' \\<and> X = NT \\<or>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   333
            G \\<turnstile> s1' <=s s \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   334
            (\\<exists>C. X = Class C \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   335
                 (\\<forall>x\\<in>set (zip apTs list). x \\<in> widen G) \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   336
                 (\\<exists>D rT. (\\<exists>b. method (G, C) (mname, list) = Some (D, rT, b)) \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   337
                         (rT # ST', y') = s1'))" (is "?NT \\<or> ?ClassC");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   338
    
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   339
    from G;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   340
    have "\\<exists>a b c. x = rev a @ b # c \\<and> length a = length apTs";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   341
      by - (rule rev_append_cons, simp add: sup_state_length_fst);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   342
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   343
    thus "\\<exists>s2'. (\\<exists>apTs X ST'.
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   344
                   x = rev apTs @ X # ST' \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   345
                   length apTs = length list \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   346
                   (s = s2' \\<and> X = NT \\<or>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   347
                    G \\<turnstile> s2' <=s s \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   348
                    (\\<exists>C. X = Class C \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   349
                         (\\<forall>x\\<in>set (zip apTs list). x \\<in> widen G) \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   350
                         (\\<exists>D rT. (\\<exists>b. method (G, C) (mname, list) = Some (D, rT, b)) \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   351
                                 (rT # ST', y) = s2')))) \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   352
               (G \\<turnstile> s2' <=s s1' \\<or> G \\<turnstile> s2' <=s s)" (is "\\<exists>s2'. ?P s2'"); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   353
    proof elim;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   354
      fix a b c;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   355
      assume rac: "x = rev a @ b # c"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   356
      with G;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   357
      have x: "G \\<turnstile> (rev a @ b # c, y) <=s (rev apTs @ X # ST', y')"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   358
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   359
      assume l: "length a = length apTs";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   360
      hence "length (rev a) = length (rev apTs)"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   361
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   362
      with x;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   363
      have "G \\<turnstile> (rev a, y) <=s (rev apTs, y') \\<and> G \\<turnstile> (b # c, y) <=s (X # ST', y')";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   364
        by - (rule sup_state_append_fst [elimify], blast+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   365
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   366
      hence x2: "G \\<turnstile> (a, y) <=s (apTs, y') \\<and> G \\<turnstile> b\\<preceq>X \\<and> G \\<turnstile> (c, y) <=s (ST', y')";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   367
        by (simp add: sup_state_rev_fst sup_state_Cons1);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   368
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   369
      show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   370
      proof (cases "X = NT");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   371
        case True;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   372
        with x2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   373
        have "b = NT"; by (clarsimp_tac simp add: widen_NT);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   374
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   375
        with rac l lapTs;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   376
        have "?P s"; by auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   377
        thus ?thesis; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   378
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   379
      next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   380
        case False;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   381
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   382
        with wtl; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   383
        have "\\<exists>C. X = Class C"; by clarsimp_tac;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   384
        with x2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   385
        have "\\<exists>r. b = RefT r"; by (auto simp add: widen_Class);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   386
        
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   387
        thus ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   388
        proof elim;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   389
          fix r;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   390
          assume b: "b = RefT r"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   391
          show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   392
          proof (cases r);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   393
            case NullT;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   394
            with b rac x2 l lapTs wtl False;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   395
            have "?P s"; by auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   396
            thus ?thesis; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   397
          next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   398
            case ClassT;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   399
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   400
            from False wtl;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   401
            have wtlC: "?ClassC"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   402
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   403
            with b ClassT;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   404
            show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   405
            proof (elim exE conjE);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   406
              fix C D rT body;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   407
              assume ClassC: "X = Class C";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   408
              assume zip: "\\<forall>x\\<in>set (zip apTs list). x \\<in> widen G";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   409
              assume s1': "(rT # ST', y') = s1'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   410
              assume s: "G \\<turnstile> s1' <=s s";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   411
              assume method: "method (G, C) (mname, list) = Some (D, rT, body)";  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   412
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   413
              from ClassC b ClassT x2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   414
              have "G \\<turnstile> cname \\<preceq>C C"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   415
              with method wfp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   416
              have "\\<exists>D' rT' b'. method (G, cname) (mname, list) = Some (D', rT', b') \\<and> G \\<turnstile> rT'\\<preceq>rT";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   417
                by - (rule subcls_widen_methd, blast);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   418
              
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   419
              thus ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   420
              proof elim;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   421
                fix D' rT' body';
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   422
                assume method': "method (G, cname) (mname, list) = Some (D', rT', body')" "G\\<turnstile>rT'\\<preceq>rT";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   423
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   424
                have "?P (rT'#c,y)" (is "(\\<exists> apTs X ST'. ?A apTs X ST') \\<and> ?B"); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   425
                proof (intro conjI);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   426
                  from s1' method' x2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   427
                  show "?B"; by (auto simp add: sup_state_Cons1);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   428
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   429
                  from b ClassT rac l lapTs method'; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   430
                  have "?A a (Class cname) c"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   431
                  proof (simp, intro conjI);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   432
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   433
                    from method' x2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   434
                    have s': "G \\<turnstile> (rT' # c, y) <=s (rT # ST', y')"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   435
                      by (auto simp add: sup_state_Cons1);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   436
                    from s s1';
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   437
                    have "G \\<turnstile> (rT # ST', y') <=s s"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   438
                    with s'; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   439
                    show "G \\<turnstile> (rT' # c, y) <=s s"; by (rule sup_state_trans);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   440
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   441
                    from x2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   442
                    have 1: "G \\<turnstile> map Some a <=l map Some apTs"; by (simp add: sup_state_def); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   443
                    from lapTs zip;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   444
                    have "G \\<turnstile> map Some apTs <=l map Some list"; by (simp add: all_widen_is_sup_loc);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   445
                    with 1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   446
                    have "G \\<turnstile> map Some a <=l map Some list"; by (rule sup_loc_trans);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   447
                    with l lapTs;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   448
                    show "\\<forall>x\\<in>set (zip a list). x \\<in> widen G"; by (simp add: all_widen_is_sup_loc);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   449
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   450
                  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   451
                  thus "\\<exists> apTs X ST'. ?A apTs X ST'"; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   452
                qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   453
                thus ?thesis; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   454
              qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   455
            qed;  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   456
          qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   457
        qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   458
      qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   459
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   460
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   461
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   462
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   463
lemma sup_loc_some:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   464
"\\<forall> y n. (G \\<turnstile> b <=l y) \\<longrightarrow> n < length y \\<longrightarrow> y!n = Some t \\<longrightarrow> (\\<exists>t. b!n = Some t \\<and> (G \\<turnstile> (b!n) <=o (y!n)))" (is "?P b");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   465
proof (induct "?P" b);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   466
  show "?P []"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   467
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   468
  case Cons;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   469
  show "?P (a#list)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   470
  proof (clarsimp_tac simp add: list_all2_Cons1 sup_loc_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   471
    fix z zs n;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   472
    assume * : 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   473
      "G \\<turnstile> a <=o z" "list_all2 (sup_ty_opt G) list zs" 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   474
      "n < Suc (length zs)" "(z # zs) ! n = Some t";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   475
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   476
    show "(\\<exists>t. (a # list) ! n = Some t) \\<and> G \\<turnstile>(a # list) ! n <=o Some t"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   477
    proof (cases n); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   478
      case 0;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   479
      with *; show ?thesis; by (simp add: sup_ty_opt_some);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   480
    next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   481
      case Suc;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   482
      with Cons *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   483
      show ?thesis; by (simp add: sup_loc_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   484
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   485
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   486
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   487
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   488
lemma mono_load: 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   489
"\\<lbrakk>G \\<turnstile> (a, b) <=s (x, y); n < length y; y!n = Some t\\<rbrakk> \\<Longrightarrow> \\<exists>ts. b!n = Some ts \\<and> G \\<turnstile> (ts#a, b) <=s (t#x, y)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   490
proof (clarsimp_tac simp add: sup_state_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   491
  assume "G  \\<turnstile> b <=l y" "n < length y" "y!n = Some t";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   492
  thus "\\<exists>ts. b ! n = Some ts \\<and> G\\<turnstile>ts\\<preceq>t";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   493
   by (rule sup_loc_some [rulify, elimify], clarsimp_tac);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   494
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   495
  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   496
lemma mono_store:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   497
"\\<lbrakk>G \\<turnstile> (a, b) <=s (ts # ST', y); n < length y\\<rbrakk> \\<Longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   498
  \\<exists> t a'. a = t#a' \\<and> G \\<turnstile> (a', b[n := Some t]) <=s (ST', y[n := Some ts])";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   499
proof (clarsimp_tac simp add: sup_state_def sup_loc_Cons2);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   500
  fix Y YT';
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   501
  assume * : "n < length y" "G \\<turnstile> b <=l y" "G \\<turnstile>Y <=o Some ts" "G \\<turnstile> YT' <=l map Some ST'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   502
  assume "map Some a = Y # YT'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   503
  hence "map Some (tl a) = YT' \\<and> Some (hd a) = Y \\<and> (\\<exists>y yt. a = y # yt)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   504
    by (rule map_hd_tl);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   505
  with *; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   506
  show "\\<exists>t a'. a = t # a' \\<and> G \\<turnstile> map Some a' <=l map Some ST' \\<and> G \\<turnstile> b[n := Some t] <=l y[n := Some ts]";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   507
    by (clarsimp_tac simp add: sup_loc_update);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   508
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   509
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   510
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   511
lemma PrimT_PrimT: "(G \\<turnstile> xb \\<preceq> PrimT p) = (xb = PrimT p)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   512
proof;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   513
  show "xb = PrimT p \\<Longrightarrow> G \\<turnstile> xb \\<preceq> PrimT p"; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   514
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   515
  show "G\\<turnstile> xb \\<preceq> PrimT p \\<Longrightarrow> xb = PrimT p";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   516
  proof (cases xb); print_cases;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   517
    fix prim;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   518
    assume "xb = PrimT prim" "G\\<turnstile>xb\\<preceq>PrimT p";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   519
    thus ?thesis; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   520
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   521
    fix ref;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   522
    assume "G\\<turnstile>xb\\<preceq>PrimT p" "xb = RefT ref";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   523
    thus ?thesis; by simp (rule widen_RefT [elimify], auto);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   524
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   525
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   526
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   527
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   528
lemma wtl_inst_pseudo_mono:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   529
"\\<lbrakk>wtl_inst i G rT s1 s1' cert mpc pc; fits ins cert phi; pc < length ins; wf_prog wf_mb G; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   530
  G \\<turnstile> s2 <=s s1; i = ins!pc\\<rbrakk> \\<Longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   531
 \\<exists> s2'. wtl_inst (ins!pc) G rT s2 s2' cert mpc pc \\<and> (G \\<turnstile> s2' <=s s1' \\<or> (\\<exists>s. cert!(Suc pc) = Some s \\<and> G \\<turnstile> s2' <=s s))";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   532
proof (simp only:);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   533
  assume 1 : "wtl_inst (ins ! pc) G rT s1 s1' cert mpc pc" "G \\<turnstile> s2 <=s s1" "pc < length ins";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   534
  assume 2 : "fits ins cert phi" "wf_prog wf_mb G" "i = ins!pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   535
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   536
  have 3: "\\<exists> a b. s2 = (a,b)"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   537
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   538
  show ?thesis; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   539
  proof (cases "ins ! pc");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   540
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   541
    case LS;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   542
    show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   543
    proof (cases "load_and_store");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   544
      case Load;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   545
      with LS 1 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   546
      show ?thesis; by (elim, clarsimp_tac) (rule mono_load [elimify], auto simp add: sup_state_length_snd);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   547
    next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   548
      case Store;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   549
      with LS 1 3; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   550
      show ?thesis; by (elim, clarsimp_tac) (rule mono_store [elimify], auto simp add: sup_state_length_snd);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   551
    next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   552
      case Bipush;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   553
      with LS 1 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   554
      show ?thesis; by (elim, clarsimp_tac simp add: sup_state_Cons1);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   555
    next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   556
      case Aconst_null;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   557
      with LS 1 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   558
      show ?thesis; by (elim, clarsimp_tac simp add: sup_state_Cons1);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   559
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   560
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   561
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   562
    case CO;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   563
    show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   564
    proof (cases create_object);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   565
      case New;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   566
      with CO 1 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   567
      show ?thesis; by (elim, clarsimp_tac simp add: sup_state_Cons1);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   568
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   569
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   570
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   571
    case MO;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   572
    show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   573
    proof (cases manipulate_object);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   574
      case Getfield;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   575
      with MO 1 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   576
      show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   577
      proof (elim, clarsimp_tac simp add: sup_state_Cons2);       
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   578
        fix oT x;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   579
        assume "G \\<turnstile> x \\<preceq> oT" "G \\<turnstile> oT \\<preceq> Class cname"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   580
        show "G \\<turnstile> x \\<preceq> Class cname"; by (rule widen_trans);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   581
      qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   582
    next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   583
      case Putfield;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   584
      with MO 1 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   585
      show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   586
      proof (elim, clarsimp_tac simp add: sup_state_Cons2);       
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   587
        fix x xa vT oT T;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   588
        assume "G \\<turnstile> x \\<preceq> vT" "G \\<turnstile> vT \\<preceq> T";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   589
        hence * : "G \\<turnstile> x \\<preceq> T"; by (rule widen_trans);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   590
        
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   591
        assume "G \\<turnstile> xa \\<preceq> oT" "G \\<turnstile> oT \\<preceq> Class cname"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   592
        hence "G \\<turnstile> xa \\<preceq> Class cname"; by (rule widen_trans);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   593
        
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   594
        with *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   595
        show "(G \\<turnstile> xa \\<preceq> Class cname) \\<and> (G \\<turnstile> x \\<preceq> T)"; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   596
      qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   597
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   598
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   599
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   600
    case CH;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   601
    show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   602
    proof (cases check_object);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   603
      case Checkcast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   604
      with CH 1 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   605
      show ?thesis; by (elim, clarsimp_tac simp add: sup_state_Cons2) (rule widen_RefT2);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   606
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   607
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   608
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   609
    case MI;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   610
    with 1 2 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   611
    show ?thesis; by elim (rule method_inv_pseudo_mono [elimify], simp+); 
8388
b66d3c49cb8d completeness of the lightweight bytecode verifier
kleing
parents:
diff changeset
   612
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   613
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   614
    case MR;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   615
    show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   616
    proof (cases meth_ret);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   617
      case Return;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   618
      with MR 1 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   619
      show ?thesis; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   620
      proof (elim, clarsimp_tac simp add: sup_state_Cons2 simp del: split_paired_Ex);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   621
        fix x T;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   622
        assume "G\\<turnstile>x\\<preceq>T" "G\\<turnstile>T\\<preceq>rT";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   623
        thus "G\\<turnstile>x\\<preceq>rT"; by (rule widen_trans);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   624
      qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   625
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   626
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   627
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   628
    case OS;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   629
    with 1 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   630
    show ?thesis; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   631
      by - (cases op_stack, (elim, clarsimp_tac simp add: sup_state_Cons2)+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   632
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   633
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   634
    case BR;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   635
    show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   636
    proof (cases branch);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   637
      case Goto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   638
      with BR 1 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   639
      show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   640
      proof (elim, clarsimp_tac simp del: split_paired_Ex);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   641
        fix a b x y;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   642
        assume "G \\<turnstile> (a, b) <=s s1" "G \\<turnstile> s1 <=s (x, y)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   643
        thus "G \\<turnstile> (a, b) <=s (x, y)"; by (rule sup_state_trans);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   644
      qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   645
    next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   646
      case Ifcmpeq;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   647
      with BR 1 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   648
      show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   649
      proof (elim, clarsimp_tac simp add: sup_state_Cons2, intro conjI);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   650
        fix xt' b ST' y c d;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   651
        assume "G \\<turnstile> (xt', b) <=s (ST', y)" "G \\<turnstile> (ST', y) <=s (c, d)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   652
        thus "G \\<turnstile> (xt', b) <=s (c, d)"; by (rule sup_state_trans);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   653
      next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   654
        fix ts ts' x xa;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   655
        assume * :
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   656
        "(\\<exists>p. ts = PrimT p \\<and> ts' = PrimT p) \\<or> (\\<exists>r. ts = RefT r) \\<and> (\\<exists>r'. ts' = RefT r')";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   657
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   658
        assume x: "G\\<turnstile>x\\<preceq>ts" "G\\<turnstile>xa\\<preceq>ts'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   659
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   660
        show "(\\<exists>p. x = PrimT p \\<and> xa = PrimT p) \\<or> (\\<exists>r. x = RefT r) \\<and> (\\<exists>r'. xa = RefT r')"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   661
        proof (cases x);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   662
          case PrimT;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   663
          with * x;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   664
          show ?thesis; by (auto simp add: PrimT_PrimT);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   665
        next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   666
          case RefT;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   667
          hence 1: "\\<exists>r. x = RefT r"; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   668
          
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   669
          have "\\<exists>r'. xa = RefT r'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   670
          proof (cases xa); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   671
            case PrimT;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   672
            with RefT * x;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   673
            have "False"; by auto (rule widen_RefT [elimify], auto); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   674
            thus ?thesis; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   675
          qed blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   676
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   677
          with 1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   678
          show ?thesis; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   679
        qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   680
      qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   681
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   682
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   683
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   684
 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   685
lemma wtl_inst_last_mono:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   686
"\\<lbrakk>wtl_inst i G rT s1 s1' cert (Suc pc) pc; G \\<turnstile> s2 <=s s1\\<rbrakk> \\<Longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   687
 \\<exists>s2'. wtl_inst i G rT s2 s2' cert (Suc pc) pc \\<and> (G \\<turnstile> s2' <=s s1')";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   688
proof -;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   689
  assume * : "wtl_inst i G rT s1 s1' cert (Suc pc) pc" "G \\<turnstile> s2 <=s s1";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   690
  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   691
  show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   692
  proof (cases i);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   693
    case LS; with *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   694
    show ?thesis; by - (cases load_and_store, simp+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   695
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   696
    case CO; with *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   697
    show ?thesis; by - (cases create_object, simp);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   698
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   699
    case MO; with *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   700
    show ?thesis; by - (cases manipulate_object, simp+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   701
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   702
    case CH; with *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   703
    show ?thesis; by - (cases check_object, simp);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   704
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   705
    case MI; with *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   706
    show ?thesis; by - (cases meth_inv, simp);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   707
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   708
    case OS; with *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   709
    show ?thesis; by - (cases op_stack, simp+); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   710
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   711
    case MR; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   712
    show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   713
    proof (cases meth_ret);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   714
      case Return; with MR *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   715
      show ?thesis; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   716
        by (clarsimp_tac simp del: split_paired_Ex simp add: sup_state_Cons2)
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   717
           (rule widen_trans, blast+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   718
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   719
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   720
    case BR;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   721
    show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   722
    proof (cases branch);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   723
      case Ifcmpeq; with BR *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   724
      show ?thesis; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   725
    next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   726
      case Goto; with BR *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   727
      show ?thesis;  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   728
      by (clarsimp_tac simp del: split_paired_Ex simp add: sup_state_Cons2)
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   729
         (rule sup_state_trans, blast+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   730
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   731
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   732
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   733
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   734
lemma wtl_option_last_mono:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   735
"\\<lbrakk>wtl_inst_option i G rT s1 s1' cert mpc pc; mpc = Suc pc; G \\<turnstile> s2 <=s s1\\<rbrakk> \\<Longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   736
 \\<exists>s2'. wtl_inst_option i G rT s2 s2' cert mpc pc \\<and> (G \\<turnstile> s2' <=s s1')";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   737
proof (simp only: ); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   738
  assume G: "G \\<turnstile> s2 <=s s1";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   739
  assume w: "wtl_inst_option i G rT s1 s1' cert (Suc pc) pc"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   740
  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   741
  show "\\<exists>s2'. wtl_inst_option i G rT s2 s2' cert (Suc pc) pc \\<and> (G \\<turnstile> s2' <=s s1')";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   742
  proof (cases "cert!pc");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   743
    case None;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   744
    with G w;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   745
    show ?thesis; by (simp add: wtl_inst_option_def wtl_inst_last_mono del: split_paired_Ex); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   746
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   747
    case Some;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   748
    with G w;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   749
    have o: "G \\<turnstile> s1 <=s a \\<and> wtl_inst i G rT a s1' cert (Suc pc) pc"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   750
      by (simp add: wtl_inst_option_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   751
    hence w' : "wtl_inst i G rT a s1' cert (Suc pc) pc"; ..;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   752
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   753
    from o G;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   754
    have G' : "G \\<turnstile> s2 <=s a"; by - (rule sup_state_trans, blast+); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   755
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   756
    from o;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   757
    have "\\<exists>s2'. wtl_inst i G rT a s2' cert (Suc pc) pc \\<and> G \\<turnstile> s2' <=s s1'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   758
      by elim (rule wtl_inst_last_mono, auto);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   759
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   760
    with Some w G';
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   761
    show ?thesis; by (auto simp add: wtl_inst_option_def);  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   762
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   763
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   764
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   765
lemma wt_instr_imp_wtl_inst:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   766
"\\<lbrakk>wt_instr (ins!pc) G rT phi max_pc pc; fits ins cert phi;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   767
  pc < length ins; length ins = max_pc\\<rbrakk> \\<Longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   768
  \\<exists> s. wtl_inst (ins!pc) G rT (phi!pc) s cert max_pc pc \\<and> G \\<turnstile> s <=s phi ! Suc pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   769
proof -;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   770
  assume * : "wt_instr (ins!pc) G rT phi max_pc pc" "fits ins cert phi"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   771
             "pc < length ins" "length ins = max_pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   772
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   773
  have xy: "\\<exists> x y. phi!pc = (x,y)"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   774
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   775
  show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   776
  proof (cases "ins!pc");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   777
    case LS; with * xy;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   778
    show ?thesis; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   779
      by - (cases load_and_store, (elim, force simp add: wt_instr_def)+); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   780
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   781
    case CO; with * xy;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   782
    show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   783
      by - (cases create_object, (elim, force simp add: wt_instr_def)+); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   784
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   785
    case MO; with * xy;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   786
    show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   787
      by - (cases manipulate_object, (elim, force simp add: wt_instr_def)+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   788
  next; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   789
    case CH; with * xy;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   790
    show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   791
      by - (cases check_object, (elim, force simp add: wt_instr_def)+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   792
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   793
    case OS; with * xy;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   794
    show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   795
      by - (cases op_stack, (elim, force simp add: wt_instr_def)+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   796
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   797
    case MR; with * xy;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   798
    show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   799
    by - (cases meth_ret, elim, 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   800
      clarsimp_tac simp add: wt_instr_def fits_def contains_dead_def simp del: split_paired_Ex);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   801
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   802
    case BR; with * xy;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   803
    show ?thesis; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   804
      by - (cases branch,
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   805
           (clarsimp_tac simp add: wt_instr_def fits_def contains_dead_def contains_targets_def 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   806
                         simp del: split_paired_Ex)+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   807
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   808
    case MI;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   809
    show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   810
    proof (cases meth_inv);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   811
      case Invoke;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   812
      with MI * xy;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   813
      show ?thesis; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   814
      proof (elim, clarsimp_tac simp add: wt_instr_def simp del: split_paired_Ex);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   815
        fix y apTs X ST'; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   816
        assume pc : "Suc pc < length ins"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   817
        assume phi : "phi ! pc = (rev apTs @ X # ST', y)" "length apTs = length list";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   818
        assume ** :
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   819
               "X = NT \\<or> (\\<exists>C. X = Class C \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   820
               (\\<forall>x\\<in>set (zip apTs list). x \\<in> widen G) \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   821
               (\\<exists>D rT. (\\<exists>b. method (G, C) (mname, list) = Some (D, rT, b)) \\<and> G \\<turnstile> (rT # ST', y) <=s phi ! Suc pc))"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   822
               (is "?NT \\<or> ?CL"); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   823
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   824
        
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   825
        from MI Invoke pc *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   826
        have cert: "cert ! Suc pc = Some (phi ! Suc pc)"; by (clarsimp_tac simp add: fits_def contains_dead_def); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   827
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   828
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   829
        show "\\<exists>s. (\\<exists>apTsa Xa ST'a.
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   830
                 rev apTs @ X # ST' = rev apTsa @ Xa # ST'a \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   831
                 length apTsa = length list \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   832
                 (\\<exists>s''. cert ! Suc pc = Some s'' \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   833
                        (s'' = s \\<and> Xa = NT \\<or>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   834
                         G \\<turnstile> s <=s s'' \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   835
                         (\\<exists>C. Xa = Class C \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   836
                              (\\<forall>x\\<in>set (zip apTsa list). x \\<in> widen G) \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   837
                              (\\<exists>D rT. (\\<exists>b. method (G, C) (mname, list) = Some (D, rT, b)) \\<and> (rT # ST'a, y) = s))))) \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   838
               G \\<turnstile> s <=s phi ! Suc pc" (is "\\<exists>s. ?P s");  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   839
        proof (cases "X=NT"); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   840
          case True;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   841
          with cert phi **;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   842
          have "?P (phi ! Suc pc)"; by (force simp del: split_paired_Ex);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   843
          thus ?thesis; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   844
        next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   845
          case False;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   846
          with **;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   847
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   848
          have "?CL"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   849
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   850
          thus ?thesis; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   851
          proof (elim exE conjE);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   852
            fix C D rT b;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   853
            assume "X = Class C" "\\<forall>x\\<in>set (zip apTs list). x \\<in> widen G" 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   854
                   "G \\<turnstile> (rT # ST', y) <=s phi ! Suc pc"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   855
                   "method (G, C) (mname, list) = Some (D, rT, b)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   856
            with cert phi;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   857
            have "?P (rT #ST', y)"; by (force simp del: split_paired_Ex); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   858
            thus ?thesis; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   859
          qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   860
        qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   861
      qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   862
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   863
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   864
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   865
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   866
  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   867
lemma wt_instr_imp_wtl_option:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   868
"\\<lbrakk>fits ins cert phi; pc < length ins; wt_instr (ins!pc) G rT phi max_pc pc;  max_pc = length ins\\<rbrakk> \\<Longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   869
 \\<exists> s. wtl_inst_option (ins!pc) G rT (phi!pc) s cert max_pc pc \\<and> G \\<turnstile> s <=s phi ! Suc pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   870
proof -;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   871
  assume fits : "fits ins cert phi" "pc < length ins" 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   872
         and "wt_instr (ins!pc) G rT phi max_pc pc" 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   873
             "max_pc = length ins";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   874
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   875
  hence * : "\\<exists> s. wtl_inst (ins!pc) G rT (phi!pc) s cert max_pc pc \\<and> G \\<turnstile> s <=s phi ! Suc pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   876
    by - (rule wt_instr_imp_wtl_inst, simp+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   877
  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   878
  show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   879
  proof (cases "cert ! pc");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   880
    case None;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   881
    with *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   882
    show ?thesis; by (simp add: wtl_inst_option_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   883
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   884
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   885
    case Some;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   886
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   887
    from fits; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   888
    have "pc < length phi"; by (clarsimp_tac simp add: fits_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   889
    with fits Some;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   890
    have "cert ! pc = Some (phi!pc)"; by (auto simp add: fits_def is_approx_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   891
     
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   892
    with *; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   893
    show ?thesis; by (simp add: wtl_inst_option_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   894
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   895
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   896
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   897
(* not needed 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   898
lemma wtl_inst_list_s:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   899
"\\<lbrakk>wtl_inst_list ins G rT s0 s' cert max_pc pc; ins \\<noteq> []; G \\<turnstile> s <=s s0; s \\<noteq> s0 \\<longrightarrow> cert ! pc = Some s0\\<rbrakk> \\<Longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   900
  wtl_inst_list ins G rT s s' cert max_pc pc";  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   901
proof -;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   902
  assume * : "wtl_inst_list ins G rT s0 s' cert max_pc pc" 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   903
             "ins \\<noteq> []" "G \\<turnstile> s <=s s0" 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   904
             "s \\<noteq> s0 \\<longrightarrow> cert ! pc = Some s0";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   905
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   906
  show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   907
  proof (cases ins);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   908
    case Nil;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   909
    with *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   910
    show ?thesis; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   911
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   912
    case Cons;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   913
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   914
    show ?thesis; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   915
    proof (cases "list = []");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   916
      case True;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   917
      with Cons *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   918
      show ?thesis; by - (cases "s = s0", (simp add: wtl_inst_option_def)+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   919
    next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   920
      case False;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   921
      with Cons *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   922
      show ?thesis; by (force simp add: wtl_inst_option_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   923
    qed; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   924
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   925
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   926
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   927
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   928
lemma wtl_inst_list_cert:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   929
"\\<lbrakk>wtl_inst_list ins G rT s0 s' cert max_pc pc; ins \\<noteq> []; G \\<turnstile> s <=s s0; cert ! pc = Some s0\\<rbrakk> \\<Longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   930
  wtl_inst_list ins G rT s s' cert max_pc pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   931
by (cases ins) (force simp add: wtl_inst_option_def)+;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   932
*)
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   933
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   934
lemma wtl_option_pseudo_mono:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   935
"\\<lbrakk>wtl_inst_option i G rT s1 s1' cert mpc pc;  fits ins cert phi; pc < length ins; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   936
  wf_prog wf_mb G; G \\<turnstile> s2 <=s s1; i = ins!pc\\<rbrakk> \\<Longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   937
 \\<exists> s2'. wtl_inst_option (ins!pc) G rT s2 s2' cert mpc pc \\<and> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   938
        (G \\<turnstile> s2' <=s s1' \\<or> (\\<exists>s. cert!(Suc pc) = Some s \\<and> G \\<turnstile> s2' <=s s))";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   939
proof -;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   940
  assume wtl:  "wtl_inst_option i G rT s1 s1' cert mpc pc" and
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   941
         fits: "fits ins cert phi" "pc < length ins"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   942
               "wf_prog wf_mb G" "G \\<turnstile> s2 <=s s1" "i = ins!pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   943
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   944
  show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   945
  proof (cases "cert!pc");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   946
    case None;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   947
    with wtl fits;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   948
    show ?thesis; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   949
      by - (rule wtl_inst_pseudo_mono [elimify], (simp add: wtl_inst_option_def)+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   950
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   951
    case Some;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   952
    with wtl fits;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   953
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   954
    have G: "G \\<turnstile> s2 <=s a";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   955
     by - (rule sup_state_trans, (simp add: wtl_inst_option_def)+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   956
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   957
    from Some wtl;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   958
    have "wtl_inst i G rT a s1' cert mpc pc"; by (simp add: wtl_inst_option_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   959
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   960
    with G fits;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   961
    have "\\<exists> s2'. wtl_inst (ins!pc) G rT a s2' cert mpc pc \\<and> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   962
                 (G \\<turnstile> s2' <=s s1' \\<or> (\\<exists>s. cert!(Suc pc) = Some s \\<and> G \\<turnstile> s2' <=s s))";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   963
      by - (rule wtl_inst_pseudo_mono, (simp add: wtl_inst_option_def)+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   964
    
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   965
    with Some G;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   966
    show ?thesis; by (simp add: wtl_inst_option_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   967
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   968
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   969
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   970
lemma append_cons_length_nth: "((l @ a # list) ! length l) = a"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   971
  by (induct l, auto);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   972
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   973
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   974
(* main induction over instruction list *)
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   975
theorem wt_imp_wtl_inst_list:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   976
"\\<forall> pc. (\\<forall>pc'. pc' < length ins \\<longrightarrow> wt_instr (ins ! pc') G rT phi (pc+length ins) (pc+pc')) \\<longrightarrow>   
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   977
       wf_prog wf_mb G \\<longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   978
       fits all_ins cert phi \\<longrightarrow> (\\<exists> l. pc = length l \\<and> all_ins=l@ins) \\<longrightarrow> pc < length all_ins \\<longrightarrow>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   979
       (\\<forall> s. (G \\<turnstile> s <=s (phi!pc)) \\<longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   980
       (\\<exists>s'. wtl_inst_list ins G rT s s' cert (pc+length ins) pc))" 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   981
(is "\\<forall>pc. ?C pc ins" is "?P ins");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   982
proof (induct "?P" "ins");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   983
  case Nil;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   984
  show "?P []"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   985
next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   986
  case Cons;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   987
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   988
  show "?P (a#list)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   989
  proof (intro allI impI, elim exE conjE);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   990
    fix pc s l;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   991
    assume 1: "wf_prog wf_mb G" "fits all_ins cert phi";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   992
    assume 2: "pc < length all_ins" "G \\<turnstile> s <=s phi ! pc"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   993
              "all_ins = l @ a # list" "pc = length l";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   994
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   995
    from Cons;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   996
    have IH: "?C (Suc pc) list"; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   997
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   998
    assume 3: "\\<forall>pc'. pc' < length (a # list) \\<longrightarrow>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   999
               wt_instr ((a # list) ! pc') G rT phi (pc + length (a # list)) (pc + pc')";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1000
    hence 4: "\\<forall>pc'. pc' < length list \\<longrightarrow>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1001
              wt_instr (list ! pc') G rT phi (Suc pc + length list) (Suc pc + pc')"; by auto;    
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1002
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1003
    from 2; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1004
    have 5: "a = all_ins ! pc"; by (simp add: append_cons_length_nth);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1005
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1006
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1007
    show "\\<exists>s'. wtl_inst_list (a # list) G rT s s' cert (pc + length (a # list)) pc"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1008
    proof (cases list);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1009
      case Nil;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1010
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1011
      with 1 2 3 5; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1012
      have "\\<exists>s'. wtl_inst_option a G rT (phi ! pc) s' cert (Suc (length l)) pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1013
        by - (rule wt_instr_imp_wtl_option [elimify], force+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1014
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1015
      with Nil 1 2 5;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1016
      have "\\<exists>s'. wtl_inst_option a G rT s s' cert (Suc (length l)) pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1017
        by elim (rule wtl_option_pseudo_mono [elimify], force+); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1018
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1019
      with Nil 2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1020
      show ?thesis; by auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1021
    next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1022
      fix i' ins'; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1023
      assume Cons2: "list = i' # ins'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1024
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1025
      with IH 1 2 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1026
      have * : "\\<forall> s. (G \\<turnstile> s <=s (phi!(Suc pc))) \\<longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1027
                     (\\<exists>s'. wtl_inst_list list G rT s s' cert ((Suc pc)+length list) (Suc pc))";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1028
        by (elim impE) force+;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1029
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1030
      from 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1031
      have "wt_instr a G rT phi (pc + length (a # list)) pc"; by auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1032
      
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1033
      with 1 2 5;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1034
      have "\\<exists>s1'. wtl_inst_option a G rT (phi!pc) s1' cert (Suc (pc + length list)) pc \\<and> G \\<turnstile> s1' <=s phi ! Suc pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1035
        by - (rule wt_instr_imp_wtl_option [elimify], assumption+, simp+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1036
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1037
      hence "\\<exists>s1. wtl_inst_option a G rT s s1 cert (Suc (pc + length list)) pc \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1038
                  (G \\<turnstile> s1 <=s (phi ! (Suc pc)) \\<or> (\\<exists>s. cert ! Suc pc = Some s \\<and> G \\<turnstile> s1 <=s s))";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1039
      proof elim; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1040
        fix s1';
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1041
        assume "wtl_inst_option a G rT (phi!pc) s1' cert (Suc (pc + length list)) pc" and
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1042
            a :"G \\<turnstile> s1' <=s phi ! Suc pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1043
        with 1 2 5;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1044
        have "\\<exists>s1. wtl_inst_option a G rT s s1 cert (Suc (pc + length list)) pc \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1045
                   ((G \\<turnstile> s1 <=s s1') \\<or> (\\<exists>s. cert ! Suc pc = Some s \\<and> G \\<turnstile> s1 <=s s))";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1046
          by - (rule wtl_option_pseudo_mono [elimify], simp+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1047
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1048
        with a;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1049
        show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1050
        proof (elim, intro);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1051
          fix s1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1052
          assume "G \\<turnstile> s1 <=s s1'" "G \\<turnstile> s1' <=s phi ! Suc pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1053
          show "G \\<turnstile> s1 <=s phi ! Suc pc"; by (rule sup_state_trans);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1054
        qed auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1055
      qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1056
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1057
      thus ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1058
      proof (elim exE conjE); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1059
        fix s1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1060
        assume wto: "wtl_inst_option a G rT s s1 cert (Suc (pc + length list)) pc"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1061
        assume Gs1: "G \\<turnstile> s1 <=s phi ! Suc pc \\<or> (\\<exists>s. cert ! Suc pc = Some s \\<and> G \\<turnstile> s1 <=s s)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1062
        
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1063
        have "\\<exists>s'. wtl_inst_list list G rT s1 s' cert ((Suc pc)+length list) (Suc pc)"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1064
        proof (cases "G \\<turnstile> s1 <=s phi ! Suc pc");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1065
          case True;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1066
          with Gs1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1067
          have "G \\<turnstile> s1 <=s phi ! Suc pc"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1068
          with *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1069
          show ?thesis; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1070
        next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1071
          case False;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1072
          with Gs1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1073
          have "\\<exists>c. cert ! Suc pc = Some c \\<and> G \\<turnstile> s1 <=s c"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1074
          thus ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1075
          proof elim;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1076
            from 1 2 Cons Cons2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1077
            have "Suc pc < length phi";  by (clarsimp_tac simp add: fits_def is_approx_def); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1078
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1079
            with 1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1080
            have cert: "cert ! (Suc pc) = None \\<or> cert ! (Suc pc) = Some (phi ! Suc pc)"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1081
              by (clarsimp_tac simp add: fits_def is_approx_def); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1082
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1083
            fix c;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1084
            assume "cert ! Suc pc = Some c"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1085
            with cert;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1086
            have c: "c = phi ! Suc pc"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1087
            assume "G \\<turnstile> s1 <=s c";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1088
            with c;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1089
            have "G \\<turnstile> s1 <=s phi ! Suc pc"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1090
            with *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1091
            show ?thesis; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1092
          qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1093
        qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1094
        with wto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1095
        show ?thesis; by (auto simp del: split_paired_Ex);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1096
      qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1097
    qed; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1098
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1099
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1100
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1101
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1102
lemma fits_imp_wtl_method_complete:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1103
"\\<lbrakk>wt_method G C pTs rT mxl ins phi; fits ins cert phi; wf_prog wf_mb G\\<rbrakk> \\<Longrightarrow> wtl_method G C pTs rT mxl ins cert";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1104
by (simp add: wt_method_def wtl_method_def del: split_paired_Ex)
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1105
   (rule wt_imp_wtl_inst_list [rulify, elimify], auto simp add: wt_start_def simp del: split_paired_Ex); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1106
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1107
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1108
lemma wtl_method_complete:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1109
"\\<lbrakk>wt_method G C pTs rT mxl ins phi; wf_prog wf_mb G\\<rbrakk> \\<Longrightarrow> wtl_method G C pTs rT mxl ins (make_cert ins phi)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1110
proof -;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1111
  assume * : "wt_method G C pTs rT mxl ins phi" "wf_prog wf_mb G";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1112
  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1113
  hence "fits ins (make_cert ins phi) phi";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1114
    by - (rule fits_make_cert, simp add: wt_method_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1115
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1116
  with *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1117
  show ?thesis; by - (rule fits_imp_wtl_method_complete);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1118
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1119
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1120
(*
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1121
Goalw[wt_jvm_prog_def, wfprg_def] "\\<lbrakk>wt_jvm_prog G Phi\\<rbrakk> \\<Longrightarrow> wfprg G";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1122
by Auto_tac;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1123
qed "wt_imp_wfprg";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1124
*)
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1125
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1126
lemma unique_set:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1127
"(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'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1128
  by (induct "l") auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1129
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1130
lemma unique_epsilon:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1131
"(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)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1132
  by (auto simp add: unique_set);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1133
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1134
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1135
theorem wtl_complete: "\\<lbrakk>wt_jvm_prog G Phi\\<rbrakk> \\<Longrightarrow> wtl_jvm_prog G (make_Cert G Phi)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1136
proof (simp only: wt_jvm_prog_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1137
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1138
  assume wfprog: "wf_prog (\\<lambda>G C (sig,rT,maxl,b). wt_method G C (snd sig) rT maxl b (Phi C sig)) G";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1139
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1140
  thus ?thesis; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1141
  proof (simp add: wtl_jvm_prog_def wf_prog_def wf_cdecl_def wf_mdecl_def, auto);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1142
    fix a aa ab b ac ba ad ae bb; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1143
    assume 1 : "\\<forall>(C,sc,fs,ms)\\<in>set G.
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1144
             Ball (set fs) (wf_fdecl G) \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1145
             unique fs \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1146
             (\\<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>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1147
             unique ms \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1148
             (case sc of None \\<Rightarrow> C = Object
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1149
              | Some D \\<Rightarrow>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1150
                  is_class G D \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1151
                  (D, C) \\<notin> (subcls1 G)^* \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1152
                  (\\<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'))"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1153
             "(a, aa, ab, b) \\<in> set G";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1154
  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1155
    assume uG : "unique G"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1156
    assume b  : "((ac, ba), ad, ae, bb) \\<in> set b";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1157
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1158
    from 1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1159
    show "wtl_method G a ba ad ae bb (make_Cert G Phi a (ac, ba))";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1160
    proof (rule bspec [elimify], clarsimp_tac);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1161
      assume ub : "unique b";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1162
      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"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1163
      from m b;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1164
      show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1165
      proof (rule bspec [elimify], clarsimp_tac);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1166
        assume "wt_method G a ba ad ae bb (Phi a (ac, ba))";         
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1167
        with wfprog uG ub b 1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1168
        show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1169
          by - (rule wtl_method_complete [elimify], assumption+, simp add: make_Cert_def unique_epsilon);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1170
      qed; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1171
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1172
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1173
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1174
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1175
end;