-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrevert.v
More file actions
48 lines (42 loc) · 1.27 KB
/
revert.v
File metadata and controls
48 lines (42 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Require Import List.
Import ListNotations.
Require Import Sumbool.
Ltac break_and :=
repeat match goal with
| [H : _ /\ _ |- _ ] => destruct H
end.
Ltac break_if :=
match goal with
| [ |- context [ if ?X then _ else _ ] ] =>
match type of X with
| sumbool _ _ => destruct X
| _ => destruct X eqn:?
end
end.
Definition update2 {A B : Type} (A_eq_dec : forall x y : A, {x = y} + {x <> y}) (f : A -> A -> B) (x y : A) (v : B) :=
fun x' y' => if sumbool_and _ _ _ _ (A_eq_dec x x') (A_eq_dec y y') then v else f x' y'.
Fixpoint collate {A B : Type} (A_eq_dec : forall x y : A, {x = y} + {x <> y}) (from : A) (f : A -> A -> list B) (ms : list (A * B)) :=
match ms with
| [] => f
| (to, m) :: ms' => collate A_eq_dec from (update2 A_eq_dec f from to (f from to ++ [m])) ms'
end.
Section Update2.
Variables A B : Type.
Hypothesis A_eq_dec : forall x y : A, {x = y} + {x <> y}.
Lemma collate_neq :
forall h n n' ns (f : A -> A -> list B),
h <> n ->
collate A_eq_dec h f ns n n' = f n n'.
Proof using.
intros.
revert f.
induction ns; intros; auto.
destruct a.
simpl in *.
rewrite IHns.
unfold update2.
break_if; auto.
break_and; subst.
intuition.
Qed.
End Update2.