source: src/ERTL/ERTLtoERTLptrOK.ma @ 2843

Last change on this file since 2843 was 2843, checked in by piccolo, 8 years ago

1) Fixed a litte bug in Joint.ma
2) ERTL to ERTLptr correctness proof in place

File size: 61.4 KB
Line 
1
2(**************************************************************************)
3(*       ___                                                              *)
4(*      ||M||                                                             *)
5(*      ||A||       A project by Andrea Asperti                           *)
6(*      ||T||                                                             *)
7(*      ||I||       Developers:                                           *)
8(*      ||T||         The HELM team.                                      *)
9(*      ||A||         http://helm.cs.unibo.it                             *)
10(*      \   /                                                             *)
11(*       \ /        This file is distributed under the terms of the       *)
12(*        v         GNU General Public License Version 2                  *)
13(*                                                                        *)
14(**************************************************************************)
15
16include "ERTL/ERTLtoERTLptrUtils.ma".
17
18
19
20(*
21lemma get_internal_function_from_ident_ok :
22∀p : sem_params. ∀globals : list ident. ∀ge : genv_t (joint_function p globals).
23∀bl,f,fn. fetch_internal_function ? ge bl = return 〈f,fn〉 →
24get_internal_function_from_ident p globals ge f= return fn.
25#p #globals #ge #bl #f #fn #EQf
26@('bind_inversion EQf) * #f1 * #fn1 whd in match fetch_function;
27normalize nodelta #H lapply(opt_eq_from_res ???? H) -H #H @('bind_inversion H) -H
28#f2 #EQf2 #H @('bind_inversion H) -H #fn2 #EQfn2 whd in ⊢ (??%% → ??%% → ?);
29#EQ1 #EQ2 destruct whd in match get_internal_function_from_ident; normalize nodelta
30>(symbol_of_block_rev … EQf2) >m_return_bind
31cut(code_block_of_block bl = return bl)
32 [ whd in match code_block_of_block; normalize nodelta @match_reg_elim
33   [ >(pi2 ?? bl) #ABS destruct] elim bl #bl1 #EQ #prf % ] #EQbl >EQbl
34>m_return_bind >EQf %
35qed.
36*)
37
38
39
40 
41(*
42  whd in match sigma_frames_opt; whd in match m_list_map; normalize nodelta
43whd in match sigma_state in ⊢ (???????%%); normalize nodelta
44cases(st_frms … st) normalize nodelta [ @res_preserve_error1]
45* #loc_mem #bl #tl inversion(sigma_frames ????)
46[ #_ normalize nodelta @res_preserve_error1] * #loc_mem1 #bl1 #tl1
47whd in match sigma_frames; normalize nodelta inversion(sigma_frames_opt ????)
48[ #_ normalize nodelta #_ #ABS destruct] #l whd in match sigma_frames_opt;
49whd in match m_list_map; normalize nodelta whd in match (foldr ?????);
50normalize nodelta inversion(fetch_internal_function ???)
51[2: #e #_ whd in ⊢ (??%% → ?); #ABS destruct] * #id1 #fn1 #EQfn1 >m_return_bind
52normalize nodelta #H @('bind_inversion H) -H #l1
53change with (sigma_frames_opt ???? = ? → ?) #EQl1
54cut (sigma_frames prog f_lbls f_regs tl = l1)
55[whd in match sigma_frames; normalize nodelta >EQl1 %] #EQl11
56cases l [ whd in ⊢ (??%? → ?); #EQ destruct] #x #y
57whd in ⊢ (??%? → ?); #EQ1 #_ #EQ2 destruct @mfr_bind1
58[2: whd in match set_regs; whd in match set_frms; normalize nodelta
59    >EQl1 in ⊢ (???????%?); normalize nodelta
60cut(sigma_regs prog f_lbls (added_registers ERTL (prog_var_names … prog) fn1 (f_regs bl1))
61    〈loc_mem,\snd (regs … st)〉 =  〈map RegisterTag beval beval loc_mem
62       (λbv:beval.sigma_beval prog f_lbls bv)∖
63         added_registers ERTL (prog_var_names … prog) fn1 (f_regs bl1),
64   \snd  (sigma_regs prog f_lbls restr (regs ERTLptr_semantics st))〉)
65[ whd in match sigma_regs; normalize nodelta @eq_f2 [ %] cases(regs ? st)
66     #x #y %] #EQ <EQ -EQ
67change with (sigma_state ???? (set_regs ERTL_semantics 〈loc_mem,\snd (regs … st)〉
68            (set_frms ERTL_semantics tl st))) in ⊢ (???????(??%)?);
69@pop_ra_ok |
70| * #st1 #pc1 @if_elim [2: #_ @res_preserve_error1] normalize nodelta
71@eq_block_elim [2: #_ *] #EQbl1 * @if_elim
72[2: >EQbl1 @eq_block_elim [#_ *] * #H @⊥ @H <pc_block_eq [%] %
73    cases bl1 in EQbl1 EQfn1; #p1 #p2 #EQ destruct lapply p2
74    whd in match sigma_stored_pc; normalize nodelta cases(sigma_pc_opt ???)
75    normalize nodelta [2: #pc2] #p2 [#_ #EQ destruct]
76    >fetch_internal_function_no_zero [2: %] #EQ destruct
77] @eq_block_elim [2: #_ *] #EQbl11 * @mfr_return_eq1 normalize nodelta
78  cases bl1 in EQbl11 EQfn1; #p1 #p2 #EQ destruct
79  lapply p2 cases(pc_block pc1) #p11 #p22 #e #EQfn1 >EQfn1
80  %
81]
82qed.
83*)
84
85
86definition ERTLptrStatusSimulation :
87∀ prog : ertl_program.
88let trans_prog ≝ ertl_to_ertlptr prog in
89∀stack_sizes.∀ f_lbls : lbl_funct. ∀ f_regs : regs_funct.
90∀f_bl_r.
91b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
92     translate_data prog f_bl_r f_lbls f_regs →
93status_rel (ERTL_status prog stack_sizes) (ERTLptr_status trans_prog stack_sizes) ≝
94λprog,stack_sizes,f_lbls,f_regs,f_lb_r,good.
95  let trans_prog ≝ ertl_to_ertlptr prog in
96    mk_status_rel ??
97    (* sem_rel ≝ *) (λs1:ERTL_status prog stack_sizes
98       .λs2:ERTLptr_status trans_prog stack_sizes
99        .s1=sigma_state_pc prog f_lbls f_regs s2)
100    (* call_rel ≝ *) 
101          (λs1:Σs:ERTL_status prog stack_sizes
102               .as_classifier (ERTL_status prog stack_sizes) s cl_call
103       .λs2:Σs:ERTLptr_status trans_prog stack_sizes
104                .as_classifier (ERTLptr_status trans_prog stack_sizes) s cl_call
105        .
106        pc (mk_prog_params ERTL_semantics prog stack_sizes) s1
107         =sigma_stored_pc prog f_lbls
108          (pc
109           (mk_prog_params ERTLptr_semantics (ertl_to_ertlptr prog) stack_sizes)
110           s2))
111    (* sim_final ≝ *) ?.
112cases daemon
113qed.
114
115include "joint/semantics_blocks.ma".
116
117
118
119lemma as_label_ok : ∀ prog : ertl_program.
120let trans_prog ≝ ertl_to_ertlptr prog in
121∀ f_lbls,f_regs,stack_sizes.
122∀f_bl_r.
123b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
124     (λglobals,fn.«translate_data globals fn,(refl …)») prog f_bl_r f_lbls f_regs →
125∀st,fn,id,stmt.
126fetch_statement ERTL_semantics (prog_var_names … prog)
127      (globalenv_noinit … prog) (pc … (sigma_state_pc prog f_lbls f_regs st)) =
128               return 〈id,fn,stmt〉 →
129as_label (ERTLptr_status trans_prog stack_sizes) st = as_label
130(ERTL_status prog stack_sizes) (sigma_state_pc prog f_lbls f_regs st).
131#prog #f_lbls #f_regs #stack_size #f_lb_r #good #st #fn #id #stmt #EQfetch
132whd in match as_label; normalize nodelta change with (pc ? ?) in ⊢ (??(??%)(??%));
133cases(b_graph_transform_program_fetch_statement … good … EQfetch)
134#init_data * #t_fn ** #EQt_fn whd in ⊢ (% → ?); cases(f_lb_r ?)
135normalize nodelta [2: #r #tl *] #EQinit destruct(EQinit) * #l_labs * #l_regs **
136#_ #_ cases stmt in EQfetch;
137[ * [ #c | * [ #c_id | #c_ptr ] #c_arg #c_dest | #reg #lbl | #s ] #nxt | #fin | * ]
138#EQfetch normalize nodelta * #bl * [1,2,3,4,5: >if_merge_right in ⊢ (% → ?); try %]
139whd in ⊢ (%→?); cases l_regs normalize nodelta [2,4,5,8,10,12: [3: *] #x #y *]
140[1,2,4,5,6:| #r #tl whd in ⊢ (% → ?); cases tl -tl normalize nodelta [2: #r1 #tl1 *]]
141#EQ destruct(EQ)
142[1,2,3,4,6: * #pre_l * #mid1 * #mid2 * #post_l *** #EQmid1
143            whd in match map_eval in ⊢ (% → ?); normalize nodelta
144            whd in ⊢ (?????%?? → ?);
145            whd in match (seq_list_in_code ???????) in ⊢ (%→?); *
146           [1,2,3,4: #EQ1 #EQ2 destruct(EQ1 EQ2) whd in EQmid1 : (???%);
147                     destruct(EQmid1) * #nxt1 * #EQt_stmt #_ #_
148           |        * #lbl1 * #rest ** #EQ destruct(EQ) * #nxt1 *
149                    #EQt_stmt #_ #_ #_ #_
150           ]
151|           * #pre_l * #mid ** #EQmid whd in ⊢ (% → ?); * #EQ destruct(EQ)
152            whd in EQmid : (???%); destruct(EQmid) #EQ destruct(EQ)
153            whd in ⊢ (% → ?); #EQt_stmt
154]
155whd in ⊢ (??%%); >EQfetch normalize nodelta whd in match fetch_statement;
156normalize nodelta >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQt_fn;
157#EQt_fn >EQt_fn >m_return_bind >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQt_stmt;
158#EQt_stmt >EQt_stmt %
159qed.
160
161include alias "basics/lists/listb.ma".
162
163lemma eval_seq_no_call_ok :
164 ∀prog.
165 let trans_prog ≝ ertl_to_ertlptr prog in
166 ∀ f_lbls,f_regs,stack_sizes.
167 ∀f_bl_r.
168 b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
169     (λglobals,fn.«translate_data globals fn,(refl …)») prog f_bl_r f_lbls f_regs →
170 ∀st2 : state_pc ERTLptr_semantics.
171 let st1 ≝ sigma_state_pc prog f_lbls f_regs st2 in
172 ∀st1' : state_pc ERTL_semantics.
173 ∀f,fn,stmt,nxt.
174   fetch_statement ERTL_semantics
175     (prog_var_names (joint_function ERTL_semantics) ℕ prog)
176    (ev_genv (mk_prog_params ERTL_semantics prog stack_sizes))
177    (pc … st1) =
178      return 〈f, fn,  sequential … (step_seq ERTL … stmt) nxt〉 →
179   eval_state ERTL_semantics
180   (prog_var_names (joint_function ERTL_semantics) ℕ prog)
181   (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes))
182   st1 =
183    return st1' →
184 ∃st2'. st1' = sigma_state_pc prog f_lbls f_regs st2' ∧
185 ∃taf : trace_any_any_free (ERTLptr_status trans_prog stack_sizes)
186  st2
187  st2'.
188 if taaf_non_empty … taf then True else
189(¬as_costed (ERTL_status prog stack_sizes) st1 ∨
190 ¬as_costed (ERTL_status prog stack_sizes) st1').
191#prog #f_lbls #f_regs #stack_size #f_bl_r #good #st2 #st1' #f #fn #stmt #nxt
192#EQfetch whd in match eval_state; normalize nodelta >EQfetch >m_return_bind
193#H @('bind_inversion H)-H #st_no_pc
194whd in match eval_statement_no_pc; normalize nodelta #EQnopc
195whd in match eval_statement_advance; normalize nodelta
196whd in match set_no_pc; whd in match next; whd in match set_pc;
197normalize nodelta whd in ⊢ (??%% → ?); #EQ destruct(EQ) lapply EQfetch
198>(fetch_stmt_ok_sigma_pc_ok … EQfetch) #EQfetch'
199cases(b_graph_transform_program_fetch_statement_plus … good … EQfetch')
200#init_data * #t_fn1 ** #EQt_fn1 whd in ⊢ (% → ?); cases (f_bl_r ?) normalize nodelta
201[2: #r #tl *] #EQ destruct(EQ) * #labs * #regs ******* #EQlabs #EQregs #_ #_ #_ #_
202#fresh_regs * #bl * >if_merge_right in ⊢ (% → ?); [2: %]
203whd in ⊢ (% → ?); cases regs in EQregs; normalize nodelta [2: #x #y #_ *] #EQregs
204#EQ destruct(EQ) #eval_spec
205lapply(err_eq_from_io ????? EQnopc) -EQnopc >(fetch_stmt_ok_sigma_state_ok … EQfetch)
206#EQnopc
207cases(eval_seq_no_pc_no_call_ok prog f_lbls f_regs ???????? EQnopc)
208[ #stnopc'' * #EQstnopc'' #EQsem %
209  [ % [@stnopc'' | @(succ_pc ERTL_semantics (pc … st2) nxt) | @(last_pop … st2)]]
210  %
211  [ whd in match sigma_state_pc; normalize nodelta @('bind_inversion EQfetch)
212    * #f1 #fn1 >(fetch_stmt_ok_sigma_pc_ok … EQfetch) #EQfn1
213    #H @('bind_inversion H) -H #stmt1 #_ whd in ⊢ (??%% → ?); #EQ destruct(EQ)
214    >EQfn1 normalize nodelta >EQsem % ]
215  % [ @(produce_trace_any_any_free_coerced) [ @f | @t_fn1 |6: @eval_spec ||| @EQt_fn1]
216    whd in match repeat_eval_seq_no_pc; normalize nodelta whd in ⊢ (??%?);
217    >EQstnopc'' %] @if_elim [#_ @I] #_ %1 % whd in match as_costed;
218    normalize nodelta * #H @H whd in ⊢ (??%?); >EQfetch %
219| #lbl whd in match code_has_label; whd in match code_has_point; normalize nodelta
220  inversion(stmt_at ????) [#_ *] #stmt1 #EQstmt1 #_
221  cut(fetch_statement ERTL_semantics (prog_var_names … prog) (globalenv_noinit … prog)
222                      (pc_of_point ERTL_semantics (pc_block (pc … st2)) lbl) =
223                 return 〈f,fn,stmt1〉)
224   [ lapply(fetch_statement_inv … EQfetch') * #EQfn #_ whd in ⊢ (??%?);
225     >EQfn normalize nodelta >point_of_pc_of_point >EQstmt1 %] #EQf_stmt1
226  cases(b_graph_transform_program_fetch_statement_plus … good … EQf_stmt1)
227  #init * #t_fn' ** #EQt_fn' whd in ⊢ (% → ?); cases(f_bl_r ?) [2: #x #y *]
228  normalize nodelta #EQ destruct(EQ) * #labels * #registers
229  ******* #EQlabels >point_of_pc_of_point change with (pc_block (pc … st2)) in match (pc_block ?);
230  #EQregisters #_ #_ #_ #_ #_ #_ >EQregisters
231  cases(excluded_middle_list ? (λreg.bool_to_Prop(¬(reg∈registers)))
232         (get_used_registers_from_seq … (functs ERTL) stmt) ?)
233  [3: #a #_ cases(¬a∈registers) // |1: #H assumption] #H @⊥
234  lapply(fetch_statement_inv … EQfetch') * #_ normalize nodelta #EQstmt
235  cases(Exists_All … H (regs_are_in_univers … (pi2 ?? fn) … EQstmt))
236   #reg ** #H1 #H2 @H1 -H1 @notb_Prop % #H1 lapply(fresh_regs … lbl) >EQregisters
237  whd in ⊢ (% → ?); #H3 lapply(All_memb … H3 H1) ** #H4 #_ @H4 assumption
238]
239qed.
240
241lemma eval_goto_ok :
242 ∀prog : ertl_program.
243 let trans_prog ≝ ertl_to_ertlptr prog in
244∀ f_lbls,f_regs,stack_sizes.
245 ∀f_bl_r.
246 b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
247     (λglobals,fn.«translate_data globals fn,(refl …)») prog f_bl_r f_lbls f_regs →
248 ∀st2.
249 let st1 ≝ (sigma_state_pc prog f_lbls f_regs st2) in
250 ∀st1',f,fn,nxt.
251   fetch_statement ERTL_semantics …
252    (globalenv_noinit ? prog) (pc … st1) =
253      return 〈f, fn,  final … (GOTO ERTL … nxt)〉 →
254   eval_state ERTL_semantics
255   (prog_var_names (joint_function ERTL_semantics) ℕ prog)
256   (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes))
257   st1 =
258    return st1' →
259    ∃ st2'. st1' = sigma_state_pc prog f_lbls f_regs st2' ∧
260 ∃taf : trace_any_any_free (ERTLptr_status trans_prog stack_sizes)
261  st2
262  st2'.
263  bool_to_Prop (taaf_non_empty … taf).
264#prog #f_lbls #f_regs #stack_size #f_bl_r #good #st2 #st1' #f #fn #nxt #EQfetch
265whd in match eval_state; normalize nodelta >EQfetch >m_return_bind
266whd in match eval_statement_no_pc; normalize nodelta
267>m_return_bind whd in match eval_statement_advance; whd in match set_no_pc;
268whd in match goto; normalize nodelta #H lapply(err_eq_from_io ????? H) -H
269#H @('bind_inversion H) -H #new_pc lapply(fetch_statement_inv … EQfetch) *
270#EQfn #_ >(pc_of_label_eq … EQfn) whd in ⊢ (??%% → ??%% → ?);
271#EQ1 #EQ2 destruct(EQ1 EQ2)
272% [ % [ @st2 | @(mk_program_counter (pc_block (pc … st2))
273                         (offset_of_point ERTL_semantics nxt)) | @(last_pop … st2)]]
274% [ >(fetch_stmt_ok_sigma_state_ok … EQfetch) >(fetch_stmt_ok_sigma_pc_ok … EQfetch)
275    >(fetch_stmt_ok_sigma_last_pop_ok … EQfetch) whd in match sigma_state_pc;
276    normalize nodelta >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQfn; #EQfn
277    >EQfn %]
278cases(b_graph_transform_program_fetch_statement … good … EQfetch)
279#init_data * #t_fn1 ** #EQt_fn1 whd in ⊢ (% → ?); cases (f_bl_r ?) normalize nodelta
280[2: #r #tl *] #EQ destruct(EQ) * #labs **
281[2: #hd #tl ** #_ #_ ** #pre #inst * whd in ⊢ (%→?); *] ** #EQlabs #EQf_regs
282whd in match translate_fin_step; normalize nodelta * #bl *
283whd in ⊢ (% → ?); #EQ destruct(EQ) **
284[2: #lb #tl * #mid ** #EQmid whd in ⊢ (% → ?); * #ABS destruct(ABS)] * #mid **
285whd in ⊢ (???% → ?); #EQ destruct(EQ) * #_ #_ change with (stmt_at ???? = ? → ?)
286#EQstmt >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQt_fn1; #EQt_fn1
287>(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQstmt; #EQstmt
288%{(taaf_step … (taa_base …) …)}
289[ whd in match as_classifier; normalize nodelta whd in ⊢ (??%?);
290  whd in match fetch_statement; normalize nodelta 
291  >EQt_fn1 >m_return_bind >EQstmt %
292| whd whd in match eval_state; normalize nodelta whd in match fetch_statement;
293  normalize nodelta  >EQt_fn1 >m_return_bind >EQstmt >m_return_bind
294  whd in match eval_statement_no_pc; normalize nodelta >m_return_bind
295  whd in match eval_statement_advance; normalize nodelta
296  whd in match goto; normalize nodelta >(pc_of_label_eq … EQt_fn1) %
297] @I
298qed.
299
300
301
302(*
303lemma list_elim_on_last : ∀A : Type[0].∀ P : (list A) → Prop. ∀ l.
304                 P ([ ]) → (∀pre,last. P (pre@[last])) → P l.
305#A #P #l #H1 #H2 cut(∀A.∀l : list A.l = [ ] ∨ ∃pre,last. l = pre@[last])
306[ #A #l elim l [ %1 % | #a #tl * [ #EQ destruct %2 %{([ ])} %{a} %]
307* #l1 * #a1 #EQ destruct %2 %{(a::l1)} %{a1} %]] #APP1
308lapply(APP1 … l) * [ #EQ >EQ assumption]
309 * #pre * #last #EQ >EQ @H2
310qed.*)
311
312
313
314lemma eval_return_ok :
315∀prog : ertl_program.
316let trans_prog ≝ ertl_to_ertlptr prog in
317∀ f_lbls,f_regs,stack_sizes.
318 ∀f_bl_r.
319 ∀ good :b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
320     translate_data prog f_bl_r f_lbls f_regs.
321∀st2, st1',f,fn.
322 let st1 ≝ sigma_state_pc prog f_lbls f_regs st2 in
323 fetch_statement ERTL_semantics …
324  (globalenv_noinit ? prog) (pc … st1) =
325    return 〈f, fn,  final … (RETURN ERTL … )〉 →
326 eval_state ERTL_semantics
327   (prog_var_names (joint_function ERTL_semantics) ℕ prog)
328   (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes))
329   st1 =
330  return st1' →
331joint_classify (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)
332  st2 = cl_return ∧
333∃st2'. st1' = sigma_state_pc prog f_lbls f_regs st2' ∧
334∃st2_after_ret.
335∃taf : trace_any_any_free (ERTLptr_status trans_prog stack_sizes) (* always empty in this case *)
336st2_after_ret
337st2'.
338(if taaf_non_empty … taf then
339  ¬as_costed (ERTLptr_status trans_prog stack_sizes)
340    st2_after_ret
341 else True) ∧
342eval_state … (ev_genv …  (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) st2 =
343return st2_after_ret ∧
344ret_rel ?? (ERTLptrStatusSimulation prog stack_sizes ??? good) st1' st2_after_ret.
345#prog #f_lbls #f_regs #stack_size #f_bl_r #good #st2 #st1' #f #fn #EQfetch
346whd in match eval_state; normalize nodelta >EQfetch >m_return_bind
347#H @('bind_inversion H) -H #st1_tmp whd in ⊢ (??%%→?); #EQ destruct
348whd in match set_no_pc in ⊢ (%→?); whd in match eval_statement_advance in ⊢ (%→?);
349whd in match eval_return; normalize nodelta #H lapply(err_eq_from_io ????? H) -H
350#H @('bind_inversion H) -H * #n_st #n_pc change with (ertl_pop_frame ? = ? → ?)
351>(fetch_stmt_ok_sigma_state_ok … EQfetch) #EQpop_frame
352cases(pop_frame_ok ?????? EQpop_frame) * #t_n_st #t_n_pc * #EQt_pop_frame
353normalize nodelta
354inversion (fetch_internal_function ??) normalize nodelta
355[ * #id1 #fn1 | #err ] normalize nodelta #EQfetch_fn1 #EQ destruct(EQ)
356#H @('bind_inversion H) -H #next_of_n_pc
357[2: >next_of_call_pc_error [2: % %] whd in ⊢ (???% → ?); #EQ destruct(EQ)]
358#EQnext_of_n_pc cases(next_of_call_pc_ok … good … EQnext_of_n_pc)
359#pc1 * #EQpc1 cut(pc1 = t_n_pc)
360[ @(sigma_stored_pc_inj prog f_lbls)
361  lapply EQnext_of_n_pc; <EQpc1 whd in match sigma_stored_pc; normalize nodelta
362  inversion(sigma_pc_opt ???) [1,3: #_ >next_of_call_pc_error [2,4: % %]
363  whd in ⊢ (???% → ?); #EQ destruct| #x #_ #_ % #EQ destruct] #x #EQx #_
364  lapply EQnext_of_n_pc whd in match sigma_stored_pc; normalize nodelta
365  inversion (sigma_pc_opt ???) [ #_ >next_of_call_pc_error [2: % %]
366  whd in ⊢ (???% → ?); #EQ destruct] #y #EQy #_ lapply EQpc1
367  whd in match sigma_stored_pc; normalize nodelta >EQx >EQy normalize nodelta
368  #EQ destruct %
369] #EQ destruct(EQ) #EQnxt whd in match next; whd in match set_last_pop;
370whd in match set_pc; normalize nodelta whd in ⊢ (??%% → ?); #EQ destruct(EQ)
371cases(b_graph_transform_program_fetch_statement … good … EQfetch)
372#init_data * #t_fn1 ** #EQt_fn1 whd in ⊢ (% → ?); cases (f_bl_r ?) normalize nodelta
373[2: #r #tl *] #EQ destruct(EQ) * #labs **
374[2: #hd #tl ** #_ #_ * #ibl * whd in ⊢ (%→?); *] ** #EQlabs #EQf_regs
375whd in match translate_fin_step; normalize nodelta * #bl *
376whd in ⊢ (% → ?); #EQ destruct(EQ) **
377[2: #lb #tl * #mid ** #EQmid whd in ⊢ (% → ?); * #ABS destruct(ABS)] * #mid **
378whd in ⊢ (???% → ?); #EQ destruct(EQ) * #_ #_ change with (stmt_at ???? = ? → ?)
379#EQstmt %
380[ whd in match joint_classify; normalize nodelta whd in match fetch_statement;
381  normalize nodelta <(fetch_stmt_ok_sigma_pc_ok … EQfetch) >EQt_fn1 >m_return_bind
382  >EQstmt %
383| %
384    [ %
385        [ @t_n_st
386        | @(succ_pc ERTL_semantics (sigma_stored_pc prog f_lbls t_n_pc) next_of_n_pc)
387        | @t_n_pc]
388    ]
389  % 
390    [ whd in match sigma_state_pc; normalize nodelta
391      lapply(next_of_call_pc_inv … EQnext_of_n_pc) * #id2 * #fn2 * #c_id * #c_arg
392      * #c_dest #EQfetch1 whd in match (succ_pc ???);
393      >(fetch_stmt_ok_sigma_pc_block_ok … EQfetch1) >EQfetch_fn1
394      normalize nodelta %
395    ]
396  %
397    [ %
398        [ @t_n_st
399        | @(succ_pc ERTL_semantics (sigma_stored_pc prog f_lbls t_n_pc) next_of_n_pc)
400        | @t_n_pc]
401    ]
402  %{(taaf_base … )} normalize nodelta % [% [@I]]
403    [ whd in match fetch_statement; normalize nodelta <(fetch_stmt_ok_sigma_pc_ok … EQfetch)
404      >EQt_fn1 >m_return_bind >EQstmt >m_return_bind whd in match eval_statement_no_pc;
405      normalize nodelta >m_return_bind whd in match eval_statement_advance;
406      whd in match eval_return; normalize nodelta 
407      change with (ertl_pop_frame ?) in match (pop_frame ????????);
408      >EQt_pop_frame >m_return_bind >EQnxt >m_return_bind whd in match next;
409      whd in match set_pc; whd in match set_last_pop; whd in match succ_pc;
410      normalize nodelta lapply(next_of_call_pc_inv … EQnext_of_n_pc)
411      * #id2 * #fn2 * #c_id * #c_arg * #c_dest #EQfetch1 whd in match (succ_pc ???);
412      >(fetch_stmt_ok_sigma_pc_block_ok … EQfetch1) %
413    | whd * #s1_pre #s1_call
414      cases (joint_classify_call … s1_call)
415      * #calling_i #calling * #call_spec * #arg * #dest * #nxt' #EQfetch_call
416      * #s2_pre #s2_call whd in ⊢ (% → ?); >EQfetch_call normalize nodelta
417      * #s1_pre_prf #EQpc_s2_pre whd in ⊢ (% → ?); #EQ1
418      >EQ1 in EQfetch_call; #EQfetch_call
419      cases(fetch_call_commute … good … EQfetch_call) #calling' * #pc1 *
420      #EQ1 cut(pc … s2_pre = pc1)
421      [ @(sigma_stored_pc_inj prog f_lbls) lapply(EQfetch_call)
422        whd in match sigma_stored_pc; normalize nodelta inversion(sigma_pc_opt ???)
423        [1,3: #_ >fetch_statement_no_zero [2,4: %] #EQ destruct(EQ)| #x #_ #_ % #EQ destruct]
424        #pc2 #EQpc2 #_ lapply EQ1 whd in match sigma_stored_pc;
425        normalize nodelta >EQpc2 normalize nodelta cases(sigma_pc_opt ???)
426        [2: #x normalize nodelta #EQ >EQ %] normalize nodelta #EQ <EQ in EQpc2;
427        #EQ1 lapply EQfetch_call >fetch_statement_no_zero [ #ABS destruct(ABS)]
428        whd in match sigma_stored_pc; normalize nodelta >EQ1 %
429      ] #EQ2 destruct(EQ2) #EQt_fetch_call whd >EQt_fetch_call normalize nodelta %
430       [ >EQ1 in s1_pre_prf; #EQ @(sigma_stored_pc_inj prog f_lbls)
431        lapply EQnext_of_n_pc whd in match sigma_stored_pc; normalize nodelta
432        inversion(sigma_pc_opt ???) [1,3: #_ >next_of_call_pc_error [2,4: % %]
433        whd in ⊢ (???% → ?); #EQ destruct] #pc1 #EQpc1 #_ [ % #EQ destruct]
434        lapply EQ whd in match sigma_stored_pc; normalize nodelta
435        >EQpc1 normalize nodelta inversion(sigma_pc_opt ???)
436        [2: #pc2 #_ normalize nodelta #EQ >EQ %] normalize nodelta
437        #ABS #ABS1 lapply EQnext_of_n_pc whd in match sigma_stored_pc;
438        normalize nodelta >EQpc1 >ABS1 normalize nodelta
439        >next_of_call_pc_error [2: % %] whd in ⊢ (???% → ?); #EQ destruct
440       | whd in match succ_pc; normalize nodelta
441        change with next_of_n_pc in match (point_of_succ ???);
442        change with nxt' in match (point_of_succ ???);
443        lapply EQpc_s2_pre whd in match succ_pc; normalize nodelta
444        change with next_of_n_pc in match (point_of_succ ???);
445        change with nxt' in match (point_of_succ ???); #EQ >EQ
446        cut(pc_block (pc … s1_pre) = pc_block (pc … s2_pre))
447        [2: #EQ >EQ %] >EQ1 <(pc_block_eq prog f_lbls …) [%]
448        lapply EQfetch_call whd in match sigma_stored_pc; normalize nodelta
449        cases(sigma_pc_opt ???) [ >fetch_statement_no_zero [2: %] #EQ destruct]
450        #x #_ % #EQ destruct
451       ]
452     ]
453]
454qed.
455
456
457
458lemma eval_cond_ok :
459∀prog.
460let trans_prog ≝ ertl_to_ertlptr prog in
461∀ f_lbls,f_regs,stack_sizes.
462 ∀f_bl_r.
463 ∀ good :b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
464     (λglobals,fn.«translate_data globals fn,(refl …)») prog f_bl_r f_lbls f_regs.
465∀st2,st1',f,fn,a,ltrue,lfalse.
466let st1 ≝ sigma_state_pc prog f_lbls f_regs st2 in
467 fetch_statement ERTL_semantics …
468  (globalenv_noinit ? prog) (pc … st1) =
469    return 〈f, fn,  sequential … (COND ERTL … a ltrue) lfalse〉 →
470 eval_state ERTL_semantics
471   (prog_var_names (joint_function ERTL_semantics) ℕ prog)
472   (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes))
473   st1 = return st1' →
474as_costed (ERTL_status prog stack_sizes) st1' →
475∃ st2'. st1' = sigma_state_pc prog f_lbls f_regs st2' ∧
476∃taf : trace_any_any_free (ERTLptr_status trans_prog stack_sizes)
477st2 st2'.
478bool_to_Prop (taaf_non_empty … taf).
479#prog #f_lbls #f_regs #stack_size #f_bl_r #good #st2 #st1' #f #fn #a #ltrue #lfalse
480#EQfetch whd in match eval_state; normalize nodelta >EQfetch >m_return_bind
481whd in match eval_statement_no_pc; normalize nodelta >m_return_bind
482whd in match eval_statement_advance; normalize nodelta
483change with (ps_reg_retrieve ??) in match (acca_retrieve ?????);
484#H lapply(err_eq_from_io ????? H) -H #H @('bind_inversion H) -H
485#bv >(fetch_stmt_ok_sigma_state_ok … EQfetch) in ⊢ (% → ?); whd in match set_no_pc;
486normalize nodelta #EQbv #H @('bind_inversion H) -H * #EQbool normalize nodelta
487 lapply(fetch_statement_inv … EQfetch) * #EQfn #_
488[ whd in match goto; normalize nodelta >(pc_of_label_eq ??????? EQfn) >m_return_bind
489| whd in match next; normalize nodelta
490] whd in match set_pc; normalize nodelta
491>(fetch_stmt_ok_sigma_state_ok … EQfetch) whd in match set_no_pc; normalize nodelta
492>(fetch_stmt_ok_sigma_pc_ok … EQfetch) >(fetch_stmt_ok_sigma_last_pop_ok … EQfetch)
493whd in ⊢ (??%% → ?); #EQ destruct #n_cost
494%{(mk_state_pc ? (st_no_pc … st2)
495                 (pc_of_point ERTLptr_semantics (pc_block (pc … st2)) ?)
496                 (last_pop … st2))} [ @ltrue |3: @lfalse]
497% [1,3: whd in match sigma_state_pc; normalize nodelta
498        >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQfn; #EQfn >EQfn %]
499cases(b_graph_transform_program_fetch_statement … good … EQfetch)
500#init_data * #t_fn1 ** #EQt_fn1 whd in ⊢ (% → ?); cases (f_bl_r ?) normalize nodelta
501[2,4: #r #tl *] #EQ destruct(EQ) >if_merge_right in ⊢ (% → ?); [2,4: %] * #labs **
502[2,4: #hd #tl ** #_ #_ *** #pre #inst #post * whd in ⊢ (%→?); *] ** #EQlabs #EQf_regs
503whd in match translate_step; normalize nodelta * #bl *
504whd in ⊢ (% → ?); #EQ destruct(EQ) whd in ⊢ (% → ?); * #l1 * #mid1 * #mid2 * #l2
505*** #EQmid1 whd in ⊢ (% → ?); * #EQ1 #EQ2 destruct(EQ1 EQ2) whd in ⊢ (% → ?); *
506#nxt1 * #EQcond #EQ destruct(EQ) whd in ⊢ (% → ?); * #EQ1 #EQ2 destruct(EQ1 EQ2)
507whd in EQmid1 : (??%%); destruct(EQmid1)
508%{(taaf_step_jump … (taa_base …) …) I}
509[2,5: whd whd in ⊢ (??%?); whd in match fetch_statement; normalize nodelta 
510      <(fetch_stmt_ok_sigma_pc_ok … EQfetch) >EQt_fn1 >m_return_bind
511      >EQcond %
512|3,6: whd whd in match eval_state; normalize nodelta whd in match eval_statement_no_pc;
513      normalize nodelta whd in match fetch_statement; normalize nodelta
514      <(fetch_stmt_ok_sigma_pc_ok … EQfetch) >EQt_fn1 >m_return_bind
515      >EQcond >m_return_bind normalize nodelta >m_return_bind
516      whd in match eval_statement_advance; normalize nodelta
517      change with (ps_reg_retrieve ??) in match (acca_retrieve ?????);
518      cases(ps_reg_retrieve_ok … EQbv) #bv1 * #EQbv1 #EQsem >EQbv1
519      >m_return_bind >EQsem in EQbool; #EQbool cases(bool_of_beval_ok … EQbool)
520      #bool1 * #EQbool1 #EQ destruct(EQ) >EQbool1 >m_return_bind normalize nodelta
521      >(fetch_stmt_ok_sigma_pc_ok … EQfetch) [2: %] whd in match goto;
522      normalize nodelta >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQt_fn1; #EQt_fn1
523      >(pc_of_label_eq … EQt_fn1) >m_return_bind %
524|*: lapply n_cost whd in match as_costed; normalize nodelta
525    [ cut((mk_state_pc ERTL_semantics
526   (sigma_state prog f_lbls f_regs
527    (added_registers ERTL (prog_var_names (joint_function ERTL) ℕ prog) fn
528     (f_regs (pc_block (pc ERTLptr_semantics st2)))) st2)
529   (pc_of_point ERTL_semantics (pc_block (pc ERTLptr_semantics st2)) ltrue)
530   (sigma_stored_pc prog f_lbls (last_pop ERTLptr_semantics st2))) =
531   sigma_state_pc prog f_lbls f_regs (mk_state_pc ERTLptr_semantics st2
532    (pc_of_point ERTLptr_semantics (pc_block (pc ERTLptr_semantics st2)) ltrue)
533    (last_pop ERTLptr_semantics st2))) [ whd in match sigma_state_pc; normalize  nodelta
534    >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQfn; #EQfn >EQfn %]
535    #EQ >EQ >(as_label_ok … good … (mk_state_pc ERTLptr_semantics st2
536    (pc_of_point ERTLptr_semantics (pc_block (pc ERTLptr_semantics st2)) ltrue)
537    (last_pop ERTLptr_semantics st2))) [#H @H] cases daemon (*needs lemma see below *)
538    | cut((mk_state_pc ERTL_semantics
539   (sigma_state prog f_lbls f_regs
540    (added_registers ERTL (prog_var_names (joint_function ERTL) ℕ prog) fn
541     (f_regs (pc_block (pc ERTLptr_semantics st2)))) st2)
542   (succ_pc ERTL_semantics (pc ERTLptr_semantics st2)
543    (point_of_succ ERTLptr_semantics
544     (point_of_pc ERTLptr_semantics
545      (pc ERTL_semantics (sigma_state_pc prog f_lbls f_regs st2))) nxt1))
546   (sigma_stored_pc prog f_lbls (last_pop ERTLptr_semantics st2))) =
547   sigma_state_pc prog f_lbls f_regs (mk_state_pc ERTLptr_semantics st2
548    (pc_of_point ERTLptr_semantics (pc_block (pc ERTLptr_semantics st2))
549     (point_of_succ ERTLptr_semantics
550      (point_of_pc ERTLptr_semantics
551       (pc ERTL_semantics (sigma_state_pc prog f_lbls f_regs st2))) nxt1))
552    (last_pop ERTLptr_semantics st2))) [ whd in match sigma_state_pc; normalize  nodelta
553    >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQfn; #EQfn >EQfn %] #EQ >EQ
554    >(as_label_ok … good … (mk_state_pc ERTLptr_semantics st2
555    (pc_of_point ERTLptr_semantics (pc_block (pc ERTLptr_semantics st2))
556     (point_of_succ ERTLptr_semantics
557      (point_of_pc ERTLptr_semantics
558       (pc ERTL_semantics (sigma_state_pc prog f_lbls f_regs st2))) nxt1))
559    (last_pop ERTLptr_semantics st2))) [#H @H] cases daemon (*needs lemma see below ! *)
560]
561qed.
562     
563lemma eval_cost_ok :
564∀prog.
565let trans_prog ≝ ertl_to_ertlptr prog in
566∀ f_lbls,f_regs,stack_sizes.
567 ∀f_bl_r.
568 ∀ good :b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
569     (λglobals,fn.«translate_data globals fn,(refl …)») prog f_bl_r f_lbls f_regs.
570∀st2,st1',f,fn,c,nxt.
571let st1 ≝ sigma_state_pc prog f_lbls f_regs st2 in
572 fetch_statement ERTL_semantics …
573  (globalenv_noinit ? prog) (pc … st1) =
574    return 〈f, fn,  sequential … (COST_LABEL ERTL … c) nxt〉 →
575 eval_state ERTL_semantics
576   (prog_var_names (joint_function ERTL_semantics) ℕ prog)
577   (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes))
578   st1 = return st1' →
579∃ st2'. st1' = sigma_state_pc prog f_lbls f_regs st2' ∧
580∃taf : trace_any_any_free (ERTLptr_status trans_prog stack_sizes)
581st2 st2'.
582bool_to_Prop (taaf_non_empty … taf).
583#prog #f_lbls #f_regs #stack_Size #f_bl_r #good #st2 #st1' #f #fn #c #nxt
584#EQfetch whd in match eval_state; normalize nodelta >EQfetch >m_return_bind
585whd in match eval_statement_no_pc; normalize nodelta >m_return_bind
586whd in match eval_statement_advance; normalize nodelta
587>(fetch_stmt_ok_sigma_state_ok … EQfetch) whd in match set_no_pc;
588normalize nodelta >(fetch_stmt_ok_sigma_pc_ok … EQfetch)
589>(fetch_stmt_ok_sigma_last_pop_ok … EQfetch) whd in match next;
590whd in match set_pc; normalize nodelta whd in ⊢ (??%% → ?); #EQ destruct(EQ)
591%{(set_pc ? (pc_of_point ERTLptr_semantics (pc_block (pc … st2)) nxt) st2)}
592% [ whd in match sigma_state_pc; normalize nodelta
593    lapply(fetch_statement_inv … EQfetch) >(fetch_stmt_ok_sigma_pc_ok … EQfetch) *
594    #EQfn #_ >EQfn %] lapply EQfetch >(fetch_stmt_ok_sigma_pc_ok … EQfetch)
595#EQfetch'
596cases(b_graph_transform_program_fetch_statement … good … EQfetch')
597#init_data * #t_fn ** #EQt_fn whd in ⊢ (% → ?); cases(f_bl_r ?) [2: #x #y *]
598normalize nodelta #EQ destruct(EQ) * #lbls * #regs ** #_ #_ whd in ⊢ (% → ?);
599* #bl * >if_merge_right [2: %] whd in ⊢ (% → ?); cases regs [2: #x #y *]
600normalize nodelta #EQ destruct(EQ) whd in ⊢ (% → ?); * #l1 * #mid1 * #mid2 * #l2
601*** #EQmid whd in ⊢ (% → ?); * #EQ1 #EQ2 destruct(EQ1 EQ2) whd in EQmid : (???%);
602destruct(EQmid) whd in ⊢ (% → ?); * #nxt1 * #EQstmt #EQ destruct(EQ)
603whd in ⊢ (% → ?); * #EQ1 #EQ2 destruct(EQ1 EQ2) %{(taaf_step … (taa_base …) …)}
604[1,2: whd [ whd in ⊢ (??%?); | whd in match eval_state; ] 
605      whd in match fetch_statement; normalize nodelta >EQt_fn >m_return_bind
606      >EQstmt [%] >m_return_bind whd in match eval_statement_no_pc;
607      normalize nodelta >m_return_bind %] @I
608qed.
609
610
611lemma eval_call_ok   :
612 ∀prog : ertl_program.
613 let trans_prog ≝ ertl_to_ertlptr prog in
614∀ f_lbls,f_regs,stack_sizes.
615 ∀f_bl_r.
616 ∀ good :b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
617     (λglobals,fn.«translate_data globals fn,(refl …)») prog f_bl_r f_lbls f_regs.
618 ∀st2,st1',f,fn,called,args,dest,nxt.
619 let st1 ≝ sigma_state_pc prog f_lbls f_regs st2 in
620  fetch_statement ERTL_semantics …
621    (globalenv_noinit ? prog) (pc … st1) =
622      return 〈f, fn,
623        sequential … (CALL ERTL … called args dest ) nxt〉 →
624   eval_state … (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes)) st1 =
625    return st1' →
626∃is_call,st2_pre_call,is_call'.
627as_call_ident (ERTLptr_status trans_prog stack_sizes)
628 («st2_pre_call,is_call'») = as_call_ident (ERTL_status prog stack_sizes)
629  («st1, is_call») ∧
630(pc … st1) = sigma_stored_pc prog f_lbls (pc … st2_pre_call) ∧
631∃taa2 : trace_any_any (ERTLptr_status trans_prog stack_sizes) st2 st2_pre_call.
632∃ st2'. st1' = sigma_state_pc prog f_lbls f_regs st2' ∧
633eval_state ERTLptr_semantics …
634 (ev_genv … (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) st2_pre_call
635 =return st2'.
636#prog #f_lbls #f_regs #stack_size #f_bl_r #good #st2 #st1' #f #fn * [#c_id | * #c_ptr1 #c_ptr2 ]
637#args #dest #nxt #EQfetch whd in match eval_state; normalize nodelta >EQfetch
638>m_return_bind whd in match eval_statement_no_pc; normalize nodelta >m_return_bind
639whd in match eval_statement_advance; whd in match eval_call; normalize nodelta
640>(fetch_stmt_ok_sigma_state_ok … EQfetch) >(fetch_stmt_ok_sigma_pc_ok … EQfetch)
641>(fetch_stmt_ok_sigma_last_pop_ok … EQfetch) #H @('bind_inversion H) -H
642#c_bl whd in match set_no_pc; normalize nodelta #H lapply(err_eq_from_io ????? H) -H
643#EQc_bl cases(block_of_call_ok ??????? EQc_bl) #c_bl' * #EQc_bl' #EQ destruct(EQ)
644#H @('bind_inversion H) -H * #f1 * [1,3: #fn1 |*: #ext_f] #H
645lapply(err_eq_from_io ????? H) -H  #EQfn1 normalize nodelta
646[3,4: #H @('bind_inversion H) -H #st whd in match eval_external_call; normalize nodelta
647      #H @('bind_inversion H) -H #list_val #_ #H @('bind_inversion H) -H #x
648      #_ #H @('bind_inversion H) -H #y whd in match do_io; normalize nodelta
649      whd in ⊢ (???% → ?); #ABS destruct(ABS) ] #H lapply(err_eq_from_io ????? H) -H
650#H @('bind_inversion H) -H #st1'' >(fetch_stmt_ok_sigma_pc_ok … EQfetch)
651>(fetch_stmt_ok_sigma_last_pop_ok … EQfetch) whd in match kind_of_call;
652normalize nodelta change with (ertl_save_frame ? it ?) in ⊢ (??%? → ?);
653[2: @ID |4: @PTR] #EQst1''  #H @('bind_inversion H) -H #st1'''
654whd in match eval_internal_call; normalize nodelta #H @('bind_inversion H) -H
655#s_size #H lapply(opt_eq_from_res ???? H) -H
656change with (stack_size ?) in ⊢ (??%? → ?); #EQs_size whd in ⊢ (??%? → ?);
657whd in ⊢ (???% → ??%% → ?); #EQ #EQ1 destruct(EQ EQ1)
658lapply EQfetch >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in ⊢ (% → ?);
659#EQfetch' lapply(fetch_statement_inv … EQfetch') * #EQfn normalize nodelta #EQstmt
660cases(b_graph_transform_program_fetch_statement_plus … good … EQfetch')
661#init_data * #calling' ** #EQcalling' whd in ⊢ (% → ?); cases(f_bl_r ?)
662[2,4: #x #y *] normalize nodelta #EQ destruct(EQ) * #labels * #registers
663******* #EQlabels #EQregisters #_ #_ #_ #_ #fresh_regs
664normalize nodelta >if_merge_right [2,4: %] whd in match translate_step;
665normalize nodelta * #bl * cases registers in EQregisters; -registers
666normalize nodelta [2,3: [ #x #y] #_ *|4: #r #tl] #EQregisters
667[ whd in ⊢ (% → ?); cases tl in EQregisters; -tl [2: #x #y #_ *] normalize nodelta
668#EQregisters | whd in ⊢ (% → ?);] #EQ destruct(EQ)
669* #pre_l * #mid1 * #mid2 * #post_l *** #EQmid1 #m_fetch_pre whd in ⊢ (% → ?);
670* #nxt1 * #EQcall change with nxt1 in ⊢ (??%? → ?); #EQ destruct(EQ)
671whd in ⊢ (% → ?); * #EQ1 #EQ2 destruct(EQ1 EQ2) cases(pre_l) in m_fetch_pre EQmid1;
672[* #x * #y ** #ABS destruct(ABS)
673|4: #lab #tl * #ABS destruct(ABS)
674| #l1 #tl #m_fetch_pre whd in ⊢ (???% → ?); #EQ destruct(EQ)
675| * #_ #EQ destruct(EQ) whd in ⊢ (???% → ?); #EQ destruct(EQ)
676]
677%
678[1,3: @hide_prf whd in ⊢ (??%?); >EQfetch %]
679cases(ertl_save_frame_ok prog f_lbls f_regs ?
680  (added_registers ERTL (prog_var_names … prog) fn1 (f_regs c_bl')) ? st1''' ?)
681[2: @PTR
682|3,7: [ %{(mk_state_pc ? (st_no_pc … st2)
683                     (pc_of_point ERTLptr_semantics (pc_block (pc … st2)) mid1)
684                     (last_pop … st2))}
685      |%{(st2)}
686      ] @hide_prf whd in match sigma_pc_opt; normalize nodelta @if_elim
687      [1,3: @eqZb_elim [2,4: #_ *] #EQbl >fetch_internal_function_no_minus_one in EQfn;
688           [1,3: #EQ destruct(EQ) |*: assumption]]
689      #_ [>point_of_pc_of_point >(get_sigma_last … good … EQfn EQstmt EQlabels)
690         | >(get_sigma_idempotent … good … EQfn EQstmt EQlabels)
691         ] >m_return_bind % whd in ⊢ (??%? → ?); #ABS destruct(ABS)
692|6: @ID
693|4,8: [change with (pc_block (pc … st2)) in match (pc_block ?);
694       >EQfn in ⊢ (??(???match % with [_ ⇒ ?| _ ⇒ ?])?);
695      |>EQfn in ⊢ (??(???match % with [_ ⇒ ?| _ ⇒ ?])?);
696      ] normalize nodelta whd in match (st_no_pc ??);
697      whd in match sigma_stored_pc in ⊢ (??(???(???%?))?);
698      whd in match sigma_pc_opt; normalize nodelta @if_elim
699     [1,3: @eqZb_elim [2,4: #_ *] #EQbl >fetch_internal_function_no_minus_one in EQfn;
700           [1,3: #EQ destruct(EQ) |*: assumption]]
701      #_ [>point_of_pc_of_point >(get_sigma_last … good … EQfn EQstmt EQlabels)
702         | >(get_sigma_idempotent … good … EQfn EQstmt EQlabels)
703         ] >m_return_bind normalize nodelta
704         change with (pc_block (pc … st2)) in match (pc_block ?);
705         >pc_of_point_of_pc assumption
706] #st_no_pc_after_call normalize nodelta *
707[ #H @('bind_inversion H) -H #st_no_pc_pre_call #EQst_no_pc_pre_call
708  whd in match set_no_pc; normalize nodelta]
709#EQst_no_pc_after_call #EQ destruct(EQ)
710[ letin pairpc ≝ (beval_pair_of_pc
711                     (pc_of_point ERTLptr_semantics (pc_block (pc … st2)) mid1))
712  %{(mk_state_pc ? (set_regs ERTL_state
713                      (〈add ?? (\fst (regs … st2)) r (\snd pairpc),\snd(regs … st2)〉)
714                      st_no_pc_pre_call)
715                   (pc_of_point ERTLptr_semantics (pc_block (pc … st2)) mid1)
716                   (last_pop … st2))}
717| %{st2}
718]
719%
720[1,3: @hide_prf whd in ⊢ (??%?); whd in match fetch_statement; normalize nodelta
721      >EQcalling' >m_return_bind [>point_of_pc_of_point ] >EQcall >m_return_bind %]
722%
723[1,3: %
724  [1,3: whd in ⊢ (??%%); whd in match fetch_statement in ⊢ (??%?);
725        normalize nodelta >EQcalling' in ⊢ (??(match % with [_ ⇒ ? | _ ⇒ ?])?);
726        >m_return_bind in ⊢ (??(match % with [_ ⇒ ? | _ ⇒ ?])?);
727       [ >point_of_pc_of_point in ⊢ (??(match % with [_ ⇒ ? | _ ⇒ ?])?);]
728       >EQcall in ⊢ (??(match % with [_ ⇒ ? | _ ⇒ ?])?); normalize nodelta
729       >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in ⊢ (???(match % with [_ ⇒ ? | _ ⇒ ?]));
730       >EQfetch' in ⊢ (???(match % with [_ ⇒ ? | _ ⇒ ?])); %
731  |*:  whd in match sigma_stored_pc; whd in match sigma_pc_opt; normalize nodelta
732      @if_elim change with (pc_block(pc … st2)) in match (pc_block ?);
733      [1,3: @eqZb_elim [2,4: #_ *] #EQbl #_
734      >fetch_internal_function_no_minus_one in EQcalling'; [2,4: assumption]
735      whd in ⊢ (???% → ?); #ABS destruct(ABS) ] #_
736      [ >point_of_pc_of_point >(get_sigma_last … good … EQfn EQstmt EQlabels)
737      | >(get_sigma_idempotent … good … EQfn EQstmt EQlabels)
738      ]
739      >m_return_bind >pc_of_point_of_pc %
740  ]
741|4: %{(taa_base …)}
742| %{(taaf_to_taa ???
743      (produce_trace_any_any_free
744           (mk_prog_params ERTLptr_semantics (ertl_to_ertlptr prog) stack_size)
745           st2 ?????
746           (mk_state_pc ?
747                (set_regs ERTL_state
748                      (〈add ?? (\fst (regs … st2)) r (\snd pairpc),\snd(regs … st2)〉)
749                      st_no_pc_pre_call)
750                (pc_of_point ERTLptr_semantics (pc_block (pc … st2)) mid1)
751                (last_pop … st2))
752           EQcalling' m_fetch_pre ?) ?)}
753  [ @if_elim [2: #_ @I] #_ % whd in ⊢ (% → ?); whd in match (as_label ??);
754    whd in match (as_pc_of ??); whd in match fetch_statement; normalize nodelta
755    >EQcalling' >m_return_bind whd in match point_of_pc; normalize nodelta
756    >point_of_offset_of_point >EQcall >m_return_bind normalize nodelta
757    whd in match cost_label_of_stmt; normalize nodelta * #H @H %
758  | whd in match repeat_eval_seq_no_pc; normalize nodelta whd in ⊢ (??%?);
759    whd in match eval_seq_no_pc in ⊢ (??match % with [_ ⇒ ?| _ ⇒ ?]?);
760    normalize nodelta whd in match (eval_ext_seq ????????);
761    whd in match (get_pc_from_label ?????); whd in match block_of_funct_id;
762    normalize nodelta @('bind_inversion EQfn) * #f2 * #fn2
763    whd in match fetch_function; normalize nodelta #H
764    lapply(opt_eq_from_res ???? H) -H #H @('bind_inversion H) -H #f3 #EQf3
765    #H @('bind_inversion H) -H #fn4 #_ whd in ⊢ (??%%→ ??%% → ?); #EQ1 #EQ2
766    destruct(EQ1 EQ2)
767    >(find_symbol_transf …
768            (λvars.transf_fundef … (λfn.(b_graph_translate … fn))) prog f)
769    >(symbol_of_block_rev … EQf3) >m_return_bind >code_block_of_block_eq
770    normalize nodelta >(pc_of_label_eq … EQcalling') normalize nodelta
771    whd in ⊢ (??%?);
772    whd in match eval_seq_no_pc in ⊢ (??match % with [_ ⇒ ?| _ ⇒ ?]?);
773    normalize nodelta whd in match (eval_ext_seq ????????);
774    whd in match acca_arg_retrieve; normalize nodelta
775    change with (ps_reg_retrieve ??) in match (acca_arg_retrieve_ ?????);
776    whd in match ps_reg_retrieve; whd in match reg_retrieve; normalize nodelta
777    >lookup_add_hit >m_return_bind whd in match set_regs; normalize nodelta
778    @('bind_inversion EQst_no_pc_pre_call) #new_st whd in match push in ⊢ (%→ ?);
779    normalize nodelta #H @('bind_inversion H) -H #is1 #EQis1 whd in ⊢ (??%% → ?);
780    #EQ destruct(EQ) #H @('bind_inversion H) -H #is2 #EQis2 whd in match set_istack;
781    normalize nodelta whd in ⊢ (??%% → ?); #EQ destruct(EQ) whd in match push;
782    normalize nodelta >EQis1 >m_return_bind whd in match set_istack; normalize nodelta
783    whd in ⊢ (??%?); whd in match eval_seq_no_pc in ⊢ (??match % with [_ ⇒ ?| _ ⇒ ?]?);
784    normalize nodelta whd in match (eval_ext_seq ????????);
785    whd in match (get_pc_from_label ?????); whd in match block_of_funct_id;
786    normalize nodelta
787    >(find_symbol_transf …
788            (λvars.transf_fundef … (λfn.(b_graph_translate … fn))) prog f)
789    >(symbol_of_block_rev … EQf3) >m_return_bind >code_block_of_block_eq
790    normalize nodelta >(pc_of_label_eq … EQcalling') normalize nodelta
791    whd in ⊢ (??%?);
792    whd in match eval_seq_no_pc in ⊢ (??match % with [_ ⇒ ?| _ ⇒ ?]?);
793    normalize nodelta whd in match (eval_ext_seq ????????);
794    whd in match acca_arg_retrieve; normalize nodelta
795    change with (ps_reg_retrieve ??) in match (acca_arg_retrieve_ ?????);
796    whd in match ps_reg_retrieve; whd in match reg_retrieve; normalize nodelta
797    >lookup_add_hit >m_return_bind whd in match set_regs; normalize nodelta
798    whd in match push; normalize nodelta >EQis2 >m_return_bind normalize nodelta
799    whd in ⊢ (??%?); @eq_f whd in match set_istack; normalize nodelta
800    whd in match reg_store; normalize  nodelta >add_idempotent %
801  | cut(∀st,st',kind.ertlptr_save_frame kind it st = return st' →
802                ∃hd,tl.st_frms … st' = return (cons ? hd tl) ∧
803                \snd hd = pc_block (pc … st))
804    [ #st * #frms #is #b #regs #m * whd in match ertlptr_save_frame;
805      normalize nodelta [ >m_return_bind | #H @('bind_inversion H) -H #st'' #EQst'']
806      #H @('bind_inversion H) -H #frames #H lapply(opt_eq_from_res ???? H) -H
807      #EQframes whd in ⊢ (??%% → ?); whd in match set_frms; whd in match set_regs;
808      normalize nodelta #EQ destruct(EQ) %{(〈\fst (regs ERTLptr_semantics ?),pc_block (pc … st)〉)}
809      [2,4: %{frames} % [1,3: %] |1,3:] %]
810    ] #save_frame_non_empty cases(save_frame_non_empty … EQst_no_pc_after_call)
811    * #fst_hd #snd_hd * #rest * #EQrest #EQhd
812  ]
813cases(b_graph_transform_program_fetch_internal_function … good c_bl' f1 fn1 ?)
814[2,4: whd in match fetch_internal_function; normalize nodelta >EQfn1 %]
815#init * #t_fn1 ** #EQt_fn1 #_ * #_ #_ #_ #EQentry #_ #_ #_ #_ #_ #_ #_
816[ %{(mk_state_pc ? st_no_pc_after_call
817        (pc_of_point
818            (mk_prog_params ERTLptr_semantics (ertl_to_ertlptr prog) stack_size)
819             c_bl' (joint_if_entry … t_fn1))
820        (last_pop … st2))}
821|
822%{(mk_state_pc ? (set_frms ERTL_state (〈(add ?? (fst_hd) r (\snd pairpc)),snd_hd〉
823                                 :: rest)
824                          st_no_pc_after_call)
825        (pc_of_point
826            (mk_prog_params ERTLptr_semantics (ertl_to_ertlptr prog) stack_size)
827             c_bl' (joint_if_entry … t_fn1))
828        (last_pop … st2))}
829]
830%
831[1,3: whd in match sigma_state_pc; normalize nodelta
832      whd in match pc_of_point in ⊢ (???%); normalize nodelta
833      whd in match fetch_internal_function; normalize nodelta >EQfn1
834      >m_return_bind normalize nodelta @eq_f3
835      [1,3,6: % |2,5: >EQentry %]
836      whd in match sigma_state; normalize nodelta
837      cut(∀ a1,a2,b1,b2,c1,c2,d1,d2,e1,e2.
838                    a1=a2 → b1 = b2 → c1 = c2 → d1 = d2 → e1 = e2 →
839                      mk_state ERTL_semantics a1 b1 c1 d1 e1 =
840                      mk_state ERTL_semantics a2 b2 c2 d2 e2)
841       [1,3: #H1 #H2 #H3 #H4 #H5 #H6 #H7 #H8 #H9 #H10 #H11 #H12 #H13 #H14
842                    #H15 //] #APP @APP try %
843       whd in match set_frms; normalize nodelta >EQrest
844       whd in match sigma_frames; normalize nodelta >m_return_bind
845       >m_return_bind whd in match sigma_frames_opt; whd in match m_list_map;
846       normalize nodelta whd in match (foldr ?????) in ⊢ (???%);
847       normalize nodelta >EQhd >EQfn >m_return_bind normalize nodelta
848       whd in match (foldr ?????); normalize nodelta
849       >EQfn >m_return_bind normalize nodelta 
850       change with (sigma_frames_opt prog f_lbls f_regs ?)
851                                            in match (foldr ?????);
852       change with (sigma_frames_opt prog f_lbls f_regs ?)
853                                                         in match (foldr ?????);
854       cases(sigma_frames_opt ????) [%] #t_rest >m_return_bind >m_return_bind
855       @eq_f @eq_f2 [2: %] @eq_f2 [2: %]
856       change with (pc_block (pc … st2)) in match (pc_block ?);
857       change with (pc_block (pc … st2)) in match (pc_block ?);
858       whd in match sigma_register_env; normalize nodelta
859       >map_add >set_minus_add [%] @list_as_set_mem @in_added_registers
860       [@(point_of_pc ERTL_semantics (pc ERTLptr_semantics st2))
861       | whd in match code_has_label; whd in match code_has_point; normalize nodelta
862         >EQstmt % | >EQregisters % % ]
863|*:    whd in match fetch_statement; normalize nodelta; >EQcalling' >m_return_bind
864       [2: >point_of_pc_of_point ] >EQcall >m_return_bind normalize nodelta
865       >m_return_bind
866       [2: >EQc_bl' >m_return_bind
867       | whd in match block_of_call; normalize nodelta
868         @('bind_inversion EQst_no_pc_pre_call) #st3 #H @('bind_inversion H) -H
869         #is3 inversion(istack … st2) [2: #bv |3: #bv1 #bv2] #EQis3
870         whd in match is_push; normalize nodelta whd in ⊢ (??%% → ??%% → ?);
871         #EQ1 #EQ2 destruct(EQ1 EQ2) #H @('bind_inversion H) -H #is3
872         whd in ⊢ (??%% → ??%% → ?); #EQ1 #EQ2 destruct(EQ1 EQ2)
873         whd in match set_regs; whd in match dpl_arg_retrieve; normalize nodelta
874         change with (ps_arg_retrieve ??) in match (dpl_arg_retrieve_ ?????);
875         @('bind_inversion EQc_bl') #c_bl'' whd in match dpl_arg_retrieve; normalize nodelta
876         change with (ps_arg_retrieve ??) in match (dpl_arg_retrieve_ ?????);
877         #H @('bind_inversion H) -H #bv_ptr1 whd in match ps_arg_retrieve;
878         normalize nodelta cases (c_ptr1) in EQstmt; [#r_ptr1 | #b_ptr1] #EQstmt
879         normalize nodelta
880         [ whd in match ps_reg_retrieve; whd in match reg_retrieve; normalize nodelta
881           #H lapply(opt_eq_from_res ???? H) -H #EQbv_ptr1
882         | whd in ⊢ (??%% → ?); #EQ destruct(EQ)
883         ]
884         whd in match dph_arg_retrieve; normalize nodelta
885         change with (ps_arg_retrieve ??) in match (dph_arg_retrieve_ ?????);
886         whd in match ps_arg_retrieve; normalize nodelta cases c_ptr2 in EQstmt;
887         [1,3: #r_ptr2 |*: #b_ptr2] #EQstmt normalize nodelta
888         [1,2: whd in match ps_reg_retrieve; whd in match reg_retrieve;
889               normalize nodelta #H @('bind_inversion H) -H
890               #bv_ptr2 #H lapply(opt_eq_from_res ???? H) -H #EQbv_ptr2
891         |*:   >m_return_bind
892         ] #H @('bind_inversion H) -H #ptr #EQptr @if_elim #ptr_ok whd in ⊢ (??%% → ?);
893         #EQ destruct(EQ) #H lapply(opt_eq_from_res ???? H) -H #EQptr_code
894         [2,4: >m_return_bind
895         |*: >lookup_add_miss
896             [1,3: >EQbv_ptr1 >m_return_bind
897             |*: % #ABS destruct(ABS)
898                lapply(fresh_regs (point_of_pc ERTL_semantics (pc … st2)))
899                >EQregisters whd in ⊢ (% → ?); *** #ABS #_ #_ @ABS
900                lapply(regs_are_in_univers … (pi2 ?? fn) … EQstmt) whd in match stmt_registers;
901                whd in match get_used_registers_from_step; normalize nodelta
902                whd in ⊢ (???% → ?); * //
903             ]
904         ]
905         change with (ps_arg_retrieve ??) in match (dph_arg_retrieve_ ?????);
906         whd in match ps_arg_retrieve; normalize nodelta
907         [2,4: >m_return_bind   
908         |*: whd in match ps_reg_retrieve; whd in match reg_retrieve;
909             normalize nodelta >lookup_add_miss
910             [1,3: >EQbv_ptr2 >m_return_bind
911             |*: % #ABS destruct(ABS)
912                lapply(fresh_regs (point_of_pc ERTL_semantics (pc … st2)))
913                >EQregisters whd in ⊢ (% → ?); *** #ABS #_ #_ @ABS
914                lapply(regs_are_in_univers … (pi2 ?? fn) … EQstmt) whd in match stmt_registers;
915                whd in match get_used_registers_from_step; normalize nodelta
916                whd in ⊢ (???% → ?); * // #_ * //
917             ]
918         ]
919         >EQptr >m_return_bind @if_elim [2,4,6,8: >ptr_ok *] #_ >m_return_bind
920         >EQptr_code >m_return_bind
921       ]
922       @('bind_inversion EQt_fn1) * #f2 * #fn2 #EQfn2 normalize nodelta
923       whd in ⊢ (??%% → ?); #EQ destruct(EQ) >EQfn2 >m_return_bind normalize nodelta
924       [   change with (ertlptr_save_frame ? it ?) in match (save_frame ??????);
925           cut(st2 = mk_state_pc ? st2 (pc … st2) (last_pop … st2))
926           [ cases st2 #H1 #H2 #H3 %] #EQ <EQ -EQ >EQst_no_pc_after_call
927           >m_return_bind
928       |*: change with (ertlptr_save_frame PTR it ?) in match (save_frame ??????);
929           @('bind_inversion EQst_no_pc_after_call) #st4 whd in ⊢ (??%% → ?);
930           #EQ destruct(EQ) #H @('bind_inversion H) -H #frms4 #H
931           lapply(opt_eq_from_res ???? H) -H #EQfrms4 whd in ⊢ (??%% → ?);
932           #EQ destruct(EQ) whd in match ertlptr_save_frame; normalize nodelta
933           >m_return_bind whd in EQrest : (???%); destruct(EQrest) >EQfrms4
934           >m_return_bind
935       ]
936       change with (stack_size ?) in match (stack_sizes ????); >EQs_size
937       >m_return_bind %
938]
939qed.
940         
941
942inductive ex_Type1 (A:Type[1]) (P:A → Prop) : Prop ≝
943    ex1_intro: ∀ x:A. P x →  ex_Type1 A P.
944(*interpretation "exists in Type[1]" 'exists x = (ex_Type1 ? x).*)
945
946lemma ertl_to_ertlptr_ok:
947∀prog.∀stack_sizes.
948let trans_prog ≝ ertl_to_ertlptr prog in
949   ex_Type1 … (λR.
950   status_simulation
951    (ERTL_status prog stack_sizes) (ERTLptr_status trans_prog stack_sizes) R).
952#prog #stack_size
953cases(make_b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
954          (λglobals,fn.«translate_data globals fn,(refl …)») prog)
955#fregs * #f_lbls * #f_bl_r #good %
956[@ERTLptrStatusSimulation assumption]
957whd in match status_simulation; normalize nodelta
958whd in match ERTL_status; whd in match ERTLptr_status; normalize nodelta
959whd in ⊢ (% → % → % → % → ?); #st1 #st1' #st2
960change with
961  (eval_state ERTL_semantics (prog_var_names ???) ?? = ? → ?) 
962#EQeval @('bind_inversion EQeval)
963** #id #fn #stmt #H lapply (err_eq_from_io ????? H) -H #EQfetch
964#_  whd in match ERTLptrStatusSimulation; normalize nodelta #EQst2 destruct
965cases stmt in EQfetch; -stmt
966[ * [ #cost | #called_id #args #dest| #reg #lbl | #seq] #nxt | #fin_step | *]
967#EQfetch
968change with (joint_classify ??) in
969                     ⊢ (match % with [ _ ⇒ ? | _ ⇒ ? | _ ⇒ ? | _ ⇒ ? | _ ⇒ ? ]);
970[ (*COST*) whd in match joint_classify; normalize nodelta >EQfetch normalize nodelta
971  cases(eval_cost_ok … good … EQfetch EQeval) #st2' * #EQst2' * #taf #tafne
972  %{st2'} %{taf} >tafne normalize nodelta % [ % [@I | assumption]]
973  whd >EQst2' >(as_label_ok … good … st2') [%] cases daemon (* needs lemma see below!! *)
974| (*CALL*)  whd in match joint_classify; normalize nodelta >EQfetch
975          normalize nodelta #is_call_st1
976          cases(eval_call_ok … good … EQfetch EQeval) #is_call_st1'
977          * #st2_pre_call * #is_call_st2_pre_call * * #Hcall
978          #call_rel * #taa * #st2' * #sem_rel #eval_rel
979          %{(«st2_pre_call,is_call_st2_pre_call»)} % [ % assumption]
980          %{st2'} %{st2'} %{taa} %{(taa_base …)} % [ % assumption]
981          whd >sem_rel >(as_label_ok … good … st2') [%] cases daemon (*TODO*)
982| (*COND*) whd in match joint_classify; normalize nodelta >EQfetch
983          normalize nodelta #n_costed
984          cases(eval_cond_ok … good … EQfetch EQeval) [2: @n_costed]
985          #st2' * #EQst2' * #taf #tafne %{st2'} %{taf} >tafne % [% [@I|assumption]]
986          whd >EQst2' >(as_label_ok … good … st2') [%] cases daemon (*TODO*)
987| (*seq*) whd in match joint_classify; normalize nodelta >EQfetch
988          normalize nodelta
989          cases (eval_seq_no_call_ok … good … EQfetch EQeval)
990          #st3 * #EQ destruct *  #taf #taf_spec %{st3} %{taf} 
991          % [% //] whd >(as_label_ok … good … st3) [%]
992          cases daemon (*needs lemma about preservation of fetch_statement *)
993|  cases fin_step in EQfetch;
994  [ (*GOTO*) #lbl #EQfetch  whd in match joint_classify; normalize nodelta
995     >EQfetch normalize nodelta
996    cases (eval_goto_ok … good  … EQfetch EQeval)
997    #st3 * #EQ destruct * #taf #tarne %{st3} %{taf} >tarne normalize nodelta
998    % [% //] whd >(as_label_ok … good … st3) [%]
999    cases daemon (*needs lemma about preservation of fetch_statement *)
1000  | (*RETURN*) #EQfetch
1001     whd in match joint_classify; normalize nodelta
1002    >EQfetch  normalize nodelta
1003    cases (eval_return_ok … good … EQfetch EQeval) #is_ret
1004    * #st3 * #EQ destruct * #after_ret * #taf ** #taf_prf #EQeval' #ret_prf
1005    % [2: % [2: % [2: %{(taa_base …)} %{taf}] |*: ] |*:]
1006    % [2: whd >(as_label_ok … good … st3) [%] cases daemon (*needs lemma *)]
1007    % [2: assumption] % [2: %] % [2: assumption] % assumption
1008  | (*TAILCALL*) *
1009  ]
1010]
1011qed.
1012
1013(*
1014lemma foo :
1015 ∀P1_unser,P2_unser: unserialized_params.
1016 ∀P1_sem_unser,P2_sem_unser.
1017 let P1_sem ≝ make_sem_graph_params P1_unser P1_sem_unser in
1018 let P2_sem ≝ make_sem_graph_params P2_unser P2_sem_unser in
1019 ∀init,translate_step.
1020 ∀translate_fin_step.
1021 ∀closed_graph_translate.
1022 let translate_internal :
1023  ∀globals.
1024   joint_closed_internal_function P1_sem globals →
1025   joint_closed_internal_function P2_sem globals
1026  ≝
1027  λglobals,fun.
1028   «b_graph_translate (mk_graph_params P1_sem) (mk_graph_params P2_sem) globals
1029    (init globals)
1030    (translate_step globals)
1031    (translate_fin_step globals)
1032    (pi1 … fun), closed_graph_translate globals fun» in
1033 ∀prog.
1034 let trans_prog ≝ transform_program ??? prog (λvarnames. transf_fundef ?? (translate_internal varnames)) in
1035 ∀stack_size.
1036 ∀sigma_state_pc.
1037 (∀s. pc_block (pc … (sigma_state_pc s)) = pc_block … (pc … s)) →
1038 ∀st : state_pc P2_sem.
1039 ∀st' : state_pc P1_sem.
1040 ∀f.
1041 ∀fn: joint_closed_internal_function P1_sem (globals (mk_prog_params P1_sem prog stack_size)).
1042 luniverse_ok … fn →
1043 ∀stmt,nxt.
1044 ∀P : (state_pc P2_sem) → Prop.
1045 (∀pre_Instrs',last_Instrs',dst.
1046   ∃st''.∃st'''.∃st''''.
1047    repeat_eval_seq_no_pc (mk_prog_params P2_sem trans_prog stack_size)
1048     f (translate_internal ? fn) (map_eval ?? pre_Instrs' dst) st = return st''' ∧
1049    eval_seq_no_pc ? (prog_var_names … trans_prog) (ev_genv … (mk_prog_params P2_sem trans_prog stack_size))
1050                      f (translate_internal … fn) (last_Instrs' dst) st''' = return st'''' ∧
1051    st'' = (mk_state_pc (mk_prog_params P2_sem trans_prog stack_size)
1052     st'''' (pc_of_point P2_sem (pc_block (pc … (sigma_state_pc st))) dst) (last_pop … st)) ∧
1053    P st'' (*st' = sigma_state_pc st''*) ∧
1054    let P2_prog_params ≝ mk_prog_params P2_sem trans_prog stack_size in
1055    let P2_globals ≝ globals P2_prog_params in
1056     All
1057      (joint_seq … P2_globals)
1058      (no_cost_label … P2_globals)
1059      (map_eval (code_point P2_sem) (joint_seq … P2_globals) pre_Instrs' dst)) →
1060 fetch_statement …
1061  (prog_var_names (joint_function P1_sem) ℕ prog)
1062  (ev_genv (mk_prog_params P1_sem prog stack_size))
1063  (pc … (sigma_state_pc st)) =
1064    return 〈f, fn,  sequential … (step_seq P1_sem … stmt) nxt〉 →
1065 eval_state …
1066 (prog_var_names (joint_function P1_sem) ℕ prog)
1067 (ev_genv … (mk_prog_params P1_sem prog stack_size))
1068 (sigma_state_pc st) = return st' →
1069 ∃st''. (*CSC: this needs to be linked back again st' = sigma_state_pc ? good st'' ∧*)
1070 P st'' ∧
1071 ∃taf : trace_any_any_free (joint_abstract_status (mk_prog_params P2_sem trans_prog stack_size)) st st''.
1072(if taaf_non_empty … taf then True else
1073(¬as_costed (joint_abstract_status (mk_prog_params P1_sem prog stack_size)) (sigma_state_pc st) ∨
1074 ¬as_costed (joint_abstract_status (mk_prog_params P1_sem prog stack_size)) st'))
1075 (* the length of taf is the same of the length of ??? *).
1076#P1_unser #P2_unser #P1_sem_unser #P2_sem_unser
1077letin P1_sem ≝ (make_sem_graph_params P1_unser P1_sem_unser)
1078letin P2_sem ≝ (make_sem_graph_params P2_unser P2_sem_unser)
1079#init #translate_step #translate_fin_step #closed_graph_translate.
1080letin translate_internal ≝
1081 (λglobals,fun.
1082   «b_graph_translate (mk_graph_params P1_sem) (mk_graph_params P2_sem) globals
1083    (init globals)
1084    (translate_step globals)
1085    (translate_fin_step globals)
1086    (pi1 … fun), closed_graph_translate globals fun»)
1087#prog
1088letin trans_prog ≝ (transform_program ??? prog (λvarnames. transf_fundef ?? (translate_internal varnames)))
1089#stack_size #sigma_state_pc #sigma_state_pc_ok #st #st' #f #fn #fn_universe_ok #stmt #nxt #P
1090#Hpass #EQfetch lapply(fetch_statement_inv … EQfetch) * #EQfn #EQstmt
1091cases
1092 (b_graph_translate_ok … (init …) (translate_step …) (translate_fin_step …) … fn_universe_ok)
1093#_ * #MK_fresh_labels * #MK_fresh_registers **** #_ #_ #_ #_ (*CSC: useful things thrown out here *)
1094#MULTI_FETCH_OK cases (MULTI_FETCH_OK … EQstmt)
1095#list_b_last * #fresh_registers ** #EQlist_b_last #EQfresh_registers
1096normalize nodelta * #Instrs * #fresh_registers_spec whd in ⊢ (% → ?);
1097@pair_elim #pre_Instrs #last_Instrs #EQInstrs * #dst * #Multi_fetch #STEP_in_code
1098#EQeval
1099cut((list
1100   (code_point P2_sem
1101    →joint_seq P2_sem (prog_var_names (joint_function P1_sem) ℕ prog)))) [ cases daemon (*Paolo should fix the lemma*)]
1102#pre_Instrs'
1103cut((code_point P2_sem
1104   →joint_seq P2_sem (prog_var_names (joint_function P1_sem) ℕ prog))) [ cases daemon (*Paolo should fix the lemma*)]
1105#last_Instrs'
1106cases (Hpass pre_Instrs' last_Instrs' dst (* MANY MORE HERE *))
1107#st'' * #st''' * #st'''' **** #REPEAT #EVAL_NO_PC_Last #EQst'' #EQst' #NO_COSTED
1108lapply(produce_trace_any_any_free … NO_COSTED … REPEAT)
1109[ cases daemon (* should be @Multi_fetch *)
1110| <sigma_state_pc_ok @(fetch_internal_function_transf … (λvars.translate_internal vars))
1111  assumption
1112| @dst
1113| @list_b_last (*wrong, should dst be destination or the last of list_b_last *)
1114] #TAAF
1115lapply
1116  (produce_step_trace (mk_prog_params P2_sem trans_prog stack_size)
1117    (mk_state_pc (mk_prog_params P2_sem trans_prog stack_size)
1118       st''' (pc_of_point P2_sem (pc_block (pc … st)) dst) (last_pop … st))
1119    f (translate_internal ? fn) (last_Instrs' dst) nxt st'''' … EVAL_NO_PC_Last)
1120[ cases daemon (* should be @STEP_In_code *)
1121| <sigma_state_pc_ok
1122  @(fetch_internal_function_transf … (λvars. translate_internal vars) … EQfn) ]
1123#LAST_STEP
1124cases daemon
1125qed.
1126
1127lemma eval_seq_no_call_ok :
1128 ∀prog.
1129 let trans_prog ≝ ertl_to_ertlptr prog in
1130 ∀good : (∀fn.good_state_transformation prog fn).     
1131 ∀stack_sizes.
1132 (*? →*)
1133 ∀st : state_pc ERTLptr_semantics.
1134 ∀st' : state_pc ERTL_semantics.
1135 ∀f,fn,stmt,nxt.
1136   fetch_statement ERTL_semantics
1137     (prog_var_names (joint_function ERTL_semantics) ℕ prog)
1138    (ev_genv (mk_prog_params ERTL_semantics prog stack_sizes))
1139    (pc … (sigma_state_pc ? good st)) =
1140      return 〈f, fn,  sequential … (step_seq ERTL … stmt) nxt〉 →
1141   eval_state ERTL_semantics
1142   (prog_var_names (joint_function ERTL_semantics) ℕ prog)
1143   (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes))
1144   (sigma_state_pc ? good st) =
1145    return st' →
1146 ∃st''. st' = sigma_state_pc ? good st'' ∧
1147 ∃taf : trace_any_any_free (ERTLptr_status trans_prog stack_sizes)
1148  st
1149  st''.
1150 bool_to_Prop (taaf_non_empty … taf).
1151#prog #good #stack_size #st #st' #f #fn #stmt #nxt #EQfetch #EQeval
1152cases (foo … translate_step translate_fin_step … EQfetch EQeval)
1153[2,3: cases daemon (* first one, take out init definition from ERTLtoERTLptr;
1154                      second one to be taken from somewhere *)
1155|4: #x cases daemon (* TO BE DONE, EASY *)
1156|5: cases daemon (* to be taken in input *)
1157|6: @(λst''.st' = sigma_state_pc ? good st'')
1158|7: cases daemon
1159| #st'' * #EQ destruct * change with ERTL_uns in match (mk_unserialized_params ???????????????);
1160  change with ERTLptr_uns in match (mk_unserialized_params ???????????????);
1161  (* change with ERTL_semantics in match (make_sem_graph_params ??);
1162  change with ERTLptr_semantics in match (make_sem_graph_params ??); *)
1163#taaf #Htaaf %{st''}
1164 % [%] cases daemon
1165 qed. *)
Note: See TracBrowser for help on using the repository browser.