Skip to content

Commit fe8cc83

Browse files
committed
intial commit
0 parents  commit fe8cc83

11 files changed

+472
-0
lines changed

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*.vo
2+
*.glob
3+
*.v.d
4+
Makefile.coq
5+
Makefile.coq.bak
6+
Makefile.coq.conf
7+
*~
8+
.coq-native/
9+
*.aux
10+
*.vio
11+
.coqdeps.d

_CoqProject

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
clear.v
2+
eauto.v
3+
exists.v
4+
firstorder.v
5+
intros.v
6+
revert.v
7+
specialize.v
8+
subst.v
9+
symmetry.v

clear.v

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Require Import List.
2+
Import ListNotations.
3+
Require Import Sumbool.
4+
5+
Ltac break_let :=
6+
match goal with
7+
| [ H : context [ (let (_,_) := ?X in _) ] |- _ ] => destruct X eqn:?
8+
| [ |- context [ (let (_,_) := ?X in _) ] ] => destruct X eqn:?
9+
end.
10+
11+
Ltac find_injection :=
12+
match goal with
13+
| [ H : ?X _ _ = ?X _ _ |- _ ] => injection H; intros; subst
14+
end.
15+
16+
Ltac break_and :=
17+
repeat match goal with
18+
| [H : _ /\ _ |- _ ] => destruct H
19+
end.
20+
21+
Ltac break_if :=
22+
match goal with
23+
| [ |- context [ if ?X then _ else _ ] ] =>
24+
match type of X with
25+
| sumbool _ _ => destruct X
26+
| _ => destruct X eqn:?
27+
end
28+
end.
29+
30+
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) :=
31+
fun x' y' => if sumbool_and _ _ _ _ (A_eq_dec x x') (A_eq_dec y y') then v else f x' y'.
32+
33+
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)) :=
34+
match ms with
35+
| [] => f
36+
| (to, m) :: ms' => collate A_eq_dec from (update2 A_eq_dec f from to (f from to ++ [m])) ms'
37+
end.
38+
39+
Section Update2.
40+
Variables A B : Type.
41+
Hypothesis A_eq_dec : forall x y : A, {x = y} + {x <> y}.
42+
43+
Lemma collate_f_eq :
44+
forall (f : A -> A -> list B) g h n n' l,
45+
f n n' = g n n' ->
46+
collate A_eq_dec h f l n n' = collate A_eq_dec h g l n n'.
47+
Proof using.
48+
intros f g h n n' l.
49+
generalize f g; clear f g.
50+
induction l; auto.
51+
intros.
52+
simpl in *.
53+
break_let.
54+
destruct a.
55+
find_injection.
56+
set (f' := update2 _ _ _ _ _).
57+
set (g' := update2 _ _ _ _ _).
58+
rewrite (IHl f' g'); auto.
59+
unfold f', g', update2.
60+
break_if; auto.
61+
break_and.
62+
subst.
63+
rewrite H.
64+
trivial.
65+
Qed.
66+
End Update2.

eauto.v

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Require Import List.
2+
Import ListNotations.
3+
4+
Set Implicit Arguments.
5+
6+
Section list_util.
7+
Variables A : Type.
8+
9+
Lemma in_firstn : forall n (x : A) xs,
10+
In x (firstn n xs) -> In x xs.
11+
Proof using.
12+
induction n; simpl; intuition.
13+
destruct xs;simpl in *; intuition.
14+
Qed.
15+
16+
Lemma firstn_NoDup : forall n (xs : list A),
17+
NoDup xs ->
18+
NoDup (firstn n xs).
19+
Proof using.
20+
induction n; intros; simpl; destruct xs; auto.
21+
- apply NoDup_nil.
22+
- inversion H; subst.
23+
apply NoDup_cons.
24+
* eauto 6 using in_firstn.
25+
* apply IHn; auto.
26+
Qed.
27+
End list_util.

exists.v

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Require Import List.
2+
Import ListNotations.
3+
4+
Set Implicit Arguments.
5+
6+
Fixpoint before {A: Type} (x : A) y l : Prop :=
7+
match l with
8+
| [] => False
9+
| a :: l' =>
10+
a = x \/
11+
(a <> y /\ before x y l')
12+
end.
13+
14+
Section before.
15+
Variable A : Type.
16+
17+
Lemma before_In :
18+
forall x y l,
19+
before (A:=A) x y l ->
20+
In x l.
21+
Proof using.
22+
induction l; intros; simpl in *; intuition.
23+
Qed.
24+
25+
Lemma before_split :
26+
forall l (x y : A),
27+
before x y l ->
28+
x <> y ->
29+
In x l ->
30+
In y l ->
31+
exists xs ys zs,
32+
l = xs ++ x :: ys ++ y :: zs.
33+
Proof using.
34+
induction l; intros; simpl in *; intuition; subst; try congruence.
35+
- exists []. simpl.
36+
apply in_split in H1.
37+
destruct H1; destruct H1.
38+
subst. eauto.
39+
- exists []. simpl.
40+
apply in_split in H1.
41+
destruct H1; destruct H1. subst. eauto.
42+
- exists []. simpl.
43+
apply in_split in H1.
44+
destruct H1; destruct H1. subst. eauto.
45+
- match goal with
46+
| [ H : context [ In ], H' : context [ In ] |- _ ] =>
47+
eapply H in H'
48+
end; eauto.
49+
destruct H1; destruct H1; destruct H1. subst.
50+
exists (a :: x0), x1, x2. auto.
51+
Qed.
52+
End before.

firstorder.v

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
Require Import List.
2+
Import ListNotations.
3+
4+
Set Implicit Arguments.
5+
6+
Fixpoint fin (n : nat) : Type :=
7+
match n with
8+
| 0 => False
9+
| S n' => option (fin n')
10+
end.
11+
12+
Fixpoint fin_eq_dec (n : nat) : forall (a b : fin n), {a = b} + {a <> b}.
13+
refine
14+
(match n with
15+
| 0 => fun a b : fin 0 => right (match b with end)
16+
| S n' => fun a b : fin (S n') =>
17+
match a, b with
18+
| Some a', Some b' =>
19+
match fin_eq_dec n' a' b' with
20+
| left _ _ => left _
21+
| right _ _ => right _
22+
end
23+
| Some a', None => right _
24+
| None, Some b' => right _
25+
| None, None => left eq_refl
26+
end
27+
end); congruence.
28+
Defined.
29+
30+
Fixpoint all_fin (n : nat) : list (fin n) :=
31+
match n with
32+
| 0 => []
33+
| S n' => None :: map (fun x => Some x) (all_fin n')
34+
end.
35+
36+
Lemma all_fin_all :
37+
forall n (x : fin n),
38+
In x (all_fin n).
39+
Proof.
40+
induction n; intros.
41+
- inversion x.
42+
- simpl in *. destruct x; auto using in_map.
43+
Qed.
44+
45+
Lemma NoDup_map_injective : forall A B (f : A -> B) xs,
46+
(forall x y, In x xs -> In y xs ->
47+
f x = f y -> x = y) ->
48+
NoDup xs -> NoDup (map f xs).
49+
Proof using.
50+
induction xs; intros.
51+
- constructor.
52+
- simpl. inversion H0. subst. constructor.
53+
+ intro.
54+
apply in_map_iff in H1.
55+
destruct H1.
56+
destruct H1.
57+
assert (x = a) by intuition.
58+
subst.
59+
congruence.
60+
+ intuition.
61+
Qed.
62+
63+
Lemma all_fin_NoDup :
64+
forall n, NoDup (all_fin n).
65+
Proof.
66+
induction n; intros; simpl; constructor.
67+
- intro. apply in_map_iff in H. firstorder. discriminate.
68+
- apply NoDup_map_injective; auto. congruence.
69+
Qed.

intros.v

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Require Import List.
2+
Import ListNotations.
3+
4+
Set Implicit Arguments.
5+
6+
Section list_util.
7+
Variables A B : Type.
8+
Hypothesis A_eq_dec : forall x y : A, {x = y} + {x <> y}.
9+
10+
Lemma In_cons_neq :
11+
forall a x xs,
12+
In(A:=A) a (x :: xs) ->
13+
a <> x ->
14+
In a xs.
15+
Proof using.
16+
simpl.
17+
intuition congruence.
18+
Qed.
19+
20+
Lemma in_fold_left_by_cons_in :
21+
forall (l : list B) (g : B -> A) x acc,
22+
In x (fold_left (fun a b => g b :: a) l acc) ->
23+
In x acc \/ exists y, In y l /\ x = g y.
24+
Proof using A_eq_dec.
25+
intros until l.
26+
induction l.
27+
- auto.
28+
- simpl; intros.
29+
destruct (A_eq_dec x (g a)); subst.
30+
+ right; exists a; tauto.
31+
+ apply IHl in H.
32+
case H; [left|right].
33+
* apply In_cons_neq in H0; tauto.
34+
* destruct H0; destruct H0.
35+
exists x0; split; auto.
36+
Qed.
37+
End list_util.

revert.v

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

specialize.v

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Require Import List.
2+
Import ListNotations.
3+
4+
Set Implicit Arguments.
5+
6+
Ltac break_match :=
7+
match goal with
8+
| [ |- context [ match ?X with _ => _ end ] ] =>
9+
match type of X with
10+
| sumbool _ _ => destruct X
11+
| _ => destruct X eqn:?
12+
end
13+
end.
14+
15+
Ltac do_in_app :=
16+
match goal with
17+
| [ H : In _ (_ ++ _) |- _ ] => apply in_app_iff in H
18+
end.
19+
20+
Section dedup.
21+
Variable A : Type.
22+
Hypothesis A_eq_dec : forall x y : A, {x = y} + {x <> y}.
23+
24+
Fixpoint dedup (xs : list A) : list A :=
25+
match xs with
26+
| [] => []
27+
| x :: xs => let tail := dedup xs in
28+
if in_dec A_eq_dec x xs then
29+
tail
30+
else
31+
x :: tail
32+
end.
33+
34+
Lemma dedup_app : forall (xs ys : list A),
35+
(forall x y, In x xs -> In y ys -> x <> y) ->
36+
dedup (xs ++ ys) = dedup xs ++ dedup ys.
37+
Proof using.
38+
intros. induction xs; simpl; auto.
39+
repeat break_match.
40+
- apply IHxs.
41+
intros.
42+
apply H; intuition.
43+
- exfalso.
44+
specialize (H a a).
45+
apply H; intuition.
46+
do_in_app.
47+
intuition.
48+
- exfalso.
49+
apply n.
50+
intuition.
51+
- simpl.
52+
f_equal.
53+
apply IHxs.
54+
intros.
55+
apply H; intuition.
56+
Qed.
57+
58+
End dedup.

0 commit comments

Comments
 (0)