source: LTS/frame_variable_pass.ma @ 3575

Last change on this file since 3575 was 3575, checked in by piccolo, 4 years ago
File size: 10.0 KB
Line 
1(**************************************************************************)
2(*       ___                                                              *)
3(*      ||M||                                                             *)
4(*      ||A||       A project by Andrea Asperti                           *)
5(*      ||T||                                                             *)
6(*      ||I||       Developers:                                           *)
7(*      ||T||         The HELM team.                                      *)
8(*      ||A||         http://helm.cs.unibo.it                             *)
9(*      \   /                                                             *)
10(*       \ /        This file is distributed under the terms of the       *)
11(*        v         GNU General Public License Version 2                  *)
12(*                                                                        *)
13(**************************************************************************)
14
15include "Simulation.ma".
16include "variable.ma".
17include alias "arithmetics/nat.ma".
18
19definition update_fun : ∀A : DeqSet.∀B : Type[0].(A → B) → A → B → A → B ≝
20λA,B,f,a,b,x.if x == a then b else f x.
21
22let rec map_exp (e : expr) (map : variable → variable) on e : expr ≝
23match e with
24[ Var v ⇒ Var (map v)
25| Const n ⇒ Const n
26| Plus e1 e2 ⇒ Plus (map_exp e1 map) (map_exp e2 map)
27| Minus e1 e2 ⇒ Minus (map_exp e1 map) (map_exp e2 map)
28].
29
30let rec map_cond (c : condition) (map : variable → variable) on c : condition ≝
31match c with
32[Eq e1 e2 ⇒ Eq (map_exp e1 map) (map_exp e2 map)
33| Not c1 ⇒ Not (map_cond c1 map)
34].
35
36definition map_seq ≝
37 λi,map.
38  match i with
39  [ sAss v e ⇒ Seq_i (sAss (map v) (map_exp e map))
40  ].
41
42let rec trans_imp_instr (i : imp_Instructions) (map : variable → variable) on i : frame_Instructions  ≝
43match i with
44[ EMPTY ⇒ EMPTY …
45| RETURN rt ⇒ RETURN … rt
46| SEQ seq opt_l i ⇒ SEQ … (map_seq seq map) opt_l (trans_imp_instr i map)
47| COND cond ltrue i_true lfalse i_false instr ⇒
48    COND frame_state_params flat_labels (map_cond cond map) ltrue (trans_imp_instr i_true map) lfalse (trans_imp_instr i_false map)
49           (trans_imp_instr instr map)
50| LOOP cond ltrue i_true lfalse instr ⇒
51    LOOP frame_state_params flat_labels (map_cond cond map) ltrue (trans_imp_instr i_true map) lfalse 
52           (trans_imp_instr instr map)
53| CALL f act_p opt_l instr ⇒
54    (CALL frame_state_params flat_labels f (map_exp (\snd act_p) map) opt_l
55      (SEQ … (PopReg (\fst act_p)) (None …) (trans_imp_instr instr map)))
56| IO lin io lout instr ⇒ ?
57].
58cases io qed.
59
60
61let rec All2 (A,B : Type[0]) (f : A → B → Prop) (l1 : list A) (l2 : list B) on l1 : Prop ≝
62match l1 with
63[ nil ⇒ match l2 with [nil ⇒ True | cons _ _ ⇒ False]
64| cons x xs ⇒ match l2 with [nil ⇒ False | cons y ys ⇒ f x y ∧ All2 … f xs ys]
65].
66
67definition environment_rel : (variable → variable) → environment → activation_frame → Prop ≝
68λmap,st1,st2.
69 All … (λx.let 〈v,val〉 ≝ x in read_frame … st2 (to_shift + (map v)) O = return val)
70  st1.
71
72definition store_rel : (variable → variable) → store_t → frame_store_t → Prop ≝
73λmap,st1,st2.
74All2 ?? (λel1,el2.environment_rel map (\fst el1) el2)
75 st1 (\fst st2) ∧ \snd st2 = 〈O,O〉.
76
77lemma store_rel_inv:
78 ∀m,env,var,l,st.
79  store_rel m (〈env,var〉::l) st →
80   ∃hd,tl,fpsp.
81    st = 〈hd::tl,fpsp〉 ∧
82     store_rel m l 〈tl,fpsp〉 ∧
83      environment_rel m env hd.
84 #m #env #var #l * #xx #fpsp * whd in ⊢ (% → ?); cases xx [*] normalize nodelta
85 #frame #frames * #Rel1 #ALL #EQ destruct (skip fpsp)
86 %{frame} %{frames} %{fpsp} % // % // % //
87qed.
88
89definition trans_imp_prog : (variable → variable) → Program imp_env_params imp_instr_params flat_labels →
90Program frame_env_params frame_instr_params flat_labels ≝ λmap,prog.
91mk_Program ???
92(foldr …
93   (λx,tail.(mk_env_item …
94               (mk_signature frame_env_params … (f_name … (f_sig … x)) it ?(*(f_ret …(f_sig … x))*))
95               (f_lab … x) (trans_imp_instr (f_body ? imp_instr_params ? x) map)) :: tail) (nil ?) (env … prog))
96(trans_imp_instr (main … prog) map).
97@(f_ret … (f_sig … x))
98qed.
99
100definition trans_imp_cont ≝
101 λmap,cont.
102  foldr … (λx:(ActionLabel flat_labels)×?.λrem.〈\fst x,(trans_imp_instr (\snd x) map)〉 :: rem) (nil ?) cont.
103
104definition imp_variable_pass_rel ≝ 
105λmap : variable → variable.
106λprog : Program imp_state_params imp_state_params imp_state_params.
107let t_prog ≝ trans_imp_prog map prog in
108mk_relations flat_labels (operational_semantics imp_state_params imp_sem_state_params prog)
109 (operational_semantics frame_state_params frame_sem_state_params t_prog)
110(λs1,s2.store_rel map (store … s1) (store … s2) ∧ code … s2 = trans_imp_instr (code … s1) map ∧ 
111cont … s2 = trans_imp_cont map (cont … s1))
112(λ_.λ_.True).
113
114lemma map_exp_ok:
115 ∀m: variable → variable.
116  ∀e: expr.
117  let e' ≝ map_exp e m in
118   ∀env: environment.
119    ∀env': activation_frame.
120     environment_rel m env env' →
121      ∀val.
122       sem_expr env e = Some … val →
123        frame_sem_expr env' e' = Some … val.
124 #m #e elim e
125 [ #v #env elim env
126   [ #env' #_ #val #abs normalize in abs; destruct
127   | * #var #val #tl #IH #env' * #RF #Htl #val'
128     whd in ⊢ (??%? → ?); inversion (?==?) #Hv_var normalize nodelta
129     [ #Hval_val' destruct >(\P Hv_var) assumption
130     | #Hread_tl @IH // assumption ]]
131 | normalize //
132 |*: #e1 #e2 #IH1 #IH2 #env #env' #Rel #v
133   change with (m_bind ?????) in match (sem_expr ??);
134   #H cases (bind_inversion ????? H) -H #v1 * #He1
135   #H cases (bind_inversion ????? H) -H #v2 * #He2
136   #H normalize in H; destruct
137   change with (m_bind ?????) in ⊢ (??%?);
138   >(IH1 … He1) // >(IH2 … He2) // ]
139qed.
140
141lemma map_cond_ok:
142 ∀m: variable → variable.
143  ∀e: condition.
144  let e' ≝ map_cond e m in
145   ∀env: environment.
146    ∀env': activation_frame.
147     environment_rel m env env' →
148      ∀val.
149       sem_condition env e = Some … val →
150        frame_sem_condition env' e' = Some … val.
151 #m #e elim e
152 [ #e1 #e2 #env #env' #Rel #v
153   change with (m_bind ?????) in ⊢ (??%? → ?);
154   #H cases (bind_inversion ????? H) -H #v1 * #He1
155   #H cases (bind_inversion ????? H) -H #v2 * #He2
156   #H normalize in H; destruct
157   change with (m_bind ?????) in ⊢ (??%?);
158   >(map_exp_ok … He1) // >(map_exp_ok … He2) //
159 | #c #IH #env #env' #Rel #v
160   change with (m_bind ?????) in ⊢ (??%? → ?);
161   #H cases (bind_inversion ????? H) -H #v' * #Hv'
162   #H normalize in H; destruct
163   change with (m_bind ?????) in ⊢ (??%?);
164   >(IH … Hv') // ]
165qed.
166
167lemma map_assign_ok:
168 ∀m,env,frame,v,val,env'.
169  environment_rel m env frame →
170   assign_frame frame (to_shift + m v) 0 val = return env' →
171   environment_rel m (assign env v val) env'.
172 #m #env #frame #v #val
173 elim env
174 [ #env' #_ #H % // @(read_frame_assign_frame_hit … H)
175 | * #v' #val' #frames #IH #env' * #Hread #Hall
176   change with (environment_rel ???) in Hall;
177   whd in match (assign ???);
178   inversion (v==v') normalize nodelta
179   [2: #Ineq #H %
180      [ <Hread @(read_frame_assign_frame_miss … H)
181        [ cases daemon
182        | cases daemon
183        | @(not_to_not ??? (\Pf Ineq)) -Ineq #H
184          cases daemon (* MANCA INIETTIVITA' DELLA M *)
185        ]
186      | @IH // ]
187   | #EQ #H %
188     [ @(read_frame_assign_frame_hit … H)
189     |change with (environment_rel ???)
190      cases daemon (* NOT IMPLIED BY Hall BECAUSE OF DUPLICATES :-( *)]]]
191qed.
192
193lemma map_assign_var_ok:
194 ∀m,env,var,tl,v,val,frame,frames,st2,fpsp.
195 store_rel m tl 〈frames,fpsp〉 →
196 environment_rel m env frame →
197  assign_var (〈env,var〉::tl) v val = Some … st2 →
198   ∃st2'.
199    frame_assign_var 〈frame::frames,fpsp〉 (m v) val = Some … st2' ∧
200     store_rel m st2 st2'.
201     cases daemon (* si è rotto!!!
202 #m #env #var #tl #v #val #frame #frames #st2 #fpsp #Rel1 #Rel2
203 whd in ⊢ (??%? → ?); #EQ destruct
204 whd in match frame_assign_var; normalize nodelta % [2: % [%] | skip]
205 cases Rel1 -Rel1 #Rel3 #Rel4 destruct % // whd /6/ *)
206qed.
207
208lemma map_seq_ok:
209 ∀m: variable → variable.
210  ∀e:seq_i.
211  let e' ≝ map_seq e m in
212   ∀st1.
213    ∀st1'.
214     store_rel m st1 st1' →
215      ∀st2.
216       imp_eval_seq e st1 = Some … st2 →
217        ∃st2'.
218         frame_eval_seq e' st1' = Some … st2' ∧
219          store_rel m st2 st2'.
220 #m * [2: #v #expr] #st1 * #st1' * #fp #sp #Rel #st2
221 whd in match imp_eval_seq; normalize nodelta
222 [2: #EQ destruct /3/
223 | cases st1 in Rel; normalize nodelta [ #_ #abs destruct ]
224   * #env #var #tl #Rel
225   cases (store_rel_inv … Rel) -Rel #frame * #frames * #fpsp ** #EQ destruct
226   #Rel1 #Rel2 normalize nodelta #H cases (bind_inversion ????? H) -H #val *
227   #Hval #H whd in match (frame_eval_seq ??); >(map_exp_ok … Rel2 … Hval)
228   normalize nodelta cases (map_assign_var_ok … Rel1 Rel2 … H) #st2' *
229   #H1 #H2 %{st2'} % // assumption ]
230qed.
231
232definition simulation_imp_frame ≝
233λprog : Program imp_state_params imp_state_params imp_state_params.
234λmap : variable → variable.
235λprf : All … (λx.map (f_pars imp_state_params imp_state_params (f_sig … x)) = O) (env … prog).
236mk_simulation_conditions … (imp_variable_pass_rel map prog) ???????????.
237[ #s1 #s2 ** #H1 #H2 #H3 whd in match (as_initial ???); (*store iniziali in relazione*) cases daemon
238| cases daemon
239| cases daemon
240| #s1 #s2 #s1' #H inversion H
241  [ #s11 #s22 * #act #instr #cont #EQcode_s11 #EQcont_s11 #EQ #EQ1 destruct #EQstore #Hio1 #Hio2
242    #act_no_ret #EQ1 #EQ2 #EQ3 destruct #_ ** #Hstore #EQcode #EQcont #_ #_
243    %{(mk_state … (trans_imp_instr (code … s22) map)
244      (trans_imp_cont map (cont … s22)) (store … s2) (io_info … s22))}
245    %{(t_ind … (t_base …))}
246    [2: @(cost_act … (None ?))
247    | @hide_prf whd applyS(empty)
248      [9: >EQcode >EQcode_s11 %
249      |2: normalize % *
250      |3: %
251      |4: cases daemon (*da mettere a posto io *)
252    |5: % |6: % |7: % |8: >EQcont >EQcont_s11 % |*:]
253    | % [ % // % // ] %1 %2 [cases daemon] %1 cases daemon
254    ]
255  |*: cases daemon 
256  ]
257|*: cases daemon
258]
259qed.
Note: See TracBrowser for help on using the repository browser.