| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Pointwise lifting of relations to lists |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.List.Relation.Binary.Pointwise.Base where |
| 10 |
|
| 11 |
open import Data.Product.Base as Product using (_×_; _,_; <_,_>; ∃-syntax) |
| 12 |
open import Data.List.Base using (List; []; _∷_) |
| 13 |
open import Level using (Level; _⊔_) |
| 14 |
open import Relation.Binary.Core using (REL; _⇒_) |
| 15 |
open import Relation.Binary.Construct.Composition using (_;_) |
| 16 |
|
| 17 |
private |
| 18 |
variable |
| 19 |
a b c ℓ : Level |
| 20 |
A B : Set a |
| 21 |
x y : A |
| 22 |
xs ys : List A |
| 23 |
R S : REL A B ℓ |
| 24 |
|
| 25 |
------------------------------------------------------------------------ |
| 26 |
-- Definition |
| 27 |
------------------------------------------------------------------------ |
| 28 |
|
| 29 |
infixr 5 _∷_ |
| 30 |
|
| 31 |
data Pointwise {A : Set a} {B : Set b} (R : REL A B ℓ) |
| 32 |
: List A → List B → Set (a ⊔ b ⊔ ℓ) where |
| 33 |
[] : Pointwise R [] [] |
| 34 |
_∷_ : (x∼y : R x y) (xs∼ys : Pointwise R xs ys) → |
| 35 |
Pointwise R (x ∷ xs) (y ∷ ys) |
| 36 |
|
| 37 |
------------------------------------------------------------------------ |
| 38 |
-- Operations |
| 39 |
------------------------------------------------------------------------ |
| 40 |
|
| 41 |
head : Pointwise R (x ∷ xs) (y ∷ ys) → R x y |
| 42 |
head (x∼y ∷ xs∼ys) = x∼y |
| 43 |
|
| 44 |
tail : Pointwise R (x ∷ xs) (y ∷ ys) → Pointwise R xs ys |
| 45 |
tail (x∼y ∷ xs∼ys) = xs∼ys |
| 46 |
|
| 47 |
uncons : Pointwise R (x ∷ xs) (y ∷ ys) → R x y × Pointwise R xs ys |
| 48 |
uncons = < head , tail > |
| 49 |
|
| 50 |
rec : ∀ (P : ∀ {xs ys} → Pointwise R xs ys → Set c) → |
| 51 |
(∀ {x y xs ys} {Rxsys : Pointwise R xs ys} → |
| 52 |
(Rxy : R x y) → P Rxsys → P (Rxy ∷ Rxsys)) → |
| 53 |
P [] → |
| 54 |
∀ {xs ys} (Rxsys : Pointwise R xs ys) → P Rxsys |
| 55 |
rec P c n [] = n |
| 56 |
rec P c n (Rxy ∷ Rxsys) = c Rxy (rec P c n Rxsys) |
| 57 |
|
| 58 |
map : R ⇒ S → Pointwise R ⇒ Pointwise S |
| 59 |
map R⇒S [] = [] |
| 60 |
map R⇒S (Rxy ∷ Rxsys) = R⇒S Rxy ∷ map R⇒S Rxsys |
| 61 |
|
| 62 |
unzip : Pointwise (R ; S) ⇒ (Pointwise R ; Pointwise S) |
| 63 |
unzip [] = [] , [] , [] |
| 64 |
unzip ((y , r , s) ∷ xs∼ys) = |
| 65 |
Product.map (y ∷_) (Product.map (r ∷_) (s ∷_)) (unzip xs∼ys) |