| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Homogeneously-indexed binary relations |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
-- The contents of this module should be accessed via |
| 8 |
-- `Relation.Binary.Indexed.Homogeneous`. |
| 9 |
|
| 10 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 11 |
|
| 12 |
open import Relation.Binary.Indexed.Homogeneous.Core |
| 13 |
|
| 14 |
module Relation.Binary.Indexed.Homogeneous.Structures |
| 15 |
{i a ℓ} {I : Set i} |
| 16 |
(A : I → Set a) -- The underlying indexed sets |
| 17 |
(_≈ᵢ_ : IRel A ℓ) -- The underlying indexed equality relation |
| 18 |
where |
| 19 |
|
| 20 |
open import Data.Product.Base using (_,_) |
| 21 |
open import Function.Base using (_⟨_⟩_) |
| 22 |
open import Level using (Level; _⊔_; suc) |
| 23 |
open import Relation.Binary.Core using (_⇒_) |
| 24 |
import Relation.Binary.Definitions as B |
| 25 |
using (Reflexive; Symmetric; Transitive; Antisymmetric |
| 26 |
;_Respectsˡ_; _Respectsʳ_; _Respects₂_) |
| 27 |
import Relation.Binary.Structures as B using (IsEquivalence; IsPreorder; IsPartialOrder) |
| 28 |
open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_) |
| 29 |
open import Relation.Binary.Indexed.Homogeneous.Definitions |
| 30 |
import Relation.Binary.Structures as B |
| 31 |
using (IsEquivalence; IsPreorder; IsPartialOrder) |
| 32 |
|
| 33 |
------------------------------------------------------------------------ |
| 34 |
-- Equivalences |
| 35 |
|
| 36 |
-- Indexed structures are laid out in a similar manner as to those |
| 37 |
-- in Relation.Binary. The main difference is each structure also |
| 38 |
-- contains proofs for the lifted version of the relation. |
| 39 |
|
| 40 |
record IsIndexedEquivalence : Set (i ⊔ a ⊔ ℓ) where |
| 41 |
field |
| 42 |
reflᵢ : Reflexive A _≈ᵢ_ |
| 43 |
symᵢ : Symmetric A _≈ᵢ_ |
| 44 |
transᵢ : Transitive A _≈ᵢ_ |
| 45 |
|
| 46 |
reflexiveᵢ : ∀ {i} → _≡_ ⟨ _⇒_ ⟩ _≈ᵢ_ {i} |
| 47 |
reflexiveᵢ ≡.refl = reflᵢ |
| 48 |
|
| 49 |
-- Lift properties |
| 50 |
|
| 51 |
reflexive : _≡_ ⇒ (Lift A _≈ᵢ_) |
| 52 |
reflexive ≡.refl i = reflᵢ |
| 53 |
|
| 54 |
refl : B.Reflexive (Lift A _≈ᵢ_) |
| 55 |
refl i = reflᵢ |
| 56 |
|
| 57 |
sym : B.Symmetric (Lift A _≈ᵢ_) |
| 58 |
sym x≈y i = symᵢ (x≈y i) |
| 59 |
|
| 60 |
trans : B.Transitive (Lift A _≈ᵢ_) |
| 61 |
trans x≈y y≈z i = transᵢ (x≈y i) (y≈z i) |
| 62 |
|
| 63 |
isEquivalence : B.IsEquivalence (Lift A _≈ᵢ_) |
| 64 |
isEquivalence = record |
| 65 |
{ refl = refl |
| 66 |
; sym = sym |
| 67 |
; trans = trans |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
record IsIndexedDecEquivalence : Set (i ⊔ a ⊔ ℓ) where |
| 72 |
infix 4 _≟ᵢ_ |
| 73 |
field |
| 74 |
_≟ᵢ_ : Decidable A _≈ᵢ_ |
| 75 |
isEquivalenceᵢ : IsIndexedEquivalence |
| 76 |
|
| 77 |
open IsIndexedEquivalence isEquivalenceᵢ public |
| 78 |
|
| 79 |
|
| 80 |
------------------------------------------------------------------------ |
| 81 |
-- Preorders |
| 82 |
|
| 83 |
record IsIndexedPreorder {ℓ₂} (_∼ᵢ_ : IRel A ℓ₂) |
| 84 |
: Set (i ⊔ a ⊔ ℓ ⊔ ℓ₂) where |
| 85 |
field |
| 86 |
isEquivalenceᵢ : IsIndexedEquivalence |
| 87 |
reflexiveᵢ : _≈ᵢ_ ⇒[ A ] _∼ᵢ_ |
| 88 |
transᵢ : Transitive A _∼ᵢ_ |
| 89 |
|
| 90 |
module Eq = IsIndexedEquivalence isEquivalenceᵢ |
| 91 |
|
| 92 |
reflᵢ : Reflexive A _∼ᵢ_ |
| 93 |
reflᵢ = reflexiveᵢ Eq.reflᵢ |
| 94 |
|
| 95 |
∼ᵢ-respˡ-≈ᵢ : Respectsˡ A _∼ᵢ_ _≈ᵢ_ |
| 96 |
∼ᵢ-respˡ-≈ᵢ x≈y x∼z = transᵢ (reflexiveᵢ (Eq.symᵢ x≈y)) x∼z |
| 97 |
|
| 98 |
∼ᵢ-respʳ-≈ᵢ : Respectsʳ A _∼ᵢ_ _≈ᵢ_ |
| 99 |
∼ᵢ-respʳ-≈ᵢ x≈y z∼x = transᵢ z∼x (reflexiveᵢ x≈y) |
| 100 |
|
| 101 |
∼ᵢ-resp-≈ᵢ : Respects₂ A _∼ᵢ_ _≈ᵢ_ |
| 102 |
∼ᵢ-resp-≈ᵢ = ∼ᵢ-respʳ-≈ᵢ , ∼ᵢ-respˡ-≈ᵢ |
| 103 |
|
| 104 |
-- Lifted properties |
| 105 |
|
| 106 |
reflexive : Lift A _≈ᵢ_ ⇒ Lift A _∼ᵢ_ |
| 107 |
reflexive x≈y i = reflexiveᵢ (x≈y i) |
| 108 |
|
| 109 |
refl : B.Reflexive (Lift A _∼ᵢ_) |
| 110 |
refl i = reflᵢ |
| 111 |
|
| 112 |
trans : B.Transitive (Lift A _∼ᵢ_) |
| 113 |
trans x≈y y≈z i = transᵢ (x≈y i) (y≈z i) |
| 114 |
|
| 115 |
∼-respˡ-≈ : (Lift A _∼ᵢ_) B.Respectsˡ (Lift A _≈ᵢ_) |
| 116 |
∼-respˡ-≈ x≈y x∼z i = ∼ᵢ-respˡ-≈ᵢ (x≈y i) (x∼z i) |
| 117 |
|
| 118 |
∼-respʳ-≈ : (Lift A _∼ᵢ_) B.Respectsʳ (Lift A _≈ᵢ_) |
| 119 |
∼-respʳ-≈ x≈y z∼x i = ∼ᵢ-respʳ-≈ᵢ (x≈y i) (z∼x i) |
| 120 |
|
| 121 |
∼-resp-≈ : (Lift A _∼ᵢ_) B.Respects₂ (Lift A _≈ᵢ_) |
| 122 |
∼-resp-≈ = ∼-respʳ-≈ , ∼-respˡ-≈ |
| 123 |
|
| 124 |
isPreorder : B.IsPreorder (Lift A _≈ᵢ_) (Lift A _∼ᵢ_) |
| 125 |
isPreorder = record |
| 126 |
{ isEquivalence = Eq.isEquivalence |
| 127 |
; reflexive = reflexive |
| 128 |
; trans = trans |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
------------------------------------------------------------------------ |
| 133 |
-- Partial orders |
| 134 |
|
| 135 |
record IsIndexedPartialOrder {ℓ₂} (_≤ᵢ_ : IRel A ℓ₂) |
| 136 |
: Set (i ⊔ a ⊔ ℓ ⊔ ℓ₂) where |
| 137 |
field |
| 138 |
isPreorderᵢ : IsIndexedPreorder _≤ᵢ_ |
| 139 |
antisymᵢ : Antisymmetric A _≈ᵢ_ _≤ᵢ_ |
| 140 |
|
| 141 |
open IsIndexedPreorder isPreorderᵢ public |
| 142 |
renaming |
| 143 |
( ∼ᵢ-respˡ-≈ᵢ to ≤ᵢ-respˡ-≈ᵢ |
| 144 |
; ∼ᵢ-respʳ-≈ᵢ to ≤ᵢ-respʳ-≈ᵢ |
| 145 |
; ∼ᵢ-resp-≈ᵢ to ≤ᵢ-resp-≈ᵢ |
| 146 |
; ∼-respˡ-≈ to ≤-respˡ-≈ |
| 147 |
; ∼-respʳ-≈ to ≤-respʳ-≈ |
| 148 |
; ∼-resp-≈ to ≤-resp-≈ |
| 149 |
) |
| 150 |
|
| 151 |
antisym : B.Antisymmetric (Lift A _≈ᵢ_) (Lift A _≤ᵢ_) |
| 152 |
antisym x≤y y≤x i = antisymᵢ (x≤y i) (y≤x i) |
| 153 |
|
| 154 |
isPartialOrder : B.IsPartialOrder (Lift A _≈ᵢ_) (Lift A _≤ᵢ_) |
| 155 |
isPartialOrder = record |
| 156 |
{ isPreorder = isPreorder |
| 157 |
; antisym = antisym |
| 158 |
} |