Skip to content

Commit cf05e57

Browse files
Added more theorems to PList and PPair
1 parent 26d2300 commit cf05e57

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

theories/Data/PList.v

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ Section plist.
6363
| pcons l ls0 => if p l then true else anyb p ls0
6464
end.
6565

66-
Polymorphic Fixpoint allb (p : T -> bool) (ls : plist) : bool :=
67-
match ls with
66+
Polymorphic Fixpoint allb (p : T -> bool) (lst : plist) : bool :=
67+
match lst with
6868
| pnil => true
69-
| pcons l ls0 => if p l then anyb p ls0 else false
69+
| pcons l ls => if p l then anyb p ls else false
7070
end.
7171

7272
Polymorphic Fixpoint nodup {RelDecA : RelDec (@eq T)} (lst : plist) :=
@@ -115,6 +115,15 @@ Arguments fold_right {_ _} _ _ _.
115115
Arguments nth_error {_} _ _.
116116

117117

118+
Section plistFun.
119+
Polymorphic Fixpoint split {A B : Type} (lst : plist ((A * B)%type)) :=
120+
match lst with
121+
| pnil => (pnil, pnil)
122+
| pcons (x, y) tl => let (left, right) := split tl in (pcons x left, pcons y right)
123+
end.
124+
125+
End plistFun.
126+
118127
Section plistOk.
119128
Context {A : Type}.
120129
Context {RelDecA : RelDec (@eq A)}.

theories/Data/PPair.v

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
Require Import ExtLib.Core.RelDec.
22

33
Set Printing Universes.
44
Set Primitive Projections.
@@ -7,7 +7,46 @@ Section pair.
77
Polymorphic Universes i j.
88
Context {T : Type@{i}} {U : Type@{j}}.
99

10-
Polymorphic Record ppair : Type :=
11-
{ fst : T ; snd : U }.
10+
Polymorphic Inductive ppair : Type :=
11+
| pprod : T -> U -> ppair.
12+
13+
Polymorphic Definition fst (p : ppair) :=
14+
match p with
15+
| pprod t _ => t
16+
end.
17+
18+
Polymorphic Definition snd (p : ppair) :=
19+
match p with
20+
| pprod _ u => u
21+
end.
1222

1323
End pair.
24+
25+
Arguments ppair _ _.
26+
Arguments fst {_ _} _.
27+
Arguments snd {_ _} _.
28+
29+
Section PProdEq.
30+
Context {T U : Type}.
31+
Context {EDT : RelDec (@eq T)}.
32+
Context {EDU : RelDec (@eq U)}.
33+
Context {EDCT : RelDec_Correct EDT}.
34+
Context {EDCU : RelDec_Correct EDU}.
35+
36+
Definition ppair_eqb (p1 p2 : @ppair T U) : bool :=
37+
fst p1 ?[ eq ] fst p2 && snd p1 ?[ eq ] snd p2.
38+
39+
(** Specialization for equality **)
40+
Global Instance RelDec_eq_ppair : RelDec (@eq (@ppair T U)) :=
41+
{ rel_dec := ppair_eqb }.
42+
43+
Global Instance RelDec_Correct_eq_ppair : RelDec_Correct RelDec_eq_ppair.
44+
Proof.
45+
constructor. intros p1 p2. destruct p1, p2. simpl.
46+
unfold ppair_eqb. simpl.
47+
rewrite Bool.andb_true_iff.
48+
repeat rewrite rel_dec_correct.
49+
split; intuition congruence.
50+
Qed.
51+
52+
End PProdEq.

0 commit comments

Comments
 (0)