src/HOL/MicroJava/BV/LBVSpec.thy
author wenzelm
Tue, 25 Jul 2000 00:06:46 +0200
changeset 9436 62bb04ab4b01
parent 9376 c32c5696ec2a
child 9549 40d64cb4f4e6
permissions -rw-r--r--
rearranged setup of arithmetic procedures, avoiding global reference values;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
     1
(*  Title:      HOL/MicroJava/BV/BVLightSpec.thy
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
     2
    ID:         $Id$
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
     3
    Author:     Gerwin Klein
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
     4
    Copyright   1999 Technische Universitaet Muenchen
9054
0e48e7d4d4f9 minor tuning for pdf documents
kleing
parents: 9012
diff changeset
     5
*)
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
     6
9054
0e48e7d4d4f9 minor tuning for pdf documents
kleing
parents: 9012
diff changeset
     7
header {* Specification of the LBV *}
0e48e7d4d4f9 minor tuning for pdf documents
kleing
parents: 9012
diff changeset
     8
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
     9
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
    10
theory LBVSpec = BVSpec:
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    11
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    12
types
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    13
  certificate       = "state_type option list" 
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    14
  class_certificate = "sig \\<Rightarrow> certificate"
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
    15
  prog_certificate  = "cname \\<Rightarrow> class_certificate"
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    16
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
    17
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    18
consts
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
    19
wtl_inst :: "[instr,jvm_prog,ty,state_type,state_type,certificate,p_count,p_count] \\<Rightarrow> bool"
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
    20
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    21
primrec
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
    22
"wtl_inst (Load idx) G rT s s' cert max_pc pc =
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    23
 (let (ST,LT) = s
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    24
  in
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    25
  pc+1 < max_pc \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    26
  idx < length LT \\<and> 
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    27
  (\\<exists>ts. (LT ! idx) = Some ts \\<and>  
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    28
   (ts # ST , LT) = s'))"
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    29
  
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
    30
"wtl_inst (Store idx) G rT s s' cert max_pc pc =
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    31
 (let (ST,LT) = s
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    32
  in
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    33
  pc+1 < max_pc \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    34
  idx < length LT \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    35
  (\\<exists>ts ST'. ST = ts # ST' \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    36
   (ST' , LT[idx:=Some ts]) = s'))"
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    37
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
    38
"wtl_inst (Bipush i) G rT s s' cert max_pc pc =
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    39
	(let (ST,LT) = s
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    40
	 in
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    41
	 pc+1 < max_pc \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    42
	 ((PrimT Integer) # ST , LT) = s')"
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    43
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
    44
"wtl_inst (Aconst_null) G rT s s' cert max_pc pc =
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    45
	(let (ST,LT) = s
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    46
	 in
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    47
	 pc+1 < max_pc \\<and>
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
    48
	 (NT # ST , LT) = s')"
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    49
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
    50
"wtl_inst (Getfield F C) G rT s s' cert max_pc pc =
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    51
	(let (ST,LT) = s
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    52
	 in
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    53
	 pc+1 < max_pc \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    54
	 is_class G C \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    55
	 (\\<exists>T oT ST'. field (G,C) F = Some(C,T) \\<and>
8390
e5b618f6824e tuned for completeness of LBV
kleing
parents: 8245
diff changeset
    56
                          ST = oT # ST'  \\<and> 
e5b618f6824e tuned for completeness of LBV
kleing
parents: 8245
diff changeset
    57
		                  G \\<turnstile> oT \\<preceq> (Class C) \\<and>
e5b618f6824e tuned for completeness of LBV
kleing
parents: 8245
diff changeset
    58
		          (T # ST' , LT) = s'))"
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    59
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
    60
"wtl_inst (Putfield F C) G rT s s' cert max_pc pc =
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    61
	(let (ST,LT) = s
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    62
	 in
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    63
	 pc+1 < max_pc \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    64
	 is_class G C \\<and> 
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    65
	 (\\<exists>T vT oT ST'.
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    66
             field (G,C) F = Some(C,T) \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    67
             ST = vT # oT # ST' \\<and> 
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    68
             G \\<turnstile> oT \\<preceq> (Class C) \\<and>
8390
e5b618f6824e tuned for completeness of LBV
kleing
parents: 8245
diff changeset
    69
             G \\<turnstile> vT \\<preceq> T  \\<and>
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
    70
             (ST' , LT) = s'))"
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    71
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
    72
"wtl_inst (New C) G rT s s' cert max_pc pc =
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    73
	(let (ST,LT) = s
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    74
	 in
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    75
	 pc+1 < max_pc \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    76
	 is_class G C \\<and>
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
    77
	 ((Class C) # ST , LT) = s')"
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    78
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
    79
"wtl_inst (Checkcast C) G rT s s' cert max_pc pc =
9054
0e48e7d4d4f9 minor tuning for pdf documents
kleing
parents: 9012
diff changeset
    80
	(let (ST,LT) = s 
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    81
	 in
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    82
	 pc+1 < max_pc \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    83
	 is_class G C \\<and> 
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    84
	 (\\<exists>rt ST'. ST = RefT rt # ST' \\<and>
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
    85
                   (Class C # ST' , LT) = s'))"
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    86
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
    87
"wtl_inst Pop G rT s s' cert max_pc pc =
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    88
	(let (ST,LT) = s
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    89
	 in
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    90
	 \\<exists>ts ST'. pc+1 < max_pc \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    91
		ST = ts # ST' \\<and> 	 
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    92
		(ST' , LT) = s')"
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    93
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
    94
"wtl_inst Dup G rT s s' cert max_pc pc =
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    95
	(let (ST,LT) = s
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    96
	 in
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    97
	 pc+1 < max_pc \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    98
	 (\\<exists>ts ST'. ST = ts # ST' \\<and> 	 
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
    99
		   (ts # ts # ST' , LT) = s'))"
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   100
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
   101
"wtl_inst Dup_x1 G rT s s' cert max_pc pc =
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   102
	(let (ST,LT) = s
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   103
	 in
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   104
	 pc+1 < max_pc \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   105
	 (\\<exists>ts1 ts2 ST'. ST = ts1 # ts2 # ST' \\<and> 	 
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   106
		        (ts1 # ts2 # ts1 # ST' , LT) = s'))"
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   107
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
   108
"wtl_inst Dup_x2 G rT s s' cert max_pc pc =
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   109
	(let (ST,LT) = s
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   110
	 in
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   111
	 pc+1 < max_pc \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   112
	 (\\<exists>ts1 ts2 ts3 ST'. ST = ts1 # ts2 # ts3 # ST' \\<and> 	 
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   113
		            (ts1 # ts2 # ts3 # ts1 # ST' , LT) = s'))"
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   114
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
   115
"wtl_inst Swap G rT s s' cert max_pc pc =
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   116
	(let (ST,LT) = s
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   117
	 in
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   118
	 pc+1 < max_pc \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   119
	 (\\<exists>ts ts' ST'. ST = ts' # ts # ST' \\<and> 	 
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   120
		       (ts # ts' # ST' , LT) = s'))"
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   121
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
   122
"wtl_inst IAdd G rT s s' cert max_pc pc =
9260
678e718a5a86 new ADD instruction
kleing
parents: 9183
diff changeset
   123
	(let (ST,LT) = s
678e718a5a86 new ADD instruction
kleing
parents: 9183
diff changeset
   124
	 in
678e718a5a86 new ADD instruction
kleing
parents: 9183
diff changeset
   125
	 pc+1 < max_pc \\<and>
678e718a5a86 new ADD instruction
kleing
parents: 9183
diff changeset
   126
	 (\\<exists>ST'. ST = (PrimT Integer) # (PrimT Integer) # ST' \\<and> 	 
678e718a5a86 new ADD instruction
kleing
parents: 9183
diff changeset
   127
		       ((PrimT Integer) # ST' , LT) = s'))"
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
   128
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
   129
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
   130
"wtl_inst (Ifcmpeq branch) G rT s s' cert max_pc pc =
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   131
	(let (ST,LT) = s
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   132
	 in
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   133
	 pc+1 < max_pc \\<and> (nat(int pc+branch)) < max_pc \\<and> 
8390
e5b618f6824e tuned for completeness of LBV
kleing
parents: 8245
diff changeset
   134
	 (\\<exists>ts ts' ST'. ST = ts # ts' # ST' \\<and>
e5b618f6824e tuned for completeness of LBV
kleing
parents: 8245
diff changeset
   135
          ((\\<exists>p. ts = PrimT p \\<and> ts' = PrimT p) \\<or>
e5b618f6824e tuned for completeness of LBV
kleing
parents: 8245
diff changeset
   136
           (\\<exists>r r'. ts = RefT r \\<and> ts' = RefT r')) \\<and>
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   137
		       ((ST' , LT) = s') \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   138
            cert ! (nat(int pc+branch)) \\<noteq> None \\<and>
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
   139
		       G \\<turnstile> (ST' , LT) <=s the (cert ! (nat(int pc+branch)))))" 
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   140
  
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
   141
"wtl_inst (Goto branch) G rT s s' cert max_pc pc =
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   142
	((let (ST,LT) = s
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   143
	 in
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   144
	 (nat(int pc+branch)) < max_pc \\<and> cert ! (nat(int pc+branch)) \\<noteq> None \\<and>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   145
	 G \\<turnstile> (ST , LT) <=s the (cert ! (nat(int pc+branch)))) \\<and>
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   146
   (cert ! (pc+1) = Some s'))"
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
   147
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
   148
"wtl_inst (Invoke mn fpTs) G rT s s' cert max_pc pc =
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   149
	(let (ST,LT) = s
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   150
	 in
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   151
         pc+1 < max_pc \\<and>
8390
e5b618f6824e tuned for completeness of LBV
kleing
parents: 8245
diff changeset
   152
         (\\<exists>apTs X ST'. ST = (rev apTs) @ (X # ST') \\<and>
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   153
         length apTs = length fpTs \\<and>
8390
e5b618f6824e tuned for completeness of LBV
kleing
parents: 8245
diff changeset
   154
         (\\<exists>s''. cert ! (pc+1) = Some s'' \\<and> 
e5b618f6824e tuned for completeness of LBV
kleing
parents: 8245
diff changeset
   155
         ((s'' = s' \\<and> X = NT) \\<or>
e5b618f6824e tuned for completeness of LBV
kleing
parents: 8245
diff changeset
   156
          ((G \\<turnstile> s' <=s s'') \\<and> (\\<exists>C. X = Class C \\<and>  
e5b618f6824e tuned for completeness of LBV
kleing
parents: 8245
diff changeset
   157
          (\\<forall>(aT,fT)\\<in>set(zip apTs fpTs). G \\<turnstile> aT \\<preceq> fT) \\<and> 
e5b618f6824e tuned for completeness of LBV
kleing
parents: 8245
diff changeset
   158
          (\\<exists>D rT b. method (G,C) (mn,fpTs) = Some(D,rT,b) \\<and>
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   159
          (rT # ST' , LT) = s')))))))"
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   160
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
   161
"wtl_inst Return G rT s s' cert max_pc pc =
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   162
	((let (ST,LT) = s
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   163
	 in
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   164
	 (\\<exists>T ST'. ST = T # ST' \\<and> G \\<turnstile> T \\<preceq> rT)) \\<and>
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   165
   (cert ! (pc+1) = Some s'))"
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   166
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   167
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   168
constdefs
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   169
wtl_inst_option :: "[instr,jvm_prog,ty,state_type,state_type,certificate,p_count,p_count] \\<Rightarrow> bool"
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   170
"wtl_inst_option i G rT s0 s1 cert max_pc pc \\<equiv>
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   171
     (case cert!pc of 
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   172
          None     \\<Rightarrow> wtl_inst i G rT s0 s1 cert max_pc pc
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   173
        | Some s0' \\<Rightarrow> (G \\<turnstile> s0 <=s s0') \\<and>
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   174
                      wtl_inst i G rT s0' s1 cert max_pc pc)"
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   175
  
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   176
consts
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   177
 wtl_inst_list :: "[instr list,jvm_prog,ty,state_type,state_type,certificate,p_count,p_count] \\<Rightarrow> bool"
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   178
primrec
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   179
  "wtl_inst_list [] G rT s0 s2 cert max_pc pc = (s0 = s2)"
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   180
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   181
  "wtl_inst_list (instr#is) G rT s0 s2 cert max_pc pc =
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   182
     (\\<exists>s1. wtl_inst_option instr G rT s0 s1 cert max_pc pc \\<and> 
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   183
           wtl_inst_list is G rT s1 s2 cert max_pc (pc+1))"
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   184
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   185
constdefs
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   186
 wtl_method :: "[jvm_prog,cname,ty list,ty,nat,instr list,certificate] \\<Rightarrow> bool" 
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   187
 "wtl_method G C pTs rT mxl ins cert \\<equiv> 
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   188
	let max_pc = length ins 
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   189
        in 
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   190
	0 < max_pc \\<and>  
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   191
        (\\<exists>s2. wtl_inst_list ins G rT 
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   192
                            ([],(Some(Class C))#((map Some pTs))@(replicate mxl None))
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   193
                            s2 cert max_pc 0)"
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   194
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   195
 wtl_jvm_prog :: "[jvm_prog,prog_certificate] \\<Rightarrow> bool"
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   196
 "wtl_jvm_prog G cert \\<equiv> 
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   197
    wf_prog (\\<lambda>G C (sig,rT,maxl,b). 
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   198
               wtl_method G C (snd sig) rT maxl b (cert C sig)) G" 
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   199
9054
0e48e7d4d4f9 minor tuning for pdf documents
kleing
parents: 9012
diff changeset
   200
text {* \medskip *}
0e48e7d4d4f9 minor tuning for pdf documents
kleing
parents: 9012
diff changeset
   201
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   202
lemma rev_eq: "\\<lbrakk>length a = n; length x = n; rev a @ b # c = rev x @ y # z\\<rbrakk> \\<Longrightarrow> a = x \\<and> b = y \\<and> c = z"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   203
by auto
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   204
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   205
lemma wtl_inst_unique: 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   206
"wtl_inst i G rT s0 s1 cert max_pc pc \\<longrightarrow>
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   207
 wtl_inst i G rT s0 s1' cert max_pc pc \\<longrightarrow> s1 = s1'" (is "?P i")
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   208
proof (induct i)
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
   209
case Invoke
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   210
  have "\\<exists>x y. s0 = (x,y)" by (simp)
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
   211
  thus "wtl_inst (Invoke mname list) G rT s0 s1 cert max_pc pc \\<longrightarrow>
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
   212
        wtl_inst (Invoke mname list) G rT s0 s1' cert max_pc pc \\<longrightarrow>
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   213
        s1 = s1'"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   214
  proof elim
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   215
    apply_end(clarsimp_tac, drule rev_eq, assumption+)
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   216
  qed auto
9376
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
   217
qed auto
c32c5696ec2a flat instruction set
kleing
parents: 9271
diff changeset
   218
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   219
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   220
lemma wtl_inst_option_unique:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   221
"\\<lbrakk>wtl_inst_option i G rT s0 s1 cert max_pc pc; 
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   222
  wtl_inst_option i G rT s0 s1' cert max_pc pc\\<rbrakk> \\<Longrightarrow> s1 = s1'"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   223
by (cases "cert!pc") (auto simp add: wtl_inst_unique wtl_inst_option_def)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   224
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   225
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   226
lemma wtl_inst_list_unique: 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   227
"\\<forall> s0 pc. wtl_inst_list is G rT s0 s1 cert max_pc pc \\<longrightarrow> 
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   228
 wtl_inst_list is G rT s0 s1' cert max_pc pc \\<longrightarrow> s1=s1'" (is "?P is")
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   229
proof (induct "?P" "is") 
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   230
  case Nil
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   231
  show "?P []" by simp
8245
6acc80f7f36f lightweight bytecode verifier with correctness proof
kleing
parents:
diff changeset
   232
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   233
  case Cons
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   234
  show "?P (a # list)" 
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   235
  proof intro
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   236
    fix s0 fix pc 
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   237
    let "?o s0 s1" = "wtl_inst_option a G rT s0 s1 cert max_pc pc"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   238
    let "?l l s1 s2 pc" = "wtl_inst_list l G rT s1 s2 cert max_pc pc" 
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   239
    assume a: "?l (a#list) s0 s1 pc"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   240
    assume b: "?l (a#list) s0 s1' pc"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   241
    with a
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   242
    show "s1 = s1'"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   243
      obtain s s' where   "?o s0 s" "?o s0 s'"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   244
                  and l:  "?l list s s1 (Suc pc)"
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   245
                  and l': "?l list s' s1' (Suc pc)" by auto
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   246
      have "s=s'" by(rule wtl_inst_option_unique)
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   247
      with l l' Cons
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   248
      show ?thesis by blast
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   249
    qed
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   250
  qed
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   251
qed
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   252
        
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   253
lemma wtl_partial:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   254
"\\<forall> pc' pc s. 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   255
   wtl_inst_list is G rT s s' cert mpc pc \\<longrightarrow> \
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   256
   pc' < length is \\<longrightarrow> \
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   257
   (\\<exists> a b s1. a @ b = is \\<and> length a = pc' \\<and> \
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   258
              wtl_inst_list a G rT s  s1 cert mpc pc \\<and> \
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   259
              wtl_inst_list b G rT s1 s' cert mpc (pc+length a))" (is "?P is")
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   260
proof (induct "?P" "is")
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   261
  case Nil
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   262
  show "?P []" by auto
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   263
  
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   264
  case Cons
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   265
  show "?P (a#list)"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   266
  proof (intro allI impI)
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   267
    fix pc' pc s
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   268
    assume length: "pc' < length (a # list)"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   269
    assume wtl:    "wtl_inst_list (a # list) G rT s s' cert mpc pc"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   270
    show "\\<exists> a' b s1. 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   271
            a' @ b = a#list \\<and> length a' = pc' \\<and> \
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   272
            wtl_inst_list a' G rT s  s1 cert mpc pc \\<and> \
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   273
            wtl_inst_list b G rT s1 s' cert mpc (pc+length a')"
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   274
        (is "\\<exists> a b s1. ?E a b s1")
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   275
    proof (cases "pc'")
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   276
      case 0
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   277
      with wtl
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   278
      have "?E [] (a#list) s" by simp
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   279
      thus ?thesis by blast
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   280
    next
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   281
      case Suc
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   282
      with wtl
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   283
      show ?thesis 
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   284
        obtain s0 where wtlSuc: "wtl_inst_list list G rT s0 s' cert mpc (Suc pc)"
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   285
                  and   wtlOpt: "wtl_inst_option a G rT s s0 cert mpc pc" by auto
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   286
        from Cons
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   287
        show ?thesis 
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   288
          obtain a' b s1' 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   289
            where "a' @ b = list" "length a' = nat"
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   290
            and w:"wtl_inst_list a' G rT s0 s1' cert mpc (Suc pc)"
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   291
            and   "wtl_inst_list b G rT s1' s' cert mpc (Suc pc + length a')" 
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   292
          proof (elim allE impE)
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   293
            from length Suc show "nat < length list" by simp 
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   294
            from wtlSuc     show "wtl_inst_list list G rT s0 s' cert mpc (Suc pc)" . 
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   295
          qed (elim exE conjE, auto)
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   296
          with Suc wtlOpt          
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   297
          have "?E (a#a') b s1'" by (auto simp del: split_paired_Ex)   
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   298
          thus ?thesis by blast
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   299
        qed
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   300
      qed
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   301
    qed
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   302
  qed
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   303
qed
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   304
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   305
lemma "wtl_append1":
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   306
"\\<lbrakk>wtl_inst_list x G rT s0 s1 cert (length (x@y)) 0; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   307
  wtl_inst_list y G rT s1 s2 cert (length (x@y)) (length x)\\<rbrakk> \\<Longrightarrow>
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   308
  wtl_inst_list (x@y) G rT s0 s2 cert (length (x@y)) 0"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   309
proof -
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   310
  assume w:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   311
    "wtl_inst_list x G rT s0 s1 cert (length (x@y)) 0"
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   312
    "wtl_inst_list y G rT s1 s2 cert (length (x@y)) (length x)"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   313
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   314
have
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   315
"\\<forall> pc s0. 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   316
 wtl_inst_list x G rT s0 s1 cert (pc+length (x@y)) pc \\<longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   317
 wtl_inst_list y G rT s1 s2 cert (pc+length (x@y)) (pc+length x) \\<longrightarrow>
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   318
 wtl_inst_list (x@y) G rT s0 s2 cert (pc+length (x@y)) pc" (is "?P x")
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   319
proof (induct "?P" "x")
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   320
  case Nil
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   321
  show "?P []" by simp
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   322
next
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   323
  case Cons
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   324
  show "?P (a#list)" 
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   325
  proof intro
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   326
    fix pc s0
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   327
    assume y: 
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   328
      "wtl_inst_list y G rT s1 s2 cert (pc + length ((a # list) @ y)) (pc + length (a # list))"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   329
    assume al: 
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   330
      "wtl_inst_list (a # list) G rT s0 s1 cert (pc + length ((a # list) @ y)) pc"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   331
    thus "wtl_inst_list ((a # list) @ y) G rT s0 s2 cert (pc + length ((a # list) @ y)) pc"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   332
      obtain s' where 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   333
       a: "wtl_inst_option a G rT s0 s' cert (Suc pc + length (list@y)) pc" and
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   334
       l: "wtl_inst_list list G rT s' s1 cert (Suc pc + length (list@y)) (Suc pc)" by auto      
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   335
      with y Cons
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   336
      have "wtl_inst_list (list @ y) G rT s' s2 cert (Suc pc + length (list @ y)) (Suc pc)"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   337
        by (elim allE impE) (assumption, simp+)
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   338
      with a
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   339
      show ?thesis by (auto simp del: split_paired_Ex)
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   340
    qed
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   341
  qed
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   342
qed
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   343
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   344
  with w
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   345
  show ?thesis 
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   346
  proof (elim allE impE)
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   347
    from w show "wtl_inst_list x G rT s0 s1 cert (0+length (x @ y)) 0" by simp
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   348
  qed simp+
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   349
qed
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   350
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   351
lemma wtl_cons_appendl:
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   352
"\\<lbrakk>wtl_inst_list a G rT s0 s1 cert (length (a@i#b)) 0; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   353
  wtl_inst_option i G rT s1 s2 cert (length (a@i#b)) (length a); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   354
  wtl_inst_list b G rT s2 s3 cert (length (a@i#b)) (Suc (length a))\\<rbrakk> \\<Longrightarrow> 
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   355
  wtl_inst_list (a@i#b) G rT s0 s3 cert (length (a@i#b)) 0"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   356
proof -
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   357
  assume a: "wtl_inst_list a G rT s0 s1 cert (length (a@i#b)) 0"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   358
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   359
  assume "wtl_inst_option i G rT s1 s2 cert (length (a@i#b)) (length a)"
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   360
         "wtl_inst_list b G rT s2 s3 cert (length (a@i#b)) (Suc (length a))"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   361
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   362
  hence "wtl_inst_list (i#b) G rT s1 s3 cert (length (a@i#b)) (length a)"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   363
    by (auto simp del: split_paired_Ex)
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   364
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   365
  with a
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   366
  show ?thesis by (rule wtl_append1)
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   367
qed
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   368
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   369
lemma "wtl_append":
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   370
"\\<lbrakk>wtl_inst_list a G rT s0 s1 cert (length (a@i#b)) 0; 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   371
  wtl_inst_option i G rT s1 s2 cert (length (a@i#b)) (length a); 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   372
  wtl_inst_list b G rT s2 s3 cert (length (a@i#b)) (Suc (length a))\\<rbrakk> \\<Longrightarrow> 
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   373
  wtl_inst_list (a@[i]) G rT s0 s2 cert (length (a@i#b)) 0"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   374
proof -
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   375
  assume a: "wtl_inst_list a G rT s0 s1 cert (length (a@i#b)) 0"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   376
  assume i: "wtl_inst_option i G rT s1 s2 cert (length (a@i#b)) (length a)"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   377
  assume b: "wtl_inst_list b G rT s2 s3 cert (length (a@i#b)) (Suc (length a))"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   378
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   379
  have "\\<forall> s0 pc. wtl_inst_list a G rT s0 s1 cert (pc+length (a@i#b)) pc \\<longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   380
        wtl_inst_option i G rT s1 s2 cert (pc+length (a@i#b)) (pc + length a) \\<longrightarrow> 
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   381
        wtl_inst_list b G rT s2 s3 cert (pc+length (a@i#b)) (Suc pc + length a) \\<longrightarrow> 
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   382
          wtl_inst_list (a@[i]) G rT s0 s2 cert (pc+length (a@i#b)) pc" (is "?P a")
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   383
  proof (induct "?P" "a")
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   384
    case Nil
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   385
    show "?P []" by (simp del: split_paired_Ex)
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   386
    case Cons
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   387
    show "?P (a#list)" (is "\\<forall>s0 pc. ?x s0 pc \\<longrightarrow> ?y s0 pc \\<longrightarrow> ?z s0 pc \\<longrightarrow> ?p s0 pc") 
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   388
    proof intro
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   389
      fix s0 pc
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   390
      assume y: "?y s0 pc"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   391
      assume z: "?z s0 pc"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   392
      assume "?x s0 pc"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   393
      thus "?p s0 pc"
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   394
        obtain s0' where opt: "wtl_inst_option a G rT s0 s0' cert (pc + length ((a # list) @ i # b)) pc"
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   395
                    and list: "wtl_inst_list list G rT s0' s1 cert (Suc pc + length (list @ i # b)) (Suc pc)"
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   396
          by (auto simp del: split_paired_Ex)
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   397
        with y z Cons
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   398
        have "wtl_inst_list (list @ [i]) G rT s0' s2 cert (Suc pc + length (list @ i # b)) (Suc pc)" 
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   399
        proof (elim allE impE) 
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   400
          from list show "wtl_inst_list list G rT s0' s1 cert (Suc pc + length (list @ i # b)) (Suc pc)" .
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   401
        qed auto
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   402
        with opt
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   403
        show ?thesis by (auto simp del: split_paired_Ex)
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   404
      qed
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   405
    qed
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   406
  qed
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   407
  with a i b
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   408
  show ?thesis 
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   409
  proof (elim allE impE)
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   410
    from a show "wtl_inst_list a G rT s0 s1 cert (0+length (a@i#b)) 0" by simp
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   411
  qed auto
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   412
qed
9012
d1bd2144ab5d switched to Isar proofs
kleing
parents: 8390
diff changeset
   413
9183
cd4494dc789a tuned for ProofGeneral 3.2
kleing
parents: 9054
diff changeset
   414
end