source: src/ASM/PolicyStep.ma @ 2242

Last change on this file since 2242 was 2242, checked in by sacerdot, 8 years ago

jump_expansion_step3 streamlined

File size: 86.1 KB
Line 
1include "ASM/PolicyFront.ma".
2include alias "basics/lists/list.ma".
3include alias "arithmetics/nat.ma".
4include alias "basics/logic.ma".
5
6lemma not_is_jump_to_destination_of_Nome:
7 ∀pi. ¬is_jump (Instruction pi) → destination_of pi = None ….
8 * try (#x #y #H) try (#y #H) try #H cases H %
9qed.
10
11lemma jump_expansion_step1:
12 ∀prefix: list labelled_instruction. S (|prefix|) < 2^16 → |prefix| < 2^16 → (*redundant*)
13 ∀labels: label_map.
14 ∀old_sigma : ppc_pc_map.
15 ∀inc_added : ℕ.
16 ∀inc_pc_sigma : ppc_pc_map.
17 ∀label : (option Identifier).
18 ∀instr : pseudo_instruction.
19 ∀inc_pc : ℕ.
20 ∀inc_sigma : (BitVectorTrie (ℕ×jump_length) 16).
21 ∀old_length : jump_length.
22 ∀Hpolicy : not_jump_default prefix 〈inc_pc,inc_sigma〉.
23 ∀policy : ppc_pc_map.
24 ∀new_length : jump_length.
25 ∀isize : ℕ.
26 let add_instr ≝ match instr with
27  [ Jmp  j        ⇒ Some ? (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
28  | Call c        ⇒ Some ? (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
29  | Instruction i ⇒ jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added (|prefix|) i
30  | _             ⇒ None ?
31  ] in
32 ∀Heq1 :
33  match add_instr with 
34   [None⇒〈short_jump,instruction_size_jmplen short_jump instr〉
35   |Some pl ⇒ 〈max_length old_length pl, instruction_size_jmplen (max_length old_length pl) instr〉]
36   =〈new_length,isize〉.
37 ∀Heq2 :
38   〈inc_pc+isize,
39     insert … (bitvector_of_nat … (S (|prefix|)))
40      〈inc_pc+isize, \snd  (lookup … (bitvector_of_nat … (S (|prefix|))) (\snd  old_sigma) 〈O,short_jump〉)〉
41      (insert … (bitvector_of_nat … (|prefix|)) 〈inc_pc,new_length〉 inc_sigma)〉
42   = policy.
43  not_jump_default (prefix@[〈label,instr〉]) policy.
44 #prefix #prefix_ok1 #prefix_ok #labels #old_sigma #inc_added #inc_pc_sigma #label #instr #inc_pc
45 #inc_sigma #old_length #Hpolicy #policy #new_length #isize #Heq1 #Heq2
46 #i >append_length <commutative_plus #Hi normalize in Hi;
47 cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
48 [ <Heq2 >lookup_insert_miss
49   [ >lookup_insert_miss
50     [ >(nth_append_first ? i prefix ?? Hi)
51       @(Hpolicy i Hi)
52     | @bitvector_of_nat_abs try assumption
53       [ @(transitive_lt ??? Hi) assumption ]
54       @lt_to_not_eq @Hi
55     ]
56   | @bitvector_of_nat_abs try assumption
57     [ @(transitive_lt ??? Hi) assumption ]
58     @lt_to_not_eq @le_S @Hi
59   ]
60 | <Heq2 >Hi >lookup_insert_miss
61   [ >lookup_insert_hit cases instr in Heq1;
62     [2,3,6: #x [3: #y] normalize nodelta #Heq1 <(proj1 ?? (pair_destruct ?????? Heq1)) #_ @refl
63     |4,5: #x normalize nodelta #Heq1 >nth_append_second try %
64           <minus_n_n #abs cases abs
65     |1: #pi normalize nodelta >nth_append_second [2: @le_n] <minus_n_n whd in match (nth ????);
66         #H #non_jump whd in match (jump_expansion_step_instruction ??????) in H;
67         >not_is_jump_to_destination_of_Nome in H; normalize nodelta // ]         
68   | @bitvector_of_nat_abs [3: // | @le_S_to_le ] assumption ]]
69qed.
70
71lemma jump_expansion_step2:
72 ∀prefix: list labelled_instruction. S (|prefix|) < 2^16 → |prefix| < 2^16 → (*redundant*)
73 ∀labels : label_map.
74 ∀old_sigma : ppc_pc_map.
75 ∀inc_pc : ℕ.
76 ∀inc_sigma : (BitVectorTrie (ℕ×jump_length) 16).
77 ∀Hpolicy1 :
78  \fst  (lookup … (bitvector_of_nat … O) inc_sigma 〈O,short_jump〉) = O.
79 ∀Hpolicy2:
80   inc_pc =\fst  (lookup … (bitvector_of_nat … (|prefix|)) inc_sigma 〈O,short_jump〉).
81 ∀policy : ppc_pc_map.
82 ∀new_length : jump_length.
83 ∀isize : ℕ.
84 ∀Heq2 :
85  〈inc_pc+isize,
86   insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
87   〈inc_pc+isize,
88   \snd  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
89               (\snd  old_sigma) 〈O,short_jump〉)〉
90   (insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
91    〈inc_pc,new_length〉 inc_sigma)〉
92   = policy.
93 \fst  (lookup … (bitvector_of_nat … O) (\snd  policy) 〈O,short_jump〉) = O.
94 #prefix #prefix_ok1 #prefix_ok #labels #old_sigma #inc_pc
95 #inc_sigma #Hpolicy1 #Hpolicy2 #policy #new_length #isize #Heq2
96 <Heq2 >lookup_insert_miss
97 [ cases (decidable_eq_nat 0 (|prefix|))
98   [ #Heq <Heq >lookup_insert_hit >Hpolicy2 <Heq @Hpolicy1
99   | #Hneq >lookup_insert_miss
100     [ @Hpolicy1
101     | @bitvector_of_nat_abs try assumption @lt_O_S ]]
102 | @bitvector_of_nat_abs [ @lt_O_S | @prefix_ok1 | 3: @lt_to_not_eq @lt_O_S ] ]
103qed.
104
105lemma destination_of_None_to_is_jump_false:
106 ∀instr. destination_of instr = None … → is_jump' instr = false.
107 * normalize // try (#H1 #H2 #abs) try (#H1 #abs) destruct(abs)
108qed.
109
110lemma destination_of_Some_to_is_jump_true:
111 ∀instr,dst. destination_of instr = Some … dst → is_jump' instr = true.
112 #instr #dst cases instr normalize // try (#H1 #H2 #abs) try (#H1 #abs) try #abs
113 destruct(abs)
114qed.
115
116lemma jump_expansion_step3:
117 ∀program.
118 ∀labels : label_map.
119 ∀old_sigma : Σpolicy:ppc_pc_map.not_jump_default program policy.
120 ∀prefix,x,tl. program=prefix@[x]@tl →
121 ∀inc_added : ℕ.
122 ∀inc_pc_sigma : ppc_pc_map.
123 ∀label : option Identifier.
124 ∀instr : pseudo_instruction.
125 ∀p1 : x≃〈label,instr〉.
126 ∀inc_pc : ℕ.
127 ∀inc_sigma : (BitVectorTrie (ℕ×jump_length) 16).
128 ∀old_pc : ℕ.
129 ∀old_length : jump_length.
130 ∀Holdeq :
131  lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) (\snd  old_sigma)
132   〈O,short_jump〉 =〈old_pc,old_length〉.
133 ∀Hpolicy : jump_increase prefix old_sigma 〈inc_pc,inc_sigma〉.
134 ∀policy : ppc_pc_map.
135 ∀new_length : jump_length.
136 ∀isize : ℕ.
137 ∀Heq1 :
138   match 
139   match instr
140    in pseudo_instruction
141    return λ_:pseudo_instruction.(option jump_length)
142    with 
143   [Instruction (i:(preinstruction Identifier))⇒
144    jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
145    (|prefix|) i
146   |Comment (_:String)⇒None jump_length
147   |Cost (_:costlabel)⇒None jump_length
148   |Jmp (j:Identifier)⇒
149    Some jump_length
150    (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
151   |Call (c:Identifier)⇒
152    Some jump_length
153    (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
154   |Mov (_:[[dptr]]) (_:Identifier)⇒None jump_length]
155    in option
156    return λ_:(option jump_length).(jump_length×ℕ)
157    with 
158   [None⇒〈short_jump,instruction_size_jmplen short_jump instr〉
159   |Some (pl:jump_length)⇒
160    〈max_length old_length pl,
161    instruction_size_jmplen (max_length old_length pl) instr〉]
162   =〈new_length,isize〉.
163 ∀prefix_ok1 : S (|prefix|)< 2 \sup 16.
164 ∀prefix_ok : |prefix|< 2 \sup 16.
165 ∀Heq2b :
166  〈inc_pc+isize,
167   insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
168   〈inc_pc+isize,
169   \snd  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
170               (\snd  old_sigma) 〈O,short_jump〉)〉
171   (insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
172    〈inc_pc,new_length〉 inc_sigma)〉
173   =policy.
174 jump_increase (prefix@[〈label,instr〉]) old_sigma policy.
175 #program #labels #old_sigma #prefix #x #tl #prf #inc_added #inc_pc_sigma #label
176 #instr #p1 #inc_pc #inc_sigma #old_pc #old_length #Holdeq #Hpolicy #policy #new_length
177 #isize #Heq1 #prefix_ok1 #prefix_ok #Heq2
178    #i >append_length >commutative_plus #Hi normalize in Hi;
179    cases (le_to_or_lt_eq … Hi) -Hi; #Hi
180    [ cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
181      [ (* USE[pass]: jump_increase *)
182        lapply (Hpolicy i (le_S_to_le … Hi))
183        <Heq2
184        @pair_elim #opc #oj #EQ1 >lookup_insert_miss
185        [ >lookup_insert_miss
186          [ @pair_elim #pc #j #EQ2 #X @X
187          | @bitvector_of_nat_abs
188            [ @(transitive_lt ??? Hi) ]
189            [1,2: assumption
190            | @lt_to_not_eq @Hi
191            ]
192          ]
193        | @bitvector_of_nat_abs
194          [ @(transitive_lt ??? Hi) @le_S_to_le ]
195          [1,2: assumption
196          | @lt_to_not_eq @le_S @Hi
197          ]
198        ]
199      | >Hi <Heq2 >Holdeq normalize nodelta
200        cut (|prefix| < |program|)
201        [ >prf >append_length <plus_n_Sm @le_S_S @le_plus_n_r ] #lt_prefix_program
202        >lookup_insert_miss
203        [ >lookup_insert_hit normalize nodelta
204          inversion instr in Heq1; normalize nodelta
205          [4,5: #x #_ #Heq1 <(proj1 ?? (pair_destruct ?????? Heq1)) @jmpleq_max_length
206          | #pi #Heqi whd in match jump_expansion_step_instruction; normalize nodelta
207            lapply (destination_of_None_to_is_jump_false pi)
208            lapply (destination_of_Some_to_is_jump_true pi)
209            cases (destination_of ?) normalize nodelta
210            [ #tgt #Hx
211            | #tgt #_ #_ #Heq1 <(proj1 ?? (pair_destruct ?????? Heq1)) @jmpleq_max_length
212            ]
213          |2,3,6: #x [3: #y] #Heqi ]
214          #Hj <(proj1 ?? (pair_destruct ?????? Hj))
215          lapply (pi2 ?? old_sigma (|prefix|) ??) try assumption
216          [1,3,5,7: >prf >nth_append_second try @le_n
217            <minus_n_n whd in match (nth ????); >p1 >Heqi
218            whd in match is_jump; normalize nodelta try % >Hx %
219          |*: >Holdeq #EQ2 >EQ2 %2 %]
220        | @bitvector_of_nat_abs
221          [ @le_S_to_le ]
222          [1,2: assumption
223          | @lt_to_not_eq @le_n
224          ]
225        ]
226      ]
227    | <Heq2 >Hi >lookup_insert_hit
228      normalize nodelta
229      cases (bvt_lookup … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma) 〈0,short_jump〉)
230      #a #b normalize nodelta %2 @refl
231    ]
232qed.
233
234lemma jump_expansion_step4:
235 ∀labels : label_map.
236 ∀old_sigma : ppc_pc_map.
237 ∀prefix : list (option Identifier×pseudo_instruction).
238 ∀inc_added : ℕ.
239 ∀inc_pc_sigma : ppc_pc_map.
240 ∀label : option Identifier.
241 ∀instr : pseudo_instruction.
242 ∀inc_pc : ℕ.
243 ∀inc_sigma : BitVectorTrie (ℕ×jump_length) 16.
244 ∀old_length : jump_length.
245 ∀Hpolicy1 : sigma_compact_unsafe prefix labels 〈inc_pc,inc_sigma〉.
246 ∀Hpolicy2: inc_pc
247    =\fst  (lookup … (bitvector_of_nat … (|prefix|)) inc_sigma
248                 〈O,short_jump〉).
249 ∀Hpolicy3: out_of_program_none prefix 〈inc_pc,inc_sigma〉.
250 ∀policy : ppc_pc_map.
251 ∀new_length : jump_length.
252 ∀isize : ℕ.
253 ∀Heq1 :
254  match 
255   match instr
256    in pseudo_instruction
257    return λ_:pseudo_instruction.(option jump_length)
258    with 
259   [Instruction (i:(preinstruction Identifier))⇒
260    jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
261    (|prefix|) i
262   |Comment (_:String)⇒None jump_length
263   |Cost (_:costlabel)⇒None jump_length
264   |Jmp (j:Identifier)⇒
265    Some jump_length
266    (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
267   |Call (c:Identifier)⇒
268    Some jump_length
269    (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
270   |Mov (_:[[dptr]])   (_:Identifier)⇒None jump_length]
271    in option
272    return λ_:(option jump_length).(jump_length×ℕ)
273    with 
274   [None⇒〈short_jump,instruction_size_jmplen short_jump instr〉
275   |Some (pl:jump_length)⇒
276    〈max_length old_length pl,
277    instruction_size_jmplen (max_length old_length pl) instr〉]
278   =〈new_length,isize〉.
279 ∀prefix_ok1 : S (|prefix|)< 2 \sup 16.
280 ∀prefix_ok : |prefix|< 2 \sup 16.
281 ∀Heq2b :
282   〈inc_pc+isize,
283   insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
284   〈inc_pc+isize,
285   \snd  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
286               (\snd  old_sigma) 〈O,short_jump〉)〉
287   (insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
288    〈inc_pc,new_length〉 inc_sigma)〉
289   =policy.
290 sigma_compact_unsafe (prefix@[〈label,instr〉]) labels policy.
291 #labels #old_sigma #prefix #inc_added #inc_pc_sigma #label #instr #inc_pc #inc_sigma
292 #old_length #Hpolicy1 #Hpolicy2 #Hpolicy3 #policy #new_length #isize
293 #Heq1 #prefix_ok1 #prefix_ok #Heq2b
294    #i >append_length <commutative_plus #Hi normalize in Hi;
295    <Heq2b
296    cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
297    [ >lookup_opt_insert_miss
298      [ >lookup_opt_insert_miss
299        [ >lookup_opt_insert_miss
300          [ cases (le_to_or_lt_eq … Hi) -Hi #Hi
301            [ >lookup_opt_insert_miss
302              [ (* USE[pass]: sigma_compact_unsafe *)
303                lapply (Hpolicy1 i ?)
304                [ @le_S_to_le @Hi ]
305                cases (bvt_lookup_opt … (bitvector_of_nat ? i) inc_sigma)
306                [ normalize nodelta #X @X
307                | #x cases x -x #x1 #x2
308                  cases (bvt_lookup_opt … (bitvector_of_nat ? (S i)) inc_sigma)
309                  normalize nodelta
310                  [ #X @X
311                  | #y cases y -y #y1 #y2 normalize nodelta >nth_append_first
312                    [ #X @X
313                    | @le_S_to_le @Hi
314                    ]
315                  ]
316                ]
317              | @bitvector_of_nat_abs
318                [3: @lt_to_not_eq @Hi ]
319              ]
320            | >Hi >lookup_opt_insert_hit normalize nodelta
321              (* USE[pass]: sigma_compact_unsafe *)
322              lapply (Hpolicy1 i ?)
323              [ <Hi @le_n
324              | cases (bvt_lookup_opt … (bitvector_of_nat ? i) inc_sigma)
325                [ normalize nodelta #X @X
326                | #x cases x -x #x1 #x2
327                  (* USE: inc_pc = fst inc_sigma *)
328                  lapply Hpolicy2
329                  <Hi lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (S i)) inc_sigma))
330                  cases (bvt_lookup_opt … (bitvector_of_nat ? (S i)) inc_sigma) in ⊢ (???% → %);
331                  [ normalize nodelta #_  #_ #H cases H
332                  | #y cases y -y #y1 #y2 #Heq >nth_append_first
333                    [ normalize nodelta >(lookup_opt_lookup_hit … Heq 〈0,short_jump〉)
334                      #Heq2 <Heq2 #X @X
335                    | <Hi @le_n]]]]]]]]
336      [3,4,5: @bitvector_of_nat_abs]
337      [ @(transitive_lt ??? (le_S_S … Hi))
338      |3: @lt_to_not_eq @le_S_S @Hi
339      |4,7,10: @(transitive_lt ??? Hi) assumption
340      |5,11: @le_S_to_le
341      |6: @lt_to_not_eq @Hi
342      |9: @lt_to_not_eq @le_S @Hi
343      ]
344      assumption
345    | >Hi >lookup_opt_insert_miss
346      [2: @bitvector_of_nat_abs try assumption @lt_to_not_eq % ]
347      >lookup_opt_insert_hit >lookup_opt_insert_hit normalize nodelta
348      (* USE: out_of_program_none ← *)
349      lapply (Hpolicy3 i ?)
350      [ >Hi assumption
351      | >Hi
352        (* USE: inc_pc = fst policy *)
353        lapply Hpolicy2
354        inversion (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) inc_sigma)
355        [ #Heq #_ #H @⊥ @(absurd (|prefix| > |prefix|))
356          [ cases H #_ #X @X %
357          | @le_to_not_lt @le_n]
358        | * #x1 #x2 #Heq #Hip #_ >nth_append_second
359          [2: @le_n] <minus_n_n whd in match (nth ????); normalize nodelta
360          >Hip >(lookup_opt_lookup_hit … Heq 〈0,short_jump〉)
361          cases instr in Heq1; normalize nodelta
362          [1: #pi cases (jump_expansion_step_instruction ??????) normalize nodelta]
363          try (#x #y #Heq1) try (#x #Heq1) try #Heq1
364          @eq_f <(proj2 ?? (pair_destruct ?????? Heq1))
365          try % <(proj1 ?? (pair_destruct ?????? Heq1)) %]]]
366qed.
367
368lemma jump_expansion_step5:
369 ∀labels : label_map.
370 ∀old_sigma : ppc_pc_map.
371 ∀prefix : list (option Identifier×pseudo_instruction).
372 ∀inc_added : ℕ.
373 ∀inc_pc_sigma : ppc_pc_map.
374 ∀label : option Identifier.
375 ∀instr : pseudo_instruction.
376 ∀inc_pc : ℕ.
377 ∀inc_sigma : BitVectorTrie (ℕ×jump_length) 16.
378 ∀old_pc : ℕ.
379 ∀old_length : jump_length.
380 ∀Holdeq :
381  lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) (\snd  old_sigma)
382   〈O,short_jump〉
383   =〈old_pc,old_length〉.
384 ∀Hpolicy1 : sigma_jump_equal prefix old_sigma 〈inc_pc,inc_sigma〉→inc_added=O.
385 ∀Hpolicy2: inc_pc
386    =\fst  (lookup … (bitvector_of_nat … (|prefix|)) inc_sigma 〈O,short_jump〉).
387 ∀added : ℕ.
388 ∀policy : ppc_pc_map.
389 ∀new_length : jump_length.
390 ∀isize : ℕ.
391 let add_instr ≝ match instr with
392  [ Jmp  j        ⇒ Some ? (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
393  | Call c        ⇒ Some ? (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
394  | Instruction i ⇒ jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added (|prefix|) i
395  | _             ⇒ None ?
396  ] in
397 ∀Heq1 :
398  match add_instr with 
399   [None⇒〈short_jump,instruction_size_jmplen short_jump instr〉
400   |Some (pl:jump_length)⇒
401    〈max_length old_length pl,
402    instruction_size_jmplen (max_length old_length pl) instr〉]
403   =〈new_length,isize〉.
404 ∀prefix_ok1 : S (|prefix|)< 2 \sup 16.
405 ∀prefix_ok : |prefix|< 2 \sup 16.
406 ∀Heq2a :
407  match add_instr with 
408   [None⇒inc_added
409   |Some (x0:jump_length)⇒
410    inc_added+(isize-instruction_size_jmplen old_length instr)]
411   =added.
412 ∀Heq2b :
413  〈inc_pc+isize,
414   insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
415   〈inc_pc+isize,
416   \snd  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
417               (\snd  old_sigma) 〈O,short_jump〉)〉
418   (insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
419    〈inc_pc,new_length〉 inc_sigma)〉
420   =policy.
421 sigma_jump_equal (prefix@[〈label,instr〉]) old_sigma policy→added=O.
422 #labels #old_sigma #prefix #inc_added #inc_pc #label #instr #inc_pc #inc_sigma
423 #old_pc #old_length #Holdeq #Hpolicy1 #Hpolicy2 #added #policy #new_length #isize
424 #Heq1 #prefix_ok1 #prefix_ok #Heq2a #Heq2b
425    <Heq2b #Heq <Heq2a
426    (* USE[pass]: policy_jump_equal → added = 0 *)
427    >Hpolicy1
428    [ cases instr in Heq1 Heq;
429      [2,3,6: #x [3: #y] normalize nodelta #_ #_ %
430      |1: #pi normalize nodelta whd in match jump_expansion_step_instruction;
431          normalize nodelta cases (destination_of ?) normalize nodelta [#_ #_ %]]
432      #x normalize nodelta #Heq1 <(proj2 ?? (pair_destruct ?????? Heq1))
433      #Heq (*CSC: make a lemma here!*) lapply Holdeq -Holdeq
434      (* USE: inc_pc = fst inc_sigma *)
435      >Hpolicy2
436      lapply (Heq (|prefix|) ?)
437      [1,3,5: >append_length <plus_n_Sm @le_S_S @le_plus_n_r]
438      -Heq >lookup_insert_miss
439      [1,3,5: >lookup_insert_hit <(proj1 ?? (pair_destruct ?????? Heq1))
440        #Heq <Heq cases (bvt_lookup … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma) 〈0,short_jump〉)
441        #y #z #Hyz >(proj2 ?? (pair_destruct ?????? Hyz)) <minus_n_n %
442      |*: @bitvector_of_nat_abs try assumption @lt_to_not_eq %]
443    | #i #Hi lapply (Heq i ?)
444      [ >append_length <plus_n_Sm @le_S <plus_n_O @Hi
445      | >lookup_insert_miss
446        [ >lookup_insert_miss
447          [ #X @X
448          | @bitvector_of_nat_abs [ @(transitive_lt ??? Hi) ] try assumption
449            @lt_to_not_eq @Hi]
450        | @bitvector_of_nat_abs [ @(transitive_lt ??? Hi) ] try assumption
451          @lt_to_not_eq @le_S @Hi ]]]
452qed.
453
454lemma jump_expansion_step6:
455(*
456 program :
457  (Σl:list labelled_instruction.S (|l|)< 2 \sup 16 ∧is_well_labelled_p l)
458 labels :
459  (Σlm:label_map
460   .(∀l:identifier ASMTag
461     .occurs_exactly_once ASMTag pseudo_instruction l program
462      →bitvector_of_nat 16 (lookup_def ASMTag ℕ lm l O)
463       =address_of_word_labels_code_mem program l))*)
464 ∀old_sigma : ppc_pc_map.(*
465  (Σpolicy:ppc_pc_map
466   .not_jump_default program policy
467    ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) (\snd  policy)
468                 〈O,short_jump〉)
469     =O
470    ∧\fst  policy
471     =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|program|))
472                  (\snd  policy) 〈O,short_jump〉)
473    ∧sigma_compact_unsafe program labels policy
474    ∧\fst  policy≤ 2 \sup 16 )*)
475 ∀prefix : list (option Identifier×pseudo_instruction).(*
476 x : (option Identifier×pseudo_instruction)
477 tl : (list (option Identifier×pseudo_instruction))
478 prf : (program=prefix@[x]@tl)
479 acc :
480  (Σx0:ℕ×ppc_pc_map
481   .(let 〈added,policy〉 ≝x0 in 
482     not_jump_default prefix policy
483     ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) (\snd  policy)
484                  〈O,short_jump〉)
485      =O
486     ∧\fst  policy
487      =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
488                   (\snd  policy) 〈O,short_jump〉)
489     ∧jump_increase prefix old_sigma policy
490     ∧sigma_compact_unsafe prefix labels policy
491     ∧(sigma_jump_equal prefix old_sigma policy→added=O)
492     ∧(added=O→sigma_pc_equal prefix old_sigma policy)
493     ∧out_of_program_none prefix policy
494     ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
495                  (\snd  policy) 〈O,short_jump〉)
496      =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
497                   (\snd  old_sigma) 〈O,short_jump〉)
498       +added
499     ∧sigma_safe prefix labels added old_sigma policy))
500 inc_added : ℕ
501 inc_pc_sigma : ppc_pc_map
502 p : (acc≃〈inc_added,inc_pc_sigma〉)*)
503 ∀label : option Identifier.
504 ∀instr : pseudo_instruction.(*
505 p1 : (x≃〈label,instr〉)
506 add_instr ≝
507  match instr
508   in pseudo_instruction
509   return λ_:pseudo_instruction.(option jump_length)
510   with 
511  [Instruction (i:(preinstruction Identifier))⇒
512   jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
513   (|prefix|) i
514  |Comment (_:String)⇒None jump_length
515  |Cost (_:costlabel)⇒None jump_length
516  |Jmp (j:Identifier)⇒
517   Some jump_length
518   (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
519  |Call (c:Identifier)⇒
520   Some jump_length
521   (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
522  |Mov (_:[[dptr]])   (_0:Identifier)⇒None jump_length]
523 inc_pc : ℕ
524 inc_sigma : (BitVectorTrie (ℕ×jump_length) 16)
525 Hips : (inc_pc_sigma=〈inc_pc,inc_sigma〉)
526 old_pc : ℕ
527 old_length : jump_length
528 Holdeq :
529  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) (\snd  old_sigma)
530   〈O,short_jump〉
531   =〈old_pc,old_length〉)
532 Hpolicy :
533  (not_jump_default prefix 〈inc_pc,inc_sigma〉
534   ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) inc_sigma
535                〈O,short_jump〉)
536    =O
537   ∧inc_pc
538    =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) inc_sigma
539                 〈O,short_jump〉)
540   ∧jump_increase prefix old_sigma 〈inc_pc,inc_sigma〉
541   ∧sigma_compact_unsafe prefix labels 〈inc_pc,inc_sigma〉
542   ∧(sigma_jump_equal prefix old_sigma 〈inc_pc,inc_sigma〉→inc_added=O)
543   ∧(inc_added=O→sigma_pc_equal prefix old_sigma 〈inc_pc,inc_sigma〉)
544   ∧out_of_program_none prefix 〈inc_pc,inc_sigma〉
545   ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) inc_sigma
546                〈O,short_jump〉)
547    =old_pc+inc_added
548   ∧sigma_safe prefix labels inc_added old_sigma 〈inc_pc,inc_sigma〉)*)
549 ∀added : ℕ.
550 ∀policy : ppc_pc_map.(*
551 new_length : jump_length
552 isize : ℕ
553 Heq1 :
554  (match 
555   match instr
556    in pseudo_instruction
557    return λ_:pseudo_instruction.(option jump_length)
558    with 
559   [Instruction (i:(preinstruction Identifier))⇒
560    jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
561    (|prefix|) i
562   |Comment (_:String)⇒None jump_length
563   |Cost (_:costlabel)⇒None jump_length
564   |Jmp (j:Identifier)⇒
565    Some jump_length
566    (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
567   |Call (c:Identifier)⇒
568    Some jump_length
569    (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
570   |Mov (_:[[dptr]])   (_0:Identifier)⇒None jump_length]
571    in option
572    return λ_0:(option jump_length).(jump_length×ℕ)
573    with 
574   [None⇒〈short_jump,instruction_size_jmplen short_jump instr〉
575   |Some (pl:jump_length)⇒
576    〈max_length old_length pl,
577    instruction_size_jmplen (max_length old_length pl) instr〉]
578   =〈new_length,isize〉)
579 prefix_ok1 : (S (|prefix|)< 2 \sup 16 )
580 prefix_ok : (|prefix|< 2 \sup 16 )
581 Heq2a :
582  (match 
583   match instr
584    in pseudo_instruction
585    return λ_0:pseudo_instruction.(option jump_length)
586    with 
587   [Instruction (i:(preinstruction Identifier))⇒
588    jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
589    (|prefix|) i
590   |Comment (_0:String)⇒None jump_length
591   |Cost (_0:costlabel)⇒None jump_length
592   |Jmp (j:Identifier)⇒
593    Some jump_length
594    (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
595   |Call (c:Identifier)⇒
596    Some jump_length
597    (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
598   |Mov (_0:[[dptr]])   (_00:Identifier)⇒None jump_length]
599    in option
600    return λ_0:(option jump_length).ℕ
601    with 
602   [None⇒inc_added
603   |Some (x0:jump_length)⇒
604    inc_added+(isize-instruction_size_jmplen old_length instr)]
605   =added)
606 Heq2b :
607  (〈inc_pc+isize,
608   insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
609   〈inc_pc+isize,
610   \snd  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
611               (\snd  old_sigma) 〈O,short_jump〉)〉
612   (insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
613    〈inc_pc,new_length〉 inc_sigma)〉
614   =policy)
615*)
616 added=O→sigma_pc_equal (prefix@[〈label,instr〉]) old_sigma policy.
617cases daemon(*
618    (* USE[pass]: added = 0 → policy_pc_equal *)
619     lapply (proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))
620    <(proj2 ?? (pair_destruct ?????? Heq2))
621    <(proj1 ?? (pair_destruct ?????? Heq2))
622    lapply Heq1 -Heq1 lapply (refl ? instr)
623    cases instr in ⊢ (???% → % → %); normalize nodelta
624    [2,3,6: #x [3: #y] #Hins #Heq1 #Hold #Hadded #i >append_length >commutative_plus
625      #Hi normalize in Hi;
626      cases (le_to_or_lt_eq … Hi) -Hi #Hi
627      [1,3,5: cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
628        [1,3,5: <(proj2 ?? (pair_destruct ?????? Heq2)) >lookup_insert_miss
629          [1,3,5: >lookup_insert_miss
630            [1,3,5: @(Hold Hadded i (le_S_to_le … Hi))
631            |2,4,6: @bitvector_of_nat_abs
632              [3,6,9: @lt_to_not_eq @Hi
633              |1,4,7: @(transitive_lt ??? Hi)
634              ]
635              @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf >append_length
636              @le_S_S <plus_n_Sm @le_S @le_plus_n_r
637            ]
638          |2,4,6: @bitvector_of_nat_abs
639            [3,6,9: @lt_to_not_eq @le_S @Hi
640            |1,4,7: @(transitive_lt … Hi) @le_S_to_le
641            ]
642            @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf >append_length
643              @le_S_S <plus_n_Sm @le_S_S @le_plus_n_r
644          ]
645        |2,4,6: >Hi >lookup_insert_miss
646          [1,3,5: >lookup_insert_hit >(Hold Hadded (|prefix|) (le_n (|prefix|)))
647            @sym_eq (* USE: fst p = lookup |prefix| *)
648            @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
649          |2,4,6: @bitvector_of_nat_abs
650            [3,6,9: @lt_to_not_eq @le_n
651            |1,4,7: @le_S_to_le
652            ]
653            @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf >append_length
654              @le_S_S <plus_n_Sm @le_S_S @le_plus_n_r
655          ]
656        ]
657      |2,4,6: >Hi >lookup_insert_hit
658        (* USE fst p = lookup |prefix| *)
659        >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
660        <(Hold Hadded (|prefix|) (le_n (|prefix|)))
661        (* USE: sigma_compact (from old_sigma) *)
662        lapply (proj2 ?? (proj1 ?? (pi2 ?? old_sigma)) (|prefix|) ?)
663        [1,3,5: >prf >append_length <plus_n_Sm @le_S_S @le_plus_n_r
664        |2,4,6:
665          lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)))
666          cases (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)) in ⊢ (???% -> %);
667          [1,3,5: normalize nodelta #_ #ABS cases ABS
668          |2,4,6: lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)))
669            cases (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)) in ⊢ (???% → %);
670            [1,3,5: normalize nodelta #Hl #x cases x -x #pc #j normalize nodelta #Hl2 #ABS cases ABS
671            |2,4,6: normalize nodelta #x cases x -x #Spc #Sj #EQS #x cases x -x #pc #j #EQ
672              normalize nodelta >(lookup_opt_lookup_hit … EQS 〈0,short_jump〉)
673              >(lookup_opt_lookup_hit … EQ 〈0,short_jump〉)
674              >prf >p1 >Hins >nth_append_second
675              [2,4,6: @(le_n (|prefix|))
676              |1,3,5: <minus_n_n whd in match (nth ????); <(proj2 ?? (pair_destruct ?????? Heq1))
677                 #H >H @plus_left_monotone @instruction_size_irrelevant @nmk / by /
678              ]
679            ]
680          ]
681        ]
682      ]
683    |4,5: #x #Hins #Heq1 #Hold #Hadded #i >append_length >commutative_plus
684       #Hi normalize in Hi; cases (le_to_or_lt_eq … Hi) -Hi #Hi
685       [1,3: cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
686         [1,3: >lookup_insert_miss
687           [1,3: >lookup_insert_miss
688             [1,3: @(Hold ? i (le_S_to_le … Hi)) >commutative_plus in Hadded;
689               @plus_zero_zero
690             |2,4: @bitvector_of_nat_abs
691               [3,6: @lt_to_not_eq @Hi
692               |1,4: @(transitive_lt ??? Hi)
693               ]
694               @(transitive_lt … (proj1 ?? (pi2 ?? program))) @le_S_S >prf
695               >append_length @le_plus_n_r
696             ]
697           |2,4: @bitvector_of_nat_abs
698             [3,6: @lt_to_not_eq @le_S @Hi
699             |1,4: @(transitive_lt ??? Hi) @le_S_to_le
700             ]
701             @(transitive_lt … (proj1 ?? (pi2 ?? program))) @le_S_S >prf
702             >append_length <plus_n_Sm @le_S_S @le_plus_n_r
703           ]
704         |2,4: >Hi >lookup_insert_miss
705           [1,3: >lookup_insert_hit >(Hold ? (|prefix|) (le_n (|prefix|)))
706             [2,4: >commutative_plus in Hadded; @plus_zero_zero] @sym_eq
707             (* USE: fst p = lookup |prefix| *)
708             @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
709           |2,4: @bitvector_of_nat_abs
710             [3,6: @lt_to_not_eq @le_n
711             |1,4: @(transitive_lt ??? (le_S_S … (le_n (|prefix|))))
712             ]
713             @(transitive_lt … (proj1 ?? (pi2 ?? program))) @le_S_S >prf
714             >append_length <plus_n_Sm @le_S_S @le_plus_n_r
715           ]
716         ]
717       |2,4: >Hi >lookup_insert_hit <(proj2 ?? (pair_destruct ?????? Heq1))
718         elim (le_to_or_lt_eq … (minus_zero_to_le … (plus_zero_zero … Hadded)))
719         [1,3: #H @⊥ @(absurd ? H) @le_to_not_lt <(proj2 ?? (pair_destruct ?????? Heq1))
720           @jump_length_le_max / by I/
721         |2,4: #H (* USE: fst p = lookup |prefix| *)
722           >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
723           <(Hold ? (|prefix|) (le_n (|prefix|)))
724           [1,3: <(proj2 ?? (pair_destruct ?????? Heq1)) in H; #H
725             >(jump_length_equal_max … H)
726             [1,3: (* USE: sigma_compact_unsafe (from old_sigma) *)
727               lapply (proj2 ?? (proj1 ?? (pi2 ?? old_sigma)) (|prefix|) ?)
728               [1,3: >prf >append_length <plus_n_Sm @le_S_S @le_plus_n_r
729               |2,4: lapply Holdeq lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)))
730                 cases (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)) in ⊢ (???% → %);
731                 [1,3: normalize nodelta #_ #_ #ABS cases ABS
732                 |2,4: normalize nodelta
733                   lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)))
734                   cases (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)) in ⊢ (???% → %);
735                   [1,3: #_ #x cases x -x #pc #j normalize nodelta #_ #_ #ABS cases ABS
736                   |2,4: #x cases x -x #Spc #Sj #EQS #x cases x -x #pc #j #EQ
737                     normalize nodelta >(lookup_opt_lookup_hit … EQ 〈0,short_jump〉)
738                     >(lookup_opt_lookup_hit … EQS 〈0,short_jump〉) #EQpair
739                     >(proj2 ?? (pair_destruct ?????? EQpair)) >prf >nth_append_second
740                     [1,3: <minus_n_n >p1 whd in match (nth ????); >Hins #H @H
741                     |2,4: @le_n
742                     ]
743                   ]
744                 ]
745               ]
746             |2,4: / by I/
747             ]
748           |2,4: @plus_zero_zero [2,4: >commutative_plus @Hadded]
749           ]
750         ]
751       ]
752     |1: #pi cases pi normalize nodelta
753      [1,2,3,4,5,6,7,8,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37:
754        [1,2,3,6,7,24,25: #x #y
755        |4,5,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23: #x]
756        #Hins #Heq1 #Hold #Hadded #i >append_length >commutative_plus #Hi normalize in Hi;
757        cases (le_to_or_lt_eq … Hi) -Hi #Hi
758        [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55:
759          cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
760          [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55:
761            <(proj2 ?? (pair_destruct ?????? Heq2))
762            >(lookup_insert_miss (ℕ×jump_length) 〈0,short_jump〉 〈inc_pc+isize,?〉 16 (bitvector_of_nat 16 (S (|prefix|))) (bitvector_of_nat 16 i))
763            [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55:
764              >(lookup_insert_miss (ℕ×jump_length) 〈0,short_jump〉 〈inc_pc,new_length〉 16 (bitvector_of_nat 16 (|prefix|)) (bitvector_of_nat 16 i) inc_sigma)
765              [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55:
766                @(Hold Hadded i (le_S_to_le … Hi))
767              |2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56:
768                @bitvector_of_nat_abs
769                [3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84:
770                  @lt_to_not_eq @Hi
771                |1,4,7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58,61,64,67,70,73,76,79,82:
772                  @(transitive_lt ??? Hi)
773                ]
774                @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf >append_length
775                @le_S_S <plus_n_Sm @le_S @le_plus_n_r
776              ]
777            |2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56:
778              @bitvector_of_nat_abs
779              [3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84:
780                @lt_to_not_eq @le_S @Hi
781              |1,4,7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58,61,64,67,70,73,76,79,82:
782                @(transitive_lt … Hi) @le_S_to_le
783              ]
784              @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf >append_length
785              @le_S_S <plus_n_Sm @le_S_S @le_plus_n_r
786            ]
787          |2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56:
788            >Hi >(lookup_insert_miss (ℕ×jump_length) 〈0,short_jump〉 〈inc_pc+isize,?〉 16 (bitvector_of_nat 16 (S (|prefix|))) (bitvector_of_nat 16 (|prefix|)))
789            [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55:
790              >lookup_insert_hit >(Hold Hadded (|prefix|) (le_n (|prefix|))) @sym_eq
791              (* USE: fst p = lookup |prefix| *)
792              @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
793            |2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56:
794              @bitvector_of_nat_abs
795              [3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84:
796                @lt_to_not_eq @le_n
797              |1,4,7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58,61,64,67,70,73,76,79,82:
798                @le_S_to_le
799              ]
800              @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf >append_length
801                @le_S_S <plus_n_Sm @le_S_S @le_plus_n_r
802            ]
803          ]
804        |2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56:
805          >Hi >lookup_insert_hit
806          (* USE fst p = lookup |prefix| *)
807          >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
808          <(Hold Hadded (|prefix|) (le_n (|prefix|)))
809          (* USE: sigma_compact (from old_sigma) *)
810          lapply (proj2 ?? (proj1 ?? (pi2 ?? old_sigma)) (|prefix|) ?)
811          [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55:
812            >prf >append_length <plus_n_Sm @le_S_S @le_plus_n_r
813          |2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56:
814            lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)))
815            cases (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)) in ⊢ (???% -> %);
816            [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55:
817              normalize nodelta #_ #ABS cases ABS
818            |2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56:
819              lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)))
820              cases (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)) in ⊢ (???% → %);
821              [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55:
822                normalize nodelta #Hl #x cases x -x #pc #j normalize nodelta #Hl2 #ABS cases ABS
823              |2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56:
824                normalize nodelta #x cases x -x #Spc #Sj #EQS #x cases x -x #pc #j #EQ
825                normalize nodelta >(lookup_opt_lookup_hit … EQS 〈0,short_jump〉)
826                >(lookup_opt_lookup_hit … EQ 〈0,short_jump〉)
827                >prf >p1 >Hins >nth_append_second
828                [2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56:
829                  @(le_n (|prefix|))
830                |1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55:
831                  <minus_n_n whd in match (nth ????); <(proj2 ?? (pair_destruct ?????? Heq1))
832                  #H >H @plus_left_monotone @instruction_size_irrelevant @nmk #H @H
833                ]
834              ]
835            ]
836          ]
837        ]
838      |9,10,11,12,13,14,15,16,17: #x [3,4,5,8,9: #y] #Hins #Heq1 #Hold #Hadded
839        #i >append_length >commutative_plus #Hi normalize in Hi; cases (le_to_or_lt_eq … Hi)
840        -Hi #Hi
841        [1,3,5,7,9,11,13,15,17: cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
842          [1,3,5,7,9,11,13,15,17:
843            >(lookup_insert_miss (ℕ×jump_length) 〈0,short_jump〉 〈inc_pc+isize,?〉 16 (bitvector_of_nat 16 (S (|prefix|))) (bitvector_of_nat 16 i))
844            [1,3,5,7,9,11,13,15,17:
845              >(lookup_insert_miss (ℕ×jump_length) 〈0,short_jump〉 〈inc_pc,new_length〉 16 (bitvector_of_nat 16 (|prefix|)) (bitvector_of_nat 16 i) inc_sigma)
846              [1,3,5,7,9,11,13,15,17: @(Hold ? i (le_S_to_le … Hi))
847                >commutative_plus in Hadded; @plus_zero_zero
848              |2,4,6,8,10,12,14,16,18: @bitvector_of_nat_abs
849                [3,6,9,12,15,18,21,24,27: @lt_to_not_eq @Hi
850                |1,4,7,10,13,16,19,22,25: @(transitive_lt ??? Hi)
851                ]
852                @(transitive_lt … (proj1 ?? (pi2 ?? program))) @le_S_S >prf
853                >append_length @le_plus_n_r
854              ]
855            |2,4,6,8,10,12,14,16,18: @bitvector_of_nat_abs
856              [3,6,9,12,15,18,21,24,27: @lt_to_not_eq @le_S @Hi
857              |1,4,7,10,13,16,19,22,25: @(transitive_lt ??? Hi) @le_S_to_le
858              ]
859              @(transitive_lt … (proj1 ?? (pi2 ?? program))) @le_S_S >prf
860              >append_length <plus_n_Sm @le_S_S @le_plus_n_r
861            ]
862          |2,4,6,8,10,12,14,16,18: >Hi
863            >(lookup_insert_miss (ℕ×jump_length) 〈0,short_jump〉 〈inc_pc+isize,?〉 16 (bitvector_of_nat 16 (S (|prefix|))) (bitvector_of_nat 16 (|prefix|)))
864            [1,3,5,7,9,11,13,15,17: >lookup_insert_hit >(Hold ? (|prefix|) (le_n (|prefix|)))
865              [2,4,6,8,10,12,14,16,18: >commutative_plus in Hadded; @plus_zero_zero] @sym_eq
866              (* USE: fst p = lookup |prefix| *)
867              @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
868            |2,4,6,8,10,12,14,16,18: @bitvector_of_nat_abs
869              [3,6,9,12,15,18,21,24,27: @lt_to_not_eq @le_n
870              |1,4,7,10,13,16,19,22,25: @(transitive_lt ??? (le_S_S … (le_n (|prefix|))))
871              ]
872              @(transitive_lt … (proj1 ?? (pi2 ?? program))) @le_S_S >prf
873              >append_length <plus_n_Sm @le_S_S @le_plus_n_r
874            ]
875          ]
876        |2,4,6,8,10,12,14,16,18: >Hi >lookup_insert_hit <(proj2 ?? (pair_destruct ?????? Heq1))
877          elim (le_to_or_lt_eq … (minus_zero_to_le … (plus_zero_zero … Hadded)))
878          [1,3,5,7,9,11,13,15,17: #H @⊥ @(absurd ? H) @le_to_not_lt
879            <(proj2 ?? (pair_destruct ?????? Heq1)) @jump_length_le_max / by I/
880          |2,4,6,8,10,12,14,16,18: #H (* USE: fst p = lookup |prefix| *)
881            >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))
882            <(Hold ? (|prefix|) (le_n (|prefix|)))
883            [1,3,5,7,9,11,13,15,17: <(proj2 ?? (pair_destruct ?????? Heq1)) in H; #H
884              >(jump_length_equal_max … H)
885              [1,3,5,7,9,11,13,15,17: (* USE: sigma_compact_unsafe (from old_sigma) *)
886                lapply (proj2 ?? (proj1 ?? (pi2 ?? old_sigma)) (|prefix|) ?)
887                [1,3,5,7,9,11,13,15,17: >prf >append_length <plus_n_Sm @le_S_S @le_plus_n_r
888                |2,4,6,8,10,12,14,16,18: lapply Holdeq
889                  lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)))
890                  cases (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)) in ⊢ (???% → %);
891                  [1,3,5,7,9,11,13,15,17: normalize nodelta #_ #_ #ABS cases ABS
892                  |2,4,6,8,10,12,14,16,18: normalize nodelta
893                    lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)))
894                    cases (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)) in ⊢ (???% → %);
895                    [1,3,5,7,9,11,13,15,17: #_ #x cases x -x #pc #j normalize nodelta
896                      #_ #_ #ABS cases ABS
897                    |2,4,6,8,10,12,14,16,18: #x cases x -x #Spc #Sj #EQS #x cases x -x
898                      #pc #j #EQ
899                      normalize nodelta >(lookup_opt_lookup_hit … EQ 〈0,short_jump〉)
900                      >(lookup_opt_lookup_hit … EQS 〈0,short_jump〉) #EQpair
901                      >(proj2 ?? (pair_destruct ?????? EQpair)) >prf >nth_append_second
902                      [1,3,5,7,9,11,13,15,17: <minus_n_n >p1 whd in match (nth ????); >Hins #H @H
903                      |2,4,6,8,10,12,14,16,18: @le_n
904                      ]
905                    ]
906                  ]
907                ]
908              |2,4,6,8,10,12,14,16,18: / by I/
909              ]
910            |2,4,6,8,10,12,14,16,18: @plus_zero_zero
911              [2,4,6,8,10,12,14,16,18: >commutative_plus @Hadded]
912            ]
913          ]
914        ]
915      ]
916    ]*)
917qed.
918
919lemma jump_expansion_step7:
920 ∀old_sigma : ppc_pc_map.
921 ∀prefix : list (option Identifier×pseudo_instruction).
922 ∀label : option Identifier.
923 ∀instr : pseudo_instruction.
924 ∀inc_pc : ℕ.
925 ∀inc_sigma : BitVectorTrie (ℕ×jump_length) 16.
926 ∀Hpolicy1 : out_of_program_none prefix 〈inc_pc,inc_sigma〉.
927 ∀policy : ppc_pc_map.
928 ∀new_length : jump_length.
929 ∀isize : ℕ.
930 ∀Heq2b :
931  〈inc_pc+isize,
932   insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
933   〈inc_pc+isize,
934   \snd  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
935               (\snd  old_sigma) 〈O,short_jump〉)〉
936   (insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
937    〈inc_pc,new_length〉 inc_sigma)〉
938   =policy.
939 out_of_program_none (prefix@[〈label,instr〉]) policy.
940 #old_sigma #prefix #label #instr #inc_pc #inc_sigma #Hpolicy1 #policy #new_length
941 #isize #Heq2b
942    #i #Hi2 >append_length <commutative_plus @conj
943    [ (* → *) #Hi normalize in Hi; <Heq2b >lookup_opt_insert_miss
944      [ >lookup_opt_insert_miss
945        [ cases (Hpolicy1 i Hi2) #X #_ @X @le_S_to_le @Hi
946        | @bitvector_of_nat_abs try assumption
947          [ @(transitive_lt … Hi2) @le_S_to_le assumption
948          | % #EQ <EQ in Hi; #abs @(absurd ?? (not_le_Sn_n (S i)))
949            @(transitive_le … abs) %2 % ]]
950      | @bitvector_of_nat_abs try assumption
951          [ @(transitive_lt … Hi2) assumption
952          | % #EQ <EQ in Hi; #abs @(absurd ?? (not_le_Sn_n i)) assumption ]]
953    | (* ← *) <Heq2b #Hl normalize
954      @(leb_elim (S i) (|prefix|))
955      [ #Hi
956        lapply (proj2 ?? (insert_lookup_opt_miss ?????? (proj2 ?? (insert_lookup_opt_miss ?????? Hl))))
957        #Hl2 (* USE[pass]: out_of_program_none ← *)
958        cases (Hpolicy1 i Hi2) #_
959        #Hi3 @⊥ @(absurd ? Hi) @le_to_not_lt @le_S_to_le @Hi3 assumption
960      | #Hi elim (le_to_or_lt_eq … (not_lt_to_le … Hi))
961        [ #Hi3 elim (le_to_or_lt_eq … Hi3)
962          [ #X @X
963          | #X lapply (proj1 ?? (insert_lookup_opt_miss ?????? Hl)) >X >eq_bv_refl #H normalize in H; destruct (H)
964          ]
965        | #X lapply (proj1 ?? (insert_lookup_opt_miss ?????? (proj2 ?? (insert_lookup_opt_miss ?????? Hl))))
966          >X >eq_bv_refl #H normalize in H; destruct (H)]]]
967qed.
968
969lemma jump_expansion_step8:
970(*
971 program :
972  (Σl:list labelled_instruction.S (|l|)< 2 \sup 16 ∧is_well_labelled_p l)
973 labels :
974  (Σlm:label_map
975   .(∀l:identifier ASMTag
976     .occurs_exactly_once ASMTag pseudo_instruction l program
977      →bitvector_of_nat 16 (lookup_def ASMTag ℕ lm l O)
978       =address_of_word_labels_code_mem program l))*)
979 ∀old_sigma : ppc_pc_map.(*
980  (Σpolicy:ppc_pc_map
981   .not_jump_default program policy
982    ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) (\snd  policy)
983                 〈O,short_jump〉)
984     =O
985    ∧\fst  policy
986     =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|program|))
987                  (\snd  policy) 〈O,short_jump〉)
988    ∧sigma_compact_unsafe program labels policy
989    ∧\fst  policy≤ 2 \sup 16 )*)
990 ∀prefix : list (option Identifier×pseudo_instruction).(*
991 x : (option Identifier×pseudo_instruction)
992 tl : (list (option Identifier×pseudo_instruction))
993 prf : (program=prefix@[x]@tl)
994 acc :
995  (Σx0:ℕ×ppc_pc_map
996   .(let 〈added,policy〉 ≝x0 in 
997     not_jump_default prefix policy
998     ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) (\snd  policy)
999                  〈O,short_jump〉)
1000      =O
1001     ∧\fst  policy
1002      =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
1003                   (\snd  policy) 〈O,short_jump〉)
1004     ∧jump_increase prefix old_sigma policy
1005     ∧sigma_compact_unsafe prefix labels policy
1006     ∧(sigma_jump_equal prefix old_sigma policy→added=O)
1007     ∧(added=O→sigma_pc_equal prefix old_sigma policy)
1008     ∧out_of_program_none prefix policy
1009     ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
1010                  (\snd  policy) 〈O,short_jump〉)
1011      =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
1012                   (\snd  old_sigma) 〈O,short_jump〉)
1013       +added
1014     ∧sigma_safe prefix labels added old_sigma policy))
1015 inc_added : ℕ
1016 inc_pc_sigma : ppc_pc_map
1017 p : (acc≃〈inc_added,inc_pc_sigma〉)*)
1018 ∀label : option Identifier.
1019 ∀instr : pseudo_instruction.(*
1020 p1 : (x≃〈label,instr〉)
1021 add_instr ≝
1022  match instr
1023   in pseudo_instruction
1024   return λ_:pseudo_instruction.(option jump_length)
1025   with 
1026  [Instruction (i:(preinstruction Identifier))⇒
1027   jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
1028   (|prefix|) i
1029  |Comment (_:String)⇒None jump_length
1030  |Cost (_:costlabel)⇒None jump_length
1031  |Jmp (j:Identifier)⇒
1032   Some jump_length
1033   (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
1034  |Call (c:Identifier)⇒
1035   Some jump_length
1036   (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
1037  |Mov (_:[[dptr]])   (_0:Identifier)⇒None jump_length]
1038 inc_pc : ℕ
1039 inc_sigma : (BitVectorTrie (ℕ×jump_length) 16)
1040 Hips : (inc_pc_sigma=〈inc_pc,inc_sigma〉)
1041 old_pc : ℕ
1042 old_length : jump_length
1043 Holdeq :
1044  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) (\snd  old_sigma)
1045   〈O,short_jump〉
1046   =〈old_pc,old_length〉)
1047 Hpolicy :
1048  (not_jump_default prefix 〈inc_pc,inc_sigma〉
1049   ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) inc_sigma
1050                〈O,short_jump〉)
1051    =O
1052   ∧inc_pc
1053    =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) inc_sigma
1054                 〈O,short_jump〉)
1055   ∧jump_increase prefix old_sigma 〈inc_pc,inc_sigma〉
1056   ∧sigma_compact_unsafe prefix labels 〈inc_pc,inc_sigma〉
1057   ∧(sigma_jump_equal prefix old_sigma 〈inc_pc,inc_sigma〉→inc_added=O)
1058   ∧(inc_added=O→sigma_pc_equal prefix old_sigma 〈inc_pc,inc_sigma〉)
1059   ∧out_of_program_none prefix 〈inc_pc,inc_sigma〉
1060   ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) inc_sigma
1061                〈O,short_jump〉)
1062    =old_pc+inc_added
1063   ∧sigma_safe prefix labels inc_added old_sigma 〈inc_pc,inc_sigma〉)*)
1064 ∀added : ℕ.
1065 ∀policy : ppc_pc_map.(*
1066 new_length : jump_length
1067 isize : ℕ
1068 Heq1 :
1069  (match 
1070   match instr
1071    in pseudo_instruction
1072    return λ_:pseudo_instruction.(option jump_length)
1073    with 
1074   [Instruction (i:(preinstruction Identifier))⇒
1075    jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
1076    (|prefix|) i
1077   |Comment (_:String)⇒None jump_length
1078   |Cost (_:costlabel)⇒None jump_length
1079   |Jmp (j:Identifier)⇒
1080    Some jump_length
1081    (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
1082   |Call (c:Identifier)⇒
1083    Some jump_length
1084    (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
1085   |Mov (_:[[dptr]])   (_0:Identifier)⇒None jump_length]
1086    in option
1087    return λ_0:(option jump_length).(jump_length×ℕ)
1088    with 
1089   [None⇒〈short_jump,instruction_size_jmplen short_jump instr〉
1090   |Some (pl:jump_length)⇒
1091    〈max_length old_length pl,
1092    instruction_size_jmplen (max_length old_length pl) instr〉]
1093   =〈new_length,isize〉)
1094 prefix_ok1 : (S (|prefix|)< 2 \sup 16 )
1095 prefix_ok : (|prefix|< 2 \sup 16 )
1096 Heq2a :
1097  (match 
1098   match instr
1099    in pseudo_instruction
1100    return λ_0:pseudo_instruction.(option jump_length)
1101    with 
1102   [Instruction (i:(preinstruction Identifier))⇒
1103    jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
1104    (|prefix|) i
1105   |Comment (_0:String)⇒None jump_length
1106   |Cost (_0:costlabel)⇒None jump_length
1107   |Jmp (j:Identifier)⇒
1108    Some jump_length
1109    (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
1110   |Call (c:Identifier)⇒
1111    Some jump_length
1112    (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
1113   |Mov (_0:[[dptr]])   (_00:Identifier)⇒None jump_length]
1114    in option
1115    return λ_0:(option jump_length).ℕ
1116    with 
1117   [None⇒inc_added
1118   |Some (x0:jump_length)⇒
1119    inc_added+(isize-instruction_size_jmplen old_length instr)]
1120   =added)
1121 Heq2b :
1122  (〈inc_pc+isize,
1123   insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
1124   〈inc_pc+isize,
1125   \snd  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
1126               (\snd  old_sigma) 〈O,short_jump〉)〉
1127   (insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
1128    〈inc_pc,new_length〉 inc_sigma)〉
1129   =policy)
1130*)
1131   \fst  (lookup (ℕ×jump_length) 16
1132              (bitvector_of_nat 16 (|(prefix@[〈label,instr〉])|)) (\snd  policy)
1133              〈O,short_jump〉)
1134  =\fst  (lookup (ℕ×jump_length) 16
1135               (bitvector_of_nat 16 (|(prefix@[〈label,instr〉])|)) (\snd  old_sigma)
1136               〈O,short_jump〉)
1137   +added.
1138cases daemon(*
1139    <(proj2 ?? (pair_destruct ?????? Heq2)) >append_length <plus_n_Sm <plus_n_O
1140    >lookup_insert_hit
1141    <(proj1 ?? (pair_destruct ?????? Heq2)) cases instr in p1 Heq1;
1142    [2,3,6: #x [3: #y] normalize nodelta #p1 #Heq1 <(proj2 ?? (pair_destruct ?????? Heq1))
1143      (* USE: sigma_compact_unsafe (from old_sigma) *)
1144      lapply (proj2 ?? (proj1 ?? (pi2 ?? old_sigma)) (|prefix|) ?)
1145      [1,3,5: >prf >append_length <plus_n_Sm @le_S_S @le_plus_n_r
1146      |2,4,6: lapply Holdeq -Holdeq
1147        lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)))
1148        cases (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)) in ⊢ (???% → %);
1149        [1,3,5: normalize nodelta #_ #_ #abs cases abs
1150        |2,4,6: lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)))
1151          cases (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)) in ⊢ (???% → %);
1152          [1,3,5: normalize nodelta #_ #x cases x -x #Spc #Sj normalize nodelta #_ #_ #abs cases abs
1153          |2,4,6: #x cases x -x #Spc #Sj #EQS #x cases x -x #pc #j #Holdeq #EQ normalize nodelta
1154            #H (* USE: fst p = lookup |prefix| *)
1155            >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))
1156            (* USE[pass]: lookup p = lookup old_sigma + added *)
1157            >(proj2 ?? (proj1 ?? Hpolicy)) >(lookup_opt_lookup_hit … Holdeq 〈0,short_jump〉) in EQ;
1158            -Holdeq #EQ <(proj1 ?? (pair_destruct ?????? EQ))
1159            >(lookup_opt_lookup_hit … EQS 〈0,short_jump〉) >H >prf >nth_append_second
1160            [1,3,5: <minus_n_n >p1 whd in match (nth ????); >associative_plus
1161              >(associative_plus pc) @plus_left_monotone >commutative_plus
1162              @plus_right_monotone @instruction_size_irrelevant @nmk #H @H
1163            |2,4,6: @le_n
1164            ]
1165          ]
1166        ]
1167      ]
1168    |4,5: #x normalize nodelta #p1 #Heq1
1169      (* USE: sigma_compact_unsafe (from old_sigma) *)
1170      lapply (proj2 ?? (proj1 ?? (pi2 ?? old_sigma)) (|prefix|) ?)
1171      [1,3: >prf >append_length <plus_n_Sm @le_S_S @le_plus_n_r
1172      |2,4: lapply Holdeq -Holdeq
1173        lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)))
1174        cases (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)) in ⊢ (???% → %);
1175        [1,3: normalize nodelta #_ #_ #abs cases abs
1176        |2,4: lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)))
1177          cases (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)) in ⊢ (???% → %);
1178          [1,3: normalize nodelta #_ #x cases x -x #Spc #Sj normalize nodelta #_ #_ #abs cases abs
1179          |2,4: #x cases x -x #Spc #Sj #EQS #x cases x -x #pc #j #Holdeq #EQ normalize nodelta
1180            #H (* USE: fst p = lookup |prefix| *)
1181            >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))
1182            (* USE[pass]: lookup p = lookup old_sigma + added *)
1183            >(proj2 ?? (proj1 ?? Hpolicy)) >(lookup_opt_lookup_hit … Holdeq 〈0,short_jump〉) in EQ;
1184            -Holdeq #EQ <(proj1 ?? (pair_destruct ?????? EQ))
1185            >(lookup_opt_lookup_hit … EQS 〈0,short_jump〉) >H >associative_plus
1186            >(associative_plus pc) @plus_left_monotone >assoc_plus1
1187            >(associative_plus inc_added) @plus_left_monotone >plus_minus_commutative
1188            [1,3: >(proj2 ?? (pair_destruct ?????? EQ)) >prf >nth_append_second
1189              [1,3: <minus_n_n whd in match (nth ????); >p1 >commutative_plus
1190                @minus_plus_m_m
1191              |2,4: @le_n
1192              ]
1193            |2,4: <(proj2 ?? (pair_destruct ?????? Heq1)) @jump_length_le_max @I
1194            ]
1195          ]
1196        ]
1197      ]
1198    |1: #pi cases pi
1199      [1,2,3,4,5,6,7,8,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37:
1200        [1,2,3,6,7,24,25: #x #y
1201        |4,5,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23: #x]
1202        normalize nodelta #p1 #Heq1 <(proj2 ?? (pair_destruct ?????? Heq1))
1203        (* USE: sigma_compact_unsafe (from old_sigma) *)
1204        lapply (proj2 ?? (proj1 ?? (pi2 ?? old_sigma)) (|prefix|) ?)
1205        [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55:
1206          >prf >append_length <plus_n_Sm @le_S_S @le_plus_n_r
1207        |2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56:
1208          lapply Holdeq -Holdeq lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)))
1209          cases (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)) in ⊢ (???% → %);
1210          [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55:
1211            normalize nodelta #_ #_ #abs cases abs
1212          |2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56:
1213            lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)))
1214            cases (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)) in ⊢ (???% → %);
1215            [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55:
1216              normalize nodelta #_ #x cases x -x #Spc #Sj normalize nodelta #_ #_ #abs cases abs
1217            |2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56:
1218              #x cases x -x #Spc #Sj #EQS #x cases x -x #pc #j #Holdeq #EQ normalize nodelta
1219              #H (* USE: fst p = lookup |prefix| *)
1220              >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))
1221              (* USE[pass]: lookup p = lookup old_sigma + added *)
1222              >(proj2 ?? (proj1 ?? Hpolicy)) >(lookup_opt_lookup_hit … Holdeq 〈0,short_jump〉) in EQ;
1223              -Holdeq #EQ <(proj1 ?? (pair_destruct ?????? EQ))
1224              >(lookup_opt_lookup_hit … EQS 〈0,short_jump〉) >H >prf >nth_append_second
1225              [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55:
1226                <minus_n_n >p1 whd in match (nth ????); >associative_plus
1227                >(associative_plus pc) @plus_left_monotone >commutative_plus
1228                @plus_right_monotone @instruction_size_irrelevant @nmk #H @H
1229              |2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56:
1230                @le_n
1231              ]
1232            ]
1233          ]
1234        ]
1235      |9,10,11,12,13,14,15,16,17: #x [3,4,5,8,9: #y] normalize nodelta #p1 #Heq1
1236      (* USE: sigma_compact_unsafe (from old_sigma) *)
1237        lapply (proj2 ?? (proj1 ?? (pi2 ?? old_sigma)) (|prefix|) ?)
1238        [1,3,5,7,9,11,13,15,17: >prf >append_length <plus_n_Sm @le_S_S @le_plus_n_r
1239        |2,4,6,8,10,12,14,16,18: lapply Holdeq -Holdeq
1240          lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)))
1241          cases (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)) in ⊢ (???% → %);
1242          [1,3,5,7,9,11,13,15,17: normalize nodelta #_ #_ #abs cases abs
1243          |2,4,6,8,10,12,14,16,18: lapply (refl ? (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)))
1244            cases (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)) in ⊢ (???% → %);
1245            [1,3,5,7,9,11,13,15,17: normalize nodelta #_ #x cases x -x #Spc #Sj
1246              normalize nodelta #_ #_ #abs cases abs
1247            |2,4,6,8,10,12,14,16,18: #x cases x -x #Spc #Sj #EQS #x cases x -x #pc #j
1248              #Holdeq #EQ normalize nodelta #H (* USE: fst p = lookup |prefix| *)
1249              >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))
1250              (* USE[pass]: lookup p = lookup old_sigma + added *)
1251              >(proj2 ?? (proj1 ?? Hpolicy)) >(lookup_opt_lookup_hit … Holdeq 〈0,short_jump〉) in EQ;
1252              -Holdeq #EQ <(proj1 ?? (pair_destruct ?????? EQ))
1253              >(lookup_opt_lookup_hit … EQS 〈0,short_jump〉) >H >associative_plus
1254              >(associative_plus pc) @plus_left_monotone >assoc_plus1
1255              >(associative_plus inc_added) @plus_left_monotone >plus_minus_commutative
1256              [1,3,5,7,9,11,13,15,17: >(proj2 ?? (pair_destruct ?????? EQ)) >prf
1257                >nth_append_second
1258                [1,3,5,7,9,11,13,15,17: <minus_n_n whd in match (nth ????); >p1
1259                  >commutative_plus @minus_plus_m_m
1260                |2,4,6,8,10,12,14,16,18: @le_n
1261                ]
1262              |2,4,6,8,10,12,14,16,18: <(proj2 ?? (pair_destruct ?????? Heq1))
1263                @jump_length_le_max @I
1264              ]
1265            ]
1266          ]
1267        ]
1268      ]
1269    ] *)
1270qed.
1271
1272lemma jump_expansion_step9:
1273(*
1274 program :
1275  (Σl:list labelled_instruction.S (|l|)< 2 \sup 16 ∧is_well_labelled_p l)*)
1276 ∀labels : label_map.(*
1277  (Σlm:label_map
1278   .(∀l:identifier ASMTag
1279     .occurs_exactly_once ASMTag pseudo_instruction l program
1280      →bitvector_of_nat 16 (lookup_def ASMTag ℕ lm l O)
1281       =address_of_word_labels_code_mem program l))*)
1282 ∀old_sigma : ppc_pc_map.(*
1283  (Σpolicy:ppc_pc_map
1284   .not_jump_default program policy
1285    ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) (\snd  policy)
1286                 〈O,short_jump〉)
1287     =O
1288    ∧\fst  policy
1289     =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|program|))
1290                  (\snd  policy) 〈O,short_jump〉)
1291    ∧sigma_compact_unsafe program labels policy
1292    ∧\fst  policy≤ 2 \sup 16 )*)
1293 ∀prefix : list (option Identifier×pseudo_instruction).(*
1294 x : (option Identifier×pseudo_instruction)
1295 tl : (list (option Identifier×pseudo_instruction))
1296 prf : (program=prefix@[x]@tl)
1297 acc :
1298  (Σx0:ℕ×ppc_pc_map
1299   .(let 〈added,policy〉 ≝x0 in 
1300     not_jump_default prefix policy
1301     ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) (\snd  policy)
1302                  〈O,short_jump〉)
1303      =O
1304     ∧\fst  policy
1305      =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
1306                   (\snd  policy) 〈O,short_jump〉)
1307     ∧jump_increase prefix old_sigma policy
1308     ∧sigma_compact_unsafe prefix labels policy
1309     ∧(sigma_jump_equal prefix old_sigma policy→added=O)
1310     ∧(added=O→sigma_pc_equal prefix old_sigma policy)
1311     ∧out_of_program_none prefix policy
1312     ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
1313                  (\snd  policy) 〈O,short_jump〉)
1314      =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
1315                   (\snd  old_sigma) 〈O,short_jump〉)
1316       +added
1317     ∧sigma_safe prefix labels added old_sigma policy))
1318 inc_added : ℕ
1319 inc_pc_sigma : ppc_pc_map
1320 p : (acc≃〈inc_added,inc_pc_sigma〉)*)
1321 ∀label : option Identifier.
1322 ∀instr : pseudo_instruction.(*
1323 p1 : (x≃〈label,instr〉)
1324 add_instr ≝
1325  match instr
1326   in pseudo_instruction
1327   return λ_:pseudo_instruction.(option jump_length)
1328   with 
1329  [Instruction (i:(preinstruction Identifier))⇒
1330   jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
1331   (|prefix|) i
1332  |Comment (_:String)⇒None jump_length
1333  |Cost (_:costlabel)⇒None jump_length
1334  |Jmp (j:Identifier)⇒
1335   Some jump_length
1336   (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
1337  |Call (c:Identifier)⇒
1338   Some jump_length
1339   (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
1340  |Mov (_:[[dptr]])   (_0:Identifier)⇒None jump_length]
1341 inc_pc : ℕ
1342 inc_sigma : (BitVectorTrie (ℕ×jump_length) 16)
1343 Hips : (inc_pc_sigma=〈inc_pc,inc_sigma〉)
1344 old_pc : ℕ
1345 old_length : jump_length
1346 Holdeq :
1347  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) (\snd  old_sigma)
1348   〈O,short_jump〉
1349   =〈old_pc,old_length〉)
1350 Hpolicy :
1351  (not_jump_default prefix 〈inc_pc,inc_sigma〉
1352   ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) inc_sigma
1353                〈O,short_jump〉)
1354    =O
1355   ∧inc_pc
1356    =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) inc_sigma
1357                 〈O,short_jump〉)
1358   ∧jump_increase prefix old_sigma 〈inc_pc,inc_sigma〉
1359   ∧sigma_compact_unsafe prefix labels 〈inc_pc,inc_sigma〉
1360   ∧(sigma_jump_equal prefix old_sigma 〈inc_pc,inc_sigma〉→inc_added=O)
1361   ∧(inc_added=O→sigma_pc_equal prefix old_sigma 〈inc_pc,inc_sigma〉)
1362   ∧out_of_program_none prefix 〈inc_pc,inc_sigma〉
1363   ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) inc_sigma
1364                〈O,short_jump〉)
1365    =old_pc+inc_added
1366   ∧sigma_safe prefix labels inc_added old_sigma 〈inc_pc,inc_sigma〉)*)
1367 ∀added : ℕ.
1368 ∀policy : ppc_pc_map.(*
1369 new_length : jump_length
1370 isize : ℕ
1371 Heq1 :
1372  (match 
1373   match instr
1374    in pseudo_instruction
1375    return λ_:pseudo_instruction.(option jump_length)
1376    with 
1377   [Instruction (i:(preinstruction Identifier))⇒
1378    jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
1379    (|prefix|) i
1380   |Comment (_:String)⇒None jump_length
1381   |Cost (_:costlabel)⇒None jump_length
1382   |Jmp (j:Identifier)⇒
1383    Some jump_length
1384    (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
1385   |Call (c:Identifier)⇒
1386    Some jump_length
1387    (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
1388   |Mov (_:[[dptr]])   (_0:Identifier)⇒None jump_length]
1389    in option
1390    return λ_0:(option jump_length).(jump_length×ℕ)
1391    with 
1392   [None⇒〈short_jump,instruction_size_jmplen short_jump instr〉
1393   |Some (pl:jump_length)⇒
1394    〈max_length old_length pl,
1395    instruction_size_jmplen (max_length old_length pl) instr〉]
1396   =〈new_length,isize〉)
1397 prefix_ok1 : (S (|prefix|)< 2 \sup 16 )
1398 prefix_ok : (|prefix|< 2 \sup 16 )
1399 Heq2a :
1400  (match 
1401   match instr
1402    in pseudo_instruction
1403    return λ_0:pseudo_instruction.(option jump_length)
1404    with 
1405   [Instruction (i:(preinstruction Identifier))⇒
1406    jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
1407    (|prefix|) i
1408   |Comment (_0:String)⇒None jump_length
1409   |Cost (_0:costlabel)⇒None jump_length
1410   |Jmp (j:Identifier)⇒
1411    Some jump_length
1412    (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
1413   |Call (c:Identifier)⇒
1414    Some jump_length
1415    (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
1416   |Mov (_0:[[dptr]])   (_00:Identifier)⇒None jump_length]
1417    in option
1418    return λ_0:(option jump_length).ℕ
1419    with 
1420   [None⇒inc_added
1421   |Some (x0:jump_length)⇒
1422    inc_added+(isize-instruction_size_jmplen old_length instr)]
1423   =added)
1424 Heq2b :
1425  (〈inc_pc+isize,
1426   insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
1427   〈inc_pc+isize,
1428   \snd  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
1429               (\snd  old_sigma) 〈O,short_jump〉)〉
1430   (insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
1431    〈inc_pc,new_length〉 inc_sigma)〉
1432   =policy)
1433*)
1434 sigma_safe (prefix@[〈label,instr〉]) labels added old_sigma policy.
1435cases daemon(*
1436    #i >append_length >commutative_plus #Hi normalize in Hi;
1437    elim (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
1438    [ >nth_append_first [2: @Hi]
1439      <Heq2b >lookup_insert_miss
1440      [ >lookup_insert_miss
1441        [ >lookup_insert_miss
1442          [ elim (le_to_or_lt_eq … Hi) -Hi #Hi
1443            [ >lookup_insert_miss
1444              [ (* USE[pass]: sigma_safe *)
1445                lapply ((proj2 ?? Hpolicy) i (le_S_to_le … Hi))
1446                cases (bvt_lookup … (bitvector_of_nat ? i) inc_sigma 〈0,short_jump〉)
1447                #pc #j normalize nodelta
1448                cases (bvt_lookup … (bitvector_of_nat ? (S i)) inc_sigma 〈0,short_jump〉)
1449                #Spc #Sj normalize nodelta
1450                cases (nth i ? prefix 〈None ?, Comment []〉) #lbl #ins normalize nodelta
1451                #Hind #dest #Hj lapply (Hind dest Hj) -Hind -Hj
1452                lapply (refl ? (leb (lookup_def … labels dest 0) (S (|prefix|))))
1453                cases (leb (lookup_def … labels dest 0) (S (|prefix|))) in ⊢ (???% → %); #H
1454                [ cases (le_to_or_lt_eq … (leb_true_to_le … H)) -H #H
1455                  [ >(le_to_leb_true … (le_S_S_to_le … H)) normalize nodelta
1456                    >lookup_insert_miss
1457                    [ cases (le_to_or_lt_eq … (le_S_S_to_le … H)) -H #H
1458                      [ >lookup_insert_miss
1459                        [ #H2 @H2
1460                        | @bitvector_of_nat_abs
1461                          [3: @lt_to_not_eq @H
1462                          |1: @(transitive_lt ??? H)
1463                          ]
1464                          @prefix_ok
1465                        ]
1466                      | >H >lookup_insert_hit
1467                        (* USE: inc_pc = lookup |prefix| *)
1468                        >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1469                        #H2 @H2
1470                      ]
1471                    | @bitvector_of_nat_abs
1472                      [3: @lt_to_not_eq @H
1473                      |1: @(transitive_lt ??? H)
1474                      ]
1475                      @prefix_ok1
1476                    ]
1477                  | >H >lookup_insert_hit normalize nodelta
1478                    >(not_le_to_leb_false … (lt_to_not_le ?? (le_S_S ?? (le_n (|prefix|)))))
1479                    normalize nodelta
1480                    >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1481                    #H2 >(proj2 ?? (proj1 ?? Hpolicy))
1482                  ]
1483                |
1484                       
1485                       
1486                       
1487                [2,3,6: [3: #x] #y normalize nodelta #EQ <EQ cases j normalize nodelta
1488                  [1,4,7: cases (decidable_le (lookup_def … labels dest 0) (S (|prefix|))) #H
1489                    [1,3,5: >(le_to_leb_true … H) normalize nodelta cases (le_to_or_lt_eq … H) -H #H
1490                      [1,3,5: >(le_to_leb_true … (le_S_S_to_le … H)) normalize nodelta
1491                        >lookup_insert_miss
1492                        [2,4,6: @bitvector_of_nat_abs
1493                          [3,6,9: @lt_to_not_eq @H
1494                          |1,4,7: @(transitive_lt ??? H)
1495                          ]
1496                          @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf
1497                          @le_S_S >append_length <plus_n_Sm @le_S_S @le_plus_n_r
1498                        ]
1499                        cases (le_to_or_lt_eq … H) -H #H
1500                        [1,3,5: >lookup_insert_miss
1501                          [1,3,5: #H @H
1502                          |2,4,6: @bitvector_of_nat_abs
1503                            [3,6,9: @lt_to_not_eq @(le_S_S_to_le … H)
1504                            |1,4,7: @(transitive_lt ??? (le_S_S_to_le … H))
1505                            ]
1506                            @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf
1507                            >append_length @le_S_S @le_plus_n_r
1508                          ]
1509                        |2,4,6: >(injective_S … H) >lookup_insert_hit
1510                          (* USE: blerp *)
1511                          >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1512                          #H @H
1513                        ]
1514                      |2,4,6: >H >lookup_insert_hit >(not_le_to_leb_false)
1515                        [2,4,6: @le_to_not_lt @le_n]
1516                        normalize nodelta
1517                        lapply (proj2 ?? (proj1 ?? (pi2 ?? old_sigma)) (|prefix|) ?)
1518                        [1,3,5: >prf >append_length <plus_n_Sm @le_S_S @le_plus_n_r]
1519                         lapply (refl ? (lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)))
1520                          cases (lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)) in ⊢ (???% → %);
1521                          [1,3,5: normalize nodelta #_ #abs cases abs
1522                          |2,4,6: #x cases x -x #ppc #pj normalize nodelta #PEQ
1523                            lapply (refl ? (lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)))
1524                            cases (lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)) in ⊢ (???% → %);
1525                            [1,3,5: normalize nodelta #_ #abs cases abs
1526                            |2,4,6: #x cases x -x #Sppc #Spj normalize nodelta #SPEQ #Pcompact
1527                              >(lookup_opt_lookup_hit … SPEQ 〈0,short_jump〉)
1528                              >(lookup_opt_lookup_hit … PEQ 〈0,short_jump〉) in Holdeq;
1529                              #H >Pcompact >(proj1 ?? (pair_destruct ?????? H))
1530                              >commutative_plus >assoc_plus1 <(proj2 ?? (proj1 ?? Hpolicy))
1531                              <(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1532                              >prf >nth_append_second
1533                              [1,3,5: <minus_n_n whd in match (nth ????); >p1
1534                                cases daemon (* to be lemmatized *)
1535                              |2,4,6: @le_n
1536                              ]
1537                            ]
1538                          ]
1539                        ]
1540                      |2,4,6: >(not_le_to_leb_false … H)
1541                        >not_le_to_leb_false
1542                        [2,4,6: @lt_to_not_le @le_S_to_le @not_le_to_lt @H
1543                        |1,3,5: normalize nodelta #H @H
1544                        ]
1545                      ]
1546                    |2,5,8: cases daemon (* like previous case *)
1547                    |3,6,9: cases daemon (* like previous case *)
1548                    ]
1549                  |4,5: #x normalize nodelta cases daemon (* blerp *)
1550                  |1: cases daemon (* blerp *)
1551                  ]
1552               
1553                               
1554                         
1555
1556   (*(\fst  (short_jump_cond (bitvector_of_nat 16 Spc)
1557              (bitvector_of_nat 16
1558               (inc_pc
1559                +instruction_size_jmplen
1560                 (max_length old_length
1561                  (select_jump_length labels old_sigma inc_pc_sigma inc_added
1562                   (|prefix|) xx)) (Jmp xx))))
1563  =true                   *)
1564                       
1565                 
1566  ]       
1567              [ >lookup_insert_miss
1568                [ (* USE[pass]: sigma_safe *)
1569                  lapply ((proj2 ?? Hpolicy) i (le_S_to_le … Hi))
1570                  cases (bvt_lookup … (bitvector_of_nat ? i) inc_sigma 〈0,short_jump〉)
1571                  #pc #j normalize nodelta
1572                  cases (bvt_lookup … (bitvector_of_nat ? (S i)) inc_sigma 〈0,short_jump〉)
1573                  #Spc #Sj normalize nodelta
1574                  cases (nth i ? prefix 〈None ?, Comment []〉) #lbl #ins normalize nodelta
1575                  #Hind #dest #Hj lapply (Hind dest Hj) -Hind -Hj lapply (proj1 ?? (pair_destruct ?????? Heq2)) cases instr
1576                  [2,3,6: [3: #x] #y normalize nodelta #EQ <EQ cases j normalize nodelta
1577                    [1,4,7: *)
1578qed.
1579
1580(* One step in the search for a jump expansion fixpoint. *)
1581definition jump_expansion_step: ∀program:(Σl:list labelled_instruction.
1582  S (|l|) < 2^16 ∧ is_well_labelled_p l).
1583  ∀labels:(Σlm:label_map.∀l.
1584    occurs_exactly_once ?? l program →
1585    bitvector_of_nat ? (lookup_def … lm l 0) =
1586    address_of_word_labels_code_mem program l).
1587  ∀old_policy:(Σpolicy:ppc_pc_map.
1588    (* out_of_program_none program policy *)
1589    And (And (And (And (not_jump_default program policy)
1590    (\fst (bvt_lookup … (bitvector_of_nat ? 0) (\snd policy) 〈0,short_jump〉) = 0))
1591    (\fst policy = \fst (bvt_lookup … (bitvector_of_nat ? (|program|)) (\snd policy) 〈0,short_jump〉)))
1592    (sigma_compact_unsafe program labels policy))
1593    (\fst policy ≤ 2^16)).
1594  (Σx:bool × (option ppc_pc_map).
1595    let 〈no_ch,y〉 ≝ x in
1596    match y with
1597    [ None ⇒ nec_plus_ultra program old_policy
1598    | Some p ⇒ And (And (And (And (And (And (And
1599       (not_jump_default program p)
1600       (\fst (bvt_lookup … (bitvector_of_nat ? 0) (\snd p) 〈0,short_jump〉) = 0))
1601       (\fst p = \fst (bvt_lookup … (bitvector_of_nat ? (|program|)) (\snd p) 〈0,short_jump〉)))
1602       (jump_increase program old_policy p))
1603       (sigma_compact_unsafe program labels p))
1604       (sigma_jump_equal program old_policy p → no_ch = true))
1605       (no_ch = true → sigma_pc_equal program old_policy p))
1606       (\fst p ≤ 2^16)
1607    ])
1608    ≝
1609  λprogram.λlabels.λold_sigma.
1610  let 〈final_added, final_policy〉 ≝
1611    pi1 ?? (foldl_strong (option Identifier × pseudo_instruction)
1612    (λprefix.Σx:ℕ × ppc_pc_map.
1613      let 〈added,policy〉 ≝ x in
1614      And (And (And (And (And (And (And (And (And (not_jump_default prefix policy)
1615      (\fst (bvt_lookup … (bitvector_of_nat ? 0) (\snd policy) 〈0,short_jump〉) = 0))
1616      (\fst policy = \fst (bvt_lookup … (bitvector_of_nat ? (|prefix|)) (\snd policy) 〈0,short_jump〉)))
1617      (jump_increase prefix old_sigma policy))
1618      (sigma_compact_unsafe prefix labels policy))
1619      (sigma_jump_equal prefix old_sigma policy → added = 0))
1620      (added = 0 → sigma_pc_equal prefix old_sigma policy))
1621      (out_of_program_none prefix policy))
1622      (\fst (bvt_lookup … (bitvector_of_nat ? (|prefix|)) (\snd policy) 〈0,short_jump〉) =
1623       \fst (bvt_lookup … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma) 〈0,short_jump〉) + added))
1624      (sigma_safe prefix labels added old_sigma policy))
1625    program
1626    (λprefix.λx.λtl.λprf.λacc.
1627      let 〈inc_added, inc_pc_sigma〉 ≝ (pi1 ?? acc) in
1628      let 〈label,instr〉 ≝ x in
1629      (* Now, we must add the current ppc and its pc translation.
1630       * Three possibilities:
1631       *   - Instruction is not a jump; i.e. constant size whatever the sigma we use;
1632       *   - Instruction is a backward jump; we can use the sigma we're constructing,
1633       *     since it will already know the translation of its destination;
1634       *   - Instruction is a forward jump; we must use the old sigma (the new sigma
1635       *     does not know the translation yet), but compensate for the jumps we
1636       *     have lengthened.
1637       *)
1638      let add_instr ≝ match instr with
1639      [ Jmp  j        ⇒ Some ? (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
1640      | Call c        ⇒ Some ? (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
1641      | Instruction i ⇒ jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added (|prefix|) i
1642      | _             ⇒ None ?
1643      ] in
1644      let 〈inc_pc, inc_sigma〉 ≝ inc_pc_sigma in
1645      let old_length ≝
1646        \snd (bvt_lookup … (bitvector_of_nat ? (|prefix|)) (\snd (pi1 ?? old_sigma)) 〈0,short_jump〉) in
1647      let old_size ≝ instruction_size_jmplen old_length instr in
1648      let 〈new_length, isize〉 ≝ match add_instr with
1649      [ None    ⇒ 〈short_jump, instruction_size_jmplen short_jump instr〉
1650      | Some pl ⇒ 〈max_length old_length pl, instruction_size_jmplen (max_length old_length pl) instr〉
1651      ] in
1652      let new_added ≝ match add_instr with
1653      [ None   ⇒ inc_added
1654      | Some x ⇒ plus inc_added (minus isize old_size)
1655      ] in
1656      let old_Slength ≝
1657        \snd (bvt_lookup … (bitvector_of_nat ? (S (|prefix|))) (\snd (pi1 ?? old_sigma)) 〈0,short_jump〉) in
1658      let updated_sigma ≝
1659        (* we add the new PC to the next position and the new jump length to this one *)
1660        bvt_insert … (bitvector_of_nat ? (S (|prefix|))) 〈inc_pc + isize, old_Slength〉
1661        (bvt_insert … (bitvector_of_nat ? (|prefix|)) 〈inc_pc, new_length〉 inc_sigma) in
1662      〈new_added, 〈plus inc_pc isize, updated_sigma〉〉
1663    ) 〈0, 〈0,
1664      bvt_insert …
1665        (bitvector_of_nat ? 0)
1666        〈0, \snd (bvt_lookup … (bitvector_of_nat ? 0) (\snd (pi1 ?? old_sigma)) 〈0,short_jump〉)〉
1667        (Stub ??)〉〉
1668    ) in
1669    if gtb (\fst final_policy) 2^16 then
1670      〈eqb final_added 0, None ?〉
1671    else
1672      〈eqb final_added 0, Some ? final_policy〉.
1673[ normalize nodelta @nmk #Habs lapply p -p cases (foldl_strong ? (λ_.Σx.?) ???)
1674  #x #H #Heq >Heq in H; normalize nodelta -Heq -x #Hind
1675  (* USE: inc_pc = fst of policy (from fold) *)
1676  >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hind)))))))) in p1;
1677  (* USE: fst policy < 2^16, inc_pc = fst of policy (old_sigma) *)
1678  lapply (proj2 ?? (pi2 ?? old_sigma)) >(proj2 ?? (proj1 ?? (proj1 ?? (pi2 ?? old_sigma))))
1679  #Hsig #Hge
1680  (* USE: added = 0 → policy_pc_equal (from fold) *)
1681  lapply ((proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hind)))) ? (|program|) (le_n (|program|)))
1682  [ (* USE: policy_jump_equal → added = 0 (from fold) *)
1683    @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hind))))) #i #Hi
1684    inversion (is_jump (\snd (nth i ? program 〈None ?, Comment []〉)))
1685    [ #Hj
1686      (* USE: policy_increase (from fold) *)
1687      lapply (proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hind)))))) i (le_S_to_le … Hi))
1688      lapply (Habs i Hi ?) [ >Hj %]
1689      cases (bvt_lookup … (bitvector_of_nat ? i) (\snd old_sigma) 〈0,short_jump〉)
1690      #opc #oj
1691      cases (bvt_lookup … (bitvector_of_nat ? i) (\snd final_policy) 〈0,short_jump〉)
1692      #pc #j normalize nodelta #Heq >Heq cases j
1693      [1,2: #abs cases abs #abs2 try (cases abs2) @refl
1694      |3: #_ @refl
1695      ]
1696    | #Hnj
1697      (* USE: not_jump_default (from fold and old_sigma) *)
1698      >(proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hind)))))))) i Hi ?)
1699      [2: >Hnj %]
1700      >(proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (pi2 ?? old_sigma)))) i Hi ?) try %
1701      >Hnj %
1702    ]
1703  | #abs >abs in Hsig; #Hsig
1704    @(absurd ? Hsig) @lt_to_not_le @ltb_true_to_lt @Hge
1705  ]
1706| normalize nodelta lapply p -p cases (foldl_strong ? (λ_.Σx.?)???) in ⊢ (% → ?); #x #H #H2
1707  >H2 in H; normalize nodelta -H2 -x #H @conj
1708  [ @conj [ @conj
1709  [ (* USE[pass]: not_jump_default, 0 ↦ 0, inc_pc = fst policy,
1710     * jump_increase, sigma_compact_unsafe (from fold) *)
1711    @(proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? H)))))
1712  | #H2 (* USE[pass]: sigma_jump_equal → added = 0 (from fold) *)
1713    @eq_to_eqb_true @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? H))))) @H2
1714  ]
1715  | (* USE[pass]: added = 0 → sigma_pc_equal (from fold) *)
1716     #H2 @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? H)))) @eqb_true_to_eq @H2
1717  ]
1718  | @not_lt_to_le @ltb_false_to_not_lt @p1
1719  ]
1720|4: lapply (pi2 ?? acc) >p lapply (refl ? (inc_pc_sigma)) cases inc_pc_sigma in ⊢ (???% → %);
1721  #inc_pc #inc_sigma #Hips
1722  inversion (bvt_lookup … (bitvector_of_nat ? (|prefix|)) (\snd (pi1 ?? old_sigma)) 〈0,short_jump〉)
1723  #old_pc #old_length #Holdeq #Hpolicy normalize nodelta in Hpolicy; @pair_elim
1724  #added #policy normalize nodelta @pair_elim #new_length #isize normalize nodelta
1725  #Heq1 #Heq2
1726 cut (S (|prefix|) < 2^16)
1727 [ @(transitive_lt … (proj1 … (pi2 ?? program))) @le_S_S >prf >append_length
1728   <plus_n_Sm @le_S_S @le_plus_n_r ] #prefix_ok1
1729 cut (|prefix| < 2^16) [ @(transitive_lt … prefix_ok1) %] #prefix_ok
1730 cases (pair_destruct ?????? Heq2) -Heq2 #Heq2a #Heq2b
1731  % [ % [ % [ % [ % [ % [ % [ % [ % ]]]]]]]]
1732  (* NOTE: to save memory and speed up work, there's cases daemon here. They can be
1733   * commented out for full proofs, but this needs a lot of memory and time *)
1734  [ (* not_jump_default *)
1735    @(jump_expansion_step1 … Heq1 Heq2b) try assumption
1736    @(proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))))
1737  | (* 0 ↦ 0 *)
1738    @(jump_expansion_step2 … Heq2b) try assumption
1739    [ @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ??  (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))))
1740    | @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))) ]
1741  | (* inc_pc = fst of policy *)
1742    <Heq2b >append_length >(commutative_plus (|prefix|)) >lookup_insert_hit @refl
1743  | (* jump_increase *)
1744    @(jump_expansion_step3 … (pi1 ?? old_sigma) … prf … p1 ??? old_length Holdeq
1745      … Heq1 prefix_ok1 prefix_ok Heq2b)
1746    try @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))
1747    cases (pi2 … old_sigma) * * * #H #_ #_ #_ #_ @H
1748  | (* sigma_compact_unsafe *)
1749    @(jump_expansion_step4 … Heq1 … Heq2b) try assumption
1750    try @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ??  (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1751    try @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))
1752    @(proj2 ?? (proj1 ?? (proj1 ?? Hpolicy)))
1753  | (* policy_jump_equal → added = 0 *)
1754    @(jump_expansion_step5 … Holdeq … Heq1 … Heq2b) try assumption
1755    try @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))
1756    @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1757  | (* added = 0 → policy_pc_equal *) cases daemon (*
1758    @(jump_expansion_step6 … Heq1 … Heq2b) try assumption
1759    try @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))
1760    @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1761    *)
1762  | (* out_of_program_none *) cases daemon(*
1763    @jump_expansion_step7 try assumption
1764    @(proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))))
1765    *)
1766  | (* lookup p = lookup old_sigma + added *) cases daemon(*
1767    @jump_expansion_step8 try assumption
1768    try @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))   
1769    @(proj2 ?? (proj1 ?? Hpolicy)) *)
1770  | (* sigma_safe *) cases daemon (*
1771    @jump_expansion_step9 try assumption
1772    @(proj2 ?? Hpolicy) *)
1773  ]     
1774| normalize nodelta % [ % [ % [ % [ % [ % [ % [ % [ % ]]]]]]]]
1775  [ #i cases i
1776    [ #Hi @⊥ @(absurd … Hi) @not_le_Sn_O
1777    | -i #i #Hi #Hj @⊥ @(absurd … Hi) @not_le_Sn_O
1778    ]
1779  | >lookup_insert_hit @refl
1780  | >lookup_insert_hit @refl
1781  | #i #Hi <(le_n_O_to_eq … Hi)
1782    >lookup_insert_hit cases (bvt_lookup … (bitvector_of_nat ? 0) (\snd old_sigma) 〈0,short_jump〉)
1783    #a #b normalize nodelta %2 @refl
1784  | #i cases i
1785    [ #Hi @⊥ @(absurd … Hi) @not_le_Sn_O
1786    | -i #i #Hi @⊥ @(absurd … Hi) @not_le_Sn_O
1787    ]
1788  | #_ %
1789  | #_ #i #Hi <(le_n_O_to_eq … Hi) >lookup_insert_hit
1790    (* USE: 0 ↦ 0 (from old_sigma) *)
1791    @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (pi2 ?? old_sigma)))))
1792  | #i cases i
1793    [ #Hi2 @conj
1794      [ #Hi @⊥ @(absurd ? Hi) @le_to_not_lt / by /
1795      | >lookup_opt_insert_hit #H destruct (H)
1796      ]
1797    | -i #i #Hi2 @conj
1798      [ #Hi >lookup_opt_insert_miss
1799        [ / by refl/
1800        | @bitvector_of_nat_abs
1801          [ @Hi2
1802          | / by /
1803          | @sym_neq @lt_to_not_eq / by /
1804          ]
1805        ]
1806      | #_ @le_S_S @le_O_n
1807      ]
1808    ]
1809  | >lookup_insert_hit (* USE: 0 ↦ 0 (from old_sigma) *)
1810    >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (pi2 ?? old_sigma))))) <plus_n_O %
1811  | #i cases i
1812    [ #Hi @⊥ @(absurd … Hi) @not_le_Sn_O
1813    | -i #i #Hi @⊥ @(absurd … Hi) @not_le_Sn_O
1814    ]
1815  ]
1816]
1817qed.
Note: See TracBrowser for help on using the repository browser.