Skip to content

Commit 28cafe6

Browse files
author
Gregory Malecha
committed
Clean up for some eq_ lemmas
- eq_option_eq moved to Data.Option - eq_list_eq added to Data.List - Changed Tactics.Equality to contain rewrites for Data.Eq - Building rewrite database for eq_matches
1 parent 3ba620d commit 28cafe6

File tree

4 files changed

+93
-49
lines changed

4 files changed

+93
-49
lines changed

theories/Data/Eq.v

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,7 @@
44
Set Implicit Arguments.
55
Set Strict Implicit.
66

7-
Lemma eq_Arr_eq
8-
: forall T (a b : T) (pf : a = b) (F G : T -> Type) val x,
9-
match pf in _ = x return F x -> G x with
10-
| eq_refl => val
11-
end x =
12-
match pf in _ = x return G x with
13-
| eq_refl => val match eq_sym pf in _ = x return F x with
14-
| eq_refl => x
15-
end
16-
end.
17-
Proof.
18-
destruct pf. reflexivity.
19-
Qed.
7+
Create HintDb eq_rw discriminated.
208

219
Lemma eq_sym_eq
2210
: forall T (a b : T) (pf : a = b) (F : T -> Type) val,
@@ -29,6 +17,7 @@ Lemma eq_sym_eq
2917
Proof.
3018
destruct pf. reflexivity.
3119
Qed.
20+
Hint Rewrite eq_sym_eq : eq_rw.
3221

3322
Lemma match_eq_sym_eq
3423
: forall T (a b : T) (pf : a = b) F X,
@@ -40,6 +29,7 @@ Lemma match_eq_sym_eq
4029
Proof.
4130
destruct pf. reflexivity.
4231
Qed.
32+
Hint Rewrite match_eq_sym_eq : eq_rw.
4333

4434
Lemma match_eq_sym_eq'
4535
: forall T (a b : T) (pf : a = b) F X,
@@ -51,15 +41,8 @@ Lemma match_eq_sym_eq'
5141
Proof.
5242
destruct pf. reflexivity.
5343
Qed.
44+
Hint Rewrite match_eq_sym_eq' : eq_rw.
5445

55-
Lemma eq_Const_eq
56-
: forall T (a b : T) (pf : a = b) (R : Type) val,
57-
match pf in _ = x return R with
58-
| eq_refl => val
59-
end = val.
60-
Proof.
61-
destruct pf. reflexivity.
62-
Qed.
6346

6447
Lemma match_eq_match_eq
6548
: forall T F (a b : T) (pf : a = b) X Y,
@@ -74,17 +57,36 @@ Proof.
7457
intros. subst. auto.
7558
Qed.
7659

77-
(** TODO: This should move to [option] **)
78-
Lemma eq_option_eq
79-
: forall T (a b : T) (pf : a = b) (F : _ -> Type) val,
80-
match pf in _ = x return option (F x) with
60+
Lemma eq_sym_eq_trans
61+
: forall T (a b c : T) (pf : a = b) (pf' : b = c),
62+
eq_sym (eq_trans pf pf') =
63+
eq_trans (eq_sym pf') (eq_sym pf).
64+
Proof.
65+
clear. destruct pf. destruct pf'. reflexivity.
66+
Qed.
67+
68+
(** Particular Instances **)
69+
Lemma eq_Const_eq
70+
: forall T (a b : T) (pf : a = b) (R : Type) val,
71+
match pf in _ = x return R with
72+
| eq_refl => val
73+
end = val.
74+
Proof.
75+
destruct pf. reflexivity.
76+
Qed.
77+
Hint Rewrite eq_Const_eq : eq_rw.
78+
79+
Lemma eq_Arr_eq
80+
: forall T (a b : T) (pf : a = b) (F G : T -> Type) val x,
81+
match pf in _ = x return F x -> G x with
8182
| eq_refl => val
82-
end = match val with
83-
| None => None
84-
| Some val => Some match pf in _ = x return F x with
85-
| eq_refl => val
86-
end
87-
end.
83+
end x =
84+
match pf in _ = x return G x with
85+
| eq_refl => val match eq_sym pf in _ = x return F x with
86+
| eq_refl => x
87+
end
88+
end.
8889
Proof.
89-
destruct pf. destruct val; reflexivity.
90-
Qed.
90+
destruct pf. reflexivity.
91+
Qed.
92+
Hint Rewrite eq_Arr_eq : eq_rw.

theories/Data/List.v

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Section type.
2222
}.
2323

2424
Context {typeOk_T : typeOk type_T}.
25-
25+
2626
Instance typeOk_list : typeOk type_list.
2727
Proof.
2828
constructor.
@@ -31,12 +31,12 @@ Section type.
3131
{ apply only_proper in H; auto. intuition; constructor; intuition. } }
3232
{ intro. induction x; intros.
3333
{ constructor. }
34-
{ inversion H; clear H; subst.
35-
constructor; auto.
34+
{ inversion H; clear H; subst.
35+
constructor; auto.
3636
apply equiv_prefl; auto. apply IHx. apply H3. } }
3737
{ intro. induction 1; constructor; auto.
3838
apply equiv_sym; auto. }
39-
{ intro. do 3 intro. revert z. induction H.
39+
{ intro. do 3 intro. revert z. induction H.
4040
{ remember nil. destruct 1; try congruence. constructor. }
4141
{ remember (y :: ys). destruct 1; try congruence. inversion Heql; clear Heql; subst.
4242
constructor. eapply equiv_trans; eauto. eapply IHlist_eq. apply H2. } }
@@ -76,6 +76,17 @@ Section AllB.
7676
end.
7777
End AllB.
7878

79+
Lemma Forall_map
80+
: forall T U (f : T -> U) P ls,
81+
Forall P (List.map f ls) <-> Forall (fun x => P (f x)) ls.
82+
Proof.
83+
induction ls; simpl.
84+
{ split; intros; constructor. }
85+
{ split; inversion 1; intros; subst; constructor; auto.
86+
apply IHls. auto. apply IHls. auto. }
87+
Qed.
88+
89+
7990
Global Instance Foldable_list {T} : Foldable (list T) T :=
8091
fun _ f x ls => fold_right f x ls.
8192

@@ -158,4 +169,16 @@ Section ListEq.
158169

159170
End ListEq.
160171

161-
Export List.
172+
Lemma eq_list_eq
173+
: forall T (a b : T) (pf : a = b) (F : _ -> Type) val,
174+
match pf in _ = x return list (F x) with
175+
| eq_refl => val
176+
end = map (fun val => match pf in _ = x return F x with
177+
| eq_refl => val
178+
end) val.
179+
Proof.
180+
destruct pf. intros. rewrite map_id. reflexivity.
181+
Qed.
182+
Hint Rewrite eq_list_eq : eq_rw.
183+
184+
Export Coq.Lists.List.

theories/Data/Option.v

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,19 @@ Section OptionEq.
141141
Qed.
142142

143143
End OptionEq.
144+
145+
Lemma eq_option_eq
146+
: forall T (a b : T) (pf : a = b) (F : _ -> Type) val,
147+
match pf in _ = x return option (F x) with
148+
| eq_refl => val
149+
end = match val with
150+
| None => None
151+
| Some val => Some match pf in _ = x return F x with
152+
| eq_refl => val
153+
end
154+
end.
155+
Proof.
156+
destruct pf. destruct val; reflexivity.
157+
Qed.
158+
159+
Hint Rewrite eq_option_eq : eq_rw.

theories/Tactics/Equality.v

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
Require Import ExtLib.Structures.EqDep.
2-
3-
Ltac existT_inj :=
4-
repeat match goal with
5-
| [ H : @existT _ _ ?X ?Y = @existT _ _ ?X ?Y |- _ ] =>
6-
clear H
7-
| [ H : @existT _ _ ?X ?Y = @existT _ _ ?X ?Z |- _ ] =>
8-
eapply inj_pair2 in H
9-
| [ H : @existT _ _ ?X _ = @existT _ _ ?Y _ |- _ ] =>
10-
inversion H
11-
end.
1+
Require Import ExtLib.Data.Eq.
2+
3+
Ltac eq_rw_goal :=
4+
autorewrite with eq_rw.
5+
6+
Ltac eq_rw_hyp H :=
7+
autorewrite with eq_rw in H.
8+
9+
Ltac eq_rw_star :=
10+
autorewrite with eq_rw in *.
11+
12+
Tactic Notation "eq_rw" := eq_rw_goal.
13+
Tactic Notation "eq_rw" "in" hyp(H) := eq_rw_hyp H.
14+
Tactic Notation "eq_rw" "in" "*" := eq_rw_star.

0 commit comments

Comments
 (0)