Skip to content

Commit 6aa6e0c

Browse files
committed
Adjust statement of relate_fold_add lemma,
used by the prune_terms tactic, to match the statement of relate_fold_add that appears in my recent pull request to coq-mmaps. rocq-community/mmaps#14 That way, when coq-mmaps is (soon) made part of the coq platform, we can easily switch vcfloat from using FMaps (the old, obsolete version of functional maps) to the new MMaps (which is better).
1 parent 367a315 commit 6aa6e0c

File tree

3 files changed

+154
-47
lines changed

3 files changed

+154
-47
lines changed

doc/VCFloat-Manual.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ \chapter{Reification}
286286
The first argument of \lstinline{HO_reify_float_expr}
287287
should be list of identifiers, to associate with those
288288
parameters of the functional model. In this case the list is
289-
simpliy \lstinline{[_x;_v]}.
289+
simply \lstinline{[_x;_v]}.
290290
291291
\chapter{Boundsmap}
292292

vcfloat/FMap_lemmas.v

Lines changed: 119 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ split; intro H0; inversion H0; clear H0; subst.
7474
- apply Table.Raw.InRight; rewrite IHt2; auto.
7575
Qed.
7676

77-
Lemma relate_fold_add:
77+
Lemma relate_fold_add':
7878
forall [elt A: Type]
7979
[eqv: A -> A -> Prop]
8080
(eqv_rel: Equivalence eqv)
@@ -199,6 +199,53 @@ rewrite u_unit.
199199
reflexivity.
200200
Qed.
201201

202+
203+
Lemma relate_fold_add:
204+
forall [elt A: Type]
205+
[eqv: A -> A -> Prop]
206+
(eqv_rel: Equivalence eqv)
207+
(lift: Table.key -> elt -> A)
208+
(lift_prop: forall k k' x, Keys.eq k k' -> eqv (lift k x) (lift k' x))
209+
(f: A -> A -> A)
210+
(f_mor: forall x1 y1, eqv x1 y1 ->
211+
forall x2 y2, eqv x2 y2 ->
212+
eqv (f x1 x2) (f y1 y2))
213+
(f_assoc: forall x y z : A, eqv (f x (f y z)) (f (f x y) z))
214+
(f_commut: forall x y : A, eqv (f x y) (f y x))
215+
(u: A)
216+
(u_unit: forall x, eqv (f u x) x)
217+
(g: Table.key -> elt -> A -> A)
218+
(g_eqv: forall k x a, eqv (g k x a) (f (lift k x) a))
219+
(tab: Table.t elt)
220+
(k: Table.key),
221+
eqv (Table.fold g tab u)
222+
(f (match Table.find k tab with Some x => lift k x | None => u end)
223+
(Table.fold (fun k' x a => if Keys.eq_dec k k' then a else g k' x a) tab u)).
224+
Proof.
225+
intros.
226+
rewrite (relate_fold_add' eqv_rel lift lift_prop f f_mor f_assoc f_commut u u_unit g g_eqv tab k).
227+
apply f_mor.
228+
reflexivity.
229+
rewrite !Table.fold_1.
230+
clear u_unit.
231+
revert u.
232+
induction (Table.elements (elt:=elt) tab); intro.
233+
simpl. reflexivity.
234+
simpl.
235+
rewrite IHl.
236+
set (ff := fold_left _).
237+
clearbody ff.
238+
match goal with |- eqv ?A ?B => replace B with A end.
239+
reflexivity.
240+
f_equal.
241+
set (j := fst a). clearbody j.
242+
clear.
243+
destruct (Keys.compare k j); try apply Keys.lt_not_eq in l;
244+
destruct (Keys.eq_dec k j); try contradiction; auto.
245+
symmetry in e. contradiction.
246+
Qed.
247+
248+
202249
Lemma fold_add_ignore:
203250
forall [elt A]
204251
(f: Table.key -> elt -> A -> A)
@@ -224,6 +271,51 @@ rewrite ?H; auto.
224271
rewrite IHis_bst2. auto.
225272
Qed.
226273

274+
275+
276+
Lemma relate_fold_add_alt:
277+
forall [elt A: Type]
278+
[eqv: A -> A -> Prop]
279+
(eqv_rel: Equivalence eqv)
280+
(lift: Table.key -> elt -> A)
281+
(lift_prop: forall k k' x, Keys.eq k k' -> eqv (lift k x) (lift k' x))
282+
(f: A -> A -> A)
283+
(f_mor: forall x1 y1, eqv x1 y1 ->
284+
forall x2 y2, eqv x2 y2 ->
285+
eqv (f x1 x2) (f y1 y2))
286+
(f_assoc: forall x y z : A, eqv (f x (f y z)) (f (f x y) z))
287+
(f_commut: forall x y : A, eqv (f x y) (f y x))
288+
(u: A)
289+
(u_unit: forall x, eqv (f u x) x)
290+
(g: Table.key -> elt -> A -> A)
291+
(g_eqv: forall k x a, eqv (g k x a) (f (lift k x) a))
292+
(tab: Table.t elt)
293+
(k: Table.key) (new oldnew : elt),
294+
eqv (f (lift k new) (match Table.find k tab with Some x => lift k x | None => u end)) (lift k oldnew) ->
295+
eqv (f (lift k new) (Table.fold g tab u)) (Table.fold g (Table.add k oldnew tab) u).
296+
Proof.
297+
intros.
298+
pose proof relate_fold_add eqv_rel lift lift_prop f f_mor f_assoc f_commut u u_unit g g_eqv.
299+
etransitivity.
300+
apply f_mor.
301+
reflexivity.
302+
apply H0 with (k:=k).
303+
rewrite f_assoc.
304+
etransitivity.
305+
apply f_mor.
306+
apply H.
307+
reflexivity.
308+
rewrite H0 with (k:=k).
309+
apply f_mor.
310+
erewrite Table.find_1 by (apply Table.add_1; reflexivity).
311+
reflexivity.
312+
rewrite fold_add_ignore.
313+
reflexivity.
314+
intros.
315+
destruct (Keys.eq_dec k k'); try contradiction.
316+
auto.
317+
Qed.
318+
227319
End FMapAVL_extra.
228320

229321
Module Demonstration.
@@ -276,34 +368,39 @@ Lemma add_to_table_correct:
276368
Proof.
277369
intros.
278370
pose (lift (k: Table.key) p := Z.pos p).
279-
pose proof relate_fold_add Z.eq_equiv lift
371+
pose (oldnew := Z.to_pos (lift k p + match Table.find (elt:=positive) k tab with
372+
| Some x => lift k x
373+
| None => 0
374+
end)).
375+
pose proof relate_fold_add_alt Z.eq_equiv lift
280376
ltac:(intros; rewrite H; auto)
281377
Z.add
282378
ltac:(intros; subst; auto)
283379
Z.add_assoc Z.add_comm
284380
Z0
285381
Z.add_0_l
286-
(fun k p x => Z.add (Z.pos p) x)
287-
ltac:(intros; subst; reflexivity).
288-
unfold addup_table.
289-
rewrite (H (add_to_table k p tab) k).
290-
rewrite (H tab k).
291-
clear H.
292-
unfold add_to_table.
293-
destruct (Table.find k tab) eqn:?H;
294-
rewrite (Table.find_1 (Table.add_1 tab _ (eq_refl k)));
295-
rewrite fold_add_ignore
296-
by (intros; rewrite <- H0;
297-
destruct (Keys.compare k k); auto; contradiction (Z.lt_irrefl k l));
382+
(fun k p x => Z.add (lift k p) x)
383+
ltac:(intros; subst; reflexivity)
384+
tab k p oldnew.
385+
unfold addup_table, add_to_table.
386+
set (f := fun (k : Table.key) (p : positive) (x : Z) => (lift k p + x)%Z) in *.
387+
change (fun (_ : Table.key) (p1 : positive) (i : Z) => (Z.pos p1 + i)%Z) with f in *.
388+
rewrite Z.add_comm.
389+
change (Z.pos p) with (lift k p).
390+
rewrite H; clear H.
391+
f_equal.
392+
destruct (Table.find k tab) eqn:?H; auto.
393+
unfold oldnew.
394+
set (b := match Table.find (elt:=positive) k tab with
395+
| Some x => lift k x
396+
| None => 0%Z
397+
end).
398+
assert (0 <= b)%Z.
399+
subst b.
298400
unfold lift.
299-
rewrite Pos.add_comm.
300-
rewrite Pos2Z.inj_add.
301-
rewrite <- !Z.add_assoc.
302-
rewrite (Z.add_comm (Z.pos p)).
303-
auto.
304-
set (u := Table.fold _ _ _).
305-
rewrite Z.add_0_l.
306-
apply Z.add_comm.
401+
destruct (Table.find (elt:=positive) k tab); simpl; Lia.lia.
402+
unfold lift.
403+
Lia.lia.
307404
Qed.
308405

309406
End Demonstration.

vcfloat/Prune.v

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,41 +2694,51 @@ unfold add_to_table.
26942694
destruct nt as [k it].
26952695
set (j := cancel1_intable (find_default [] k tab) it).
26962696
pose (lift k x := reflect_intable_simple k x zeroexpr).
2697-
pose proof relate_fold_add expr_equiv_rel lift
2697+
set (f := Ebinary Add).
2698+
set (u := zeroexpr).
2699+
(*
2700+
pose (oldnew :=
2701+
Ebinary Add (lift k j) match Table.find (elt:=intable_t) k tab with
2702+
| Some x => lift k x
2703+
| None => zeroexpr
2704+
end).
2705+
*)
2706+
pose proof relate_fold_add_alt expr_equiv_rel lift
26982707
ltac:(intros; apply reflect_intable_simple_mor; auto; reflexivity)
26992708
(Ebinary Add)
27002709
(Ebinary_mor Add Add (eq_refl _))
27012710
ltac:(intros; intro; simpl; ring)
27022711
ltac:(intros; intro; simpl; ring)
2703-
zeroexpr
2712+
u
27042713
ltac:(intros; intro; simpl; ring)
27052714
reflect_intable_simple
2706-
reflect_intable_simple_untangle.
2707-
etransitivity.
2708-
apply (H (Table.add k j tab) k).
2709-
change (lift k []) with zeroexpr.
2710-
pose proof (H tab k).
2711-
change (lift k []) with zeroexpr in H0.
2712-
rewrite H0; clear H H0.
2713-
rewrite fold_add_ignore.
2714-
2:{ intros. rewrite cmp_compare in H.
2715-
destruct (Keys.compare k k'); auto; discriminate.
2716-
}
2717-
set (u := Table.fold _ _ _); clearbody u. clear.
2718-
rewrite (Table.find_1 (Table.add_1 tab j (Keys.eq_refl k))).
2719-
subst j.
2715+
reflect_intable_simple_untangle
2716+
tab k [it] j.
2717+
rewrite <- H; clear H.
2718+
-
27202719
unfold lift at 1.
2720+
unfold f.
2721+
intro; simpl.
2722+
rewrite Rplus_comm.
2723+
f_equal.
2724+
symmetry.
2725+
rewrite reflect_powers_untangle.
2726+
simpl.
2727+
rewrite Rplus_0_r.
2728+
f_equal.
2729+
apply reflect_coeff_spec.
2730+
-
2731+
unfold lift.
2732+
subst j.
27212733
rewrite cancel1_intable_correct.
2722-
unfold reflect_intable_simple at 1.
2723-
simpl fold_right.
2734+
rewrite !reflect_intable_cons.
2735+
intro.
2736+
simpl.
2737+
f_equal.
2738+
apply Rplus_0_r.
27242739
unfold find_default.
27252740
fold intable_t.
2726-
rewrite reflect_normterm_spec.
2727-
destruct (Table.find k tab); subst lift; cbv beta.
2728-
fold (reflect_intable_simple k i zeroexpr).
2729-
set (v := reflect_intable_simple _ _ _). clearbody v.
2730-
intro; simpl; ring.
2731-
intro; simpl; ring.
2741+
destruct (Table.find (elt:=intable_t) k tab); simpl; auto.
27322742
Qed.
27332743

27342744
Definition reflect_intable_aux (al: intable_t) : expr :=

0 commit comments

Comments
 (0)