src/HOL/MicroJava/BV/LBVComplete.thy
author kleing
Mon, 17 Jul 2000 14:00:53 +0200
changeset 9376 c32c5696ec2a
parent 9260 678e718a5a86
child 9549 40d64cb4f4e6
permissions -rw-r--r--
flat instruction set
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>
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
    21
    (((\\<exists> branch. ins!pc = (Goto branch)) \\<or> ins!pc = Return) \\<or>
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
    22
     (\\<exists>m l. ins!pc = Invoke m l)) \\<longrightarrow> Suc pc < length phi \\<longrightarrow>
8388
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> 
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
    27
    \\<forall> branch. (ins!pc = (Goto branch) \\<or> ins!pc = (Ifcmpeq branch)) \\<longrightarrow>
8388
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> 
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
    39
                   (ins ! pc' = (Ifcmpeq branch) \\<or> ins ! pc' = (Goto branch)) \\<and> 
8388
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>
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
    44
     \\<exists> pc'. pc = pc'+1 \\<and> ((\\<exists> branch. ins!pc' = (Goto branch)) \\<or>
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
    45
                          ins!pc' = Return \\<or>
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
    46
                          (\\<exists>m l. ins!pc' = Invoke m l))"
8388
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
  
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    73
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    74
lemma length_ofn: "\\<forall>n. length (option_filter_n l P n) = length l";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    75
  by (induct l) auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    76
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    77
lemma is_approx_option_filter_n:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    78
"\\<forall>n. is_approx (option_filter_n a P n) a" (is "?P a");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    79
proof (induct a);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    80
  show "?P []"; by (auto simp add: is_approx_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    81
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    82
  fix l ls;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    83
  assume Cons: "?P ls";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    84
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    85
  show "?P (l#ls)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    86
  proof (unfold is_approx_def, intro allI conjI impI);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    87
    fix n;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    88
    show "length (option_filter_n (l # ls) P n) = length (l # ls)"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    89
      by (simp only: length_ofn);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    90
    
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    91
    fix m;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    92
    assume "m < length (option_filter_n (l # ls) P n)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    93
    hence m: "m < Suc (length ls)"; by (simp only: length_ofn) simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    94
 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    95
    show "option_filter_n (l # ls) P n ! m = None \\<or>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    96
          option_filter_n (l # ls) P n ! m = Some ((l # ls) ! m)"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    97
    proof (cases "m");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    98
      assume "m = 0";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
    99
      with m; show ?thesis; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   100
    next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   101
      fix m'; assume Suc: "m = Suc m'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   102
      from Cons;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   103
      show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   104
      proof (unfold is_approx_def, elim allE impE conjE);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   105
        from m Suc;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   106
        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
   107
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   108
        assume "option_filter_n ls P (Suc n) ! m' = None \\<or> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   109
                option_filter_n ls P (Suc n) ! m' = Some (ls ! m')";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   110
        with m Suc;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   111
        show ?thesis; by auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   112
      qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   113
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   114
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   115
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   116
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   117
lemma is_approx_option_filter: "is_approx (option_filter l P) l"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   118
  by (simp add: option_filter_def is_approx_option_filter_n);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   119
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   120
lemma option_filter_Some:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   121
"\\<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
   122
proof -;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   123
  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   124
  assume 1: "n < length l" "P n";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   125
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   126
  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
   127
    (is "?P l");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   128
  proof (induct l);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   129
    show "?P []"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   130
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   131
    fix l ls; assume Cons: "?P ls";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   132
    show "?P (l#ls)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   133
    proof (intro);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   134
      fix n n';
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   135
      assume l: "n < length (l # ls)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   136
      assume P: "P (n + n')";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   137
      show "option_filter_n (l # ls) P n' ! n = Some ((l # ls) ! n)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   138
      proof (cases "n");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   139
        assume "n=0";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   140
        with P; show ?thesis; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   141
      next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   142
        fix m; assume "n = Suc m";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   143
        with l P Cons;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   144
        show ?thesis; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   145
      qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   146
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   147
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   148
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   149
  with 1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   150
  show ?thesis; by (auto simp add: option_filter_def);
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
lemma option_filter_contains_dead:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   154
"contains_dead ins (option_filter phi (mdot ins)) phi pc"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   155
  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
   156
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   157
lemma option_filter_contains_targets:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   158
"pc < length ins \\<Longrightarrow> contains_targets ins (option_filter phi (mdot ins)) phi pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   159
proof (simp add: contains_targets_def, intro allI impI conjI); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   160
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   161
  fix branch;
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   162
  assume 1: "ins ! pc = Goto branch" 
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   163
            "nat (int pc + branch) < length phi"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   164
            "pc < length ins";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   165
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   166
  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
   167
  proof (rule option_filter_Some);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   168
    from 1; show "nat (int pc + branch) < length phi"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   169
    from 1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   170
    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
   171
    thus "mdot ins (nat (int pc + branch))"; by (simp add: mdot_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   172
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   173
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   174
next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   175
  fix branch;
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   176
  assume 2: "ins ! pc = Ifcmpeq branch" 
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   177
            "nat (int pc + branch) < length phi"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   178
            "pc < length ins";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   179
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   180
  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
   181
  proof (rule option_filter_Some);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   182
    from 2; show "nat (int pc + branch) < length phi"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   183
    from 2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   184
    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
   185
    thus "mdot ins (nat (int pc + branch))"; by (simp add: mdot_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   186
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   187
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   188
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   189
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   190
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   191
lemma fits_make_cert:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   192
  "length ins < length phi \\<Longrightarrow> fits ins (make_cert ins phi) phi";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   193
proof -;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   194
  assume l: "length ins < length phi";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   195
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   196
  thus "fits ins (make_cert ins phi) phi";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   197
  proof (unfold fits_def make_cert_def, intro conjI allI impI);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   198
    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
   199
    show "length ins < length phi"; .;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   200
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   201
    fix pc;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   202
    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
   203
    
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   204
    assume "pc < length ins"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   205
    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
   206
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   207
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   208
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   209
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   210
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   211
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
   212
proof (induct "?P" "x");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   213
  show "?P []"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   214
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   215
  fix l ls; assume Cons: "?P ls";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   216
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   217
  show "?P (l#ls)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   218
  proof (intro allI impI);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   219
    fix n;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   220
    assume l: "n \\<le> length (l # ls)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   221
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   222
    show "\\<exists>a b. l # ls = a @ b \\<and> length a = n"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   223
    proof (cases n);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   224
      assume "n=0"; thus ?thesis; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   225
    next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   226
      fix "n'"; assume s: "n = Suc n'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   227
      with l; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   228
      have  "n' \\<le> length ls"; by simp; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   229
      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
   230
      thus ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   231
      proof elim;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   232
        fix a b; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   233
        assume "ls = a @ b" "length a = n'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   234
        with s;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   235
        have "l # ls = (l#a) @ b \\<and> length (l#a) = n"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   236
        thus ?thesis; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   237
      qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   238
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   239
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   240
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   241
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   242
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   243
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   244
lemma rev_append_cons:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   245
"\\<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
   246
proof -;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   247
  assume n: "n < length x";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   248
  hence "n \\<le> length x"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   249
  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
   250
  thus ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   251
  proof elim;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   252
    fix r d; assume x: "x = r@d" "length r = n";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   253
    with n;
9182
9c443de2ba42 tuning, eliminated rev_surj
kleing
parents: 9054
diff changeset
   254
    have "\\<exists>b c. d = b#c"; by (simp add: neq_Nil_conv);
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   255
    
9182
9c443de2ba42 tuning, eliminated rev_surj
kleing
parents: 9054
diff changeset
   256
    thus ?thesis; 
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   257
    proof elim;
9182
9c443de2ba42 tuning, eliminated rev_surj
kleing
parents: 9054
diff changeset
   258
      fix b c; 
9c443de2ba42 tuning, eliminated rev_surj
kleing
parents: 9054
diff changeset
   259
      assume "d = b#c";
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   260
      with x;
9182
9c443de2ba42 tuning, eliminated rev_surj
kleing
parents: 9054
diff changeset
   261
      have "x = (rev (rev r)) @ b # c \\<and> length (rev r) = n"; by simp;
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   262
      thus ?thesis; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   263
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   264
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   265
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   266
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   267
lemma widen_NT: "G \\<turnstile> b \\<preceq> NT \\<Longrightarrow> b = NT";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   268
proof (cases b); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   269
  case RefT;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   270
  thus "G\\<turnstile>b\\<preceq>NT \\<Longrightarrow> b = NT"; by - (cases ref_ty, auto);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   271
qed auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   272
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   273
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
   274
by (cases b) auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   275
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   276
lemma all_widen_is_sup_loc:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   277
"\\<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
   278
 (is "\\<forall>b. length a = length b \\<longrightarrow> ?Q a b" is "?P a");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   279
proof (induct "a");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   280
  show "?P []"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   281
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   282
  fix l ls; assume Cons: "?P ls";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   283
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   284
  show "?P (l#ls)"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   285
  proof (intro allI impI);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   286
    fix b; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   287
    assume "length (l # ls) = length (b::ty list)"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   288
    with Cons;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   289
    show "?Q (l # ls) b"; by - (cases b, auto);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   290
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   291
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   292
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   293
lemma method_inv_pseudo_mono:
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   294
"\\<lbrakk>fits ins cert phi; i = ins!pc; i = Invoke mname list; pc < length ins; 
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   295
  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
   296
 \\<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
   297
          ((G \\<turnstile> s2' <=s s1') \\<or> (\\<exists> s. cert ! (Suc pc) = Some s \\<and> (G \\<turnstile> s2' <=s s)))";
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   298
proof -
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   299
  assume fits: "fits ins cert phi" and
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   300
         i: "i = ins ! pc" "i = Invoke mname list" and
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   301
         pc: "pc < length ins" and
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   302
         wfp: "wf_prog wf_mb G" and
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   303
         "wtl_inst (ins!pc) G rT s1 s1' cert mpc pc" and
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   304
         lt: "G \\<turnstile> (x, y) <=s s1";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   305
 
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   306
  thus ?thesis
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   307
  proof (clarsimp_tac simp del: split_paired_Ex)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   308
    fix apTs X  ST' y' s;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   309
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   310
    assume G: "G \\<turnstile> (x, y) <=s (rev apTs @ X # ST', y')";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   311
    assume lapTs: "length apTs = length list";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   312
    assume "cert ! Suc pc = Some s"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   313
    assume wtl: "s = s1' \\<and> X = NT \\<or>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   314
            G \\<turnstile> s1' <=s s \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   315
            (\\<exists>C. X = Class C \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   316
                 (\\<forall>x\\<in>set (zip apTs list). x \\<in> widen G) \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   317
                 (\\<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
   318
                         (rT # ST', y') = s1'))" (is "?NT \\<or> ?ClassC");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   319
    
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   320
    from G;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   321
    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
   322
      by - (rule rev_append_cons, simp add: sup_state_length_fst);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   323
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   324
    thus "\\<exists>s2'. (\\<exists>apTs X ST'.
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   325
                   x = rev apTs @ X # ST' \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   326
                   length apTs = length list \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   327
                   (s = s2' \\<and> X = NT \\<or>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   328
                    G \\<turnstile> s2' <=s s \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   329
                    (\\<exists>C. X = Class C \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   330
                         (\\<forall>x\\<in>set (zip apTs list). x \\<in> widen G) \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   331
                         (\\<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
   332
                                 (rT # ST', y) = s2')))) \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   333
               (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
   334
    proof elim;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   335
      fix a b c;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   336
      assume rac: "x = rev a @ b # c"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   337
      with G;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   338
      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
   339
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   340
      assume l: "length a = length apTs";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   341
      hence "length (rev a) = length (rev apTs)"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   342
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   343
      with x;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   344
      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
   345
        by - (rule sup_state_append_fst [elimify], blast+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   346
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   347
      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
   348
        by (simp add: sup_state_rev_fst sup_state_Cons1);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   349
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   350
      show ?thesis 
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   351
      proof (cases "X = NT");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   352
        case True;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   353
        with x2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   354
        have "b = NT"; by (clarsimp_tac simp add: widen_NT);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   355
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   356
        with rac l lapTs;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   357
        have "?P s"; by auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   358
        thus ?thesis; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   359
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   360
      next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   361
        case False;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   362
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   363
        with wtl; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   364
        have "\\<exists>C. X = Class C"; by clarsimp_tac;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   365
        with x2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   366
        have "\\<exists>r. b = RefT r"; by (auto simp add: widen_Class);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   367
        
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   368
        thus ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   369
        proof elim;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   370
          fix r;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   371
          assume b: "b = RefT r"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   372
          show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   373
          proof (cases r);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   374
            case NullT;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   375
            with b rac x2 l lapTs wtl False;
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
          next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   379
            case ClassT;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   380
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   381
            from False wtl;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   382
            have wtlC: "?ClassC"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   383
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   384
            with b ClassT;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   385
            show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   386
            proof (elim exE conjE);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   387
              fix C D rT body;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   388
              assume ClassC: "X = Class C";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   389
              assume zip: "\\<forall>x\\<in>set (zip apTs list). x \\<in> widen G";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   390
              assume s1': "(rT # ST', y') = s1'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   391
              assume s: "G \\<turnstile> s1' <=s s";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   392
              assume method: "method (G, C) (mname, list) = Some (D, rT, body)";  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   393
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   394
              from ClassC b ClassT x2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   395
              have "G \\<turnstile> cname \\<preceq>C C"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   396
              with method wfp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   397
              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
   398
                by - (rule subcls_widen_methd, blast);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   399
              
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   400
              thus ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   401
              proof elim;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   402
                fix D' rT' body';
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   403
                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
   404
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   405
                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
   406
                proof (intro conjI);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   407
                  from s1' method' x2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   408
                  show "?B"; by (auto simp add: sup_state_Cons1);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   409
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   410
                  from b ClassT rac l lapTs method'; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   411
                  have "?A a (Class cname) c"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   412
                  proof (simp, intro conjI);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   413
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   414
                    from method' x2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   415
                    have s': "G \\<turnstile> (rT' # c, y) <=s (rT # ST', y')"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   416
                      by (auto simp add: sup_state_Cons1);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   417
                    from s s1';
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   418
                    have "G \\<turnstile> (rT # ST', y') <=s s"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   419
                    with s'; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   420
                    show "G \\<turnstile> (rT' # c, y) <=s s"; by (rule sup_state_trans);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   421
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   422
                    from x2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   423
                    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
   424
                    from lapTs zip;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   425
                    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
   426
                    with 1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   427
                    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
   428
                    with l lapTs;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   429
                    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
   430
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   431
                  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   432
                  thus "\\<exists> apTs X ST'. ?A apTs X ST'"; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   433
                qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   434
                thus ?thesis; by blast;
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   435
              qed
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   436
            qed 
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   437
          qed
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   438
        qed
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   439
      qed
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   440
    qed
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   441
  qed
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   442
qed
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   443
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   444
lemma sup_loc_some:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   445
"\\<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
   446
proof (induct "?P" b);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   447
  show "?P []"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   448
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   449
  case Cons;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   450
  show "?P (a#list)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   451
  proof (clarsimp_tac simp add: list_all2_Cons1 sup_loc_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   452
    fix z zs n;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   453
    assume * : 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   454
      "G \\<turnstile> a <=o z" "list_all2 (sup_ty_opt G) list zs" 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   455
      "n < Suc (length zs)" "(z # zs) ! n = Some t";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   456
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   457
    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
   458
    proof (cases n); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   459
      case 0;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   460
      with *; show ?thesis; by (simp add: sup_ty_opt_some);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   461
    next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   462
      case Suc;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   463
      with Cons *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   464
      show ?thesis; by (simp add: sup_loc_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   465
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   466
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   467
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   468
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   469
lemma mono_load: 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   470
"\\<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
   471
proof (clarsimp_tac simp add: sup_state_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   472
  assume "G  \\<turnstile> b <=l y" "n < length y" "y!n = Some t";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   473
  thus "\\<exists>ts. b ! n = Some ts \\<and> G\\<turnstile>ts\\<preceq>t";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   474
   by (rule sup_loc_some [rulify, elimify], clarsimp_tac);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   475
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   476
  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   477
lemma mono_store:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   478
"\\<lbrakk>G \\<turnstile> (a, b) <=s (ts # ST', y); n < length y\\<rbrakk> \\<Longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   479
  \\<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
   480
proof (clarsimp_tac simp add: sup_state_def sup_loc_Cons2);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   481
  fix Y YT';
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   482
  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
   483
  assume "map Some a = Y # YT'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   484
  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
   485
    by (rule map_hd_tl);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   486
  with *; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   487
  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
   488
    by (clarsimp_tac simp add: sup_loc_update);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   489
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   490
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   491
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   492
lemma PrimT_PrimT: "(G \\<turnstile> xb \\<preceq> PrimT p) = (xb = PrimT p)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   493
proof;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   494
  show "xb = PrimT p \\<Longrightarrow> G \\<turnstile> xb \\<preceq> PrimT p"; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   495
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   496
  show "G\\<turnstile> xb \\<preceq> PrimT p \\<Longrightarrow> xb = PrimT p";
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   497
  proof (cases xb);
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   498
    fix prim;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   499
    assume "xb = PrimT prim" "G\\<turnstile>xb\\<preceq>PrimT p";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   500
    thus ?thesis; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   501
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   502
    fix ref;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   503
    assume "G\\<turnstile>xb\\<preceq>PrimT p" "xb = RefT ref";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   504
    thus ?thesis; by simp (rule widen_RefT [elimify], auto);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   505
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   506
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   507
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   508
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   509
lemma wtl_inst_pseudo_mono:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   510
"\\<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
   511
  G \\<turnstile> s2 <=s s1; i = ins!pc\\<rbrakk> \\<Longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   512
 \\<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
   513
proof (simp only:);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   514
  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
   515
  assume 2 : "fits ins cert phi" "wf_prog wf_mb G" "i = ins!pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   516
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   517
  have 3: "\\<exists> a b. s2 = (a,b)"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   518
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   519
  show ?thesis; 
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   520
  proof (cases "ins ! pc", insert 1, insert 3);
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   521
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   522
    case Load
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   523
    with 1 3 
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   524
    show ?thesis; by (elim, clarsimp_tac) (rule mono_load [elimify], auto simp add: sup_state_length_snd);
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   525
  next
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   526
    case Store;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   527
    with 1 3; 
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   528
    show ?thesis; by (elim, clarsimp_tac) (rule mono_store [elimify], auto simp add: sup_state_length_snd);
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   529
  next
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   530
    case Getfield;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   531
    with 1 3;
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   532
    show ?thesis;
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   533
    proof (elim, clarsimp_tac simp add: sup_state_Cons2);       
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   534
      fix oT x;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   535
      assume "G \\<turnstile> x \\<preceq> oT" "G \\<turnstile> oT \\<preceq> Class cname"; 
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   536
      show "G \\<turnstile> x \\<preceq> Class cname"; by (rule widen_trans);
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   537
    qed;
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   538
  next
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   539
    case Putfield;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   540
    with 1 3;
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   541
    show ?thesis;
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   542
    proof (elim, clarsimp_tac simp add: sup_state_Cons2);       
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   543
      fix x xa vT oT T;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   544
      assume "G \\<turnstile> x \\<preceq> vT" "G \\<turnstile> vT \\<preceq> T";
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   545
      hence * : "G \\<turnstile> x \\<preceq> T"; by (rule widen_trans);
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   546
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   547
      assume "G \\<turnstile> xa \\<preceq> oT" "G \\<turnstile> oT \\<preceq> Class cname"; 
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   548
      hence "G \\<turnstile> xa \\<preceq> Class cname"; by (rule widen_trans);
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   549
      
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   550
      with *
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   551
      show "(G \\<turnstile> xa \\<preceq> Class cname) \\<and> (G \\<turnstile> x \\<preceq> T)"; by blast;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   552
    qed
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   553
  next
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   554
    case Checkcast;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   555
    with 1 3;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   556
    show ?thesis; by (elim, clarsimp_tac simp add: sup_state_Cons2) (rule widen_RefT2);
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   557
  next
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   558
    case Invoke;
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   559
    with 1 2 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   560
    show ?thesis; by elim (rule method_inv_pseudo_mono [elimify], simp+); 
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   561
  next    
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   562
    case Return;
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   563
    with 1 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   564
    show ?thesis; 
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   565
    proof (elim, clarsimp_tac simp add: sup_state_Cons2 simp del: split_paired_Ex);
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   566
      fix x T;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   567
      assume "G\\<turnstile>x\\<preceq>T" "G\\<turnstile>T\\<preceq>rT";
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   568
      thus "G\\<turnstile>x\\<preceq>rT"; by (rule widen_trans);
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   569
    qed 
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   570
  next
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   571
    case Goto;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   572
    with 1 3;
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   573
    show ?thesis;
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   574
    proof (elim, clarsimp_tac simp del: split_paired_Ex);
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   575
      fix a b x y;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   576
      assume "G \\<turnstile> (a, b) <=s s1" "G \\<turnstile> s1 <=s (x, y)";
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   577
      thus "G \\<turnstile> (a, b) <=s (x, y)"; by (rule sup_state_trans);
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   578
    qed
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   579
  next
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   580
    case Ifcmpeq;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   581
    with 1 3;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   582
    show ?thesis
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   583
    proof (elim, clarsimp_tac simp add: sup_state_Cons2, intro conjI);
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   584
      fix xt' b ST' y c d;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   585
      assume "G \\<turnstile> (xt', b) <=s (ST', y)" "G \\<turnstile> (ST', y) <=s (c, d)";
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   586
      thus "G \\<turnstile> (xt', b) <=s (c, d)"; by (rule sup_state_trans);
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   587
    next;
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   588
      fix ts ts' x xa;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   589
      assume * :
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   590
        "(\\<exists>p. ts = PrimT p \\<and> ts' = PrimT p) \\<or> (\\<exists>r. ts = RefT r) \\<and> (\\<exists>r'. ts' = RefT r')";
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   591
      
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   592
      assume x: "G\\<turnstile>x\\<preceq>ts" "G\\<turnstile>xa\\<preceq>ts'";
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   593
      
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   594
      show "(\\<exists>p. x = PrimT p \\<and> xa = PrimT p) \\<or> (\\<exists>r. x = RefT r) \\<and> (\\<exists>r'. xa = RefT r')"; 
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   595
      proof (cases x);
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   596
        case PrimT;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   597
        with * x;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   598
        show ?thesis; by (auto simp add: PrimT_PrimT);
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   599
      next;
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   600
        case RefT;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   601
        hence 1: "\\<exists>r. x = RefT r"; by blast;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   602
        
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   603
        have "\\<exists>r'. xa = RefT r'";
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   604
        proof (cases xa); 
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   605
          case PrimT;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   606
          with RefT * x;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   607
          have "False"; by auto (rule widen_RefT [elimify], auto); 
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   608
          thus ?thesis; by blast;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   609
        qed blast;
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   610
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   611
        with 1
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   612
        show ?thesis by blast
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   613
      qed
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   614
    qed
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   615
  qed (elim, clarsimp_tac simp add: sup_state_Cons1 sup_state_Cons2 PrimT_PrimT)+
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   616
qed
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   617
 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   618
lemma wtl_inst_last_mono:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   619
"\\<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
   620
 \\<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
   621
proof -;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   622
  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
   623
  
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   624
  show ?thesis
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   625
  proof (cases i, insert *)
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   626
    case Return with *
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   627
    show ?thesis 
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   628
      by (clarsimp_tac simp del: split_paired_Ex simp add: sup_state_Cons2)
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   629
        (rule widen_trans, blast+);
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   630
  next
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   631
    case Goto with *
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   632
    show ?thesis
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   633
      by (clarsimp_tac simp del: split_paired_Ex simp add: sup_state_Cons2)
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   634
         (rule sup_state_trans, blast+);
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   635
  qed auto
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   636
qed
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   637
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   638
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   639
lemma wtl_option_last_mono:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   640
"\\<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
   641
 \\<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
   642
proof (simp only: ); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   643
  assume G: "G \\<turnstile> s2 <=s s1";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   644
  assume w: "wtl_inst_option i G rT s1 s1' cert (Suc pc) pc"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   645
  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   646
  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
   647
  proof (cases "cert!pc");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   648
    case None;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   649
    with G w;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   650
    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
   651
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   652
    case Some;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   653
    with G w;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   654
    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
   655
      by (simp add: wtl_inst_option_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   656
    hence w' : "wtl_inst i G rT a s1' cert (Suc pc) pc"; ..;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   657
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   658
    from o G;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   659
    have G' : "G \\<turnstile> s2 <=s a"; by - (rule sup_state_trans, blast+); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   660
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   661
    from o;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   662
    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
   663
      by elim (rule wtl_inst_last_mono, auto);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   664
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   665
    with Some w G';
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   666
    show ?thesis; by (auto simp add: wtl_inst_option_def);  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   667
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   668
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   669
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   670
lemma wt_instr_imp_wtl_inst:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   671
"\\<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
   672
  pc < length ins; length ins = max_pc\\<rbrakk> \\<Longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   673
  \\<exists> s. wtl_inst (ins!pc) G rT (phi!pc) s cert max_pc pc \\<and> G \\<turnstile> s <=s phi ! Suc pc";
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   674
proof -
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   675
  assume * : "wt_instr (ins!pc) G rT phi max_pc pc" "fits ins cert phi"
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   676
             "pc < length ins" "length ins = max_pc"
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   677
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   678
  have xy: "\\<exists> x y. phi!pc = (x,y)" by simp
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   679
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   680
  show ?thesis
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   681
  proof (cases "ins!pc", insert *, insert xy);
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   682
    case Return with * xy
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   683
    show ?thesis
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   684
      by (elim, clarsimp_tac simp add: fits_def contains_dead_def simp del: split_paired_Ex);
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   685
  next
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   686
    case Goto with * xy
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   687
    show ?thesis; 
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   688
      by (clarsimp_tac simp add: fits_def contains_dead_def contains_targets_def simp del: split_paired_Ex);
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   689
  next
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   690
    case Ifcmpeq with * xy
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   691
    show ?thesis; 
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   692
      by (clarsimp_tac simp add: fits_def contains_dead_def contains_targets_def simp del: split_paired_Ex);    
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   693
  next
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   694
    case Invoke with * xy
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   695
    show ?thesis
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   696
    proof (elim, clarsimp_tac simp del: split_paired_Ex)
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   697
      fix y apTs X ST'; 
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   698
      assume pc : "Suc pc < length ins"; 
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   699
      assume phi : "phi ! pc = (rev apTs @ X # ST', y)" "length apTs = length list";
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   700
      assume ** :
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   701
        "X = NT \\<or> (\\<exists>C. X = Class C \\<and>
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   702
        (\\<forall>x\\<in>set (zip apTs list). x \\<in> widen G) \\<and>
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   703
        (\\<exists>D rT. (\\<exists>b. method (G, C) (mname, list) = Some (D, rT, b)) \\<and> G \\<turnstile> (rT # ST', y) <=s phi ! Suc pc))"
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   704
      (is "?NT \\<or> ?CL"); 
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   705
        
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   706
      from Invoke pc *;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   707
      have cert: "cert ! Suc pc = Some (phi ! Suc pc)"; by (clarsimp_tac simp add: fits_def contains_dead_def); 
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   708
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   709
      show "\\<exists>s. (\\<exists>apTsa Xa ST'a.
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   710
                rev apTs @ X # ST' = rev apTsa @ Xa # ST'a \\<and>
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   711
                length apTsa = length list \\<and>
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   712
                 (\\<exists>s''. cert ! Suc pc = Some s'' \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   713
                        (s'' = s \\<and> Xa = NT \\<or>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   714
                         G \\<turnstile> s <=s s'' \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   715
                         (\\<exists>C. Xa = Class C \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   716
                              (\\<forall>x\\<in>set (zip apTsa list). x \\<in> widen G) \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   717
                              (\\<exists>D rT. (\\<exists>b. method (G, C) (mname, list) = Some (D, rT, b)) \\<and> (rT # ST'a, y) = s))))) \\<and>
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   718
                G \\<turnstile> s <=s phi ! Suc pc" (is "\\<exists>s. ?P s");  
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   719
      proof (cases "X=NT"); 
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   720
        case True
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   721
        with cert phi **
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   722
        have "?P (phi ! Suc pc)" by (force simp del: split_paired_Ex)
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   723
        thus ?thesis by blast
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   724
      next
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   725
        case False
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   726
        with **
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   727
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   728
        have "?CL" by simp
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   729
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   730
        thus ?thesis
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   731
        proof (elim exE conjE);
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   732
          fix C D rT b;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   733
          assume "X = Class C" "\\<forall>x\\<in>set (zip apTs list). x \\<in> widen G" 
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   734
                 "G \\<turnstile> (rT # ST', y) <=s phi ! Suc pc"
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   735
                 "method (G, C) (mname, list) = Some (D, rT, b)";
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   736
          with cert phi;
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   737
          have "?P (rT #ST', y)" by (force simp del: split_paired_Ex)
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   738
          thus ?thesis by blast
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   739
        qed
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   740
      qed
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   741
    qed
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   742
  qed (elim, force)+
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   743
qed
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   744
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   745
  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   746
lemma wt_instr_imp_wtl_option:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   747
"\\<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
   748
 \\<exists> s. wtl_inst_option (ins!pc) G rT (phi!pc) s cert max_pc pc \\<and> G \\<turnstile> s <=s phi ! Suc pc";
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   749
proof -
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   750
  assume fits : "fits ins cert phi" "pc < length ins" 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   751
         and "wt_instr (ins!pc) G rT phi max_pc pc" 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   752
             "max_pc = length ins";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   753
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   754
  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
   755
    by - (rule wt_instr_imp_wtl_inst, simp+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   756
  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   757
  show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   758
  proof (cases "cert ! pc");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   759
    case None;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   760
    with *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   761
    show ?thesis; by (simp add: wtl_inst_option_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   762
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   763
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   764
    case Some;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   765
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   766
    from fits; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   767
    have "pc < length phi"; by (clarsimp_tac simp add: fits_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   768
    with fits Some;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   769
    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
   770
     
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   771
    with *; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   772
    show ?thesis; by (simp add: wtl_inst_option_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   773
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   774
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   775
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   776
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   777
lemma wtl_option_pseudo_mono:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   778
"\\<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
   779
  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
   780
 \\<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
   781
        (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
   782
proof -;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   783
  assume wtl:  "wtl_inst_option i G rT s1 s1' cert mpc pc" and
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   784
         fits: "fits ins cert phi" "pc < length ins"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   785
               "wf_prog wf_mb G" "G \\<turnstile> s2 <=s s1" "i = ins!pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   786
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   787
  show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   788
  proof (cases "cert!pc");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   789
    case None;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   790
    with wtl fits;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   791
    show ?thesis; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   792
      by - (rule wtl_inst_pseudo_mono [elimify], (simp add: wtl_inst_option_def)+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   793
  next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   794
    case Some;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   795
    with wtl fits;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   796
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   797
    have G: "G \\<turnstile> s2 <=s a";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   798
     by - (rule sup_state_trans, (simp add: wtl_inst_option_def)+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   799
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   800
    from Some wtl;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   801
    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
   802
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   803
    with G fits;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   804
    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
   805
                 (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
   806
      by - (rule wtl_inst_pseudo_mono, (simp add: wtl_inst_option_def)+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   807
    
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   808
    with Some G;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   809
    show ?thesis; by (simp add: wtl_inst_option_def);
9376
c32c5696ec2a flat instruction set
kleing
parents: 9260
diff changeset
   810
  qed
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   811
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   812
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   813
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   814
(* main induction over instruction list *)
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   815
theorem wt_imp_wtl_inst_list:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   816
"\\<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
   817
       wf_prog wf_mb G \\<longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   818
       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
   819
       (\\<forall> s. (G \\<turnstile> s <=s (phi!pc)) \\<longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   820
       (\\<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
   821
(is "\\<forall>pc. ?C pc ins" is "?P ins");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   822
proof (induct "?P" "ins");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   823
  case Nil;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   824
  show "?P []"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   825
next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   826
  case Cons;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   827
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   828
  show "?P (a#list)";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   829
  proof (intro allI impI, elim exE conjE);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   830
    fix pc s l;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   831
    assume 1: "wf_prog wf_mb G" "fits all_ins cert phi";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   832
    assume 2: "pc < length all_ins" "G \\<turnstile> s <=s phi ! pc"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   833
              "all_ins = l @ a # list" "pc = length l";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   834
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   835
    from Cons;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   836
    have IH: "?C (Suc pc) list"; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   837
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   838
    assume 3: "\\<forall>pc'. pc' < length (a # list) \\<longrightarrow>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   839
               wt_instr ((a # list) ! pc') G rT phi (pc + length (a # list)) (pc + pc')";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   840
    hence 4: "\\<forall>pc'. pc' < length list \\<longrightarrow>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   841
              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
   842
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   843
    from 2; 
9182
9c443de2ba42 tuning, eliminated rev_surj
kleing
parents: 9054
diff changeset
   844
    have 5: "a = all_ins ! pc"; by (simp add: nth_append);
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   845
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   846
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   847
    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
   848
    proof (cases list);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   849
      case Nil;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   850
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   851
      with 1 2 3 5; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   852
      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
   853
        by - (rule wt_instr_imp_wtl_option [elimify], force+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   854
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   855
      with Nil 1 2 5;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   856
      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
   857
        by elim (rule wtl_option_pseudo_mono [elimify], force+); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   858
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   859
      with Nil 2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   860
      show ?thesis; by auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   861
    next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   862
      fix i' ins'; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   863
      assume Cons2: "list = i' # ins'";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   864
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   865
      with IH 1 2 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   866
      have * : "\\<forall> s. (G \\<turnstile> s <=s (phi!(Suc pc))) \\<longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   867
                     (\\<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
   868
        by (elim impE) force+;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   869
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   870
      from 3;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   871
      have "wt_instr a G rT phi (pc + length (a # list)) pc"; by auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   872
      
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   873
      with 1 2 5;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   874
      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
   875
        by - (rule wt_instr_imp_wtl_option [elimify], assumption+, simp+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   876
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   877
      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
   878
                  (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
   879
      proof elim; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   880
        fix s1';
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   881
        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
   882
            a :"G \\<turnstile> s1' <=s phi ! Suc pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   883
        with 1 2 5;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   884
        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
   885
                   ((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
   886
          by - (rule wtl_option_pseudo_mono [elimify], simp+);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   887
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   888
        with a;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   889
        show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   890
        proof (elim, intro);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   891
          fix s1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   892
          assume "G \\<turnstile> s1 <=s s1'" "G \\<turnstile> s1' <=s phi ! Suc pc";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   893
          show "G \\<turnstile> s1 <=s phi ! Suc pc"; by (rule sup_state_trans);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   894
        qed auto;
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
      thus ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   898
      proof (elim exE conjE); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   899
        fix s1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   900
        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
   901
        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
   902
        
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   903
        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
   904
        proof (cases "G \\<turnstile> s1 <=s phi ! Suc pc");
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   905
          case True;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   906
          with Gs1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   907
          have "G \\<turnstile> s1 <=s phi ! Suc pc"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   908
          with *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   909
          show ?thesis; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   910
        next;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   911
          case False;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   912
          with Gs1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   913
          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
   914
          thus ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   915
          proof elim;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   916
            from 1 2 Cons Cons2;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   917
            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
   918
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   919
            with 1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   920
            have cert: "cert ! (Suc pc) = None \\<or> cert ! (Suc pc) = Some (phi ! Suc pc)"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   921
              by (clarsimp_tac simp add: fits_def is_approx_def); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   922
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   923
            fix c;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   924
            assume "cert ! Suc pc = Some c"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   925
            with cert;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   926
            have c: "c = phi ! Suc pc"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   927
            assume "G \\<turnstile> s1 <=s c";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   928
            with c;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   929
            have "G \\<turnstile> s1 <=s phi ! Suc pc"; by simp;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   930
            with *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   931
            show ?thesis; by blast;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   932
          qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   933
        qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   934
        with wto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   935
        show ?thesis; by (auto simp del: split_paired_Ex);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   936
      qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   937
    qed; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   938
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   939
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   940
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   941
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   942
lemma fits_imp_wtl_method_complete:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   943
"\\<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
   944
by (simp add: wt_method_def wtl_method_def del: split_paired_Ex)
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   945
   (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
   946
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   947
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   948
lemma wtl_method_complete:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   949
"\\<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
   950
proof -;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   951
  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
   952
  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   953
  hence "fits ins (make_cert ins phi) phi";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   954
    by - (rule fits_make_cert, simp add: wt_method_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   955
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   956
  with *;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   957
  show ?thesis; by - (rule fits_imp_wtl_method_complete);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   958
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   959
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   960
lemma unique_set:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   961
"(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
   962
  by (induct "l") auto;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   963
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   964
lemma unique_epsilon:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   965
"(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
   966
  by (auto simp add: unique_set);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   967
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   968
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   969
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
   970
proof (simp only: wt_jvm_prog_def);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   971
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   972
  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
   973
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   974
  thus ?thesis; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   975
  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
   976
    fix a aa ab b ac ba ad ae bb; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   977
    assume 1 : "\\<forall>(C,sc,fs,ms)\\<in>set G.
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   978
             Ball (set fs) (wf_fdecl G) \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   979
             unique fs \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   980
             (\\<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
   981
             unique ms \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   982
             (case sc of None \\<Rightarrow> C = Object
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   983
              | Some D \\<Rightarrow>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   984
                  is_class G D \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   985
                  (D, C) \\<notin> (subcls1 G)^* \\<and>
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   986
                  (\\<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
   987
             "(a, aa, ab, b) \\<in> set G";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   988
  
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   989
    assume uG : "unique G"; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   990
    assume b  : "((ac, ba), ad, ae, bb) \\<in> set b";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   991
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   992
    from 1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   993
    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
   994
    proof (rule bspec [elimify], clarsimp_tac);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   995
      assume ub : "unique b";
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   996
      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
   997
      from m b;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   998
      show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
   999
      proof (rule bspec [elimify], clarsimp_tac);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1000
        assume "wt_method G a ba ad ae bb (Phi a (ac, ba))";         
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1001
        with wfprog uG ub b 1;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1002
        show ?thesis;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1003
          by - (rule wtl_method_complete [elimify], assumption+, simp add: make_Cert_def unique_epsilon);
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1004
      qed; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1005
    qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1006
  qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1007
qed;
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1008
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8388
diff changeset
  1009
end;