-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclear.v
More file actions
66 lines (58 loc) · 1.76 KB
/
clear.v
File metadata and controls
66 lines (58 loc) · 1.76 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Require Import List.
Import ListNotations.
Require Import Sumbool.
Ltac break_let :=
match goal with
| [ H : context [ (let (_,_) := ?X in _) ] |- _ ] => destruct X eqn:?
| [ |- context [ (let (_,_) := ?X in _) ] ] => destruct X eqn:?
end.
Ltac find_injection :=
match goal with
| [ H : ?X _ _ = ?X _ _ |- _ ] => injection H; intros; subst
end.
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_f_eq :
forall (f : A -> A -> list B) g h n n' l,
f n n' = g n n' ->
collate A_eq_dec h f l n n' = collate A_eq_dec h g l n n'.
Proof using.
intros f g h n n' l.
generalize f g; clear f g.
induction l; auto.
intros.
simpl in *.
break_let.
destruct a.
find_injection.
set (f' := update2 _ _ _ _ _).
set (g' := update2 _ _ _ _ _).
rewrite (IHl f' g'); auto.
unfold f', g', update2.
break_if; auto.
break_and.
subst.
rewrite H.
trivial.
Qed.
End Update2.