6
6
7
7
{-# OPTIONS --without-K --safe #-}
8
8
9
- module Data.List.Relation.Unary.AllPairs where
9
+ open import Relation.Binary using (Rel)
10
+
11
+ module Data.List.Relation.Unary.AllPairs
12
+ {a ℓ} {A : Set a} {R : Rel A ℓ} where
10
13
11
14
open import Data.List using (List; []; _∷_)
12
15
open import Data.List.Relation.Unary.All as All using (All; []; _∷_)
@@ -23,65 +26,54 @@ import Relation.Nullary.Decidable as Dec
23
26
------------------------------------------------------------------------
24
27
-- Definition
25
28
26
- -- AllPairs R xs means that every pair of elements (x , y) in xs is a
27
- -- member of relation R (as long as x comes before y in the list).
28
-
29
- infixr 5 _∷_
30
-
31
- data AllPairs {a ℓ} {A : Set a} (R : Rel A ℓ) : List A → Set (a ⊔ ℓ) where
32
- [] : AllPairs R []
33
- _∷_ : ∀ {x xs} → All (R x) xs → AllPairs R xs → AllPairs R (x ∷ xs)
29
+ open import Data.List.Relation.Unary.AllPairs.Core public
34
30
35
31
------------------------------------------------------------------------
36
32
-- Operations
37
33
38
- module _ {a ℓ} {A : Set a} {R : Rel A ℓ} where
34
+ head : ∀ {x xs} → AllPairs R (x ∷ xs) → All (R x) xs
35
+ head (px ∷ pxs) = px
39
36
40
- head : ∀ {x xs} → AllPairs R (x ∷ xs) → All (R x) xs
41
- head (px ∷ pxs) = px
37
+ tail : ∀ {x xs} → AllPairs R (x ∷ xs) → AllPairs R xs
38
+ tail (px ∷ pxs) = pxs
42
39
43
- tail : ∀ {x xs} → AllPairs R (x ∷ xs) → AllPairs R xs
44
- tail (px ∷ pxs) = pxs
45
-
46
- module _ {a p q} {A : Set a} {R : Rel A p} {S : Rel A q} where
40
+ module _ {q} {S : Rel A q} where
47
41
48
42
map : R ⇒ S → AllPairs R ⊆ AllPairs S
49
43
map ~₁⇒~₂ [] = []
50
44
map ~₁⇒~₂ (x~xs ∷ pxs) = All.map ~₁⇒~₂ x~xs ∷ (map ~₁⇒~₂ pxs)
51
45
52
- module _ {a p q r } {A : Set a} {P : Rel A p } {Q : Rel A q} {R : Rel A r } where
46
+ module _ {s t } {S : Rel A s } {T : Rel A t } where
53
47
54
- zipWith : P ∩ᵇ Q ⇒ R → AllPairs P ∩ᵘ AllPairs Q ⊆ AllPairs R
48
+ zipWith : R ∩ᵇ S ⇒ T → AllPairs R ∩ᵘ AllPairs S ⊆ AllPairs T
55
49
zipWith f ([] , []) = []
56
50
zipWith f (px ∷ pxs , qx ∷ qxs) = All.zipWith f (px , qx) ∷ zipWith f (pxs , qxs)
57
51
58
- unzipWith : R ⇒ P ∩ᵇ Q → AllPairs R ⊆ AllPairs P ∩ᵘ AllPairs Q
52
+ unzipWith : T ⇒ R ∩ᵇ S → AllPairs T ⊆ AllPairs R ∩ᵘ AllPairs S
59
53
unzipWith f [] = [] , []
60
54
unzipWith f (rx ∷ rxs) = Prod.zip _∷_ _∷_ (All.unzipWith f rx) (unzipWith f rxs)
61
55
62
- module _ {a p q } {A : Set a} {P : Rel A p} {Q : Rel A q } where
56
+ module _ {s } {S : Rel A s } where
63
57
64
- zip : AllPairs P ∩ᵘ AllPairs Q ⊆ AllPairs (P ∩ᵇ Q )
58
+ zip : AllPairs R ∩ᵘ AllPairs S ⊆ AllPairs (R ∩ᵇ S )
65
59
zip = zipWith id
66
60
67
- unzip : AllPairs (P ∩ᵇ Q ) ⊆ AllPairs P ∩ᵘ AllPairs Q
61
+ unzip : AllPairs (R ∩ᵇ S ) ⊆ AllPairs R ∩ᵘ AllPairs S
68
62
unzip = unzipWith id
69
63
70
64
------------------------------------------------------------------------
71
65
-- Properties of predicates preserved by AllPairs
72
66
73
- module _ {a ℓ} {A : Set a} {R : Rel A ℓ} where
74
-
75
- allPairs? : B.Decidable R → U.Decidable (AllPairs R)
76
- allPairs? R? [] = yes []
77
- allPairs? R? (x ∷ xs) with All.all (R? x) xs
78
- ... | yes px = Dec.map′ (px ∷_) tail (allPairs? R? xs)
79
- ... | no ¬px = no (¬px ∘ head)
67
+ allPairs? : B.Decidable R → U.Decidable (AllPairs R)
68
+ allPairs? R? [] = yes []
69
+ allPairs? R? (x ∷ xs) with All.all (R? x) xs
70
+ ... | yes px = Dec.map′ (px ∷_) tail (allPairs? R? xs)
71
+ ... | no ¬px = no (¬px ∘ head)
80
72
81
- irrelevant : B.Irrelevant R → U.Irrelevant (AllPairs R)
82
- irrelevant irr [] [] = refl
83
- irrelevant irr (px₁ ∷ pxs₁) (px₂ ∷ pxs₂) =
84
- cong₂ _∷_ (All.irrelevant irr px₁ px₂) (irrelevant irr pxs₁ pxs₂)
73
+ irrelevant : B.Irrelevant R → U.Irrelevant (AllPairs R)
74
+ irrelevant irr [] [] = refl
75
+ irrelevant irr (px₁ ∷ pxs₁) (px₂ ∷ pxs₂) =
76
+ cong₂ _∷_ (All.irrelevant irr px₁ px₂) (irrelevant irr pxs₁ pxs₂)
85
77
86
- satisfiable : U.Satisfiable (AllPairs R)
87
- satisfiable = [] , []
78
+ satisfiable : U.Satisfiable (AllPairs R)
79
+ satisfiable = [] , []
0 commit comments