source: src/ERTL/ERTLtoERTLptrOK.ma @ 2883

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

partial commit

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