source: LTS/frame_variable_pass.ma @ 3580

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