Skip to content

Commit 7ef44be

Browse files
Added more theorems to PPair and PList
1 parent cf05e57 commit 7ef44be

File tree

2 files changed

+57
-20
lines changed

2 files changed

+57
-20
lines changed

theories/Data/PList.v

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Require Import ExtLib.Structures.Functor.
22
Require Import ExtLib.Structures.Applicative.
33
Require Import ExtLib.Data.POption.
4+
Require Import ExtLib.Data.PPair.
45
Require Import ExtLib.Core.RelDec.
56
Require Import ExtLib.Tactics.Consider.
67

@@ -66,7 +67,7 @@ Section plist.
6667
Polymorphic Fixpoint allb (p : T -> bool) (lst : plist) : bool :=
6768
match lst with
6869
| pnil => true
69-
| pcons l ls => if p l then anyb p ls else false
70+
| pcons l ls => if p l then allb p ls else false
7071
end.
7172

7273
Polymorphic Fixpoint nodup {RelDecA : RelDec (@eq T)} (lst : plist) :=
@@ -104,6 +105,7 @@ End plist.
104105

105106
Arguments pnil {_}.
106107
Arguments pcons {_} _ _.
108+
Arguments app {_} _ _.
107109
Arguments pIn {_} _ _.
108110
Arguments pNoDup {_} _.
109111
Arguments anyb {_} _ _.
@@ -116,12 +118,44 @@ Arguments nth_error {_} _ _.
116118

117119

118120
Section plistFun.
119-
Polymorphic Fixpoint split {A B : Type} (lst : plist ((A * B)%type)) :=
121+
Polymorphic Fixpoint split {A B : Type} (lst : plist (ppair A B)) :=
120122
match lst with
121123
| pnil => (pnil, pnil)
122-
| pcons (x, y) tl => let (left, right) := split tl in (pcons x left, pcons y right)
124+
| pcons (pprod x y) tl => let (left, right) := split tl in (pcons x left, pcons y right)
123125
end.
124126

127+
Lemma pIn_split_l {A B : Type} (lst : plist (ppair A B)) (p : ppair A B) (H : pIn p lst) :
128+
(pIn (pfst p) (fst (split lst))).
129+
Proof.
130+
destruct p; simpl.
131+
induction lst; simpl in *.
132+
+ destruct H.
133+
+ destruct t; simpl.
134+
destruct (split lst); simpl.
135+
destruct H as [H | H]; [
136+
inversion H; left; reflexivity |
137+
right; apply IHlst; apply H].
138+
Qed.
139+
140+
Lemma pIn_split_r {A B : Type} (lst : plist (ppair A B)) (p : ppair A B) (H : pIn p lst) :
141+
(pIn (psnd p) (snd (split lst))).
142+
Proof.
143+
destruct p; simpl.
144+
induction lst; simpl in *.
145+
+ destruct H.
146+
+ destruct t; simpl.
147+
destruct (split lst); simpl.
148+
destruct H as [H | H]; [
149+
inversion H; left; reflexivity |
150+
right; apply IHlst; apply H].
151+
Qed.
152+
153+
Lemma pIn_app_iff (A : Type) (l l' : plist A) (a : A) :
154+
pIn a (app l l') <-> pIn a l \/ pIn a l'.
155+
Proof.
156+
induction l; simpl; intuition congruence.
157+
Qed.
158+
125159
End plistFun.
126160

127161
Section plistOk.
@@ -192,7 +226,7 @@ Section applicative.
192226
: plist@{j} U :=
193227
match fs with
194228
| pnil => pnil
195-
| pcons f fs => app@{j} _ (fmap_plist@{i j} f xs) (ap_plist fs xs)
229+
| pcons f fs => app@{j} (fmap_plist@{i j} f xs) (ap_plist fs xs)
196230
end.
197231
End applicative.
198232

@@ -202,10 +236,11 @@ Polymorphic Definition Applicative_plist@{i} : Applicative@{i i} plist@{i} :=
202236
|}.
203237

204238
Section PListEq.
205-
Variable T : Type.
239+
Polymorphic Universe i.
240+
Variable T : Type@{i}.
206241
Variable EDT : RelDec (@eq T).
207242

208-
Fixpoint plist_eqb (ls rs : plist T) : bool :=
243+
Polymorphic Fixpoint plist_eqb (ls rs : plist T) : bool :=
209244
match ls , rs with
210245
| pnil , pnil => true
211246
| pcons l ls , pcons r rs =>
@@ -214,12 +249,12 @@ Section PListEq.
214249
end.
215250

216251
(** Specialization for equality **)
217-
Global Instance RelDec_eq_plist : RelDec (@eq (plist T)) :=
252+
Global Polymorphic Instance RelDec_eq_plist : RelDec (@eq (plist T)) :=
218253
{ rel_dec := plist_eqb }.
219254

220255
Variable EDCT : RelDec_Correct EDT.
221256

222-
Global Instance RelDec_Correct_eq_plist : RelDec_Correct RelDec_eq_plist.
257+
Global Polymorphic Instance RelDec_Correct_eq_plist : RelDec_Correct RelDec_eq_plist.
223258
Proof.
224259
constructor; induction x; destruct y; split; simpl in *; intros;
225260
repeat match goal with

theories/Data/PPair.v

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,47 @@ Require Import ExtLib.Core.RelDec.
22

33
Set Printing Universes.
44
Set Primitive Projections.
5-
5+
Set Universe Polymorphism.
66
Section pair.
77
Polymorphic Universes i j.
8-
Context {T : Type@{i}} {U : Type@{j}}.
8+
Variable (T : Type@{i}) (U : Type@{j}).
99

10-
Polymorphic Inductive ppair : Type :=
10+
Polymorphic Inductive ppair : Type@{max (i, j)} :=
1111
| pprod : T -> U -> ppair.
1212

13-
Polymorphic Definition fst (p : ppair) :=
13+
Polymorphic Definition pfst (p : ppair) :=
1414
match p with
1515
| pprod t _ => t
1616
end.
1717

18-
Polymorphic Definition snd (p : ppair) :=
18+
Polymorphic Definition psnd (p : ppair) :=
1919
match p with
2020
| pprod _ u => u
2121
end.
2222

2323
End pair.
2424

2525
Arguments ppair _ _.
26-
Arguments fst {_ _} _.
27-
Arguments snd {_ _} _.
26+
Arguments pprod {_ _} _ _.
27+
Arguments pfst {_ _} _.
28+
Arguments psnd {_ _} _.
2829

2930
Section PProdEq.
30-
Context {T U : Type}.
31+
Polymorphic Universes i j.
32+
Context {T : Type@{i}} {U : Type@{j}}.
3133
Context {EDT : RelDec (@eq T)}.
3234
Context {EDU : RelDec (@eq U)}.
3335
Context {EDCT : RelDec_Correct EDT}.
3436
Context {EDCU : RelDec_Correct EDU}.
3537

36-
Definition ppair_eqb (p1 p2 : @ppair T U) : bool :=
37-
fst p1 ?[ eq ] fst p2 && snd p1 ?[ eq ] snd p2.
38+
Polymorphic Definition ppair_eqb (p1 p2 : ppair T U) : bool :=
39+
pfst p1 ?[ eq ] pfst p2 && psnd p1 ?[ eq ] psnd p2.
3840

3941
(** Specialization for equality **)
40-
Global Instance RelDec_eq_ppair : RelDec (@eq (@ppair T U)) :=
42+
Global Polymorphic Instance RelDec_eq_ppair : RelDec (@eq (@ppair T U)) :=
4143
{ rel_dec := ppair_eqb }.
4244

43-
Global Instance RelDec_Correct_eq_ppair : RelDec_Correct RelDec_eq_ppair.
45+
Global Polymorphic Instance RelDec_Correct_eq_ppair : RelDec_Correct RelDec_eq_ppair.
4446
Proof.
4547
constructor. intros p1 p2. destruct p1, p2. simpl.
4648
unfold ppair_eqb. simpl.

0 commit comments

Comments
 (0)