include "Clight/Cexec.ma". include "Clight/label.ma". (* Formalise the notion of a trace with extra cost labels added. Note that we don't require the left trace to be cost free (we possibly should...). *) inductive trace_with_extra_labels : trace → trace → Prop ≝ | twel_0 : trace_with_extra_labels E0 E0 | twel_both : ∀h,t1,t2. trace_with_extra_labels t1 t2 → trace_with_extra_labels (h::t1) (h::t2) | twel_new : ∀c,t1,t2. trace_with_extra_labels t1 t2 → trace_with_extra_labels t1 (EVcost c::t2). (* A finite trace is produced by some prefix of an execution. *) inductive steps : trace → execution state io_out io_in → execution state io_out io_in → Prop ≝ | steps_stop : ∀tr,s,r. steps tr (e_stop … tr s r) (e_stop … tr s r) | steps_step : ∀tr,s,e. steps tr (e_step … tr s e) e | steps_steps : ∀tr,s,e,tr',e'. steps tr e e' → steps (tr'⧺tr) (e_step … tr' s e) e'. (* One execution is simulated by another, but possibly using more steps and introducing some cost labels. *) coinductive sim_with_labels : execution state io_out io_in → execution state io_out io_in → Prop ≝ | swl_stop : ∀tr1,tr2,tr2',r,s1,s2,e2. steps tr2 e2 (e_stop … tr2' r s2) → trace_with_extra_labels tr1 tr2 → sim_with_labels (e_stop … tr1 r s1) e2 | swl_steps : ∀tr1,tr2,s1,e1,e2,e2'. steps tr2 e2 e2' → trace_with_extra_labels tr1 tr2 → sim_with_labels e1 e2' → sim_with_labels (e_step … tr1 s1 e1) e2 | swl_interact : ∀o,k1,k2. (∀i. sim_with_labels (k1 i) (k2 i)) → sim_with_labels (e_interact … o k1) (e_interact … o k2). (* We do not consider wrong executions or I/O. *) coinductive not_wrong : execution state io_out io_in → Prop ≝ | nw_stop : ∀tr,i,s. not_wrong (e_stop … tr i s) | nw_step : ∀tr,s,e. not_wrong e → not_wrong (e_step … tr s e) | nw_interact : ∀o,k. (∀i. not_wrong (k i)) → not_wrong (e_interact … o k). (* Desired result *) definition labelled_exec_is_equiv : Prop ≝ ∀p:clight_program. let e1 ≝ exec_inf … clight_fullexec p in let e2 ≝ exec_inf … clight_fullexec (clight_label p) in not_wrong e1 → sim_with_labels e1 e2.