source: src/ASM/PolicyStep.ma @ 2246

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

Final technical lemma streamlined. Maybe it can be streamlined even more.

File size: 61.3 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_None:
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 destination_of_None_to_is_jump_false:
12 ∀instr. destination_of instr = None … → is_jump' instr = false.
13 * normalize // try (#H1 #H2 #abs) try (#H1 #abs) destruct(abs)
14qed.
15
16lemma destination_of_Some_to_is_jump_true:
17 ∀instr,dst. destination_of instr = Some … dst → is_jump' instr = true.
18 #instr #dst cases instr normalize // try (#H1 #H2 #abs) try (#H1 #abs) try #abs
19 destruct(abs)
20qed.
21
22lemma jump_expansion_step1:
23 ∀prefix: list labelled_instruction. S (|prefix|) < 2^16 → |prefix| < 2^16 → (*redundant*)
24 ∀labels: label_map.
25 ∀old_sigma : ppc_pc_map.
26 ∀inc_added : ℕ.
27 ∀inc_pc_sigma : ppc_pc_map.
28 ∀label : (option Identifier).
29 ∀instr : pseudo_instruction.
30 ∀inc_pc : ℕ.
31 ∀inc_sigma : (BitVectorTrie (ℕ×jump_length) 16).
32 ∀old_length : jump_length.
33 ∀Hpolicy : not_jump_default prefix 〈inc_pc,inc_sigma〉.
34 ∀policy : ppc_pc_map.
35 ∀new_length : jump_length.
36 ∀isize : ℕ.
37 let add_instr ≝ match instr with
38  [ Jmp  j        ⇒ Some ? (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
39  | Call c        ⇒ Some ? (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
40  | Instruction i ⇒ jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added (|prefix|) i
41  | _             ⇒ None ?
42  ] in
43 ∀Heq1 :
44  match add_instr with 
45   [None⇒〈short_jump,instruction_size_jmplen short_jump instr〉
46   |Some pl ⇒ 〈max_length old_length pl, instruction_size_jmplen (max_length old_length pl) instr〉]
47   =〈new_length,isize〉.
48 ∀Heq2 :
49   〈inc_pc+isize,
50     insert … (bitvector_of_nat … (S (|prefix|)))
51      〈inc_pc+isize, \snd  (lookup … (bitvector_of_nat … (S (|prefix|))) (\snd  old_sigma) 〈O,short_jump〉)〉
52      (insert … (bitvector_of_nat … (|prefix|)) 〈inc_pc,new_length〉 inc_sigma)〉
53   = policy.
54  not_jump_default (prefix@[〈label,instr〉]) policy.
55 #prefix #prefix_ok1 #prefix_ok #labels #old_sigma #inc_added #inc_pc_sigma #label #instr #inc_pc
56 #inc_sigma #old_length #Hpolicy #policy #new_length #isize #Heq1 #Heq2
57 #i >append_length <commutative_plus #Hi normalize in Hi;
58 cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
59 [ <Heq2 >lookup_insert_miss
60   [ >lookup_insert_miss
61     [ >(nth_append_first ? i prefix ?? Hi)
62       @(Hpolicy i Hi)
63     | @bitvector_of_nat_abs try assumption
64       [ @(transitive_lt ??? Hi) assumption ]
65       @lt_to_not_eq @Hi
66     ]
67   | @bitvector_of_nat_abs try assumption
68     [ @(transitive_lt ??? Hi) assumption ]
69     @lt_to_not_eq @le_S @Hi
70   ]
71 | <Heq2 >Hi >lookup_insert_miss
72   [ >lookup_insert_hit cases instr in Heq1;
73     [2,3,6: #x [3: #y] normalize nodelta #Heq1 <(proj1 ?? (pair_destruct ?????? Heq1)) #_ @refl
74     |4,5: #x normalize nodelta #Heq1 >nth_append_second try %
75           <minus_n_n #abs cases abs
76     |1: #pi normalize nodelta >nth_append_second [2: @le_n] <minus_n_n whd in match (nth ????);
77         #H #non_jump whd in match (jump_expansion_step_instruction ??????) in H;
78         >not_is_jump_to_destination_of_None in H; normalize nodelta // ]         
79   | @bitvector_of_nat_abs [3: // | @le_S_to_le ] assumption ]]
80qed.
81
82lemma jump_expansion_step2:
83 ∀prefix: list labelled_instruction. S (|prefix|) < 2^16 → |prefix| < 2^16 → (*redundant*)
84 ∀labels : label_map.
85 ∀old_sigma : ppc_pc_map.
86 ∀inc_pc : ℕ.
87 ∀inc_sigma : (BitVectorTrie (ℕ×jump_length) 16).
88 ∀Hpolicy1 :
89  \fst  (lookup … (bitvector_of_nat … O) inc_sigma 〈O,short_jump〉) = O.
90 ∀Hpolicy2:
91   inc_pc =\fst  (lookup … (bitvector_of_nat … (|prefix|)) inc_sigma 〈O,short_jump〉).
92 ∀policy : ppc_pc_map.
93 ∀new_length : jump_length.
94 ∀isize : ℕ.
95 ∀Heq2 :
96  〈inc_pc+isize,
97   insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
98   〈inc_pc+isize,
99   \snd  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
100               (\snd  old_sigma) 〈O,short_jump〉)〉
101   (insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
102    〈inc_pc,new_length〉 inc_sigma)〉
103   = policy.
104 \fst  (lookup … (bitvector_of_nat … O) (\snd  policy) 〈O,short_jump〉) = O.
105 #prefix #prefix_ok1 #prefix_ok #labels #old_sigma #inc_pc
106 #inc_sigma #Hpolicy1 #Hpolicy2 #policy #new_length #isize #Heq2
107 <Heq2 >lookup_insert_miss
108 [ cases (decidable_eq_nat 0 (|prefix|))
109   [ #Heq <Heq >lookup_insert_hit >Hpolicy2 <Heq @Hpolicy1
110   | #Hneq >lookup_insert_miss
111     [ @Hpolicy1
112     | @bitvector_of_nat_abs try assumption @lt_O_S ]]
113 | @bitvector_of_nat_abs [ @lt_O_S | @prefix_ok1 | 3: @lt_to_not_eq @lt_O_S ] ]
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 ∀program : list labelled_instruction.(*
456  (Σl:list labelled_instruction.S (|l|)< 2 \sup 16 ∧is_well_labelled_p l)*)
457 ∀labels : label_map.(*
458  (Σlm:label_map
459   .(∀l:identifier ASMTag
460     .occurs_exactly_once ASMTag pseudo_instruction l program
461      →bitvector_of_nat 16 (lookup_def ASMTag ℕ lm l O)
462       =address_of_word_labels_code_mem program l))*)
463 ∀old_sigma :
464   Σpolicy:ppc_pc_map
465   .(*not_jump_default program policy
466    ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) (\snd  policy)
467                 〈O,short_jump〉)
468     =O
469    ∧\fst  policy
470     =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|program|))
471                  (\snd  policy) 〈O,short_jump〉)
472    ∧*)sigma_compact_unsafe program labels policy
473    (*∧\fst  policy≤ 2 \sup 16*).
474 ∀prefix : list (option Identifier×pseudo_instruction).
475 ∀x : option Identifier×pseudo_instruction.
476 ∀tl : list (option Identifier×pseudo_instruction).
477 ∀prf : program=prefix@[x]@tl.(*
478 acc :
479  (Σx0:ℕ×ppc_pc_map
480   .(let 〈added,policy〉 ≝x0 in 
481     not_jump_default prefix policy
482     ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) (\snd  policy)
483                  〈O,short_jump〉)
484      =O
485     ∧\fst  policy
486      =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
487                   (\snd  policy) 〈O,short_jump〉)
488     ∧jump_increase prefix old_sigma policy
489     ∧sigma_compact_unsafe prefix labels policy
490     ∧(sigma_jump_equal prefix old_sigma policy→added=O)
491     ∧(added=O→sigma_pc_equal prefix old_sigma policy)
492     ∧out_of_program_none prefix policy
493     ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
494                  (\snd  policy) 〈O,short_jump〉)
495      =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
496                   (\snd  old_sigma) 〈O,short_jump〉)
497       +added
498     ∧sigma_safe prefix labels added old_sigma policy))*)
499 ∀inc_added : ℕ.
500 ∀inc_pc_sigma : ppc_pc_map.(*
501 p : (acc≃〈inc_added,inc_pc_sigma〉)*)
502 ∀label : option Identifier.
503 ∀instr : pseudo_instruction.
504 ∀p1 : x≃〈label,instr〉.(*
505 add_instr ≝
506  match instr
507   in pseudo_instruction
508   return λ_:pseudo_instruction.(option jump_length)
509   with 
510  [Instruction (i:(preinstruction Identifier))⇒
511   jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
512   (|prefix|) i
513  |Comment (_:String)⇒None jump_length
514  |Cost (_:costlabel)⇒None jump_length
515  |Jmp (j:Identifier)⇒
516   Some jump_length
517   (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
518  |Call (c:Identifier)⇒
519   Some jump_length
520   (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
521  |Mov (_:[[dptr]])   (_0:Identifier)⇒None jump_length]*)
522 ∀inc_pc : ℕ.
523 ∀inc_sigma : BitVectorTrie (ℕ×jump_length) 16.(*
524 Hips : (inc_pc_sigma=〈inc_pc,inc_sigma〉)*)
525 ∀old_pc : ℕ.
526 ∀old_length : jump_length.
527 ∀Holdeq :
528  lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) (\snd  old_sigma)
529   〈O,short_jump〉
530   =〈old_pc,old_length〉.
531 ∀Hpolicy1 :(*
532  (not_jump_default prefix 〈inc_pc,inc_sigma〉
533   ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) inc_sigma
534                〈O,short_jump〉)
535    =O
536   ∧inc_pc
537    =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) inc_sigma
538                 〈O,short_jump〉)
539   ∧jump_increase prefix old_sigma 〈inc_pc,inc_sigma〉
540   ∧sigma_compact_unsafe prefix labels 〈inc_pc,inc_sigma〉
541   ∧(sigma_jump_equal prefix old_sigma 〈inc_pc,inc_sigma〉→inc_added=O)
542   ∧( *)inc_added=O→sigma_pc_equal prefix old_sigma 〈inc_pc,inc_sigma〉.(*)
543   ∧out_of_program_none prefix 〈inc_pc,inc_sigma〉
544   ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) inc_sigma
545                〈O,short_jump〉)
546    =old_pc+inc_added
547   ∧sigma_safe prefix labels inc_added old_sigma 〈inc_pc,inc_sigma〉)*)
548 ∀Hpolic2: inc_pc
549    =\fst  (lookup … (bitvector_of_nat … (|prefix|)) inc_sigma 〈O,short_jump〉).
550 ∀added : ℕ.
551 ∀policy : ppc_pc_map.
552 ∀new_length : jump_length.
553 ∀isize : ℕ.
554 let add_instr ≝ match instr with
555  [ Jmp  j        ⇒ Some ? (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
556  | Call c        ⇒ Some ? (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
557  | Instruction i ⇒ jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added (|prefix|) i
558  | _             ⇒ None ?
559  ] in
560 ∀Heq1 :
561  match add_instr with 
562   [None⇒〈short_jump,instruction_size_jmplen short_jump instr〉
563   |Some (pl:jump_length)⇒
564    〈max_length old_length pl,
565    instruction_size_jmplen (max_length old_length pl) instr〉]
566   =〈new_length,isize〉.
567 ∀prefix_ok1 : S (|prefix|)< 2 \sup 16.
568 ∀prefix_ok : |prefix|< 2 \sup 16.
569 ∀Heq2a :
570  match add_instr with
571   [None⇒inc_added
572   |Some (x0:jump_length)⇒
573    inc_added+(isize-instruction_size_jmplen old_length instr)]
574   =added.
575 ∀Heq2b :
576  〈inc_pc+isize,
577   insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
578   〈inc_pc+isize,
579   \snd  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
580               (\snd  old_sigma) 〈O,short_jump〉)〉
581   (insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
582    〈inc_pc,new_length〉 inc_sigma)〉
583   =policy.
584 added=O→sigma_pc_equal (prefix@[〈label,instr〉]) old_sigma policy.
585 #program #labels #old_sigma #prefix #x #tl #prf #inc_added #inc_pc_sigma #label
586 #instr #p1 #inc_pc #inc_sigma #old_pc #old_length #Holdeq #Hpolicy1 #Hpolicy2
587 #added #policy #new_length #isize #Heq1 #prefix_ok #prefix_ok1 #Heq2a #Heq2b
588    (* USE[pass]: added = 0 → policy_pc_equal *)
589    lapply Hpolicy1 <Heq2b <Heq2a lapply Heq1 -Heq1
590    inversion instr normalize nodelta
591    [ #pi #Hins whd in match jump_expansion_step_instruction; normalize nodelta
592      lapply (destination_of_None_to_is_jump_false pi)
593      lapply (destination_of_Some_to_is_jump_true pi)
594      cases (destination_of ?) normalize nodelta
595      [ #_ #dest_None | #tgt #dest_Some #_ ]]
596    try (#x #y #Hins #Heq1 #Hold #Hadded #i #Hi)
597    try (#x #Hins #Heq1 #Hold #Hadded #i #Hi)
598    try (#Heq1 #Hold #Hadded #i #Hi)
599    >append_length in Hi; >commutative_plus #Hi normalize in Hi;
600    cases (le_to_or_lt_eq … Hi) -Hi #Hi
601    [1,3,5,7,9,11,13: cases (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
602      [1,3,5,7,9,11,13: <Heq2b >lookup_insert_miss
603        [1,3,5,7,9,11,13: >lookup_insert_miss
604          [1,3,5,7,9,11,13:
605            try @(Hold Hadded i (le_S_to_le … Hi))
606            @(Hold ? i (le_S_to_le … Hi)) >commutative_plus in Hadded; @plus_zero_zero
607          |*: @bitvector_of_nat_abs try assumption
608            [2,4,6,8,10,12,14: @lt_to_not_eq @Hi
609            |*: @(transitive_lt ??? Hi) assumption ]]
610        |*: @bitvector_of_nat_abs try assumption
611          [2,4,6,8,10,12,14: @lt_to_not_eq @le_S @Hi
612          |*: @(transitive_lt … Hi) assumption ]]
613      |*: >Hi >lookup_insert_miss
614        [1,3,5,7,9,11,13: >lookup_insert_hit
615          try (>(Hold Hadded (|prefix|) (le_n (|prefix|)))
616               @sym_eq (* USE: fst p = lookup |prefix| *)
617               @Hpolicy2)
618          >(Hold ? (|prefix|) (le_n (|prefix|)))
619          [2,4,6,8: >commutative_plus in Hadded; @plus_zero_zero] @sym_eq
620             (* USE: fst p = lookup |prefix| *)
621          @Hpolicy2
622        |*: @bitvector_of_nat_abs try assumption
623            @lt_to_not_eq %]]
624    |*: >Hi >lookup_insert_hit
625      (* USE fst p = lookup |prefix| *)
626      >Hpolicy2
627      <(Hold ? (|prefix|) (le_n (|prefix|))) try @Hadded
628      [3,7,9: @plus_zero_zero [2,4,6: >commutative_plus @Hadded |*: skip]]
629      (* USE: sigma_compact (from old_sigma) *)
630      lapply (pi2 ?? old_sigma (|prefix|) ?)
631      [1,3,5,7,9,11,13: >prf >append_length <plus_n_Sm @le_S_S @le_plus_n_r
632      |*:
633        inversion (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma))
634        [1,3,5,7,9,11,13: normalize nodelta #_ #ABS cases ABS
635        |*: inversion (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma))
636          [1,3,5,7,9,11,13: normalize nodelta #Hl * #pc #j normalize nodelta #Hl2 #ABS cases ABS
637          |*: normalize nodelta * #Spc #Sj #EQS * #pc #j #EQ
638            normalize nodelta >(lookup_opt_lookup_hit … EQS 〈0,short_jump〉)
639            >(lookup_opt_lookup_hit … EQ 〈0,short_jump〉)
640            >prf >p1 >Hins >nth_append_second try %
641            <minus_n_n whd in match (nth ????); <(proj2 ?? (pair_destruct ?????? Heq1))
642            #H >H @plus_left_monotone
643            [1,3,4,7: @instruction_size_irrelevant try %
644              whd in match is_jump; normalize nodelta >dest_None %
645            |*: >(lookup_opt_lookup_hit … EQ 〈0,short_jump〉) in Holdeq; #EQ'
646                >(proj2 … (pair_destruct … EQ'))
647               elim (le_to_or_lt_eq … (minus_zero_to_le … (plus_zero_zero … Hadded)))
648               [1,3,5: #H @⊥ @(absurd ? H) @le_to_not_lt
649                 <(proj2 ?? (pair_destruct ?????? Heq1))
650                 @jump_length_le_max try %
651                 whd in match is_jump; normalize nodelta >dest_Some %]
652               #EQisize >(proj2 … (pair_destruct … Heq1)) >EQisize % ]]]]]
653qed.
654
655lemma jump_expansion_step7:
656 ∀old_sigma : ppc_pc_map.
657 ∀prefix : list (option Identifier×pseudo_instruction).
658 ∀label : option Identifier.
659 ∀instr : pseudo_instruction.
660 ∀inc_pc : ℕ.
661 ∀inc_sigma : BitVectorTrie (ℕ×jump_length) 16.
662 ∀Hpolicy1 : out_of_program_none prefix 〈inc_pc,inc_sigma〉.
663 ∀policy : ppc_pc_map.
664 ∀new_length : jump_length.
665 ∀isize : ℕ.
666 ∀Heq2b :
667  〈inc_pc+isize,
668   insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
669   〈inc_pc+isize,
670   \snd  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
671               (\snd  old_sigma) 〈O,short_jump〉)〉
672   (insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
673    〈inc_pc,new_length〉 inc_sigma)〉
674   =policy.
675 out_of_program_none (prefix@[〈label,instr〉]) policy.
676 #old_sigma #prefix #label #instr #inc_pc #inc_sigma #Hpolicy1 #policy #new_length
677 #isize #Heq2b
678    #i #Hi2 >append_length <commutative_plus @conj
679    [ (* → *) #Hi normalize in Hi; <Heq2b >lookup_opt_insert_miss
680      [ >lookup_opt_insert_miss
681        [ cases (Hpolicy1 i Hi2) #X #_ @X @le_S_to_le @Hi
682        | @bitvector_of_nat_abs try assumption
683          [ @(transitive_lt … Hi2) @le_S_to_le assumption
684          | % #EQ <EQ in Hi; #abs @(absurd ?? (not_le_Sn_n (S i)))
685            @(transitive_le … abs) %2 % ]]
686      | @bitvector_of_nat_abs try assumption
687          [ @(transitive_lt … Hi2) assumption
688          | % #EQ <EQ in Hi; #abs @(absurd ?? (not_le_Sn_n i)) assumption ]]
689    | (* ← *) <Heq2b #Hl normalize
690      @(leb_elim (S i) (|prefix|))
691      [ #Hi
692        lapply (proj2 ?? (insert_lookup_opt_miss ?????? (proj2 ?? (insert_lookup_opt_miss ?????? Hl))))
693        #Hl2 (* USE[pass]: out_of_program_none ← *)
694        cases (Hpolicy1 i Hi2) #_
695        #Hi3 @⊥ @(absurd ? Hi) @le_to_not_lt @le_S_to_le @Hi3 assumption
696      | #Hi elim (le_to_or_lt_eq … (not_lt_to_le … Hi))
697        [ #Hi3 elim (le_to_or_lt_eq … Hi3)
698          [ #X @X
699          | #X lapply (proj1 ?? (insert_lookup_opt_miss ?????? Hl)) >X >eq_bv_refl #H normalize in H; destruct (H)
700          ]
701        | #X lapply (proj1 ?? (insert_lookup_opt_miss ?????? (proj2 ?? (insert_lookup_opt_miss ?????? Hl))))
702          >X >eq_bv_refl #H normalize in H; destruct (H)]]]
703qed.
704
705lemma jump_expansion_step8:
706 ∀program : list labelled_instruction.
707 ∀labels : label_map.
708 ∀old_sigma :
709  Σpolicy:ppc_pc_map.sigma_compact_unsafe program labels policy ∧\fst  policy≤ 2 \sup 16.
710 ∀prefix : list (option Identifier×pseudo_instruction).
711 ∀x : option Identifier×pseudo_instruction.
712 ∀tl : list (option Identifier×pseudo_instruction).
713 ∀prf : program=prefix@[x]@tl.
714 ∀inc_added : ℕ.
715 ∀inc_pc_sigma : ppc_pc_map.
716 ∀label : option Identifier.
717 ∀instr : pseudo_instruction.
718 ∀p1 : x≃〈label,instr〉.
719 ∀inc_pc : ℕ.
720 ∀inc_sigma : BitVectorTrie (ℕ×jump_length) 16.
721 ∀old_pc : ℕ.
722 ∀old_length : jump_length.
723 ∀Holdeq :
724  lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) (\snd  old_sigma)
725   〈O,short_jump〉
726   =〈old_pc,old_length〉.
727 ∀Hpolicy1 : inc_pc
728    =\fst  (lookup … (bitvector_of_nat … (|prefix|)) inc_sigma 〈O,short_jump〉).
729 ∀Hpolicy2: \fst  (lookup … (bitvector_of_nat … (|prefix|)) inc_sigma 〈O,short_jump〉)
730    =old_pc+inc_added.
731 ∀added : ℕ.
732 ∀policy : ppc_pc_map.
733 ∀new_length : jump_length.
734 ∀isize : ℕ.
735 let add_instr ≝ match instr with
736  [ Jmp  j        ⇒ Some ? (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
737  | Call c        ⇒ Some ? (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
738  | Instruction i ⇒ jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added (|prefix|) i
739  | _             ⇒ None ?
740  ] in
741 ∀Heq1 :
742  match add_instr with 
743   [None⇒〈short_jump,instruction_size_jmplen short_jump instr〉
744   |Some (pl:jump_length)⇒
745    〈max_length old_length pl,
746    instruction_size_jmplen (max_length old_length pl) instr〉]
747   =〈new_length,isize〉.
748 ∀Heq2a :
749  match add_instr with
750   [None⇒inc_added
751   |Some (x0:jump_length)⇒
752    inc_added+(isize-instruction_size_jmplen old_length instr)]
753   =added.
754 ∀Heq2b :
755  〈inc_pc+isize,
756   insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
757   〈inc_pc+isize,
758   \snd  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
759               (\snd  old_sigma) 〈O,short_jump〉)〉
760   (insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
761    〈inc_pc,new_length〉 inc_sigma)〉
762   =policy.
763   \fst  (lookup (ℕ×jump_length) 16
764              (bitvector_of_nat 16 (|(prefix@[〈label,instr〉])|)) (\snd  policy)
765              〈O,short_jump〉)
766  =\fst  (lookup (ℕ×jump_length) 16
767               (bitvector_of_nat 16 (|(prefix@[〈label,instr〉])|)) (\snd  old_sigma)
768               〈O,short_jump〉)
769   +added.
770 #program #labels #old_sigma #prefix #x #tl #prf #inc_added #inc_pc_sigma #label #instr
771 #p1 #inc_pc #inc_sigma #old_pc #old_length #Holdeq #Hpolicy1 #Hpolicy2 #added
772 #policy #new_length #isize #Heq1 #Heq2a #Heq2b
773    <Heq2b >append_length <plus_n_Sm <plus_n_O
774    >lookup_insert_hit
775    <Heq2a cases instr in p1 Heq1;
776    [1: #pi normalize nodelta whd in match jump_expansion_step_instruction;
777        normalize nodelta lapply (destination_of_None_to_is_jump_false pi)
778        lapply (destination_of_Some_to_is_jump_true pi)
779        cases (destination_of ?) normalize nodelta ]
780    try (#x #y #z #p1 #Heq1) try (#x #y #p1 #Heq1) try (#x #p1 #Heq1) try (#p1 #Heq1)
781    <(proj2 ?? (pair_destruct ?????? Heq1))
782    (* USE: sigma_compact_unsafe (from old_sigma) *)
783    lapply (proj1 ?? (pi2 ?? old_sigma) (|prefix|) ?)
784    [1,3,5,7,9,11,13,15: >prf >append_length <plus_n_Sm @le_S_S @le_plus_n_r]
785    lapply Holdeq -Holdeq
786    inversion (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma))
787    [1,3,5,7,9,11,13,15: normalize nodelta #_ #_ #abs cases abs]
788    inversion (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma))
789    [1,3,5,7,9,11,13,15: normalize nodelta #_ * #Spc #Sj normalize nodelta #_ #_ #abs cases abs]
790    * #Spc #Sj #EQS * #pc #j #Holdeq #EQ normalize nodelta
791    #H (* USE: fst p = lookup |prefix| *) (*CSC: This part of the proof is repeated somewhere else*)
792    >Hpolicy1
793    (* USE[pass]: lookup p = lookup old_sigma + added *)
794    >Hpolicy2
795    [1,3,4,7:
796      >(lookup_opt_lookup_hit … Holdeq 〈0,short_jump〉) in EQ;
797      -Holdeq #EQ <(proj1 ?? (pair_destruct ?????? EQ))
798      >(lookup_opt_lookup_hit … EQS 〈0,short_jump〉) >H >prf >nth_append_second try %
799      <minus_n_n >p1 whd in match (nth ????); >associative_plus
800      >(associative_plus pc) @plus_left_monotone >commutative_plus
801      @plus_right_monotone @instruction_size_irrelevant try %
802      whd in match is_jump; normalize nodelta >y %
803    |2,5,6:
804      >(lookup_opt_lookup_hit … EQS 〈0,short_jump〉) >H
805      >(lookup_opt_lookup_hit … Holdeq 〈0,short_jump〉) in EQ; #EQ
806      -Holdeq <(proj1 ?? (pair_destruct ?????? EQ))
807      >associative_plus
808      >(associative_plus pc) @plus_left_monotone >assoc_plus1
809      >(associative_plus inc_added) @plus_left_monotone >plus_minus_commutative
810      [1,3,5: >(proj2 ?? (pair_destruct ?????? EQ)) >prf in old_sigma; #old_sigma
811        >nth_append_second try %
812        <minus_n_n whd in match (nth ????); >p1 in old_sigma; #old_sigma
813        >commutative_plus @minus_plus_m_m
814      |*: <(proj2 ?? (pair_destruct ?????? Heq1)) @jump_length_le_max try %
815        whd in match is_jump; normalize nodelta >y %]]
816qed.
817
818lemma jump_expansion_step9:
819(*
820 program :
821  (Σl:list labelled_instruction.S (|l|)< 2 \sup 16 ∧is_well_labelled_p l)*)
822 ∀labels : label_map.(*
823  (Σlm:label_map
824   .(∀l:identifier ASMTag
825     .occurs_exactly_once ASMTag pseudo_instruction l program
826      →bitvector_of_nat 16 (lookup_def ASMTag ℕ lm l O)
827       =address_of_word_labels_code_mem program l))*)
828 ∀old_sigma : ppc_pc_map.(*
829  (Σpolicy:ppc_pc_map
830   .not_jump_default program policy
831    ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) (\snd  policy)
832                 〈O,short_jump〉)
833     =O
834    ∧\fst  policy
835     =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|program|))
836                  (\snd  policy) 〈O,short_jump〉)
837    ∧sigma_compact_unsafe program labels policy
838    ∧\fst  policy≤ 2 \sup 16 )*)
839 ∀prefix : list (option Identifier×pseudo_instruction).(*
840 x : (option Identifier×pseudo_instruction)
841 tl : (list (option Identifier×pseudo_instruction))
842 prf : (program=prefix@[x]@tl)
843 acc :
844  (Σx0:ℕ×ppc_pc_map
845   .(let 〈added,policy〉 ≝x0 in 
846     not_jump_default prefix policy
847     ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) (\snd  policy)
848                  〈O,short_jump〉)
849      =O
850     ∧\fst  policy
851      =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
852                   (\snd  policy) 〈O,short_jump〉)
853     ∧jump_increase prefix old_sigma policy
854     ∧sigma_compact_unsafe prefix labels policy
855     ∧(sigma_jump_equal prefix old_sigma policy→added=O)
856     ∧(added=O→sigma_pc_equal prefix old_sigma policy)
857     ∧out_of_program_none prefix policy
858     ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
859                  (\snd  policy) 〈O,short_jump〉)
860      =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
861                   (\snd  old_sigma) 〈O,short_jump〉)
862       +added
863     ∧sigma_safe prefix labels added old_sigma policy))
864 inc_added : ℕ
865 inc_pc_sigma : ppc_pc_map
866 p : (acc≃〈inc_added,inc_pc_sigma〉)*)
867 ∀label : option Identifier.
868 ∀instr : pseudo_instruction.(*
869 p1 : (x≃〈label,instr〉)
870 add_instr ≝
871  match instr
872   in pseudo_instruction
873   return λ_:pseudo_instruction.(option jump_length)
874   with 
875  [Instruction (i:(preinstruction Identifier))⇒
876   jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
877   (|prefix|) i
878  |Comment (_:String)⇒None jump_length
879  |Cost (_:costlabel)⇒None jump_length
880  |Jmp (j:Identifier)⇒
881   Some jump_length
882   (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
883  |Call (c:Identifier)⇒
884   Some jump_length
885   (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
886  |Mov (_:[[dptr]])   (_0:Identifier)⇒None jump_length]
887 inc_pc : ℕ
888 inc_sigma : (BitVectorTrie (ℕ×jump_length) 16)
889 Hips : (inc_pc_sigma=〈inc_pc,inc_sigma〉)
890 old_pc : ℕ
891 old_length : jump_length
892 Holdeq :
893  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) (\snd  old_sigma)
894   〈O,short_jump〉
895   =〈old_pc,old_length〉)
896 Hpolicy :
897  (not_jump_default prefix 〈inc_pc,inc_sigma〉
898   ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) inc_sigma
899                〈O,short_jump〉)
900    =O
901   ∧inc_pc
902    =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) inc_sigma
903                 〈O,short_jump〉)
904   ∧jump_increase prefix old_sigma 〈inc_pc,inc_sigma〉
905   ∧sigma_compact_unsafe prefix labels 〈inc_pc,inc_sigma〉
906   ∧(sigma_jump_equal prefix old_sigma 〈inc_pc,inc_sigma〉→inc_added=O)
907   ∧(inc_added=O→sigma_pc_equal prefix old_sigma 〈inc_pc,inc_sigma〉)
908   ∧out_of_program_none prefix 〈inc_pc,inc_sigma〉
909   ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) inc_sigma
910                〈O,short_jump〉)
911    =old_pc+inc_added
912   ∧sigma_safe prefix labels inc_added old_sigma 〈inc_pc,inc_sigma〉)*)
913 ∀added : ℕ.
914 ∀policy : ppc_pc_map.(*
915 new_length : jump_length
916 isize : ℕ
917 Heq1 :
918  (match 
919   match instr
920    in pseudo_instruction
921    return λ_:pseudo_instruction.(option jump_length)
922    with 
923   [Instruction (i:(preinstruction Identifier))⇒
924    jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
925    (|prefix|) i
926   |Comment (_:String)⇒None jump_length
927   |Cost (_:costlabel)⇒None jump_length
928   |Jmp (j:Identifier)⇒
929    Some jump_length
930    (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
931   |Call (c:Identifier)⇒
932    Some jump_length
933    (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
934   |Mov (_:[[dptr]])   (_0:Identifier)⇒None jump_length]
935    in option
936    return λ_0:(option jump_length).(jump_length×ℕ)
937    with 
938   [None⇒〈short_jump,instruction_size_jmplen short_jump instr〉
939   |Some (pl:jump_length)⇒
940    〈max_length old_length pl,
941    instruction_size_jmplen (max_length old_length pl) instr〉]
942   =〈new_length,isize〉)
943 prefix_ok1 : (S (|prefix|)< 2 \sup 16 )
944 prefix_ok : (|prefix|< 2 \sup 16 )
945 Heq2a :
946  (match 
947   match instr
948    in pseudo_instruction
949    return λ_0:pseudo_instruction.(option jump_length)
950    with 
951   [Instruction (i:(preinstruction Identifier))⇒
952    jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
953    (|prefix|) i
954   |Comment (_0:String)⇒None jump_length
955   |Cost (_0:costlabel)⇒None jump_length
956   |Jmp (j:Identifier)⇒
957    Some jump_length
958    (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
959   |Call (c:Identifier)⇒
960    Some jump_length
961    (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
962   |Mov (_0:[[dptr]])   (_00:Identifier)⇒None jump_length]
963    in option
964    return λ_0:(option jump_length).ℕ
965    with 
966   [None⇒inc_added
967   |Some (x0:jump_length)⇒
968    inc_added+(isize-instruction_size_jmplen old_length instr)]
969   =added)
970 Heq2b :
971  (〈inc_pc+isize,
972   insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
973   〈inc_pc+isize,
974   \snd  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
975               (\snd  old_sigma) 〈O,short_jump〉)〉
976   (insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
977    〈inc_pc,new_length〉 inc_sigma)〉
978   =policy)
979*)
980 sigma_safe (prefix@[〈label,instr〉]) labels added old_sigma policy.
981cases daemon(*
982    #i >append_length >commutative_plus #Hi normalize in Hi;
983    elim (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
984    [ >nth_append_first [2: @Hi]
985      <Heq2b >lookup_insert_miss
986      [ >lookup_insert_miss
987        [ >lookup_insert_miss
988          [ elim (le_to_or_lt_eq … Hi) -Hi #Hi
989            [ >lookup_insert_miss
990              [ (* USE[pass]: sigma_safe *)
991                lapply ((proj2 ?? Hpolicy) i (le_S_to_le … Hi))
992                cases (bvt_lookup … (bitvector_of_nat ? i) inc_sigma 〈0,short_jump〉)
993                #pc #j normalize nodelta
994                cases (bvt_lookup … (bitvector_of_nat ? (S i)) inc_sigma 〈0,short_jump〉)
995                #Spc #Sj normalize nodelta
996                cases (nth i ? prefix 〈None ?, Comment []〉) #lbl #ins normalize nodelta
997                #Hind #dest #Hj lapply (Hind dest Hj) -Hind -Hj
998                lapply (refl ? (leb (lookup_def … labels dest 0) (S (|prefix|))))
999                cases (leb (lookup_def … labels dest 0) (S (|prefix|))) in ⊢ (???% → %); #H
1000                [ cases (le_to_or_lt_eq … (leb_true_to_le … H)) -H #H
1001                  [ >(le_to_leb_true … (le_S_S_to_le … H)) normalize nodelta
1002                    >lookup_insert_miss
1003                    [ cases (le_to_or_lt_eq … (le_S_S_to_le … H)) -H #H
1004                      [ >lookup_insert_miss
1005                        [ #H2 @H2
1006                        | @bitvector_of_nat_abs
1007                          [3: @lt_to_not_eq @H
1008                          |1: @(transitive_lt ??? H)
1009                          ]
1010                          @prefix_ok
1011                        ]
1012                      | >H >lookup_insert_hit
1013                        (* USE: inc_pc = lookup |prefix| *)
1014                        >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1015                        #H2 @H2
1016                      ]
1017                    | @bitvector_of_nat_abs
1018                      [3: @lt_to_not_eq @H
1019                      |1: @(transitive_lt ??? H)
1020                      ]
1021                      @prefix_ok1
1022                    ]
1023                  | >H >lookup_insert_hit normalize nodelta
1024                    >(not_le_to_leb_false … (lt_to_not_le ?? (le_S_S ?? (le_n (|prefix|)))))
1025                    normalize nodelta
1026                    >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1027                    #H2 >(proj2 ?? (proj1 ?? Hpolicy))
1028                  ]
1029                |
1030                       
1031                       
1032                       
1033                [2,3,6: [3: #x] #y normalize nodelta #EQ <EQ cases j normalize nodelta
1034                  [1,4,7: cases (decidable_le (lookup_def … labels dest 0) (S (|prefix|))) #H
1035                    [1,3,5: >(le_to_leb_true … H) normalize nodelta cases (le_to_or_lt_eq … H) -H #H
1036                      [1,3,5: >(le_to_leb_true … (le_S_S_to_le … H)) normalize nodelta
1037                        >lookup_insert_miss
1038                        [2,4,6: @bitvector_of_nat_abs
1039                          [3,6,9: @lt_to_not_eq @H
1040                          |1,4,7: @(transitive_lt ??? H)
1041                          ]
1042                          @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf
1043                          @le_S_S >append_length <plus_n_Sm @le_S_S @le_plus_n_r
1044                        ]
1045                        cases (le_to_or_lt_eq … H) -H #H
1046                        [1,3,5: >lookup_insert_miss
1047                          [1,3,5: #H @H
1048                          |2,4,6: @bitvector_of_nat_abs
1049                            [3,6,9: @lt_to_not_eq @(le_S_S_to_le … H)
1050                            |1,4,7: @(transitive_lt ??? (le_S_S_to_le … H))
1051                            ]
1052                            @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf
1053                            >append_length @le_S_S @le_plus_n_r
1054                          ]
1055                        |2,4,6: >(injective_S … H) >lookup_insert_hit
1056                          (* USE: blerp *)
1057                          >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1058                          #H @H
1059                        ]
1060                      |2,4,6: >H >lookup_insert_hit >(not_le_to_leb_false)
1061                        [2,4,6: @le_to_not_lt @le_n]
1062                        normalize nodelta
1063                        lapply (proj2 ?? (proj1 ?? (pi2 ?? old_sigma)) (|prefix|) ?)
1064                        [1,3,5: >prf >append_length <plus_n_Sm @le_S_S @le_plus_n_r]
1065                         lapply (refl ? (lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)))
1066                          cases (lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)) in ⊢ (???% → %);
1067                          [1,3,5: normalize nodelta #_ #abs cases abs
1068                          |2,4,6: #x cases x -x #ppc #pj normalize nodelta #PEQ
1069                            lapply (refl ? (lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)))
1070                            cases (lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)) in ⊢ (???% → %);
1071                            [1,3,5: normalize nodelta #_ #abs cases abs
1072                            |2,4,6: #x cases x -x #Sppc #Spj normalize nodelta #SPEQ #Pcompact
1073                              >(lookup_opt_lookup_hit … SPEQ 〈0,short_jump〉)
1074                              >(lookup_opt_lookup_hit … PEQ 〈0,short_jump〉) in Holdeq;
1075                              #H >Pcompact >(proj1 ?? (pair_destruct ?????? H))
1076                              >commutative_plus >assoc_plus1 <(proj2 ?? (proj1 ?? Hpolicy))
1077                              <(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1078                              >prf >nth_append_second
1079                              [1,3,5: <minus_n_n whd in match (nth ????); >p1
1080                                cases daemon (* to be lemmatized *)
1081                              |2,4,6: @le_n
1082                              ]
1083                            ]
1084                          ]
1085                        ]
1086                      |2,4,6: >(not_le_to_leb_false … H)
1087                        >not_le_to_leb_false
1088                        [2,4,6: @lt_to_not_le @le_S_to_le @not_le_to_lt @H
1089                        |1,3,5: normalize nodelta #H @H
1090                        ]
1091                      ]
1092                    |2,5,8: cases daemon (* like previous case *)
1093                    |3,6,9: cases daemon (* like previous case *)
1094                    ]
1095                  |4,5: #x normalize nodelta cases daemon (* blerp *)
1096                  |1: cases daemon (* blerp *)
1097                  ]
1098               
1099                               
1100                         
1101
1102   (*(\fst  (short_jump_cond (bitvector_of_nat 16 Spc)
1103              (bitvector_of_nat 16
1104               (inc_pc
1105                +instruction_size_jmplen
1106                 (max_length old_length
1107                  (select_jump_length labels old_sigma inc_pc_sigma inc_added
1108                   (|prefix|) xx)) (Jmp xx))))
1109  =true                   *)
1110                       
1111                 
1112  ]       
1113              [ >lookup_insert_miss
1114                [ (* USE[pass]: sigma_safe *)
1115                  lapply ((proj2 ?? Hpolicy) i (le_S_to_le … Hi))
1116                  cases (bvt_lookup … (bitvector_of_nat ? i) inc_sigma 〈0,short_jump〉)
1117                  #pc #j normalize nodelta
1118                  cases (bvt_lookup … (bitvector_of_nat ? (S i)) inc_sigma 〈0,short_jump〉)
1119                  #Spc #Sj normalize nodelta
1120                  cases (nth i ? prefix 〈None ?, Comment []〉) #lbl #ins normalize nodelta
1121                  #Hind #dest #Hj lapply (Hind dest Hj) -Hind -Hj lapply (proj1 ?? (pair_destruct ?????? Heq2)) cases instr
1122                  [2,3,6: [3: #x] #y normalize nodelta #EQ <EQ cases j normalize nodelta
1123                    [1,4,7: *)
1124qed.
1125
1126(* One step in the search for a jump expansion fixpoint. *)
1127definition jump_expansion_step: ∀program:(Σl:list labelled_instruction.
1128  S (|l|) < 2^16 ∧ is_well_labelled_p l).
1129  ∀labels:(Σlm:label_map.∀l.
1130    occurs_exactly_once ?? l program →
1131    bitvector_of_nat ? (lookup_def … lm l 0) =
1132    address_of_word_labels_code_mem program l).
1133  ∀old_policy:(Σpolicy:ppc_pc_map.
1134    (* out_of_program_none program policy *)
1135    And (And (And (And (not_jump_default program policy)
1136    (\fst (bvt_lookup … (bitvector_of_nat ? 0) (\snd policy) 〈0,short_jump〉) = 0))
1137    (\fst policy = \fst (bvt_lookup … (bitvector_of_nat ? (|program|)) (\snd policy) 〈0,short_jump〉)))
1138    (sigma_compact_unsafe program labels policy))
1139    (\fst policy ≤ 2^16)).
1140  (Σx:bool × (option ppc_pc_map).
1141    let 〈no_ch,y〉 ≝ x in
1142    match y with
1143    [ None ⇒ nec_plus_ultra program old_policy
1144    | Some p ⇒ And (And (And (And (And (And (And
1145       (not_jump_default program p)
1146       (\fst (bvt_lookup … (bitvector_of_nat ? 0) (\snd p) 〈0,short_jump〉) = 0))
1147       (\fst p = \fst (bvt_lookup … (bitvector_of_nat ? (|program|)) (\snd p) 〈0,short_jump〉)))
1148       (jump_increase program old_policy p))
1149       (sigma_compact_unsafe program labels p))
1150       (sigma_jump_equal program old_policy p → no_ch = true))
1151       (no_ch = true → sigma_pc_equal program old_policy p))
1152       (\fst p ≤ 2^16)
1153    ])
1154    ≝
1155  λprogram.λlabels.λold_sigma.
1156  let 〈final_added, final_policy〉 ≝
1157    pi1 ?? (foldl_strong (option Identifier × pseudo_instruction)
1158    (λprefix.Σx:ℕ × ppc_pc_map.
1159      let 〈added,policy〉 ≝ x in
1160      And (And (And (And (And (And (And (And (And (not_jump_default prefix policy)
1161      (\fst (bvt_lookup … (bitvector_of_nat ? 0) (\snd policy) 〈0,short_jump〉) = 0))
1162      (\fst policy = \fst (bvt_lookup … (bitvector_of_nat ? (|prefix|)) (\snd policy) 〈0,short_jump〉)))
1163      (jump_increase prefix old_sigma policy))
1164      (sigma_compact_unsafe prefix labels policy))
1165      (sigma_jump_equal prefix old_sigma policy → added = 0))
1166      (added = 0 → sigma_pc_equal prefix old_sigma policy))
1167      (out_of_program_none prefix policy))
1168      (\fst (bvt_lookup … (bitvector_of_nat ? (|prefix|)) (\snd policy) 〈0,short_jump〉) =
1169       \fst (bvt_lookup … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma) 〈0,short_jump〉) + added))
1170      (sigma_safe prefix labels added old_sigma policy))
1171    program
1172    (λprefix.λx.λtl.λprf.λacc.
1173      let 〈inc_added, inc_pc_sigma〉 ≝ (pi1 ?? acc) in
1174      let 〈label,instr〉 ≝ x in
1175      (* Now, we must add the current ppc and its pc translation.
1176       * Three possibilities:
1177       *   - Instruction is not a jump; i.e. constant size whatever the sigma we use;
1178       *   - Instruction is a backward jump; we can use the sigma we're constructing,
1179       *     since it will already know the translation of its destination;
1180       *   - Instruction is a forward jump; we must use the old sigma (the new sigma
1181       *     does not know the translation yet), but compensate for the jumps we
1182       *     have lengthened.
1183       *)
1184      let add_instr ≝ match instr with
1185      [ Jmp  j        ⇒ Some ? (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
1186      | Call c        ⇒ Some ? (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
1187      | Instruction i ⇒ jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added (|prefix|) i
1188      | _             ⇒ None ?
1189      ] in
1190      let 〈inc_pc, inc_sigma〉 ≝ inc_pc_sigma in
1191      let old_length ≝
1192        \snd (bvt_lookup … (bitvector_of_nat ? (|prefix|)) (\snd (pi1 ?? old_sigma)) 〈0,short_jump〉) in
1193      let old_size ≝ instruction_size_jmplen old_length instr in
1194      let 〈new_length, isize〉 ≝ match add_instr with
1195      [ None    ⇒ 〈short_jump, instruction_size_jmplen short_jump instr〉
1196      | Some pl ⇒ 〈max_length old_length pl, instruction_size_jmplen (max_length old_length pl) instr〉
1197      ] in
1198      let new_added ≝ match add_instr with
1199      [ None   ⇒ inc_added
1200      | Some x ⇒ plus inc_added (minus isize old_size)
1201      ] in
1202      let old_Slength ≝
1203        \snd (bvt_lookup … (bitvector_of_nat ? (S (|prefix|))) (\snd (pi1 ?? old_sigma)) 〈0,short_jump〉) in
1204      let updated_sigma ≝
1205        (* we add the new PC to the next position and the new jump length to this one *)
1206        bvt_insert … (bitvector_of_nat ? (S (|prefix|))) 〈inc_pc + isize, old_Slength〉
1207        (bvt_insert … (bitvector_of_nat ? (|prefix|)) 〈inc_pc, new_length〉 inc_sigma) in
1208      〈new_added, 〈plus inc_pc isize, updated_sigma〉〉
1209    ) 〈0, 〈0,
1210      bvt_insert …
1211        (bitvector_of_nat ? 0)
1212        〈0, \snd (bvt_lookup … (bitvector_of_nat ? 0) (\snd (pi1 ?? old_sigma)) 〈0,short_jump〉)〉
1213        (Stub ??)〉〉
1214    ) in
1215    if gtb (\fst final_policy) 2^16 then
1216      〈eqb final_added 0, None ?〉
1217    else
1218      〈eqb final_added 0, Some ? final_policy〉.
1219[ normalize nodelta @nmk #Habs lapply p -p cases (foldl_strong ? (λ_.Σx.?) ???)
1220  #x #H #Heq >Heq in H; normalize nodelta -Heq -x #Hind
1221  (* USE: inc_pc = fst of policy (from fold) *)
1222  >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hind)))))))) in p1;
1223  (* USE: fst policy < 2^16, inc_pc = fst of policy (old_sigma) *)
1224  lapply (proj2 ?? (pi2 ?? old_sigma)) >(proj2 ?? (proj1 ?? (proj1 ?? (pi2 ?? old_sigma))))
1225  #Hsig #Hge
1226  (* USE: added = 0 → policy_pc_equal (from fold) *)
1227  lapply ((proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hind)))) ? (|program|) (le_n (|program|)))
1228  [ (* USE: policy_jump_equal → added = 0 (from fold) *)
1229    @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hind))))) #i #Hi
1230    inversion (is_jump (\snd (nth i ? program 〈None ?, Comment []〉)))
1231    [ #Hj
1232      (* USE: policy_increase (from fold) *)
1233      lapply (proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hind)))))) i (le_S_to_le … Hi))
1234      lapply (Habs i Hi ?) [ >Hj %]
1235      cases (bvt_lookup … (bitvector_of_nat ? i) (\snd old_sigma) 〈0,short_jump〉)
1236      #opc #oj
1237      cases (bvt_lookup … (bitvector_of_nat ? i) (\snd final_policy) 〈0,short_jump〉)
1238      #pc #j normalize nodelta #Heq >Heq cases j
1239      [1,2: #abs cases abs #abs2 try (cases abs2) @refl
1240      |3: #_ @refl
1241      ]
1242    | #Hnj
1243      (* USE: not_jump_default (from fold and old_sigma) *)
1244      >(proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hind)))))))) i Hi ?)
1245      [2: >Hnj %]
1246      >(proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (pi2 ?? old_sigma)))) i Hi ?) try %
1247      >Hnj %
1248    ]
1249  | #abs >abs in Hsig; #Hsig
1250    @(absurd ? Hsig) @lt_to_not_le @ltb_true_to_lt @Hge
1251  ]
1252| normalize nodelta lapply p -p cases (foldl_strong ? (λ_.Σx.?)???) in ⊢ (% → ?); #x #H #H2
1253  >H2 in H; normalize nodelta -H2 -x #H @conj
1254  [ @conj [ @conj
1255  [ (* USE[pass]: not_jump_default, 0 ↦ 0, inc_pc = fst policy,
1256     * jump_increase, sigma_compact_unsafe (from fold) *)
1257    @(proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? H)))))
1258  | #H2 (* USE[pass]: sigma_jump_equal → added = 0 (from fold) *)
1259    @eq_to_eqb_true @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? H))))) @H2
1260  ]
1261  | (* USE[pass]: added = 0 → sigma_pc_equal (from fold) *)
1262     #H2 @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? H)))) @eqb_true_to_eq @H2
1263  ]
1264  | @not_lt_to_le @ltb_false_to_not_lt @p1
1265  ]
1266|4: lapply (pi2 ?? acc) >p -acc inversion inc_pc_sigma
1267  #inc_pc #inc_sigma #Hips normalize nodelta
1268  inversion (bvt_lookup … (bitvector_of_nat ? (|prefix|)) (\snd (pi1 ?? old_sigma)) 〈0,short_jump〉)
1269  #old_pc #old_length #Holdeq #Hpolicy normalize nodelta in Hpolicy; @pair_elim
1270  #added #policy normalize nodelta @pair_elim #new_length #isize normalize nodelta
1271  #Heq1 #Heq2
1272 cut (S (|prefix|) < 2^16)
1273 [ @(transitive_lt … (proj1 … (pi2 ?? program))) @le_S_S >prf >append_length
1274   <plus_n_Sm @le_S_S @le_plus_n_r ] #prefix_ok1
1275 cut (|prefix| < 2^16) [ @(transitive_lt … prefix_ok1) %] #prefix_ok
1276 cases (pair_destruct ?????? Heq2) -Heq2 #Heq2a #Heq2b
1277  % [ % [ % [ % [ % [ % [ % [ % [ % ]]]]]]]]
1278  (* NOTE: to save memory and speed up work, there's cases daemon here. They can be
1279   * commented out for full proofs, but this needs a lot of memory and time *)
1280  [ (* not_jump_default *)
1281    @(jump_expansion_step1 … Heq1 Heq2b) try assumption
1282    @(proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))))
1283  | (* 0 ↦ 0 *)
1284    @(jump_expansion_step2 … Heq2b) try assumption
1285    [ @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ??  (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))))
1286    | @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))) ]
1287  | (* inc_pc = fst of policy *)
1288    <Heq2b >append_length >(commutative_plus (|prefix|)) >lookup_insert_hit @refl
1289  | (* jump_increase *)
1290    @(jump_expansion_step3 … (pi1 ?? old_sigma) … prf … p1 ??? old_length Holdeq
1291      … Heq1 prefix_ok1 prefix_ok Heq2b)
1292    try @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))
1293    cases (pi2 … old_sigma) * * * #H #_ #_ #_ #_ @H
1294  | (* sigma_compact_unsafe *)
1295    @(jump_expansion_step4 … Heq1 … Heq2b) try assumption
1296    try @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ??  (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1297    try @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))
1298    @(proj2 ?? (proj1 ?? (proj1 ?? Hpolicy)))
1299  | (* policy_jump_equal → added = 0 *)
1300    @(jump_expansion_step5 … Holdeq … Heq1 … Heq2b) try assumption
1301    try @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))
1302    @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1303  | (* added = 0 → policy_pc_equal *) cases daemon (*
1304    @(jump_expansion_step6 … Heq1 … Heq2b) try assumption
1305    try @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))
1306    @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1307    *)
1308  | (* out_of_program_none *)
1309    @(jump_expansion_step7 … Heq2b)
1310    @(proj2 ?? (proj1 ?? (proj1 ?? Hpolicy)))
1311  | (* lookup p = lookup old_sigma + added *)
1312    @(jump_expansion_step8 (pi1 ?? program) (pi1 ?? labels) (pi1 ?? old_sigma) … Holdeq … Heq1 Heq2a Heq2b) try assumption
1313    [ cases (pi2 … old_sigma) * #_ #H1 #H2 % assumption
1314    | @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1315    | @(proj2 ?? (proj1 ?? Hpolicy)) ]
1316  | (* sigma_safe *) cases daemon (*
1317    @jump_expansion_step9 try assumption
1318    @(proj2 ?? Hpolicy) *)
1319  ]     
1320| normalize nodelta % [ % [ % [ % [ % [ % [ % [ % [ % ]]]]]]]]
1321  [ #i cases i
1322    [ #Hi @⊥ @(absurd … Hi) @not_le_Sn_O
1323    | -i #i #Hi #Hj @⊥ @(absurd … Hi) @not_le_Sn_O
1324    ]
1325  | >lookup_insert_hit @refl
1326  | >lookup_insert_hit @refl
1327  | #i #Hi <(le_n_O_to_eq … Hi)
1328    >lookup_insert_hit cases (bvt_lookup … (bitvector_of_nat ? 0) (\snd old_sigma) 〈0,short_jump〉)
1329    #a #b normalize nodelta %2 @refl
1330  | #i cases i
1331    [ #Hi @⊥ @(absurd … Hi) @not_le_Sn_O
1332    | -i #i #Hi @⊥ @(absurd … Hi) @not_le_Sn_O
1333    ]
1334  | #_ %
1335  | #_ #i #Hi <(le_n_O_to_eq … Hi) >lookup_insert_hit
1336    (* USE: 0 ↦ 0 (from old_sigma) *)
1337    @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (pi2 ?? old_sigma)))))
1338  | #i cases i
1339    [ #Hi2 @conj
1340      [ #Hi @⊥ @(absurd ? Hi) @le_to_not_lt / by /
1341      | >lookup_opt_insert_hit #H destruct (H)
1342      ]
1343    | -i #i #Hi2 @conj
1344      [ #Hi >lookup_opt_insert_miss
1345        [ / by refl/
1346        | @bitvector_of_nat_abs
1347          [ @Hi2
1348          | / by /
1349          | @sym_neq @lt_to_not_eq / by /
1350          ]
1351        ]
1352      | #_ @le_S_S @le_O_n
1353      ]
1354    ]
1355  | >lookup_insert_hit (* USE: 0 ↦ 0 (from old_sigma) *)
1356    >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (pi2 ?? old_sigma))))) <plus_n_O %
1357  | #i cases i
1358    [ #Hi @⊥ @(absurd … Hi) @not_le_Sn_O
1359    | -i #i #Hi @⊥ @(absurd … Hi) @not_le_Sn_O
1360    ]
1361  ]
1362]
1363qed.
Note: See TracBrowser for help on using the repository browser.