Debian Codegraph @

src/AbstractInterpretation/Wf.v

raw
1 From Coq Require Import Lia.
2 From Coq Require Import ZArith.
3 From Coq Require Import Morphisms.
4 From Coq Require Import RelationPairs.
5 From Coq Require Import Relations.
6 Require Import Crypto.Util.ZRange.
7 Require Import Crypto.Util.Sum.
8 Require Import Crypto.Util.LetIn.
9 Require Import Crypto.Util.Prod.
10 Require Import Crypto.Util.Sigma.
11 Require Import Crypto.Util.Option.
12 Require Import Crypto.Util.ListUtil.
13 Require Import Crypto.Util.ListUtil.Forall.
14 Require Import Crypto.Util.NatUtil.
15 Require Import Crypto.Util.Bool.Reflect.
16 Require Import Crypto.Util.ZUtil.Tactics.LtbToLt.
17 Require Import Crypto.Util.Tactics.BreakMatch.
18 Require Import Crypto.Util.Tactics.DestructHead.
19 Require Import Crypto.Util.Tactics.SplitInContext.
20 Require Import Crypto.Util.Tactics.UniquePose.
21 Require Import Crypto.Util.Tactics.SpecializeBy.
22 Require Import Crypto.Util.Tactics.SpecializeAllWays.
23 Require Import Rewriter.Language.Language.
24 Require Import Rewriter.Language.Inversion.
25 Require Import Crypto.Language.InversionExtra.
26 Require Import Rewriter.Language.Wf.
27 Require Import Rewriter.Language.UnderLetsProofs.
28 Require Import Rewriter.Util.Decidable.
29 Require Import Crypto.AbstractInterpretation.AbstractInterpretation.
30 Require Import Crypto.AbstractInterpretation.ZRangeCommonProofs.
31 Import Coq.Lists.List.
32
33 Import EqNotations.
34 Module Compilers.
35 Import Language.Compilers.
36 Import UnderLets.Compilers.
37 Import AbstractInterpretation.Compilers.
38 Import AbstractInterpretation.ZRangeCommonProofs.Compilers.
39 Import Language.Inversion.Compilers.
40 Import Language.InversionExtra.Compilers.
41 Import Language.Wf.Compilers.
42 Import UnderLetsProofs.Compilers.
43 Import invert_expr.
44
45 Module Import partial.
46 Import AbstractInterpretation.Compilers.partial.
47 Import UnderLets.Compilers.UnderLets.
48 Section with_type.
49 Context {base_type : Type}.
50 Local Notation type := (type base_type).
51 Let type_base (x : base_type) : type := type.base x.
52 Local Coercion type_base : base_type >-> type.
53 Context {ident : type -> Type}.
54 Local Notation expr := (@expr base_type ident).
55 Local Notation Expr := (@expr.Expr base_type ident).
56 Local Notation UnderLets := (@UnderLets base_type ident).
57 Context (abstract_domain' : base_type -> Type)
58 (bottom' : forall A, abstract_domain' A)
59 (abstract_interp_ident : forall t, ident t -> type.interp abstract_domain' t)
60 (abstract_domain'_R : forall t, abstract_domain' t -> abstract_domain' t -> Prop)
61 {abstract_interp_ident_Proper : forall t, Proper (eq ==> abstract_domain'_R t) (abstract_interp_ident t)}
62 {bottom'_Proper : forall t, Proper (abstract_domain'_R t) (bottom' t)}.
63 Local Notation value var := (@value base_type ident var abstract_domain').
64 Local Notation abstract_domain := (@abstract_domain base_type abstract_domain').
65 Local Notation bottom := (@bottom base_type abstract_domain' (@bottom')).
66 Local Notation bottom_for_each_lhs_of_arrow := (@bottom_for_each_lhs_of_arrow base_type abstract_domain' (@bottom')).
67
68 Section with_var2.
69 Context {var1 var2 : type -> Type}.
70 Local Notation UnderLets1 := (@UnderLets.UnderLets base_type ident var1).
71 Local Notation UnderLets2 := (@UnderLets.UnderLets base_type ident var2).
72 Local Notation expr1 := (@expr.expr base_type ident var1).
73 Local Notation expr2 := (@expr.expr base_type ident var2).
74 Local Notation value1 := (@value var1).
75 Local Notation value2 := (@value var2).
76 Local Notation value_with_lets1 := (@value_with_lets base_type ident var1 abstract_domain').
77 Local Notation value_with_lets2 := (@value_with_lets base_type ident var2 abstract_domain').
78 Local Notation state_of_value1 := (@state_of_value base_type ident var1 abstract_domain' bottom').
79 Local Notation state_of_value2 := (@state_of_value base_type ident var2 abstract_domain' bottom').
80 Context (annotate1 : forall (is_let_bound : bool) t, abstract_domain' t -> @expr1 t -> UnderLets1 (@expr1 t))
81 (annotate2 : forall (is_let_bound : bool) t, abstract_domain' t -> @expr2 t -> UnderLets2 (@expr2 t))
82 (annotate_Proper
83 : forall is_let_bound t G
84 v1 v2 (Hv : abstract_domain'_R t v1 v2)
85 e1 e2 (He : expr.wf G e1 e2),
86 UnderLets.wf (fun G' => expr.wf G') G (annotate1 is_let_bound t v1 e1) (annotate2 is_let_bound t v2 e2))
87 (interp_ident1 : bool -> forall t, ident t -> value_with_lets1 t)
88 (interp_ident2 : bool -> forall t, ident t -> value_with_lets2 t)
89 (skip_annotations_under : forall t, ident t -> bool).
90 Local Notation reify1 := (@reify base_type ident var1 abstract_domain' annotate1 bottom').
91 Local Notation reify2 := (@reify base_type ident var2 abstract_domain' annotate2 bottom').
92 Local Notation reflect1 := (@reflect base_type ident var1 abstract_domain' annotate1 bottom').
93 Local Notation reflect2 := (@reflect base_type ident var2 abstract_domain' annotate2 bottom').
94 Local Notation bottomify1 := (@bottomify base_type ident var1 abstract_domain' bottom').
95 Local Notation bottomify2 := (@bottomify base_type ident var2 abstract_domain' bottom').
96 Local Notation interp1 := (@interp base_type ident var1 abstract_domain' annotate1 bottom' skip_annotations_under interp_ident1).
97 Local Notation interp2 := (@interp base_type ident var2 abstract_domain' annotate2 bottom' skip_annotations_under interp_ident2).
98 Local Notation eval_with_bound'1 := (@eval_with_bound' base_type ident var1 abstract_domain' annotate1 bottom' skip_annotations_under interp_ident1).
99 Local Notation eval_with_bound'2 := (@eval_with_bound' base_type ident var2 abstract_domain' annotate2 bottom' skip_annotations_under interp_ident2).
100 Local Notation eval'1 := (@eval' base_type ident var1 abstract_domain' annotate1 bottom' skip_annotations_under interp_ident1).
101 Local Notation eval'2 := (@eval' base_type ident var2 abstract_domain' annotate2 bottom' skip_annotations_under interp_ident2).
102 Local Notation eta_expand_with_bound'1 := (@eta_expand_with_bound' base_type ident var1 abstract_domain' annotate1 bottom').
103 Local Notation eta_expand_with_bound'2 := (@eta_expand_with_bound' base_type ident var2 abstract_domain' annotate2 bottom').
104
105 Definition abstract_domain_R {t} : relation (abstract_domain t)
106 := type.related abstract_domain'_R.
107
108 (** This one is tricky. Because we need to be stable under
109 weakening and reordering of the context, we permit any
110 context for well-formedness of the input in the arrow
111 case, and simply tack on that context at the beginning of
112 the output. This is sort-of wasteful on the output
113 context, but it's sufficient to prove
114 [wf_value_Proper_list] below, which is what we really
115 need. *)
116 Fixpoint wf_value G {t} : value1 t -> value2 t -> Prop
117 := match t return value1 t -> value2 t -> Prop with
118 | type.base t
119 => fun v1 v2
120 => abstract_domain_R (fst v1) (fst v2)
121 /\ expr.wf G (snd v1) (snd v2)
122 | type.arrow s d
123 => fun v1 v2
124 => forall seg G' sv1 sv2,
125 G' = (seg ++ G)%list
126 -> @wf_value seg s sv1 sv2
127 -> UnderLets.wf
128 (fun G' => @wf_value G' d) G'
129 (v1 sv1) (v2 sv2)
130 end.
131
132 Definition wf_value_with_lets G {t} : value_with_lets1 t -> value_with_lets2 t -> Prop
133 := UnderLets.wf (fun G' => wf_value G') G.
134
135 Context (interp_ident_Proper
136 : forall G t idc1 idc2 (Hidc : idc1 = idc2) annotate_with_state,
137 wf_value_with_lets G (interp_ident1 annotate_with_state t idc1) (interp_ident2 annotate_with_state t idc2)).
138
139 Global Instance bottom_Proper {t} : Proper abstract_domain_R (@bottom t) | 10.
140 Proof using bottom'_Proper.
141 clear -bottom'_Proper type_base.
142 cbv [Proper] in *; induction t; cbn; cbv [respectful]; eauto.
143 Qed.
144
145 Global Instance bottom_for_each_lhs_of_arrow_Proper {t}
146 : Proper (type.and_for_each_lhs_of_arrow (@abstract_domain_R)) (@bottom_for_each_lhs_of_arrow t) | 10.
147 Proof using bottom'_Proper.
148 clear -bottom'_Proper type_base.
149 pose proof (@bottom_Proper).
150 cbv [Proper] in *; induction t; cbn; cbv [respectful]; eauto.
151 Qed.
152
153 Lemma state_of_value_Proper G {t} v1 v2 (Hv : @wf_value G t v1 v2)
154 : abstract_domain_R (state_of_value1 v1) (state_of_value2 v2).
155 Proof using bottom'_Proper.
156 clear -Hv type_base bottom'_Proper.
157 destruct t; [ destruct v1, v2, Hv | ]; cbn in *; cbv [respectful]; eauto; intros; apply bottom_Proper.
158 Qed.
159
160 Local Definition ex_intro_nil A (P : list A -> Prop) := ex_intro P nil.
161 Local Definition ex_intro_singleton A (x : A) (P : list A -> Prop) := ex_intro P (cons x nil).
162 Local Hint Resolve ex_intro_nil ex_intro_singleton : core.
163 Local Hint Constructors expr.wf ex : core.
164 Local Hint Unfold List.In : core.
165
166 Lemma wf_value_Proper_list G1 G2
167 (HG1G2 : forall t v1 v2, List.In (existT _ t (v1, v2)) G1 -> List.In (existT _ t (v1, v2)) G2)
168 t e1 e2
169 (Hwf : @wf_value G1 t e1 e2)
170 : @wf_value G2 t e1 e2.
171 Proof using Type.
172 clear -type_base HG1G2 Hwf.
173 revert dependent G1; revert dependent G2; induction t; intros;
174 repeat first [ progress cbn in *
175 | progress intros
176 | solve [ eauto ]
177 | progress subst
178 | progress destruct_head'_and
179 | progress destruct_head'_or
180 | apply conj
181 | rewrite List.in_app_iff in *
182 | match goal with H : _ |- _ => apply H; clear H end
183 | wf_unsafe_t_step
184 | eapply UnderLets.wf_Proper_list; [ | | solve [ eauto ] ] ].
185 Qed.
186
187 Fixpoint wf_reify (annotate_with_state : bool) (is_let_bound : bool) G {t}
188 : forall v1 v2 (Hv : @wf_value G t v1 v2)
189 s1 s2 (Hs : type.and_for_each_lhs_of_arrow (@abstract_domain_R) s1 s2),
190 UnderLets.wf (fun G' => expr.wf G') G (@reify1 annotate_with_state is_let_bound t v1 s1) (@reify2 annotate_with_state is_let_bound t v2 s2)
191 with wf_reflect (annotate_with_state : bool) G {t}
192 : forall e1 e2 (He : expr.wf G e1 e2)
193 s1 s2 (Hs : abstract_domain_R s1 s2),
194 @wf_value G t (@reflect1 annotate_with_state t e1 s1) (@reflect2 annotate_with_state t e2 s2).
195 Proof using annotate_Proper bottom'_Proper.
196 all: clear -wf_reflect wf_reify annotate_Proper type_base bottom'_Proper.
197 all: pose proof (@bottom_for_each_lhs_of_arrow_Proper); cbv [Proper abstract_domain_R] in *.
198 all: destruct t as [t|s d];
199 [ clear wf_reify wf_reflect
200 | pose proof (fun G => wf_reflect annotate_with_state G s) as wf_reflect_s;
201 pose proof (fun G => wf_reflect annotate_with_state G d) as wf_reflect_d;
202 pose proof (fun G => wf_reify annotate_with_state false G s) as wf_reify_s;
203 pose proof (fun G => wf_reify annotate_with_state false G d) as wf_reify_d;
204 pose proof (@bottom_Proper s);
205 clear wf_reify wf_reflect ].
206 all: cbn [reify reflect] in *.
207 all: fold (@reify2) (@reflect2) (@reify1) (@reflect1).
208 all: cbn in *.
209 all: repeat first [ progress cbn [fst snd] in *
210 | progress cbv [respectful] in *
211 | progress intros
212 | progress subst
213 | progress destruct_head'_and
214 | progress destruct_head'_ex
215 | solve [ eauto | wf_t ]
216 | apply annotate_Proper
217 | apply UnderLets.wf_to_expr
218 | break_innermost_match_step
219 | match goal with
220 | [ |- UnderLets.wf _ _ _ _ ] => constructor
221 | [ |- expr.wf _ _ _ ] => constructor
222 | [ He : forall seg G' sv1 sv2, G' = (seg ++ ?G)%list -> _ |- UnderLets.wf _ (?v :: ?G) (UnderLets.splice _ _) (UnderLets.splice _ _) ]
223 => eapply UnderLets.wf_splice; [ apply (He (cons v nil)) | ]
224 | [ |- UnderLets.wf _ _ (UnderLets.splice (reify1 _ _ _ _) _) (UnderLets.splice (reify2 _ _ _ _) _) ]
225 => eapply UnderLets.wf_splice; [ apply wf_reify_s || apply wf_reify_d | ]
226 | [ |- wf_value _ (reflect1 _ _ _) (reflect2 _ _ _) ] => apply wf_reflect_s || apply wf_reflect_d
227 | [ H : wf_value _ ?x ?y |- wf_value _ ?x ?y ]
228 => eapply wf_value_Proper_list; [ | eassumption ]
229 | [ H : forall x y, ?R x y -> ?R' (?f x) (?g y) |- ?R' (?f _) (?g _) ]
230 => apply H
231 | [ |- ?R (state_of_value1 _) (state_of_value2 _) ] => eapply state_of_value_Proper
232 end ].
233 Qed.
234
235 Lemma wf_bottomify {t} G v1 v2
236 (Hwf : @wf_value G t v1 v2)
237 : wf_value_with_lets G (bottomify1 v1) (bottomify2 v2).
238 Proof using bottom'_Proper.
239 cbv [wf_value_with_lets] in *.
240 revert dependent G; induction t as [|s IHs d IHd]; intros;
241 cbn [bottomify wf_value]; fold (@value1) (@value2) in *; break_innermost_match;
242 constructor.
243 all: repeat first [ progress cbn [fst snd wf_value] in *
244 | progress destruct_head'_and
245 | assumption
246 | apply bottom'_Proper
247 | apply conj
248 | progress intros
249 | progress subst
250 | solve [ eapply UnderLets.wf_splice; eauto ] ].
251 Qed.
252
253 Local Ltac wf_interp_t :=
254 repeat first [ progress cbv [wf_value_with_lets abstract_domain_R respectful] in *
255 | progress cbn [wf_value fst snd partial.bottom type.related eq_rect List.In] in *
256 | wf_safe_t_step
257 | exact I
258 | apply wf_reify
259 | apply bottom_Proper
260 | progress destruct_head'_ex
261 | progress destruct_head'_or
262 | eapply UnderLets.wf_splice
263 | match goal with
264 | [ |- UnderLets.wf _ _ (bottomify1 _) (bottomify2 _) ] => apply wf_bottomify
265 | [ |- UnderLets.wf _ _ _ _ ] => constructor
266 | [ |- and _ _ ] => apply conj
267 end
268 | eapply wf_value_Proper_list; [ | solve [ eauto ] ]
269 | eapply UnderLets.wf_Proper_list; [ | | solve [ eauto ] ]
270 | match goal with
271 | [ H : _ |- _ ] => eapply H; clear H; solve [ wf_interp_t ]
272 end
273 | break_innermost_match_step ].
274
275 Local Notation skip_annotations_for_App := (@skip_annotations_for_App base_type ident skip_annotations_under).
276
277 Lemma wf_skip_annotations_for_App {var1' var2' G t e1 e2} (Hwf : expr.wf G (t:=t) e1 e2)
278 : @skip_annotations_for_App var1' t e1 = @skip_annotations_for_App var2' t e2.
279 Proof using Type.
280 cbv [skip_annotations_for_App]; break_innermost_match;
281 expr.invert_subst;
282 repeat first [ progress cbn [projT1 projT2 fst snd eq_rect invert_App_curried invert_Ident Option.bind] in *
283 | reflexivity
284 | exfalso; assumption
285 | progress inversion_option
286 | progress destruct_head'_sig
287 | progress destruct_head'_and
288 | progress expr.inversion_wf_constr
289 | progress subst
290 | match goal with
291 | [ H : expr.wf _ (App_curried _ _) _ |- _ ]
292 => apply expr.invert_wf_App_curried_or_eq_base in H;
293 [ | clear H .. ]
294 | [ |- _ \/ _ ] => right; split; intros; congruence
295 | [ Hwf : expr.wf _ (App_curried _ _) ?e, H' : invert_AppIdent_curried _ = None |- _ ]
296 => apply expr.wf_invert_AppIdent_curried in Hwf; rewrite H' in Hwf; cbv [invert_AppIdent_curried Option.option_eq] in Hwf
297 | [ Hwf : expr.wf _ ?e (App_curried _ _), H' : invert_AppIdent_curried _ = None |- _ ]
298 => apply expr.wf_invert_AppIdent_curried in Hwf; rewrite H' in Hwf; cbv [Option.option_eq invert_AppIdent_curried] in Hwf
299 | [ H : context[invert_App_curried (App_curried _ _)] |- _ ]
300 => rewrite expr.invert_App_curried_App_curried in Hwf
301 end ].
302 Qed.
303
304 Lemma wf_interp (annotate_with_state : bool) G G' {t} (e1 : @expr (@value_with_lets1) t) (e2 : @expr (@value_with_lets2) t)
305 (Hwf : expr.wf G e1 e2)
306 (HGG' : forall t v1 v2, List.In (existT _ t (v1, v2)) G -> wf_value_with_lets G' v1 v2)
307 : wf_value_with_lets G' (interp1 annotate_with_state e1) (interp2 annotate_with_state e2).
308 Proof using annotate_Proper bottom'_Proper interp_ident_Proper.
309 revert dependent G'; revert annotate_with_state; induction Hwf; intros; cbn [interp];
310 try solve [ apply interp_ident_Proper; auto
311 | eauto ];
312 match goal with
313 | [ G' : list _ |- context[skip_annotations_for_App ?e1v] ]
314 => match goal with
315 | [ |- context[skip_annotations_for_App ?e2v] ]
316 => epose proof (wf_skip_annotations_for_App (e1:=e1v) (e2:=e2v) (G:=G') ltac:(solve [ wf_t ]));
317 generalize dependent (skip_annotations_for_App e1v);
318 generalize dependent (skip_annotations_for_App e2v); intros;
319 subst
320 end
321 end;
322 wf_interp_t.
323 Qed.
324
325 Lemma wf_eval_with_bound' (annotate_with_state : bool) G G' {t} e1 e2 (He : expr.wf G e1 e2) st1 st2 (Hst : type.and_for_each_lhs_of_arrow (@abstract_domain_R) st1 st2)
326 (HGG' : forall t v1 v2, List.In (existT _ t (v1, v2)) G -> wf_value_with_lets G' v1 v2)
327 : expr.wf G' (@eval_with_bound'1 annotate_with_state t e1 st1) (@eval_with_bound'2 annotate_with_state t e2 st2).
328 Proof using annotate_Proper bottom'_Proper interp_ident_Proper.
329 eapply UnderLets.wf_to_expr, UnderLets.wf_splice.
330 { eapply wf_interp; solve [ eauto ]. }
331 { intros; destruct_head'_ex; subst; eapply wf_reify; eauto. }
332 Qed.
333
334 Lemma wf_eval' G G' {t} e1 e2 (He : expr.wf G e1 e2)
335 (HGG' : forall t v1 v2, List.In (existT _ t (v1, v2)) G -> wf_value_with_lets G' v1 v2)
336 : expr.wf G' (@eval'1 t e1) (@eval'2 t e2).
337 Proof using annotate_Proper bottom'_Proper interp_ident_Proper.
338 eapply wf_eval_with_bound'; eauto; apply bottom_for_each_lhs_of_arrow_Proper.
339 Qed.
340
341 Lemma wf_eta_expand_with_bound' G {t} e1 e2 (He : expr.wf G e1 e2) st1 st2 (Hst : type.and_for_each_lhs_of_arrow (@abstract_domain_R) st1 st2)
342 : expr.wf G (@eta_expand_with_bound'1 t e1 st1) (@eta_expand_with_bound'2 t e2 st2).
343 Proof using annotate_Proper bottom'_Proper.
344 eapply UnderLets.wf_to_expr, wf_reify; [ eapply wf_reflect | ]; eauto; apply bottom_Proper.
345 Qed.
346 End with_var2.
347 End with_type.
348
349 Module ident.
350 Import API.
351 Local Notation UnderLets := (@UnderLets base.type ident).
352 Section with_type.
353 Context (abstract_domain' : base.type -> Type).
354 Local Notation abstract_domain := (@abstract_domain base.type abstract_domain').
355 Context (bottom' : forall A, abstract_domain' A)
356 (abstract_interp_ident : forall t, ident t -> type.interp abstract_domain' t)
357 (extract_list_state : forall A, abstract_domain' (base.type.list A) -> option (list (abstract_domain' A)))
358 (extract_option_state : forall A, abstract_domain' (base.type.option A) -> option (option (abstract_domain' A))).
359 Context (abstract_domain'_R : forall t, abstract_domain' t -> abstract_domain' t -> Prop).
360 Local Notation abstract_domain_R := (@abstract_domain_R base.type abstract_domain' abstract_domain'_R).
361 Context {abstract_interp_ident_Proper : forall t, Proper (eq ==> @abstract_domain_R t) (abstract_interp_ident t)}
362 {bottom'_Proper : forall t, Proper (abstract_domain'_R t) (bottom' t)}
363 (extract_list_state_length : forall t v1 v2, abstract_domain'_R _ v1 v2 -> option_map (@length _) (extract_list_state t v1) = option_map (@length _) (extract_list_state t v2))
364 (extract_list_state_rel : forall t v1 v2, abstract_domain'_R _ v1 v2 -> forall l1 l2, extract_list_state t v1 = Some l1 -> extract_list_state t v2 = Some l2 -> List.Forall2 (@abstract_domain'_R t) l1 l2)
365 (extract_option_state_rel : forall t v1 v2, abstract_domain'_R _ v1 v2 -> option_eq (option_eq (abstract_domain'_R _)) (extract_option_state t v1) (extract_option_state t v2)).
366
367 Local Instance abstract_interp_ident_Proper_arrow s d
368 : Proper (eq ==> abstract_domain'_R s ==> abstract_domain'_R d) (abstract_interp_ident (type.arrow s d))
369 := abstract_interp_ident_Proper (type.arrow s d).
370
371 Local Ltac handle_Forall2_step :=
372 first [ match goal with
373 | [ |- List.Forall2 _ ?x ?x ] => rewrite Forall2_Forall; cbv [Proper]
374 | [ |- List.Forall2 _ (List.map _ _) (List.map _ _) ] => rewrite Forall2_map_map_iff
375 | [ |- List.Forall2 _ (List.combine _ _) (List.combine _ _) ]
376 => eapply Forall2_combine; [ intros | eassumption | eassumption ]
377 | [ |- List.Forall2 _ (List.combine ?x _) (List.combine ?x _) ]
378 => eapply Forall2_combine;
379 [ intros
380 | instantiate (1:=fun a b => a = b /\ List.In a x);
381 rewrite Forall2_Forall, Forall_forall; cbv [Proper]; auto
382 | eassumption ]
383 | [ H : expr.wf _ ?d1 ?d2, H' : List.Forall2 (expr.wf _) ?xs ?ys
384 |- expr.wf ?G (nth_default ?d1 ?xs ?n) (nth_default ?d2 ?ys ?n) ]
385 => cut (List.Forall2 (expr.wf G) xs ys /\ expr.wf G d1 d2);
386 [ rewrite Forall2_forall_iff'';
387 let H := fresh in intros [? H]; apply H
388 | ]
389 end ].
390
391
392 Section with_var2.
393 Context {var1 var2 : type -> Type}.
394 Local Notation wf_value_with_lets := (@wf_value_with_lets base.type ident abstract_domain' abstract_domain'_R var1 var2).
395 Local Notation wf_value := (@wf_value base.type ident abstract_domain' abstract_domain'_R var1 var2).
396 Context (annotate_expr1 : forall t, abstract_domain' t -> option (@expr var1 (t -> t)))
397 (annotate_expr2 : forall t, abstract_domain' t -> option (@expr var2 (t -> t)))
398 (is_annotated_for1 : forall t t', @expr var1 t -> abstract_domain' t' -> bool)
399 (is_annotated_for2 : forall t t', @expr var2 t -> abstract_domain' t' -> bool)
400 (strip_annotation1 : forall t, ident t -> option (value _ t))
401 (strip_annotation2 : forall t, ident t -> option (value _ t))
402 (annotation_to_cast1 : forall s d, @expr var1 (s -> d) -> option (@expr var1 s -> @expr var1 d))
403 (annotation_to_cast2 : forall s d, @expr var2 (s -> d) -> option (@expr var2 s -> @expr var2 d))
404 (skip_annotations_under : forall t, ident t -> bool)
405 {wf_annotation_to_cast
406 : forall s d G e1 e2,
407 expr.wf G e1 e2
408 -> option_eq (fun f g => forall e1 e2, expr.wf G e1 e2 -> expr.wf G (f e1) (g e2))
409 (annotation_to_cast1 s d e1)
410 (annotation_to_cast2 s d e2)}
411 {annotate_expr_Proper : forall t s1 s2,
412 abstract_domain'_R t s1 s2
413 -> option_eq (expr.wf nil) (annotate_expr1 t s1) (annotate_expr2 t s2)}
414 {is_annotated_for_Proper : forall G t t' e1 e2,
415 expr.wf G e1 e2
416 -> ((abstract_domain'_R _ ==> eq)%signature)
417 (@is_annotated_for1 t t' e1)
418 (@is_annotated_for2 t t' e2)}
419 {wf_strip_annotation
420 : forall G t idc,
421 option_eq (wf_value G)
422 (@strip_annotation1 t idc)
423 (@strip_annotation2 t idc)}.
424
425 Local Notation update_annotation1 := (@ident.update_annotation var1 abstract_domain' annotate_expr1 is_annotated_for1).
426 Local Notation update_annotation2 := (@ident.update_annotation var2 abstract_domain' annotate_expr2 is_annotated_for2).
427 Local Notation annotate1 := (@ident.annotate var1 abstract_domain' annotate_expr1 abstract_interp_ident extract_list_state extract_option_state is_annotated_for1).
428 Local Notation annotate2 := (@ident.annotate var2 abstract_domain' annotate_expr2 abstract_interp_ident extract_list_state extract_option_state is_annotated_for2).
429 Local Notation annotate_base1 := (@ident.annotate_base var1 abstract_domain' annotate_expr1 is_annotated_for1).
430 Local Notation annotate_base2 := (@ident.annotate_base var2 abstract_domain' annotate_expr2 is_annotated_for2).
431 Local Notation annotate_with_expr1 := (@ident.annotate_with_expr var1 abstract_domain' annotate_expr1 is_annotated_for1).
432 Local Notation annotate_with_expr2 := (@ident.annotate_with_expr var2 abstract_domain' annotate_expr2 is_annotated_for2).
433 Local Notation interp_ident1 := (@ident.interp_ident var1 abstract_domain' annotate_expr1 bottom' abstract_interp_ident extract_list_state extract_option_state is_annotated_for1 strip_annotation1).
434 Local Notation interp_ident2 := (@ident.interp_ident var2 abstract_domain' annotate_expr2 bottom' abstract_interp_ident extract_list_state extract_option_state is_annotated_for2 strip_annotation2).
435 Local Notation reflect1 := (@reflect base.type ident var1 abstract_domain' annotate1 bottom').
436 Local Notation reflect2 := (@reflect base.type ident var2 abstract_domain' annotate2 bottom').
437
438 Lemma wf_update_annotation G {t} st1 st2 (Hst : abstract_domain'_R t st1 st2) e1 e2 (He : expr.wf G e1 e2)
439 : expr.wf G (@update_annotation1 t st1 e1) (@update_annotation2 t st2 e2).
440 Proof using abstract_interp_ident_Proper annotate_expr_Proper is_annotated_for_Proper.
441 cbv [ident.update_annotation];
442 repeat first [ progress subst
443 | progress expr.invert_subst
444 | progress cbn [fst snd projT1 projT2 eq_rect] in *
445 | progress cbn [invert_AppIdent Option.bind invert_App invert_Ident] in *
446 | progress destruct_head'_sig
447 | progress destruct_head'_sigT
448 | progress destruct_head'_and
449 | progress destruct_head'_prod
450 | progress destruct_head' False
451 | progress inversion_option
452 | progress expr.inversion_wf_constr
453 | progress expr.inversion_wf_one_constr
454 | break_innermost_match_hyps_step
455 | expr.invert_match_step
456 | progress expr.inversion_expr
457 | progress rewrite_type_transport_correct
458 | progress type_beq_to_eq
459 | progress type.inversion_type
460 | progress base.type.inversion_type
461 | discriminate
462 | match goal with
463 | [ H : abstract_domain'_R _ ?x _ |- _ ] => rewrite !H
464 | [ H : abstract_domain'_R _ ?x _, H' : context[?x] |- _ ] => rewrite !H in H'
465 end
466 | progress wf_safe_t
467 | break_innermost_match_step
468 | solve [ wf_t ]
469 | match goal with
470 | [ H : abstract_domain'_R _ ?x ?y, H1 : annotate_expr1 _ ?x = _, H2 : annotate_expr2 _ ?y = _ |- _ ]
471 => let H' := fresh in
472 pose proof (annotate_expr_Proper _ _ _ H) as H';
473 rewrite H1, H2 in H'; clear H1 H2; cbv [option_eq] in H'
474 | [ H1 : is_annotated_for1 _ _ ?e1 ?s1 = _,
475 H2 : is_annotated_for2 _ _ ?e2 ?s2 = _ ,
476 Hwf : expr.wf _ ?e1 ?e2,
477 Hrel : abstract_domain'_R _ ?s1 ?s2 |- _ ]
478 => let H' := fresh in
479 pose proof (is_annotated_for_Proper _ _ _ _ _ Hwf _ _ Hrel) as H';
480 rewrite H1, H2 in H'; clear H1 H2
481 end ].
482 Qed.
483
484 Lemma wf_annotate_with_expr
485 is_let_bound t G
486 v1 v2 (Hv : abstract_domain'_R t v1 v2)
487 e1 e2 (He : expr.wf G e1 e2)
488 : UnderLets.wf (fun G' => expr.wf G') G (@annotate_with_expr1 is_let_bound t v1 e1) (@annotate_with_expr2 is_let_bound t v2 e2).
489 Proof using abstract_interp_ident_Proper annotate_expr_Proper is_annotated_for_Proper.
490 cbv [ident.annotate_with_expr]; break_innermost_match; repeat constructor; apply wf_update_annotation; assumption.
491 Qed.
492
493 Lemma wf_annotate_base
494 is_let_bound (t : base.type.base) G
495 v1 v2 (Hv : abstract_domain'_R t v1 v2)
496 e1 e2 (He : expr.wf G e1 e2)
497 : UnderLets.wf (fun G' => expr.wf G') G (@annotate_base1 is_let_bound t v1 e1) (@annotate_base2 is_let_bound t v2 e2).
498 Proof using abstract_interp_ident_Proper annotate_expr_Proper is_annotated_for_Proper.
499 cbv [ident.annotate_base];
500 repeat first [ apply wf_annotate_with_expr
501 | break_innermost_match_step
502 | progress subst
503 | progress cbv [type_base ident.smart_Literal] in *
504 | progress cbn [invert_Literal] in *
505 | discriminate
506 | progress destruct_head' False
507 | progress expr.invert_subst
508 | progress expr.inversion_wf
509 | wf_safe_t_step
510 | break_innermost_match_hyps_step
511 | match goal with
512 | [ H : _ = _ :> ident _ |- _ ] => inversion H; clear H
513 | [ |- UnderLets.wf _ _ _ _ ] => constructor
514 | [ H : abstract_domain'_R _ _ _ |- _ ] => rewrite !H
515 end
516 | progress expr.invert_match_step
517 | progress expr.inversion_expr ].
518 Qed.
519
520 Local Opaque ident.ident_Some ident.ident_None.
521 Lemma wf_annotate
522 is_let_bound t G
523 v1 v2 (Hv : abstract_domain'_R t v1 v2)
524 e1 e2 (He : expr.wf G e1 e2)
525 : UnderLets.wf (fun G' => expr.wf G') G (@annotate1 is_let_bound t v1 e1) (@annotate2 is_let_bound t v2 e2).
526 Proof using abstract_interp_ident_Proper annotate_expr_Proper extract_list_state_length extract_list_state_rel extract_option_state_rel is_annotated_for_Proper.
527 revert dependent G; induction t; intros;
528 cbn [ident.annotate]; try apply wf_annotate_base; trivial.
529 all: try solve [ repeat first [ lazymatch goal with
530 | [ H : expr.wf _ ?e1 ?e2, H' : reflect_list ?e1 = Some _, H'' : reflect_list ?e2 = None |- _ ]
531 => apply expr.wf_reflect_list in H; rewrite H', H'' in H; exfalso; clear -H; intuition congruence
532 | [ H : expr.wf _ ?e1 ?e2, H' : reflect_list ?e2 = Some _, H'' : reflect_list ?e1 = None |- _ ]
533 => apply expr.wf_reflect_list in H; rewrite H', H'' in H; exfalso; clear -H; intuition congruence
534 | [ H : expr.wf _ (reify_list _) (reify_list _) |- _ ] => apply expr.wf_reify_list in H
535 | [ |- expr.wf _ (reify_list _) (reify_list _) ] => apply expr.wf_reify_list
536 | [ |- UnderLets.wf _ _ (UnderLets.splice_list _ _) (UnderLets.splice_list _ _) ]
537 => eapply @UnderLets.wf_splice_list_no_order with (P:=fun G => expr.wf G); autorewrite with distr_length
538 | [ H : expr.wf _ (reify_list _) ?e, H' : reflect_list ?e = None |- _ ]
539 => apply expr.wf_reflect_list in H; rewrite H', expr.reflect_reify_list in H; exfalso; clear -H; intuition congruence
540 | [ H : expr.wf _ ?e (reify_list _), H' : reflect_list ?e = None |- _ ]
541 => apply expr.wf_reflect_list in H; rewrite H', expr.reflect_reify_list in H; exfalso; clear -H; intuition congruence
542 | [ H : extract_list_state ?t ?v1 = ?x1, H' : extract_list_state ?t ?v2 = ?x2, Hv : abstract_domain'_R _ ?v1 ?v2 |- _ ]
543 => let Hl := fresh in
544 let Hl' := fresh in
545 pose proof (extract_list_state_length _ v1 v2 Hv) as Hl;
546 pose proof (extract_list_state_rel _ v1 v2 Hv) as Hl';
547 rewrite H, H' in Hl, Hl'; cbv [option_eq option_map] in Hl, Hl'; clear H H'
548 | [ H : abstract_domain'_R _ ?v1 ?v2, H1 : extract_option_state _ ?v1 = _, H2 : extract_option_state _ ?v2 = _ |- _ ]
549 => let H' := fresh in
550 pose proof H as H';
551 apply extract_option_state_rel in H';
552 rewrite H1, H2 in H';
553 cbv [option_eq] in H';
554 clear H1 H2
555 | [ H : ?x = ?x |- _ ] => clear H
556 | [ H : length ?l1 = length ?l2, H' : context[length ?l1] |- _ ] => rewrite H in H'
557 | [ H : context[invert_pair ?e] |- _ ]
558 => let lem := lazymatch e with
559 | (?x, ?y)%expr => constr:(expr.invert_pair_ident_pair(v1:=x) (v2:=y) : invert_pair e = _)
560 end in
561 rewrite lem in H
562 end
563 | apply wf_annotate_with_expr
564 | apply DefaultValue.expr.base.wf_default
565 | apply DefaultValue.expr.wf_default
566 | progress expr.invert_subst
567 | progress cbn [ident.annotate ident.smart_Literal invert_Literal invert_pair invert_AppIdent2 invert_App2 fst snd projT2 projT1 eq_rect Option.bind] in *
568 | progress destruct_head' False
569 | progress inversion_option
570 | progress destruct_head'_ex
571 | discriminate
572 | wf_safe_t_step
573 | progress expr.inversion_wf_constr
574 | progress expr.inversion_expr
575 | progress type_beq_to_eq
576 | progress type.inversion_type
577 | progress base.type.inversion_type
578 | match goal with
579 | [ |- expr.wf _ (update_annotation1 _ _) (update_annotation2 _ _) ] => apply wf_update_annotation
580 | [ H : _ = _ :> ident _ |- _ ] => inversion H; clear H
581 | [ |- UnderLets.wf _ _ _ _ ] => constructor
582 | [ H : abstract_domain'_R _ ?x _ |- _ ] => rewrite !H
583 | [ |- UnderLets.wf _ _ (UnderLets.splice _ _) (UnderLets.splice _ _) ] => eapply UnderLets.wf_splice
584 | [ H : List.nth_error (List.map _ _) _ = Some _ |- _ ] => apply nth_error_map_ex in H
585 | [ H : context[List.nth_error (List.combine _ _) _] |- _ ] => rewrite nth_error_combine in H
586 | [ |- context[List.nth_error (List.combine _ _) _] ] => rewrite nth_error_combine
587 | [ H : forall x y, Some _ = Some _ -> Some _ = Some _ -> _ |- _ ]
588 => specialize (H _ _ eq_refl eq_refl)
589 | [ H : forall v1 v2, List.In (v1, v2) (List.combine ?l1 ?l2) -> ?R v1 v2, H' : List.nth_error ?l1 ?n = Some ?a1, H'' : List.nth_error ?l2 ?n = Some ?a2
590 |- ?R ?a1 ?a2 ]
591 => apply H
592 | [ H : List.nth_error ?l ?n' = Some ?v |- List.In (?v, _) (List.combine ?l _) ] => apply nth_error_In with (n:=n')
593 | [ H : length ?x = length ?y |- context[length ?x] ] => rewrite H
594 end
595 | handle_Forall2_step
596 | break_innermost_match_step
597 | break_innermost_match_hyps_step
598 | progress expr.invert_match
599 | progress expr.inversion_wf_one_constr
600 | match goal with
601 | [ H : context[UnderLets.wf _ _ (annotate1 _ _ _) (annotate2 _ _ _)]
602 |- UnderLets.wf _ _ (annotate1 _ _ _) (annotate2 _ _ _) ] => eapply H
603 end
604 | apply abstract_interp_ident_Proper_arrow
605 | progress rewrite_type_transport_correct
606 | apply conj
607 | congruence
608 | progress destruct_head' option
609 | progress cbn [Option.combine option_map UnderLets.splice_option reify_option option_rect] in *
610 | progress cbn [type.decode f_equal eq_rect fst snd] in *
611 | solve [ wf_t ] ] ].
612 Qed.
613 Local Ltac type_of_value v :=
614 lazymatch v with
615 | (abstract_domain ?t * _)%type => t
616 | (?a -> UnderLets _ ?b)
617 => let a' := type_of_value a in
618 let b' := type_of_value b in
619 constr:(type.arrow a' b')
620 end.
621 Local Opaque ident.ident_Literal.
622 Lemma wf_interp_ident_nth_default (annotate_with_state : bool) G T
623 : wf_value_with_lets G (@interp_ident1 annotate_with_state _ (@ident.List_nth_default T)) (@interp_ident2 annotate_with_state _ (@ident.List_nth_default T)).
624 Proof using abstract_interp_ident_Proper annotate_expr_Proper extract_list_state_length extract_list_state_rel extract_option_state_rel is_annotated_for_Proper.
625 cbv [wf_value_with_lets wf_value ident.interp_ident]; constructor; cbn -[abstract_domain_R abstract_domain].
626 { intros; subst.
627 destruct_head'_prod; destruct_head'_and; cbn [fst snd] in *.
628 repeat first [ progress subst
629 | lazymatch goal with
630 | [ H : expr.wf _ ?e1 ?e2, H' : reflect_list ?e1 = Some _, H'' : reflect_list ?e2 = None |- _ ]
631 => apply expr.wf_reflect_list in H; rewrite H', H'' in H; exfalso; clear -H; intuition congruence
632 | [ H : expr.wf _ ?e1 ?e2, H' : reflect_list ?e2 = Some _, H'' : reflect_list ?e1 = None |- _ ]
633 => apply expr.wf_reflect_list in H; rewrite H', H'' in H; exfalso; clear -H; intuition congruence
634 | [ H : expr.wf _ (reify_list _) (reify_list _) |- _ ] => apply expr.wf_reify_list in H
635 | [ |- expr.wf _ (reify_list _) (reify_list _) ] => apply expr.wf_reify_list
636 | [ |- UnderLets.wf _ _ (UnderLets.splice_list _ _) (UnderLets.splice_list _ _) ]
637 => eapply @UnderLets.wf_splice_list_no_order with (P:=fun G => expr.wf G); autorewrite with distr_length
638 | [ H : expr.wf _ (reify_list _) ?e, H' : reflect_list ?e = None |- _ ]
639 => apply expr.wf_reflect_list in H; rewrite H', expr.reflect_reify_list in H; exfalso; clear -H; intuition congruence
640 | [ H : expr.wf _ ?e (reify_list _), H' : reflect_list ?e = None |- _ ]
641 => apply expr.wf_reflect_list in H; rewrite H', expr.reflect_reify_list in H; exfalso; clear -H; intuition congruence
642 | [ H : extract_list_state ?t ?v1 = ?x1, H' : extract_list_state ?t ?v2 = ?x2, Hv : abstract_domain_R ?v1 ?v2 |- _ ]
643 => let Hl := fresh in
644 let Hl' := fresh in
645 pose proof (extract_list_state_length _ v1 v2 Hv) as Hl;
646 pose proof (extract_list_state_rel _ v1 v2 Hv) as Hl';
647 rewrite H, H' in Hl, Hl'; cbv [option_eq option_map] in Hl, Hl'; clear H H'
648 | [ H : ?x = ?x |- _ ] => clear H
649 | [ H : length ?l1 = length ?l2, H' : context[length ?l1] |- _ ] => rewrite H in H'
650 end
651 | match goal with
652 | [ |- UnderLets.wf ?Q ?G (UnderLets.splice ?x1 ?e1) (UnderLets.splice ?x2 ?e2) ]
653 => simple refine (@UnderLets.wf_splice _ _ _ _ _ _ _ _ _ Q G x1 x2 _ e1 e2 _);
654 [ let G := fresh "G" in
655 intro G;
656 lazymatch goal with
657 | [ |- expr _ -> _ -> _ ]
658 => refine (expr.wf G)
659 | [ |- ?T -> _ -> _ ]
660 => let t := type_of_value T in
661 refine (@wf_value G t)
662 end
663 | | ]
664 | [ |- UnderLets.wf ?Q ?G (UnderLets.Base _) (UnderLets.Base _) ]
665 => constructor
666 | [ H : ident.ident_Literal _ = ident.ident_Literal _ |- _ ]
667 => apply (f_equal (fun idc => invert_Literal (var:=var1) (#idc))) in H; rewrite !expr.invert_Literal_ident_Literal in H
668 | [ H : _ = _ :> ident _ |- _ ] => inversion H; clear H
669 | [ H : List.nth_error _ _ = None |- _ ] => apply List.nth_error_None in H
670 | [ H : List.nth_error _ _ = Some _ |- _ ]
671 => unique pose proof (@ListUtil.nth_error_value_length _ _ _ _ H);
672 unique pose proof (@ListUtil.nth_error_value_In _ _ _ _ H)
673 | [ H : context[List.In _ (List.map _ _)] |- _ ] => rewrite List.in_map_iff in H
674 | [ H : (?x <= ?y)%nat, H' : (?y < ?x)%nat |- _ ] => exfalso; clear -H H'; lia
675 | [ H : (?x <= ?y)%nat, H' : (?y < ?x')%nat, H'' : ?x' = ?x |- _ ] => exfalso; clear -H H' H''; lia
676 | [ H : length ?x = length ?y |- context[length ?x] ] => rewrite H
677 | [ H : List.nth_error (List.map _ _) _ = Some _ |- _ ] => apply nth_error_map_ex in H
678 | [ H : context[List.nth_error (List.combine _ _) _] |- _ ] => rewrite nth_error_combine in H
679 | [ |- context[List.nth_error (List.combine _ _) _] ] => rewrite nth_error_combine
680 | [ H : forall x y, Some _ = Some _ -> Some _ = Some _ -> _ |- _ ]
681 => specialize (H _ _ eq_refl eq_refl)
682 | [ H : forall v1 v2, List.In (v1, v2) (List.combine ?l1 ?l2) -> ?R v1 v2, H' : List.nth_error ?l1 ?n' = Some ?a1, H'' : List.nth_error ?l2 ?n' = Some ?a2
683 |- _ ]
684 => unique pose proof (H a1 a2 ltac:(apply nth_error_In with (n:=n'); rewrite nth_error_combine, H', H''; reflexivity))
685 | [ H : List.nth_error ?l ?n' = Some ?v |- List.In (?v, _) (List.combine ?l _) ] => apply nth_error_In with (n:=n')
686 | [ H : context[length ?ls] |- _ ] => tryif is_var ls then fail else (progress autorewrite with distr_length in H)
687 | [ H : context[List.nth_error (List.seq _ _) _] |- _ ] => rewrite nth_error_seq in H
688 end
689 | progress inversion_option
690 | progress intros
691 | progress cbn [fst snd value] in *
692 | progress destruct_head'_prod
693 | progress destruct_head'_ex
694 | progress destruct_head'_and
695 | progress destruct_head' False
696 | progress specialize_by_assumption
697 | apply conj
698 | progress expr.invert_subst
699 | progress expr.inversion_wf_constr
700 | progress expr.inversion_expr
701 | handle_Forall2_step
702 | wf_safe_t_step
703 | progress destruct_head' (@partial.wf_value)
704 | solve [ eapply wf_annotate; wf_t; try apply DefaultValue.expr.base.wf_default
705 | eapply wf_annotate_base; wf_t
706 | eapply (abstract_interp_ident_Proper _ (@ident.List_nth_default T) _ eq_refl); assumption
707 | eapply wf_update_annotation; wf_t
708 | wf_t
709 | match goal with
710 | [ H : context[UnderLets.wf _ _ _ _] |- UnderLets.wf _ _ _ _ ] => eapply H; solve [ repeat esplit; eauto ]
711 end
712 | eauto using List.nth_error_In
713 | eapply expr.wf_Proper_list; [ | eassumption ]; wf_safe_t; eauto 10 ]
714 | break_innermost_match_step
715 | match goal with
716 | [ H : context[List.In] |- expr.wf _ ?x ?y ]
717 => specialize (H x y); rewrite !List.nth_default_eq, <- List.combine_nth, <- !List.nth_default_eq in H; cbv [List.nth_default] in H |- *
718 | [ H : List.In _ _ -> ?P |- ?P ] => apply H
719 end
720 | break_innermost_match_hyps_step
721 | congruence
722 | rewrite List.combine_length in *
723 | rewrite Nat.min_r in * by lia
724 | rewrite Nat.min_l in * by lia
725 | progress expr.inversion_wf_one_constr
726 | progress expr.invert_match
727 | match goal with
728 | [ |- wf_value _ _ _ ] => progress hnf
729 end ]. }
730 Qed.
731
732 Lemma wf_interp_ident_not_nth_default_nostrip (annotate_with_state : bool) G {t} (idc : ident t)
733 : wf_value_with_lets G (Base (reflect1 annotate_with_state (###idc)%expr (abstract_interp_ident _ idc))) (Base (reflect2 annotate_with_state (###idc)%expr (abstract_interp_ident _ idc))).
734 Proof using abstract_interp_ident_Proper annotate_expr_Proper bottom'_Proper extract_list_state_length extract_list_state_rel extract_option_state_rel is_annotated_for_Proper.
735 constructor; eapply wf_reflect;
736 solve [ apply bottom'_Proper
737 | apply wf_annotate
738 | repeat constructor
739 | apply abstract_interp_ident_Proper; reflexivity ].
740 Qed.
741
742 Lemma wf_interp_ident_not_nth_default (annotate_with_state : bool) G {t} (idc : ident t)
743 : (wf_value_with_lets G)
744 (Base match strip_annotation1 _ idc with
745 | Some v => v
746 | None => reflect1 annotate_with_state (###idc)%expr (abstract_interp_ident _ idc)
747 end)
748 (Base match strip_annotation2 _ idc with
749 | Some v => v
750 | None => reflect2 annotate_with_state (###idc)%expr (abstract_interp_ident _ idc)
751 end).
752 Proof using abstract_interp_ident_Proper annotate_expr_Proper bottom'_Proper extract_list_state_length extract_list_state_rel extract_option_state_rel is_annotated_for_Proper wf_strip_annotation.
753 pose proof (wf_strip_annotation G _ idc).
754 break_innermost_match; cbn [option_eq] in *;
755 solve [ exfalso; assumption
756 | congruence
757 | apply wf_interp_ident_not_nth_default_nostrip
758 | constructor; assumption ].
759 Qed.
760
761 Lemma wf_interp_ident G {t} idc1 idc2 (Hidc : idc1 = idc2) (annotate_with_state : bool)
762 : wf_value_with_lets G (@interp_ident1 annotate_with_state t idc1) (@interp_ident2 annotate_with_state t idc2).
763 Proof using abstract_interp_ident_Proper annotate_expr_Proper bottom'_Proper extract_list_state_length extract_list_state_rel extract_option_state_rel is_annotated_for_Proper wf_strip_annotation.
764 cbv [wf_value_with_lets ident.interp_ident]; subst idc2; destruct idc1;
765 first [ apply wf_interp_ident_nth_default
766 | apply wf_interp_ident_not_nth_default ].
767 Qed.
768
769 Local Notation strip_all_annotations'1 := (@partial.ident.strip_all_annotations' var1 annotation_to_cast1 skip_annotations_under).
770 Local Notation strip_all_annotations'2 := (@partial.ident.strip_all_annotations' var2 annotation_to_cast2 skip_annotations_under).
771 Local Notation strip_all_annotations1 := (@partial.ident.strip_all_annotations var1 annotation_to_cast1 skip_annotations_under).
772 Local Notation strip_all_annotations2 := (@partial.ident.strip_all_annotations var2 annotation_to_cast2 skip_annotations_under).
773 Lemma wf_strip_all_annotations' G t e1 e2 (Hwf : expr.wf G e1 e2)
774 : forall should_strip, expr.wf G (@strip_all_annotations'1 should_strip t e1) (@strip_all_annotations'2 should_strip t e2).
775 Proof using wf_annotation_to_cast.
776 induction Hwf; cbn [partial.ident.strip_all_annotations'];
777 repeat first [ progress cbn [projT1 projT2 fst snd] in *
778 | progress type.inversion_type
779 | progress wf_safe_t
780 | progress break_innermost_match
781 | progress expr.invert_subst
782 | discriminate
783 | solve [ exfalso; eauto
784 | eassert (Some _ = None) by eauto; congruence ]
785 | match goal with
786 | [ H1 : annotation_to_cast1 ?s ?d ?e1 = _, H2 : annotation_to_cast2 ?s ?d ?e2 = _ |- _ ]
787 => let H := fresh in
788 pose proof (fun G => wf_annotation_to_cast s d G e1 e2) as H;
789 rewrite H1, H2 in H; cbv [option_eq] in H;
790 clear H1 H2
791 end ].
792 Qed.
793
794 Lemma wf_strip_all_annotations G t e1 e2 (Hwf : expr.wf G e1 e2)
795 : expr.wf G (@strip_all_annotations1 t e1) (@strip_all_annotations2 t e2).
796 Proof using wf_annotation_to_cast. now apply wf_strip_all_annotations'. Qed.
797
798 Local Notation eval_with_bound1 := (@partial.ident.eval_with_bound var1 abstract_domain' annotate_expr1 bottom' abstract_interp_ident extract_list_state extract_option_state is_annotated_for1 strip_annotation1 skip_annotations_under).
799 Local Notation eval_with_bound2 := (@partial.ident.eval_with_bound var2 abstract_domain' annotate_expr2 bottom' abstract_interp_ident extract_list_state extract_option_state is_annotated_for2 strip_annotation2 skip_annotations_under).
800 Lemma wf_eval_with_bound (annotate_with_state : bool) {t} G G' e1 e2 (Hwf : expr.wf G e1 e2) st1 st2 (Hst : type.and_for_each_lhs_of_arrow (@abstract_domain_R) st1 st2)
801 (HGG' : forall t v1 v2, List.In (existT _ t (v1, v2)) G -> wf_value_with_lets G' v1 v2)
802 : expr.wf G' (@eval_with_bound1 annotate_with_state t e1 st1) (@eval_with_bound2 annotate_with_state t e2 st2).
803 Proof using abstract_interp_ident_Proper annotate_expr_Proper bottom'_Proper extract_list_state_length extract_list_state_rel extract_option_state_rel is_annotated_for_Proper wf_strip_annotation.
804 eapply wf_eval_with_bound';
805 solve [ eassumption
806 | eapply wf_annotate
807 | eapply wf_interp_ident ].
808 Qed.
809
810 Local Notation eval1 := (@partial.ident.eval var1 abstract_domain' annotate_expr1 bottom' abstract_interp_ident extract_list_state extract_option_state is_annotated_for1 strip_annotation1).
811 Local Notation eval2 := (@partial.ident.eval var2 abstract_domain' annotate_expr2 bottom' abstract_interp_ident extract_list_state extract_option_state is_annotated_for2 strip_annotation2).
812 Lemma wf_eval {t} G G' e1 e2 (Hwf : expr.wf G e1 e2)
813 (HGG' : forall t v1 v2, List.In (existT _ t (v1, v2)) G -> wf_value_with_lets G' v1 v2)
814 : expr.wf G' (@eval1 t e1) (@eval2 t e2).
815 Proof using abstract_interp_ident_Proper annotate_expr_Proper bottom'_Proper extract_list_state_length extract_list_state_rel extract_option_state_rel is_annotated_for_Proper wf_strip_annotation.
816 eapply wf_eval';
817 solve [ eassumption
818 | eapply wf_annotate
819 | eapply wf_interp_ident ].
820 Qed.
821
822 Local Notation eta_expand_with_bound1 := (@partial.ident.eta_expand_with_bound var1 abstract_domain' annotate_expr1 bottom' abstract_interp_ident extract_list_state extract_option_state is_annotated_for1).
823 Local Notation eta_expand_with_bound2 := (@partial.ident.eta_expand_with_bound var2 abstract_domain' annotate_expr2 bottom' abstract_interp_ident extract_list_state extract_option_state is_annotated_for2).
824 Lemma wf_eta_expand_with_bound {t} G e1 e2 (Hwf : expr.wf G e1 e2) st1 st2 (Hst : type.and_for_each_lhs_of_arrow (@abstract_domain_R) st1 st2)
825 : expr.wf G (@eta_expand_with_bound1 t e1 st1) (@eta_expand_with_bound2 t e2 st2).
826 Proof using abstract_interp_ident_Proper annotate_expr_Proper bottom'_Proper extract_list_state_length extract_list_state_rel extract_option_state_rel is_annotated_for_Proper.
827 eapply wf_eta_expand_with_bound';
828 solve [ eassumption
829 | eapply wf_annotate
830 | eapply wf_interp_ident ].
831 Qed.
832 End with_var2.
833 End with_type.
834 End ident.
835
836 Section specialized.
837 Import API.
838 Local Notation abstract_domain' := ZRange.type.base.option.interp (only parsing).
839 Local Notation abstract_domain := (@partial.abstract_domain base.type abstract_domain').
840 Local Notation abstract_domain'_R t := (@eq (abstract_domain' t)) (only parsing).
841 Local Notation abstract_domain_R := (@abstract_domain_R base.type abstract_domain' (fun t => abstract_domain'_R t)).
842 Local Notation wf_value := (@wf_value base.type ident abstract_domain' (fun t => abstract_domain'_R t)).
843
844 Lemma annotate_expr_Proper {relax_zrange var1 var2} {t} s1 s2
845 : abstract_domain'_R t s1 s2
846 -> option_eq (expr.wf nil)
847 (@annotate_expr relax_zrange var1 t s1)
848 (@annotate_expr relax_zrange var2 t s2).
849 Proof using Type.
850 intros ?; subst s2.
851 cbv [annotate_expr Crypto.Util.Option.bind option_eq]; break_innermost_match;
852 repeat constructor.
853 Qed.
854
855 Global Instance bottom'_Proper {t} : Proper (abstract_domain'_R t) (bottom' t).
856 Proof using Type. reflexivity. Qed.
857
858 Global Instance abstract_interp_ident_Proper {opts : AbstractInterpretation.Options} {assume_cast_truncates : bool} {t}
859 : Proper (eq ==> @abstract_domain_R t) (abstract_interp_ident assume_cast_truncates t).
860 Proof using Type. apply ZRange.ident.option.interp_Proper. Qed.
861
862 Global Instance extract_list_state_Proper {t}
863 : Proper (abstract_domain'_R _ ==> option_eq (SetoidList.eqlistA (@abstract_domain'_R t)))
864 (extract_list_state t).
865 Proof using Type.
866 intros st st' ?; subst st'; cbv [option_eq extract_list_state]; break_innermost_match; reflexivity.
867 Qed.
868
869 Local Notation tZ := (base.type.type_base base.type.Z).
870 Local Notation cstZ r
871 := (expr.App
872 (d:=type.arrow (type.base tZ) (type.base tZ))
873 (expr.Ident ident.Z_cast)
874 (expr.Ident (@ident.Literal base.type.zrange r%zrange))).
875 Local Notation cstZZ r1 r2
876 := (expr.App
877 (d:=type.arrow (type.base (tZ * tZ)) (type.base (tZ * tZ)))
878 (expr.Ident ident.Z_cast2)
879 (#(@ident.Literal base.type.zrange r1%zrange), #(@ident.Literal base.type.zrange r2%zrange))%expr_pat).
880
881 Lemma wf_always_strip_annotation {opts : AbstractInterpretation.Options} (assume_cast_truncates : bool) {var1 var2} G {t} idc
882 : option_eq (wf_value G)
883 (always_strip_annotation assume_cast_truncates (var:=var1) t idc)
884 (always_strip_annotation assume_cast_truncates (var:=var2) t idc).
885 Proof using Type.
886 cbv [always_strip_annotation]; break_innermost_match; try reflexivity;
887 cbn [option_eq wf_value].
888 all: repeat first [ progress intros
889 | assumption
890 | progress subst
891 | exfalso; congruence
892 | progress cbn [fst snd] in *
893 | progress break_innermost_match
894 | progress destruct_head'_and
895 | match goal with
896 | [ |- UnderLets.wf _ _ (Base _) (Base _) ] => constructor
897 | [ |- _ /\ _ ] => split
898 end
899 | solve [ wf_t ]
900 | progress cbn [abstract_domain_R type.related] in * ].
901 Qed.
902
903 Lemma wf_strip_annotation {opts : AbstractInterpretation.Options} (assume_cast_truncates : bool) (strip_annotations : bool) {var1 var2} G {t} idc
904 : option_eq (wf_value G)
905 (strip_annotation assume_cast_truncates strip_annotations (var:=var1) t idc)
906 (strip_annotation assume_cast_truncates strip_annotations (var:=var2) t idc).
907 Proof using Type.
908 cbv [strip_annotation]; break_innermost_match; now try apply wf_always_strip_annotation.
909 Qed.
910
911 Local Arguments base.try_make_transport_cps / _ _ _.
912 Local Arguments type.try_make_transport_cps / _ _ _ _ _.
913 Lemma is_annotated_for_spec {relax_zrange var} t t' e st
914 : @is_annotated_for relax_zrange var t t' e st = true
915 <-> ((exists (pf : t' = tZ) r,
916 (annotation_of_state relax_zrange (rew pf in st) = Some r)
917 /\ existT (@expr var) t e = existT (@expr var) _ (cstZ r))
918 \/ (exists (pf : t' = (tZ * tZ)%etype) r1 r2,
919 ((fun '(r1, r2) => (annotation_of_state relax_zrange r1, annotation_of_state relax_zrange r2))
920 (rew pf in st) = (Some r1, Some r2))
921 /\ existT (@expr var) t e = existT (@expr var) _ (cstZZ r1 r2))).
922 Proof using Type.
923 split.
924 { cbv [is_annotated_for]; break_innermost_match; try discriminate.
925 all: rewrite ?Bool.andb_true_iff.
926 all: intro; destruct_head'_and; reflect_beq_to_eq (option_beq zrange_beq).
927 all: constructor; exists eq_refl; cbn [eq_rect].
928 all: repeat esplit; try apply (f_equal2 (@pair _ _)); try (symmetry; eassumption).
929 all: multimatch goal with
930 | [ H : invert_Z_cast _ = Some _ |- _ ]
931 => apply expr.invert_Z_cast_Some in H
932 | [ H : invert_Z_cast2 _ = Some _ |- _ ]
933 => apply expr.invert_Z_cast2_Some in H
934 end;
935 solve [ repeat first [ progress inversion_sigma
936 | progress subst
937 | progress cbn [eq_rect] in *
938 | reflexivity ] ]. }
939 { repeat first [ progress intros
940 | progress subst
941 | progress cbn [eq_rect fst snd] in *
942 | progress inversion_option
943 | progress inversion_sigma
944 | progress inversion_prod
945 | progress destruct_head'_ex
946 | progress destruct_head'_and
947 | progress destruct_head'_or
948 | progress cbn
949 | break_innermost_match_step
950 | rewrite Bool.andb_true_iff
951 | apply conj
952 | apply zrange_lb
953 | reflexivity ]. }
954 Qed.
955
956 Lemma is_annotated_for_Proper {relax_zrange var1 var2} G t t' e1 e2
957 : expr.wf G e1 e2
958 -> ((abstract_domain'_R _ ==> eq)%signature)
959 (@is_annotated_for relax_zrange var1 t t' e1)
960 (@is_annotated_for relax_zrange var2 t t' e2).
961 Proof using Type.
962 repeat intro; subst;
963 match goal with |- ?x = ?y => destruct x eqn:?, y eqn:? end.
964 all: repeat first [ match goal with
965 | [ H : is_annotated_for _ _ _ _ _ = true |- _ ]
966 => rewrite is_annotated_for_spec in H
967 | [ H : ?x <> ?x |- _ ] => congruence
968 end
969 | reflexivity
970 | exfalso; assumption
971 | progress cbn [eq_rect fst snd projT1 projT2 andb] in *
972 | progress subst
973 | progress inversion_prod
974 | progress destruct_head'_ex
975 | progress destruct_head'_sig
976 | progress destruct_head'_sigT
977 | progress destruct_head'_prod
978 | progress destruct_head'_and
979 | progress reflect_beq_to_eq zrange_beq
980 | progress inversion_sigma
981 | progress inversion_option
982 | progress destruct_head'_or
983 | progress inversion_type
984 | progress expr.inversion_wf_one_constr
985 | progress expr.invert_subst
986 | progress expr.invert_match
987 | progress expr.inversion_expr
988 | break_innermost_match_hyps_step
989 | match goal with
990 | [ H : is_annotated_for _ _ _ _ _ = false |- _ ]
991 => progress cbn in H
992 end ].
993 Qed.
994
995 Lemma wf_annotation_to_cast_helper {var1 var2 t G idc1 idc2}
996 (Hidc : idc1 = idc2)
997 : option_eq (fun f g => forall e1 e2, expr.wf G e1 e2 -> expr.wf G (f e1) (g e2))
998 (@annotation_to_cast_helper var1 t idc1)
999 (@annotation_to_cast_helper var2 t idc2).
1000 Proof using Type.
1001 subst idc2; destruct idc1; cbv; try reflexivity; intros; assumption.
1002 Qed.
1003
1004 Lemma wf_annotation_to_cast {var1 var2 s d G e1 e2}
1005 (Hwf : expr.wf G e1 e2)
1006 : option_eq (fun f g => forall e1 e2, expr.wf G e1 e2 -> expr.wf G (f e1) (g e2))
1007 (@annotation_to_cast var1 s d e1)
1008 (@annotation_to_cast var2 s d e2).
1009 Proof using Type.
1010 cbv [annotation_to_cast];
1011 repeat first [ progress wf_safe_t
1012 | congruence
1013 | progress inversion_option
1014 | progress cbn [fst snd projT1 projT2] in *
1015 | progress cbv [Option.bind] in *
1016 | progress break_innermost_match
1017 | progress break_innermost_match_hyps
1018 | progress expr.invert_subst
1019 | progress expr.inversion_wf_one_constr
1020 | progress cbn [invert_AppIdent invert_App invert_Ident invert_App_cps invert_AppIdent_cps Option.bind] in *
1021 | progress expr.invert_match
1022 | progress expr.inversion_expr
1023 | now refine (wf_annotation_to_cast_helper eq_refl) ].
1024 Qed.
1025
1026 Lemma extract_list_state_length
1027 : forall t v1 v2, abstract_domain'_R _ v1 v2 -> option_map (@length _) (extract_list_state t v1) = option_map (@length _) (extract_list_state t v2).
1028 Proof using Type.
1029 intros; subst; cbv [option_map extract_list_state]; break_innermost_match; reflexivity.
1030 Qed.
1031 Lemma extract_list_state_rel
1032 : forall t v1 v2, abstract_domain'_R _ v1 v2 -> forall l1 l2, extract_list_state t v1 = Some l1 -> extract_list_state t v2 = Some l2 -> List.Forall2 (@abstract_domain'_R t) l1 l2.
1033 Proof using Type.
1034 intros; cbv [extract_list_state] in *; subst; inversion_option; subst.
1035 now rewrite Forall2_Forall, Forall_forall; cbv [Proper].
1036 Qed.
1037
1038 Lemma extract_option_state_rel
1039 : forall t v1 v2, abstract_domain'_R _ v1 v2 -> option_eq (option_eq (abstract_domain'_R _)) (extract_option_state t v1) (extract_option_state t v2).
1040 Proof using Type.
1041 cbv [extract_option_state option_eq]; intros; subst; break_match; reflexivity.
1042 Qed.
1043
1044 Section with_var2.
1045 Context {var1 var2 : type -> Type}.
1046 Local Notation wf_value_with_lets := (@wf_value_with_lets base.type ident abstract_domain' (fun t => abstract_domain'_R t) var1 var2).
1047
1048 Lemma wf_eval {opts : AbstractInterpretation.Options} {t} G G' e1 e2 (Hwf : expr.wf G e1 e2)
1049 (HGG' : forall t v1 v2, List.In (existT _ t (v1, v2)) G -> wf_value_with_lets G' v1 v2)
1050 : expr.wf G' (t:=t) (eval (var:=var1) e1) (eval (var:=var2) e2).
1051 Proof using Type.
1052 eapply ident.wf_eval;
1053 solve [ eassumption
1054 | exact _
1055 | apply extract_list_state_length
1056 | apply extract_list_state_rel
1057 | apply extract_option_state_rel
1058 | apply wf_strip_annotation
1059 | intros; now apply annotate_expr_Proper
1060 | apply is_annotated_for_Proper ].
1061 Qed.
1062
1063 Lemma wf_strip_all_annotations strip_annotations_under G t e1 e2 (Hwf : expr.wf G e1 e2)
1064 : expr.wf G (@strip_all_annotations strip_annotations_under var1 t e1) (@strip_all_annotations strip_annotations_under var2 t e2).
1065 Proof using Type. revert Hwf; apply ident.wf_strip_all_annotations, @wf_annotation_to_cast. Qed.
1066
1067 Lemma wf_eval_with_bound {opts : AbstractInterpretation.Options} {relax_zrange assume_cast_truncates skip_annotations_under strip_preexisting_annotations t} G G' e1 e2 (Hwf : expr.wf G e1 e2) st1 st2 (Hst : type.and_for_each_lhs_of_arrow (@abstract_domain_R) st1 st2)
1068 (HGG' : forall t v1 v2, List.In (existT _ t (v1, v2)) G -> wf_value_with_lets G' v1 v2)
1069 : expr.wf G' (var1:=var1) (var2:=var2) (t:=t)
1070 (eval_with_bound relax_zrange assume_cast_truncates skip_annotations_under strip_preexisting_annotations e1 st1)
1071 (eval_with_bound relax_zrange assume_cast_truncates skip_annotations_under strip_preexisting_annotations e2 st2).
1072 Proof using Type.
1073 eapply ident.wf_eval_with_bound;
1074 solve [ eassumption
1075 | exact _
1076 | apply extract_list_state_length
1077 | apply extract_list_state_rel
1078 | apply extract_option_state_rel
1079 | apply wf_strip_annotation
1080 | intros; now apply annotate_expr_Proper
1081 | apply is_annotated_for_Proper ].
1082 Qed.
1083
1084 Lemma wf_strip_annotations {opts : AbstractInterpretation.Options} {assume_cast_truncates} {t} G G' e1 e2 (Hwf : expr.wf G e1 e2) st1 st2 (Hst : type.and_for_each_lhs_of_arrow (@abstract_domain_R) st1 st2)
1085 (HGG' : forall t v1 v2, List.In (existT _ t (v1, v2)) G -> wf_value_with_lets G' v1 v2)
1086 : expr.wf G' (t:=t) (strip_annotations assume_cast_truncates (var:=var1) e1 st1) (strip_annotations assume_cast_truncates (var:=var2) e2 st2).
1087 Proof using Type.
1088 eapply ident.wf_eval_with_bound;
1089 solve [ eassumption
1090 | exact _
1091 | apply extract_list_state_length
1092 | apply extract_list_state_rel
1093 | apply extract_option_state_rel
1094 | apply wf_strip_annotation
1095 | intros; now apply annotate_expr_Proper
1096 | apply is_annotated_for_Proper ].
1097 Qed.
1098
1099 Lemma wf_eta_expand_with_bound {relax_zrange t} G e1 e2 (Hwf : expr.wf G e1 e2) st1 st2 (Hst : type.and_for_each_lhs_of_arrow (@abstract_domain_R) st1 st2)
1100 : expr.wf G (t:=t) (eta_expand_with_bound relax_zrange (var:=var1) e1 st1) (eta_expand_with_bound relax_zrange (var:=var2) e2 st2).
1101 Proof using Type.
1102 eapply ident.wf_eta_expand_with_bound;
1103 solve [ eassumption
1104 | exact _
1105 | apply extract_list_state_length
1106 | apply extract_list_state_rel
1107 | apply extract_option_state_rel
1108 | intros; now apply annotate_expr_Proper
1109 | apply is_annotated_for_Proper ].
1110 Qed.
1111 End with_var2.
1112
1113 Lemma Wf_StripAllAnnotations strip_annotations_under {t} (e : Expr t) (Hwf : Wf e) : Wf (StripAllAnnotations strip_annotations_under e).
1114 Proof using Type.
1115 intros ??; now apply wf_strip_all_annotations.
1116 Qed.
1117
1118 Lemma Wf_Eval {opts : AbstractInterpretation.Options} {t} (e : Expr t) (Hwf : Wf e) : Wf (Eval e).
1119 Proof using Type.
1120 intros ??; eapply wf_eval with (G:=nil); cbn [List.In]; try apply Hwf; tauto.
1121 Qed.
1122
1123 Lemma Wf_EvalWithBound {opts : AbstractInterpretation.Options} {relax_zrange assume_cast_truncates skip_annotations_under strip_preexisting_annotations t} (e : Expr t) bound (Hwf : Wf e) (bound_valid : Proper (type.and_for_each_lhs_of_arrow (@abstract_domain_R)) bound)
1124 : Wf (EvalWithBound relax_zrange assume_cast_truncates skip_annotations_under strip_preexisting_annotations e bound).
1125 Proof using Type.
1126 intros ??; eapply wf_eval_with_bound with (G:=nil); cbn [List.In]; try apply Hwf; tauto.
1127 Qed.
1128
1129 Lemma Wf_StripAnnotations {opts : AbstractInterpretation.Options} {assume_cast_truncates} {t} (e : Expr t) bound (Hwf : Wf e) (bound_valid : Proper (type.and_for_each_lhs_of_arrow (@abstract_domain_R)) bound)
1130 : Wf (StripAnnotations assume_cast_truncates e bound).
1131 Proof using Type.
1132 intros ??; eapply wf_strip_annotations with (G:=nil); cbn [List.In]; try tauto; apply Hwf.
1133 Qed.
1134
1135 Lemma Wf_EtaExpandWithBound {relax_zrange t} (e : Expr t) bound (Hwf : Wf e) (bound_valid : Proper (type.and_for_each_lhs_of_arrow (@abstract_domain_R)) bound)
1136 : Wf (EtaExpandWithBound relax_zrange e bound).
1137 Proof using Type.
1138 intros ??; eapply wf_eta_expand_with_bound with (G:=nil); cbn [List.In]; try apply Hwf; tauto.
1139 Qed.
1140
1141 Local Instance Proper_strip_ranges {t}
1142 : Proper (@abstract_domain_R t ==> @abstract_domain_R t) (@ZRange.type.option.strip_ranges t).
1143 Proof using Type.
1144 cbv [Proper abstract_domain_R respectful].
1145 induction t as [t|s IHs d IHd]; cbn in *; destruct_head'_prod; destruct_head'_and; cbn in *; intros; subst; cbv [respectful] in *;
1146 eauto.
1147 Qed.
1148
1149 Lemma Wf_EtaExpandWithListInfoFromBound {t} (e : Expr t) bound (Hwf : Wf e) (bound_valid : Proper (type.and_for_each_lhs_of_arrow (@abstract_domain_R)) bound)
1150 : Wf (EtaExpandWithListInfoFromBound e bound).
1151 Proof using Type.
1152 eapply Wf_EtaExpandWithBound; [ assumption | ].
1153 clear dependent e.
1154 cbv [Proper] in *; induction t as [t|s IHs d IHd]; cbn in *; destruct_head'_prod; destruct_head'_and; cbn in *; eauto.
1155 split; auto; apply Proper_strip_ranges; auto.
1156 Qed.
1157 End specialized.
1158 End partial.
1159 #[global]
1160 Hint Resolve Wf_Eval Wf_EvalWithBound Wf_EtaExpandWithBound Wf_EtaExpandWithListInfoFromBound Wf_StripAllAnnotations Wf_StripAnnotations : wf.
1161 #[global]
1162 Hint Opaque partial.Eval partial.EvalWithBound partial.EtaExpandWithBound partial.EtaExpandWithListInfoFromBound partial.StripAnnotations partial.StripAllAnnotations : wf interp rewrite.
1163 Import API.
1164
1165 Lemma Wf_PartialEvaluateWithListInfoFromBounds
1166 {opts : AbstractInterpretation.Options}
1167 {t} (E : Expr t)
1168 (b_in : type.for_each_lhs_of_arrow ZRange.type.option.interp t)
1169 (Hwf : Wf E)
1170 {b_in_Proper : Proper (type.and_for_each_lhs_of_arrow (@abstract_domain_R base.type ZRange.type.base.option.interp (fun t0 : base.type => eq))) b_in}
1171 : Wf (PartialEvaluateWithListInfoFromBounds E b_in).
1172 Proof. cbv [PartialEvaluateWithListInfoFromBounds]; eauto with wf. Qed.
1173 #[global]
1174 Hint Resolve Wf_PartialEvaluateWithListInfoFromBounds : wf.
1175 #[global]
1176 Hint Opaque PartialEvaluateWithListInfoFromBounds : wf interp rewrite.
1177
1178 Lemma Wf_PartialEvaluateWithBounds
1179 {opts : AbstractInterpretation.Options}
1180 {relax_zrange} {assume_cast_truncates : bool} {skip_annotations_under : forall t, ident t -> bool} {strip_preexisting_annotations : bool} {t} (E : Expr t)
1181 (b_in : type.for_each_lhs_of_arrow ZRange.type.option.interp t)
1182 (Hwf : Wf E)
1183 {b_in_Proper : Proper (type.and_for_each_lhs_of_arrow (@abstract_domain_R base.type ZRange.type.base.option.interp (fun t0 : base.type => eq))) b_in}
1184 : Wf (PartialEvaluateWithBounds relax_zrange assume_cast_truncates skip_annotations_under strip_preexisting_annotations E b_in).
1185 Proof. cbv [PartialEvaluateWithBounds]; eauto with wf. Qed.
1186 #[global]
1187 Hint Resolve Wf_PartialEvaluateWithBounds : wf.
1188 #[global]
1189 Hint Opaque PartialEvaluateWithBounds : wf interp rewrite.
1190 End Compilers.