source: src/ASM/PolicyStep.ma @ 2243

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

One more lemma streamlined, one to go + one to be completed.

File size: 76.2 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(*
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 ∀program : list labelled_instruction.
971 ∀labels : label_map.
972 ∀old_sigma :
973  Σpolicy:ppc_pc_map.sigma_compact_unsafe program labels policy ∧\fst  policy≤ 2 \sup 16.
974 ∀prefix : list (option Identifier×pseudo_instruction).
975 ∀x : option Identifier×pseudo_instruction.
976 ∀tl : list (option Identifier×pseudo_instruction).
977 ∀prf : program=prefix@[x]@tl.
978 ∀inc_added : ℕ.
979 ∀inc_pc_sigma : ppc_pc_map.
980 ∀label : option Identifier.
981 ∀instr : pseudo_instruction.
982 ∀p1 : x≃〈label,instr〉.
983 ∀inc_pc : ℕ.
984 ∀inc_sigma : BitVectorTrie (ℕ×jump_length) 16.
985 ∀old_pc : ℕ.
986 ∀old_length : jump_length.
987 ∀Holdeq :
988  lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) (\snd  old_sigma)
989   〈O,short_jump〉
990   =〈old_pc,old_length〉.
991 ∀Hpolicy1 : inc_pc
992    =\fst  (lookup … (bitvector_of_nat … (|prefix|)) inc_sigma 〈O,short_jump〉).
993 ∀Hpolicy2: \fst  (lookup … (bitvector_of_nat … (|prefix|)) inc_sigma 〈O,short_jump〉)
994    =old_pc+inc_added.
995 ∀added : ℕ.
996 ∀policy : ppc_pc_map.
997 ∀new_length : jump_length.
998 ∀isize : ℕ.
999 let add_instr ≝ match instr with
1000  [ Jmp  j        ⇒ Some ? (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
1001  | Call c        ⇒ Some ? (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
1002  | Instruction i ⇒ jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added (|prefix|) i
1003  | _             ⇒ None ?
1004  ] in
1005 ∀Heq1 :
1006  match add_instr with 
1007   [None⇒〈short_jump,instruction_size_jmplen short_jump instr〉
1008   |Some (pl:jump_length)⇒
1009    〈max_length old_length pl,
1010    instruction_size_jmplen (max_length old_length pl) instr〉]
1011   =〈new_length,isize〉.
1012 ∀Heq2a :
1013  match add_instr with
1014   [None⇒inc_added
1015   |Some (x0:jump_length)⇒
1016    inc_added+(isize-instruction_size_jmplen old_length instr)]
1017   =added.
1018 ∀Heq2b :
1019  〈inc_pc+isize,
1020   insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
1021   〈inc_pc+isize,
1022   \snd  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
1023               (\snd  old_sigma) 〈O,short_jump〉)〉
1024   (insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
1025    〈inc_pc,new_length〉 inc_sigma)〉
1026   =policy.
1027   \fst  (lookup (ℕ×jump_length) 16
1028              (bitvector_of_nat 16 (|(prefix@[〈label,instr〉])|)) (\snd  policy)
1029              〈O,short_jump〉)
1030  =\fst  (lookup (ℕ×jump_length) 16
1031               (bitvector_of_nat 16 (|(prefix@[〈label,instr〉])|)) (\snd  old_sigma)
1032               〈O,short_jump〉)
1033   +added.
1034 #program #labels #old_sigma #prefix #x #tl #prf #inc_added #inc_pc_sigma #label #instr
1035 #p1 #inc_pc #inc_sigma #old_pc #old_length #Holdeq #Hpolicy1 #Hpolicy2 #added
1036 #policy #new_length #isize #Heq1 #Heq2a #Heq2b
1037    <Heq2b >append_length <plus_n_Sm <plus_n_O
1038    >lookup_insert_hit
1039    <Heq2a cases instr in p1 Heq1;
1040    [1: #pi normalize nodelta whd in match jump_expansion_step_instruction;
1041        normalize nodelta lapply (destination_of_None_to_is_jump_false pi)
1042        lapply (destination_of_Some_to_is_jump_true pi)
1043        cases (destination_of ?) normalize nodelta ]
1044    try (#x #y #z #p1 #Heq1) try (#x #y #p1 #Heq1) try (#x #p1 #Heq1) try (#p1 #Heq1)
1045    <(proj2 ?? (pair_destruct ?????? Heq1))
1046    (* USE: sigma_compact_unsafe (from old_sigma) *)
1047    lapply (proj1 ?? (pi2 ?? old_sigma) (|prefix|) ?)
1048    [1,3,5,7,9,11,13,15: >prf >append_length <plus_n_Sm @le_S_S @le_plus_n_r]
1049    lapply Holdeq -Holdeq
1050    inversion (bvt_lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma))
1051    [1,3,5,7,9,11,13,15: normalize nodelta #_ #_ #abs cases abs]
1052    inversion (bvt_lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma))
1053    [1,3,5,7,9,11,13,15: normalize nodelta #_ * #Spc #Sj normalize nodelta #_ #_ #abs cases abs]
1054    * #Spc #Sj #EQS * #pc #j #Holdeq #EQ normalize nodelta
1055    #H (* USE: fst p = lookup |prefix| *) (*CSC: This part of the proof is repeated somewhere else*)
1056    >Hpolicy1
1057    (* USE[pass]: lookup p = lookup old_sigma + added *)
1058    >Hpolicy2
1059    [1,3,4,7:
1060      >(lookup_opt_lookup_hit … Holdeq 〈0,short_jump〉) in EQ;
1061      -Holdeq #EQ <(proj1 ?? (pair_destruct ?????? EQ))
1062      >(lookup_opt_lookup_hit … EQS 〈0,short_jump〉) >H >prf >nth_append_second try %
1063      <minus_n_n >p1 whd in match (nth ????); >associative_plus
1064      >(associative_plus pc) @plus_left_monotone >commutative_plus
1065      @plus_right_monotone @instruction_size_irrelevant try %
1066      whd in match is_jump; normalize nodelta >y %
1067    |2,5,6:
1068      >(lookup_opt_lookup_hit … EQS 〈0,short_jump〉) >H
1069      >(lookup_opt_lookup_hit … Holdeq 〈0,short_jump〉) in EQ; #EQ
1070      -Holdeq <(proj1 ?? (pair_destruct ?????? EQ))
1071      >associative_plus
1072      >(associative_plus pc) @plus_left_monotone >assoc_plus1
1073      >(associative_plus inc_added) @plus_left_monotone >plus_minus_commutative
1074      [1,3,5: >(proj2 ?? (pair_destruct ?????? EQ)) >prf in old_sigma; #old_sigma
1075        >nth_append_second try %
1076        <minus_n_n whd in match (nth ????); >p1 in old_sigma; #old_sigma
1077        >commutative_plus @minus_plus_m_m
1078      |*: <(proj2 ?? (pair_destruct ?????? Heq1)) @jump_length_le_max try %
1079        whd in match is_jump; normalize nodelta >y %]]
1080qed.
1081
1082lemma jump_expansion_step9:
1083(*
1084 program :
1085  (Σl:list labelled_instruction.S (|l|)< 2 \sup 16 ∧is_well_labelled_p l)*)
1086 ∀labels : label_map.(*
1087  (Σlm:label_map
1088   .(∀l:identifier ASMTag
1089     .occurs_exactly_once ASMTag pseudo_instruction l program
1090      →bitvector_of_nat 16 (lookup_def ASMTag ℕ lm l O)
1091       =address_of_word_labels_code_mem program l))*)
1092 ∀old_sigma : ppc_pc_map.(*
1093  (Σpolicy:ppc_pc_map
1094   .not_jump_default program policy
1095    ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) (\snd  policy)
1096                 〈O,short_jump〉)
1097     =O
1098    ∧\fst  policy
1099     =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|program|))
1100                  (\snd  policy) 〈O,short_jump〉)
1101    ∧sigma_compact_unsafe program labels policy
1102    ∧\fst  policy≤ 2 \sup 16 )*)
1103 ∀prefix : list (option Identifier×pseudo_instruction).(*
1104 x : (option Identifier×pseudo_instruction)
1105 tl : (list (option Identifier×pseudo_instruction))
1106 prf : (program=prefix@[x]@tl)
1107 acc :
1108  (Σx0:ℕ×ppc_pc_map
1109   .(let 〈added,policy〉 ≝x0 in 
1110     not_jump_default prefix policy
1111     ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) (\snd  policy)
1112                  〈O,short_jump〉)
1113      =O
1114     ∧\fst  policy
1115      =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
1116                   (\snd  policy) 〈O,short_jump〉)
1117     ∧jump_increase prefix old_sigma policy
1118     ∧sigma_compact_unsafe prefix labels policy
1119     ∧(sigma_jump_equal prefix old_sigma policy→added=O)
1120     ∧(added=O→sigma_pc_equal prefix old_sigma policy)
1121     ∧out_of_program_none prefix policy
1122     ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
1123                  (\snd  policy) 〈O,short_jump〉)
1124      =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
1125                   (\snd  old_sigma) 〈O,short_jump〉)
1126       +added
1127     ∧sigma_safe prefix labels added old_sigma policy))
1128 inc_added : ℕ
1129 inc_pc_sigma : ppc_pc_map
1130 p : (acc≃〈inc_added,inc_pc_sigma〉)*)
1131 ∀label : option Identifier.
1132 ∀instr : pseudo_instruction.(*
1133 p1 : (x≃〈label,instr〉)
1134 add_instr ≝
1135  match instr
1136   in pseudo_instruction
1137   return λ_:pseudo_instruction.(option jump_length)
1138   with 
1139  [Instruction (i:(preinstruction Identifier))⇒
1140   jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
1141   (|prefix|) i
1142  |Comment (_:String)⇒None jump_length
1143  |Cost (_:costlabel)⇒None jump_length
1144  |Jmp (j:Identifier)⇒
1145   Some jump_length
1146   (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
1147  |Call (c:Identifier)⇒
1148   Some jump_length
1149   (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
1150  |Mov (_:[[dptr]])   (_0:Identifier)⇒None jump_length]
1151 inc_pc : ℕ
1152 inc_sigma : (BitVectorTrie (ℕ×jump_length) 16)
1153 Hips : (inc_pc_sigma=〈inc_pc,inc_sigma〉)
1154 old_pc : ℕ
1155 old_length : jump_length
1156 Holdeq :
1157  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) (\snd  old_sigma)
1158   〈O,short_jump〉
1159   =〈old_pc,old_length〉)
1160 Hpolicy :
1161  (not_jump_default prefix 〈inc_pc,inc_sigma〉
1162   ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 O) inc_sigma
1163                〈O,short_jump〉)
1164    =O
1165   ∧inc_pc
1166    =\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) inc_sigma
1167                 〈O,short_jump〉)
1168   ∧jump_increase prefix old_sigma 〈inc_pc,inc_sigma〉
1169   ∧sigma_compact_unsafe prefix labels 〈inc_pc,inc_sigma〉
1170   ∧(sigma_jump_equal prefix old_sigma 〈inc_pc,inc_sigma〉→inc_added=O)
1171   ∧(inc_added=O→sigma_pc_equal prefix old_sigma 〈inc_pc,inc_sigma〉)
1172   ∧out_of_program_none prefix 〈inc_pc,inc_sigma〉
1173   ∧\fst  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|)) inc_sigma
1174                〈O,short_jump〉)
1175    =old_pc+inc_added
1176   ∧sigma_safe prefix labels inc_added old_sigma 〈inc_pc,inc_sigma〉)*)
1177 ∀added : ℕ.
1178 ∀policy : ppc_pc_map.(*
1179 new_length : jump_length
1180 isize : ℕ
1181 Heq1 :
1182  (match 
1183   match instr
1184    in pseudo_instruction
1185    return λ_:pseudo_instruction.(option jump_length)
1186    with 
1187   [Instruction (i:(preinstruction Identifier))⇒
1188    jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
1189    (|prefix|) i
1190   |Comment (_:String)⇒None jump_length
1191   |Cost (_:costlabel)⇒None jump_length
1192   |Jmp (j:Identifier)⇒
1193    Some jump_length
1194    (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
1195   |Call (c:Identifier)⇒
1196    Some jump_length
1197    (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
1198   |Mov (_:[[dptr]])   (_0:Identifier)⇒None jump_length]
1199    in option
1200    return λ_0:(option jump_length).(jump_length×ℕ)
1201    with 
1202   [None⇒〈short_jump,instruction_size_jmplen short_jump instr〉
1203   |Some (pl:jump_length)⇒
1204    〈max_length old_length pl,
1205    instruction_size_jmplen (max_length old_length pl) instr〉]
1206   =〈new_length,isize〉)
1207 prefix_ok1 : (S (|prefix|)< 2 \sup 16 )
1208 prefix_ok : (|prefix|< 2 \sup 16 )
1209 Heq2a :
1210  (match 
1211   match instr
1212    in pseudo_instruction
1213    return λ_0:pseudo_instruction.(option jump_length)
1214    with 
1215   [Instruction (i:(preinstruction Identifier))⇒
1216    jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added
1217    (|prefix|) i
1218   |Comment (_0:String)⇒None jump_length
1219   |Cost (_0:costlabel)⇒None jump_length
1220   |Jmp (j:Identifier)⇒
1221    Some jump_length
1222    (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
1223   |Call (c:Identifier)⇒
1224    Some jump_length
1225    (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
1226   |Mov (_0:[[dptr]])   (_00:Identifier)⇒None jump_length]
1227    in option
1228    return λ_0:(option jump_length).ℕ
1229    with 
1230   [None⇒inc_added
1231   |Some (x0:jump_length)⇒
1232    inc_added+(isize-instruction_size_jmplen old_length instr)]
1233   =added)
1234 Heq2b :
1235  (〈inc_pc+isize,
1236   insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
1237   〈inc_pc+isize,
1238   \snd  (lookup (ℕ×jump_length) 16 (bitvector_of_nat 16 (S (|prefix|)))
1239               (\snd  old_sigma) 〈O,short_jump〉)〉
1240   (insert (ℕ×jump_length) 16 (bitvector_of_nat 16 (|prefix|))
1241    〈inc_pc,new_length〉 inc_sigma)〉
1242   =policy)
1243*)
1244 sigma_safe (prefix@[〈label,instr〉]) labels added old_sigma policy.
1245cases daemon(*
1246    #i >append_length >commutative_plus #Hi normalize in Hi;
1247    elim (le_to_or_lt_eq … (le_S_S_to_le … Hi)) -Hi #Hi
1248    [ >nth_append_first [2: @Hi]
1249      <Heq2b >lookup_insert_miss
1250      [ >lookup_insert_miss
1251        [ >lookup_insert_miss
1252          [ elim (le_to_or_lt_eq … Hi) -Hi #Hi
1253            [ >lookup_insert_miss
1254              [ (* USE[pass]: sigma_safe *)
1255                lapply ((proj2 ?? Hpolicy) i (le_S_to_le … Hi))
1256                cases (bvt_lookup … (bitvector_of_nat ? i) inc_sigma 〈0,short_jump〉)
1257                #pc #j normalize nodelta
1258                cases (bvt_lookup … (bitvector_of_nat ? (S i)) inc_sigma 〈0,short_jump〉)
1259                #Spc #Sj normalize nodelta
1260                cases (nth i ? prefix 〈None ?, Comment []〉) #lbl #ins normalize nodelta
1261                #Hind #dest #Hj lapply (Hind dest Hj) -Hind -Hj
1262                lapply (refl ? (leb (lookup_def … labels dest 0) (S (|prefix|))))
1263                cases (leb (lookup_def … labels dest 0) (S (|prefix|))) in ⊢ (???% → %); #H
1264                [ cases (le_to_or_lt_eq … (leb_true_to_le … H)) -H #H
1265                  [ >(le_to_leb_true … (le_S_S_to_le … H)) normalize nodelta
1266                    >lookup_insert_miss
1267                    [ cases (le_to_or_lt_eq … (le_S_S_to_le … H)) -H #H
1268                      [ >lookup_insert_miss
1269                        [ #H2 @H2
1270                        | @bitvector_of_nat_abs
1271                          [3: @lt_to_not_eq @H
1272                          |1: @(transitive_lt ??? H)
1273                          ]
1274                          @prefix_ok
1275                        ]
1276                      | >H >lookup_insert_hit
1277                        (* USE: inc_pc = lookup |prefix| *)
1278                        >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1279                        #H2 @H2
1280                      ]
1281                    | @bitvector_of_nat_abs
1282                      [3: @lt_to_not_eq @H
1283                      |1: @(transitive_lt ??? H)
1284                      ]
1285                      @prefix_ok1
1286                    ]
1287                  | >H >lookup_insert_hit normalize nodelta
1288                    >(not_le_to_leb_false … (lt_to_not_le ?? (le_S_S ?? (le_n (|prefix|)))))
1289                    normalize nodelta
1290                    >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1291                    #H2 >(proj2 ?? (proj1 ?? Hpolicy))
1292                  ]
1293                |
1294                       
1295                       
1296                       
1297                [2,3,6: [3: #x] #y normalize nodelta #EQ <EQ cases j normalize nodelta
1298                  [1,4,7: cases (decidable_le (lookup_def … labels dest 0) (S (|prefix|))) #H
1299                    [1,3,5: >(le_to_leb_true … H) normalize nodelta cases (le_to_or_lt_eq … H) -H #H
1300                      [1,3,5: >(le_to_leb_true … (le_S_S_to_le … H)) normalize nodelta
1301                        >lookup_insert_miss
1302                        [2,4,6: @bitvector_of_nat_abs
1303                          [3,6,9: @lt_to_not_eq @H
1304                          |1,4,7: @(transitive_lt ??? H)
1305                          ]
1306                          @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf
1307                          @le_S_S >append_length <plus_n_Sm @le_S_S @le_plus_n_r
1308                        ]
1309                        cases (le_to_or_lt_eq … H) -H #H
1310                        [1,3,5: >lookup_insert_miss
1311                          [1,3,5: #H @H
1312                          |2,4,6: @bitvector_of_nat_abs
1313                            [3,6,9: @lt_to_not_eq @(le_S_S_to_le … H)
1314                            |1,4,7: @(transitive_lt ??? (le_S_S_to_le … H))
1315                            ]
1316                            @(transitive_lt … (proj1 ?? (pi2 ?? program))) >prf
1317                            >append_length @le_S_S @le_plus_n_r
1318                          ]
1319                        |2,4,6: >(injective_S … H) >lookup_insert_hit
1320                          (* USE: blerp *)
1321                          >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1322                          #H @H
1323                        ]
1324                      |2,4,6: >H >lookup_insert_hit >(not_le_to_leb_false)
1325                        [2,4,6: @le_to_not_lt @le_n]
1326                        normalize nodelta
1327                        lapply (proj2 ?? (proj1 ?? (pi2 ?? old_sigma)) (|prefix|) ?)
1328                        [1,3,5: >prf >append_length <plus_n_Sm @le_S_S @le_plus_n_r]
1329                         lapply (refl ? (lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)))
1330                          cases (lookup_opt … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma)) in ⊢ (???% → %);
1331                          [1,3,5: normalize nodelta #_ #abs cases abs
1332                          |2,4,6: #x cases x -x #ppc #pj normalize nodelta #PEQ
1333                            lapply (refl ? (lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)))
1334                            cases (lookup_opt … (bitvector_of_nat ? (S (|prefix|))) (\snd old_sigma)) in ⊢ (???% → %);
1335                            [1,3,5: normalize nodelta #_ #abs cases abs
1336                            |2,4,6: #x cases x -x #Sppc #Spj normalize nodelta #SPEQ #Pcompact
1337                              >(lookup_opt_lookup_hit … SPEQ 〈0,short_jump〉)
1338                              >(lookup_opt_lookup_hit … PEQ 〈0,short_jump〉) in Holdeq;
1339                              #H >Pcompact >(proj1 ?? (pair_destruct ?????? H))
1340                              >commutative_plus >assoc_plus1 <(proj2 ?? (proj1 ?? Hpolicy))
1341                              <(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1342                              >prf >nth_append_second
1343                              [1,3,5: <minus_n_n whd in match (nth ????); >p1
1344                                cases daemon (* to be lemmatized *)
1345                              |2,4,6: @le_n
1346                              ]
1347                            ]
1348                          ]
1349                        ]
1350                      |2,4,6: >(not_le_to_leb_false … H)
1351                        >not_le_to_leb_false
1352                        [2,4,6: @lt_to_not_le @le_S_to_le @not_le_to_lt @H
1353                        |1,3,5: normalize nodelta #H @H
1354                        ]
1355                      ]
1356                    |2,5,8: cases daemon (* like previous case *)
1357                    |3,6,9: cases daemon (* like previous case *)
1358                    ]
1359                  |4,5: #x normalize nodelta cases daemon (* blerp *)
1360                  |1: cases daemon (* blerp *)
1361                  ]
1362               
1363                               
1364                         
1365
1366   (*(\fst  (short_jump_cond (bitvector_of_nat 16 Spc)
1367              (bitvector_of_nat 16
1368               (inc_pc
1369                +instruction_size_jmplen
1370                 (max_length old_length
1371                  (select_jump_length labels old_sigma inc_pc_sigma inc_added
1372                   (|prefix|) xx)) (Jmp xx))))
1373  =true                   *)
1374                       
1375                 
1376  ]       
1377              [ >lookup_insert_miss
1378                [ (* USE[pass]: sigma_safe *)
1379                  lapply ((proj2 ?? Hpolicy) i (le_S_to_le … Hi))
1380                  cases (bvt_lookup … (bitvector_of_nat ? i) inc_sigma 〈0,short_jump〉)
1381                  #pc #j normalize nodelta
1382                  cases (bvt_lookup … (bitvector_of_nat ? (S i)) inc_sigma 〈0,short_jump〉)
1383                  #Spc #Sj normalize nodelta
1384                  cases (nth i ? prefix 〈None ?, Comment []〉) #lbl #ins normalize nodelta
1385                  #Hind #dest #Hj lapply (Hind dest Hj) -Hind -Hj lapply (proj1 ?? (pair_destruct ?????? Heq2)) cases instr
1386                  [2,3,6: [3: #x] #y normalize nodelta #EQ <EQ cases j normalize nodelta
1387                    [1,4,7: *)
1388qed.
1389
1390(* One step in the search for a jump expansion fixpoint. *)
1391definition jump_expansion_step: ∀program:(Σl:list labelled_instruction.
1392  S (|l|) < 2^16 ∧ is_well_labelled_p l).
1393  ∀labels:(Σlm:label_map.∀l.
1394    occurs_exactly_once ?? l program →
1395    bitvector_of_nat ? (lookup_def … lm l 0) =
1396    address_of_word_labels_code_mem program l).
1397  ∀old_policy:(Σpolicy:ppc_pc_map.
1398    (* out_of_program_none program policy *)
1399    And (And (And (And (not_jump_default program policy)
1400    (\fst (bvt_lookup … (bitvector_of_nat ? 0) (\snd policy) 〈0,short_jump〉) = 0))
1401    (\fst policy = \fst (bvt_lookup … (bitvector_of_nat ? (|program|)) (\snd policy) 〈0,short_jump〉)))
1402    (sigma_compact_unsafe program labels policy))
1403    (\fst policy ≤ 2^16)).
1404  (Σx:bool × (option ppc_pc_map).
1405    let 〈no_ch,y〉 ≝ x in
1406    match y with
1407    [ None ⇒ nec_plus_ultra program old_policy
1408    | Some p ⇒ And (And (And (And (And (And (And
1409       (not_jump_default program p)
1410       (\fst (bvt_lookup … (bitvector_of_nat ? 0) (\snd p) 〈0,short_jump〉) = 0))
1411       (\fst p = \fst (bvt_lookup … (bitvector_of_nat ? (|program|)) (\snd p) 〈0,short_jump〉)))
1412       (jump_increase program old_policy p))
1413       (sigma_compact_unsafe program labels p))
1414       (sigma_jump_equal program old_policy p → no_ch = true))
1415       (no_ch = true → sigma_pc_equal program old_policy p))
1416       (\fst p ≤ 2^16)
1417    ])
1418    ≝
1419  λprogram.λlabels.λold_sigma.
1420  let 〈final_added, final_policy〉 ≝
1421    pi1 ?? (foldl_strong (option Identifier × pseudo_instruction)
1422    (λprefix.Σx:ℕ × ppc_pc_map.
1423      let 〈added,policy〉 ≝ x in
1424      And (And (And (And (And (And (And (And (And (not_jump_default prefix policy)
1425      (\fst (bvt_lookup … (bitvector_of_nat ? 0) (\snd policy) 〈0,short_jump〉) = 0))
1426      (\fst policy = \fst (bvt_lookup … (bitvector_of_nat ? (|prefix|)) (\snd policy) 〈0,short_jump〉)))
1427      (jump_increase prefix old_sigma policy))
1428      (sigma_compact_unsafe prefix labels policy))
1429      (sigma_jump_equal prefix old_sigma policy → added = 0))
1430      (added = 0 → sigma_pc_equal prefix old_sigma policy))
1431      (out_of_program_none prefix policy))
1432      (\fst (bvt_lookup … (bitvector_of_nat ? (|prefix|)) (\snd policy) 〈0,short_jump〉) =
1433       \fst (bvt_lookup … (bitvector_of_nat ? (|prefix|)) (\snd old_sigma) 〈0,short_jump〉) + added))
1434      (sigma_safe prefix labels added old_sigma policy))
1435    program
1436    (λprefix.λx.λtl.λprf.λacc.
1437      let 〈inc_added, inc_pc_sigma〉 ≝ (pi1 ?? acc) in
1438      let 〈label,instr〉 ≝ x in
1439      (* Now, we must add the current ppc and its pc translation.
1440       * Three possibilities:
1441       *   - Instruction is not a jump; i.e. constant size whatever the sigma we use;
1442       *   - Instruction is a backward jump; we can use the sigma we're constructing,
1443       *     since it will already know the translation of its destination;
1444       *   - Instruction is a forward jump; we must use the old sigma (the new sigma
1445       *     does not know the translation yet), but compensate for the jumps we
1446       *     have lengthened.
1447       *)
1448      let add_instr ≝ match instr with
1449      [ Jmp  j        ⇒ Some ? (select_jump_length labels old_sigma inc_pc_sigma inc_added (|prefix|) j)
1450      | Call c        ⇒ Some ? (select_call_length labels old_sigma inc_pc_sigma inc_added (|prefix|) c)
1451      | Instruction i ⇒ jump_expansion_step_instruction labels old_sigma inc_pc_sigma inc_added (|prefix|) i
1452      | _             ⇒ None ?
1453      ] in
1454      let 〈inc_pc, inc_sigma〉 ≝ inc_pc_sigma in
1455      let old_length ≝
1456        \snd (bvt_lookup … (bitvector_of_nat ? (|prefix|)) (\snd (pi1 ?? old_sigma)) 〈0,short_jump〉) in
1457      let old_size ≝ instruction_size_jmplen old_length instr in
1458      let 〈new_length, isize〉 ≝ match add_instr with
1459      [ None    ⇒ 〈short_jump, instruction_size_jmplen short_jump instr〉
1460      | Some pl ⇒ 〈max_length old_length pl, instruction_size_jmplen (max_length old_length pl) instr〉
1461      ] in
1462      let new_added ≝ match add_instr with
1463      [ None   ⇒ inc_added
1464      | Some x ⇒ plus inc_added (minus isize old_size)
1465      ] in
1466      let old_Slength ≝
1467        \snd (bvt_lookup … (bitvector_of_nat ? (S (|prefix|))) (\snd (pi1 ?? old_sigma)) 〈0,short_jump〉) in
1468      let updated_sigma ≝
1469        (* we add the new PC to the next position and the new jump length to this one *)
1470        bvt_insert … (bitvector_of_nat ? (S (|prefix|))) 〈inc_pc + isize, old_Slength〉
1471        (bvt_insert … (bitvector_of_nat ? (|prefix|)) 〈inc_pc, new_length〉 inc_sigma) in
1472      〈new_added, 〈plus inc_pc isize, updated_sigma〉〉
1473    ) 〈0, 〈0,
1474      bvt_insert …
1475        (bitvector_of_nat ? 0)
1476        〈0, \snd (bvt_lookup … (bitvector_of_nat ? 0) (\snd (pi1 ?? old_sigma)) 〈0,short_jump〉)〉
1477        (Stub ??)〉〉
1478    ) in
1479    if gtb (\fst final_policy) 2^16 then
1480      〈eqb final_added 0, None ?〉
1481    else
1482      〈eqb final_added 0, Some ? final_policy〉.
1483[ normalize nodelta @nmk #Habs lapply p -p cases (foldl_strong ? (λ_.Σx.?) ???)
1484  #x #H #Heq >Heq in H; normalize nodelta -Heq -x #Hind
1485  (* USE: inc_pc = fst of policy (from fold) *)
1486  >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hind)))))))) in p1;
1487  (* USE: fst policy < 2^16, inc_pc = fst of policy (old_sigma) *)
1488  lapply (proj2 ?? (pi2 ?? old_sigma)) >(proj2 ?? (proj1 ?? (proj1 ?? (pi2 ?? old_sigma))))
1489  #Hsig #Hge
1490  (* USE: added = 0 → policy_pc_equal (from fold) *)
1491  lapply ((proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hind)))) ? (|program|) (le_n (|program|)))
1492  [ (* USE: policy_jump_equal → added = 0 (from fold) *)
1493    @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hind))))) #i #Hi
1494    inversion (is_jump (\snd (nth i ? program 〈None ?, Comment []〉)))
1495    [ #Hj
1496      (* USE: policy_increase (from fold) *)
1497      lapply (proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hind)))))) i (le_S_to_le … Hi))
1498      lapply (Habs i Hi ?) [ >Hj %]
1499      cases (bvt_lookup … (bitvector_of_nat ? i) (\snd old_sigma) 〈0,short_jump〉)
1500      #opc #oj
1501      cases (bvt_lookup … (bitvector_of_nat ? i) (\snd final_policy) 〈0,short_jump〉)
1502      #pc #j normalize nodelta #Heq >Heq cases j
1503      [1,2: #abs cases abs #abs2 try (cases abs2) @refl
1504      |3: #_ @refl
1505      ]
1506    | #Hnj
1507      (* USE: not_jump_default (from fold and old_sigma) *)
1508      >(proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hind)))))))) i Hi ?)
1509      [2: >Hnj %]
1510      >(proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (pi2 ?? old_sigma)))) i Hi ?) try %
1511      >Hnj %
1512    ]
1513  | #abs >abs in Hsig; #Hsig
1514    @(absurd ? Hsig) @lt_to_not_le @ltb_true_to_lt @Hge
1515  ]
1516| normalize nodelta lapply p -p cases (foldl_strong ? (λ_.Σx.?)???) in ⊢ (% → ?); #x #H #H2
1517  >H2 in H; normalize nodelta -H2 -x #H @conj
1518  [ @conj [ @conj
1519  [ (* USE[pass]: not_jump_default, 0 ↦ 0, inc_pc = fst policy,
1520     * jump_increase, sigma_compact_unsafe (from fold) *)
1521    @(proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? H)))))
1522  | #H2 (* USE[pass]: sigma_jump_equal → added = 0 (from fold) *)
1523    @eq_to_eqb_true @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? H))))) @H2
1524  ]
1525  | (* USE[pass]: added = 0 → sigma_pc_equal (from fold) *)
1526     #H2 @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? H)))) @eqb_true_to_eq @H2
1527  ]
1528  | @not_lt_to_le @ltb_false_to_not_lt @p1
1529  ]
1530|4: lapply (pi2 ?? acc) >p lapply (refl ? (inc_pc_sigma)) cases inc_pc_sigma in ⊢ (???% → %);
1531  #inc_pc #inc_sigma #Hips
1532  inversion (bvt_lookup … (bitvector_of_nat ? (|prefix|)) (\snd (pi1 ?? old_sigma)) 〈0,short_jump〉)
1533  #old_pc #old_length #Holdeq #Hpolicy normalize nodelta in Hpolicy; @pair_elim
1534  #added #policy normalize nodelta @pair_elim #new_length #isize normalize nodelta
1535  #Heq1 #Heq2
1536 cut (S (|prefix|) < 2^16)
1537 [ @(transitive_lt … (proj1 … (pi2 ?? program))) @le_S_S >prf >append_length
1538   <plus_n_Sm @le_S_S @le_plus_n_r ] #prefix_ok1
1539 cut (|prefix| < 2^16) [ @(transitive_lt … prefix_ok1) %] #prefix_ok
1540 cases (pair_destruct ?????? Heq2) -Heq2 #Heq2a #Heq2b
1541  % [ % [ % [ % [ % [ % [ % [ % [ % ]]]]]]]]
1542  (* NOTE: to save memory and speed up work, there's cases daemon here. They can be
1543   * commented out for full proofs, but this needs a lot of memory and time *)
1544  [ (* not_jump_default *)
1545    @(jump_expansion_step1 … Heq1 Heq2b) try assumption
1546    @(proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))))
1547  | (* 0 ↦ 0 *)
1548    @(jump_expansion_step2 … Heq2b) try assumption
1549    [ @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ??  (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))))
1550    | @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))) ]
1551  | (* inc_pc = fst of policy *)
1552    <Heq2b >append_length >(commutative_plus (|prefix|)) >lookup_insert_hit @refl
1553  | (* jump_increase *)
1554    @(jump_expansion_step3 … (pi1 ?? old_sigma) … prf … p1 ??? old_length Holdeq
1555      … Heq1 prefix_ok1 prefix_ok Heq2b)
1556    try @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))
1557    cases (pi2 … old_sigma) * * * #H #_ #_ #_ #_ @H
1558  | (* sigma_compact_unsafe *)
1559    @(jump_expansion_step4 … Heq1 … Heq2b) try assumption
1560    try @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ??  (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1561    try @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))
1562    @(proj2 ?? (proj1 ?? (proj1 ?? Hpolicy)))
1563  | (* policy_jump_equal → added = 0 *)
1564    @(jump_expansion_step5 … Holdeq … Heq1 … Heq2b) try assumption
1565    try @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))
1566    @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1567  | (* added = 0 → policy_pc_equal *) cases daemon (*
1568    @(jump_expansion_step6 … Heq1 … Heq2b) try assumption
1569    try @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))
1570    @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))
1571    *)
1572  | (* out_of_program_none *) cases daemon(*
1573    @jump_expansion_step7 try assumption
1574    @(proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy))))))))))
1575    *)
1576  | (* lookup p = lookup old_sigma + added *) cases daemon(*
1577    @jump_expansion_step8 try assumption
1578    try @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? (proj1 ?? Hpolicy)))))))   
1579    @(proj2 ?? (proj1 ?? Hpolicy)) *)
1580  | (* sigma_safe *) cases daemon (*
1581    @jump_expansion_step9 try assumption
1582    @(proj2 ?? Hpolicy) *)
1583  ]     
1584| normalize nodelta % [ % [ % [ % [ % [ % [ % [ % [ % ]]]]]]]]
1585  [ #i cases i
1586    [ #Hi @⊥ @(absurd … Hi) @not_le_Sn_O
1587    | -i #i #Hi #Hj @⊥ @(absurd … Hi) @not_le_Sn_O
1588    ]
1589  | >lookup_insert_hit @refl
1590  | >lookup_insert_hit @refl
1591  | #i #Hi <(le_n_O_to_eq … Hi)
1592    >lookup_insert_hit cases (bvt_lookup … (bitvector_of_nat ? 0) (\snd old_sigma) 〈0,short_jump〉)
1593    #a #b normalize nodelta %2 @refl
1594  | #i cases i
1595    [ #Hi @⊥ @(absurd … Hi) @not_le_Sn_O
1596    | -i #i #Hi @⊥ @(absurd … Hi) @not_le_Sn_O
1597    ]
1598  | #_ %
1599  | #_ #i #Hi <(le_n_O_to_eq … Hi) >lookup_insert_hit
1600    (* USE: 0 ↦ 0 (from old_sigma) *)
1601    @(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (pi2 ?? old_sigma)))))
1602  | #i cases i
1603    [ #Hi2 @conj
1604      [ #Hi @⊥ @(absurd ? Hi) @le_to_not_lt / by /
1605      | >lookup_opt_insert_hit #H destruct (H)
1606      ]
1607    | -i #i #Hi2 @conj
1608      [ #Hi >lookup_opt_insert_miss
1609        [ / by refl/
1610        | @bitvector_of_nat_abs
1611          [ @Hi2
1612          | / by /
1613          | @sym_neq @lt_to_not_eq / by /
1614          ]
1615        ]
1616      | #_ @le_S_S @le_O_n
1617      ]
1618    ]
1619  | >lookup_insert_hit (* USE: 0 ↦ 0 (from old_sigma) *)
1620    >(proj2 ?? (proj1 ?? (proj1 ?? (proj1 ?? (pi2 ?? old_sigma))))) <plus_n_O %
1621  | #i cases i
1622    [ #Hi @⊥ @(absurd … Hi) @not_le_Sn_O
1623    | -i #i #Hi @⊥ @(absurd … Hi) @not_le_Sn_O
1624    ]
1625  ]
1626]
1627qed.
Note: See TracBrowser for help on using the repository browser.