| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Pointwise lifting of binary relations to sigma types |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.Product.Relation.Binary.Pointwise.Dependent where |
| 10 |
|
| 11 |
open import Data.Product.Base as Product using (_×_; _,_; Σ; proj₁; proj₂) |
| 12 |
open import Level using (Level; _⊔_) |
| 13 |
open import Function.Base using (id) |
| 14 |
open import Relation.Binary.Core using (Rel; REL; _⇒_) |
| 15 |
open import Relation.Binary.Bundles using (Setoid) |
| 16 |
open import Relation.Binary.Structures using (IsEquivalence) |
| 17 |
open import Relation.Binary.Definitions as B |
| 18 |
using (Reflexive; Symmetric; Transitive) |
| 19 |
open import Relation.Binary.Indexed.Heterogeneous as I |
| 20 |
using (IREL; IRel; IndexedSetoid; IsIndexedEquivalence) |
| 21 |
open import Relation.Binary.PropositionalEquality.Core using (_≡_) |
| 22 |
|
| 23 |
------------------------------------------------------------------------ |
| 24 |
-- Pointwise lifting |
| 25 |
|
| 26 |
infixr 4 _,_ |
| 27 |
|
| 28 |
record POINTWISE {a₁ a₂ b₁ b₂ ℓ₁ ℓ₂} |
| 29 |
{A₁ : Set a₁} (B₁ : A₁ → Set b₁) |
| 30 |
{A₂ : Set a₂} (B₂ : A₂ → Set b₂) |
| 31 |
(_R₁_ : REL A₁ A₂ ℓ₁) (_R₂_ : IREL B₁ B₂ ℓ₂) |
| 32 |
(xy₁ : Σ A₁ B₁) (xy₂ : Σ A₂ B₂) |
| 33 |
: Set (a₁ ⊔ a₂ ⊔ b₁ ⊔ b₂ ⊔ ℓ₁ ⊔ ℓ₂) where |
| 34 |
constructor _,_ |
| 35 |
field |
| 36 |
proj₁ : (proj₁ xy₁) R₁ (proj₁ xy₂) |
| 37 |
proj₂ : (proj₂ xy₁) R₂ (proj₂ xy₂) |
| 38 |
|
| 39 |
open POINTWISE public |
| 40 |
|
| 41 |
Pointwise : ∀ {a b ℓ₁ ℓ₂} {A : Set a} (B : A → Set b) |
| 42 |
(_R₁_ : Rel A ℓ₁) (_R₂_ : IRel B ℓ₂) → Rel (Σ A B) _ |
| 43 |
Pointwise B = POINTWISE B B |
| 44 |
|
| 45 |
------------------------------------------------------------------------ |
| 46 |
-- Pointwise preserves many relational properties |
| 47 |
|
| 48 |
module _ {a b ℓ₁ ℓ₂} {A : Set a} {B : A → Set b} |
| 49 |
{R : Rel A ℓ₁} {S : IRel B ℓ₂} where |
| 50 |
|
| 51 |
private |
| 52 |
R×S = Pointwise B R S |
| 53 |
|
| 54 |
refl : B.Reflexive R → I.Reflexive B S → B.Reflexive R×S |
| 55 |
refl refl₁ refl₂ = (refl₁ , refl₂) |
| 56 |
|
| 57 |
symmetric : B.Symmetric R → I.Symmetric B S → B.Symmetric R×S |
| 58 |
symmetric sym₁ sym₂ (x₁Rx₂ , y₁Ry₂) = (sym₁ x₁Rx₂ , sym₂ y₁Ry₂) |
| 59 |
|
| 60 |
transitive : B.Transitive R → I.Transitive B S → B.Transitive R×S |
| 61 |
transitive trans₁ trans₂ (x₁Rx₂ , y₁Ry₂) (x₂Rx₃ , y₂Ry₃) = |
| 62 |
(trans₁ x₁Rx₂ x₂Rx₃ , trans₂ y₁Ry₂ y₂Ry₃) |
| 63 |
|
| 64 |
isEquivalence : IsEquivalence R → IsIndexedEquivalence B S → |
| 65 |
IsEquivalence R×S |
| 66 |
isEquivalence eq₁ eq₂ = record |
| 67 |
{ refl = refl Eq.refl IEq.refl |
| 68 |
; sym = symmetric Eq.sym IEq.sym |
| 69 |
; trans = transitive Eq.trans IEq.trans |
| 70 |
} where |
| 71 |
module Eq = IsEquivalence eq₁ |
| 72 |
module IEq = IsIndexedEquivalence eq₂ |
| 73 |
|
| 74 |
module _ {a b ℓ₁ ℓ₂} where |
| 75 |
|
| 76 |
setoid : (A : Setoid a ℓ₁) → |
| 77 |
IndexedSetoid (Setoid.Carrier A) b ℓ₂ → |
| 78 |
Setoid _ _ |
| 79 |
setoid s₁ s₂ = record |
| 80 |
{ isEquivalence = isEquivalence Eq.isEquivalence IEq.isEquivalence |
| 81 |
} where |
| 82 |
module Eq = Setoid s₁ |
| 83 |
module IEq = IndexedSetoid s₂ |