source: LTS/frame_variable_pass.ma @ 3568

Last change on this file since 3568 was 3568, checked in by sacerdot, 4 years ago

More progress.

File size: 9.8 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  [ sNop ⇒ Seq_i sNop
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
62let rec All2 (A,B : Type[0]) (f : A → B → Prop) (l1 : list A) (l2 : list B) on l1 : Prop ≝
63match l1 with
64[ nil ⇒ match l2 with [nil ⇒ True | cons _ _ ⇒ False]
65| cons x xs ⇒ match l2 with [nil ⇒ False | cons y ys ⇒ f x y ∧ All2 … f xs ys]
66].
67
68definition environment_rel : (variable → variable) → environment → activation_frame → Prop ≝
69λmap,st1,st2.
70 All … (λx.let 〈v,val〉 ≝ x in read_frame … st2 (to_shift + (map v)) O = return val)
71  st1.
72
73definition store_rel : (variable → variable) → store_t → frame_store_t → Prop ≝
74λmap,st1,st2.
75All2 ?? (λel1,el2.environment_rel map (\fst el1) el2)
76 st1 (\fst st2) ∧ \snd st2 = 〈O,O〉.
77
78lemma store_rel_inv:
79 ∀m,env,var,l,st.
80  store_rel m (〈env,var〉::l) st →
81   ∃hd,tl,fpsp.
82    st = 〈hd::tl,fpsp〉 ∧
83     store_rel m l 〈tl,fpsp〉 ∧
84      environment_rel m env hd.
85 #m #env #var #l * #xx #fpsp * whd in ⊢ (% → ?); cases xx [*] normalize nodelta
86 #frame #frames * #Rel1 #ALL #EQ destruct (skip fpsp)
87 %{frame} %{frames} %{fpsp} % // % // % //
88qed.
89
90definition trans_imp_prog : (variable → variable) → Program imp_env_params imp_instr_params flat_labels →
91Program frame_env_params frame_instr_params flat_labels ≝ λmap,prog.
92mk_Program ???
93(foldr …
94   (λx,tail.(mk_env_item …
95               (mk_signature frame_env_params … (f_name … (f_sig … x)) it ?(*(f_ret …(f_sig … x))*))
96               (f_lab … x) (trans_imp_instr (f_body ? imp_instr_params ? x) map)) :: tail) (nil ?) (env … prog))
97(trans_imp_instr (main … prog) map).
98@(f_ret … (f_sig … x))
99qed.
100
101definition trans_imp_cont ≝
102 λmap,cont.
103  foldr … (λx:(ActionLabel flat_labels)×?.λrem.〈\fst x,(trans_imp_instr (\snd x) map)〉 :: rem) (nil ?) cont.
104
105definition imp_variable_pass_rel ≝ 
106λmap : variable → variable.
107λprog : Program imp_state_params imp_state_params imp_state_params.
108let t_prog ≝ trans_imp_prog map prog in
109mk_relations flat_labels (operational_semantics imp_state_params imp_sem_state_params prog)
110 (operational_semantics frame_state_params frame_sem_state_params t_prog)
111(λs1,s2.store_rel map (store … s1) (store … s2) ∧ code … s2 = trans_imp_instr (code … s1) map ∧ 
112cont … s2 = trans_imp_cont map (cont … s1))
113(λ_.λ_.True).
114
115lemma map_exp_ok:
116 ∀m: variable → variable.
117  ∀e: expr.
118  let e' ≝ map_exp e m in
119   ∀env: environment.
120    ∀env': activation_frame.
121     environment_rel m env env' →
122      ∀val.
123       sem_expr env e = Some … val →
124        frame_sem_expr env' e' = Some … val.
125 #m #e elim e
126 [ #v #env elim env
127   [ #env' #_ #val #abs normalize in abs; destruct
128   | * #var #val #tl #IH #env' * #RF #Htl #val'
129     whd in ⊢ (??%? → ?); inversion (?==?) #Hv_var normalize nodelta
130     [ #Hval_val' destruct >(\P Hv_var) assumption
131     | #Hread_tl @IH // assumption ]]
132 | normalize //
133 |*: #e1 #e2 #IH1 #IH2 #env #env' #Rel #v
134   change with (m_bind ?????) in match (sem_expr ??);
135   #H cases (bind_inversion ????? H) -H #v1 * #He1
136   #H cases (bind_inversion ????? H) -H #v2 * #He2
137   #H normalize in H; destruct
138   change with (m_bind ?????) in ⊢ (??%?);
139   >(IH1 … He1) // >(IH2 … He2) // ]
140qed.
141
142lemma map_cond_ok:
143 ∀m: variable → variable.
144  ∀e: condition.
145  let e' ≝ map_cond e m in
146   ∀env: environment.
147    ∀env': activation_frame.
148     environment_rel m env env' →
149      ∀val.
150       sem_condition env e = Some … val →
151        frame_sem_condition env' e' = Some … val.
152 #m #e elim e
153 [ #e1 #e2 #env #env' #Rel #v
154   change with (m_bind ?????) in ⊢ (??%? → ?);
155   #H cases (bind_inversion ????? H) -H #v1 * #He1
156   #H cases (bind_inversion ????? H) -H #v2 * #He2
157   #H normalize in H; destruct
158   change with (m_bind ?????) in ⊢ (??%?);
159   >(map_exp_ok … He1) // >(map_exp_ok … He2) //
160 | #c #IH #env #env' #Rel #v
161   change with (m_bind ?????) in ⊢ (??%? → ?);
162   #H cases (bind_inversion ????? H) -H #v' * #Hv'
163   #H normalize in H; destruct
164   change with (m_bind ?????) in ⊢ (??%?);
165   >(IH … Hv') // ]
166qed.
167
168lemma map_assign_ok:
169 ∀m,env,frame,v,val.
170  environment_rel m env frame →
171   environment_rel m (assign env v val) (assign_frame frame (m v) 0 val).
172 #m #env #frame #v #val #Rel whd in match assign_frame; normalize nodelta
173 elim env in Rel;
174 [ * % // whd in ⊢ (??%?); cases daemon (* NTH-UPDATE *)
175 | * #v' #val' #frames #IH * #Hread #Hall change with (environment_rel ???) in Hall;
176   whd in match (assign ???);
177   inversion (v==v') normalize nodelta
178   [2: #Ineq % [ cases daemon (* NTH-UPDATE *) | @IH // ]
179   | #EQ % [ cases daemon (* NTH-UPDATE *)
180   |change with (environment_rel ???) cases daemon (* NOT IMPLIED BY Hall BECAUSE
181    OF DUPLICATES :-( *)]]]
182qed.
183
184lemma map_assign_var_ok:
185 ∀m,env,var,tl,v,val,frame,frames,st2,fpsp.
186 store_rel m tl 〈frames,fpsp〉 →
187 environment_rel m env frame →
188  assign_var (〈env,var〉::tl) v val = Some … st2 →
189   ∃st2'.
190    frame_assign_var 〈frame::frames,fpsp〉 (m v) val = Some … st2' ∧
191     store_rel m st2 st2'.
192 #m #env #var #tl #v #val #frame #frames #st2 #fpsp #Rel1 #Rel2
193 whd in ⊢ (??%? → ?); #EQ destruct
194 whd in match frame_assign_var; normalize nodelta % [2: % [%] | skip]
195 cases Rel1 -Rel1 #Rel3 #Rel4 destruct % // whd /6/
196qed.
197
198lemma map_seq_ok:
199 ∀m: variable → variable.
200  ∀e:seq_i.
201  let e' ≝ map_seq e m in
202   ∀st1.
203    ∀st1'.
204     store_rel m st1 st1' →
205      ∀st2.
206       imp_eval_seq e st1 = Some … st2 →
207        ∃st2'.
208         frame_eval_seq e' st1' = Some … st2' ∧
209          store_rel m st2 st2'.
210 #m * [2: #v #expr] #st1 * #st1' * #fp #sp #Rel #st2
211 whd in match imp_eval_seq; normalize nodelta
212 [2: #EQ destruct /3/
213 | cases st1 in Rel; normalize nodelta [ #_ #abs destruct ]
214   * #env #var #tl #Rel
215   cases (store_rel_inv … Rel) -Rel #frame * #frames * #fpsp ** #EQ destruct
216   #Rel1 #Rel2 normalize nodelta #H cases (bind_inversion ????? H) -H #val *
217   #Hval #H whd in match (frame_eval_seq ??); >(map_exp_ok … Rel2 … Hval)
218   normalize nodelta cases (map_assign_var_ok … Rel1 Rel2 … H) #st2' *
219   #H1 #H2 %{st2'} % // assumption ]
220qed.
221
222definition simulation_imp_frame ≝
223λprog : Program imp_state_params imp_state_params imp_state_params.
224λmap : variable → variable.
225λprf : All … (λx.map (f_pars imp_state_params imp_state_params (f_sig … x)) = O) (env … prog).
226mk_simulation_conditions … (imp_variable_pass_rel map prog) ???????????.
227[ #s1 #s2 ** #H1 #H2 #H3 whd in match (as_initial ???); (*store iniziali in relazione*) cases daemon
228| cases daemon
229| cases daemon
230| #s1 #s2 #s1' #H inversion H
231  [ #s11 #s22 * #act #instr #cont #EQcode_s11 #EQcont_s11 #EQ #EQ1 destruct #EQstore #Hio1 #Hio2
232    #act_no_ret #EQ1 #EQ2 #EQ3 destruct #_ ** #Hstore #EQcode #EQcont #_ #_
233    %{(mk_state … (trans_imp_instr (code … s22) map)
234      (trans_imp_cont map (cont … s22)) (store … s2) (io_info … s22))}
235    %{(t_ind … (t_base …))}
236    [2: @(cost_act … (None ?))
237    | @hide_prf whd applyS(empty)
238      [9: >EQcode >EQcode_s11 %
239      |2: normalize % *
240      |3: %
241      |4: cases daemon (*da mettere a posto io *)
242    |5: % |6: % |7: % |8: >EQcont >EQcont_s11 % |*:]
243    | % [ % // % // ] %1 %2 [cases daemon] %1 cases daemon
244    ]
245  |*: cases daemon 
246  ]
247|*: cases daemon
248]
249qed.
Note: See TracBrowser for help on using the repository browser.