summaryrefslogtreecommitdiff
path: root/src/Relation
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2018-11-23 17:29:46 -0700
committerSean Whitton <spwhitton@spwhitton.name>2018-11-23 17:29:46 -0700
commit5a91775bd7c909bbaf3b3c8ee964136961a5146d (patch)
treecea89f085c1382f1567ff71a30b6f953708dc6a9 /src/Relation
parent5d2b156377dce5bdca65b14639306eaed3ac3a92 (diff)
parenta19b25a865b2000bbd3acd909f5951a5407c1eec (diff)
Merge tag 'upstream/0.17'
Upstream version 0.17 # gpg: Signature made Fri 23 Nov 2018 05:29:18 PM MST # gpg: using RSA key 9B917007AE030E36E4FC248B695B7AE4BF066240 # gpg: issuer "spwhitton@spwhitton.name" # gpg: Good signature from "Sean Whitton <spwhitton@spwhitton.name>" [ultimate] # Primary key fingerprint: 8DC2 487E 51AB DD90 B5C4 753F 0F56 D055 3B6D 411B # Subkey fingerprint: 9B91 7007 AE03 0E36 E4FC 248B 695B 7AE4 BF06 6240
Diffstat (limited to 'src/Relation')
-rw-r--r--src/Relation/Binary.agda78
-rw-r--r--src/Relation/Binary/Consequences.agda240
-rw-r--r--src/Relation/Binary/Consequences/Core.agda19
-rw-r--r--src/Relation/Binary/Construct/Always.agda54
-rw-r--r--src/Relation/Binary/Construct/Closure/Equivalence.agda63
-rw-r--r--src/Relation/Binary/Construct/Closure/Reflexive.agda54
-rw-r--r--src/Relation/Binary/Construct/Closure/ReflexiveTransitive.agda134
-rw-r--r--src/Relation/Binary/Construct/Closure/ReflexiveTransitive/Properties.agda126
-rw-r--r--src/Relation/Binary/Construct/Closure/Symmetric.agda36
-rw-r--r--src/Relation/Binary/Construct/Closure/Transitive.agda99
-rw-r--r--src/Relation/Binary/Construct/Constant.agda39
-rw-r--r--src/Relation/Binary/Construct/Converse.agda196
-rw-r--r--src/Relation/Binary/Construct/Flip.agda197
-rw-r--r--src/Relation/Binary/Construct/FromPred.agda49
-rw-r--r--src/Relation/Binary/Construct/FromRel.agda47
-rw-r--r--src/Relation/Binary/Construct/Never.agda18
-rw-r--r--src/Relation/Binary/Construct/NonStrictToStrict.agda151
-rw-r--r--src/Relation/Binary/Construct/On.agda (renamed from src/Relation/Binary/On.agda)2
-rw-r--r--src/Relation/Binary/Construct/StrictToNonStrict.agda144
-rw-r--r--src/Relation/Binary/Core.agda70
-rw-r--r--src/Relation/Binary/EqReasoning.agda13
-rw-r--r--src/Relation/Binary/EquivalenceClosure.agda53
-rw-r--r--src/Relation/Binary/Flip.agda196
-rw-r--r--src/Relation/Binary/HeterogeneousEquality.agda116
-rw-r--r--src/Relation/Binary/HeterogeneousEquality/Core.agda2
-rw-r--r--src/Relation/Binary/HeterogeneousEquality/Quotients.agda147
-rw-r--r--src/Relation/Binary/HeterogeneousEquality/Quotients/Examples.agda146
-rw-r--r--src/Relation/Binary/Indexed.agda35
-rw-r--r--src/Relation/Binary/Indexed/Core.agda69
-rw-r--r--src/Relation/Binary/Indexed/Heterogeneous.agda95
-rw-r--r--src/Relation/Binary/Indexed/Heterogeneous/Construct/At.agda66
-rw-r--r--src/Relation/Binary/Indexed/Heterogeneous/Construct/Trivial.agda56
-rw-r--r--src/Relation/Binary/Indexed/Heterogeneous/Core.agda48
-rw-r--r--src/Relation/Binary/Indexed/Homogeneous.agda253
-rw-r--r--src/Relation/Binary/Indexed/Homogeneous/Core.agda88
-rw-r--r--src/Relation/Binary/InducedPreorders.agda48
-rw-r--r--src/Relation/Binary/Lattice.agda254
-rw-r--r--src/Relation/Binary/List/NonStrictLex.agda177
-rw-r--r--src/Relation/Binary/List/Pointwise.agda186
-rw-r--r--src/Relation/Binary/List/StrictLex.agda295
-rw-r--r--src/Relation/Binary/NonStrictToStrict.agda106
-rw-r--r--src/Relation/Binary/PreorderReasoning.agda6
-rw-r--r--src/Relation/Binary/Product/NonStrictLex.agda170
-rw-r--r--src/Relation/Binary/Product/Pointwise.agda425
-rw-r--r--src/Relation/Binary/Product/StrictLex.agda266
-rw-r--r--src/Relation/Binary/Properties/DecTotalOrder.agda9
-rw-r--r--src/Relation/Binary/Properties/DistributiveLattice.agda56
-rw-r--r--src/Relation/Binary/Properties/HeytingAlgebra.agda99
-rw-r--r--src/Relation/Binary/Properties/Poset.agda10
-rw-r--r--src/Relation/Binary/Properties/StrictPartialOrder.agda12
-rw-r--r--src/Relation/Binary/Properties/StrictTotalOrder.agda12
-rw-r--r--src/Relation/Binary/PropositionalEquality.agda125
-rw-r--r--src/Relation/Binary/PropositionalEquality/Core.agda54
-rw-r--r--src/Relation/Binary/PropositionalEquality/TrustMe.agda18
-rw-r--r--src/Relation/Binary/SetoidReasoning.agda4
-rw-r--r--src/Relation/Binary/Sigma/Pointwise.agda442
-rw-r--r--src/Relation/Binary/Simple.agda34
-rw-r--r--src/Relation/Binary/StrictToNonStrict.agda103
-rw-r--r--src/Relation/Binary/Sum.agda618
-rw-r--r--src/Relation/Binary/SymmetricClosure.agda32
-rw-r--r--src/Relation/Binary/Vec/Pointwise.agda234
-rw-r--r--src/Relation/Nullary.agda10
-rw-r--r--src/Relation/Nullary/Decidable.agda26
-rw-r--r--src/Relation/Nullary/Negation.agda10
-rw-r--r--src/Relation/Nullary/Universe.agda18
-rw-r--r--src/Relation/Unary.agda165
-rw-r--r--src/Relation/Unary/Closure/Base.agda61
-rw-r--r--src/Relation/Unary/Closure/Preorder.agda30
-rw-r--r--src/Relation/Unary/Closure/StrictPartialOrder.agda28
-rw-r--r--src/Relation/Unary/Indexed.agda22
-rw-r--r--src/Relation/Unary/Properties.agda101
71 files changed, 3552 insertions, 3913 deletions
diff --git a/src/Relation/Binary.agda b/src/Relation/Binary.agda
index 54fef09..26fa333 100644
--- a/src/Relation/Binary.agda
+++ b/src/Relation/Binary.agda
@@ -6,21 +6,18 @@
module Relation.Binary where
+open import Agda.Builtin.Equality using (_≡_)
open import Data.Product
open import Data.Sum
open import Function
open import Level
import Relation.Binary.PropositionalEquality.Core as PropEq
-open import Relation.Binary.Consequences as Consequences
-open import Relation.Binary.Core as Core using (_≡_)
-import Relation.Binary.Indexed.Core as I
+open import Relation.Binary.Consequences
------------------------------------------------------------------------
-- Simple properties and equivalence relations
-open Core public hiding (_≡_; refl; _≢_)
-
-open Consequences public using (Total)
+open import Relation.Binary.Core public
------------------------------------------------------------------------
-- Preorders
@@ -40,9 +37,14 @@ record IsPreorder {a ℓ₁ ℓ₂} {A : Set a}
refl : Reflexive _∼_
refl = reflexive Eq.refl
+ ∼-respˡ-≈ : _∼_ Respectsˡ _≈_
+ ∼-respˡ-≈ x≈y x∼z = trans (reflexive (Eq.sym x≈y)) x∼z
+
+ ∼-respʳ-≈ : _∼_ Respectsʳ _≈_
+ ∼-respʳ-≈ x≈y z∼x = trans z∼x (reflexive x≈y)
+
∼-resp-≈ : _∼_ Respects₂ _≈_
- ∼-resp-≈ = (λ x≈y z∼x → trans z∼x (reflexive x≈y))
- , (λ x≈y x∼z → trans (reflexive $ Eq.sym x≈y) x∼z)
+ ∼-resp-≈ = ∼-respʳ-≈ , ∼-respˡ-≈
record Preorder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
infix 4 _≈_ _∼_
@@ -78,19 +80,6 @@ record Setoid c ℓ : Set (suc (c ⊔ ℓ)) where
preorder : Preorder c c ℓ
preorder = record { isPreorder = isPreorder }
- -- A trivially indexed setoid.
-
- indexedSetoid : ∀ {i} {I : Set i} → I.Setoid I c _
- indexedSetoid = record
- { Carrier = λ _ → Carrier
- ; _≈_ = _≈_
- ; isEquivalence = record
- { refl = refl
- ; sym = sym
- ; trans = trans
- }
- }
-
------------------------------------------------------------------------
-- Decidable equivalence relations
@@ -128,7 +117,11 @@ record IsPartialOrder {a ℓ₁ ℓ₂} {A : Set a}
antisym : Antisymmetric _≈_ _≤_
open IsPreorder isPreorder public
- renaming (∼-resp-≈ to ≤-resp-≈)
+ renaming
+ ( ∼-respˡ-≈ to ≤-respˡ-≈
+ ; ∼-respʳ-≈ to ≤-respʳ-≈
+ ; ∼-resp-≈ to ≤-resp-≈
+ )
record Poset c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
infix 4 _≈_ _≤_
@@ -207,6 +200,21 @@ record IsStrictPartialOrder {a ℓ₁ ℓ₂} {A : Set a}
module Eq = IsEquivalence isEquivalence
+ asym : Asymmetric _<_
+ asym {x} {y} = trans∧irr⟶asym Eq.refl trans irrefl {x = x} {y}
+
+ <-respʳ-≈ : _<_ Respectsʳ _≈_
+ <-respʳ-≈ = proj₁ <-resp-≈
+
+ <-respˡ-≈ : _<_ Respectsˡ _≈_
+ <-respˡ-≈ = proj₂ <-resp-≈
+
+ asymmetric = asym
+ {-# WARNING_ON_USAGE asymmetric
+ "Warning: asymmetric was deprecated in v0.16.
+ Please use asym instead."
+ #-}
+
record StrictPartialOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
infix 4 _≈_ _<_
field
@@ -217,10 +225,6 @@ record StrictPartialOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂))
open IsStrictPartialOrder isStrictPartialOrder public
- asymmetric : Asymmetric _<_
- asymmetric {x} {y} =
- trans∧irr⟶asym Eq.refl trans irrefl {x = x} {y = y}
-
------------------------------------------------------------------------
-- Decidable strict partial orders
@@ -308,15 +312,13 @@ record IsDecTotalOrder {a ℓ₁ ℓ₂} {A : Set a}
_≟_ : Decidable _≈_
_≤?_ : Decidable _≤_
- private
- module TO = IsTotalOrder isTotalOrder
- open TO public hiding (module Eq)
+ open IsTotalOrder isTotalOrder public hiding (module Eq)
module Eq where
isDecEquivalence : IsDecEquivalence _≈_
isDecEquivalence = record
- { isEquivalence = TO.isEquivalence
+ { isEquivalence = isEquivalence
; _≟_ = _≟_
}
@@ -349,7 +351,10 @@ record DecTotalOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
------------------------------------------------------------------------
-- Strict total orders
--- Note that these orders are decidable (see compare).
+-- Note that these orders are decidable. The current implementation
+-- of `Trichotomous` subsumes irreflexivity and asymmetry. Any reasonable
+-- definition capturing these three properties implies decidability
+-- as `Trichotomous` necessarily separates out the equality case.
record IsStrictTotalOrder {a ℓ₁ ℓ₂} {A : Set a}
(_≈_ : Rel A ℓ₁) (_<_ : Rel A ℓ₂) :
@@ -375,8 +380,14 @@ record IsStrictTotalOrder {a ℓ₁ ℓ₂} {A : Set a}
module Eq = IsDecEquivalence isDecEquivalence
+ <-respˡ-≈ : _<_ Respectsˡ _≈_
+ <-respˡ-≈ = trans∧tri⟶respˡ≈ Eq.trans trans compare
+
+ <-respʳ-≈ : _<_ Respectsʳ _≈_
+ <-respʳ-≈ = trans∧tri⟶respʳ≈ Eq.sym Eq.trans trans compare
+
<-resp-≈ : _<_ Respects₂ _≈_
- <-resp-≈ = trans∧tri⟶resp≈ Eq.sym Eq.trans trans compare
+ <-resp-≈ = <-respʳ-≈ , <-respˡ-≈
isStrictPartialOrder : IsStrictPartialOrder _≈_ _<_
isStrictPartialOrder = record
@@ -386,7 +397,8 @@ record IsStrictTotalOrder {a ℓ₁ ℓ₂} {A : Set a}
; <-resp-≈ = <-resp-≈
}
- open IsStrictPartialOrder isStrictPartialOrder public using (irrefl)
+ open IsStrictPartialOrder isStrictPartialOrder public
+ using (irrefl; asym)
record StrictTotalOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
infix 4 _≈_ _<_
diff --git a/src/Relation/Binary/Consequences.agda b/src/Relation/Binary/Consequences.agda
index dafdc88..4164a69 100644
--- a/src/Relation/Binary/Consequences.agda
+++ b/src/Relation/Binary/Consequences.agda
@@ -6,136 +6,128 @@
module Relation.Binary.Consequences where
-open import Relation.Binary.Core hiding (refl)
-open import Relation.Nullary
-open import Relation.Binary.PropositionalEquality.Core
-open import Function
-open import Data.Sum
-open import Data.Product
-open import Data.Empty
-
--- Some of the definitions can be found in the following module:
-
-open import Relation.Binary.Consequences.Core public
-
-Total : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Set _
-Total _∼_ = ∀ x y → (x ∼ y) ⊎ (y ∼ x)
-
-trans∧irr⟶asym :
- ∀ {a ℓ₁ ℓ₂} {A : Set a} → {_≈_ : Rel A ℓ₁} {_<_ : Rel A ℓ₂} →
- Reflexive _≈_ →
- Transitive _<_ → Irreflexive _≈_ _<_ → Asymmetric _<_
-trans∧irr⟶asym refl trans irrefl = λ x<y y<x →
- irrefl refl (trans x<y y<x)
-
-irr∧antisym⟶asym :
- ∀ {a ℓ₁ ℓ₂} {A : Set a} {_≈_ : Rel A ℓ₁} {_<_ : Rel A ℓ₂} →
- Irreflexive _≈_ _<_ → Antisymmetric _≈_ _<_ → Asymmetric _<_
-irr∧antisym⟶asym irrefl antisym = λ x<y y<x →
- irrefl (antisym x<y y<x) x<y
-
-asym⟶antisym :
- ∀ {a ℓ₁ ℓ₂} {A : Set a} {_≈_ : Rel A ℓ₁} {_<_ : Rel A ℓ₂} →
- Asymmetric _<_ → Antisymmetric _≈_ _<_
-asym⟶antisym asym x<y y<x = ⊥-elim (asym x<y y<x)
-
-asym⟶irr :
- ∀ {a ℓ₁ ℓ₂} {A : Set a} {_≈_ : Rel A ℓ₁} {_<_ : Rel A ℓ₂} →
- _<_ Respects₂ _≈_ → Symmetric _≈_ →
- Asymmetric _<_ → Irreflexive _≈_ _<_
-asym⟶irr {_<_ = _<_} resp sym asym {x} {y} x≈y x<y = asym x<y y<x
- where
- y<y : y < y
- y<y = proj₂ resp x≈y x<y
- y<x : y < x
- y<x = proj₁ resp (sym x≈y) y<y
-
-total⟶refl :
- ∀ {a ℓ₁ ℓ₂} {A : Set a} {_≈_ : Rel A ℓ₁} {_∼_ : Rel A ℓ₂} →
- _∼_ Respects₂ _≈_ → Symmetric _≈_ →
- Total _∼_ → _≈_ ⇒ _∼_
-total⟶refl {_≈_ = _≈_} {_∼_ = _∼_} resp sym total = refl
- where
- refl : _≈_ ⇒ _∼_
- refl {x} {y} x≈y with total x y
- ... | inj₁ x∼y = x∼y
- ... | inj₂ y∼x =
- proj₁ resp x≈y (proj₂ resp (sym x≈y) y∼x)
-
-total+dec⟶dec :
- ∀ {a ℓ₁ ℓ₂} {A : Set a} {_≈_ : Rel A ℓ₁} {_≤_ : Rel A ℓ₂} →
- _≈_ ⇒ _≤_ → Antisymmetric _≈_ _≤_ →
- Total _≤_ → Decidable _≈_ → Decidable _≤_
-total+dec⟶dec {_≈_ = _≈_} {_≤_ = _≤_} refl antisym total _≟_ = dec
- where
- dec : Decidable _≤_
- dec x y with total x y
+open import Relation.Binary.Core
+open import Relation.Nullary using (yes; no)
+open import Relation.Unary using (∁)
+open import Function using (_∘_; flip)
+open import Data.Sum using (inj₁; inj₂)
+open import Data.Product using (_,_)
+open import Data.Empty using (⊥-elim)
+
+------------------------------------------------------------------------
+-- Substitutive properties
+
+module _ {a ℓ p} {A : Set a} {_∼_ : Rel A ℓ} (P : Rel A p) where
+
+ subst⟶respˡ : Substitutive _∼_ p → P Respectsˡ _∼_
+ subst⟶respˡ subst {y} x'∼x Px'y = subst (flip P y) x'∼x Px'y
+
+ subst⟶respʳ : Substitutive _∼_ p → P Respectsʳ _∼_
+ subst⟶respʳ subst {x} y'∼y Pxy' = subst (P x) y'∼y Pxy'
+
+ subst⟶resp₂ : Substitutive _∼_ p → P Respects₂ _∼_
+ subst⟶resp₂ subst = subst⟶respʳ subst , subst⟶respˡ subst
+
+module _ {a ℓ p} {A : Set a} {∼ : Rel A ℓ} {P : A → Set p} where
+
+ P-resp⟶¬P-resp : Symmetric ∼ → P Respects ∼ → (∁ P) Respects ∼
+ P-resp⟶¬P-resp sym resp x∼y ¬Px Py = ¬Px (resp (sym x∼y) Py)
+
+------------------------------------------------------------------------
+-- Proofs for non-strict orders
+
+module _ {a ℓ₁ ℓ₂} {A : Set a} {_≈_ : Rel A ℓ₁} {_≤_ : Rel A ℓ₂} where
+
+ total⟶refl : _≤_ Respects₂ _≈_ → Symmetric _≈_ →
+ Total _≤_ → _≈_ ⇒ _≤_
+ total⟶refl (respʳ , respˡ) sym total {x} {y} x≈y with total x y
+ ... | inj₁ x∼y = x∼y
+ ... | inj₂ y∼x = respʳ x≈y (respˡ (sym x≈y) y∼x)
+
+ total+dec⟶dec : _≈_ ⇒ _≤_ → Antisymmetric _≈_ _≤_ →
+ Total _≤_ → Decidable _≈_ → Decidable _≤_
+ total+dec⟶dec refl antisym total _≟_ x y with total x y
... | inj₁ x≤y = yes x≤y
... | inj₂ y≤x with x ≟ y
- ... | yes x≈y = yes (refl x≈y)
- ... | no ¬x≈y = no (λ x≤y → ¬x≈y (antisym x≤y y≤x))
-
-tri⟶asym :
- ∀ {a ℓ₁ ℓ₂} {A : Set a} {_≈_ : Rel A ℓ₁} {_<_ : Rel A ℓ₂} →
- Trichotomous _≈_ _<_ → Asymmetric _<_
-tri⟶asym tri {x} {y} x<y x>y with tri x y
-... | tri< _ _ x≯y = x≯y x>y
-... | tri≈ _ _ x≯y = x≯y x>y
-... | tri> x≮y _ _ = x≮y x<y
-
-tri⟶irr :
- ∀ {a ℓ₁ ℓ₂} {A : Set a} {_≈_ : Rel A ℓ₁} {_<_ : Rel A ℓ₂} →
- Trichotomous _≈_ _<_ → Irreflexive _≈_ _<_
-tri⟶irr {_≈_ = _≈_} {_<_} compare = irr
- where
- irr : ∀ {x y} → x ≈ y → ¬ (x < y)
- irr {x} {y} x≈y x<y with compare x y
+ ... | yes x≈y = yes (refl x≈y)
+ ... | no x≉y = no (λ x≤y → x≉y (antisym x≤y y≤x))
+
+------------------------------------------------------------------------
+-- Proofs for strict orders
+
+module _ {a ℓ₁ ℓ₂} {A : Set a} {_≈_ : Rel A ℓ₁} {_<_ : Rel A ℓ₂} where
+
+ trans∧irr⟶asym : Reflexive _≈_ → Transitive _<_ →
+ Irreflexive _≈_ _<_ → Asymmetric _<_
+ trans∧irr⟶asym refl trans irrefl x<y y<x =
+ irrefl refl (trans x<y y<x)
+
+ irr∧antisym⟶asym : Irreflexive _≈_ _<_ → Antisymmetric _≈_ _<_ →
+ Asymmetric _<_
+ irr∧antisym⟶asym irrefl antisym x<y y<x =
+ irrefl (antisym x<y y<x) x<y
+
+ asym⟶antisym : Asymmetric _<_ → Antisymmetric _≈_ _<_
+ asym⟶antisym asym x<y y<x = ⊥-elim (asym x<y y<x)
+
+ asym⟶irr : _<_ Respects₂ _≈_ → Symmetric _≈_ →
+ Asymmetric _<_ → Irreflexive _≈_ _<_
+ asym⟶irr (respʳ , respˡ) sym asym {x} {y} x≈y x<y =
+ asym x<y (respʳ (sym x≈y) (respˡ x≈y x<y))
+
+ tri⟶asym : Trichotomous _≈_ _<_ → Asymmetric _<_
+ tri⟶asym tri {x} {y} x<y x>y with tri x y
+ ... | tri< _ _ x≯y = x≯y x>y
+ ... | tri≈ _ _ x≯y = x≯y x>y
+ ... | tri> x≮y _ _ = x≮y x<y
+
+ tri⟶irr : Trichotomous _≈_ _<_ → Irreflexive _≈_ _<_
+ tri⟶irr compare {x} {y} x≈y x<y with compare x y
... | tri< _ x≉y y≮x = x≉y x≈y
... | tri> x≮y x≉y y<x = x≉y x≈y
... | tri≈ x≮y _ y≮x = x≮y x<y
-trans∧tri⟶resp≈ :
- ∀ {a ℓ₁ ℓ₂} {A : Set a} {_≈_ : Rel A ℓ₁} {_<_ : Rel A ℓ₂} →
- Symmetric _≈_ → Transitive _≈_ →
- Transitive _<_ → Trichotomous _≈_ _<_ →
- _<_ Respects₂ _≈_
-trans∧tri⟶resp≈ {_≈_ = _≈_} {_<_} sym trans <-trans tri =
- respʳ , respˡ
- where
- respʳ : ∀ {x y z} → y ≈ z → x < y → x < z
- respʳ {x} {z = z} y≈z x<y with tri x z
+ tri⟶dec≈ : Trichotomous _≈_ _<_ → Decidable _≈_
+ tri⟶dec≈ compare x y with compare x y
+ ... | tri< _ x≉y _ = no x≉y
+ ... | tri≈ _ x≈y _ = yes x≈y
+ ... | tri> _ x≉y _ = no x≉y
+
+ tri⟶dec< : Trichotomous _≈_ _<_ → Decidable _<_
+ tri⟶dec< compare x y with compare x y
+ ... | tri< x<y _ _ = yes x<y
+ ... | tri≈ x≮y _ _ = no x≮y
+ ... | tri> x≮y _ _ = no x≮y
+
+ trans∧tri⟶respʳ≈ : Symmetric _≈_ → Transitive _≈_ →
+ Transitive _<_ → Trichotomous _≈_ _<_ →
+ _<_ Respectsʳ _≈_
+ trans∧tri⟶respʳ≈ sym ≈-tr <-tr tri {x} {y} {z} y≈z x<y with tri x z
... | tri< x<z _ _ = x<z
- ... | tri≈ _ x≈z _ = ⊥-elim (tri⟶irr tri (trans x≈z (sym y≈z)) x<y)
- ... | tri> _ _ z<x = ⊥-elim (tri⟶irr tri (sym y≈z) (<-trans z<x x<y))
+ ... | tri≈ _ x≈z _ = ⊥-elim (tri⟶irr tri (≈-tr x≈z (sym y≈z)) x<y)
+ ... | tri> _ _ z<x = ⊥-elim (tri⟶irr tri (sym y≈z) (<-tr z<x x<y))
- respˡ : ∀ {z x y} → x ≈ y → x < z → y < z
- respˡ {z} {y = y} x≈y x<z with tri y z
+ trans∧tri⟶respˡ≈ : Transitive _≈_ →
+ Transitive _<_ → Trichotomous _≈_ _<_ →
+ _<_ Respectsˡ _≈_
+ trans∧tri⟶respˡ≈ ≈-tr <-tr tri {z} {_} {y} x≈y x<z with tri y z
... | tri< y<z _ _ = y<z
- ... | tri≈ _ y≈z _ = ⊥-elim (tri⟶irr tri (trans x≈y y≈z) x<z)
- ... | tri> _ _ z<y = ⊥-elim (tri⟶irr tri x≈y (<-trans x<z z<y))
-
-P-resp⟶¬P-resp :
- ∀ {a p ℓ} {A : Set a} {_≈_ : Rel A ℓ} {P : A → Set p} →
- Symmetric _≈_ → P Respects _≈_ → (¬_ ∘ P) Respects _≈_
-P-resp⟶¬P-resp sym resp x≈y ¬Px Py = ¬Px (resp (sym x≈y) Py)
-
-tri⟶dec≈ :
- ∀ {a ℓ₁ ℓ₂} {A : Set a} {_≈_ : Rel A ℓ₁} {_<_ : Rel A ℓ₂} →
- Trichotomous _≈_ _<_ → Decidable _≈_
-tri⟶dec≈ compare x y with compare x y
-... | tri< _ x≉y _ = no x≉y
-... | tri≈ _ x≈y _ = yes x≈y
-... | tri> _ x≉y _ = no x≉y
-
-tri⟶dec< :
- ∀ {a ℓ₁ ℓ₂} {A : Set a} {_≈_ : Rel A ℓ₁} {_<_ : Rel A ℓ₂} →
- Trichotomous _≈_ _<_ → Decidable _<_
-tri⟶dec< compare x y with compare x y
-... | tri< x<y _ _ = yes x<y
-... | tri≈ x≮y _ _ = no x≮y
-... | tri> x≮y _ _ = no x≮y
-
-map-NonEmpty : ∀ {a b p q} {A : Set a} {B : Set b}
- {P : REL A B p} {Q : REL A B q} →
- P ⇒ Q → NonEmpty P → NonEmpty Q
-map-NonEmpty f x = nonEmpty (f (NonEmpty.proof x))
+ ... | tri≈ _ y≈z _ = ⊥-elim (tri⟶irr tri (≈-tr x≈y y≈z) x<z)
+ ... | tri> _ _ z<y = ⊥-elim (tri⟶irr tri x≈y (<-tr x<z z<y))
+
+ trans∧tri⟶resp≈ : Symmetric _≈_ → Transitive _≈_ →
+ Transitive _<_ → Trichotomous _≈_ _<_ →
+ _<_ Respects₂ _≈_
+ trans∧tri⟶resp≈ sym ≈-tr <-tr tri =
+ trans∧tri⟶respʳ≈ sym ≈-tr <-tr tri ,
+ trans∧tri⟶respˡ≈ ≈-tr <-tr tri
+
+------------------------------------------------------------------------
+-- Other proofs
+
+module _ {a b p q} {A : Set a} {B : Set b }
+ {P : REL A B p} {Q : REL A B q}
+ where
+
+ map-NonEmpty : P ⇒ Q → NonEmpty P → NonEmpty Q
+ map-NonEmpty f x = nonEmpty (f (NonEmpty.proof x))
diff --git a/src/Relation/Binary/Consequences/Core.agda b/src/Relation/Binary/Consequences/Core.agda
deleted file mode 100644
index 515c0dd..0000000
--- a/src/Relation/Binary/Consequences/Core.agda
+++ /dev/null
@@ -1,19 +0,0 @@
-------------------------------------------------------------------------
--- The Agda standard library
---
--- Some properties imply others
-------------------------------------------------------------------------
-
--- This file contains some core definitions which are reexported by
--- Relation.Binary.Consequences.
-
-module Relation.Binary.Consequences.Core where
-
-open import Relation.Binary.Core
-open import Data.Product
-
-subst⟶resp₂ : ∀ {a ℓ p} {A : Set a} {∼ : Rel A ℓ}
- (P : Rel A p) → Substitutive ∼ p → P Respects₂ ∼
-subst⟶resp₂ {∼ = ∼} P subst =
- (λ {x _ _} y'∼y Pxy' → subst (P x) y'∼y Pxy') ,
- (λ {y _ _} x'∼x Px'y → subst (λ x → P x y) x'∼x Px'y)
diff --git a/src/Relation/Binary/Construct/Always.agda b/src/Relation/Binary/Construct/Always.agda
new file mode 100644
index 0000000..97363b6
--- /dev/null
+++ b/src/Relation/Binary/Construct/Always.agda
@@ -0,0 +1,54 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- The universal binary relation
+------------------------------------------------------------------------
+
+module Relation.Binary.Construct.Always where
+
+open import Relation.Binary
+open import Relation.Binary.Construct.Constant using (Const)
+open import Data.Unit using (⊤; tt)
+open import Level using (Lift; lift)
+
+------------------------------------------------------------------------
+-- Definition
+
+Always : ∀ {a ℓ} {A : Set a} → Rel A ℓ
+Always = Const (Lift _ ⊤)
+
+------------------------------------------------------------------------
+-- Properties
+
+module _ {a} (A : Set a) ℓ where
+
+ refl : Reflexive {ℓ = ℓ} {A} Always
+ refl = lift tt
+
+ sym : Symmetric {ℓ = ℓ} {A} Always
+ sym _ = lift tt
+
+ trans : Transitive {ℓ = ℓ} {A} Always
+ trans _ _ = lift tt
+
+ isEquivalence : IsEquivalence {ℓ = ℓ} {A} Always
+ isEquivalence = record {}
+
+ setoid : Setoid a ℓ
+ setoid = record
+ { isEquivalence = isEquivalence
+ }
+
+------------------------------------------------------------------------
+-- DEPRECATED NAMES
+------------------------------------------------------------------------
+-- Please use the new names as continuing support for the old names is
+-- not guaranteed.
+
+-- Version 0.17
+
+Always-setoid = setoid
+{-# WARNING_ON_USAGE Always-setoid
+"Warning: Always-setoid was deprecated in v0.14.
+Please use setoid instead."
+#-}
diff --git a/src/Relation/Binary/Construct/Closure/Equivalence.agda b/src/Relation/Binary/Construct/Closure/Equivalence.agda
new file mode 100644
index 0000000..fd678cc
--- /dev/null
+++ b/src/Relation/Binary/Construct/Closure/Equivalence.agda
@@ -0,0 +1,63 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- The reflexive, symmetric and transitive closure of a binary
+-- relation (aka the equivalence closure).
+------------------------------------------------------------------------
+
+module Relation.Binary.Construct.Closure.Equivalence where
+
+open import Function using (flip; id; _∘_)
+open import Level using (_⊔_)
+open import Relation.Binary
+open import Relation.Binary.Construct.Closure.ReflexiveTransitive as Star
+ using (Star; ε; _◅◅_; reverse)
+open import Relation.Binary.Construct.Closure.Symmetric as SC using (SymClosure)
+
+------------------------------------------------------------------------
+-- Definition
+
+EqClosure : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Rel A (a ⊔ ℓ)
+EqClosure _∼_ = Star (SymClosure _∼_)
+
+------------------------------------------------------------------------
+-- Equivalence closures are equivalences.
+
+module _ {a ℓ} {A : Set a} (_∼_ : Rel A ℓ) where
+
+ reflexive : Reflexive (EqClosure _∼_)
+ reflexive = ε
+
+ transitive : Transitive (EqClosure _∼_)
+ transitive = _◅◅_
+
+ symmetric : Symmetric (EqClosure _∼_)
+ symmetric = reverse (SC.symmetric _∼_)
+
+ isEquivalence : IsEquivalence (EqClosure _∼_)
+ isEquivalence = record
+ { refl = reflexive
+ ; sym = symmetric
+ ; trans = transitive
+ }
+
+ setoid : Setoid a (a ⊔ ℓ)
+ setoid = record
+ { _≈_ = EqClosure _∼_
+ ; isEquivalence = isEquivalence
+ }
+
+------------------------------------------------------------------------
+-- Operations
+
+module _ {a ℓ₁ ℓ₂} {A : Set a} where
+
+ -- A generalised variant of map which allows the index type to change.
+
+ gmap : ∀ {b} {B : Set b} {P : Rel A ℓ₁} {Q : Rel B ℓ₂} →
+ (f : A → B) → P =[ f ]⇒ Q → EqClosure P =[ f ]⇒ EqClosure Q
+ gmap {Q = Q} f = Star.gmap f ∘ SC.gmap {Q = Q} f
+
+ map : ∀ {P : Rel A ℓ₁} {Q : Rel A ℓ₂} →
+ P ⇒ Q → EqClosure P ⇒ EqClosure Q
+ map = gmap id
diff --git a/src/Relation/Binary/Construct/Closure/Reflexive.agda b/src/Relation/Binary/Construct/Closure/Reflexive.agda
new file mode 100644
index 0000000..c726993
--- /dev/null
+++ b/src/Relation/Binary/Construct/Closure/Reflexive.agda
@@ -0,0 +1,54 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Reflexive closures
+------------------------------------------------------------------------
+
+module Relation.Binary.Construct.Closure.Reflexive where
+
+open import Data.Unit
+open import Level
+open import Function
+open import Relation.Binary
+open import Relation.Binary.Construct.Constant using (Const)
+open import Relation.Binary.PropositionalEquality using (_≡_ ; refl)
+
+------------------------------------------------------------------------
+-- Reflexive closure
+
+data Refl {a ℓ} {A : Set a} (_∼_ : Rel A ℓ) : Rel A (a ⊔ ℓ) where
+ [_] : ∀ {x y} (x∼y : x ∼ y) → Refl _∼_ x y
+ refl : Reflexive (Refl _∼_)
+
+[]-injective : ∀ {a ℓ} {A : Set a} {_∼_ : Rel A ℓ} {x y p q} →
+ (Refl _∼_ x y ∋ [ p ]) ≡ [ q ] → p ≡ q
+[]-injective refl = refl
+
+-- Map.
+
+map : ∀ {a a′ ℓ ℓ′} {A : Set a} {A′ : Set a′}
+ {_R_ : Rel A ℓ} {_R′_ : Rel A′ ℓ′} {f : A → A′} →
+ _R_ =[ f ]⇒ _R′_ → Refl _R_ =[ f ]⇒ Refl _R′_
+map R⇒R′ [ xRy ] = [ R⇒R′ xRy ]
+map R⇒R′ refl = refl
+
+-- The reflexive closure has no effect on reflexive relations.
+
+drop-refl : ∀ {a ℓ} {A : Set a} {_R_ : Rel A ℓ} →
+ Reflexive _R_ → Refl _R_ ⇒ _R_
+drop-refl rfl [ x∼y ] = x∼y
+drop-refl rfl refl = rfl
+
+------------------------------------------------------------------------
+-- Example: Maybe
+
+module Maybe where
+
+ Maybe : ∀ {ℓ} → Set ℓ → Set ℓ
+ Maybe A = Refl (Const A) tt tt
+
+ nothing : ∀ {a} {A : Set a} → Maybe A
+ nothing = refl
+
+ just : ∀ {a} {A : Set a} → A → Maybe A
+ just = [_]
diff --git a/src/Relation/Binary/Construct/Closure/ReflexiveTransitive.agda b/src/Relation/Binary/Construct/Closure/ReflexiveTransitive.agda
new file mode 100644
index 0000000..7aabae8
--- /dev/null
+++ b/src/Relation/Binary/Construct/Closure/ReflexiveTransitive.agda
@@ -0,0 +1,134 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- The reflexive transitive closures of McBride, Norell and Jansson
+------------------------------------------------------------------------
+
+module Relation.Binary.Construct.Closure.ReflexiveTransitive where
+
+open import Relation.Binary
+open import Function
+open import Level using (_⊔_)
+
+infixr 5 _◅_
+
+-- Reflexive transitive closure.
+
+data Star {i t} {I : Set i} (T : Rel I t) : Rel I (i ⊔ t) where
+ ε : Reflexive (Star T)
+ _◅_ : ∀ {i j k} (x : T i j) (xs : Star T j k) → Star T i k
+ -- The type of _◅_ is Trans T (Star T) (Star T); The
+ -- definition is expanded in order to be able to name
+ -- the arguments (x and xs).
+
+-- Append/transitivity.
+
+infixr 5 _◅◅_
+
+_◅◅_ : ∀ {i t} {I : Set i} {T : Rel I t} → Transitive (Star T)
+ε ◅◅ ys = ys
+(x ◅ xs) ◅◅ ys = x ◅ (xs ◅◅ ys)
+
+-- Sometimes you want to view cons-lists as snoc-lists. Then the
+-- following "constructor" is handy. Note that this is _not_ snoc for
+-- cons-lists, it is just a synonym for cons (with a different
+-- argument order).
+
+infixl 5 _▻_
+
+_▻_ : ∀ {i t} {I : Set i} {T : Rel I t} {i j k} →
+ Star T j k → T i j → Star T i k
+_▻_ = flip _◅_
+
+-- A corresponding variant of append.
+
+infixr 5 _▻▻_
+
+_▻▻_ : ∀ {i t} {I : Set i} {T : Rel I t} {i j k} →
+ Star T j k → Star T i j → Star T i k
+_▻▻_ = flip _◅◅_
+
+-- A generalised variant of map which allows the index type to change.
+
+gmap : ∀ {i j t u} {I : Set i} {T : Rel I t} {J : Set j} {U : Rel J u} →
+ (f : I → J) → T =[ f ]⇒ U → Star T =[ f ]⇒ Star U
+gmap f g ε = ε
+gmap f g (x ◅ xs) = g x ◅ gmap f g xs
+
+map : ∀ {i t u} {I : Set i} {T : Rel I t} {U : Rel I u} →
+ T ⇒ U → Star T ⇒ Star U
+map = gmap id
+
+-- A generalised variant of fold.
+
+gfold : ∀ {i j t p} {I : Set i} {J : Set j} {T : Rel I t}
+ (f : I → J) (P : Rel J p) →
+ Trans T (P on f) (P on f) →
+ TransFlip (Star T) (P on f) (P on f)
+gfold f P _⊕_ ∅ ε = ∅
+gfold f P _⊕_ ∅ (x ◅ xs) = x ⊕ gfold f P _⊕_ ∅ xs
+
+fold : ∀ {i t p} {I : Set i} {T : Rel I t} (P : Rel I p) →
+ Trans T P P → Reflexive P → Star T ⇒ P
+fold P _⊕_ ∅ = gfold id P _⊕_ ∅
+
+gfoldl : ∀ {i j t p} {I : Set i} {J : Set j} {T : Rel I t}
+ (f : I → J) (P : Rel J p) →
+ Trans (P on f) T (P on f) →
+ Trans (P on f) (Star T) (P on f)
+gfoldl f P _⊕_ ∅ ε = ∅
+gfoldl f P _⊕_ ∅ (x ◅ xs) = gfoldl f P _⊕_ (∅ ⊕ x) xs
+
+foldl : ∀ {i t p} {I : Set i} {T : Rel I t} (P : Rel I p) →
+ Trans P T P → Reflexive P → Star T ⇒ P
+foldl P _⊕_ ∅ = gfoldl id P _⊕_ ∅
+
+concat : ∀ {i t} {I : Set i} {T : Rel I t} → Star (Star T) ⇒ Star T
+concat {T = T} = fold (Star T) _◅◅_ ε
+
+-- If the underlying relation is symmetric, then the reflexive
+-- transitive closure is also symmetric.
+
+revApp : ∀ {i t u} {I : Set i} {T : Rel I t} {U : Rel I u} →
+ Sym T U → ∀ {i j k} → Star T j i → Star U j k → Star U i k
+revApp rev ε ys = ys
+revApp rev (x ◅ xs) ys = revApp rev xs (rev x ◅ ys)
+
+reverse : ∀ {i t u} {I : Set i} {T : Rel I t} {U : Rel I u} →
+ Sym T U → Sym (Star T) (Star U)
+reverse rev xs = revApp rev xs ε
+
+-- Reflexive transitive closures form a (generalised) monad.
+
+-- return could also be called singleton.
+
+return : ∀ {i t} {I : Set i} {T : Rel I t} → T ⇒ Star T
+return x = x ◅ ε
+
+-- A generalised variant of the Kleisli star (flip bind, or
+-- concatMap).
+
+kleisliStar : ∀ {i j t u}
+ {I : Set i} {J : Set j} {T : Rel I t} {U : Rel J u}
+ (f : I → J) → T =[ f ]⇒ Star U → Star T =[ f ]⇒ Star U
+kleisliStar f g = concat ∘′ gmap f g
+
+_⋆ : ∀ {i t u} {I : Set i} {T : Rel I t} {U : Rel I u} →
+ T ⇒ Star U → Star T ⇒ Star U
+_⋆ = kleisliStar id
+
+infixl 1 _>>=_
+
+_>>=_ : ∀ {i t u} {I : Set i} {T : Rel I t} {U : Rel I u} {i j} →
+ Star T i j → T ⇒ Star U → Star U i j
+m >>= f = (f ⋆) m
+
+-- Note that the monad-like structure above is not an indexed monad
+-- (as defined in Category.Monad.Indexed). If it were, then _>>=_
+-- would have a type similar to
+--
+-- ∀ {I} {T U : Rel I t} {i j k} →
+-- Star T i j → (T i j → Star U j k) → Star U i k.
+-- ^^^^^
+-- Note, however, that there is no scope for applying T to any indices
+-- in the definition used in Category.Monad.Indexed.
diff --git a/src/Relation/Binary/Construct/Closure/ReflexiveTransitive/Properties.agda b/src/Relation/Binary/Construct/Closure/ReflexiveTransitive/Properties.agda
new file mode 100644
index 0000000..52d4e2c
--- /dev/null
+++ b/src/Relation/Binary/Construct/Closure/ReflexiveTransitive/Properties.agda
@@ -0,0 +1,126 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Some properties of reflexive transitive closures.
+------------------------------------------------------------------------
+
+module Relation.Binary.Construct.Closure.ReflexiveTransitive.Properties where
+
+open import Function
+open import Relation.Binary
+open import Relation.Binary.Construct.Closure.ReflexiveTransitive
+open import Relation.Binary.PropositionalEquality as PropEq
+ using (_≡_; refl; sym; cong; cong₂)
+import Relation.Binary.PreorderReasoning as PreR
+
+------------------------------------------------------------------------
+-- Equality
+
+module _ {i t} {I : Set i} {T : Rel I t} {i j k} {x y : T i j} {xs ys} where
+
+ ◅-injectiveˡ : (Star T i k ∋ x ◅ xs) ≡ y ◅ ys → x ≡ y
+ ◅-injectiveˡ refl = refl
+
+ ◅-injectiveʳ : (Star T i k ∋ x ◅ xs) ≡ y ◅ ys → xs ≡ ys
+ ◅-injectiveʳ refl = refl
+
+------------------------------------------------------------------------
+-- _◅◅_
+
+module _ {i t} {I : Set i} {T : Rel I t} where
+
+ ◅◅-assoc : ∀ {i j k l}
+ (xs : Star T i j) (ys : Star T j k) (zs : Star T k l) →
+ (xs ◅◅ ys) ◅◅ zs ≡ xs ◅◅ (ys ◅◅ zs)
+ ◅◅-assoc ε ys zs = refl
+ ◅◅-assoc (x ◅ xs) ys zs = cong (_◅_ x) (◅◅-assoc xs ys zs)
+
+------------------------------------------------------------------------
+-- gmap
+
+gmap-id : ∀ {i t} {I : Set i} {T : Rel I t} {i j} (xs : Star T i j) →
+ gmap id id xs ≡ xs
+gmap-id ε = refl
+gmap-id (x ◅ xs) = cong (_◅_ x) (gmap-id xs)
+
+gmap-∘ : ∀ {i t} {I : Set i} {T : Rel I t}
+ {j u} {J : Set j} {U : Rel J u}
+ {k v} {K : Set k} {V : Rel K v}
+ (f : J → K) (g : U =[ f ]⇒ V)
+ (f′ : I → J) (g′ : T =[ f′ ]⇒ U)
+ {i j} (xs : Star T i j) →
+ (gmap {U = V} f g ∘ gmap f′ g′) xs ≡ gmap (f ∘ f′) (g ∘ g′) xs
+gmap-∘ f g f′ g′ ε = refl
+gmap-∘ f g f′ g′ (x ◅ xs) = cong (_◅_ (g (g′ x))) (gmap-∘ f g f′ g′ xs)
+
+gmap-◅◅ : ∀ {i t j u}
+ {I : Set i} {T : Rel I t} {J : Set j} {U : Rel J u}
+ (f : I → J) (g : T =[ f ]⇒ U)
+ {i j k} (xs : Star T i j) (ys : Star T j k) →
+ gmap {U = U} f g (xs ◅◅ ys) ≡ gmap f g xs ◅◅ gmap f g ys
+gmap-◅◅ f g ε ys = refl
+gmap-◅◅ f g (x ◅ xs) ys = cong (_◅_ (g x)) (gmap-◅◅ f g xs ys)
+
+gmap-cong : ∀ {i t j u}
+ {I : Set i} {T : Rel I t} {J : Set j} {U : Rel J u}
+ (f : I → J) (g : T =[ f ]⇒ U) (g′ : T =[ f ]⇒ U) →
+ (∀ {i j} (x : T i j) → g x ≡ g′ x) →
+ ∀ {i j} (xs : Star T i j) →
+ gmap {U = U} f g xs ≡ gmap f g′ xs
+gmap-cong f g g′ eq ε = refl
+gmap-cong f g g′ eq (x ◅ xs) = cong₂ _◅_ (eq x) (gmap-cong f g g′ eq xs)
+
+------------------------------------------------------------------------
+-- fold
+
+fold-◅◅ : ∀ {i p} {I : Set i}
+ (P : Rel I p) (_⊕_ : Transitive P) (∅ : Reflexive P) →
+ (∀ {i j} (x : P i j) → (∅ ⊕ x) ≡ x) →
+ (∀ {i j k l} (x : P i j) (y : P j k) (z : P k l) →
+ ((x ⊕ y) ⊕ z) ≡ (x ⊕ (y ⊕ z))) →
+ ∀ {i j k} (xs : Star P i j) (ys : Star P j k) →
+ fold P _⊕_ ∅ (xs ◅◅ ys) ≡ (fold P _⊕_ ∅ xs ⊕ fold P _⊕_ ∅ ys)
+fold-◅◅ P _⊕_ ∅ left-unit assoc ε ys = sym (left-unit _)
+fold-◅◅ P _⊕_ ∅ left-unit assoc (x ◅ xs) ys = begin
+ (x ⊕ fold P _⊕_ ∅ (xs ◅◅ ys)) ≡⟨ cong (_⊕_ x) $
+ fold-◅◅ P _⊕_ ∅ left-unit assoc xs ys ⟩
+ (x ⊕ (fold P _⊕_ ∅ xs ⊕ fold P _⊕_ ∅ ys)) ≡⟨ sym (assoc x _ _) ⟩
+ ((x ⊕ fold P _⊕_ ∅ xs) ⊕ fold P _⊕_ ∅ ys) ∎
+ where open PropEq.≡-Reasoning
+
+------------------------------------------------------------------------
+-- Relational properties
+
+module _ {i t} {I : Set i} (T : Rel I t) where
+
+ reflexive : _≡_ ⇒ Star T
+ reflexive refl = ε
+
+ trans : Transitive (Star T)
+ trans = _◅◅_
+
+ isPreorder : IsPreorder _≡_ (Star T)
+ isPreorder = record
+ { isEquivalence = PropEq.isEquivalence
+ ; reflexive = reflexive
+ ; trans = trans
+ }
+
+ preorder : Preorder _ _ _
+ preorder = record
+ { _≈_ = _≡_
+ ; _∼_ = Star T
+ ; isPreorder = isPreorder
+ }
+
+------------------------------------------------------------------------
+-- Preorder reasoning for Star
+
+module StarReasoning {i t} {I : Set i} (T : Rel I t) where
+ open PreR (preorder T) public
+ hiding (_≈⟨_⟩_) renaming (_∼⟨_⟩_ to _⟶⋆⟨_⟩_)
+
+ infixr 2 _⟶⟨_⟩_
+
+ _⟶⟨_⟩_ : ∀ x {y z} → T x y → y IsRelatedTo z → x IsRelatedTo z
+ x ⟶⟨ x⟶y ⟩ y⟶⋆z = x ⟶⋆⟨ x⟶y ◅ ε ⟩ y⟶⋆z
diff --git a/src/Relation/Binary/Construct/Closure/Symmetric.agda b/src/Relation/Binary/Construct/Closure/Symmetric.agda
new file mode 100644
index 0000000..96aa131
--- /dev/null
+++ b/src/Relation/Binary/Construct/Closure/Symmetric.agda
@@ -0,0 +1,36 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Symmetric closures of binary relations
+------------------------------------------------------------------------
+
+module Relation.Binary.Construct.Closure.Symmetric where
+
+open import Data.Sum as Sum using (_⊎_)
+open import Function using (id)
+open import Relation.Binary
+
+open Sum public using () renaming (inj₁ to fwd; inj₂ to bwd)
+
+-- The symmetric closure of a relation.
+
+SymClosure : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Rel A ℓ
+SymClosure _∼_ a b = a ∼ b ⊎ b ∼ a
+
+module _ {a ℓ} {A : Set a} where
+
+ -- Symmetric closures are symmetric.
+
+ symmetric : (_∼_ : Rel A ℓ) → Symmetric (SymClosure _∼_)
+ symmetric _ (fwd a∼b) = bwd a∼b
+ symmetric _ (bwd b∼a) = fwd b∼a
+
+ -- A generalised variant of map which allows the index type to change.
+
+ gmap : ∀ {b ℓ₂} {B : Set b} {P : Rel A ℓ} {Q : Rel B ℓ₂} →
+ (f : A → B) → P =[ f ]⇒ Q → SymClosure P =[ f ]⇒ SymClosure Q
+ gmap _ g = Sum.map g g
+
+ map : ∀ {ℓ₂} {P : Rel A ℓ} {Q : Rel A ℓ₂} →
+ P ⇒ Q → SymClosure P ⇒ SymClosure Q
+ map = gmap id
diff --git a/src/Relation/Binary/Construct/Closure/Transitive.agda b/src/Relation/Binary/Construct/Closure/Transitive.agda
new file mode 100644
index 0000000..348925d
--- /dev/null
+++ b/src/Relation/Binary/Construct/Closure/Transitive.agda
@@ -0,0 +1,99 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Transitive closures
+------------------------------------------------------------------------
+
+module Relation.Binary.Construct.Closure.Transitive where
+
+open import Function
+open import Function.Equivalence as Equiv using (_⇔_)
+open import Level
+open import Relation.Binary
+open import Relation.Binary.PropositionalEquality using (_≡_ ; refl)
+
+------------------------------------------------------------------------
+-- Transitive closure
+
+infix 4 Plus
+
+syntax Plus R x y = x [ R ]⁺ y
+
+data Plus {a ℓ} {A : Set a} (_∼_ : Rel A ℓ) : Rel A (a ⊔ ℓ) where
+ [_] : ∀ {x y} (x∼y : x ∼ y) → x [ _∼_ ]⁺ y
+ _∼⁺⟨_⟩_ : ∀ x {y z} (x∼⁺y : x [ _∼_ ]⁺ y) (y∼⁺z : y [ _∼_ ]⁺ z) →
+ x [ _∼_ ]⁺ z
+
+module _ {a ℓ} {A : Set a} {_∼_ : Rel A ℓ} where
+
+ []-injective : ∀ {x y p q} → (x [ _∼_ ]⁺ y ∋ [ p ]) ≡ [ q ] → p ≡ q
+ []-injective refl = refl
+
+ ∼⁺⟨⟩-injectiveˡ : ∀ {x y z} {p r : x [ _∼_ ]⁺ y} {q s} →
+ (x [ _∼_ ]⁺ z ∋ x ∼⁺⟨ p ⟩ q) ≡ (x ∼⁺⟨ r ⟩ s) → p ≡ r
+ ∼⁺⟨⟩-injectiveˡ refl = refl
+
+ ∼⁺⟨⟩-injectiveʳ : ∀ {x y z} {p r : x [ _∼_ ]⁺ y} {q s} →
+ (x [ _∼_ ]⁺ z ∋ x ∼⁺⟨ p ⟩ q) ≡ (x ∼⁺⟨ r ⟩ s) → q ≡ s
+ ∼⁺⟨⟩-injectiveʳ refl = refl
+
+
+-- "Equational" reasoning notation. Example:
+--
+-- lemma =
+-- x ∼⁺⟨ [ lemma₁ ] ⟩
+-- y ∼⁺⟨ lemma₂ ⟩∎
+-- z ∎
+
+finally : ∀ {a ℓ} {A : Set a} {_∼_ : Rel A ℓ} x y →
+ x [ _∼_ ]⁺ y → x [ _∼_ ]⁺ y
+finally _ _ = id
+
+syntax finally x y x∼⁺y = x ∼⁺⟨ x∼⁺y ⟩∎ y ∎
+
+infixr 2 _∼⁺⟨_⟩_
+infix 3 finally
+
+-- Map.
+
+map : ∀ {a a′ ℓ ℓ′} {A : Set a} {A′ : Set a′}
+ {_R_ : Rel A ℓ} {_R′_ : Rel A′ ℓ′} {f : A → A′} →
+ _R_ =[ f ]⇒ _R′_ → Plus _R_ =[ f ]⇒ Plus _R′_
+map R⇒R′ [ xRy ] = [ R⇒R′ xRy ]
+map R⇒R′ (x ∼⁺⟨ xR⁺z ⟩ zR⁺y) =
+ _ ∼⁺⟨ map R⇒R′ xR⁺z ⟩ map R⇒R′ zR⁺y
+
+------------------------------------------------------------------------
+-- Alternative definition of transitive closure
+
+-- A generalisation of Data.List.Nonempty.List⁺.
+
+infixr 5 _∷_ _++_
+infix 4 Plus′
+
+syntax Plus′ R x y = x ⟨ R ⟩⁺ y
+
+data Plus′ {a ℓ} {A : Set a} (_∼_ : Rel A ℓ) : Rel A (a ⊔ ℓ) where
+ [_] : ∀ {x y} (x∼y : x ∼ y) → x ⟨ _∼_ ⟩⁺ y
+ _∷_ : ∀ {x y z} (x∼y : x ∼ y) (y∼⁺z : y ⟨ _∼_ ⟩⁺ z) → x ⟨ _∼_ ⟩⁺ z
+
+-- Transitivity.
+
+_++_ : ∀ {a ℓ} {A : Set a} {_∼_ : Rel A ℓ} {x y z} →
+ x ⟨ _∼_ ⟩⁺ y → y ⟨ _∼_ ⟩⁺ z → x ⟨ _∼_ ⟩⁺ z
+[ x∼y ] ++ y∼⁺z = x∼y ∷ y∼⁺z
+(x∼y ∷ y∼⁺z) ++ z∼⁺u = x∼y ∷ (y∼⁺z ++ z∼⁺u)
+
+-- Plus and Plus′ are equivalent.
+
+equivalent : ∀ {a ℓ} {A : Set a} {_∼_ : Rel A ℓ} {x y} →
+ Plus _∼_ x y ⇔ Plus′ _∼_ x y
+equivalent {_∼_ = _∼_} = Equiv.equivalence complete sound
+ where
+ complete : Plus _∼_ ⇒ Plus′ _∼_
+ complete [ x∼y ] = [ x∼y ]
+ complete (x ∼⁺⟨ x∼⁺y ⟩ y∼⁺z) = complete x∼⁺y ++ complete y∼⁺z
+
+ sound : Plus′ _∼_ ⇒ Plus _∼_
+ sound [ x∼y ] = [ x∼y ]
+ sound (x∼y ∷ y∼⁺z) = _ ∼⁺⟨ [ x∼y ] ⟩ sound y∼⁺z
diff --git a/src/Relation/Binary/Construct/Constant.agda b/src/Relation/Binary/Construct/Constant.agda
new file mode 100644
index 0000000..9120d78
--- /dev/null
+++ b/src/Relation/Binary/Construct/Constant.agda
@@ -0,0 +1,39 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- The binary relation defined by a constant
+------------------------------------------------------------------------
+
+module Relation.Binary.Construct.Constant where
+
+open import Relation.Binary
+
+------------------------------------------------------------------------
+-- Definition
+
+Const : ∀ {a b c} {A : Set a} {B : Set b} → Set c → REL A B c
+Const I = λ _ _ → I
+
+------------------------------------------------------------------------
+-- Properties
+
+module _ {a c} (A : Set a) {C : Set c} where
+
+ refl : C → Reflexive {A = A} (Const C)
+ refl c = c
+
+ sym : Symmetric {A = A} (Const C)
+ sym c = c
+
+ trans : Transitive {A = A} (Const C)
+ trans c d = c
+
+ isEquivalence : C → IsEquivalence {A = A} (Const C)
+ isEquivalence c = record
+ { refl = λ {x} → refl c {x}
+ ; sym = λ {x} {y} → sym {x} {y}
+ ; trans = λ {x} {y} {z} → trans {x} {y} {z}
+ }
+
+ setoid : C → Setoid a c
+ setoid x = record { isEquivalence = isEquivalence x }
diff --git a/src/Relation/Binary/Construct/Converse.agda b/src/Relation/Binary/Construct/Converse.agda
new file mode 100644
index 0000000..835caf6
--- /dev/null
+++ b/src/Relation/Binary/Construct/Converse.agda
@@ -0,0 +1,196 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Many properties which hold for `∼` also hold for `flip ∼`. Unlike
+-- the module `Relation.Binary.Construct.Flip` this module does not
+-- flip the underlying equality.
+------------------------------------------------------------------------
+
+open import Relation.Binary
+
+module Relation.Binary.Construct.Converse where
+
+open import Function
+open import Data.Product
+
+------------------------------------------------------------------------
+-- Properties
+
+module _ {a ℓ} {A : Set a} (∼ : Rel A ℓ) where
+
+ refl : Reflexive ∼ → Reflexive (flip ∼)
+ refl refl = refl
+
+ sym : Symmetric ∼ → Symmetric (flip ∼)
+ sym sym = sym
+
+ trans : Transitive ∼ → Transitive (flip ∼)
+ trans trans = flip trans
+
+ asym : Asymmetric ∼ → Asymmetric (flip ∼)
+ asym asym = asym
+
+ total : Total ∼ → Total (flip ∼)
+ total total x y = total y x
+
+ resp : ∀ {p} (P : A → Set p) → Symmetric ∼ →
+ P Respects ∼ → P Respects (flip ∼)
+ resp _ sym resp ∼ = resp (sym ∼)
+
+ max : ∀ {⊥} → Minimum ∼ ⊥ → Maximum (flip ∼) ⊥
+ max min = min
+
+ min : ∀ {⊤} → Maximum ∼ ⊤ → Minimum (flip ∼) ⊤
+ min max = max
+
+module _ {a ℓ₁ ℓ₂} {A : Set a} {≈ : Rel A ℓ₁} (∼ : Rel A ℓ₂) where
+
+ reflexive : Symmetric ≈ → (≈ ⇒ ∼) → (≈ ⇒ flip ∼)
+ reflexive sym impl = impl ∘ sym
+
+ irrefl : Symmetric ≈ → Irreflexive ≈ ∼ → Irreflexive ≈ (flip ∼)
+ irrefl sym irrefl x≈y y∼x = irrefl (sym x≈y) y∼x
+
+ antisym : Antisymmetric ≈ ∼ → Antisymmetric ≈ (flip ∼)
+ antisym antisym = flip antisym
+
+ compare : Trichotomous ≈ ∼ → Trichotomous ≈ (flip ∼)
+ compare cmp x y with cmp x y
+ ... | tri< x<y x≉y y≮x = tri> y≮x x≉y x<y
+ ... | tri≈ x≮y x≈y y≮x = tri≈ y≮x x≈y x≮y
+ ... | tri> x≮y x≉y y<x = tri< y<x x≉y x≮y
+
+module _ {a ℓ₁ ℓ₂} {A : Set a} (∼₁ : Rel A ℓ₁) (∼₂ : Rel A ℓ₂) where
+
+ resp₂ : ∼₁ Respects₂ ∼₂ → (flip ∼₁) Respects₂ ∼₂
+ resp₂ (resp₁ , resp₂) = resp₂ , resp₁
+
+module _ {a b ℓ} {A : Set a} {B : Set b} (∼ : REL A B ℓ) where
+
+ dec : Decidable ∼ → Decidable (flip ∼)
+ dec dec = flip dec
+
+------------------------------------------------------------------------
+-- Structures
+
+module _ {a ℓ} {A : Set a} {≈ : Rel A ℓ} where
+
+ isEquivalence : IsEquivalence ≈ → IsEquivalence (flip ≈)
+ isEquivalence eq = record
+ { refl = refl ≈ Eq.refl
+ ; sym = sym ≈ Eq.sym
+ ; trans = trans ≈ Eq.trans
+ }
+ where module Eq = IsEquivalence eq
+
+ isDecEquivalence : IsDecEquivalence ≈ → IsDecEquivalence (flip ≈)
+ isDecEquivalence eq = record
+ { isEquivalence = isEquivalence Dec.isEquivalence
+ ; _≟_ = dec ≈ Dec._≟_
+ }
+ where module Dec = IsDecEquivalence eq
+
+module _ {a ℓ₁ ℓ₂} {A : Set a} {≈ : Rel A ℓ₁} {∼ : Rel A ℓ₂} where
+
+ isPreorder : IsPreorder ≈ ∼ → IsPreorder ≈ (flip ∼)
+ isPreorder O = record
+ { isEquivalence = O.isEquivalence
+ ; reflexive = reflexive ∼ O.Eq.sym O.reflexive
+ ; trans = trans ∼ O.trans
+ }
+ where module O = IsPreorder O
+
+ isPartialOrder : IsPartialOrder ≈ ∼ → IsPartialOrder ≈ (flip ∼)
+ isPartialOrder O = record
+ { isPreorder = isPreorder O.isPreorder
+ ; antisym = antisym ∼ O.antisym
+ }
+ where module O = IsPartialOrder O
+
+ isTotalOrder : IsTotalOrder ≈ ∼ → IsTotalOrder ≈ (flip ∼)
+ isTotalOrder O = record
+ { isPartialOrder = isPartialOrder O.isPartialOrder
+ ; total = total ∼ O.total
+ }
+ where module O = IsTotalOrder O
+
+ isDecTotalOrder : IsDecTotalOrder ≈ ∼ → IsDecTotalOrder ≈ (flip ∼)
+ isDecTotalOrder O = record
+ { isTotalOrder = isTotalOrder O.isTotalOrder
+ ; _≟_ = O._≟_
+ ; _≤?_ = dec ∼ O._≤?_
+ }
+ where module O = IsDecTotalOrder O
+
+ isStrictPartialOrder : IsStrictPartialOrder ≈ ∼ →
+ IsStrictPartialOrder ≈ (flip ∼)
+ isStrictPartialOrder O = record
+ { isEquivalence = O.isEquivalence
+ ; irrefl = irrefl ∼ O.Eq.sym O.irrefl
+ ; trans = trans ∼ O.trans
+ ; <-resp-≈ = resp₂ ∼ ≈ O.<-resp-≈
+ }
+ where module O = IsStrictPartialOrder O
+
+ isStrictTotalOrder : IsStrictTotalOrder ≈ ∼ →
+ IsStrictTotalOrder ≈ (flip ∼)
+ isStrictTotalOrder O = record
+ { isEquivalence = O.isEquivalence
+ ; trans = trans ∼ O.trans
+ ; compare = compare ∼ O.compare
+ }
+ where module O = IsStrictTotalOrder O
+
+module _ {a ℓ} where
+
+ setoid : Setoid a ℓ → Setoid a ℓ
+ setoid S = record
+ { isEquivalence = isEquivalence S.isEquivalence
+ }
+ where module S = Setoid S
+
+ decSetoid : DecSetoid a ℓ → DecSetoid a ℓ
+ decSetoid S = record
+ { isDecEquivalence = isDecEquivalence S.isDecEquivalence
+ }
+ where module S = DecSetoid S
+
+module _ {a ℓ₁ ℓ₂} where
+
+ preorder : Preorder a ℓ₁ ℓ₂ → Preorder a ℓ₁ ℓ₂
+ preorder O = record
+ { isPreorder = isPreorder O.isPreorder
+ }
+ where module O = Preorder O
+
+ poset : Poset a ℓ₁ ℓ₂ → Poset a ℓ₁ ℓ₂
+ poset O = record
+ { isPartialOrder = isPartialOrder O.isPartialOrder
+ }
+ where module O = Poset O
+
+ totalOrder : TotalOrder a ℓ₁ ℓ₂ → TotalOrder a ℓ₁ ℓ₂
+ totalOrder O = record
+ { isTotalOrder = isTotalOrder O.isTotalOrder
+ }
+ where module O = TotalOrder O
+
+ decTotalOrder : DecTotalOrder a ℓ₁ ℓ₂ → DecTotalOrder a ℓ₁ ℓ₂
+ decTotalOrder O = record
+ { isDecTotalOrder = isDecTotalOrder O.isDecTotalOrder
+ }
+ where module O = DecTotalOrder O
+
+ strictPartialOrder : StrictPartialOrder a ℓ₁ ℓ₂ →
+ StrictPartialOrder a ℓ₁ ℓ₂
+ strictPartialOrder O = record
+ { isStrictPartialOrder = isStrictPartialOrder O.isStrictPartialOrder
+ }
+ where module O = StrictPartialOrder O
+
+ strictTotalOrder : StrictTotalOrder a ℓ₁ ℓ₂ →
+ StrictTotalOrder a ℓ₁ ℓ₂
+ strictTotalOrder O = record
+ { isStrictTotalOrder = isStrictTotalOrder O.isStrictTotalOrder
+ }
+ where module O = StrictTotalOrder O
diff --git a/src/Relation/Binary/Construct/Flip.agda b/src/Relation/Binary/Construct/Flip.agda
new file mode 100644
index 0000000..2436646
--- /dev/null
+++ b/src/Relation/Binary/Construct/Flip.agda
@@ -0,0 +1,197 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Many properties which hold for `∼` also hold for `flip ∼`. Unlike
+-- the module `Relation.Binary.Construct.Converse` this module flips
+-- both the relation and the underlying equality.
+------------------------------------------------------------------------
+
+open import Relation.Binary
+
+module Relation.Binary.Construct.Flip where
+
+open import Function
+open import Data.Product
+
+------------------------------------------------------------------------
+-- Properties
+
+module _ {a ℓ} {A : Set a} (∼ : Rel A ℓ) where
+
+ reflexive : Reflexive ∼ → Reflexive (flip ∼)
+ reflexive refl = refl
+
+ symmetric : Symmetric ∼ → Symmetric (flip ∼)
+ symmetric sym = sym
+
+ transitive : Transitive ∼ → Transitive (flip ∼)
+ transitive trans = flip trans
+
+ asymmetric : Asymmetric ∼ → Asymmetric (flip ∼)
+ asymmetric asym = asym
+
+ total : Total ∼ → Total (flip ∼)
+ total total x y = total y x
+
+ respects : ∀ {p} (P : A → Set p) → Symmetric ∼ →
+ P Respects ∼ → P Respects flip ∼
+ respects _ sym resp ∼ = resp (sym ∼)
+
+ max : ∀ {⊥} → Minimum ∼ ⊥ → Maximum (flip ∼) ⊥
+ max min = min
+
+ min : ∀ {⊤} → Maximum ∼ ⊤ → Minimum (flip ∼) ⊤
+ min max = max
+
+module _ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b}
+ (≈ : REL A B ℓ₁) (∼ : REL A B ℓ₂) where
+
+ implies : ≈ ⇒ ∼ → flip ≈ ⇒ flip ∼
+ implies impl = impl
+
+ irreflexive : Irreflexive ≈ ∼ → Irreflexive (flip ≈) (flip ∼)
+ irreflexive irrefl = irrefl
+
+module _ {a ℓ₁ ℓ₂} {A : Set a} (≈ : Rel A ℓ₁) (∼ : Rel A ℓ₂) where
+
+ antisymmetric : Antisymmetric ≈ ∼ → Antisymmetric (flip ≈) (flip ∼)
+ antisymmetric antisym = antisym
+
+ trichotomous : Trichotomous ≈ ∼ → Trichotomous (flip ≈) (flip ∼)
+ trichotomous compare x y = compare y x
+
+module _ {a ℓ₁ ℓ₂} {A : Set a} (∼₁ : Rel A ℓ₁) (∼₂ : Rel A ℓ₂) where
+
+ respects₂ : Symmetric ∼₂ → ∼₁ Respects₂ ∼₂ → flip ∼₁ Respects₂ flip ∼₂
+ respects₂ sym (resp₁ , resp₂) = (resp₂ ∘ sym , resp₁ ∘ sym)
+
+module _ {a b ℓ} {A : Set a} {B : Set b} (∼ : REL A B ℓ) where
+
+ decidable : Decidable ∼ → Decidable (flip ∼)
+ decidable dec x y = dec y x
+
+module _ {a ℓ} {A : Set a} {≈ : Rel A ℓ} where
+
+ isEquivalence : IsEquivalence ≈ → IsEquivalence (flip ≈)
+ isEquivalence eq = record
+ { refl = reflexive ≈ Eq.refl
+ ; sym = symmetric ≈ Eq.sym
+ ; trans = transitive ≈ Eq.trans
+ }
+ where module Eq = IsEquivalence eq
+
+ isDecEquivalence : IsDecEquivalence ≈ → IsDecEquivalence (flip ≈)
+ isDecEquivalence dec = record
+ { isEquivalence = isEquivalence Dec.isEquivalence
+ ; _≟_ = decidable ≈ Dec._≟_
+ }
+ where module Dec = IsDecEquivalence dec
+
+------------------------------------------------------------------------
+-- Structures
+
+module _ {a ℓ₁ ℓ₂} {A : Set a} {≈ : Rel A ℓ₁} {∼ : Rel A ℓ₂} where
+
+ isPreorder : IsPreorder ≈ ∼ → IsPreorder (flip ≈) (flip ∼)
+ isPreorder O = record
+ { isEquivalence = isEquivalence O.isEquivalence
+ ; reflexive = implies ≈ ∼ O.reflexive
+ ; trans = transitive ∼ O.trans
+ }
+ where module O = IsPreorder O
+
+ isPartialOrder : IsPartialOrder ≈ ∼ → IsPartialOrder (flip ≈) (flip ∼)
+ isPartialOrder O = record
+ { isPreorder = isPreorder O.isPreorder
+ ; antisym = antisymmetric ≈ ∼ O.antisym
+ }
+ where module O = IsPartialOrder O
+
+ isTotalOrder : IsTotalOrder ≈ ∼ → IsTotalOrder (flip ≈) (flip ∼)
+ isTotalOrder O = record
+ { isPartialOrder = isPartialOrder O.isPartialOrder
+ ; total = total ∼ O.total
+ }
+ where module O = IsTotalOrder O
+
+ isDecTotalOrder : IsDecTotalOrder ≈ ∼ → IsDecTotalOrder (flip ≈) (flip ∼)
+ isDecTotalOrder O = record
+ { isTotalOrder = isTotalOrder O.isTotalOrder
+ ; _≟_ = decidable ≈ O._≟_
+ ; _≤?_ = decidable ∼ O._≤?_
+ }
+ where module O = IsDecTotalOrder O
+
+ isStrictPartialOrder : IsStrictPartialOrder ≈ ∼ →
+ IsStrictPartialOrder (flip ≈) (flip ∼)
+ isStrictPartialOrder O = record
+ { isEquivalence = isEquivalence O.isEquivalence
+ ; irrefl = irreflexive ≈ ∼ O.irrefl
+ ; trans = transitive ∼ O.trans
+ ; <-resp-≈ = respects₂ ∼ ≈ O.Eq.sym O.<-resp-≈
+ }
+ where module O = IsStrictPartialOrder O
+
+ isStrictTotalOrder : IsStrictTotalOrder ≈ ∼ →
+ IsStrictTotalOrder (flip ≈) (flip ∼)
+ isStrictTotalOrder O = record
+ { isEquivalence = isEquivalence O.isEquivalence
+ ; trans = transitive ∼ O.trans
+ ; compare = trichotomous ≈ ∼ O.compare
+ } where module O = IsStrictTotalOrder O
+
+module _ {a ℓ} where
+
+ setoid : Setoid a ℓ → Setoid a ℓ
+ setoid S = record
+ { _≈_ = flip S._≈_
+ ; isEquivalence = isEquivalence S.isEquivalence
+ }
+ where module S = Setoid S
+
+ decSetoid : DecSetoid a ℓ → DecSetoid a ℓ
+ decSetoid S = record
+ { _≈_ = flip S._≈_
+ ; isDecEquivalence = isDecEquivalence S.isDecEquivalence
+ }
+ where module S = DecSetoid S
+
+module _ {a ℓ₁ ℓ₂} where
+
+ preorder : Preorder a ℓ₁ ℓ₂ → Preorder a ℓ₁ ℓ₂
+ preorder O = record
+ { isPreorder = isPreorder O.isPreorder
+ }
+ where module O = Preorder O
+
+ poset : Poset a ℓ₁ ℓ₂ → Poset a ℓ₁ ℓ₂
+ poset O = record
+ { isPartialOrder = isPartialOrder O.isPartialOrder
+ }
+ where module O = Poset O
+
+ totalOrder : TotalOrder a ℓ₁ ℓ₂ → TotalOrder a ℓ₁ ℓ₂
+ totalOrder O = record
+ { isTotalOrder = isTotalOrder O.isTotalOrder
+ }
+ where module O = TotalOrder O
+
+ decTotalOrder : DecTotalOrder a ℓ₁ ℓ₂ → DecTotalOrder a ℓ₁ ℓ₂
+ decTotalOrder O = record
+ { isDecTotalOrder = isDecTotalOrder O.isDecTotalOrder
+ }
+ where module O = DecTotalOrder O
+
+ strictPartialOrder : StrictPartialOrder a ℓ₁ ℓ₂ →
+ StrictPartialOrder a ℓ₁ ℓ₂
+ strictPartialOrder O = record
+ { isStrictPartialOrder = isStrictPartialOrder O.isStrictPartialOrder
+ }
+ where module O = StrictPartialOrder O
+
+ strictTotalOrder : StrictTotalOrder a ℓ₁ ℓ₂ →
+ StrictTotalOrder a ℓ₁ ℓ₂
+ strictTotalOrder O = record
+ { isStrictTotalOrder = isStrictTotalOrder O.isStrictTotalOrder
+ }
+ where module O = StrictTotalOrder O
diff --git a/src/Relation/Binary/Construct/FromPred.agda b/src/Relation/Binary/Construct/FromPred.agda
new file mode 100644
index 0000000..2b1b521
--- /dev/null
+++ b/src/Relation/Binary/Construct/FromPred.agda
@@ -0,0 +1,49 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Every respectful unary relation induces a preorder. No claim is
+-- made that this preorder is unique.
+------------------------------------------------------------------------
+
+open import Relation.Binary
+open import Relation.Unary using (Pred)
+
+module Relation.Binary.Construct.FromPred
+ {s₁ s₂} (S : Setoid s₁ s₂) -- The underlying equality
+ {p} (P : Pred (Setoid.Carrier S) p) -- The predicate
+ where
+
+open import Function
+open import Data.Product
+
+open module Eq = Setoid S using (_≈_) renaming (Carrier to A)
+
+------------------------------------------------------------------------
+-- Definition
+
+Resp : Rel A p
+Resp x y = P x → P y
+
+------------------------------------------------------------------------
+-- Properties
+
+reflexive : P Respects _≈_ → _≈_ ⇒ Resp
+reflexive resp = resp
+
+refl : P Respects _≈_ → Reflexive Resp
+refl resp = resp Eq.refl
+
+trans : Transitive Resp
+trans x⇒y y⇒z = y⇒z ∘ x⇒y
+
+isPreorder : P Respects _≈_ → IsPreorder _≈_ Resp
+isPreorder resp = record
+ { isEquivalence = Eq.isEquivalence
+ ; reflexive = reflexive resp
+ ; trans = flip _∘′_
+ }
+
+preorder : P Respects _≈_ → Preorder _ _ _
+preorder resp = record
+ { isPreorder = isPreorder resp
+ }
diff --git a/src/Relation/Binary/Construct/FromRel.agda b/src/Relation/Binary/Construct/FromRel.agda
new file mode 100644
index 0000000..7417ec4
--- /dev/null
+++ b/src/Relation/Binary/Construct/FromRel.agda
@@ -0,0 +1,47 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Every respectful binary relation induces a preorder. No claim is
+-- made that this preorder is unique.
+------------------------------------------------------------------------
+
+open import Relation.Binary
+open Setoid using (Carrier)
+
+module Relation.Binary.Construct.FromRel
+ {s₁ s₂} (S : Setoid s₁ s₂) -- The underlying equality
+ {a r} {A : Set a} (_R_ : REL A (Carrier S) r) -- The relation
+ where
+
+open import Data.Product
+open import Function
+open import Level using (_⊔_)
+
+open module Eq = Setoid S using (_≈_) renaming (Carrier to B)
+
+------------------------------------------------------------------------
+-- Definition
+
+Resp : Rel B (a ⊔ r)
+Resp x y = ∀ {a} → a R x → a R y
+
+------------------------------------------------------------------------
+-- Properties
+
+reflexive : (∀ {a} → (a R_) Respects _≈_) → _≈_ ⇒ Resp
+reflexive resp x≈y = resp x≈y
+
+trans : Transitive Resp
+trans x∼y y∼z = y∼z ∘ x∼y
+
+isPreorder : (∀ {a} → (a R_) Respects _≈_) → IsPreorder _≈_ Resp
+isPreorder resp = record
+ { isEquivalence = Eq.isEquivalence
+ ; reflexive = reflexive resp
+ ; trans = trans
+ }
+
+preorder : (∀ {a} → (a R_) Respects _≈_) → Preorder _ _ _
+preorder resp = record
+ { isPreorder = isPreorder resp
+ }
diff --git a/src/Relation/Binary/Construct/Never.agda b/src/Relation/Binary/Construct/Never.agda
new file mode 100644
index 0000000..b0033cb
--- /dev/null
+++ b/src/Relation/Binary/Construct/Never.agda
@@ -0,0 +1,18 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- The empty binary relation
+------------------------------------------------------------------------
+
+module Relation.Binary.Construct.Never where
+
+open import Relation.Binary
+open import Relation.Binary.Construct.Constant
+open import Data.Empty using (⊥)
+open import Level using (Lift; lift)
+
+------------------------------------------------------------------------
+-- Definition
+
+Never : ∀ {a ℓ} {A : Set a} → Rel A ℓ
+Never = Const (Lift _ ⊥)
diff --git a/src/Relation/Binary/Construct/NonStrictToStrict.agda b/src/Relation/Binary/Construct/NonStrictToStrict.agda
new file mode 100644
index 0000000..d5809c9
--- /dev/null
+++ b/src/Relation/Binary/Construct/NonStrictToStrict.agda
@@ -0,0 +1,151 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Conversion of _≤_ to _<_
+------------------------------------------------------------------------
+
+open import Relation.Binary
+
+module Relation.Binary.Construct.NonStrictToStrict
+ {a ℓ₁ ℓ₂} {A : Set a} (_≈_ : Rel A ℓ₁) (_≤_ : Rel A ℓ₂) where
+
+open import Data.Product using (_×_; _,_; proj₁; proj₂)
+open import Data.Sum using (inj₁; inj₂)
+open import Function using (_∘_; flip)
+open import Relation.Nullary using (¬_; yes; no)
+
+------------------------------------------------------------------------
+-- _≤_ can be turned into _<_ as follows:
+
+_<_ : Rel A _
+x < y = (x ≤ y) × ¬ (x ≈ y)
+
+------------------------------------------------------------------------
+-- The converted relations have certain properties
+-- (if the original relations have certain other properties)
+
+<⇒≤ : _<_ ⇒ _≤_
+<⇒≤ = proj₁
+
+<-irrefl : Irreflexive _≈_ _<_
+<-irrefl x≈y (_ , x≉y) = x≉y x≈y
+
+<-trans : IsPartialOrder _≈_ _≤_ → Transitive _<_
+<-trans po (x≤y , x≉y) (y≤z , y≉z) =
+ (trans x≤y y≤z , x≉y ∘ antisym x≤y ∘ trans y≤z ∘ reflexive ∘ Eq.sym)
+ where open IsPartialOrder po
+
+<-≤-trans : Symmetric _≈_ → Transitive _≤_ → Antisymmetric _≈_ _≤_ →
+ _≤_ Respectsʳ _≈_ → Trans _<_ _≤_ _<_
+<-≤-trans sym trans antisym respʳ (x≤y , x≉y) y≤z =
+ trans x≤y y≤z , (λ x≈z → x≉y (antisym x≤y (respʳ (sym x≈z) y≤z)))
+
+≤-<-trans : Transitive _≤_ → Antisymmetric _≈_ _≤_ →
+ _≤_ Respectsˡ _≈_ → Trans _≤_ _<_ _<_
+≤-<-trans trans antisym respʳ x≤y (y≤z , y≉z) =
+ trans x≤y y≤z , (λ x≈z → y≉z (antisym y≤z (respʳ x≈z x≤y)))
+
+<-asym : Antisymmetric _≈_ _≤_ → Asymmetric _<_
+<-asym antisym (x≤y , x≉y) (y≤x , _) = x≉y (antisym x≤y y≤x)
+
+<-respˡ-≈ : Transitive _≈_ → _≤_ Respectsˡ _≈_ → _<_ Respectsˡ _≈_
+<-respˡ-≈ trans respˡ y≈z (y≤x , y≉x) =
+ (respˡ y≈z y≤x) , (λ z≈x → y≉x (trans y≈z z≈x))
+
+<-respʳ-≈ : Symmetric _≈_ → Transitive _≈_ →
+ _≤_ Respectsʳ _≈_ → _<_ Respectsʳ _≈_
+<-respʳ-≈ sym trans respʳ {x} {y} {z} y≈z (x≤y , x≉y) =
+ (respʳ y≈z x≤y) , λ x≈z → x≉y (trans x≈z (sym y≈z))
+
+<-resp-≈ : IsEquivalence _≈_ → _≤_ Respects₂ _≈_ → _<_ Respects₂ _≈_
+<-resp-≈ eq (respʳ , respˡ) =
+ <-respʳ-≈ sym trans respʳ , <-respˡ-≈ trans respˡ
+ where open IsEquivalence eq
+
+<-trichotomous : Symmetric _≈_ → Decidable _≈_ →
+ Antisymmetric _≈_ _≤_ → Total _≤_ →
+ Trichotomous _≈_ _<_
+<-trichotomous ≈-sym _≟_ antisym total x y with x ≟ y
+... | yes x≈y = tri≈ (<-irrefl x≈y) x≈y (<-irrefl (≈-sym x≈y))
+... | no x≉y with total x y
+... | inj₁ x≤y = tri< (x≤y , x≉y) x≉y
+ (x≉y ∘ antisym x≤y ∘ proj₁)
+... | inj₂ x≥y = tri> (x≉y ∘ flip antisym x≥y ∘ proj₁) x≉y
+ (x≥y , x≉y ∘ ≈-sym)
+
+<-decidable : Decidable _≈_ → Decidable _≤_ → Decidable _<_
+<-decidable _≟_ _≤?_ x y with x ≟ y | x ≤? y
+... | yes x≈y | _ = no (flip proj₂ x≈y)
+... | no x≉y | yes x≤y = yes (x≤y , x≉y)
+... | no x≉y | no x≰y = no (x≰y ∘ proj₁)
+
+<-isStrictPartialOrder : IsPartialOrder _≈_ _≤_ →
+ IsStrictPartialOrder _≈_ _<_
+<-isStrictPartialOrder po = record
+ { isEquivalence = isEquivalence
+ ; irrefl = <-irrefl
+ ; trans = <-trans po
+ ; <-resp-≈ = <-resp-≈ isEquivalence ≤-resp-≈
+ } where open IsPartialOrder po
+
+<-isStrictTotalOrder₁ : Decidable _≈_ → IsTotalOrder _≈_ _≤_ →
+ IsStrictTotalOrder _≈_ _<_
+<-isStrictTotalOrder₁ ≟ tot = record
+ { isEquivalence = isEquivalence
+ ; trans = <-trans isPartialOrder
+ ; compare = <-trichotomous Eq.sym ≟ antisym total
+ } where open IsTotalOrder tot
+
+<-isStrictTotalOrder₂ : IsDecTotalOrder _≈_ _≤_ →
+ IsStrictTotalOrder _≈_ _<_
+<-isStrictTotalOrder₂ dtot = <-isStrictTotalOrder₁ _≟_ isTotalOrder
+ where open IsDecTotalOrder dtot
+
+------------------------------------------------------------------------
+-- DEPRECATED NAMES
+------------------------------------------------------------------------
+-- Please use the new names as continuing support for the old names is
+-- not guaranteed.
+
+-- Version 0.16
+
+irrefl = <-irrefl
+{-# WARNING_ON_USAGE irrefl
+"Warning: irrefl was deprecated in v0.16.
+Please use <-irrefl instead."
+#-}
+trans = <-trans
+{-# WARNING_ON_USAGE trans
+"Warning: trans was deprecated in v0.16.
+Please use <-trans instead."
+#-}
+antisym⟶asym = <-asym
+{-# WARNING_ON_USAGE antisym⟶asym
+"Warning: antisym⟶asym was deprecated in v0.16.
+Please use <-asym instead."
+#-}
+decidable = <-decidable
+{-# WARNING_ON_USAGE decidable
+"Warning: decidable was deprecated in v0.16.
+Please use <-decidable instead."
+#-}
+trichotomous = <-trichotomous
+{-# WARNING_ON_USAGE trichotomous
+"Warning: trichotomous was deprecated in v0.16.
+Please use <-trichotomous instead."
+#-}
+isPartialOrder⟶isStrictPartialOrder = <-isStrictPartialOrder
+{-# WARNING_ON_USAGE isPartialOrder⟶isStrictPartialOrder
+"Warning: isPartialOrder⟶isStrictPartialOrder was deprecated in v0.16.
+Please use <-isStrictPartialOrder instead."
+#-}
+isTotalOrder⟶isStrictTotalOrder = <-isStrictTotalOrder₁
+{-# WARNING_ON_USAGE isTotalOrder⟶isStrictTotalOrder
+"Warning: isTotalOrder⟶isStrictTotalOrder was deprecated in v0.16.
+Please use <-isStrictTotalOrder₁ instead."
+#-}
+isDecTotalOrder⟶isStrictTotalOrder = <-isStrictTotalOrder₂
+{-# WARNING_ON_USAGE isDecTotalOrder⟶isStrictTotalOrder
+"Warning: isDecTotalOrder⟶isStrictTotalOrder was deprecated in v0.16.
+Please use <-isStrictTotalOrder₂ instead."
+#-}
diff --git a/src/Relation/Binary/On.agda b/src/Relation/Binary/Construct/On.agda
index 6ec98e5..47c9b66 100644
--- a/src/Relation/Binary/On.agda
+++ b/src/Relation/Binary/Construct/On.agda
@@ -6,7 +6,7 @@
open import Relation.Binary
-module Relation.Binary.On where
+module Relation.Binary.Construct.On where
open import Function
open import Data.Product
diff --git a/src/Relation/Binary/Construct/StrictToNonStrict.agda b/src/Relation/Binary/Construct/StrictToNonStrict.agda
new file mode 100644
index 0000000..21e6693
--- /dev/null
+++ b/src/Relation/Binary/Construct/StrictToNonStrict.agda
@@ -0,0 +1,144 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Conversion of < to ≤, along with a number of properties
+------------------------------------------------------------------------
+
+-- Possible TODO: Prove that a conversion ≤ → < → ≤ returns a
+-- relation equivalent to the original one (and similarly for
+-- < → ≤ → <).
+
+open import Relation.Binary
+
+module Relation.Binary.Construct.StrictToNonStrict
+ {a ℓ₁ ℓ₂} {A : Set a}
+ (_≈_ : Rel A ℓ₁) (_<_ : Rel A ℓ₂)
+ where
+
+open import Relation.Nullary
+open import Relation.Binary.Consequences
+open import Function
+open import Data.Product
+open import Data.Sum
+open import Data.Empty
+
+------------------------------------------------------------------------
+-- Conversion
+
+-- _<_ can be turned into _≤_ as follows:
+
+_≤_ : Rel A _
+x ≤ y = (x < y) ⊎ (x ≈ y)
+
+------------------------------------------------------------------------
+-- The converted relations have certain properties
+-- (if the original relations have certain other properties)
+
+<⇒≤ : _<_ ⇒ _≤_
+<⇒≤ = inj₁
+
+reflexive : _≈_ ⇒ _≤_
+reflexive = inj₂
+
+antisym : IsEquivalence _≈_ → Transitive _<_ → Irreflexive _≈_ _<_ →
+ Antisymmetric _≈_ _≤_
+antisym eq trans irrefl = as
+ where
+ module Eq = IsEquivalence eq
+
+ as : Antisymmetric _≈_ _≤_
+ as (inj₂ x≈y) _ = x≈y
+ as (inj₁ _) (inj₂ y≈x) = Eq.sym y≈x
+ as (inj₁ x<y) (inj₁ y<x) =
+ ⊥-elim (trans∧irr⟶asym {_≈_ = _≈_} Eq.refl trans irrefl x<y y<x)
+
+trans : IsEquivalence _≈_ → _<_ Respects₂ _≈_ → Transitive _<_ →
+ Transitive _≤_
+trans eq (respʳ , respˡ) <-trans = tr
+ where
+ module Eq = IsEquivalence eq
+
+ tr : Transitive _≤_
+ tr (inj₁ x<y) (inj₁ y<z) = inj₁ $ <-trans x<y y<z
+ tr (inj₁ x<y) (inj₂ y≈z) = inj₁ $ respʳ y≈z x<y
+ tr (inj₂ x≈y) (inj₁ y<z) = inj₁ $ respˡ (Eq.sym x≈y) y<z
+ tr (inj₂ x≈y) (inj₂ y≈z) = inj₂ $ Eq.trans x≈y y≈z
+
+<-≤-trans : Transitive _<_ → _<_ Respectsʳ _≈_ → Trans _<_ _≤_ _<_
+<-≤-trans trans respʳ x<y (inj₁ y<z) = trans x<y y<z
+<-≤-trans trans respʳ x<y (inj₂ y≈z) = respʳ y≈z x<y
+
+≤-<-trans : Symmetric _≈_ → Transitive _<_ → _<_ Respectsˡ _≈_ → Trans _≤_ _<_ _<_
+≤-<-trans sym trans respˡ (inj₁ x<y) y<z = trans x<y y<z
+≤-<-trans sym trans respˡ (inj₂ x≈y) y<z = respˡ (sym x≈y) y<z
+
+≤-respʳ-≈ : Transitive _≈_ → _<_ Respectsʳ _≈_ → _≤_ Respectsʳ _≈_
+≤-respʳ-≈ trans respʳ y'≈y (inj₁ x<y') = inj₁ (respʳ y'≈y x<y')
+≤-respʳ-≈ trans respʳ y'≈y (inj₂ x≈y') = inj₂ (trans x≈y' y'≈y)
+
+≤-respˡ-≈ : Symmetric _≈_ → Transitive _≈_ → _<_ Respectsˡ _≈_ → _≤_ Respectsˡ _≈_
+≤-respˡ-≈ sym trans respˡ x'≈x (inj₁ x'<y) = inj₁ (respˡ x'≈x x'<y)
+≤-respˡ-≈ sym trans respˡ x'≈x (inj₂ x'≈y) = inj₂ (trans (sym x'≈x) x'≈y)
+
+≤-resp-≈ : IsEquivalence _≈_ → _<_ Respects₂ _≈_ → _≤_ Respects₂ _≈_
+≤-resp-≈ eq (respʳ , respˡ) = ≤-respʳ-≈ Eq.trans respʳ , ≤-respˡ-≈ Eq.sym Eq.trans respˡ
+ where module Eq = IsEquivalence eq
+
+total : Trichotomous _≈_ _<_ → Total _≤_
+total <-tri x y with <-tri x y
+... | tri< x<y x≉y x≯y = inj₁ (inj₁ x<y)
+... | tri≈ x≮y x≈y x≯y = inj₁ (inj₂ x≈y)
+... | tri> x≮y x≉y x>y = inj₂ (inj₁ x>y)
+
+decidable : Decidable _≈_ → Decidable _<_ → Decidable _≤_
+decidable ≈-dec <-dec x y with ≈-dec x y | <-dec x y
+... | yes x≈y | _ = yes (inj₂ x≈y)
+... | no x≉y | yes x<y = yes (inj₁ x<y)
+... | no x≉y | no x≮y = no [ x≮y , x≉y ]′
+
+decidable' : Trichotomous _≈_ _<_ → Decidable _≤_
+decidable' compare x y with compare x y
+... | tri< x<y _ _ = yes (inj₁ x<y)
+... | tri≈ _ x≈y _ = yes (inj₂ x≈y)
+... | tri> x≮y x≉y _ = no [ x≮y , x≉y ]′
+
+------------------------------------------------------------------------
+-- Converting structures
+
+isPreorder₁ : IsPreorder _≈_ _<_ → IsPreorder _≈_ _≤_
+isPreorder₁ PO = record
+ { isEquivalence = S.isEquivalence
+ ; reflexive = reflexive
+ ; trans = trans S.isEquivalence S.∼-resp-≈ S.trans
+ }
+ where module S = IsPreorder PO
+
+isPreorder₂ : IsStrictPartialOrder _≈_ _<_ → IsPreorder _≈_ _≤_
+isPreorder₂ SPO = record
+ { isEquivalence = S.isEquivalence
+ ; reflexive = reflexive
+ ; trans = trans S.isEquivalence S.<-resp-≈ S.trans
+ }
+ where module S = IsStrictPartialOrder SPO
+
+isPartialOrder : IsStrictPartialOrder _≈_ _<_ → IsPartialOrder _≈_ _≤_
+isPartialOrder SPO = record
+ { isPreorder = isPreorder₂ SPO
+ ; antisym = antisym S.isEquivalence S.trans S.irrefl
+ }
+ where module S = IsStrictPartialOrder SPO
+
+isTotalOrder : IsStrictTotalOrder _≈_ _<_ → IsTotalOrder _≈_ _≤_
+isTotalOrder STO = record
+ { isPartialOrder = isPartialOrder S.isStrictPartialOrder
+ ; total = total S.compare
+ }
+ where module S = IsStrictTotalOrder STO
+
+isDecTotalOrder : IsStrictTotalOrder _≈_ _<_ → IsDecTotalOrder _≈_ _≤_
+isDecTotalOrder STO = record
+ { isTotalOrder = isTotalOrder STO
+ ; _≟_ = S._≟_
+ ; _≤?_ = decidable' S.compare
+ }
+ where module S = IsStrictTotalOrder STO
diff --git a/src/Relation/Binary/Core.agda b/src/Relation/Binary/Core.agda
index 8b927f8..76deae6 100644
--- a/src/Relation/Binary/Core.agda
+++ b/src/Relation/Binary/Core.agda
@@ -9,10 +9,13 @@
module Relation.Binary.Core where
-open import Data.Product
-open import Function
+open import Agda.Builtin.Equality using (_≡_) renaming (refl to ≡-refl)
+
+open import Data.Product using (_×_)
+open import Data.Sum.Base using (_⊎_)
+open import Function using (_on_; flip)
open import Level
-open import Relation.Nullary
+open import Relation.Nullary using (Dec; ¬_)
------------------------------------------------------------------------
-- Binary relations
@@ -38,8 +41,7 @@ _⇒_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} →
REL A B ℓ₁ → REL A B ℓ₂ → Set _
P ⇒ Q = ∀ {i j} → P i j → Q i j
--- Generalised implication. If P ≡ Q it can be read as "f preserves
--- P".
+-- Generalised implication. If P ≡ Q it can be read as "f preserves P".
_=[_]⇒_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} →
Rel A ℓ₁ → (A → B) → Rel B ℓ₂ → Set _
@@ -100,13 +102,36 @@ Antisymmetric _≈_ _≤_ = ∀ {x y} → x ≤ y → y ≤ x → x ≈ y
Asymmetric : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Set _
Asymmetric _<_ = ∀ {x y} → x < y → ¬ (y < x)
+Total : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Set _
+Total _∼_ = ∀ x y → (x ∼ y) ⊎ (y ∼ x)
+
+data Tri {a b c} (A : Set a) (B : Set b) (C : Set c) :
+ Set (a ⊔ b ⊔ c) where
+ tri< : ( a : A) (¬b : ¬ B) (¬c : ¬ C) → Tri A B C
+ tri≈ : (¬a : ¬ A) ( b : B) (¬c : ¬ C) → Tri A B C
+ tri> : (¬a : ¬ A) (¬b : ¬ B) ( c : C) → Tri A B C
+
+Trichotomous : ∀ {a ℓ₁ ℓ₂} {A : Set a} → Rel A ℓ₁ → Rel A ℓ₂ → Set _
+Trichotomous _≈_ _<_ = ∀ x y → Tri (x < y) (x ≈ y) (x > y)
+ where _>_ = flip _<_
+
+Maximum : ∀ {a ℓ} {A : Set a} → Rel A ℓ → A → Set _
+Maximum _≤_ ⊤ = ∀ x → x ≤ ⊤
+
+Minimum : ∀ {a ℓ} {A : Set a} → Rel A ℓ → A → Set _
+Minimum _≤_ = Maximum (flip _≤_)
+
_Respects_ : ∀ {a ℓ₁ ℓ₂} {A : Set a} → (A → Set ℓ₁) → Rel A ℓ₂ → Set _
P Respects _∼_ = ∀ {x y} → x ∼ y → P x → P y
+_Respectsʳ_ : ∀ {a ℓ₁ ℓ₂} {A : Set a} → Rel A ℓ₁ → Rel A ℓ₂ → Set _
+P Respectsʳ _∼_ = ∀ {x} → (P x) Respects _∼_
+
+_Respectsˡ_ : ∀ {a ℓ₁ ℓ₂} {A : Set a} → Rel A ℓ₁ → Rel A ℓ₂ → Set _
+P Respectsˡ _∼_ = ∀ {y} → (flip P y) Respects _∼_
+
_Respects₂_ : ∀ {a ℓ₁ ℓ₂} {A : Set a} → Rel A ℓ₁ → Rel A ℓ₂ → Set _
-P Respects₂ _∼_ =
- (∀ {x} → P x Respects _∼_) ×
- (∀ {y} → flip P y Respects _∼_)
+P Respects₂ _∼_ = (P Respectsʳ _∼_) × (P Respectsˡ _∼_)
Substitutive : ∀ {a ℓ₁} {A : Set a} → Rel A ℓ₁ → (ℓ₂ : Level) → Set _
Substitutive {A = A} _∼_ p = (P : A → Set p) → P Respects _∼_
@@ -114,15 +139,8 @@ Substitutive {A = A} _∼_ p = (P : A → Set p) → P Respects _∼_
Decidable : ∀ {a b ℓ} {A : Set a} {B : Set b} → REL A B ℓ → Set _
Decidable _∼_ = ∀ x y → Dec (x ∼ y)
-data Tri {a b c} (A : Set a) (B : Set b) (C : Set c) :
- Set (a ⊔ b ⊔ c) where
- tri< : ( a : A) (¬b : ¬ B) (¬c : ¬ C) → Tri A B C
- tri≈ : (¬a : ¬ A) ( b : B) (¬c : ¬ C) → Tri A B C
- tri> : (¬a : ¬ A) (¬b : ¬ B) ( c : C) → Tri A B C
-
-Trichotomous : ∀ {a ℓ₁ ℓ₂} {A : Set a} → Rel A ℓ₁ → Rel A ℓ₂ → Set _
-Trichotomous _≈_ _<_ = ∀ x y → Tri (x < y) (x ≈ y) (x > y)
- where _>_ = flip _<_
+Irrelevant : ∀ {a b ℓ} {A : Set a} {B : Set b} → REL A B ℓ → Set _
+Irrelevant _∼_ = ∀ {x y} (a : x ∼ y) (b : x ∼ y) → a ≡ b
record NonEmpty {a b ℓ} {A : Set a} {B : Set b}
(T : REL A B ℓ) : Set (a ⊔ b ⊔ ℓ) where
@@ -133,19 +151,6 @@ record NonEmpty {a b ℓ} {A : Set a} {B : Set b}
proof : T x y
------------------------------------------------------------------------
--- Propositional equality
-
--- This dummy module is used to avoid shadowing of the field named
--- refl defined in IsEquivalence below. The module is opened publicly
--- at the end of this file.
-
-import Agda.Builtin.Equality as Dummy
-
-infix 4 _≢_
-_≢_ : ∀ {a} {A : Set a} → A → A → Set a
-x ≢ y = ¬ x Dummy.≡ y
-
-------------------------------------------------------------------------
-- Equivalence relations
-- The preorders of this library are defined in terms of an underlying
@@ -159,7 +164,6 @@ record IsEquivalence {a ℓ} {A : Set a}
sym : Symmetric _≈_
trans : Transitive _≈_
- reflexive : Dummy._≡_ ⇒ _≈_
- reflexive Dummy.refl = refl
+ reflexive : _≡_ ⇒ _≈_
+ reflexive ≡-refl = refl
-open Dummy public
diff --git a/src/Relation/Binary/EqReasoning.agda b/src/Relation/Binary/EqReasoning.agda
index 394cb50..c498059 100644
--- a/src/Relation/Binary/EqReasoning.agda
+++ b/src/Relation/Binary/EqReasoning.agda
@@ -28,9 +28,10 @@ open import Relation.Binary
module Relation.Binary.EqReasoning {s₁ s₂} (S : Setoid s₁ s₂) where
open Setoid S
-import Relation.Binary.PreorderReasoning as PreR
-open PreR preorder public
- renaming ( _∼⟨_⟩_ to _≈⟨_⟩_
- ; _≈⟨_⟩_ to _≡⟨_⟩_
- ; _≈⟨⟩_ to _≡⟨⟩_
- )
+open import Relation.Binary.PreorderReasoning preorder public
+ hiding (_≈⟨_⟩_)
+ renaming
+ ( _∼⟨_⟩_ to _≈⟨_⟩_
+ ; _≈⟨⟩_ to _≡⟨⟩_
+ )
+
diff --git a/src/Relation/Binary/EquivalenceClosure.agda b/src/Relation/Binary/EquivalenceClosure.agda
index 8962238..d55cd15 100644
--- a/src/Relation/Binary/EquivalenceClosure.agda
+++ b/src/Relation/Binary/EquivalenceClosure.agda
@@ -2,56 +2,11 @@
-- The Agda standard library
--
-- Equivalence closures of binary relations
+--
+-- This module is DEPRECATED. Please use the
+-- Relation.Binary.Construct.Closure.Equivalence module directly.
------------------------------------------------------------------------
module Relation.Binary.EquivalenceClosure where
-open import Data.Star as Star using (Star; ε; _◅◅_; reverse)
-open import Function using (flip; id; _∘_)
-open import Level using (_⊔_)
-open import Relation.Binary
-open import Relation.Binary.SymmetricClosure as SC using (SymClosure)
-
--- The reflexive, transitive and symmetric closure of a binary
--- relation (aka the equivalence closure).
-
-EqClosure : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Rel A (a ⊔ ℓ)
-EqClosure _∼_ = Star (SymClosure _∼_)
-
-module _ {a ℓ} {A : Set a} where
-
- -- Equivalence closures are equivalences.
-
- reflexive : (_∼_ : Rel A ℓ) → Reflexive (EqClosure _∼_)
- reflexive _∼_ = ε
-
- transitive : (_∼_ : Rel A ℓ) → Transitive (EqClosure _∼_)
- transitive _∼_ = _◅◅_
-
- symmetric : (_∼_ : Rel A ℓ) → Symmetric (EqClosure _∼_)
- symmetric _∼_ = reverse (SC.symmetric _∼_)
-
- isEquivalence : (_∼_ : Rel A ℓ) → IsEquivalence (EqClosure _∼_)
- isEquivalence _∼_ = record
- { refl = reflexive _∼_
- ; sym = symmetric _∼_
- ; trans = transitive _∼_
- }
-
- -- The setoid associated with an equivalence closure.
-
- setoid : Rel A ℓ → Setoid a (a ⊔ ℓ)
- setoid _∼_ = record
- { _≈_ = EqClosure _∼_
- ; isEquivalence = isEquivalence _∼_
- }
-
- -- A generalised variant of map which allows the index type to change.
-
- gmap : ∀ {b ℓ₂} {B : Set b} {P : Rel A ℓ} {Q : Rel B ℓ₂} →
- (f : A → B) → P =[ f ]⇒ Q → EqClosure P =[ f ]⇒ EqClosure Q
- gmap {Q = Q} f = Star.gmap f ∘ SC.gmap {Q = Q} f
-
- map : ∀ {ℓ₂} {P : Rel A ℓ} {Q : Rel A ℓ₂} →
- P ⇒ Q → EqClosure P ⇒ EqClosure Q
- map = gmap id
+open import Relation.Binary.Construct.Closure.Equivalence public
diff --git a/src/Relation/Binary/Flip.agda b/src/Relation/Binary/Flip.agda
deleted file mode 100644
index 79644e5..0000000
--- a/src/Relation/Binary/Flip.agda
+++ /dev/null
@@ -1,196 +0,0 @@
-------------------------------------------------------------------------
--- The Agda standard library
---
--- Many properties which hold for _∼_ also hold for flip _∼_
-------------------------------------------------------------------------
-
-open import Relation.Binary
-
-module Relation.Binary.Flip where
-
-open import Function
-open import Data.Product
-
-implies : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b}
- (≈ : REL A B ℓ₁) (∼ : REL A B ℓ₂) →
- ≈ ⇒ ∼ → flip ≈ ⇒ flip ∼
-implies _ _ impl = impl
-
-reflexive : ∀ {a ℓ} {A : Set a} (∼ : Rel A ℓ) →
- Reflexive ∼ → Reflexive (flip ∼)
-reflexive _ refl = refl
-
-irreflexive : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b}
- (≈ : REL A B ℓ₁) (∼ : REL A B ℓ₂) →
- Irreflexive ≈ ∼ → Irreflexive (flip ≈) (flip ∼)
-irreflexive _ _ irrefl = irrefl
-
-symmetric : ∀ {a ℓ} {A : Set a} (∼ : Rel A ℓ) →
- Symmetric ∼ → Symmetric (flip ∼)
-symmetric _ sym = sym
-
-transitive : ∀ {a ℓ} {A : Set a} (∼ : Rel A ℓ) →
- Transitive ∼ → Transitive (flip ∼)
-transitive _ trans = flip trans
-
-antisymmetric : ∀ {a ℓ₁ ℓ₂} {A : Set a} (≈ : Rel A ℓ₁) (≤ : Rel A ℓ₂) →
- Antisymmetric ≈ ≤ → Antisymmetric (flip ≈) (flip ≤)
-antisymmetric _ _ antisym = antisym
-
-asymmetric : ∀ {a ℓ} {A : Set a} (< : Rel A ℓ) →
- Asymmetric < → Asymmetric (flip <)
-asymmetric _ asym = asym
-
-respects : ∀ {a ℓ p} {A : Set a} (∼ : Rel A ℓ) (P : A → Set p) →
- Symmetric ∼ → P Respects ∼ → P Respects flip ∼
-respects _ _ sym resp ∼ = resp (sym ∼)
-
-respects₂ : ∀ {a ℓ₁ ℓ₂} {A : Set a} (∼₁ : Rel A ℓ₁) (∼₂ : Rel A ℓ₂) →
- Symmetric ∼₂ → ∼₁ Respects₂ ∼₂ → flip ∼₁ Respects₂ flip ∼₂
-respects₂ _ _ sym (resp₁ , resp₂) =
- ((λ {_} {_} {_} ∼ → resp₂ (sym ∼)) , λ {_} {_} {_} ∼ → resp₁ (sym ∼))
-
-decidable : ∀ {a b ℓ} {A : Set a} {B : Set b} (∼ : REL A B ℓ) →
- Decidable ∼ → Decidable (flip ∼)
-decidable _ dec x y = dec y x
-
-total : ∀ {a ℓ} {A : Set a} (∼ : Rel A ℓ) →
- Total ∼ → Total (flip ∼)
-total _ tot x y = tot y x
-
-trichotomous : ∀ {a ℓ₁ ℓ₂} {A : Set a} (≈ : Rel A ℓ₁) (< : Rel A ℓ₂) →
- Trichotomous ≈ < → Trichotomous (flip ≈) (flip <)
-trichotomous _ _ compare x y = compare y x
-
-isEquivalence : ∀ {a ℓ} {A : Set a} {≈ : Rel A ℓ} →
- IsEquivalence ≈ → IsEquivalence (flip ≈)
-isEquivalence {≈ = ≈} eq = record
- { refl = reflexive ≈ Eq.refl
- ; sym = symmetric ≈ Eq.sym
- ; trans = transitive ≈ Eq.trans
- }
- where module Eq = IsEquivalence eq
-
-setoid : ∀ {s₁ s₂} → Setoid s₁ s₂ → Setoid s₁ s₂
-setoid S = record
- { _≈_ = flip S._≈_
- ; isEquivalence = isEquivalence S.isEquivalence
- } where module S = Setoid S
-
-isPreorder : ∀ {a ℓ₁ ℓ₂} {A : Set a} {≈ : Rel A ℓ₁} {∼ : Rel A ℓ₂} →
- IsPreorder ≈ ∼ → IsPreorder (flip ≈) (flip ∼)
-isPreorder {≈ = ≈} {∼} pre = record
- { isEquivalence = isEquivalence Pre.isEquivalence
- ; reflexive = implies ≈ ∼ Pre.reflexive
- ; trans = transitive ∼ Pre.trans
- }
- where module Pre = IsPreorder pre
-
-preorder : ∀ {p₁ p₂ p₃} → Preorder p₁ p₂ p₃ → Preorder p₁ p₂ p₃
-preorder P = record
- { _∼_ = flip P._∼_
- ; _≈_ = flip P._≈_
- ; isPreorder = isPreorder P.isPreorder
- } where module P = Preorder P
-
-isDecEquivalence : ∀ {a ℓ} {A : Set a} {≈ : Rel A ℓ} →
- IsDecEquivalence ≈ → IsDecEquivalence (flip ≈)
-isDecEquivalence {≈ = ≈} dec = record
- { isEquivalence = isEquivalence Dec.isEquivalence
- ; _≟_ = decidable ≈ Dec._≟_
- }
- where module Dec = IsDecEquivalence dec
-
-decSetoid : ∀ {s₁ s₂} → DecSetoid s₁ s₂ → DecSetoid s₁ s₂
-decSetoid S = record
- { _≈_ = flip S._≈_
- ; isDecEquivalence = isDecEquivalence S.isDecEquivalence
- } where module S = DecSetoid S
-
-isPartialOrder : ∀ {a ℓ₁ ℓ₂} {A : Set a} {≈ : Rel A ℓ₁} {≤ : Rel A ℓ₂} →
- IsPartialOrder ≈ ≤ →
- IsPartialOrder (flip ≈) (flip ≤)
-isPartialOrder {≈ = ≈} {≤} po = record
- { isPreorder = isPreorder Po.isPreorder
- ; antisym = antisymmetric ≈ ≤ Po.antisym
- }
- where module Po = IsPartialOrder po
-
-poset : ∀ {p₁ p₂ p₃} → Poset p₁ p₂ p₃ → Poset p₁ p₂ p₃
-poset O = record
- { _≈_ = flip O._≈_
- ; _≤_ = flip O._≤_
- ; isPartialOrder = isPartialOrder O.isPartialOrder
- } where module O = Poset O
-
-isStrictPartialOrder :
- ∀ {a ℓ₁ ℓ₂} {A : Set a} {≈ : Rel A ℓ₁} {< : Rel A ℓ₂} →
- IsStrictPartialOrder ≈ < → IsStrictPartialOrder (flip ≈) (flip <)
-isStrictPartialOrder {≈ = ≈} {<} spo = record
- { isEquivalence = isEquivalence Spo.isEquivalence
- ; irrefl = irreflexive ≈ < Spo.irrefl
- ; trans = transitive < Spo.trans
- ; <-resp-≈ = respects₂ < ≈ Spo.Eq.sym Spo.<-resp-≈
- }
- where module Spo = IsStrictPartialOrder spo
-
-strictPartialOrder :
- ∀ {s₁ s₂ s₃} →
- StrictPartialOrder s₁ s₂ s₃ → StrictPartialOrder s₁ s₂ s₃
-strictPartialOrder O = record
- { _≈_ = flip O._≈_
- ; _<_ = flip O._<_
- ; isStrictPartialOrder = isStrictPartialOrder O.isStrictPartialOrder
- } where module O = StrictPartialOrder O
-
-isTotalOrder :
- ∀ {a ℓ₁ ℓ₂} {A : Set a} {≈ : Rel A ℓ₁} {≤ : Rel A ℓ₂} →
- IsTotalOrder ≈ ≤ → IsTotalOrder (flip ≈) (flip ≤)
-isTotalOrder {≈ = ≈} {≤} to = record
- { isPartialOrder = isPartialOrder To.isPartialOrder
- ; total = total ≤ To.total
- }
- where module To = IsTotalOrder to
-
-totalOrder : ∀ {t₁ t₂ t₃} → TotalOrder t₁ t₂ t₃ → TotalOrder t₁ t₂ t₃
-totalOrder O = record
- { _≈_ = flip O._≈_
- ; _≤_ = flip O._≤_
- ; isTotalOrder = isTotalOrder O.isTotalOrder
- } where module O = TotalOrder O
-
-isDecTotalOrder :
- ∀ {a ℓ₁ ℓ₂} {A : Set a} {≈ : Rel A ℓ₁} {≤ : Rel A ℓ₂} →
- IsDecTotalOrder ≈ ≤ → IsDecTotalOrder (flip ≈) (flip ≤)
-isDecTotalOrder {≈ = ≈} {≤} dec = record
- { isTotalOrder = isTotalOrder Dec.isTotalOrder
- ; _≟_ = decidable ≈ Dec._≟_
- ; _≤?_ = decidable ≤ Dec._≤?_
- }
- where module Dec = IsDecTotalOrder dec
-
-decTotalOrder :
- ∀ {d₁ d₂ d₃} → DecTotalOrder d₁ d₂ d₃ → DecTotalOrder d₁ d₂ d₃
-decTotalOrder O = record
- { _≈_ = flip O._≈_
- ; _≤_ = flip O._≤_
- ; isDecTotalOrder = isDecTotalOrder O.isDecTotalOrder
- } where module O = DecTotalOrder O
-
-isStrictTotalOrder :
- ∀ {a ℓ₁ ℓ₂} {A : Set a} {≈ : Rel A ℓ₁} {< : Rel A ℓ₂} →
- IsStrictTotalOrder ≈ < → IsStrictTotalOrder (flip ≈) (flip <)
-isStrictTotalOrder {≈ = ≈} {<} sto = record
- { isEquivalence = isEquivalence Sto.isEquivalence
- ; trans = transitive < Sto.trans
- ; compare = trichotomous ≈ < Sto.compare
- }
- where module Sto = IsStrictTotalOrder sto
-
-strictTotalOrder :
- ∀ {s₁ s₂ s₃} → StrictTotalOrder s₁ s₂ s₃ → StrictTotalOrder s₁ s₂ s₃
-strictTotalOrder O = record
- { _≈_ = flip O._≈_
- ; _<_ = flip O._<_
- ; isStrictTotalOrder = isStrictTotalOrder O.isStrictTotalOrder
- } where module O = StrictTotalOrder O
diff --git a/src/Relation/Binary/HeterogeneousEquality.agda b/src/Relation/Binary/HeterogeneousEquality.agda
index 12ab465..de50fea 100644
--- a/src/Relation/Binary/HeterogeneousEquality.agda
+++ b/src/Relation/Binary/HeterogeneousEquality.agda
@@ -14,7 +14,10 @@ open import Level
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.Consequences
-open import Relation.Binary.Indexed as I using (_at_)
+open import Relation.Binary.Indexed.Heterogeneous
+ using (IndexedSetoid)
+open import Relation.Binary.Indexed.Heterogeneous.Construct.At
+ using (_atₛ_)
open import Relation.Binary.PropositionalEquality as P using (_≡_; refl)
import Relation.Binary.HeterogeneousEquality.Core as Core
@@ -93,9 +96,63 @@ cong₂ f refl refl = refl
resp₂ : ∀ {a ℓ} {A : Set a} (∼ : Rel A ℓ) → ∼ Respects₂ (λ x y → x ≅ y)
resp₂ _∼_ = subst⟶resp₂ _∼_ subst
-proof-irrelevance : ∀ {ℓ} {A B : Set ℓ} {x : A} {y : B}
- (p q : x ≅ y) → p ≡ q
-proof-irrelevance refl refl = refl
+icong : ∀ {a b ℓ} {I : Set ℓ}
+ (A : I → Set a) {B : {k : I} → A k → Set b}
+ {i j : I} {x : A i} {y : A j} →
+ i ≡ j →
+ (f : {k : I} → (z : A k) → B z) →
+ x ≅ y →
+ f x ≅ f y
+icong _ refl _ refl = refl
+
+icong₂ : ∀ {a b c ℓ} {I : Set ℓ}
+ (A : I → Set a)
+ {B : {k : I} → A k → Set b}
+ {C : {k : I} → (a : A k) → B a → Set c}
+ {i j : I} {x : A i} {y : A j} {u : B x} {v : B y} →
+ i ≡ j →
+ (f : {k : I} → (z : A k) → (w : B z) → C z w) →
+ x ≅ y → u ≅ v →
+ f x u ≅ f y v
+icong₂ _ refl _ refl refl = refl
+
+icong-subst-removable : ∀ {a b ℓ}
+ {I : Set ℓ}
+ (A : I → Set a) {B : {k : I} → A k → Set b}
+ {i j : I} (eq : i ≅ j)
+ (f : {k : I} → (z : A k) → B z)
+ (x : A i) →
+ f (subst A eq x) ≅ f x
+icong-subst-removable _ refl _ _ = refl
+
+icong-≡-subst-removable : ∀ {a b ℓ}
+ {I : Set ℓ}
+ (A : I → Set a) {B : {k : I} → A k → Set b}
+ {i j : I} (eq : i ≡ j)
+ (f : {k : I} → (z : A k) → B z)
+ (x : A i) →
+ f (P.subst A eq x) ≅ f x
+icong-≡-subst-removable _ refl _ _ = refl
+
+------------------------------------------------------------------------
+--Proof irrelevance
+
+≅-irrelevance : ∀ {ℓ} {A B : Set ℓ} → Irrelevant ((A → B → Set ℓ) ∋ λ a → a ≅_)
+≅-irrelevance refl refl = refl
+
+module _ {ℓ} {A₁ A₂ A₃ A₄ : Set ℓ} {a₁ : A₁} {a₂ : A₂} {a₃ : A₃} {a₄ : A₄} where
+
+ ≅-heterogeneous-irrelevance : (p : a₁ ≅ a₂) (q : a₃ ≅ a₄) → a₂ ≅ a₃ → p ≅ q
+ ≅-heterogeneous-irrelevance refl refl refl = refl
+
+ ≅-heterogeneous-irrelevanceˡ : (p : a₁ ≅ a₂) (q : a₃ ≅ a₄) → a₁ ≅ a₃ → p ≅ q
+ ≅-heterogeneous-irrelevanceˡ refl refl refl = refl
+
+ ≅-heterogeneous-irrelevanceʳ : (p : a₁ ≅ a₂) (q : a₃ ≅ a₄) → a₂ ≅ a₄ → p ≅ q
+ ≅-heterogeneous-irrelevanceʳ refl refl refl = refl
+
+------------------------------------------------------------------------
+-- Structures
isEquivalence : ∀ {a} {A : Set a} →
IsEquivalence {A = A} (λ x y → x ≅ y)
@@ -112,7 +169,7 @@ setoid A = record
; isEquivalence = isEquivalence
}
-indexedSetoid : ∀ {a b} {A : Set a} → (A → Set b) → I.Setoid A _ _
+indexedSetoid : ∀ {a b} {A : Set a} → (A → Set b) → IndexedSetoid A _ _
indexedSetoid B = record
{ Carrier = B
; _≈_ = λ x y → x ≅ y
@@ -124,7 +181,7 @@ indexedSetoid B = record
}
≡↔≅ : ∀ {a b} {A : Set a} (B : A → Set b) {x : A} →
- Inverse (P.setoid (B x)) (indexedSetoid B at x)
+ Inverse (P.setoid (B x)) ((indexedSetoid B) atₛ x)
≡↔≅ B = record
{ to = record { _⟨$⟩_ = id; cong = ≡-to-≅ }
; from = record { _⟨$⟩_ = id; cong = ≅-to-≡ }
@@ -227,37 +284,11 @@ Extensionality a b =
ext′ : P.Extensionality ℓ₁ ℓ₂
ext′ = P.extensionality-for-lower-levels ℓ₁ (suc ℓ₂) ext
-
------------------------------------------------------------------------
--- The old inspect on steroids
-
--- The old inspect on steroids idiom has been deprecated, and may be
--- removed in the future. Use simplified inspect on steroids instead.
-
-module Deprecated-inspect-on-steroids where
-
- -- Inspect on steroids can be used when you want to pattern match on
- -- the result r of some expression e, and you also need to "remember"
- -- that r ≡ e.
+-- Inspect
- data Reveal_is_ {a} {A : Set a} (x : Hidden A) (y : A) : Set a where
- [_] : (eq : reveal x ≡ y) → Reveal x is y
-
- inspect : ∀ {a b} {A : Set a} {B : A → Set b}
- (f : (x : A) → B x) (x : A) → Reveal (hide f x) is (f x)
- inspect f x = [ refl ]
-
- -- Example usage:
-
- -- f x y with g x | inspect g x
- -- f x y | c z | [ eq ] = ...
-
-------------------------------------------------------------------------
--- Simplified inspect on steroids
-
--- Simplified inspect on steroids can be used when you want to pattern
--- match on the result r of some expression e, and you also need to
--- "remember" that r ≡ e.
+-- Inspect can be used when you want to pattern match on the result r
+-- of some expression e, and you also need to "remember" that r ≡ e.
record Reveal_·_is_ {a b} {A : Set a} {B : A → Set b}
(f : (x : A) → B x) (x : A) (y : B x) :
@@ -273,3 +304,18 @@ inspect f x = [ refl ]
-- f x y with g x | inspect g x
-- f x y | c z | [ eq ] = ...
+
+
+------------------------------------------------------------------------
+-- DEPRECATED NAMES
+------------------------------------------------------------------------
+-- Please use the new names as continuing support for the old names is
+-- not guaranteed.
+
+-- Version 0.15
+
+proof-irrelevance = ≅-irrelevance
+{-# WARNING_ON_USAGE proof-irrelevance
+"Warning: proof-irrelevance was deprecated in v0.15.
+Please use ≅-irrelevance instead."
+#-}
diff --git a/src/Relation/Binary/HeterogeneousEquality/Core.agda b/src/Relation/Binary/HeterogeneousEquality/Core.agda
index 15c104e..a3be2aa 100644
--- a/src/Relation/Binary/HeterogeneousEquality/Core.agda
+++ b/src/Relation/Binary/HeterogeneousEquality/Core.agda
@@ -9,7 +9,7 @@
module Relation.Binary.HeterogeneousEquality.Core where
-open import Relation.Binary.Core using (_≡_; refl)
+open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl)
------------------------------------------------------------------------
-- Heterogeneous equality
diff --git a/src/Relation/Binary/HeterogeneousEquality/Quotients.agda b/src/Relation/Binary/HeterogeneousEquality/Quotients.agda
new file mode 100644
index 0000000..839a82f
--- /dev/null
+++ b/src/Relation/Binary/HeterogeneousEquality/Quotients.agda
@@ -0,0 +1,147 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Quotients for Heterogeneous equality
+------------------------------------------------------------------------
+
+module Relation.Binary.HeterogeneousEquality.Quotients where
+
+open import Function
+open import Level hiding (lift)
+open import Relation.Binary
+open import Relation.Binary.HeterogeneousEquality
+open ≅-Reasoning
+
+record Quotient {c ℓ} (S : Setoid c ℓ) : Set (suc (c ⊔ ℓ)) where
+ open Setoid S renaming (Carrier to A)
+ field
+ Q : Set c
+ abs : A → Q
+
+ compat : (B : Q → Set c) (f : ∀ a → B (abs a)) → Set (c ⊔ ℓ)
+ compat _ f = {a a′ : A} → a ≈ a′ → f a ≅ f a′
+
+ field
+ compat-abs : compat _ abs
+ lift : (B : Q → Set c) (f : ∀ a → B (abs a)) → compat B f → ∀ q → B q
+ lift-conv : {B : Q → Set c} (f : ∀ a → B (abs a)) (p : compat B f) →
+ ∀ a → lift B f p (abs a) ≅ f a
+
+Quotients : ∀ c ℓ → Set (suc (c ⊔ ℓ))
+Quotients c ℓ = (S : Setoid c ℓ) → Quotient S
+
+module Properties {c ℓ} {S : Setoid c ℓ} (Qu : Quotient S) where
+
+ open Setoid S renaming (Carrier to A) hiding (refl; sym; trans)
+ open Quotient Qu
+
+ module _ {B B′ : Q → Set c} {f : ∀ a → B (abs a)} {p : compat B f} where
+
+ lift-unique : {g : ∀ q → B′ q} → (∀ a → g (abs a) ≅ f a) →
+ ∀ x → lift B f p x ≅ g x
+ lift-unique {g} ext = lift _ liftf≅g liftf≅g-ext where
+
+ liftf≅g : ∀ a → lift B f p (abs a) ≅ g (abs a)
+ liftf≅g x = begin
+ lift _ f p (abs x) ≅⟨ lift-conv f p x ⟩
+ f x ≅⟨ sym (ext x) ⟩
+ g (abs x) ∎
+
+ liftf≅g-ext : ∀ {a a′} → a ≈ a′ → liftf≅g a ≅ liftf≅g a′
+ liftf≅g-ext eq = ≅-heterogeneous-irrelevanceˡ _ _
+ $ cong (lift B f p) (compat-abs eq)
+
+ lift-ext : {g : ∀ a → B′ (abs a)} {p′ : compat B′ g} → (∀ x → f x ≅ g x) →
+ ∀ x → lift B f p x ≅ lift B′ g p′ x
+ lift-ext {g} {p′} h = lift-unique $ λ a → begin
+ lift B′ g p′ (abs a) ≅⟨ lift-conv g p′ a ⟩
+ g a ≅⟨ sym (h a) ⟩
+ f a ∎
+
+ lift-conv-abs : ∀ a → lift (const Q) abs compat-abs a ≅ a
+ lift-conv-abs = lift-unique (λ _ → refl)
+
+ lift-fold : {B : Q → Set c} (f : ∀ q → B q) →
+ ∀ a → lift B (f ∘ abs) (cong f ∘ compat-abs) a ≅ f a
+ lift-fold f = lift-unique (λ _ → refl)
+
+ abs-epimorphism : {B : Q → Set c} {f g : ∀ q → B q} →
+ (∀ x → f (abs x) ≅ g (abs x)) → ∀ q → f q ≅ g q
+ abs-epimorphism {B} {f} {g} p q = begin
+ f q ≅⟨ sym (lift-fold f q) ⟩
+ lift B (f ∘ abs) (cong f ∘ compat-abs) q ≅⟨ lift-ext p q ⟩
+ lift B (g ∘ abs) (cong g ∘ compat-abs) q ≅⟨ lift-fold g q ⟩
+ g q ∎
+
+------------------------------------------------------------------------
+-- Properties provable with extensionality
+
+module _ (ext : ∀ {a b} {A : Set a} {B₁ B₂ : A → Set b} {f₁ : ∀ a → B₁ a}
+ {f₂ : ∀ a → B₂ a} → (∀ a → f₁ a ≅ f₂ a) → f₁ ≅ f₂) where
+
+ module Properties₂
+ {c ℓ} {S₁ S₂ : Setoid c ℓ} (Qu₁ : Quotient S₁) (Qu₂ : Quotient S₂)
+ where
+
+ module S₁ = Setoid S₁
+ module S₂ = Setoid S₂
+ module Qu₁ = Quotient Qu₁
+ module Qu₂ = Quotient Qu₂
+
+ module _ {B : _ → _ → Set c} (f : ∀ s₁ s₂ → B (Qu₁.abs s₁) (Qu₂.abs s₂)) where
+
+ compat₂ : Set _
+ compat₂ = ∀ {a b a′ b′} → a S₁.≈ a′ → b S₂.≈ b′ → f a b ≅ f a′ b′
+
+ lift₂ : compat₂ → ∀ q q′ → B q q′
+ lift₂ p = Qu₁.lift _ g (ext ∘ g-ext) module Lift₂ where
+
+ g : ∀ a q → B (Qu₁.abs a) q
+ g a = Qu₂.lift (B (Qu₁.abs a)) (f a) (p S₁.refl)
+
+ g-ext : ∀ {a a′} → a S₁.≈ a′ → ∀ q → g a q ≅ g a′ q
+ g-ext a≈a′ = Properties.lift-ext Qu₂ (λ _ → p a≈a′ S₂.refl)
+
+ lift₂-conv : (p : compat₂) → ∀ a a′ → lift₂ p (Qu₁.abs a) (Qu₂.abs a′) ≅ f a a′
+ lift₂-conv p a a′ = begin
+ lift₂ p (Qu₁.abs a) (Qu₂.abs a′)
+ ≅⟨ cong (_$ (Qu₂.abs a′)) (Qu₁.lift-conv (Lift₂.g p) (ext ∘ Lift₂.g-ext p) a) ⟩
+ Lift₂.g p a (Qu₂.abs a′)
+ ≡⟨⟩
+ Qu₂.lift (B (Qu₁.abs a)) (f a) (p S₁.refl) (Qu₂.abs a′)
+ ≅⟨ Qu₂.lift-conv (f a) (p S₁.refl) a′ ⟩
+ f a a′
+ ∎
+
+ module Properties₃ {c ℓ} {S₁ S₂ S₃ : Setoid c ℓ}
+ (Qu₁ : Quotient S₁) (Qu₂ : Quotient S₂) (Qu₃ : Quotient S₃)
+ where
+
+ module S₁ = Setoid S₁
+ module S₂ = Setoid S₂
+ module S₃ = Setoid S₃
+ module Qu₁ = Quotient Qu₁
+ module Qu₂ = Quotient Qu₂
+ module Qu₃ = Quotient Qu₃
+
+ module _ {B : _ → _ → _ → Set c}
+ (f : ∀ s₁ s₂ s₃ → B (Qu₁.abs s₁) (Qu₂.abs s₂) (Qu₃.abs s₃)) where
+
+ compat₃ : Set _
+ compat₃ = ∀ {a b c a′ b′ c′} → a S₁.≈ a′ → b S₂.≈ b′ → c S₃.≈ c′ →
+ f a b c ≅ f a′ b′ c′
+
+ lift₃ : compat₃ → ∀ q₁ q₂ q₃ → B q₁ q₂ q₃
+ lift₃ p = Qu₁.lift _ h (ext ∘ h-ext) module Lift₃ where
+
+ g : ∀ a b q → B (Qu₁.abs a) (Qu₂.abs b) q
+ g a b = Qu₃.lift (B (Qu₁.abs a) (Qu₂.abs b)) (f a b) (p S₁.refl S₂.refl)
+
+ g-ext : ∀ {a a′ b b′} → a S₁.≈ a′ → b S₂.≈ b′ → ∀ c → g a b c ≅ g a′ b′ c
+ g-ext a≈a′ b≈b′ = Properties.lift-ext Qu₃ (λ _ → p a≈a′ b≈b′ S₃.refl)
+
+ h : ∀ a q₂ q₃ → B (Qu₁.abs a) q₂ q₃
+ h a = Qu₂.lift (λ b → ∀ q → B (Qu₁.abs a) b q) (g a) (ext ∘ g-ext S₁.refl)
+
+ h-ext : ∀ {a a′} → a S₁.≈ a′ → ∀ b → h a b ≅ h a′ b
+ h-ext a≈a′ = Properties.lift-ext Qu₂ $ λ _ → ext (g-ext a≈a′ S₂.refl)
diff --git a/src/Relation/Binary/HeterogeneousEquality/Quotients/Examples.agda b/src/Relation/Binary/HeterogeneousEquality/Quotients/Examples.agda
new file mode 100644
index 0000000..2f141f1
--- /dev/null
+++ b/src/Relation/Binary/HeterogeneousEquality/Quotients/Examples.agda
@@ -0,0 +1,146 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Example of a Quotient: ℤ as (ℕ × ℕ / ~)
+------------------------------------------------------------------------
+
+module Relation.Binary.HeterogeneousEquality.Quotients.Examples where
+
+open import Relation.Binary.HeterogeneousEquality.Quotients
+open import Level as L hiding (lift)
+open import Relation.Binary
+open import Relation.Binary.HeterogeneousEquality hiding (isEquivalence)
+import Relation.Binary.PropositionalEquality as ≡
+open import Data.Nat
+open import Data.Nat.Properties
+open import Data.Product
+open import Function
+open ≅-Reasoning
+
+ℕ² = ℕ × ℕ
+
+_∼_ : ℕ² → ℕ² → Set
+(x , y) ∼ (x' , y') = x + y' ≅ x' + y
+
+infix 10 _∼_
+
+∼-trans : ∀ {i j k} → i ∼ j → j ∼ k → i ∼ k
+∼-trans {x₁ , y₁} {x₂ , y₂} {x₃ , y₃} p q =
+ ≡-to-≅ $ +-cancelˡ-≡ y₂ $ ≅-to-≡ $ begin
+ y₂ + (x₁ + y₃) ≡⟨ ≡.sym (+-assoc y₂ x₁ y₃) ⟩
+ y₂ + x₁ + y₃ ≡⟨ ≡.cong (_+ y₃) (+-comm y₂ x₁) ⟩
+ x₁ + y₂ + y₃ ≅⟨ cong (_+ y₃) p ⟩
+ x₂ + y₁ + y₃ ≡⟨ ≡.cong (_+ y₃) (+-comm x₂ y₁) ⟩
+ y₁ + x₂ + y₃ ≡⟨ +-assoc y₁ x₂ y₃ ⟩
+ y₁ + (x₂ + y₃) ≅⟨ cong (y₁ +_) q ⟩
+ y₁ + (x₃ + y₂) ≡⟨ +-comm y₁ (x₃ + y₂) ⟩
+ x₃ + y₂ + y₁ ≡⟨ ≡.cong (_+ y₁) (+-comm x₃ y₂) ⟩
+ y₂ + x₃ + y₁ ≡⟨ +-assoc y₂ x₃ y₁ ⟩
+ y₂ + (x₃ + y₁) ∎
+
+~-isEquivalence : IsEquivalence _∼_
+~-isEquivalence = record
+ { refl = refl
+ ; sym = sym
+ ; trans = λ {i} {j} {k} → ∼-trans {i} {j} {k}
+ }
+
+ℕ²-∼-setoid : Setoid L.zero L.zero
+ℕ²-∼-setoid = record { isEquivalence = ~-isEquivalence }
+
+module Integers (quot : Quotients L.zero L.zero) where
+
+ Int : Quotient ℕ²-∼-setoid
+ Int = quot _
+
+ open Quotient Int renaming (Q to ℤ)
+
+ _+²_ : ℕ² → ℕ² → ℕ²
+ (x₁ , y₁) +² (x₂ , y₂) = x₁ + x₂ , y₁ + y₂
+
+ +²-cong : ∀{a b a' b'} → a ∼ a' → b ∼ b' → a +² b ∼ a' +² b'
+ +²-cong {a₁ , b₁} {c₁ , d₁} {a₂ , b₂} {c₂ , d₂} ab~cd₁ ab~cd₂ = begin
+ (a₁ + c₁) + (b₂ + d₂) ≡⟨ ≡.cong (_+ (b₂ + d₂)) (+-comm a₁ c₁) ⟩
+ (c₁ + a₁) + (b₂ + d₂) ≡⟨ +-assoc c₁ a₁ (b₂ + d₂) ⟩
+ c₁ + (a₁ + (b₂ + d₂)) ≡⟨ ≡.cong (c₁ +_) (≡.sym (+-assoc a₁ b₂ d₂)) ⟩
+ c₁ + (a₁ + b₂ + d₂) ≅⟨ cong (λ n → c₁ + (n + d₂)) ab~cd₁ ⟩
+ c₁ + (a₂ + b₁ + d₂) ≡⟨ ≡.cong (c₁ +_) (+-assoc a₂ b₁ d₂) ⟩
+ c₁ + (a₂ + (b₁ + d₂)) ≡⟨ ≡.cong (λ n → c₁ + (a₂ + n)) (+-comm b₁ d₂) ⟩
+ c₁ + (a₂ + (d₂ + b₁)) ≡⟨ ≡.sym (+-assoc c₁ a₂ (d₂ + b₁)) ⟩
+ (c₁ + a₂) + (d₂ + b₁) ≡⟨ ≡.cong (_+ (d₂ + b₁)) (+-comm c₁ a₂) ⟩
+ (a₂ + c₁) + (d₂ + b₁) ≡⟨ +-assoc a₂ c₁ (d₂ + b₁) ⟩
+ a₂ + (c₁ + (d₂ + b₁)) ≡⟨ ≡.cong (a₂ +_) (≡.sym (+-assoc c₁ d₂ b₁)) ⟩
+ a₂ + (c₁ + d₂ + b₁) ≅⟨ cong (λ n → a₂ + (n + b₁)) ab~cd₂ ⟩
+ a₂ + (c₂ + d₁ + b₁) ≡⟨ ≡.cong (a₂ +_) (+-assoc c₂ d₁ b₁) ⟩
+ a₂ + (c₂ + (d₁ + b₁)) ≡⟨ ≡.cong (λ n → a₂ + (c₂ + n)) (+-comm d₁ b₁) ⟩
+ a₂ + (c₂ + (b₁ + d₁)) ≡⟨ ≡.sym (+-assoc a₂ c₂ (b₁ + d₁)) ⟩
+ (a₂ + c₂) + (b₁ + d₁) ∎
+
+ module _ (ext : ∀ {a b} {A : Set a} {B₁ B₂ : A → Set b} {f₁ : ∀ a → B₁ a}
+ {f₂ : ∀ a → B₂ a} → (∀ a → f₁ a ≅ f₂ a) → f₁ ≅ f₂) where
+
+ _+ℤ_ : ℤ → ℤ → ℤ
+ _+ℤ_ = Properties₂.lift₂ ext Int Int (λ i j → abs (i +² j))
+ $ λ {a} {b} {c} p p' → compat-abs (+²-cong {a} {b} {c} p p')
+
+ zero² : ℕ²
+ zero² = 0 , 0
+
+ zeroℤ : ℤ
+ zeroℤ = abs zero²
+
+ +²-identityʳ : (i : ℕ²) → (i +² zero²) ∼ i
+ +²-identityʳ (x , y) = begin
+ (x + 0) + y ≡⟨ ≡.cong (_+ y) (+-identityʳ x) ⟩
+ x + y ≡⟨ ≡.cong (x +_) (≡.sym (+-identityʳ y)) ⟩
+ x + (y + 0) ∎
+
+ +ℤ-on-abs≅abs-+₂ : ∀ a b → abs a +ℤ abs b ≅ abs (a +² b)
+ +ℤ-on-abs≅abs-+₂ = Properties₂.lift₂-conv ext Int Int _
+ $ λ {a} {b} {c} p p′ → compat-abs (+²-cong {a} {b} {c} p p′)
+
+ +ℤ-identityʳ : ∀ i → i +ℤ zeroℤ ≅ i
+ +ℤ-identityʳ = lift _ eq (≅-heterogeneous-irrelevanceʳ _ _ ∘ compat-abs) where
+
+ eq : ∀ a → abs a +ℤ zeroℤ ≅ abs a
+ eq a = begin
+ abs a +ℤ zeroℤ ≡⟨⟩
+ abs a +ℤ abs zero² ≅⟨ +ℤ-on-abs≅abs-+₂ a zero² ⟩
+ abs (a +² zero²) ≅⟨ compat-abs (+²-identityʳ a) ⟩
+ abs a ∎
+
+ +²-identityˡ : (i : ℕ²) → (zero² +² i) ∼ i
+ +²-identityˡ i = refl
+
+ +ℤ-identityˡ : (i : ℤ) → zeroℤ +ℤ i ≅ i
+ +ℤ-identityˡ = lift _ eq (≅-heterogeneous-irrelevanceʳ _ _ ∘ compat-abs) where
+
+ eq : ∀ a → zeroℤ +ℤ abs a ≅ abs a
+ eq a = begin
+ zeroℤ +ℤ abs a ≡⟨⟩
+ abs zero² +ℤ abs a ≅⟨ +ℤ-on-abs≅abs-+₂ zero² a ⟩
+ abs (zero² +² a) ≅⟨ compat-abs (+²-identityˡ a) ⟩
+ abs a ∎
+
+ +²-assoc : (i j k : ℕ²) → (i +² j) +² k ∼ i +² (j +² k)
+ +²-assoc (a , b) (c , d) (e , f) = begin
+ ((a + c) + e) + (b + (d + f)) ≡⟨ ≡.cong (_+ (b + (d + f))) (+-assoc a c e) ⟩
+ (a + (c + e)) + (b + (d + f)) ≡⟨ ≡.cong ((a + (c + e)) +_) (≡.sym (+-assoc b d f)) ⟩
+ (a + (c + e)) + ((b + d) + f) ∎
+
+ +ℤ-assoc : ∀ i j k → (i +ℤ j) +ℤ k ≅ i +ℤ (j +ℤ k)
+ +ℤ-assoc = Properties₃.lift₃ ext Int Int Int eq compat₃ where
+
+ eq : ∀ i j k → (abs i +ℤ abs j) +ℤ abs k ≅ abs i +ℤ (abs j +ℤ abs k)
+ eq i j k = begin
+ (abs i +ℤ abs j) +ℤ abs k ≅⟨ cong (_+ℤ abs k) (+ℤ-on-abs≅abs-+₂ i j) ⟩
+ (abs (i +² j) +ℤ abs k) ≅⟨ +ℤ-on-abs≅abs-+₂ (i +² j) k ⟩
+ abs ((i +² j) +² k) ≅⟨ compat-abs (+²-assoc i j k) ⟩
+ abs (i +² (j +² k)) ≅⟨ sym (+ℤ-on-abs≅abs-+₂ i (j +² k)) ⟩
+ (abs i +ℤ abs (j +² k)) ≅⟨ cong (abs i +ℤ_) (sym (+ℤ-on-abs≅abs-+₂ j k)) ⟩
+ abs i +ℤ (abs j +ℤ abs k) ∎
+
+ compat₃ : ∀ {a a′ b b′ c c′} → a ∼ a′ → b ∼ b′ → c ∼ c′ → eq a b c ≅ eq a′ b′ c′
+ compat₃ p q r = ≅-heterogeneous-irrelevanceˡ _ _
+ $ cong₂ _+ℤ_ (cong₂ _+ℤ_ (compat-abs p) (compat-abs q))
+ $ compat-abs r
diff --git a/src/Relation/Binary/Indexed.agda b/src/Relation/Binary/Indexed.agda
deleted file mode 100644
index 603fe97..0000000
--- a/src/Relation/Binary/Indexed.agda
+++ /dev/null
@@ -1,35 +0,0 @@
-------------------------------------------------------------------------
--- The Agda standard library
---
--- Indexed binary relations
-------------------------------------------------------------------------
-
-module Relation.Binary.Indexed where
-
-import Relation.Binary as B
-
-open import Relation.Binary.Indexed.Core public
-
--- By "instantiating" an indexed setoid one gets an ordinary setoid.
-
-_at_ : ∀ {i s₁ s₂} {I : Set i} → Setoid I s₁ s₂ → I → B.Setoid _ _
-S at i = record
- { Carrier = S.Carrier i
- ; _≈_ = S._≈_
- ; isEquivalence = record
- { refl = S.refl
- ; sym = S.sym
- ; trans = S.trans
- }
- } where module S = Setoid S
-
-------------------------------------------------------------------------
--- Simple properties of indexed binary relations
-
--- Generalised implication.
-
-infixr 4 _=[_]⇒_
-
-_=[_]⇒_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : A → Set b} →
- B.Rel A ℓ₁ → ((x : A) → B x) → Rel B ℓ₂ → Set _
-P =[ f ]⇒ Q = ∀ {i j} → P i j → Q (f i) (f j)
diff --git a/src/Relation/Binary/Indexed/Core.agda b/src/Relation/Binary/Indexed/Core.agda
deleted file mode 100644
index c6f1332..0000000
--- a/src/Relation/Binary/Indexed/Core.agda
+++ /dev/null
@@ -1,69 +0,0 @@
-------------------------------------------------------------------------
--- The Agda standard library
---
--- Indexed binary relations
-------------------------------------------------------------------------
-
--- This file contains some core definitions which are reexported by
--- Relation.Binary.Indexed.
-
-module Relation.Binary.Indexed.Core where
-
-open import Function
-open import Level
-import Relation.Binary.Core as B
-import Relation.Binary.Core as P
-
-------------------------------------------------------------------------
--- Indexed binary relations
-
--- Heterogeneous.
-
-REL : ∀ {i₁ i₂ a₁ a₂} {I₁ : Set i₁} {I₂ : Set i₂} →
- (I₁ → Set a₁) → (I₂ → Set a₂) → (ℓ : Level) → Set _
-REL A₁ A₂ ℓ = ∀ {i₁ i₂} → A₁ i₁ → A₂ i₂ → Set ℓ
-
--- Homogeneous.
-
-Rel : ∀ {i a} {I : Set i} → (I → Set a) → (ℓ : Level) → Set _
-Rel A ℓ = REL A A ℓ
-
-------------------------------------------------------------------------
--- Simple properties of indexed binary relations
-
--- Reflexivity.
-
-Reflexive : ∀ {i a ℓ} {I : Set i} (A : I → Set a) → Rel A ℓ → Set _
-Reflexive _ _∼_ = ∀ {i} → B.Reflexive (_∼_ {i})
-
--- Symmetry.
-
-Symmetric : ∀ {i a ℓ} {I : Set i} (A : I → Set a) → Rel A ℓ → Set _
-Symmetric _ _∼_ = ∀ {i j} → B.Sym (_∼_ {i} {j}) _∼_
-
--- Transitivity.
-
-Transitive : ∀ {i a ℓ} {I : Set i} (A : I → Set a) → Rel A ℓ → Set _
-Transitive _ _∼_ = ∀ {i j k} → B.Trans _∼_ (_∼_ {j}) (_∼_ {i} {k})
-
-------------------------------------------------------------------------
--- Setoids
-
-record IsEquivalence {i a ℓ} {I : Set i} (A : I → Set a)
- (_≈_ : Rel A ℓ) : Set (i ⊔ a ⊔ ℓ) where
- field
- refl : Reflexive A _≈_
- sym : Symmetric A _≈_
- trans : Transitive A _≈_
-
- reflexive : ∀ {i} → P._≡_ ⟨ B._⇒_ ⟩ _≈_ {i}
- reflexive P.refl = refl
-
-record Setoid {i} (I : Set i) c ℓ : Set (suc (i ⊔ c ⊔ ℓ)) where
- infix 4 _≈_
- field
- Carrier : I → Set c
- _≈_ : Rel Carrier ℓ
- isEquivalence : IsEquivalence Carrier _≈_
-
- open IsEquivalence isEquivalence public
diff --git a/src/Relation/Binary/Indexed/Heterogeneous.agda b/src/Relation/Binary/Indexed/Heterogeneous.agda
new file mode 100644
index 0000000..4e8d0cc
--- /dev/null
+++ b/src/Relation/Binary/Indexed/Heterogeneous.agda
@@ -0,0 +1,95 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Indexed binary relations
+------------------------------------------------------------------------
+
+module Relation.Binary.Indexed.Heterogeneous where
+
+open import Function
+open import Level using (suc; _⊔_)
+open import Relation.Binary using (_⇒_)
+open import Relation.Binary.PropositionalEquality.Core as P using (_≡_)
+
+------------------------------------------------------------------------
+-- Publically export core definitions
+
+open import Relation.Binary.Indexed.Heterogeneous.Core public
+
+------------------------------------------------------------------------
+-- Equivalences
+
+record IsIndexedEquivalence {i a ℓ} {I : Set i} (A : I → Set a)
+ (_≈_ : IRel A ℓ) : Set (i ⊔ a ⊔ ℓ) where
+ field
+ refl : Reflexive A _≈_
+ sym : Symmetric A _≈_
+ trans : Transitive A _≈_
+
+ reflexive : ∀ {i} → _≡_ ⟨ _⇒_ ⟩ _≈_ {i}
+ reflexive P.refl = refl
+
+record IndexedSetoid {i} (I : Set i) c ℓ : Set (suc (i ⊔ c ⊔ ℓ)) where
+ infix 4 _≈_
+ field
+ Carrier : I → Set c
+ _≈_ : IRel Carrier ℓ
+ isEquivalence : IsIndexedEquivalence Carrier _≈_
+
+ open IsIndexedEquivalence isEquivalence public
+
+------------------------------------------------------------------------
+-- Preorders
+
+record IsIndexedPreorder {i a ℓ₁ ℓ₂} {I : Set i} (A : I → Set a)
+ (_≈_ : IRel A ℓ₁) (_∼_ : IRel A ℓ₂) :
+ Set (i ⊔ a ⊔ ℓ₁ ⊔ ℓ₂) where
+ field
+ isEquivalence : IsIndexedEquivalence A _≈_
+ reflexive : ∀ {i j} → (_≈_ {i} {j}) ⟨ _⇒_ ⟩ _∼_
+ trans : Transitive A _∼_
+
+ module Eq = IsIndexedEquivalence isEquivalence
+
+ refl : Reflexive A _∼_
+ refl = reflexive Eq.refl
+
+record IndexedPreorder {i} (I : Set i) c ℓ₁ ℓ₂ :
+ Set (suc (i ⊔ c ⊔ ℓ₁ ⊔ ℓ₂)) where
+ infix 4 _≈_ _∼_
+ field
+ Carrier : I → Set c
+ _≈_ : IRel Carrier ℓ₁ -- The underlying equality.
+ _∼_ : IRel Carrier ℓ₂ -- The relation.
+ isPreorder : IsIndexedPreorder Carrier _≈_ _∼_
+
+ open IsIndexedPreorder isPreorder public
+
+------------------------------------------------------------------------
+-- DEPRECATED NAMES
+------------------------------------------------------------------------
+-- Please use the new names as continuing support for the old names is
+-- not guaranteed.
+
+-- Version 0.17
+
+REL = IREL
+{-# WARNING_ON_USAGE REL
+"Warning: REL was deprecated in v0.17.
+Please use IREL instead."
+#-}
+Rel = IRel
+{-# WARNING_ON_USAGE Rel
+"Warning: Rel was deprecated in v0.17.
+Please use IRel instead."
+#-}
+Setoid = IndexedSetoid
+{-# WARNING_ON_USAGE Setoid
+"Warning: Setoid was deprecated in v0.17.
+Please use IndexedSetoid instead."
+#-}
+IsEquivalence = IsIndexedEquivalence
+{-# WARNING_ON_USAGE IsEquivalence
+"Warning: IsEquivalence was deprecated in v0.17.
+Please use IsIndexedEquivalence instead."
+#-}
diff --git a/src/Relation/Binary/Indexed/Heterogeneous/Construct/At.agda b/src/Relation/Binary/Indexed/Heterogeneous/Construct/At.agda
new file mode 100644
index 0000000..dc71b48
--- /dev/null
+++ b/src/Relation/Binary/Indexed/Heterogeneous/Construct/At.agda
@@ -0,0 +1,66 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Instantiates indexed binary structures at an index to the equivalent
+-- non-indexed structures.
+------------------------------------------------------------------------
+
+module Relation.Binary.Indexed.Heterogeneous.Construct.At where
+
+open import Relation.Binary
+open import Relation.Binary.Indexed.Heterogeneous
+ hiding (IsEquivalence; Setoid)
+
+------------------------------------------------------------------------
+-- Structures
+
+module _ {a i} {I : Set i} {A : I → Set a} where
+
+ isEquivalence : ∀ {ℓ} {_≈_ : IRel A ℓ} → IsIndexedEquivalence A _≈_ →
+ (index : I) → IsEquivalence (_≈_ {index})
+ isEquivalence isEq index = record
+ { refl = refl
+ ; sym = sym
+ ; trans = trans
+ }
+ where open IsIndexedEquivalence isEq
+
+ isPreorder : ∀ {ℓ₁ ℓ₂} {_≈_ : IRel A ℓ₁} {_∼_ : IRel A ℓ₂} →
+ IsIndexedPreorder A _≈_ _∼_ →
+ (index : I) → IsPreorder (_≈_ {index}) _∼_
+ isPreorder isPreorder index = record
+ { isEquivalence = isEquivalence O.isEquivalence index
+ ; reflexive = O.reflexive
+ ; trans = O.trans
+ }
+ where module O = IsIndexedPreorder isPreorder
+
+------------------------------------------------------------------------
+-- Packages
+
+module _ {a i} {I : Set i} where
+
+ setoid : ∀ {ℓ} → IndexedSetoid I a ℓ → I → Setoid a ℓ
+ setoid S index = record
+ { Carrier = S.Carrier index
+ ; _≈_ = S._≈_
+ ; isEquivalence = isEquivalence S.isEquivalence index
+ }
+ where module S = IndexedSetoid S
+
+ preorder : ∀ {ℓ₁ ℓ₂} → IndexedPreorder I a ℓ₁ ℓ₂ → I → Preorder a ℓ₁ ℓ₂
+ preorder O index = record
+ { Carrier = O.Carrier index
+ ; _≈_ = O._≈_
+ ; _∼_ = O._∼_
+ ; isPreorder = isPreorder O.isPreorder index
+ }
+ where module O = IndexedPreorder O
+
+------------------------------------------------------------------------
+-- Some useful shorthand infix notation
+
+module _ {a i} {I : Set i} where
+
+ _atₛ_ : ∀ {ℓ} → IndexedSetoid I a ℓ → I → Setoid a ℓ
+ _atₛ_ = setoid
diff --git a/src/Relation/Binary/Indexed/Heterogeneous/Construct/Trivial.agda b/src/Relation/Binary/Indexed/Heterogeneous/Construct/Trivial.agda
new file mode 100644
index 0000000..947f28e
--- /dev/null
+++ b/src/Relation/Binary/Indexed/Heterogeneous/Construct/Trivial.agda
@@ -0,0 +1,56 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Creates trivially indexed records from their non-indexed counterpart.
+------------------------------------------------------------------------
+
+module Relation.Binary.Indexed.Heterogeneous.Construct.Trivial
+ {i} {I : Set i} where
+
+open import Relation.Binary
+open import Relation.Binary.Indexed.Heterogeneous hiding (Rel)
+ hiding (IsEquivalence; Setoid)
+
+------------------------------------------------------------------------
+-- Structures
+
+module _ {a} {A : Set a} where
+
+ private
+ Aᵢ : I → Set a
+ Aᵢ i = A
+
+ isIndexedEquivalence : ∀ {ℓ} {_≈_ : Rel A ℓ} → IsEquivalence _≈_ →
+ IsIndexedEquivalence Aᵢ _≈_
+ isIndexedEquivalence isEq = record
+ { refl = refl
+ ; sym = sym
+ ; trans = trans
+ }
+ where open IsEquivalence isEq
+
+ isIndexedPreorder : ∀ {ℓ₁ ℓ₂} {_≈_ : Rel A ℓ₁} {_∼_ : Rel A ℓ₂} →
+ IsPreorder _≈_ _∼_ →
+ IsIndexedPreorder Aᵢ _≈_ _∼_
+ isIndexedPreorder isPreorder = record
+ { isEquivalence = isIndexedEquivalence isEquivalence
+ ; reflexive = reflexive
+ ; trans = trans
+ }
+ where open IsPreorder isPreorder
+
+------------------------------------------------------------------------
+-- Packages
+
+indexedSetoid : ∀ {a ℓ} → Setoid a ℓ → IndexedSetoid I a ℓ
+indexedSetoid S = record
+ { isEquivalence = isIndexedEquivalence isEquivalence
+ }
+ where open Setoid S
+
+indexedPreorder : ∀ {a ℓ₁ ℓ₂} → Preorder a ℓ₁ ℓ₂ →
+ IndexedPreorder I a ℓ₁ ℓ₂
+indexedPreorder O = record
+ { isPreorder = isIndexedPreorder isPreorder
+ }
+ where open Preorder O
diff --git a/src/Relation/Binary/Indexed/Heterogeneous/Core.agda b/src/Relation/Binary/Indexed/Heterogeneous/Core.agda
new file mode 100644
index 0000000..92c1d42
--- /dev/null
+++ b/src/Relation/Binary/Indexed/Heterogeneous/Core.agda
@@ -0,0 +1,48 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Indexed binary relations
+------------------------------------------------------------------------
+
+-- This file contains some core definitions which are re-exported by
+-- Relation.Binary.Indexed.Heterogeneous.
+
+module Relation.Binary.Indexed.Heterogeneous.Core where
+
+open import Level
+import Relation.Binary.Core as B
+import Relation.Binary.PropositionalEquality.Core as P
+
+------------------------------------------------------------------------
+-- Indexed binary relations
+
+-- Heterogeneous types
+
+IREL : ∀ {i₁ i₂ a₁ a₂} {I₁ : Set i₁} {I₂ : Set i₂} →
+ (I₁ → Set a₁) → (I₂ → Set a₂) → (ℓ : Level) → Set _
+IREL A₁ A₂ ℓ = ∀ {i₁ i₂} → A₁ i₁ → A₂ i₂ → Set ℓ
+
+-- Homogeneous types
+
+IRel : ∀ {i a} {I : Set i} → (I → Set a) → (ℓ : Level) → Set _
+IRel A ℓ = IREL A A ℓ
+
+------------------------------------------------------------------------
+-- Simple properties of indexed binary relations
+
+Reflexive : ∀ {i a ℓ} {I : Set i} (A : I → Set a) → IRel A ℓ → Set _
+Reflexive _ _∼_ = ∀ {i} → B.Reflexive (_∼_ {i})
+
+Symmetric : ∀ {i a ℓ} {I : Set i} (A : I → Set a) → IRel A ℓ → Set _
+Symmetric _ _∼_ = ∀ {i j} → B.Sym (_∼_ {i} {j}) _∼_
+
+Transitive : ∀ {i a ℓ} {I : Set i} (A : I → Set a) → IRel A ℓ → Set _
+Transitive _ _∼_ = ∀ {i j k} → B.Trans _∼_ (_∼_ {j}) (_∼_ {i} {k})
+
+-- Generalised implication.
+
+infixr 4 _=[_]⇒_
+
+_=[_]⇒_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : A → Set b} →
+ B.Rel A ℓ₁ → ((x : A) → B x) → IRel B ℓ₂ → Set _
+P =[ f ]⇒ Q = ∀ {i j} → P i j → Q (f i) (f j)
diff --git a/src/Relation/Binary/Indexed/Homogeneous.agda b/src/Relation/Binary/Indexed/Homogeneous.agda
new file mode 100644
index 0000000..fc1c545
--- /dev/null
+++ b/src/Relation/Binary/Indexed/Homogeneous.agda
@@ -0,0 +1,253 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Homogeneously-indexed binary relations
+--
+-- Indexed structures are laid out in a similar manner as to those
+-- in Relation.Binary. The main difference is each structure also
+-- contains proofs for the lifted version of the relation.
+------------------------------------------------------------------------
+
+module Relation.Binary.Indexed.Homogeneous where
+
+open import Function using (_⟨_⟩_)
+open import Level using (Level; _⊔_; suc)
+open import Relation.Binary as B using (_⇒_)
+open import Relation.Binary.PropositionalEquality as P using (_≡_)
+open import Relation.Nullary using (¬_)
+open import Data.Product using (_,_)
+
+------------------------------------------------------------------------
+-- Publically export core definitions
+
+open import Relation.Binary.Indexed.Homogeneous.Core public
+
+------------------------------------------------------------------------
+-- Equivalences
+
+record IsIndexedEquivalence {i a ℓ} {I : Set i} (A : I → Set a)
+ (_≈ᵢ_ : IRel A ℓ) : Set (i ⊔ a ⊔ ℓ) where
+ field
+ reflᵢ : Reflexive A _≈ᵢ_
+ symᵢ : Symmetric A _≈ᵢ_
+ transᵢ : Transitive A _≈ᵢ_
+
+ reflexiveᵢ : ∀ {i} → _≡_ ⟨ _⇒_ ⟩ _≈ᵢ_ {i}
+ reflexiveᵢ P.refl = reflᵢ
+
+ -- Lift properties
+
+ reflexive : _≡_ ⇒ (Lift A _≈ᵢ_)
+ reflexive P.refl i = reflᵢ
+
+ refl : B.Reflexive (Lift A _≈ᵢ_)
+ refl i = reflᵢ
+
+ sym : B.Symmetric (Lift A _≈ᵢ_)
+ sym x≈y i = symᵢ (x≈y i)
+
+ trans : B.Transitive (Lift A _≈ᵢ_)
+ trans x≈y y≈z i = transᵢ (x≈y i) (y≈z i)
+
+ isEquivalence : B.IsEquivalence (Lift A _≈ᵢ_)
+ isEquivalence = record
+ { refl = refl
+ ; sym = sym
+ ; trans = trans
+ }
+
+record IndexedSetoid {i} (I : Set i) c ℓ : Set (suc (i ⊔ c ⊔ ℓ)) where
+ infix 4 _≈ᵢ_ _≈_
+ field
+ Carrierᵢ : I → Set c
+ _≈ᵢ_ : IRel Carrierᵢ ℓ
+ isEquivalenceᵢ : IsIndexedEquivalence Carrierᵢ _≈ᵢ_
+
+ open IsIndexedEquivalence isEquivalenceᵢ public
+
+ Carrier : Set _
+ Carrier = ∀ i → Carrierᵢ i
+
+ _≈_ : B.Rel Carrier _
+ _≈_ = Lift Carrierᵢ _≈ᵢ_
+
+ _≉_ : B.Rel Carrier _
+ x ≉ y = ¬ (x ≈ y)
+
+ setoid : B.Setoid _ _
+ setoid = record
+ { isEquivalence = isEquivalence
+ }
+
+------------------------------------------------------------------------
+-- Decidable equivalences
+
+record IsIndexedDecEquivalence {i a ℓ} {I : Set i} (A : I → Set a)
+ (_≈ᵢ_ : IRel A ℓ) : Set (i ⊔ a ⊔ ℓ) where
+ infix 4 _≟ᵢ_
+ field
+ _≟ᵢ_ : Decidable A _≈ᵢ_
+ isEquivalenceᵢ : IsIndexedEquivalence A _≈ᵢ_
+
+ open IsIndexedEquivalence isEquivalenceᵢ public
+
+record IndexedDecSetoid {i} (I : Set i) c ℓ : Set (suc (i ⊔ c ⊔ ℓ)) where
+ infix 4 _≈ᵢ_
+ field
+ Carrierᵢ : I → Set c
+ _≈ᵢ_ : IRel Carrierᵢ ℓ
+ isDecEquivalenceᵢ : IsIndexedDecEquivalence Carrierᵢ _≈ᵢ_
+
+ open IsIndexedDecEquivalence isDecEquivalenceᵢ public
+
+ indexedSetoid : IndexedSetoid I c ℓ
+ indexedSetoid = record { isEquivalenceᵢ = isEquivalenceᵢ }
+
+ open IndexedSetoid indexedSetoid public
+ using (Carrier; _≈_; _≉_; setoid)
+
+------------------------------------------------------------------------
+-- Preorders
+
+record IsIndexedPreorder {i a ℓ₁ ℓ₂} {I : Set i} (A : I → Set a)
+ (_≈ᵢ_ : IRel A ℓ₁) (_∼ᵢ_ : IRel A ℓ₂)
+ : Set (i ⊔ a ⊔ ℓ₁ ⊔ ℓ₂) where
+ field
+ isEquivalenceᵢ : IsIndexedEquivalence A _≈ᵢ_
+ reflexiveᵢ : _≈ᵢ_ ⇒[ A ] _∼ᵢ_
+ transᵢ : Transitive A _∼ᵢ_
+
+ module Eq = IsIndexedEquivalence isEquivalenceᵢ
+
+ reflᵢ : Reflexive A _∼ᵢ_
+ reflᵢ = reflexiveᵢ Eq.reflᵢ
+
+ ∼ᵢ-respˡ-≈ᵢ : Respectsˡ A _∼ᵢ_ _≈ᵢ_
+ ∼ᵢ-respˡ-≈ᵢ x≈y x∼z = transᵢ (reflexiveᵢ (Eq.symᵢ x≈y)) x∼z
+
+ ∼ᵢ-respʳ-≈ᵢ : Respectsʳ A _∼ᵢ_ _≈ᵢ_
+ ∼ᵢ-respʳ-≈ᵢ x≈y z∼x = transᵢ z∼x (reflexiveᵢ x≈y)
+
+ ∼ᵢ-resp-≈ᵢ : Respects₂ A _∼ᵢ_ _≈ᵢ_
+ ∼ᵢ-resp-≈ᵢ = ∼ᵢ-respʳ-≈ᵢ , ∼ᵢ-respˡ-≈ᵢ
+
+ -- Lifted properties
+
+ reflexive : Lift A _≈ᵢ_ B.⇒ Lift A _∼ᵢ_
+ reflexive x≈y i = reflexiveᵢ (x≈y i)
+
+ refl : B.Reflexive (Lift A _∼ᵢ_)
+ refl i = reflᵢ
+
+ trans : B.Transitive (Lift A _∼ᵢ_)
+ trans x≈y y≈z i = transᵢ (x≈y i) (y≈z i)
+
+ ∼-respˡ-≈ : (Lift A _∼ᵢ_) B.Respectsˡ (Lift A _≈ᵢ_)
+ ∼-respˡ-≈ x≈y x∼z i = ∼ᵢ-respˡ-≈ᵢ (x≈y i) (x∼z i)
+
+ ∼-respʳ-≈ : (Lift A _∼ᵢ_) B.Respectsʳ (Lift A _≈ᵢ_)
+ ∼-respʳ-≈ x≈y z∼x i = ∼ᵢ-respʳ-≈ᵢ (x≈y i) (z∼x i)
+
+ ∼-resp-≈ : (Lift A _∼ᵢ_) B.Respects₂ (Lift A _≈ᵢ_)
+ ∼-resp-≈ = ∼-respʳ-≈ , ∼-respˡ-≈
+
+ isPreorder : B.IsPreorder (Lift A _≈ᵢ_) (Lift A _∼ᵢ_)
+ isPreorder = record
+ { isEquivalence = Eq.isEquivalence
+ ; reflexive = reflexive
+ ; trans = trans
+ }
+
+record IndexedPreorder {i} (I : Set i) c ℓ₁ ℓ₂ :
+ Set (suc (i ⊔ c ⊔ ℓ₁ ⊔ ℓ₂)) where
+
+ infix 4 _≈ᵢ_ _∼ᵢ_ _≈_ _∼_
+
+ field
+ Carrierᵢ : I → Set c
+ _≈ᵢ_ : IRel Carrierᵢ ℓ₁
+ _∼ᵢ_ : IRel Carrierᵢ ℓ₂
+ isPreorderᵢ : IsIndexedPreorder Carrierᵢ _≈ᵢ_ _∼ᵢ_
+
+ open IsIndexedPreorder isPreorderᵢ public
+
+ Carrier : Set _
+ Carrier = ∀ i → Carrierᵢ i
+
+ _≈_ : B.Rel Carrier _
+ x ≈ y = ∀ i → x i ≈ᵢ y i
+
+ _∼_ : B.Rel Carrier _
+ x ∼ y = ∀ i → x i ∼ᵢ y i
+
+ preorder : B.Preorder _ _ _
+ preorder = record { isPreorder = isPreorder }
+
+------------------------------------------------------------------------
+-- Partial orders
+
+record IsIndexedPartialOrder {i a ℓ₁ ℓ₂} {I : Set i} (A : I → Set a)
+ (_≈ᵢ_ : IRel A ℓ₁) (_≤ᵢ_ : IRel A ℓ₂) :
+ Set (i ⊔ a ⊔ ℓ₁ ⊔ ℓ₂) where
+ field
+ isPreorderᵢ : IsIndexedPreorder A _≈ᵢ_ _≤ᵢ_
+ antisymᵢ : Antisymmetric A _≈ᵢ_ _≤ᵢ_
+
+ open IsIndexedPreorder isPreorderᵢ public
+ renaming
+ ( ∼ᵢ-respˡ-≈ᵢ to ≤ᵢ-respˡ-≈ᵢ
+ ; ∼ᵢ-respʳ-≈ᵢ to ≤ᵢ-respʳ-≈ᵢ
+ ; ∼ᵢ-resp-≈ᵢ to ≤ᵢ-resp-≈ᵢ
+ ; ∼-respˡ-≈ to ≤-respˡ-≈
+ ; ∼-respʳ-≈ to ≤-respʳ-≈
+ ; ∼-resp-≈ to ≤-resp-≈
+ )
+
+ antisym : B.Antisymmetric (Lift A _≈ᵢ_) (Lift A _≤ᵢ_)
+ antisym x≤y y≤x i = antisymᵢ (x≤y i) (y≤x i)
+
+ isPartialOrder : B.IsPartialOrder (Lift A _≈ᵢ_) (Lift A _≤ᵢ_)
+ isPartialOrder = record
+ { isPreorder = isPreorder
+ ; antisym = antisym
+ }
+
+record IndexedPoset {i} (I : Set i) c ℓ₁ ℓ₂ :
+ Set (suc (i ⊔ c ⊔ ℓ₁ ⊔ ℓ₂)) where
+ field
+ Carrierᵢ : I → Set c
+ _≈ᵢ_ : IRel Carrierᵢ ℓ₁
+ _≤ᵢ_ : IRel Carrierᵢ ℓ₂
+ isPartialOrderᵢ : IsIndexedPartialOrder Carrierᵢ _≈ᵢ_ _≤ᵢ_
+
+ open IsIndexedPartialOrder isPartialOrderᵢ public
+
+ preorderᵢ : IndexedPreorder I c ℓ₁ ℓ₂
+ preorderᵢ = record { isPreorderᵢ = isPreorderᵢ }
+
+ open IndexedPreorder preorderᵢ public
+ using (Carrier; _≈_; preorder)
+ renaming
+ (_∼_ to _≤_)
+
+ poset : B.Poset _ _ _
+ poset = record { isPartialOrder = isPartialOrder }
+
+------------------------------------------------------------------------
+-- DEPRECATED NAMES
+------------------------------------------------------------------------
+-- Please use the new names as continuing support for the old names is
+-- not guaranteed.
+
+-- Version 0.17
+
+REL = IREL
+{-# WARNING_ON_USAGE REL
+"Warning: REL was deprecated in v0.17.
+Please use IREL instead."
+#-}
+Rel = IRel
+{-# WARNING_ON_USAGE Rel
+"Warning: Rel was deprecated in v0.17.
+Please use IRel instead."
+#-}
diff --git a/src/Relation/Binary/Indexed/Homogeneous/Core.agda b/src/Relation/Binary/Indexed/Homogeneous/Core.agda
new file mode 100644
index 0000000..abb2609
--- /dev/null
+++ b/src/Relation/Binary/Indexed/Homogeneous/Core.agda
@@ -0,0 +1,88 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Homogeneously-indexed binary relations
+------------------------------------------------------------------------
+-- This file contains some core definitions which are reexported by
+-- Relation.Binary.Indexed.Homogeneous
+
+module Relation.Binary.Indexed.Homogeneous.Core where
+
+open import Level using (Level; _⊔_)
+open import Data.Product using (_×_)
+open import Relation.Binary as B using (REL; Rel)
+open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl)
+import Relation.Binary.Indexed.Heterogeneous as I
+open import Relation.Unary.Indexed using (IPred)
+
+------------------------------------------------------------------------
+-- Homegeneously indexed binary relations
+
+-- Heterogeneous types
+
+IREL : ∀ {i a b} {I : Set i} → (I → Set a) → (I → Set b) → (ℓ : Level) → Set _
+IREL A B ℓ = ∀ {i} → REL (A i) (B i) ℓ
+
+-- Homogeneous types
+
+IRel : ∀ {i a} {I : Set i} → (I → Set a) → (ℓ : Level) → Set _
+IRel A = IREL A A
+
+------------------------------------------------------------------------
+-- Simple properties
+
+module _ {i a} {I : Set i} (A : I → Set a) where
+
+ syntax Implies A _∼₁_ _∼₂_ = _∼₁_ ⇒[ A ] _∼₂_
+
+ Implies : ∀ {ℓ₁ ℓ₂} → IRel A ℓ₁ → IRel A ℓ₂ → Set _
+ Implies _∼₁_ _∼₂_ = ∀ {i} → _∼₁_ B.⇒ (_∼₂_ {i})
+
+ Reflexive : ∀ {ℓ} → IRel A ℓ → Set _
+ Reflexive _∼_ = ∀ {i} → B.Reflexive (_∼_ {i})
+
+ Symmetric : ∀ {ℓ} → IRel A ℓ → Set _
+ Symmetric _∼_ = ∀ {i} → B.Symmetric (_∼_ {i})
+
+ Transitive : ∀ {ℓ} → IRel A ℓ → Set _
+ Transitive _∼_ = ∀ {i} → B.Transitive (_∼_ {i})
+
+ Antisymmetric : ∀ {ℓ₁ ℓ₂} → IRel A ℓ₁ → IRel A ℓ₂ → Set _
+ Antisymmetric _≈_ _∼_ = ∀ {i} → B.Antisymmetric _≈_ (_∼_ {i})
+
+ Decidable : ∀ {ℓ} → IRel A ℓ → Set _
+ Decidable _∼_ = ∀ {i} → B.Decidable (_∼_ {i})
+
+ Respects : ∀ {ℓ₁ ℓ₂} → IPred A ℓ₁ → IRel A ℓ₂ → Set _
+ Respects P _∼_ = ∀ {i} {x y : A i} → x ∼ y → P x → P y
+
+ Respectsˡ : ∀ {ℓ₁ ℓ₂} → IRel A ℓ₁ → IRel A ℓ₂ → Set _
+ Respectsˡ P _∼_ = ∀ {i} {x y z : A i} → x ∼ y → P x z → P y z
+
+ Respectsʳ : ∀ {ℓ₁ ℓ₂} → IRel A ℓ₁ → IRel A ℓ₂ → Set _
+ Respectsʳ P _∼_ = ∀ {i} {x y z : A i} → x ∼ y → P z x → P z y
+
+ Respects₂ : ∀ {ℓ₁ ℓ₂} → IRel A ℓ₁ → IRel A ℓ₂ → Set _
+ Respects₂ P _∼_ = (Respectsʳ P _∼_) × (Respectsˡ P _∼_)
+
+------------------------------------------------------------------------
+-- Conversion between homogeneous and heterogeneously indexed relations
+
+module _ {i a b} {I : Set i} {A : I → Set a} {B : I → Set b} where
+
+ OverPath : ∀ {ℓ} → IREL A B ℓ → ∀ {i j} → i ≡ j → REL (A i) (B j) ℓ
+ OverPath _∼_ refl = _∼_
+
+ toHetIndexed : ∀ {ℓ} → IREL A B ℓ → I.IREL A B (i ⊔ ℓ)
+ toHetIndexed _∼_ {i} {j} x y = (p : i ≡ j) → OverPath _∼_ p x y
+
+ fromHetIndexed : ∀ {ℓ} → I.IREL A B ℓ → IREL A B ℓ
+ fromHetIndexed _∼_ = _∼_
+
+------------------------------------------------------------------------
+-- Lifting to non-indexed binary relations
+
+module _ {i a} {I : Set i} (A : I → Set a) where
+
+ Lift : ∀ {ℓ} → IRel A ℓ → Rel (∀ i → A i) _
+ Lift _∼_ x y = ∀ i → x i ∼ y i
diff --git a/src/Relation/Binary/InducedPreorders.agda b/src/Relation/Binary/InducedPreorders.agda
deleted file mode 100644
index 53d343b..0000000
--- a/src/Relation/Binary/InducedPreorders.agda
+++ /dev/null
@@ -1,48 +0,0 @@
-------------------------------------------------------------------------
--- The Agda standard library
---
--- Induced preorders
-------------------------------------------------------------------------
-
-open import Relation.Binary
-
-module Relation.Binary.InducedPreorders
- {s₁ s₂}
- (S : Setoid s₁ s₂) -- The underlying equality.
- where
-
-open import Function
-open import Data.Product
-
-open Setoid S
-
--- Every respectful unary relation induces a preorder. (No claim is
--- made that this preorder is unique.)
-
-InducedPreorder₁ : ∀ {p} (P : Carrier → Set p) →
- P Respects _≈_ → Preorder _ _ _
-InducedPreorder₁ P resp = record
- { _≈_ = _≈_
- ; _∼_ = λ c₁ c₂ → P c₁ → P c₂
- ; isPreorder = record
- { isEquivalence = isEquivalence
- ; reflexive = resp
- ; trans = flip _∘′_
- }
- }
-
--- Every respectful binary relation induces a preorder. (No claim is
--- made that this preorder is unique.)
-
-InducedPreorder₂ : ∀ {a r} {A : Set a} →
- (_R_ : A → Carrier → Set r) →
- (∀ {x} → _R_ x Respects _≈_) → Preorder _ _ _
-InducedPreorder₂ _R_ resp = record
- { _≈_ = _≈_
- ; _∼_ = λ c₁ c₂ → ∀ {a} → a R c₁ → a R c₂
- ; isPreorder = record
- { isEquivalence = isEquivalence
- ; reflexive = λ c₁≈c₂ → resp c₁≈c₂
- ; trans = λ c₁∼c₂ c₂∼c₃ → c₂∼c₃ ∘ c₁∼c₂
- }
- }
diff --git a/src/Relation/Binary/Lattice.agda b/src/Relation/Binary/Lattice.agda
index b38daab..caa0f09 100644
--- a/src/Relation/Binary/Lattice.agda
+++ b/src/Relation/Binary/Lattice.agda
@@ -7,14 +7,15 @@
module Relation.Binary.Lattice where
open import Algebra.FunctionProperties
-open import Data.Product
+open import Data.Product using (_×_; _,_)
open import Function using (flip)
-open import Level
+open import Level using (suc; _⊔_)
open import Relation.Binary
-import Relation.Binary.PropositionalEquality as PropEq
------------------------------------------------------------------------
--- Bounds and extrema
+-- Relationships between orders and operators
+
+open import Relation.Binary public using (Maximum; Minimum)
Supremum : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Op₂ A → Set _
Supremum _≤_ _∨_ =
@@ -23,15 +24,12 @@ Supremum _≤_ _∨_ =
Infimum : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Op₂ A → Set _
Infimum _≤_ = Supremum (flip _≤_)
-Maximum : ∀ {a ℓ} {A : Set a} → Rel A ℓ → A → Set _
-Maximum _≤_ ⊤ = ∀ x → x ≤ ⊤
-
-Minimum : ∀ {a ℓ} {A : Set a} → Rel A ℓ → A → Set _
-Minimum _≤_ = Maximum (flip _≤_)
-
+Exponential : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Op₂ A → Op₂ A → Set _
+Exponential _≤_ _∧_ _⇨_ =
+ ∀ w x y → ((w ∧ x) ≤ y → w ≤ (x ⇨ y)) × (w ≤ (x ⇨ y) → (w ∧ x) ≤ y)
------------------------------------------------------------------------
--- Semilattices
+-- Join semilattices
record IsJoinSemilattice {a ℓ₁ ℓ₂} {A : Set a}
(_≈_ : Rel A ℓ₁) -- The underlying equality.
@@ -42,6 +40,15 @@ record IsJoinSemilattice {a ℓ₁ ℓ₂} {A : Set a}
isPartialOrder : IsPartialOrder _≈_ _≤_
supremum : Supremum _≤_ _∨_
+ x≤x∨y : ∀ x y → x ≤ (x ∨ y)
+ x≤x∨y x y = let pf , _ , _ = supremum x y in pf
+
+ y≤x∨y : ∀ x y → y ≤ (x ∨ y)
+ y≤x∨y x y = let _ , pf , _ = supremum x y in pf
+
+ ∨-least : ∀ {x y z} → x ≤ z → y ≤ z → (x ∨ y) ≤ z
+ ∨-least {x} {y} {z} = let _ , _ , pf = supremum x y in pf z
+
open IsPartialOrder isPartialOrder public
record JoinSemilattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
@@ -61,6 +68,45 @@ record JoinSemilattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) whe
open Poset poset public using (preorder)
+record IsBoundedJoinSemilattice {a ℓ₁ ℓ₂} {A : Set a}
+ (_≈_ : Rel A ℓ₁) -- The underlying equality.
+ (_≤_ : Rel A ℓ₂) -- The partial order.
+ (_∨_ : Op₂ A) -- The join operation.
+ (⊥ : A) -- The minimum.
+ : Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
+ field
+ isJoinSemilattice : IsJoinSemilattice _≈_ _≤_ _∨_
+ minimum : Minimum _≤_ ⊥
+
+ open IsJoinSemilattice isJoinSemilattice public
+
+record BoundedJoinSemilattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
+ infix 4 _≈_ _≤_
+ infixr 6 _∨_
+ field
+ Carrier : Set c
+ _≈_ : Rel Carrier ℓ₁ -- The underlying equality.
+ _≤_ : Rel Carrier ℓ₂ -- The partial order.
+ _∨_ : Op₂ Carrier -- The join operation.
+ ⊥ : Carrier -- The minimum.
+ isBoundedJoinSemilattice : IsBoundedJoinSemilattice _≈_ _≤_ _∨_ ⊥
+
+ open IsBoundedJoinSemilattice isBoundedJoinSemilattice public
+
+ joinSemilattice : JoinSemilattice c ℓ₁ ℓ₂
+ joinSemilattice = record { isJoinSemilattice = isJoinSemilattice }
+
+ joinSemiLattice = joinSemilattice
+ {-# WARNING_ON_USAGE joinSemiLattice
+ "Warning: joinSemiLattice was deprecated in v0.17.
+ Please use joinSemilattice instead."
+ #-}
+
+ open JoinSemilattice joinSemilattice public using (preorder; poset)
+
+------------------------------------------------------------------------
+-- Meet semilattices
+
record IsMeetSemilattice {a ℓ₁ ℓ₂} {A : Set a}
(_≈_ : Rel A ℓ₁) -- The underlying equality.
(_≤_ : Rel A ℓ₂) -- The partial order.
@@ -70,6 +116,15 @@ record IsMeetSemilattice {a ℓ₁ ℓ₂} {A : Set a}
isPartialOrder : IsPartialOrder _≈_ _≤_
infimum : Infimum _≤_ _∧_
+ x∧y≤x : ∀ x y → (x ∧ y) ≤ x
+ x∧y≤x x y = let pf , _ , _ = infimum x y in pf
+
+ x∧y≤y : ∀ x y → (x ∧ y) ≤ y
+ x∧y≤y x y = let _ , pf , _ = infimum x y in pf
+
+ ∧-greatest : ∀ {x y z} → x ≤ y → x ≤ z → x ≤ (y ∧ z)
+ ∧-greatest {x} {y} {z} = let _ , _ , pf = infimum y z in pf x
+
open IsPartialOrder isPartialOrder public
record MeetSemilattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
@@ -89,36 +144,6 @@ record MeetSemilattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) whe
open Poset poset public using (preorder)
-record IsBoundedJoinSemilattice {a ℓ₁ ℓ₂} {A : Set a}
- (_≈_ : Rel A ℓ₁) -- The underlying equality.
- (_≤_ : Rel A ℓ₂) -- The partial order.
- (_∨_ : Op₂ A) -- The join operation.
- (⊥ : A) -- The minimum.
- : Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
- field
- isJoinSemilattice : IsJoinSemilattice _≈_ _≤_ _∨_
- minimum : Minimum _≤_ ⊥
-
- open IsJoinSemilattice isJoinSemilattice public
-
-record BoundedJoinSemilattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
- infix 4 _≈_ _≤_
- infixr 6 _∨_
- field
- Carrier : Set c
- _≈_ : Rel Carrier ℓ₁ -- The underlying equality.
- _≤_ : Rel Carrier ℓ₂ -- The partial order.
- _∨_ : Op₂ Carrier -- The join operation.
- ⊥ : Carrier -- The minimum.
- isBoundedJoinSemilattice : IsBoundedJoinSemilattice _≈_ _≤_ _∨_ ⊥
-
- open IsBoundedJoinSemilattice isBoundedJoinSemilattice public
-
- joinSemiLattice : JoinSemilattice c ℓ₁ ℓ₂
- joinSemiLattice = record { isJoinSemilattice = isJoinSemilattice }
-
- open JoinSemilattice joinSemiLattice public using (preorder; poset)
-
record IsBoundedMeetSemilattice {a ℓ₁ ℓ₂} {A : Set a}
(_≈_ : Rel A ℓ₁) -- The underlying equality.
(_≤_ : Rel A ℓ₂) -- The partial order.
@@ -144,10 +169,16 @@ record BoundedMeetSemilattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ
open IsBoundedMeetSemilattice isBoundedMeetSemilattice public
- meetSemiLattice : MeetSemilattice c ℓ₁ ℓ₂
- meetSemiLattice = record { isMeetSemilattice = isMeetSemilattice }
+ meetSemilattice : MeetSemilattice c ℓ₁ ℓ₂
+ meetSemilattice = record { isMeetSemilattice = isMeetSemilattice }
+
+ meetSemiLattice = meetSemilattice
+ {-# WARNING_ON_USAGE meetSemiLattice
+ "Warning: meetSemiLattice was deprecated in v0.17.
+ Please use meetSemilattice instead."
+ #-}
- open MeetSemilattice meetSemiLattice public using (preorder; poset)
+ open MeetSemilattice meetSemilattice public using (preorder; poset)
------------------------------------------------------------------------
-- Lattices
@@ -175,6 +206,10 @@ record IsLattice {a ℓ₁ ℓ₂} {A : Set a}
; infimum = infimum
}
+ open IsJoinSemilattice isJoinSemilattice public
+ using (x≤x∨y; y≤x∨y; ∨-least)
+ open IsMeetSemilattice isMeetSemilattice public
+ using (x∧y≤x; x∧y≤y; ∧-greatest)
open IsPartialOrder isPartialOrder public
record Lattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
@@ -199,6 +234,38 @@ record Lattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
open JoinSemilattice joinSemilattice public using (poset; preorder)
+record IsDistributiveLattice {a ℓ₁ ℓ₂} {A : Set a}
+ (_≈_ : Rel A ℓ₁) -- The underlying equality.
+ (_≤_ : Rel A ℓ₂) -- The partial order.
+ (_∨_ : Op₂ A) -- The join operation.
+ (_∧_ : Op₂ A) -- The meet operation.
+ : Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
+ field
+ isLattice : IsLattice _≈_ _≤_ _∨_ _∧_
+ ∧-distribˡ-∨ : _DistributesOverˡ_ _≈_ _∧_ _∨_
+
+ open IsLattice isLattice public
+
+record DistributiveLattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
+ infix 4 _≈_ _≤_
+ infixr 6 _∨_
+ infixr 7 _∧_
+ field
+ Carrier : Set c
+ _≈_ : Rel Carrier ℓ₁ -- The underlying equality.
+ _≤_ : Rel Carrier ℓ₂ -- The partial order.
+ _∨_ : Op₂ Carrier -- The join operation.
+ _∧_ : Op₂ Carrier -- The meet operation.
+ isDistributiveLattice : IsDistributiveLattice _≈_ _≤_ _∨_ _∧_
+
+ open IsDistributiveLattice isDistributiveLattice using (∧-distribˡ-∨) public
+ open IsDistributiveLattice isDistributiveLattice using (isLattice)
+
+ lattice : Lattice c ℓ₁ ℓ₂
+ lattice = record { isLattice = isLattice }
+
+ open Lattice lattice hiding (Carrier; _≈_; _≤_; _∨_; _∧_) public
+
record IsBoundedLattice {a ℓ₁ ℓ₂} {A : Set a}
(_≈_ : Rel A ℓ₁) -- The underlying equality.
(_≤_ : Rel A ℓ₂) -- The partial order.
@@ -249,3 +316,102 @@ record BoundedLattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) wher
boundedMeetSemilattice : BoundedMeetSemilattice c ℓ₁ ℓ₂
boundedMeetSemilattice = record
{ isBoundedMeetSemilattice = isBoundedMeetSemilattice }
+
+ lattice : Lattice c ℓ₁ ℓ₂
+ lattice = record { isLattice = isLattice }
+
+ open Lattice lattice public
+ using (joinSemilattice; meetSemilattice; poset; preorder)
+
+------------------------------------------------------------------------
+-- Heyting algebras (a bounded lattice with exponential operator)
+
+record IsHeytingAlgebra {a ℓ₁ ℓ₂} {A : Set a}
+ (_≈_ : Rel A ℓ₁) -- The underlying equality.
+ (_≤_ : Rel A ℓ₂) -- The partial order.
+ (_∨_ : Op₂ A) -- The join operation.
+ (_∧_ : Op₂ A) -- The meet operation.
+ (_⇨_ : Op₂ A) -- The exponential operation.
+ (⊤ : A) -- The maximum.
+ (⊥ : A) -- The minimum.
+ : Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
+ field
+ isBoundedLattice : IsBoundedLattice _≈_ _≤_ _∨_ _∧_ ⊤ ⊥
+ exponential : Exponential _≤_ _∧_ _⇨_
+
+ transpose-⇨ : ∀ {w x y} → (w ∧ x) ≤ y → w ≤ (x ⇨ y)
+ transpose-⇨ {w} {x} {y} = let pf , _ = exponential w x y in pf
+
+ transpose-∧ : ∀ {w x y} → w ≤ (x ⇨ y) → (w ∧ x) ≤ y
+ transpose-∧ {w} {x} {y} = let _ , pf = exponential w x y in pf
+
+ open IsBoundedLattice isBoundedLattice public
+
+record HeytingAlgebra c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
+ infix 4 _≈_ _≤_
+ infixr 5 _⇨_
+ infixr 6 _∨_
+ infixr 7 _∧_
+ field
+ Carrier : Set c
+ _≈_ : Rel Carrier ℓ₁ -- The underlying equality.
+ _≤_ : Rel Carrier ℓ₂ -- The partial order.
+ _∨_ : Op₂ Carrier -- The join operation.
+ _∧_ : Op₂ Carrier -- The meet operation.
+ _⇨_ : Op₂ Carrier -- The exponential operation.
+ ⊤ : Carrier -- The maximum.
+ ⊥ : Carrier -- The minimum.
+ isHeytingAlgebra : IsHeytingAlgebra _≈_ _≤_ _∨_ _∧_ _⇨_ ⊤ ⊥
+
+ boundedLattice : BoundedLattice c ℓ₁ ℓ₂
+ boundedLattice = record
+ { isBoundedLattice = IsHeytingAlgebra.isBoundedLattice isHeytingAlgebra }
+
+ open IsHeytingAlgebra isHeytingAlgebra
+ using (exponential; transpose-⇨; transpose-∧) public
+ open BoundedLattice boundedLattice
+ hiding (Carrier; _≈_; _≤_; _∨_; _∧_; ⊤; ⊥) public
+
+------------------------------------------------------------------------
+-- Boolean algebras (a specialized Heyting algebra)
+
+record IsBooleanAlgebra {a ℓ₁ ℓ₂} {A : Set a}
+ (_≈_ : Rel A ℓ₁) -- The underlying equality.
+ (_≤_ : Rel A ℓ₂) -- The partial order.
+ (_∨_ : Op₂ A) -- The join operation.
+ (_∧_ : Op₂ A) -- The meet operation.
+ (¬_ : Op₁ A) -- The negation operation.
+ (⊤ : A) -- The maximum.
+ (⊥ : A) -- The minimum.
+ : Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
+ _⇨_ : Op₂ A
+ x ⇨ y = (¬ x) ∨ y
+
+ field
+ isHeytingAlgebra : IsHeytingAlgebra _≈_ _≤_ _∨_ _∧_ _⇨_ ⊤ ⊥
+
+ open IsHeytingAlgebra isHeytingAlgebra public
+
+record BooleanAlgebra c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
+ infix 4 _≈_ _≤_
+ infixr 6 _∨_
+ infixr 7 _∧_
+ infix 8 ¬_
+ field
+ Carrier : Set c
+ _≈_ : Rel Carrier ℓ₁ -- The underlying equality.
+ _≤_ : Rel Carrier ℓ₂ -- The partial order.
+ _∨_ : Op₂ Carrier -- The join operation.
+ _∧_ : Op₂ Carrier -- The meet operation.
+ ¬_ : Op₁ Carrier -- The negation operation.
+ ⊤ : Carrier -- The maximum.
+ ⊥ : Carrier -- The minimum.
+ isBooleanAlgebra : IsBooleanAlgebra _≈_ _≤_ _∨_ _∧_ ¬_ ⊤ ⊥
+
+ open IsBooleanAlgebra isBooleanAlgebra using (isHeytingAlgebra)
+
+ heytingAlgebra : HeytingAlgebra c ℓ₁ ℓ₂
+ heytingAlgebra = record { isHeytingAlgebra = isHeytingAlgebra }
+
+ open HeytingAlgebra heytingAlgebra public
+ hiding (Carrier; _≈_; _≤_; _∨_; _∧_; ⊤; ⊥)
diff --git a/src/Relation/Binary/List/NonStrictLex.agda b/src/Relation/Binary/List/NonStrictLex.agda
index 013cda5..cb427db 100644
--- a/src/Relation/Binary/List/NonStrictLex.agda
+++ b/src/Relation/Binary/List/NonStrictLex.agda
@@ -2,6 +2,9 @@
-- The Agda standard library
--
-- Lexicographic ordering of lists
+--
+-- This module is DEPRECATED. Please use
+-- Data.List.Relation.Lex.NonStrict directly.
------------------------------------------------------------------------
-- The definition of lexicographic ordering used here is suitable if
@@ -11,174 +14,6 @@
module Relation.Binary.List.NonStrictLex where
-open import Data.Empty
-open import Function
-open import Data.Unit.Base using (⊤; tt)
-open import Data.Product
-open import Data.List.Base
-open import Level
-open import Relation.Nullary
-open import Relation.Binary
-
-import Relation.Binary.NonStrictToStrict as Conv
-import Relation.Binary.List.StrictLex as Strict
-
-open import Relation.Binary.List.Pointwise as Pointwise using ([])
-
-module _ {A : Set} where
-
- Lex : (P : Set) → (_≈_ _≤_ : Rel A zero) → Rel (List A) zero
- Lex P _≈_ _≤_ = Strict.Lex P _≈_ (Conv._<_ _≈_ _≤_)
-
- -- Strict lexicographic ordering.
-
- Lex-< : (_≈_ _≤_ : Rel A zero) → Rel (List A) zero
- Lex-< = Lex ⊥
-
- -- Non-strict lexicographic ordering.
-
- Lex-≤ : (_≈_ _≤_ : Rel A zero) → Rel (List A) zero
- Lex-≤ = Lex ⊤
-
- ------------------------------------------------------------------------
- -- Properties
-
- ≤-reflexive : ∀ _≈_ _≤_ → Pointwise.Rel _≈_ ⇒ Lex-≤ _≈_ _≤_
- ≤-reflexive _≈_ _≤_ = Strict.≤-reflexive _≈_ (Conv._<_ _≈_ _≤_)
-
- <-irreflexive : ∀ {_≈_ _≤_} →
- Irreflexive (Pointwise.Rel _≈_) (Lex-< _≈_ _≤_)
- <-irreflexive {_≈_} {_≤_} =
- Strict.<-irreflexive {_<_ = Conv._<_ _≈_ _≤_} (Conv.irrefl _≈_ _≤_)
-
- transitive : ∀ {P _≈_ _≤_} →
- IsPartialOrder _≈_ _≤_ → Transitive (Lex P _≈_ _≤_)
- transitive po =
- Strict.transitive
- isEquivalence
- (Conv.<-resp-≈ _ _ isEquivalence ≤-resp-≈)
- (Conv.trans _ _ po)
- where open IsPartialOrder po
-
- antisymmetric : ∀ {P _≈_ _≤_} →
- Symmetric _≈_ → Antisymmetric _≈_ _≤_ →
- Antisymmetric (Pointwise.Rel _≈_) (Lex P _≈_ _≤_)
- antisymmetric {_≈_ = _≈_} {_≤_} sym antisym =
- Strict.antisymmetric sym (Conv.irrefl _≈_ _≤_)
- (Conv.antisym⟶asym _≈_ _ antisym)
-
- <-asymmetric : ∀ {_≈_ _≤_} →
- IsEquivalence _≈_ → _≤_ Respects₂ _≈_ →
- Antisymmetric _≈_ _≤_ → Asymmetric (Lex-< _≈_ _≤_)
- <-asymmetric {_≈_} eq resp antisym =
- Strict.<-asymmetric sym (Conv.<-resp-≈ _ _ eq resp)
- (Conv.antisym⟶asym _≈_ _ antisym)
- where open IsEquivalence eq
-
- respects₂ : ∀ {P _≈_ _≤_} →
- IsEquivalence _≈_ → _≤_ Respects₂ _≈_ →
- Lex P _≈_ _≤_ Respects₂ Pointwise.Rel _≈_
- respects₂ eq resp = Strict.respects₂ eq (Conv.<-resp-≈ _ _ eq resp)
-
- decidable : ∀ {P _≈_ _≤_} →
- Dec P → Decidable _≈_ → Decidable _≤_ →
- Decidable (Lex P _≈_ _≤_)
- decidable dec-P dec-≈ dec-≤ =
- Strict.decidable dec-P dec-≈ (Conv.decidable _ _ dec-≈ dec-≤)
-
- <-decidable :
- ∀ {_≈_ _≤_} →
- Decidable _≈_ → Decidable _≤_ → Decidable (Lex-< _≈_ _≤_)
- <-decidable = decidable (no id)
-
- ≤-decidable :
- ∀ {_≈_ _≤_} →
- Decidable _≈_ → Decidable _≤_ → Decidable (Lex-≤ _≈_ _≤_)
- ≤-decidable = decidable (yes tt)
-
- ≤-total : ∀ {_≈_ _≤_} → Symmetric _≈_ → Decidable _≈_ →
- Antisymmetric _≈_ _≤_ → Total _≤_ →
- Total (Lex-≤ _≈_ _≤_)
- ≤-total sym dec-≈ antisym tot =
- Strict.≤-total sym (Conv.trichotomous _ _ sym dec-≈ antisym tot)
-
- <-compare : ∀ {_≈_ _≤_} → Symmetric _≈_ → Decidable _≈_ →
- Antisymmetric _≈_ _≤_ → Total _≤_ →
- Trichotomous (Pointwise.Rel _≈_) (Lex-< _≈_ _≤_)
- <-compare sym dec-≈ antisym tot =
- Strict.<-compare sym (Conv.trichotomous _ _ sym dec-≈ antisym tot)
-
- -- Some collections of properties which are preserved by Lex-≤ or
- -- Lex-<.
-
- ≤-isPreorder : ∀ {_≈_ _≤_} →
- IsPartialOrder _≈_ _≤_ →
- IsPreorder (Pointwise.Rel _≈_) (Lex-≤ _≈_ _≤_)
- ≤-isPreorder po =
- Strict.≤-isPreorder
- isEquivalence (Conv.trans _ _ po)
- (Conv.<-resp-≈ _ _ isEquivalence ≤-resp-≈)
- where open IsPartialOrder po
-
- ≤-isPartialOrder : ∀ {_≈_ _≤_} →
- IsPartialOrder _≈_ _≤_ →
- IsPartialOrder (Pointwise.Rel _≈_) (Lex-≤ _≈_ _≤_)
- ≤-isPartialOrder po =
- Strict.≤-isPartialOrder
- (Conv.isPartialOrder⟶isStrictPartialOrder _ _ po)
-
- ≤-isTotalOrder : ∀ {_≈_ _≤_} →
- Decidable _≈_ → IsTotalOrder _≈_ _≤_ →
- IsTotalOrder (Pointwise.Rel _≈_) (Lex-≤ _≈_ _≤_)
- ≤-isTotalOrder dec tot =
- Strict.≤-isTotalOrder
- (Conv.isTotalOrder⟶isStrictTotalOrder _ _ dec tot)
-
- ≤-isDecTotalOrder :
- ∀ {_≈_ _≤_} →
- IsDecTotalOrder _≈_ _≤_ →
- IsDecTotalOrder (Pointwise.Rel _≈_) (Lex-≤ _≈_ _≤_)
- ≤-isDecTotalOrder dtot =
- Strict.≤-isDecTotalOrder
- (Conv.isDecTotalOrder⟶isStrictTotalOrder _ _ dtot)
-
- <-isStrictPartialOrder : ∀ {_≈_ _≤_} →
- IsPartialOrder _≈_ _≤_ →
- IsStrictPartialOrder (Pointwise.Rel _≈_) (Lex-< _≈_ _≤_)
- <-isStrictPartialOrder po =
- Strict.<-isStrictPartialOrder
- (Conv.isPartialOrder⟶isStrictPartialOrder _ _ po)
-
- <-isStrictTotalOrder : ∀ {_≈_ _≤_} →
- Decidable _≈_ → IsTotalOrder _≈_ _≤_ →
- IsStrictTotalOrder (Pointwise.Rel _≈_) (Lex-< _≈_ _≤_)
- <-isStrictTotalOrder dec tot =
- Strict.<-isStrictTotalOrder
- (Conv.isTotalOrder⟶isStrictTotalOrder _ _ dec tot)
-
--- "Packages" (e.g. preorders) can also be handled.
-
-≤-preorder : Poset _ _ _ → Preorder _ _ _
-≤-preorder po = record
- { isPreorder = ≤-isPreorder isPartialOrder
- } where open Poset po
-
-≤-partialOrder : Poset _ _ _ → Poset _ _ _
-≤-partialOrder po = record
- { isPartialOrder = ≤-isPartialOrder isPartialOrder
- } where open Poset po
-
-≤-decTotalOrder : DecTotalOrder _ _ _ → DecTotalOrder _ _ _
-≤-decTotalOrder dtot = record
- { isDecTotalOrder = ≤-isDecTotalOrder isDecTotalOrder
- } where open DecTotalOrder dtot
-
-<-strictPartialOrder : Poset _ _ _ → StrictPartialOrder _ _ _
-<-strictPartialOrder po = record
- { isStrictPartialOrder = <-isStrictPartialOrder isPartialOrder
- } where open Poset po
-
-<-strictTotalOrder : DecTotalOrder _ _ _ → StrictTotalOrder _ _ _
-<-strictTotalOrder dtot = record
- { isStrictTotalOrder = <-isStrictTotalOrder _≟_ isTotalOrder
- } where open IsDecTotalOrder (DecTotalOrder.isDecTotalOrder dtot)
+open import Data.List.Relation.Lex.NonStrict public
+ hiding (base; halt; this; next; ²-this; ²-next)
+open import Data.List.Relation.Lex.Core public
diff --git a/src/Relation/Binary/List/Pointwise.agda b/src/Relation/Binary/List/Pointwise.agda
index 225f433..e44fa41 100644
--- a/src/Relation/Binary/List/Pointwise.agda
+++ b/src/Relation/Binary/List/Pointwise.agda
@@ -2,189 +2,11 @@
-- The Agda standard library
--
-- Pointwise lifting of relations to lists
+--
+-- This module is DEPRECATED. Please use Data.List.Relation.Pointwise
+-- directly.
------------------------------------------------------------------------
module Relation.Binary.List.Pointwise where
-open import Function
-open import Function.Inverse using (Inverse)
-open import Data.Product hiding (map)
-open import Data.List.Base hiding (map)
-open import Level
-open import Relation.Nullary
-import Relation.Nullary.Decidable as Dec using (map′)
-open import Relation.Binary renaming (Rel to Rel₂)
-open import Relation.Binary.PropositionalEquality as P using (_≡_)
-
-infixr 5 _∷_
-
-data Rel {a b ℓ} {A : Set a} {B : Set b}
- (_∼_ : REL A B ℓ) : List A → List B → Set (a ⊔ b ⊔ ℓ) where
- [] : Rel _∼_ [] []
- _∷_ : ∀ {x xs y ys} (x∼y : x ∼ y) (xs∼ys : Rel _∼_ xs ys) →
- Rel _∼_ (x ∷ xs) (y ∷ ys)
-
-head : ∀ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} {x y xs ys} →
- Rel _∼_ (x ∷ xs) (y ∷ ys) → x ∼ y
-head (x∼y ∷ xs∼ys) = x∼y
-
-tail : ∀ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} {x y xs ys} →
- Rel _∼_ (x ∷ xs) (y ∷ ys) → Rel _∼_ xs ys
-tail (x∼y ∷ xs∼ys) = xs∼ys
-
-rec : ∀ {a b c ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ}
- (P : ∀ {xs ys} → Rel _∼_ xs ys → Set c) →
- (∀ {x y xs ys} {xs∼ys : Rel _∼_ xs ys} →
- (x∼y : x ∼ y) → P xs∼ys → P (x∼y ∷ xs∼ys)) →
- P [] →
- ∀ {xs ys} (xs∼ys : Rel _∼_ xs ys) → P xs∼ys
-rec P c n [] = n
-rec P c n (x∼y ∷ xs∼ys) = c x∼y (rec P c n xs∼ys)
-
-map : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b}
- {_≈_ : REL A B ℓ₁} {_∼_ : REL A B ℓ₂} →
- _≈_ ⇒ _∼_ → Rel _≈_ ⇒ Rel _∼_
-map ≈⇒∼ [] = []
-map ≈⇒∼ (x≈y ∷ xs≈ys) = ≈⇒∼ x≈y ∷ map ≈⇒∼ xs≈ys
-
-reflexive : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b}
- {_≈_ : REL A B ℓ₁} {_∼_ : REL A B ℓ₂} →
- _≈_ ⇒ _∼_ → Rel _≈_ ⇒ Rel _∼_
-reflexive ≈⇒∼ [] = []
-reflexive ≈⇒∼ (x≈y ∷ xs≈ys) = ≈⇒∼ x≈y ∷ reflexive ≈⇒∼ xs≈ys
-
-refl : ∀ {a ℓ} {A : Set a} {_∼_ : Rel₂ A ℓ} →
- Reflexive _∼_ → Reflexive (Rel _∼_)
-refl rfl {[]} = []
-refl rfl {x ∷ xs} = rfl ∷ refl rfl
-
-symmetric : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b}
- {_≈_ : REL A B ℓ₁} {_∼_ : REL B A ℓ₂} →
- Sym _≈_ _∼_ → Sym (Rel _≈_) (Rel _∼_)
-symmetric sym [] = []
-symmetric sym (x∼y ∷ xs∼ys) = sym x∼y ∷ symmetric sym xs∼ys
-
-transitive :
- ∀ {a b c ℓ₁ ℓ₂ ℓ₃} {A : Set a} {B : Set b} {C : Set c}
- {_≋_ : REL A B ℓ₁} {_≈_ : REL B C ℓ₂} {_∼_ : REL A C ℓ₃} →
- Trans _≋_ _≈_ _∼_ → Trans (Rel _≋_) (Rel _≈_) (Rel _∼_)
-transitive trans [] [] = []
-transitive trans (x∼y ∷ xs∼ys) (y∼z ∷ ys∼zs) =
- trans x∼y y∼z ∷ transitive trans xs∼ys ys∼zs
-
-antisymmetric : ∀ {a ℓ₁ ℓ₂} {A : Set a}
- {_≈_ : Rel₂ A ℓ₁} {_≤_ : Rel₂ A ℓ₂} →
- Antisymmetric _≈_ _≤_ →
- Antisymmetric (Rel _≈_) (Rel _≤_)
-antisymmetric antisym [] [] = []
-antisymmetric antisym (x∼y ∷ xs∼ys) (y∼x ∷ ys∼xs) =
- antisym x∼y y∼x ∷ antisymmetric antisym xs∼ys ys∼xs
-
-respects₂ : ∀ {a ℓ₁ ℓ₂} {A : Set a}
- {_≈_ : Rel₂ A ℓ₁} {_∼_ : Rel₂ A ℓ₂} →
- _∼_ Respects₂ _≈_ → (Rel _∼_) Respects₂ (Rel _≈_)
-respects₂ {_≈_ = _≈_} {_∼_} resp =
- (λ {xs} {ys} {zs} → resp¹ {xs} {ys} {zs}) ,
- (λ {xs} {ys} {zs} → resp² {xs} {ys} {zs})
- where
- resp¹ : ∀ {xs} → (Rel _∼_ xs) Respects (Rel _≈_)
- resp¹ [] [] = []
- resp¹ (x≈y ∷ xs≈ys) (z∼x ∷ zs∼xs) =
- proj₁ resp x≈y z∼x ∷ resp¹ xs≈ys zs∼xs
-
- resp² : ∀ {ys} → (flip (Rel _∼_) ys) Respects (Rel _≈_)
- resp² [] [] = []
- resp² (x≈y ∷ xs≈ys) (x∼z ∷ xs∼zs) =
- proj₂ resp x≈y x∼z ∷ resp² xs≈ys xs∼zs
-
-decidable : ∀ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} →
- Decidable _∼_ → Decidable (Rel _∼_)
-decidable dec [] [] = yes []
-decidable dec [] (y ∷ ys) = no (λ ())
-decidable dec (x ∷ xs) [] = no (λ ())
-decidable dec (x ∷ xs) (y ∷ ys) with dec x y
-... | no ¬x∼y = no (¬x∼y ∘ head)
-... | yes x∼y with decidable dec xs ys
-... | no ¬xs∼ys = no (¬xs∼ys ∘ tail)
-... | yes xs∼ys = yes (x∼y ∷ xs∼ys)
-
-isEquivalence : ∀ {a ℓ} {A : Set a} {_≈_ : Rel₂ A ℓ} →
- IsEquivalence _≈_ → IsEquivalence (Rel _≈_)
-isEquivalence eq = record
- { refl = refl Eq.refl
- ; sym = symmetric Eq.sym
- ; trans = transitive Eq.trans
- } where module Eq = IsEquivalence eq
-
-isPreorder : ∀ {a ℓ₁ ℓ₂} {A : Set a}
- {_≈_ : Rel₂ A ℓ₁} {_∼_ : Rel₂ A ℓ₂} →
- IsPreorder _≈_ _∼_ → IsPreorder (Rel _≈_) (Rel _∼_)
-isPreorder pre = record
- { isEquivalence = isEquivalence Pre.isEquivalence
- ; reflexive = reflexive Pre.reflexive
- ; trans = transitive Pre.trans
- } where module Pre = IsPreorder pre
-
-isDecEquivalence : ∀ {a ℓ} {A : Set a}
- {_≈_ : Rel₂ A ℓ} → IsDecEquivalence _≈_ →
- IsDecEquivalence (Rel _≈_)
-isDecEquivalence eq = record
- { isEquivalence = isEquivalence DE.isEquivalence
- ; _≟_ = decidable DE._≟_
- } where module DE = IsDecEquivalence eq
-
-isPartialOrder : ∀ {a ℓ₁ ℓ₂} {A : Set a}
- {_≈_ : Rel₂ A ℓ₁} {_≤_ : Rel₂ A ℓ₂} →
- IsPartialOrder _≈_ _≤_ →
- IsPartialOrder (Rel _≈_) (Rel _≤_)
-isPartialOrder po = record
- { isPreorder = isPreorder PO.isPreorder
- ; antisym = antisymmetric PO.antisym
- } where module PO = IsPartialOrder po
-
-preorder : ∀ {p₁ p₂ p₃} → Preorder p₁ p₂ p₃ → Preorder _ _ _
-preorder p = record
- { isPreorder = isPreorder (Preorder.isPreorder p)
- }
-
-setoid : ∀ {c ℓ} → Setoid c ℓ → Setoid _ _
-setoid s = record
- { isEquivalence = isEquivalence (Setoid.isEquivalence s)
- }
-
-decSetoid : ∀ {c ℓ} → DecSetoid c ℓ → DecSetoid _ _
-decSetoid d = record
- { isDecEquivalence = isDecEquivalence (DecSetoid.isDecEquivalence d)
- }
-
-poset : ∀ {c ℓ₁ ℓ₂} → Poset c ℓ₁ ℓ₂ → Poset _ _ _
-poset p = record
- { isPartialOrder = isPartialOrder (Poset.isPartialOrder p)
- }
-
--- Rel _≡_ coincides with _≡_.
-
-Rel≡⇒≡ : ∀ {a} {A : Set a} → Rel {A = A} _≡_ ⇒ _≡_
-Rel≡⇒≡ [] = P.refl
-Rel≡⇒≡ (P.refl ∷ xs∼ys) with Rel≡⇒≡ xs∼ys
-Rel≡⇒≡ (P.refl ∷ xs∼ys) | P.refl = P.refl
-
-≡⇒Rel≡ : ∀ {a} {A : Set a} → _≡_ ⇒ Rel {A = A} _≡_
-≡⇒Rel≡ P.refl = refl P.refl
-
-Rel↔≡ : ∀ {a} {A : Set a} →
- Inverse (setoid (P.setoid A)) (P.setoid (List A))
-Rel↔≡ = record
- { to = record { _⟨$⟩_ = id; cong = Rel≡⇒≡ }
- ; from = record { _⟨$⟩_ = id; cong = ≡⇒Rel≡ }
- ; inverse-of = record
- { left-inverse-of = λ _ → refl P.refl
- ; right-inverse-of = λ _ → P.refl
- }
- }
-
-decidable-≡ : ∀ {a} {A : Set a} →
- Decidable {A = A} _≡_ → Decidable {A = List A} _≡_
-decidable-≡ dec xs ys = Dec.map′ Rel≡⇒≡ ≡⇒Rel≡ (xs ≟ ys)
- where
- open DecSetoid (decSetoid (P.decSetoid dec))
+open import Data.List.Relation.Pointwise public
diff --git a/src/Relation/Binary/List/StrictLex.agda b/src/Relation/Binary/List/StrictLex.agda
index 9bf21ad..57f86c4 100644
--- a/src/Relation/Binary/List/StrictLex.agda
+++ b/src/Relation/Binary/List/StrictLex.agda
@@ -2,6 +2,9 @@
-- The Agda standard library
--
-- Lexicographic ordering of lists
+--
+-- This module is DEPRECATED. Please use Data.List.Relation.Lex.Strict
+-- directly.
------------------------------------------------------------------------
-- The definition of lexicographic ordering used here is suitable if
@@ -11,292 +14,6 @@
module Relation.Binary.List.StrictLex where
-open import Data.Empty
-open import Data.Unit.Base using (⊤; tt)
-open import Function
-open import Data.Product
-open import Data.Sum
-open import Data.List.Base
-open import Level
-open import Relation.Nullary
-open import Relation.Binary
-open import Relation.Binary.Consequences
-open import Relation.Binary.List.Pointwise as Pointwise
- using ([]; _∷_; head; tail)
-
-module _ {A : Set} where
-
- data Lex (P : Set) (_≈_ _<_ : Rel A zero) : Rel (List A) zero where
- base : P → Lex P _≈_ _<_ [] []
- halt : ∀ {y ys} → Lex P _≈_ _<_ [] (y ∷ ys)
- this : ∀ {x xs y ys} (x<y : x < y) → Lex P _≈_ _<_ (x ∷ xs) (y ∷ ys)
- next : ∀ {x xs y ys} (x≈y : x ≈ y)
- (xs⊴ys : Lex P _≈_ _<_ xs ys) → Lex P _≈_ _<_ (x ∷ xs) (y ∷ ys)
-
- -- Strict lexicographic ordering.
-
- Lex-< : (_≈_ _<_ : Rel A zero) → Rel (List A) zero
- Lex-< = Lex ⊥
-
- ¬[]<[] : ∀ {_≈_ _<_} → ¬ Lex-< _≈_ _<_ [] []
- ¬[]<[] (base ())
-
- -- Non-strict lexicographic ordering.
-
- Lex-≤ : (_≈_ _<_ : Rel A zero) → Rel (List A) zero
- Lex-≤ = Lex ⊤
-
- -- Utilities.
-
- ¬≤-this : ∀ {P _≈_ _<_ x y xs ys} → ¬ (x ≈ y) → ¬ (x < y) →
- ¬ Lex P _≈_ _<_ (x ∷ xs) (y ∷ ys)
- ¬≤-this ¬x≈y ¬x<y (this x<y) = ¬x<y x<y
- ¬≤-this ¬x≈y ¬x<y (next x≈y xs⊴ys) = ¬x≈y x≈y
-
- ¬≤-next : ∀ {P _≈_ _<_ x y xs ys} →
- ¬ (x < y) → ¬ Lex P _≈_ _<_ xs ys →
- ¬ Lex P _≈_ _<_ (x ∷ xs) (y ∷ ys)
- ¬≤-next ¬x<y ¬xs⊴ys (this x<y) = ¬x<y x<y
- ¬≤-next ¬x<y ¬xs⊴ys (next x≈y xs⊴ys) = ¬xs⊴ys xs⊴ys
-
- ----------------------------------------------------------------------
- -- Properties
-
- ≤-reflexive : ∀ _≈_ _<_ → Pointwise.Rel _≈_ ⇒ Lex-≤ _≈_ _<_
- ≤-reflexive _≈_ _<_ [] = base tt
- ≤-reflexive _≈_ _<_ (x≈y ∷ xs≈ys) =
- next x≈y (≤-reflexive _≈_ _<_ xs≈ys)
-
- <-irreflexive : ∀ {_≈_ _<_} → Irreflexive _≈_ _<_ →
- Irreflexive (Pointwise.Rel _≈_) (Lex-< _≈_ _<_)
- <-irreflexive irr [] (base ())
- <-irreflexive irr (x≈y ∷ xs≈ys) (this x<y) = irr x≈y x<y
- <-irreflexive irr (x≈y ∷ xs≈ys) (next x≊y xs⊴ys) =
- <-irreflexive irr xs≈ys xs⊴ys
-
- transitive : ∀ {P _≈_ _<_} →
- IsEquivalence _≈_ → _<_ Respects₂ _≈_ → Transitive _<_ →
- Transitive (Lex P _≈_ _<_)
- transitive {P} {_≈_} {_<_} eq resp tr = trans
- where
- trans : Transitive (Lex P _≈_ _<_)
- trans (base p) (base _) = base p
- trans (base y) halt = halt
- trans halt (this y<z) = halt
- trans halt (next y≈z ys⊴zs) = halt
- trans (this x<y) (this y<z) = this (tr x<y y<z)
- trans (this x<y) (next y≈z ys⊴zs) = this (proj₁ resp y≈z x<y)
- trans (next x≈y xs⊴ys) (this y<z) =
- this (proj₂ resp (IsEquivalence.sym eq x≈y) y<z)
- trans (next x≈y xs⊴ys) (next y≈z ys⊴zs) =
- next (IsEquivalence.trans eq x≈y y≈z) (trans xs⊴ys ys⊴zs)
-
- antisymmetric :
- ∀ {P _≈_ _<_} →
- Symmetric _≈_ → Irreflexive _≈_ _<_ → Asymmetric _<_ →
- Antisymmetric (Pointwise.Rel _≈_) (Lex P _≈_ _<_)
- antisymmetric {P} {_≈_} {_<_} sym ir asym = as
- where
- as : Antisymmetric (Pointwise.Rel _≈_) (Lex P _≈_ _<_)
- as (base _) (base _) = []
- as halt ()
- as (this x<y) (this y<x) = ⊥-elim (asym x<y y<x)
- as (this x<y) (next y≈x ys⊴xs) = ⊥-elim (ir (sym y≈x) x<y)
- as (next x≈y xs⊴ys) (this y<x) = ⊥-elim (ir (sym x≈y) y<x)
- as (next x≈y xs⊴ys) (next y≈x ys⊴xs) = x≈y ∷ as xs⊴ys ys⊴xs
-
- <-asymmetric : ∀ {_≈_ _<_} →
- Symmetric _≈_ → _<_ Respects₂ _≈_ → Asymmetric _<_ →
- Asymmetric (Lex-< _≈_ _<_)
- <-asymmetric {_≈_} {_<_} sym resp as = asym
- where
- irrefl : Irreflexive _≈_ _<_
- irrefl = asym⟶irr resp sym as
-
- asym : Asymmetric (Lex-< _≈_ _<_)
- asym (base bot) _ = bot
- asym halt ()
- asym (this x<y) (this y<x) = as x<y y<x
- asym (this x<y) (next y≈x ys⊴xs) = irrefl (sym y≈x) x<y
- asym (next x≈y xs⊴ys) (this y<x) = irrefl (sym x≈y) y<x
- asym (next x≈y xs⊴ys) (next y≈x ys⊴xs) = asym xs⊴ys ys⊴xs
-
- respects₂ : ∀ {P _≈_ _<_} →
- IsEquivalence _≈_ → _<_ Respects₂ _≈_ →
- Lex P _≈_ _<_ Respects₂ Pointwise.Rel _≈_
- respects₂ {P} {_≈_} {_<_} eq resp =
- (λ {xs} {ys} {zs} → resp¹ {xs} {ys} {zs}) ,
- (λ {xs} {ys} {zs} → resp² {xs} {ys} {zs})
- where
- resp¹ : ∀ {xs} → Lex P _≈_ _<_ xs Respects Pointwise.Rel _≈_
- resp¹ [] xs⊴[] = xs⊴[]
- resp¹ (x≈y ∷ xs≈ys) halt = halt
- resp¹ (x≈y ∷ xs≈ys) (this z<x) = this (proj₁ resp x≈y z<x)
- resp¹ (x≈y ∷ xs≈ys) (next z≈x zs⊴xs) =
- next (Eq.trans z≈x x≈y) (resp¹ xs≈ys zs⊴xs)
- where module Eq = IsEquivalence eq
-
- resp² : ∀ {ys} → flip (Lex P _≈_ _<_) ys Respects Pointwise.Rel _≈_
- resp² [] []⊴ys = []⊴ys
- resp² (x≈z ∷ xs≈zs) (this x<y) = this (proj₂ resp x≈z x<y)
- resp² (x≈z ∷ xs≈zs) (next x≈y xs⊴ys) =
- next (Eq.trans (Eq.sym x≈z) x≈y) (resp² xs≈zs xs⊴ys)
- where module Eq = IsEquivalence eq
-
- decidable : ∀ {P _≈_ _<_} →
- Dec P → Decidable _≈_ → Decidable _<_ →
- Decidable (Lex P _≈_ _<_)
- decidable (yes p) dec-≈ dec-< [] [] = yes (base p)
- decidable (no ¬p) dec-≈ dec-< [] [] = no λ{(base p) → ¬p p}
- decidable dec-P dec-≈ dec-< [] (y ∷ ys) = yes halt
- decidable dec-P dec-≈ dec-< (x ∷ xs) [] = no (λ ())
- decidable dec-P dec-≈ dec-< (x ∷ xs) (y ∷ ys) with dec-< x y
- ... | yes x<y = yes (this x<y)
- ... | no ¬x<y with dec-≈ x y
- ... | no ¬x≈y = no (¬≤-this ¬x≈y ¬x<y)
- ... | yes x≈y with decidable dec-P dec-≈ dec-< xs ys
- ... | yes xs⊴ys = yes (next x≈y xs⊴ys)
- ... | no ¬xs⊴ys = no (¬≤-next ¬x<y ¬xs⊴ys)
-
- <-decidable :
- ∀ {_≈_ _<_} →
- Decidable _≈_ → Decidable _<_ → Decidable (Lex-< _≈_ _<_)
- <-decidable = decidable (no id)
-
- ≤-decidable :
- ∀ {_≈_ _<_} →
- Decidable _≈_ → Decidable _<_ → Decidable (Lex-≤ _≈_ _<_)
- ≤-decidable = decidable (yes tt)
-
- -- Note that trichotomy is an unnecessarily strong precondition for
- -- the following lemma.
-
- ≤-total :
- ∀ {_≈_ _<_} →
- Symmetric _≈_ → Trichotomous _≈_ _<_ → Total (Lex-≤ _≈_ _<_)
- ≤-total {_≈_} {_<_} sym tri = total
- where
- total : Total (Lex-≤ _≈_ _<_)
- total [] [] = inj₁ (base tt)
- total [] (x ∷ xs) = inj₁ halt
- total (x ∷ xs) [] = inj₂ halt
- total (x ∷ xs) (y ∷ ys) with tri x y
- ... | tri< x<y _ _ = inj₁ (this x<y)
- ... | tri> _ _ y<x = inj₂ (this y<x)
- ... | tri≈ _ x≈y _ with total xs ys
- ... | inj₁ xs≲ys = inj₁ (next x≈y xs≲ys)
- ... | inj₂ ys≲xs = inj₂ (next (sym x≈y) ys≲xs)
-
- <-compare : ∀ {_≈_ _<_} →
- Symmetric _≈_ → Trichotomous _≈_ _<_ →
- Trichotomous (Pointwise.Rel _≈_) (Lex-< _≈_ _<_)
- <-compare {_≈_} {_<_} sym tri = cmp
- where
- cmp : Trichotomous (Pointwise.Rel _≈_) (Lex-< _≈_ _<_)
- cmp [] [] = tri≈ ¬[]<[] [] ¬[]<[]
- cmp [] (y ∷ ys) = tri< halt (λ ()) (λ ())
- cmp (x ∷ xs) [] = tri> (λ ()) (λ ()) halt
- cmp (x ∷ xs) (y ∷ ys) with tri x y
- ... | tri< x<y ¬x≈y ¬y<x =
- tri< (this x<y) (¬x≈y ∘ head) (¬≤-this (¬x≈y ∘ sym) ¬y<x)
- ... | tri> ¬x<y ¬x≈y y<x =
- tri> (¬≤-this ¬x≈y ¬x<y) (¬x≈y ∘ head) (this y<x)
- ... | tri≈ ¬x<y x≈y ¬y<x with cmp xs ys
- ... | tri< xs<ys ¬xs≈ys ¬ys<xs =
- tri< (next x≈y xs<ys) (¬xs≈ys ∘ tail) (¬≤-next ¬y<x ¬ys<xs)
- ... | tri≈ ¬xs<ys xs≈ys ¬ys<xs =
- tri≈ (¬≤-next ¬x<y ¬xs<ys) (x≈y ∷ xs≈ys) (¬≤-next ¬y<x ¬ys<xs)
- ... | tri> ¬xs<ys ¬xs≈ys ys<xs =
- tri> (¬≤-next ¬x<y ¬xs<ys) (¬xs≈ys ∘ tail) (next (sym x≈y) ys<xs)
-
- -- Some collections of properties which are preserved by Lex-≤ or
- -- Lex-<.
-
- ≤-isPreorder : ∀ {_≈_ _<_} →
- IsEquivalence _≈_ → Transitive _<_ → _<_ Respects₂ _≈_ →
- IsPreorder (Pointwise.Rel _≈_) (Lex-≤ _≈_ _<_)
- ≤-isPreorder {_≈_} {_<_} eq tr resp = record
- { isEquivalence = Pointwise.isEquivalence eq
- ; reflexive = ≤-reflexive _≈_ _<_
- ; trans = transitive eq resp tr
- }
-
- ≤-isPartialOrder : ∀ {_≈_ _<_} →
- IsStrictPartialOrder _≈_ _<_ →
- IsPartialOrder (Pointwise.Rel _≈_) (Lex-≤ _≈_ _<_)
- ≤-isPartialOrder {_≈_} {_<_} spo = record
- { isPreorder = ≤-isPreorder isEquivalence trans <-resp-≈
- ; antisym = antisymmetric Eq.sym irrefl
- (trans∧irr⟶asym {_≈_ = _≈_} {_<_ = _<_}
- Eq.refl trans irrefl)
- } where open IsStrictPartialOrder spo
-
- ≤-isTotalOrder : ∀ {_≈_ _<_} →
- IsStrictTotalOrder _≈_ _<_ →
- IsTotalOrder (Pointwise.Rel _≈_) (Lex-≤ _≈_ _<_)
- ≤-isTotalOrder sto = record
- { isPartialOrder =
- ≤-isPartialOrder (record
- { isEquivalence = isEquivalence
- ; irrefl = tri⟶irr compare
- ; trans = trans
- ; <-resp-≈ = <-resp-≈
- })
- ; total = ≤-total Eq.sym compare
- } where open IsStrictTotalOrder sto
-
- ≤-isDecTotalOrder : ∀ {_≈_ _<_} →
- IsStrictTotalOrder _≈_ _<_ →
- IsDecTotalOrder (Pointwise.Rel _≈_) (Lex-≤ _≈_ _<_)
- ≤-isDecTotalOrder sto = record
- { isTotalOrder = ≤-isTotalOrder sto
- ; _≟_ = Pointwise.decidable _≟_
- ; _≤?_ = ≤-decidable _≟_ (tri⟶dec< compare)
- } where open IsStrictTotalOrder sto
-
- <-isStrictPartialOrder
- : ∀ {_≈_ _<_} → IsStrictPartialOrder _≈_ _<_ →
- IsStrictPartialOrder (Pointwise.Rel _≈_) (Lex-< _≈_ _<_)
- <-isStrictPartialOrder spo = record
- { isEquivalence = Pointwise.isEquivalence isEquivalence
- ; irrefl = <-irreflexive irrefl
- ; trans = transitive isEquivalence <-resp-≈ trans
- ; <-resp-≈ = respects₂ isEquivalence <-resp-≈
- } where open IsStrictPartialOrder spo
-
- <-isStrictTotalOrder
- : ∀ {_≈_ _<_} → IsStrictTotalOrder _≈_ _<_ →
- IsStrictTotalOrder (Pointwise.Rel _≈_) (Lex-< _≈_ _<_)
- <-isStrictTotalOrder sto = record
- { isEquivalence = Pointwise.isEquivalence isEquivalence
- ; trans = transitive isEquivalence <-resp-≈ trans
- ; compare = <-compare Eq.sym compare
- } where open IsStrictTotalOrder sto
-
--- "Packages" (e.g. preorders) can also be handled.
-
-≤-preorder : Preorder _ _ _ → Preorder _ _ _
-≤-preorder pre = record
- { isPreorder = ≤-isPreorder isEquivalence trans ∼-resp-≈
- } where open Preorder pre
-
-≤-partialOrder : StrictPartialOrder _ _ _ → Poset _ _ _
-≤-partialOrder spo = record
- { isPartialOrder = ≤-isPartialOrder isStrictPartialOrder
- } where open StrictPartialOrder spo
-
-≤-decTotalOrder : StrictTotalOrder _ _ _ → DecTotalOrder _ _ _
-≤-decTotalOrder sto = record
- { isDecTotalOrder = ≤-isDecTotalOrder isStrictTotalOrder
- } where open StrictTotalOrder sto
-
-<-strictPartialOrder :
- StrictPartialOrder _ _ _ → StrictPartialOrder _ _ _
-<-strictPartialOrder spo = record
- { isStrictPartialOrder = <-isStrictPartialOrder isStrictPartialOrder
- } where open StrictPartialOrder spo
-
-<-strictTotalOrder : StrictTotalOrder _ _ _ → StrictTotalOrder _ _ _
-<-strictTotalOrder sto = record
- { isStrictTotalOrder = <-isStrictTotalOrder isStrictTotalOrder
- } where open StrictTotalOrder sto
+open import Data.List.Relation.Lex.Core public
+open import Data.List.Relation.Lex.Strict public
+ hiding (base; halt; this; next; ²-this; ²-next)
diff --git a/src/Relation/Binary/NonStrictToStrict.agda b/src/Relation/Binary/NonStrictToStrict.agda
deleted file mode 100644
index cd67ba1..0000000
--- a/src/Relation/Binary/NonStrictToStrict.agda
+++ /dev/null
@@ -1,106 +0,0 @@
-------------------------------------------------------------------------
--- The Agda standard library
---
--- Conversion of ≤ to <, along with a number of properties
-------------------------------------------------------------------------
-
--- Possible TODO: Prove that a conversion ≤ → < → ≤ returns a
--- relation equivalent to the original one (and similarly for
--- < → ≤ → <).
-
-open import Relation.Binary
-
-module Relation.Binary.NonStrictToStrict
- {a ℓ₁ ℓ₂} {A : Set a}
- (_≈_ : Rel A ℓ₁) (_≤_ : Rel A ℓ₂)
- where
-
-open import Relation.Nullary
-open import Relation.Binary.Consequences
-open import Function
-open import Data.Product
-open import Data.Sum
-
-------------------------------------------------------------------------
--- Conversion
-
--- _≤_ can be turned into _<_ as follows:
-
-_<_ : Rel A _
-x < y = (x ≤ y) × ¬ (x ≈ y)
-
-------------------------------------------------------------------------
--- The converted relations have certain properties
--- (if the original relations have certain other properties)
-
-irrefl : Irreflexive _≈_ _<_
-irrefl x≈y x<y = proj₂ x<y x≈y
-
-trans : IsPartialOrder _≈_ _≤_ → Transitive _<_
-trans po = λ x<y y<z →
- ( PO.trans (proj₁ x<y) (proj₁ y<z)
- , λ x≈z → proj₂ x<y $ lemma (proj₁ x<y) (proj₁ y<z) x≈z
- )
- where
- module PO = IsPartialOrder po
-
- lemma : ∀ {x y z} → x ≤ y → y ≤ z → x ≈ z → x ≈ y
- lemma x≤y y≤z x≈z =
- PO.antisym x≤y $ PO.trans y≤z (PO.reflexive $ PO.Eq.sym x≈z)
-
-antisym⟶asym : Antisymmetric _≈_ _≤_ → Asymmetric _<_
-antisym⟶asym antisym (x≤y , ¬x≈y) (y≤x , ¬y≈x) =
- ¬x≈y (antisym x≤y y≤x)
-
-<-resp-≈ : IsEquivalence _≈_ → _≤_ Respects₂ _≈_ → _<_ Respects₂ _≈_
-<-resp-≈ eq ≤-resp-≈ =
- (λ {x y' y} y'≈y x<y' →
- ( proj₁ ≤-resp-≈ y'≈y (proj₁ x<y')
- , λ x≈y → proj₂ x<y' (Eq.trans x≈y (Eq.sym y'≈y))
- )
- ) ,
- (λ {y x' x} x'≈x x'<y →
- ( proj₂ ≤-resp-≈ x'≈x (proj₁ x'<y)
- , λ x≈y → proj₂ x'<y (Eq.trans x'≈x x≈y)
- ))
- where module Eq = IsEquivalence eq
-
-trichotomous : Symmetric _≈_ → Decidable _≈_ →
- Antisymmetric _≈_ _≤_ → Total _≤_ →
- Trichotomous _≈_ _<_
-trichotomous ≈-sym ≈-dec antisym total x y with ≈-dec x y
-... | yes x≈y = tri≈ (irrefl x≈y) x≈y (irrefl (≈-sym x≈y))
-... | no x≉y with total x y
-... | inj₁ x≤y = tri< (x≤y , x≉y) x≉y
- (x≉y ∘ antisym x≤y ∘ proj₁)
-... | inj₂ x≥y = tri> (x≉y ∘ flip antisym x≥y ∘ proj₁) x≉y
- (x≥y , x≉y ∘ ≈-sym)
-
-decidable : Decidable _≈_ → Decidable _≤_ → Decidable _<_
-decidable ≈-dec ≤-dec x y with ≈-dec x y | ≤-dec x y
-... | yes x≈y | _ = no (flip proj₂ x≈y)
-... | no x≉y | yes x≤y = yes (x≤y , x≉y)
-... | no x≉y | no x≰y = no (x≰y ∘ proj₁)
-
-isPartialOrder⟶isStrictPartialOrder :
- IsPartialOrder _≈_ _≤_ → IsStrictPartialOrder _≈_ _<_
-isPartialOrder⟶isStrictPartialOrder po = record
- { isEquivalence = PO.isEquivalence
- ; irrefl = irrefl
- ; trans = trans po
- ; <-resp-≈ = <-resp-≈ PO.isEquivalence PO.≤-resp-≈
- } where module PO = IsPartialOrder po
-
-isTotalOrder⟶isStrictTotalOrder :
- Decidable _≈_ → IsTotalOrder _≈_ _≤_ → IsStrictTotalOrder _≈_ _<_
-isTotalOrder⟶isStrictTotalOrder dec-≈ tot = record
- { isEquivalence = TO.isEquivalence
- ; trans = trans TO.isPartialOrder
- ; compare = trichotomous TO.Eq.sym dec-≈ TO.antisym TO.total
- } where module TO = IsTotalOrder tot
-
-isDecTotalOrder⟶isStrictTotalOrder :
- IsDecTotalOrder _≈_ _≤_ → IsStrictTotalOrder _≈_ _<_
-isDecTotalOrder⟶isStrictTotalOrder dtot =
- isTotalOrder⟶isStrictTotalOrder DTO._≟_ DTO.isTotalOrder
- where module DTO = IsDecTotalOrder dtot
diff --git a/src/Relation/Binary/PreorderReasoning.agda b/src/Relation/Binary/PreorderReasoning.agda
index fb9c3e2..5b753c4 100644
--- a/src/Relation/Binary/PreorderReasoning.agda
+++ b/src/Relation/Binary/PreorderReasoning.agda
@@ -28,11 +28,12 @@ open import Relation.Binary
module Relation.Binary.PreorderReasoning
{p₁ p₂ p₃} (P : Preorder p₁ p₂ p₃) where
+open import Relation.Binary.PropositionalEquality as P using (_≡_)
open Preorder P
infix 4 _IsRelatedTo_
infix 3 _∎
-infixr 2 _∼⟨_⟩_ _≈⟨_⟩_ _≈⟨⟩_
+infixr 2 _∼⟨_⟩_ _≈⟨_⟩_ _≈⟨⟩_ _≡⟨_⟩_
infix 1 begin_
-- This seemingly unnecessary type is used to make it possible to
@@ -50,6 +51,9 @@ _ ∼⟨ x∼y ⟩ relTo y∼z = relTo (trans x∼y y∼z)
_≈⟨_⟩_ : ∀ x {y z} → x ≈ y → y IsRelatedTo z → x IsRelatedTo z
_ ≈⟨ x≈y ⟩ relTo y∼z = relTo (trans (reflexive x≈y) y∼z)
+_≡⟨_⟩_ : ∀ x {y z} → x ≡ y → y IsRelatedTo z → x IsRelatedTo z
+_ ≡⟨ P.refl ⟩ x∼z = x∼z
+
_≈⟨⟩_ : ∀ x {y} → x IsRelatedTo y → x IsRelatedTo y
_ ≈⟨⟩ x∼y = x∼y
diff --git a/src/Relation/Binary/Product/NonStrictLex.agda b/src/Relation/Binary/Product/NonStrictLex.agda
index 4f89cdc..39d658c 100644
--- a/src/Relation/Binary/Product/NonStrictLex.agda
+++ b/src/Relation/Binary/Product/NonStrictLex.agda
@@ -2,6 +2,9 @@
-- The Agda standard library
--
-- Lexicographic products of binary relations
+--
+-- This module is DEPRECATED. Please use
+-- Data.Product.Relation.Lex.NonStrict directly.
------------------------------------------------------------------------
-- The definition of lexicographic product used here is suitable if
@@ -9,169 +12,4 @@
module Relation.Binary.Product.NonStrictLex where
-open import Data.Product
-open import Data.Sum
-open import Level
-open import Relation.Binary
-open import Relation.Binary.Consequences
-import Relation.Binary.NonStrictToStrict as Conv
-open import Relation.Binary.Product.Pointwise as Pointwise
- using (_×-Rel_)
-import Relation.Binary.Product.StrictLex as Strict
-
-module _ {a₁ a₂ ℓ₁ ℓ₂} {A₁ : Set a₁} {A₂ : Set a₂} where
-
- ×-Lex : (_≈₁_ _≤₁_ : Rel A₁ ℓ₁) → (_≤₂_ : Rel A₂ ℓ₂) →
- Rel (A₁ × A₂) _
- ×-Lex _≈₁_ _≤₁_ _≤₂_ = Strict.×-Lex _≈₁_ (Conv._<_ _≈₁_ _≤₁_) _≤₂_
-
- -- Some properties which are preserved by ×-Lex (under certain
- -- assumptions).
-
- ×-reflexive : ∀ _≈₁_ _≤₁_ {_≈₂_} _≤₂_ →
- _≈₂_ ⇒ _≤₂_ → (_≈₁_ ×-Rel _≈₂_) ⇒ (×-Lex _≈₁_ _≤₁_ _≤₂_)
- ×-reflexive _≈₁_ _≤₁_ _≤₂_ refl₂ {x} {y} =
- Strict.×-reflexive _≈₁_ (Conv._<_ _≈₁_ _≤₁_) _≤₂_ refl₂ {x} {y}
-
- ×-transitive : ∀ {_≈₁_ _≤₁_} → IsPartialOrder _≈₁_ _≤₁_ →
- ∀ {_≤₂_} → Transitive _≤₂_ →
- Transitive (×-Lex _≈₁_ _≤₁_ _≤₂_)
- ×-transitive {_≈₁_ = _≈₁_} {_≤₁_ = _≤₁_} po₁ {_≤₂_ = _≤₂_} trans₂
- {x} {y} {z} =
- Strict.×-transitive
- {_<₁_ = Conv._<_ _≈₁_ _≤₁_}
- isEquivalence (Conv.<-resp-≈ _ _ isEquivalence ≤-resp-≈)
- (Conv.trans _ _ po₁)
- {_≤₂_ = _≤₂_} trans₂ {x} {y} {z}
- where open IsPartialOrder po₁
-
- ×-antisymmetric :
- ∀ {_≈₁_ _≤₁_} → IsPartialOrder _≈₁_ _≤₁_ →
- ∀ {_≈₂_ _≤₂_} → Antisymmetric _≈₂_ _≤₂_ →
- Antisymmetric (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _≤₁_ _≤₂_)
- ×-antisymmetric {_≈₁_ = _≈₁_} {_≤₁_ = _≤₁_}
- po₁ {_≤₂_ = _≤₂_} antisym₂ {x} {y} =
- Strict.×-antisymmetric {_<₁_ = Conv._<_ _≈₁_ _≤₁_}
- ≈-sym₁ irrefl₁ asym₁
- {_≤₂_ = _≤₂_} antisym₂ {x} {y}
- where
- open IsPartialOrder po₁
- open Eq renaming (refl to ≈-refl₁; sym to ≈-sym₁)
-
- irrefl₁ : Irreflexive _≈₁_ (Conv._<_ _≈₁_ _≤₁_)
- irrefl₁ = Conv.irrefl _≈₁_ _≤₁_
-
- asym₁ : Asymmetric (Conv._<_ _≈₁_ _≤₁_)
- asym₁ = trans∧irr⟶asym {_≈_ = _≈₁_}
- ≈-refl₁ (Conv.trans _ _ po₁) irrefl₁
-
- ×-≈-respects₂ :
- ∀ {_≈₁_ _≤₁_} → IsEquivalence _≈₁_ → _≤₁_ Respects₂ _≈₁_ →
- ∀ {_≈₂_ _≤₂_ : Rel A₂ ℓ₂} → _≤₂_ Respects₂ _≈₂_ →
- (×-Lex _≈₁_ _≤₁_ _≤₂_) Respects₂ (_≈₁_ ×-Rel _≈₂_)
- ×-≈-respects₂ eq₁ resp₁ resp₂ =
- Strict.×-≈-respects₂ eq₁ (Conv.<-resp-≈ _ _ eq₁ resp₁) resp₂
-
- ×-decidable : ∀ {_≈₁_ _≤₁_} → Decidable _≈₁_ → Decidable _≤₁_ →
- ∀ {_≤₂_} → Decidable _≤₂_ →
- Decidable (×-Lex _≈₁_ _≤₁_ _≤₂_)
- ×-decidable dec-≈₁ dec-≤₁ dec-≤₂ =
- Strict.×-decidable dec-≈₁ (Conv.decidable _ _ dec-≈₁ dec-≤₁)
- dec-≤₂
-
- ×-total : ∀ {_≈₁_ _≤₁_} → Symmetric _≈₁_ → Decidable _≈₁_ →
- Antisymmetric _≈₁_ _≤₁_ → Total _≤₁_ →
- ∀ {_≤₂_} → Total _≤₂_ →
- Total (×-Lex _≈₁_ _≤₁_ _≤₂_)
- ×-total {_≈₁_ = _≈₁_} {_≤₁_ = _≤₁_} sym₁ dec₁ antisym₁ total₁
- {_≤₂_ = _≤₂_} total₂ = total
- where
- tri₁ : Trichotomous _≈₁_ (Conv._<_ _≈₁_ _≤₁_)
- tri₁ = Conv.trichotomous _ _ sym₁ dec₁ antisym₁ total₁
-
- total : Total (×-Lex _≈₁_ _≤₁_ _≤₂_)
- total x y with tri₁ (proj₁ x) (proj₁ y)
- ... | tri< x₁<y₁ x₁≉y₁ x₁≯y₁ = inj₁ (inj₁ x₁<y₁)
- ... | tri> x₁≮y₁ x₁≉y₁ x₁>y₁ = inj₂ (inj₁ x₁>y₁)
- ... | tri≈ x₁≮y₁ x₁≈y₁ x₁≯y₁ with total₂ (proj₂ x) (proj₂ y)
- ... | inj₁ x₂≤y₂ = inj₁ (inj₂ (x₁≈y₁ , x₂≤y₂))
- ... | inj₂ x₂≥y₂ = inj₂ (inj₂ (sym₁ x₁≈y₁ , x₂≥y₂))
-
- -- Some collections of properties which are preserved by ×-Lex
- -- (under certain assumptions).
-
- _×-isPartialOrder_ :
- ∀ {_≈₁_ _≤₁_} → IsPartialOrder _≈₁_ _≤₁_ →
- ∀ {_≈₂_ _≤₂_} → IsPartialOrder _≈₂_ _≤₂_ →
- IsPartialOrder (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _≤₁_ _≤₂_)
- _×-isPartialOrder_ {_≈₁_ = _≈₁_} {_≤₁_ = _≤₁_} po₁
- {_≤₂_ = _≤₂_} po₂ = record
- { isPreorder = record
- { isEquivalence = Pointwise._×-isEquivalence_
- (isEquivalence po₁)
- (isEquivalence po₂)
- ; reflexive = λ {x y} →
- ×-reflexive _≈₁_ _≤₁_ _≤₂_ (reflexive po₂)
- {x} {y}
- ; trans = λ {x y z} →
- ×-transitive po₁ {_≤₂_ = _≤₂_} (trans po₂)
- {x} {y} {z}
- }
- ; antisym = λ {x y} →
- ×-antisymmetric {_≤₁_ = _≤₁_} po₁
- {_≤₂_ = _≤₂_} (antisym po₂) {x} {y}
- }
- where open IsPartialOrder
-
- ×-isTotalOrder :
- ∀ {_≈₁_ _≤₁_} → Decidable _≈₁_ → IsTotalOrder _≈₁_ _≤₁_ →
- ∀ {_≈₂_ _≤₂_} → IsTotalOrder _≈₂_ _≤₂_ →
- IsTotalOrder (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _≤₁_ _≤₂_)
- ×-isTotalOrder {_≤₁_ = _≤₁_} ≈₁-dec to₁ {_≤₂_ = _≤₂_} to₂ = record
- { isPartialOrder = isPartialOrder to₁ ×-isPartialOrder
- isPartialOrder to₂
- ; total = ×-total {_≤₁_ = _≤₁_} (Eq.sym to₁) ≈₁-dec
- (antisym to₁) (total to₁)
- {_≤₂_ = _≤₂_} (total to₂)
- }
- where open IsTotalOrder
-
- _×-isDecTotalOrder_ :
- ∀ {_≈₁_ _≤₁_} → IsDecTotalOrder _≈₁_ _≤₁_ →
- ∀ {_≈₂_ _≤₂_} → IsDecTotalOrder _≈₂_ _≤₂_ →
- IsDecTotalOrder (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _≤₁_ _≤₂_)
- _×-isDecTotalOrder_ {_≤₁_ = _≤₁_} to₁ {_≤₂_ = _≤₂_} to₂ = record
- { isTotalOrder = ×-isTotalOrder (_≟_ to₁)
- (isTotalOrder to₁)
- (isTotalOrder to₂)
- ; _≟_ = Pointwise._×-decidable_ (_≟_ to₁) (_≟_ to₂)
- ; _≤?_ = ×-decidable (_≟_ to₁) (_≤?_ to₁) (_≤?_ to₂)
- }
- where open IsDecTotalOrder
-
--- "Packages" (e.g. posets) can also be combined.
-
-_×-poset_ :
- ∀ {p₁ p₂ p₃ p₄} → Poset p₁ p₂ _ → Poset p₃ p₄ _ → Poset _ _ _
-p₁ ×-poset p₂ = record
- { isPartialOrder = isPartialOrder p₁ ×-isPartialOrder
- isPartialOrder p₂
- } where open Poset
-
-_×-totalOrder_ :
- ∀ {d₁ d₂ t₃ t₄} →
- DecTotalOrder d₁ d₂ _ → TotalOrder t₃ t₄ _ → TotalOrder _ _ _
-t₁ ×-totalOrder t₂ = record
- { isTotalOrder = ×-isTotalOrder T₁._≟_ T₁.isTotalOrder T₂.isTotalOrder
- }
- where
- module T₁ = DecTotalOrder t₁
- module T₂ = TotalOrder t₂
-
-_×-decTotalOrder_ :
- ∀ {d₁ d₂ d₃ d₄} →
- DecTotalOrder d₁ d₂ _ → DecTotalOrder d₃ d₄ _ → DecTotalOrder _ _ _
-t₁ ×-decTotalOrder t₂ = record
- { isDecTotalOrder = isDecTotalOrder t₁ ×-isDecTotalOrder
- isDecTotalOrder t₂
- } where open DecTotalOrder
+open import Data.Product.Relation.Lex.NonStrict public
diff --git a/src/Relation/Binary/Product/Pointwise.agda b/src/Relation/Binary/Product/Pointwise.agda
index 3a71f8c..213e2bc 100644
--- a/src/Relation/Binary/Product/Pointwise.agda
+++ b/src/Relation/Binary/Product/Pointwise.agda
@@ -2,428 +2,11 @@
-- The Agda standard library
--
-- Pointwise products of binary relations
+--
+-- This module is DEPRECATED. Please use
+-- Data.Product.Relation.Pointwise.NonDependent directly.
------------------------------------------------------------------------
module Relation.Binary.Product.Pointwise where
-open import Data.Product as Prod
-open import Data.Sum
-open import Data.Unit.Base using (⊤)
-open import Function
-open import Function.Equality as F using (_⟶_; _⟨$⟩_)
-open import Function.Equivalence as Eq
- using (Equivalence; _⇔_; module Equivalence)
-open import Function.Injection as Inj
- using (Injection; _↣_; module Injection)
-open import Function.Inverse as Inv
- using (Inverse; _↔_; module Inverse)
-open import Function.LeftInverse as LeftInv
- using (LeftInverse; _↞_; _LeftInverseOf_; module LeftInverse)
-open import Function.Related
-open import Function.Surjection as Surj
- using (Surjection; _↠_; module Surjection)
-open import Level
-import Relation.Nullary.Decidable as Dec
-open import Relation.Nullary.Product
-open import Relation.Binary
-open import Relation.Binary.PropositionalEquality as P using (_≡_)
-
-module _ {a₁ a₂ ℓ₁ ℓ₂} {A₁ : Set a₁} {A₂ : Set a₂} where
-
- infixr 2 _×-Rel_
-
- _×-Rel_ : Rel A₁ ℓ₁ → Rel A₂ ℓ₂ → Rel (A₁ × A₂) _
- _∼₁_ ×-Rel _∼₂_ = (_∼₁_ on proj₁) -×- (_∼₂_ on proj₂)
-
- -- Some properties which are preserved by ×-Rel (under certain
- -- assumptions).
-
- _×-reflexive_ :
- ∀ {_≈₁_ _∼₁_ _≈₂_ _∼₂_} →
- _≈₁_ ⇒ _∼₁_ → _≈₂_ ⇒ _∼₂_ → (_≈₁_ ×-Rel _≈₂_) ⇒ (_∼₁_ ×-Rel _∼₂_)
- refl₁ ×-reflexive refl₂ = λ x≈y →
- (refl₁ (proj₁ x≈y) , refl₂ (proj₂ x≈y))
-
- _×-refl_ :
- ∀ {_∼₁_ _∼₂_} →
- Reflexive _∼₁_ → Reflexive _∼₂_ → Reflexive (_∼₁_ ×-Rel _∼₂_)
- refl₁ ×-refl refl₂ = (refl₁ , refl₂)
-
- ×-irreflexive₁ :
- ∀ {_≈₁_ _<₁_ _≈₂_ _<₂_} →
- Irreflexive _≈₁_ _<₁_ →
- Irreflexive (_≈₁_ ×-Rel _≈₂_) (_<₁_ ×-Rel _<₂_)
- ×-irreflexive₁ ir = λ x≈y x<y → ir (proj₁ x≈y) (proj₁ x<y)
-
- ×-irreflexive₂ :
- ∀ {_≈₁_ _<₁_ _≈₂_ _<₂_} →
- Irreflexive _≈₂_ _<₂_ →
- Irreflexive (_≈₁_ ×-Rel _≈₂_) (_<₁_ ×-Rel _<₂_)
- ×-irreflexive₂ ir = λ x≈y x<y → ir (proj₂ x≈y) (proj₂ x<y)
-
- _×-symmetric_ :
- ∀ {_∼₁_ _∼₂_} →
- Symmetric _∼₁_ → Symmetric _∼₂_ → Symmetric (_∼₁_ ×-Rel _∼₂_)
- sym₁ ×-symmetric sym₂ = λ x∼y → sym₁ (proj₁ x∼y) , sym₂ (proj₂ x∼y)
-
- _×-transitive_ : ∀ {_∼₁_ _∼₂_} →
- Transitive _∼₁_ → Transitive _∼₂_ →
- Transitive (_∼₁_ ×-Rel _∼₂_)
- trans₁ ×-transitive trans₂ = λ x∼y y∼z →
- trans₁ (proj₁ x∼y) (proj₁ y∼z) ,
- trans₂ (proj₂ x∼y) (proj₂ y∼z)
-
- _×-antisymmetric_ :
- ∀ {_≈₁_ _≤₁_ _≈₂_ _≤₂_} →
- Antisymmetric _≈₁_ _≤₁_ → Antisymmetric _≈₂_ _≤₂_ →
- Antisymmetric (_≈₁_ ×-Rel _≈₂_) (_≤₁_ ×-Rel _≤₂_)
- antisym₁ ×-antisymmetric antisym₂ = λ x≤y y≤x →
- ( antisym₁ (proj₁ x≤y) (proj₁ y≤x)
- , antisym₂ (proj₂ x≤y) (proj₂ y≤x) )
-
- ×-asymmetric₁ :
- ∀ {_<₁_ _∼₂_} → Asymmetric _<₁_ → Asymmetric (_<₁_ ×-Rel _∼₂_)
- ×-asymmetric₁ asym₁ = λ x<y y<x → asym₁ (proj₁ x<y) (proj₁ y<x)
-
- ×-asymmetric₂ :
- ∀ {_∼₁_ _<₂_} → Asymmetric _<₂_ → Asymmetric (_∼₁_ ×-Rel _<₂_)
- ×-asymmetric₂ asym₂ = λ x<y y<x → asym₂ (proj₂ x<y) (proj₂ y<x)
-
- _×-≈-respects₂_ : ∀ {_≈₁_ _∼₁_ _≈₂_ _∼₂_} →
- _∼₁_ Respects₂ _≈₁_ → _∼₂_ Respects₂ _≈₂_ →
- (_∼₁_ ×-Rel _∼₂_) Respects₂ (_≈₁_ ×-Rel _≈₂_)
- _×-≈-respects₂_
- {_≈₁_ = _≈₁_} {_∼₁_ = _∼₁_} {_≈₂_ = _≈₂_} {_∼₂_ = _∼₂_}
- resp₁ resp₂ =
- (λ {x y z} → resp¹ {x} {y} {z}) ,
- (λ {x y z} → resp² {x} {y} {z})
- where
- _∼_ = _∼₁_ ×-Rel _∼₂_
-
- resp¹ : ∀ {x} → (_∼_ x) Respects (_≈₁_ ×-Rel _≈₂_)
- resp¹ y≈y' x∼y = proj₁ resp₁ (proj₁ y≈y') (proj₁ x∼y) ,
- proj₁ resp₂ (proj₂ y≈y') (proj₂ x∼y)
-
- resp² : ∀ {y} → (flip _∼_ y) Respects (_≈₁_ ×-Rel _≈₂_)
- resp² x≈x' x∼y = proj₂ resp₁ (proj₁ x≈x') (proj₁ x∼y) ,
- proj₂ resp₂ (proj₂ x≈x') (proj₂ x∼y)
-
- ×-total :
- ∀ {_∼₁_ _∼₂_} →
- Symmetric _∼₁_ → Total _∼₁_ → Total _∼₂_ → Total (_∼₁_ ×-Rel _∼₂_)
- ×-total {_∼₁_ = _∼₁_} {_∼₂_ = _∼₂_} sym₁ total₁ total₂ = total
- where
- total : Total (_∼₁_ ×-Rel _∼₂_)
- total x y with total₁ (proj₁ x) (proj₁ y)
- | total₂ (proj₂ x) (proj₂ y)
- ... | inj₁ x₁∼y₁ | inj₁ x₂∼y₂ = inj₁ ( x₁∼y₁ , x₂∼y₂)
- ... | inj₁ x₁∼y₁ | inj₂ y₂∼x₂ = inj₂ (sym₁ x₁∼y₁ , y₂∼x₂)
- ... | inj₂ y₁∼x₁ | inj₂ y₂∼x₂ = inj₂ ( y₁∼x₁ , y₂∼x₂)
- ... | inj₂ y₁∼x₁ | inj₁ x₂∼y₂ = inj₁ (sym₁ y₁∼x₁ , x₂∼y₂)
-
- _×-decidable_ :
- ∀ {_∼₁_ _∼₂_} →
- Decidable _∼₁_ → Decidable _∼₂_ → Decidable (_∼₁_ ×-Rel _∼₂_)
- dec₁ ×-decidable dec₂ = λ x y →
- dec₁ (proj₁ x) (proj₁ y)
- ×-dec
- dec₂ (proj₂ x) (proj₂ y)
-
- -- Some collections of properties which are preserved by ×-Rel.
-
- _×-isEquivalence_ : ∀ {_≈₁_ _≈₂_} →
- IsEquivalence _≈₁_ → IsEquivalence _≈₂_ →
- IsEquivalence (_≈₁_ ×-Rel _≈₂_)
- _×-isEquivalence_ {_≈₁_ = _≈₁_} {_≈₂_ = _≈₂_} eq₁ eq₂ = record
- { refl = λ {x} →
- _×-refl_ {_∼₁_ = _≈₁_} {_∼₂_ = _≈₂_}
- (refl eq₁) (refl eq₂) {x}
- ; sym = λ {x y} →
- _×-symmetric_ {_∼₁_ = _≈₁_} {_∼₂_ = _≈₂_}
- (sym eq₁) (sym eq₂) {x} {y}
- ; trans = λ {x y z} →
- _×-transitive_ {_∼₁_ = _≈₁_} {_∼₂_ = _≈₂_}
- (trans eq₁) (trans eq₂) {x} {y} {z}
- }
- where open IsEquivalence
-
- _×-isPreorder_ : ∀ {_≈₁_ _∼₁_ _≈₂_ _∼₂_} →
- IsPreorder _≈₁_ _∼₁_ → IsPreorder _≈₂_ _∼₂_ →
- IsPreorder (_≈₁_ ×-Rel _≈₂_) (_∼₁_ ×-Rel _∼₂_)
- _×-isPreorder_ {_∼₁_ = _∼₁_} {_∼₂_ = _∼₂_} pre₁ pre₂ = record
- { isEquivalence = isEquivalence pre₁ ×-isEquivalence
- isEquivalence pre₂
- ; reflexive = λ {x y} →
- _×-reflexive_ {_∼₁_ = _∼₁_} {_∼₂_ = _∼₂_}
- (reflexive pre₁) (reflexive pre₂)
- {x} {y}
- ; trans = λ {x y z} →
- _×-transitive_ {_∼₁_ = _∼₁_} {_∼₂_ = _∼₂_}
- (trans pre₁) (trans pre₂)
- {x} {y} {z}
- }
- where open IsPreorder
-
- _×-isDecEquivalence_ :
- ∀ {_≈₁_ _≈₂_} →
- IsDecEquivalence _≈₁_ → IsDecEquivalence _≈₂_ →
- IsDecEquivalence (_≈₁_ ×-Rel _≈₂_)
- eq₁ ×-isDecEquivalence eq₂ = record
- { isEquivalence = isEquivalence eq₁ ×-isEquivalence
- isEquivalence eq₂
- ; _≟_ = _≟_ eq₁ ×-decidable _≟_ eq₂
- }
- where open IsDecEquivalence
-
- _×-isPartialOrder_ :
- ∀ {_≈₁_ _≤₁_ _≈₂_ _≤₂_} →
- IsPartialOrder _≈₁_ _≤₁_ → IsPartialOrder _≈₂_ _≤₂_ →
- IsPartialOrder (_≈₁_ ×-Rel _≈₂_) (_≤₁_ ×-Rel _≤₂_)
- _×-isPartialOrder_ {_≤₁_ = _≤₁_} {_≤₂_ = _≤₂_} po₁ po₂ = record
- { isPreorder = isPreorder po₁ ×-isPreorder isPreorder po₂
- ; antisym = λ {x y} →
- _×-antisymmetric_ {_≤₁_ = _≤₁_} {_≤₂_ = _≤₂_}
- (antisym po₁) (antisym po₂)
- {x} {y}
- }
- where open IsPartialOrder
-
- _×-isStrictPartialOrder_ :
- ∀ {_≈₁_ _<₁_ _≈₂_ _<₂_} →
- IsStrictPartialOrder _≈₁_ _<₁_ → IsStrictPartialOrder _≈₂_ _<₂_ →
- IsStrictPartialOrder (_≈₁_ ×-Rel _≈₂_) (_<₁_ ×-Rel _<₂_)
- _×-isStrictPartialOrder_ {_<₁_ = _<₁_} {_≈₂_ = _≈₂_} {_<₂_ = _<₂_}
- spo₁ spo₂ =
- record
- { isEquivalence = isEquivalence spo₁ ×-isEquivalence
- isEquivalence spo₂
- ; irrefl = λ {x y} →
- ×-irreflexive₁ {_<₁_ = _<₁_}
- {_≈₂_ = _≈₂_} {_<₂_ = _<₂_}
- (irrefl spo₁) {x} {y}
- ; trans = λ {x y z} →
- _×-transitive_ {_∼₁_ = _<₁_} {_∼₂_ = _<₂_}
- (trans spo₁) (trans spo₂)
- {x} {y} {z}
- ; <-resp-≈ = <-resp-≈ spo₁ ×-≈-respects₂ <-resp-≈ spo₂
- }
- where open IsStrictPartialOrder
-
--- "Packages" (e.g. setoids) can also be combined.
-
-_×-preorder_ :
- ∀ {p₁ p₂ p₃ p₄} →
- Preorder p₁ p₂ _ → Preorder p₃ p₄ _ → Preorder _ _ _
-p₁ ×-preorder p₂ = record
- { isPreorder = isPreorder p₁ ×-isPreorder isPreorder p₂
- } where open Preorder
-
-_×-setoid_ :
- ∀ {s₁ s₂ s₃ s₄} → Setoid s₁ s₂ → Setoid s₃ s₄ → Setoid _ _
-s₁ ×-setoid s₂ = record
- { isEquivalence = isEquivalence s₁ ×-isEquivalence isEquivalence s₂
- } where open Setoid
-
-_×-decSetoid_ :
- ∀ {d₁ d₂ d₃ d₄} → DecSetoid d₁ d₂ → DecSetoid d₃ d₄ → DecSetoid _ _
-s₁ ×-decSetoid s₂ = record
- { isDecEquivalence = isDecEquivalence s₁ ×-isDecEquivalence
- isDecEquivalence s₂
- } where open DecSetoid
-
-_×-poset_ :
- ∀ {p₁ p₂ p₃ p₄} → Poset p₁ p₂ _ → Poset p₃ p₄ _ → Poset _ _ _
-s₁ ×-poset s₂ = record
- { isPartialOrder = isPartialOrder s₁ ×-isPartialOrder
- isPartialOrder s₂
- } where open Poset
-
-_×-strictPartialOrder_ :
- ∀ {s₁ s₂ s₃ s₄} →
- StrictPartialOrder s₁ s₂ _ → StrictPartialOrder s₃ s₄ _ →
- StrictPartialOrder _ _ _
-s₁ ×-strictPartialOrder s₂ = record
- { isStrictPartialOrder = isStrictPartialOrder s₁
- ×-isStrictPartialOrder
- isStrictPartialOrder s₂
- } where open StrictPartialOrder
-
-------------------------------------------------------------------------
--- Some properties related to "relatedness"
-
-private
-
- to-cong : ∀ {a b} {A : Set a} {B : Set b} →
- (_≡_ ×-Rel _≡_) ⇒ _≡_ {A = A × B}
- to-cong {i = (x , y)} {j = (.x , .y)} (P.refl , P.refl) = P.refl
-
- from-cong : ∀ {a b} {A : Set a} {B : Set b} →
- _≡_ {A = A × B} ⇒ (_≡_ ×-Rel _≡_)
- from-cong P.refl = (P.refl , P.refl)
-
-×-Rel↔≡ : ∀ {a b} {A : Set a} {B : Set b} →
- Inverse (P.setoid A ×-setoid P.setoid B) (P.setoid (A × B))
-×-Rel↔≡ = record
- { to = record { _⟨$⟩_ = id; cong = to-cong }
- ; from = record { _⟨$⟩_ = id; cong = from-cong }
- ; inverse-of = record
- { left-inverse-of = λ _ → (P.refl , P.refl)
- ; right-inverse-of = λ _ → P.refl
- }
- }
-
-_×-≟_ : ∀ {a b} {A : Set a} {B : Set b} →
- Decidable {A = A} _≡_ → Decidable {A = B} _≡_ →
- Decidable {A = A × B} _≡_
-(dec₁ ×-≟ dec₂) p₁ p₂ = Dec.map′ to-cong from-cong (p₁ ≟ p₂)
- where
- open DecSetoid (P.decSetoid dec₁ ×-decSetoid P.decSetoid dec₂)
-
-_×-⟶_ :
- ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈}
- {A : Setoid s₁ s₂} {B : Setoid s₃ s₄}
- {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} →
- A ⟶ B → C ⟶ D → (A ×-setoid C) ⟶ (B ×-setoid D)
-_×-⟶_ {A = A} {B} {C} {D} f g = record
- { _⟨$⟩_ = fg
- ; cong = fg-cong
- }
- where
- open Setoid (A ×-setoid C) using () renaming (_≈_ to _≈AC_)
- open Setoid (B ×-setoid D) using () renaming (_≈_ to _≈BD_)
-
- fg = Prod.map (_⟨$⟩_ f) (_⟨$⟩_ g)
-
- fg-cong : _≈AC_ =[ fg ]⇒ _≈BD_
- fg-cong (_∼₁_ , _∼₂_) = (F.cong f _∼₁_ , F.cong g _∼₂_)
-
-_×-equivalence_ :
- ∀ {a₁ a₂ b₁ b₂ c₁ c₂ d₁ d₂}
- {A : Setoid a₁ a₂} {B : Setoid b₁ b₂}
- {C : Setoid c₁ c₂} {D : Setoid d₁ d₂} →
- Equivalence A B → Equivalence C D →
- Equivalence (A ×-setoid C) (B ×-setoid D)
-_×-equivalence_ {A = A} {B} {C} {D} A⇔B C⇔D = record
- { to = to A⇔B ×-⟶ to C⇔D
- ; from = from A⇔B ×-⟶ from C⇔D
- } where open Equivalence
-
-_×-⇔_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
- A ⇔ B → C ⇔ D → (A × C) ⇔ (B × D)
-_×-⇔_ {A = A} {B} {C} {D} A⇔B C⇔D =
- Inverse.equivalence (×-Rel↔≡ {A = B} {B = D}) ⟨∘⟩
- (A⇔B ×-equivalence C⇔D) ⟨∘⟩
- Eq.sym (Inverse.equivalence (×-Rel↔≡ {A = A} {B = C}))
- where open Eq using () renaming (_∘_ to _⟨∘⟩_)
-
-_×-injection_ :
- ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈}
- {A : Setoid s₁ s₂} {B : Setoid s₃ s₄}
- {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} →
- Injection A B → Injection C D →
- Injection (A ×-setoid C) (B ×-setoid D)
-A↣B ×-injection C↣D = record
- { to = to A↣B ×-⟶ to C↣D
- ; injective = Prod.map (injective A↣B) (injective C↣D)
- } where open Injection
-
-_×-↣_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
- A ↣ B → C ↣ D → (A × C) ↣ (B × D)
-_×-↣_ {A = A} {B} {C} {D} A↣B C↣D =
- Inverse.injection (×-Rel↔≡ {A = B} {B = D}) ⟨∘⟩
- (A↣B ×-injection C↣D) ⟨∘⟩
- Inverse.injection (Inv.sym (×-Rel↔≡ {A = A} {B = C}))
- where open Inj using () renaming (_∘_ to _⟨∘⟩_)
-
-_×-left-inverse_ :
- ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈}
- {A : Setoid s₁ s₂} {B : Setoid s₃ s₄}
- {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} →
- LeftInverse A B → LeftInverse C D →
- LeftInverse (A ×-setoid C) (B ×-setoid D)
-A↞B ×-left-inverse C↞D = record
- { to = Equivalence.to eq
- ; from = Equivalence.from eq
- ; left-inverse-of = left
- }
- where
- open LeftInverse
- eq = LeftInverse.equivalence A↞B ×-equivalence
- LeftInverse.equivalence C↞D
-
- left : Equivalence.from eq LeftInverseOf Equivalence.to eq
- left (x , y) = ( left-inverse-of A↞B x
- , left-inverse-of C↞D y
- )
-
-_×-↞_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
- A ↞ B → C ↞ D → (A × C) ↞ (B × D)
-_×-↞_ {A = A} {B} {C} {D} A↞B C↞D =
- Inverse.left-inverse (×-Rel↔≡ {A = B} {B = D}) ⟨∘⟩
- (A↞B ×-left-inverse C↞D) ⟨∘⟩
- Inverse.left-inverse (Inv.sym (×-Rel↔≡ {A = A} {B = C}))
- where open LeftInv using () renaming (_∘_ to _⟨∘⟩_)
-
-_×-surjection_ :
- ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈}
- {A : Setoid s₁ s₂} {B : Setoid s₃ s₄}
- {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} →
- Surjection A B → Surjection C D →
- Surjection (A ×-setoid C) (B ×-setoid D)
-A↠B ×-surjection C↠D = record
- { to = LeftInverse.from inv
- ; surjective = record
- { from = LeftInverse.to inv
- ; right-inverse-of = LeftInverse.left-inverse-of inv
- }
- }
- where
- open Surjection
- inv = right-inverse A↠B ×-left-inverse right-inverse C↠D
-
-_×-↠_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
- A ↠ B → C ↠ D → (A × C) ↠ (B × D)
-_×-↠_ {A = A} {B} {C} {D} A↠B C↠D =
- Inverse.surjection (×-Rel↔≡ {A = B} {B = D}) ⟨∘⟩
- (A↠B ×-surjection C↠D) ⟨∘⟩
- Inverse.surjection (Inv.sym (×-Rel↔≡ {A = A} {B = C}))
- where open Surj using () renaming (_∘_ to _⟨∘⟩_)
-
-_×-inverse_ :
- ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈}
- {A : Setoid s₁ s₂} {B : Setoid s₃ s₄}
- {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} →
- Inverse A B → Inverse C D → Inverse (A ×-setoid C) (B ×-setoid D)
-A↔B ×-inverse C↔D = record
- { to = Surjection.to surj
- ; from = Surjection.from surj
- ; inverse-of = record
- { left-inverse-of = LeftInverse.left-inverse-of inv
- ; right-inverse-of = Surjection.right-inverse-of surj
- }
- }
- where
- open Inverse
- surj = Inverse.surjection A↔B ×-surjection
- Inverse.surjection C↔D
- inv = Inverse.left-inverse A↔B ×-left-inverse
- Inverse.left-inverse C↔D
-
-_×-↔_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
- A ↔ B → C ↔ D → (A × C) ↔ (B × D)
-_×-↔_ {A = A} {B} {C} {D} A↔B C↔D =
- ×-Rel↔≡ {A = B} {B = D} ⟨∘⟩
- (A↔B ×-inverse C↔D) ⟨∘⟩
- Inv.sym (×-Rel↔≡ {A = A} {B = C})
- where open Inv using () renaming (_∘_ to _⟨∘⟩_)
-
-_×-cong_ : ∀ {k a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
- A ∼[ k ] B → C ∼[ k ] D → (A × C) ∼[ k ] (B × D)
-_×-cong_ {implication} = λ f g → Prod.map f g
-_×-cong_ {reverse-implication} = λ f g → lam (Prod.map (app-← f) (app-← g))
-_×-cong_ {equivalence} = _×-⇔_
-_×-cong_ {injection} = _×-↣_
-_×-cong_ {reverse-injection} = λ f g → lam (app-↢ f ×-↣ app-↢ g)
-_×-cong_ {left-inverse} = _×-↞_
-_×-cong_ {surjection} = _×-↠_
-_×-cong_ {bijection} = _×-↔_
+open import Data.Product.Relation.Pointwise.NonDependent public
diff --git a/src/Relation/Binary/Product/StrictLex.agda b/src/Relation/Binary/Product/StrictLex.agda
index 915c224..416accc 100644
--- a/src/Relation/Binary/Product/StrictLex.agda
+++ b/src/Relation/Binary/Product/StrictLex.agda
@@ -2,6 +2,9 @@
-- The Agda standard library
--
-- Lexicographic products of binary relations
+--
+-- This module is DEPRECATED. Please use
+-- Data.Product.Relation.Lex.Strict directly.
------------------------------------------------------------------------
-- The definition of lexicographic product used here is suitable if
@@ -9,265 +12,4 @@
module Relation.Binary.Product.StrictLex where
-open import Function
-open import Data.Product
-open import Data.Sum
-open import Data.Empty
-open import Level
-open import Relation.Nullary.Product
-open import Relation.Nullary.Sum
-open import Relation.Binary
-open import Relation.Binary.Consequences
-open import Relation.Binary.Product.Pointwise as Pointwise
- using (_×-Rel_)
-open import Relation.Nullary
-
-module _ {a₁ a₂ ℓ₁ ℓ₂} {A₁ : Set a₁} {A₂ : Set a₂} where
-
- ×-Lex : (_≈₁_ _<₁_ : Rel A₁ ℓ₁) → (_≤₂_ : Rel A₂ ℓ₂) → Rel (A₁ × A₂) _
- ×-Lex _≈₁_ _<₁_ _≤₂_ =
- (_<₁_ on proj₁) -⊎- (_≈₁_ on proj₁) -×- (_≤₂_ on proj₂)
-
- -- Some properties which are preserved by ×-Lex (under certain
- -- assumptions).
-
- ×-reflexive : ∀ _≈₁_ _∼₁_ {_≈₂_ : Rel A₂ ℓ₂} _≤₂_ →
- _≈₂_ ⇒ _≤₂_ → (_≈₁_ ×-Rel _≈₂_) ⇒ (×-Lex _≈₁_ _∼₁_ _≤₂_)
- ×-reflexive _ _ _ refl₂ = λ x≈y →
- inj₂ (proj₁ x≈y , refl₂ (proj₂ x≈y))
-
- _×-irreflexive_ : ∀ {_≈₁_ _<₁_} → Irreflexive _≈₁_ _<₁_ →
- ∀ {_≈₂_ _<₂_ : Rel A₂ ℓ₂} → Irreflexive _≈₂_ _<₂_ →
- Irreflexive (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _<₁_ _<₂_)
- (ir₁ ×-irreflexive ir₂) x≈y (inj₁ x₁<y₁) = ir₁ (proj₁ x≈y) x₁<y₁
- (ir₁ ×-irreflexive ir₂) x≈y (inj₂ x≈<y) =
- ir₂ (proj₂ x≈y) (proj₂ x≈<y)
-
- ×-transitive :
- ∀ {_≈₁_ _<₁_} →
- IsEquivalence _≈₁_ → _<₁_ Respects₂ _≈₁_ → Transitive _<₁_ →
- ∀ {_≤₂_} →
- Transitive _≤₂_ →
- Transitive (×-Lex _≈₁_ _<₁_ _≤₂_)
- ×-transitive {_≈₁_} {_<₁_} eq₁ resp₁ trans₁
- {_≤₂_} trans₂ = trans
- where
- module Eq₁ = IsEquivalence eq₁
-
- trans : Transitive (×-Lex _≈₁_ _<₁_ _≤₂_)
- trans (inj₁ x₁<y₁) (inj₁ y₁<z₁) = inj₁ (trans₁ x₁<y₁ y₁<z₁)
- trans (inj₁ x₁<y₁) (inj₂ y≈≤z) =
- inj₁ (proj₁ resp₁ (proj₁ y≈≤z) x₁<y₁)
- trans (inj₂ x≈≤y) (inj₁ y₁<z₁) =
- inj₁ (proj₂ resp₁ (Eq₁.sym $ proj₁ x≈≤y) y₁<z₁)
- trans (inj₂ x≈≤y) (inj₂ y≈≤z) =
- inj₂ ( Eq₁.trans (proj₁ x≈≤y) (proj₁ y≈≤z)
- , trans₂ (proj₂ x≈≤y) (proj₂ y≈≤z) )
-
- ×-antisymmetric :
- ∀ {_≈₁_ _<₁_} →
- Symmetric _≈₁_ → Irreflexive _≈₁_ _<₁_ → Asymmetric _<₁_ →
- ∀ {_≈₂_ _≤₂_ : Rel A₂ ℓ₂} →
- Antisymmetric _≈₂_ _≤₂_ →
- Antisymmetric (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _<₁_ _≤₂_)
- ×-antisymmetric {_≈₁_} {_<₁_} sym₁ irrefl₁ asym₁
- {_≈₂_} {_≤₂_} antisym₂ = antisym
- where
- antisym : Antisymmetric (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _<₁_ _≤₂_)
- antisym (inj₁ x₁<y₁) (inj₁ y₁<x₁) =
- ⊥-elim $ asym₁ x₁<y₁ y₁<x₁
- antisym (inj₁ x₁<y₁) (inj₂ y≈≤x) =
- ⊥-elim $ irrefl₁ (sym₁ $ proj₁ y≈≤x) x₁<y₁
- antisym (inj₂ x≈≤y) (inj₁ y₁<x₁) =
- ⊥-elim $ irrefl₁ (sym₁ $ proj₁ x≈≤y) y₁<x₁
- antisym (inj₂ x≈≤y) (inj₂ y≈≤x) =
- proj₁ x≈≤y , antisym₂ (proj₂ x≈≤y) (proj₂ y≈≤x)
-
- ×-asymmetric :
- ∀ {_≈₁_ _<₁_} →
- Symmetric _≈₁_ → _<₁_ Respects₂ _≈₁_ → Asymmetric _<₁_ →
- ∀ {_<₂_} →
- Asymmetric _<₂_ →
- Asymmetric (×-Lex _≈₁_ _<₁_ _<₂_)
- ×-asymmetric {_≈₁_} {_<₁_} sym₁ resp₁ asym₁
- {_<₂_} asym₂ = asym
- where
- irrefl₁ : Irreflexive _≈₁_ _<₁_
- irrefl₁ = asym⟶irr resp₁ sym₁ asym₁
-
- asym : Asymmetric (×-Lex _≈₁_ _<₁_ _<₂_)
- asym (inj₁ x₁<y₁) (inj₁ y₁<x₁) = asym₁ x₁<y₁ y₁<x₁
- asym (inj₁ x₁<y₁) (inj₂ y≈<x) = irrefl₁ (sym₁ $ proj₁ y≈<x) x₁<y₁
- asym (inj₂ x≈<y) (inj₁ y₁<x₁) = irrefl₁ (sym₁ $ proj₁ x≈<y) y₁<x₁
- asym (inj₂ x≈<y) (inj₂ y≈<x) = asym₂ (proj₂ x≈<y) (proj₂ y≈<x)
-
- ×-≈-respects₂ :
- ∀ {_≈₁_ _<₁_} → IsEquivalence _≈₁_ → _<₁_ Respects₂ _≈₁_ →
- {_≈₂_ _<₂_ : Rel A₂ ℓ₂} → _<₂_ Respects₂ _≈₂_ →
- (×-Lex _≈₁_ _<₁_ _<₂_) Respects₂ (_≈₁_ ×-Rel _≈₂_)
- ×-≈-respects₂ {_≈₁_} {_<₁_} eq₁ resp₁
- {_≈₂_} {_<₂_} resp₂ = resp¹ , resp²
- where
- _<_ = ×-Lex _≈₁_ _<₁_ _<₂_
-
- open IsEquivalence eq₁ renaming (sym to sym₁; trans to trans₁)
-
- resp¹ : ∀ {x} → (x <_) Respects (_≈₁_ ×-Rel _≈₂_)
- resp¹ y≈y' (inj₁ x₁<y₁) = inj₁ (proj₁ resp₁ (proj₁ y≈y') x₁<y₁)
- resp¹ y≈y' (inj₂ x≈<y) =
- inj₂ ( trans₁ (proj₁ x≈<y) (proj₁ y≈y')
- , proj₁ resp₂ (proj₂ y≈y') (proj₂ x≈<y) )
-
- resp² : ∀ {y} → (flip _<_ y) Respects (_≈₁_ ×-Rel _≈₂_)
- resp² x≈x' (inj₁ x₁<y₁) = inj₁ (proj₂ resp₁ (proj₁ x≈x') x₁<y₁)
- resp² x≈x' (inj₂ x≈<y) =
- inj₂ ( trans₁ (sym₁ $ proj₁ x≈x') (proj₁ x≈<y)
- , proj₂ resp₂ (proj₂ x≈x') (proj₂ x≈<y) )
-
- ×-decidable : ∀ {_≈₁_ _<₁_} → Decidable _≈₁_ → Decidable _<₁_ →
- ∀ {_≤₂_} → Decidable _≤₂_ →
- Decidable (×-Lex _≈₁_ _<₁_ _≤₂_)
- ×-decidable dec-≈₁ dec-<₁ dec-≤₂ x y =
- dec-<₁ (proj₁ x) (proj₁ y)
- ⊎-dec
- (dec-≈₁ (proj₁ x) (proj₁ y)
- ×-dec
- dec-≤₂ (proj₂ x) (proj₂ y))
-
- ×-total₁ : ∀ {_≈₁_ _<₁_} → Total _<₁_ →
- ∀ {_≤₂_} → Total (×-Lex _≈₁_ _<₁_ _≤₂_)
- ×-total₁ total₁ x y with total₁ (proj₁ x) (proj₁ y)
- ... | inj₁ x₁<y₁ = inj₁ (inj₁ x₁<y₁)
- ... | inj₂ x₁>y₁ = inj₂ (inj₁ x₁>y₁)
-
- ×-total₂ : ∀ {_≈₁_ _<₁_} → Symmetric _≈₁_ → Trichotomous _≈₁_ _<₁_ →
- ∀ {_≤₂_} → Total _≤₂_ →
- Total (×-Lex _≈₁_ _<₁_ _≤₂_)
- ×-total₂ sym tri₁ total₂ x y with tri₁ (proj₁ x) (proj₁ y)
- ... | tri< x₁<y₁ _ _ = inj₁ (inj₁ x₁<y₁)
- ... | tri> _ _ y₁<x₁ = inj₂ (inj₁ y₁<x₁)
- ... | tri≈ _ x₁≈y₁ _ with total₂ (proj₂ x) (proj₂ y)
- ... | inj₁ x₂≤y₂ = inj₁ (inj₂ (x₁≈y₁ , x₂≤y₂))
- ... | inj₂ y₂≤x₂ = inj₂ (inj₂ (sym x₁≈y₁ , y₂≤x₂))
-
- ×-compare :
- {_≈₁_ _<₁_ : Rel A₁ ℓ₁} → Symmetric _≈₁_ → Trichotomous _≈₁_ _<₁_ →
- {_≈₂_ _<₂_ : Rel A₂ ℓ₂} → Trichotomous _≈₂_ _<₂_ →
- Trichotomous (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _<₁_ _<₂_)
- ×-compare {_≈₁_} {_<₁_} sym₁ compare₁ {_≈₂_} {_<₂_} compare₂ = cmp
- where
- cmp″ : ∀ {x₁ y₁ x₂ y₂} →
- ¬ (x₁ <₁ y₁) → x₁ ≈₁ y₁ → ¬ (y₁ <₁ x₁) →
- Tri (x₂ <₂ y₂) (x₂ ≈₂ y₂) (y₂ <₂ x₂) →
- Tri (×-Lex _≈₁_ _<₁_ _<₂_ (x₁ , x₂) (y₁ , y₂))
- ((_≈₁_ ×-Rel _≈₂_) (x₁ , x₂) (y₁ , y₂))
- (×-Lex _≈₁_ _<₁_ _<₂_ (y₁ , y₂) (x₁ , x₂))
- cmp″ x₁≮y₁ x₁≈y₁ x₁≯y₁ (tri< x₂<y₂ x₂≉y₂ x₂≯y₂) =
- tri< (inj₂ (x₁≈y₁ , x₂<y₂))
- (x₂≉y₂ ∘ proj₂)
- [ x₁≯y₁ , x₂≯y₂ ∘ proj₂ ]
- cmp″ x₁≮y₁ x₁≈y₁ x₁≯y₁ (tri> x₂≮y₂ x₂≉y₂ x₂>y₂) =
- tri> [ x₁≮y₁ , x₂≮y₂ ∘ proj₂ ]
- (x₂≉y₂ ∘ proj₂)
- (inj₂ (sym₁ x₁≈y₁ , x₂>y₂))
- cmp″ x₁≮y₁ x₁≈y₁ x₁≯y₁ (tri≈ x₂≮y₂ x₂≈y₂ x₂≯y₂) =
- tri≈ [ x₁≮y₁ , x₂≮y₂ ∘ proj₂ ]
- (x₁≈y₁ , x₂≈y₂)
- [ x₁≯y₁ , x₂≯y₂ ∘ proj₂ ]
-
- cmp′ : ∀ {x₁ y₁} → Tri (x₁ <₁ y₁) (x₁ ≈₁ y₁) (y₁ <₁ x₁) →
- ∀ x₂ y₂ →
- Tri (×-Lex _≈₁_ _<₁_ _<₂_ (x₁ , x₂) (y₁ , y₂))
- ((_≈₁_ ×-Rel _≈₂_) (x₁ , x₂) (y₁ , y₂))
- (×-Lex _≈₁_ _<₁_ _<₂_ (y₁ , y₂) (x₁ , x₂))
- cmp′ (tri< x₁<y₁ x₁≉y₁ x₁≯y₁) x₂ y₂ =
- tri< (inj₁ x₁<y₁) (x₁≉y₁ ∘ proj₁) [ x₁≯y₁ , x₁≉y₁ ∘ sym₁ ∘ proj₁ ]
- cmp′ (tri> x₁≮y₁ x₁≉y₁ x₁>y₁) x₂ y₂ =
- tri> [ x₁≮y₁ , x₁≉y₁ ∘ proj₁ ] (x₁≉y₁ ∘ proj₁) (inj₁ x₁>y₁)
- cmp′ (tri≈ x₁≮y₁ x₁≈y₁ x₁≯y₁) x₂ y₂ =
- cmp″ x₁≮y₁ x₁≈y₁ x₁≯y₁ (compare₂ x₂ y₂)
-
- cmp : Trichotomous (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _<₁_ _<₂_)
- cmp (x₁ , x₂) (y₁ , y₂) = cmp′ (compare₁ x₁ y₁) x₂ y₂
-
- -- Some collections of properties which are preserved by ×-Lex.
-
- _×-isPreorder_ : ∀ {_≈₁_ _∼₁_} → IsPreorder _≈₁_ _∼₁_ →
- ∀ {_≈₂_ _∼₂_} → IsPreorder _≈₂_ _∼₂_ →
- IsPreorder (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _∼₁_ _∼₂_)
- _×-isPreorder_ {_≈₁_} {_∼₁_} pre₁ {_∼₂_ = _∼₂_} pre₂ =
- record
- { isEquivalence = Pointwise._×-isEquivalence_
- (isEquivalence pre₁) (isEquivalence pre₂)
- ; reflexive = ×-reflexive _≈₁_ _∼₁_ _∼₂_ (reflexive pre₂)
- ; trans = ×-transitive
- (isEquivalence pre₁) (∼-resp-≈ pre₁)
- (trans pre₁) {_≤₂_ = _∼₂_} (trans pre₂)
- }
- where open IsPreorder
-
- _×-isStrictPartialOrder_ :
- ∀ {_≈₁_ _<₁_} → IsStrictPartialOrder _≈₁_ _<₁_ →
- ∀ {_≈₂_ _<₂_} → IsStrictPartialOrder _≈₂_ _<₂_ →
- IsStrictPartialOrder (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _<₁_ _<₂_)
- _×-isStrictPartialOrder_ {_<₁_ = _<₁_} spo₁ {_<₂_ = _<₂_} spo₂ =
- record
- { isEquivalence = Pointwise._×-isEquivalence_
- (isEquivalence spo₁) (isEquivalence spo₂)
- ; irrefl = _×-irreflexive_ {_<₁_ = _<₁_} (irrefl spo₁)
- {_<₂_ = _<₂_} (irrefl spo₂)
- ; trans = ×-transitive
- {_<₁_ = _<₁_} (isEquivalence spo₁)
- (<-resp-≈ spo₁) (trans spo₁)
- {_≤₂_ = _<₂_} (trans spo₂)
- ; <-resp-≈ = ×-≈-respects₂ (isEquivalence spo₁)
- (<-resp-≈ spo₁)
- (<-resp-≈ spo₂)
- }
- where open IsStrictPartialOrder
-
- _×-isStrictTotalOrder_ :
- ∀ {_≈₁_ _<₁_} → IsStrictTotalOrder _≈₁_ _<₁_ →
- ∀ {_≈₂_ _<₂_} → IsStrictTotalOrder _≈₂_ _<₂_ →
- IsStrictTotalOrder (_≈₁_ ×-Rel _≈₂_) (×-Lex _≈₁_ _<₁_ _<₂_)
- _×-isStrictTotalOrder_ {_<₁_ = _<₁_} spo₁ {_<₂_ = _<₂_} spo₂ =
- record
- { isEquivalence = Pointwise._×-isEquivalence_
- (isEquivalence spo₁) (isEquivalence spo₂)
- ; trans = ×-transitive
- {_<₁_ = _<₁_} (isEquivalence spo₁)
- (<-resp-≈ spo₁) (trans spo₁)
- {_≤₂_ = _<₂_} (trans spo₂)
- ; compare = ×-compare (Eq.sym spo₁) (compare spo₁)
- (compare spo₂)
- }
- where open IsStrictTotalOrder
-
--- "Packages" (e.g. preorders) can also be combined.
-
-_×-preorder_ :
- ∀ {p₁ p₂ p₃ p₄} →
- Preorder p₁ p₂ _ → Preorder p₃ p₄ _ → Preorder _ _ _
-p₁ ×-preorder p₂ = record
- { isPreorder = isPreorder p₁ ×-isPreorder isPreorder p₂
- } where open Preorder
-
-_×-strictPartialOrder_ :
- ∀ {s₁ s₂ s₃ s₄} →
- StrictPartialOrder s₁ s₂ _ → StrictPartialOrder s₃ s₄ _ →
- StrictPartialOrder _ _ _
-s₁ ×-strictPartialOrder s₂ = record
- { isStrictPartialOrder = isStrictPartialOrder s₁
- ×-isStrictPartialOrder
- isStrictPartialOrder s₂
- } where open StrictPartialOrder
-
-_×-strictTotalOrder_ :
- ∀ {s₁ s₂ s₃ s₄} →
- StrictTotalOrder s₁ s₂ _ → StrictTotalOrder s₃ s₄ _ →
- StrictTotalOrder _ _ _
-s₁ ×-strictTotalOrder s₂ = record
- { isStrictTotalOrder = isStrictTotalOrder s₁
- ×-isStrictTotalOrder
- isStrictTotalOrder s₂
- } where open StrictTotalOrder
+open import Data.Product.Relation.Lex.Strict public
diff --git a/src/Relation/Binary/Properties/DecTotalOrder.agda b/src/Relation/Binary/Properties/DecTotalOrder.agda
index 5b25739..baae088 100644
--- a/src/Relation/Binary/Properties/DecTotalOrder.agda
+++ b/src/Relation/Binary/Properties/DecTotalOrder.agda
@@ -10,16 +10,11 @@ module Relation.Binary.Properties.DecTotalOrder
{d₁ d₂ d₃} (DT : DecTotalOrder d₁ d₂ d₃) where
open Relation.Binary.DecTotalOrder DT hiding (trans)
-import Relation.Binary.NonStrictToStrict as Conv
-open Conv _≈_ _≤_
+open import Relation.Binary.Construct.NonStrictToStrict _≈_ _≤_
strictTotalOrder : StrictTotalOrder _ _ _
strictTotalOrder = record
- { isStrictTotalOrder = record
- { isEquivalence = isEquivalence
- ; trans = trans isPartialOrder
- ; compare = trichotomous Eq.sym _≟_ antisym total
- }
+ { isStrictTotalOrder = <-isStrictTotalOrder₂ isDecTotalOrder
}
open StrictTotalOrder strictTotalOrder public
diff --git a/src/Relation/Binary/Properties/DistributiveLattice.agda b/src/Relation/Binary/Properties/DistributiveLattice.agda
new file mode 100644
index 0000000..e74477e
--- /dev/null
+++ b/src/Relation/Binary/Properties/DistributiveLattice.agda
@@ -0,0 +1,56 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Properties for distributive lattice
+------------------------------------------------------------------------
+
+open import Relation.Binary.Lattice
+
+module Relation.Binary.Properties.DistributiveLattice
+ {c ℓ₁ ℓ₂} (L : DistributiveLattice c ℓ₁ ℓ₂) where
+
+open import Data.Product using (_,_)
+open import Relation.Binary
+open import Relation.Binary.SetoidReasoning
+
+open DistributiveLattice L hiding (refl)
+open import Algebra.FunctionProperties _≈_
+open import Relation.Binary.Properties.Lattice lattice
+open import Relation.Binary.Properties.MeetSemilattice meetSemilattice
+open import Relation.Binary.Properties.JoinSemilattice joinSemilattice
+
+private
+ ≈-setoid : Setoid _ _
+ ≈-setoid = record { isEquivalence = isEquivalence }
+
+open Setoid ≈-setoid
+
+∧-distribʳ-∨ : _∧_ DistributesOverʳ _∨_
+∧-distribʳ-∨ x y z = begin⟨ ≈-setoid ⟩
+ (y ∨ z) ∧ x ≈⟨ ∧-comm _ _ ⟩
+ x ∧ (y ∨ z) ≈⟨ ∧-distribˡ-∨ x y z ⟩
+ x ∧ y ∨ x ∧ z ≈⟨ ∨-cong (∧-comm _ _) (∧-comm _ _) ⟩
+ y ∧ x ∨ z ∧ x ∎
+
+∧-distrib-∨ : _∧_ DistributesOver _∨_
+∧-distrib-∨ = ∧-distribˡ-∨ , ∧-distribʳ-∨
+
+∨-distribˡ-∧ : _∨_ DistributesOverˡ _∧_
+∨-distribˡ-∧ x y z = begin⟨ ≈-setoid ⟩
+ x ∨ y ∧ z ≈⟨ ∨-cong (sym (∨-absorbs-∧ x y)) refl ⟩
+ (x ∨ x ∧ y) ∨ y ∧ z ≈⟨ ∨-cong (∨-cong refl (∧-comm _ _)) refl ⟩
+ (x ∨ y ∧ x) ∨ y ∧ z ≈⟨ ∨-assoc x (y ∧ x) (y ∧ z) ⟩
+ x ∨ y ∧ x ∨ y ∧ z ≈⟨ ∨-cong refl (sym (∧-distribˡ-∨ y x z)) ⟩
+ x ∨ y ∧ (x ∨ z) ≈⟨ ∨-cong (sym (∧-absorbs-∨ _ _)) refl ⟩
+ x ∧ (x ∨ z) ∨ y ∧ (x ∨ z) ≈⟨ sym (∧-distribʳ-∨ (x ∨ z) x y) ⟩
+ (x ∨ y) ∧ (x ∨ z) ∎
+
+∨-distribʳ-∧ : _∨_ DistributesOverʳ _∧_
+∨-distribʳ-∧ x y z = begin⟨ ≈-setoid ⟩
+ y ∧ z ∨ x ≈⟨ ∨-comm _ _ ⟩
+ x ∨ y ∧ z ≈⟨ ∨-distribˡ-∧ _ _ _ ⟩
+ (x ∨ y) ∧ (x ∨ z) ≈⟨ ∧-cong (∨-comm _ _) (∨-comm _ _) ⟩
+ (y ∨ x) ∧ (z ∨ x) ∎
+
+∨-distrib-∧ : _∨_ DistributesOver _∧_
+∨-distrib-∧ = ∨-distribˡ-∧ , ∨-distribʳ-∧
diff --git a/src/Relation/Binary/Properties/HeytingAlgebra.agda b/src/Relation/Binary/Properties/HeytingAlgebra.agda
new file mode 100644
index 0000000..5ff1908
--- /dev/null
+++ b/src/Relation/Binary/Properties/HeytingAlgebra.agda
@@ -0,0 +1,99 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Properties satisfied by Heyting Algebra
+------------------------------------------------------------------------
+
+open import Relation.Binary.Lattice
+
+module Relation.Binary.Properties.HeytingAlgebra
+ {c ℓ₁ ℓ₂} (L : HeytingAlgebra c ℓ₁ ℓ₂) where
+
+open import Data.Product using (_,_)
+open import Level using (_⊔_)
+open import Relation.Binary
+open import Function using (_$_)
+
+open HeytingAlgebra L
+open import Algebra.FunctionProperties _≈_
+open import Relation.Binary.PartialOrderReasoning poset
+open import Relation.Binary.Properties.MeetSemilattice meetSemilattice
+open import Relation.Binary.Properties.JoinSemilattice joinSemilattice
+open import Relation.Binary.Properties.Lattice lattice
+
+open IsEquivalence isEquivalence using ()
+ renaming (sym to ≈-sym; refl to ≈-refl)
+
+------------------------------------------------------------------------
+-- Useful lemmas
+
+⇨-eval : ∀ {x y} → (x ⇨ y) ∧ x ≤ y
+⇨-eval {x} {y} = transpose-∧ refl
+
+swap-transpose-⇨ : ∀ {x y w} → x ∧ w ≤ y → w ≤ x ⇨ y
+swap-transpose-⇨ x∧w≤y = transpose-⇨ $ trans (reflexive $ ∧-comm _ _) x∧w≤y
+
+------------------------------------------------------------------------
+-- Various proofs of distributivity
+
+∧-distribˡ-∨-≤ : ∀ x y z → x ∧ (y ∨ z) ≤ x ∧ y ∨ x ∧ z
+∧-distribˡ-∨-≤ x y z = trans (reflexive $ ∧-comm _ _)
+ (transpose-∧ $ ∨-least (swap-transpose-⇨ (x≤x∨y _ _)) $ swap-transpose-⇨ (y≤x∨y _ _))
+
+∧-distribˡ-∨-≥ : ∀ x y z → x ∧ y ∨ x ∧ z ≤ x ∧ (y ∨ z)
+∧-distribˡ-∨-≥ x y z = let
+ x∧y≤x , x∧y≤y , _ = infimum x y
+ x∧z≤x , x∧z≤z , _ = infimum x z
+ y≤y∨z , z≤y∨z , _ = supremum y z
+ in ∧-greatest (∨-least x∧y≤x x∧z≤x)
+ (∨-least (trans x∧y≤y y≤y∨z) (trans x∧z≤z z≤y∨z))
+
+∧-distribˡ-∨ : _∧_ DistributesOverˡ _∨_
+∧-distribˡ-∨ x y z = antisym (∧-distribˡ-∨-≤ x y z) (∧-distribˡ-∨-≥ x y z)
+
+⇨-distribˡ-∧-≤ : ∀ x y z → x ⇨ y ∧ z ≤ (x ⇨ y) ∧ (x ⇨ z)
+⇨-distribˡ-∧-≤ x y z = let
+ y∧z≤y , y∧z≤z , _ = infimum y z
+ in ∧-greatest (transpose-⇨ $ trans ⇨-eval y∧z≤y)
+ (transpose-⇨ $ trans ⇨-eval y∧z≤z)
+
+⇨-distribˡ-∧-≥ : ∀ x y z → (x ⇨ y) ∧ (x ⇨ z) ≤ x ⇨ y ∧ z
+⇨-distribˡ-∧-≥ x y z = transpose-⇨ (begin
+ (((x ⇨ y) ∧ (x ⇨ z)) ∧ x) ≈⟨ ∧-cong ≈-refl $ ≈-sym $ ∧-idempotent _ ⟩
+ (((x ⇨ y) ∧ (x ⇨ z)) ∧ x ∧ x) ≈⟨ ≈-sym $ ∧-assoc _ _ _ ⟩
+ (((x ⇨ y) ∧ (x ⇨ z)) ∧ x) ∧ x ≈⟨ ∧-cong (∧-assoc _ _ _) ≈-refl ⟩
+ (((x ⇨ y) ∧ (x ⇨ z) ∧ x) ∧ x) ≈⟨ ∧-cong (∧-cong ≈-refl $ ∧-comm _ _) ≈-refl ⟩
+ (((x ⇨ y) ∧ x ∧ (x ⇨ z)) ∧ x) ≈⟨ ∧-cong (≈-sym $ ∧-assoc _ _ _) ≈-refl ⟩
+ (((x ⇨ y) ∧ x) ∧ (x ⇨ z)) ∧ x ≈⟨ ∧-assoc _ _ _ ⟩
+ (((x ⇨ y) ∧ x) ∧ (x ⇨ z) ∧ x) ≤⟨ ∧-monotonic ⇨-eval ⇨-eval ⟩
+ y ∧ z ∎)
+
+⇨-distribˡ-∧ : _⇨_ DistributesOverˡ _∧_
+⇨-distribˡ-∧ x y z = antisym (⇨-distribˡ-∧-≤ x y z) (⇨-distribˡ-∧-≥ x y z)
+
+⇨-distribˡ-∨-∧-≤ : ∀ x y z → x ∨ y ⇨ z ≤ (x ⇨ z) ∧ (y ⇨ z)
+⇨-distribˡ-∨-∧-≤ x y z = let x≤x∨y , y≤x∨y , _ = supremum x y
+ in ∧-greatest (transpose-⇨ $ trans (∧-monotonic refl x≤x∨y) ⇨-eval)
+ (transpose-⇨ $ trans (∧-monotonic refl y≤x∨y) ⇨-eval)
+
+⇨-distribˡ-∨-∧-≥ : ∀ x y z → (x ⇨ z) ∧ (y ⇨ z) ≤ x ∨ y ⇨ z
+⇨-distribˡ-∨-∧-≥ x y z = transpose-⇨ (trans (reflexive $ ∧-distribˡ-∨ _ _ _)
+ (∨-least (trans (transpose-∧ (x∧y≤x _ _)) refl)
+ (trans (transpose-∧ (x∧y≤y _ _)) refl)))
+
+⇨-distribˡ-∨-∧ : ∀ x y z → x ∨ y ⇨ z ≈ (x ⇨ z) ∧ (y ⇨ z)
+⇨-distribˡ-∨-∧ x y z = antisym (⇨-distribˡ-∨-∧-≤ x y z) (⇨-distribˡ-∨-∧-≥ x y z)
+
+------------------------------------------------------------------------
+-- Heyting algebras are distributive lattices
+
+isDistributiveLattice : IsDistributiveLattice _≈_ _≤_ _∨_ _∧_
+isDistributiveLattice = record
+ { isLattice = isLattice
+ ; ∧-distribˡ-∨ = ∧-distribˡ-∨
+ }
+
+distributiveLattice : DistributiveLattice _ _ _
+distributiveLattice = record
+ { isDistributiveLattice = isDistributiveLattice
+ }
diff --git a/src/Relation/Binary/Properties/Poset.agda b/src/Relation/Binary/Properties/Poset.agda
index 724fc93..c69d41c 100644
--- a/src/Relation/Binary/Properties/Poset.agda
+++ b/src/Relation/Binary/Properties/Poset.agda
@@ -10,8 +10,7 @@ module Relation.Binary.Properties.Poset
{p₁ p₂ p₃} (P : Poset p₁ p₂ p₃) where
open Relation.Binary.Poset P hiding (trans)
-import Relation.Binary.NonStrictToStrict as Conv
-open Conv _≈_ _≤_
+open import Relation.Binary.Construct.NonStrictToStrict _≈_ _≤_
open import Relation.Binary.Properties.Preorder preorder
open import Function using (flip)
@@ -31,12 +30,7 @@ invPoset = record { isPartialOrder = invIsPartialOrder }
strictPartialOrder : StrictPartialOrder _ _ _
strictPartialOrder = record
- { isStrictPartialOrder = record
- { isEquivalence = isEquivalence
- ; irrefl = irrefl
- ; trans = trans isPartialOrder
- ; <-resp-≈ = <-resp-≈ isEquivalence ≤-resp-≈
- }
+ { isStrictPartialOrder = <-isStrictPartialOrder isPartialOrder
}
open StrictPartialOrder strictPartialOrder
diff --git a/src/Relation/Binary/Properties/StrictPartialOrder.agda b/src/Relation/Binary/Properties/StrictPartialOrder.agda
index d62d245..5c69ca7 100644
--- a/src/Relation/Binary/Properties/StrictPartialOrder.agda
+++ b/src/Relation/Binary/Properties/StrictPartialOrder.agda
@@ -11,22 +11,14 @@ module Relation.Binary.Properties.StrictPartialOrder
open Relation.Binary.StrictPartialOrder SPO
renaming (trans to <-trans)
-import Relation.Binary.StrictToNonStrict as Conv
-open Conv _≈_ _<_
+open import Relation.Binary.Construct.StrictToNonStrict _≈_ _<_
------------------------------------------------------------------------
-- Strict partial orders can be converted to posets
poset : Poset _ _ _
poset = record
- { isPartialOrder = record
- { isPreorder = record
- { isEquivalence = isEquivalence
- ; reflexive = reflexive
- ; trans = trans isEquivalence <-resp-≈ <-trans
- }
- ; antisym = antisym isEquivalence <-trans irrefl
- }
+ { isPartialOrder = isPartialOrder isStrictPartialOrder
}
open Poset poset public
diff --git a/src/Relation/Binary/Properties/StrictTotalOrder.agda b/src/Relation/Binary/Properties/StrictTotalOrder.agda
index 7d7a836..83f54e9 100644
--- a/src/Relation/Binary/Properties/StrictTotalOrder.agda
+++ b/src/Relation/Binary/Properties/StrictTotalOrder.agda
@@ -11,8 +11,7 @@ module Relation.Binary.Properties.StrictTotalOrder
where
open Relation.Binary.StrictTotalOrder STO
-import Relation.Binary.StrictToNonStrict as Conv
-open Conv _≈_ _<_
+open import Relation.Binary.Construct.StrictToNonStrict _≈_ _<_
import Relation.Binary.Properties.StrictPartialOrder as SPO
open import Relation.Binary.Consequences
@@ -21,14 +20,7 @@ open import Relation.Binary.Consequences
decTotalOrder : DecTotalOrder _ _ _
decTotalOrder = record
- { isDecTotalOrder = record
- { isTotalOrder = record
- { isPartialOrder = SPO.isPartialOrder strictPartialOrder
- ; total = total compare
- }
- ; _≟_ = _≟_
- ; _≤?_ = decidable' compare
- }
+ { isDecTotalOrder = isDecTotalOrder isStrictTotalOrder
}
open DecTotalOrder decTotalOrder public
diff --git a/src/Relation/Binary/PropositionalEquality.agda b/src/Relation/Binary/PropositionalEquality.agda
index 4299d70..d062026 100644
--- a/src/Relation/Binary/PropositionalEquality.agda
+++ b/src/Relation/Binary/PropositionalEquality.agda
@@ -8,17 +8,21 @@ module Relation.Binary.PropositionalEquality where
open import Function
open import Function.Equality using (Π; _⟶_; ≡-setoid)
-open import Data.Product
-open import Data.Unit.NonEta
open import Level
+open import Data.Empty
+open import Data.Product
+open import Relation.Nullary using (yes ; no)
+open import Relation.Unary using (Pred)
open import Relation.Binary
-import Relation.Binary.Indexed as I
-open import Relation.Binary.Consequences
+open import Relation.Binary.Indexed.Heterogeneous
+ using (IndexedSetoid)
+import Relation.Binary.Indexed.Heterogeneous.Construct.Trivial
+ as Trivial
open import Relation.Binary.HeterogeneousEquality.Core as H using (_≅_)
--- Some of the definitions can be found in the following modules:
+------------------------------------------------------------------------
+-- Re-export contents of core module
-open import Relation.Binary.Core public using (_≡_; refl; _≢_)
open import Relation.Binary.PropositionalEquality.Core public
------------------------------------------------------------------------
@@ -40,9 +44,6 @@ cong₂ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c}
(f : A → B → C) {x y u v} → x ≡ y → u ≡ v → f x u ≡ f y v
cong₂ f refl refl = refl
-proof-irrelevance : ∀ {a} {A : Set a} {x y : A} (p q : x ≡ y) → p ≡ q
-proof-irrelevance refl refl = refl
-
setoid : ∀ {a} → Set a → Setoid _ _
setoid A = record
{ Carrier = A
@@ -50,7 +51,7 @@ setoid A = record
; isEquivalence = isEquivalence
}
-decSetoid : ∀ {a} {A : Set a} → Decidable (_≡_ {A = A}) → DecSetoid _ _
+decSetoid : ∀ {a} {A : Set a} → Decidable {A = A} _≡_ → DecSetoid _ _
decSetoid dec = record
{ _≈_ = _≡_
; isDecEquivalence = record
@@ -80,82 +81,29 @@ preorder A = record
infix 4 _≗_
_→-setoid_ : ∀ {a b} (A : Set a) (B : Set b) → Setoid _ _
-A →-setoid B = ≡-setoid A (Setoid.indexedSetoid (setoid B))
+A →-setoid B = ≡-setoid A (Trivial.indexedSetoid (setoid B))
_≗_ : ∀ {a b} {A : Set a} {B : Set b} (f g : A → B) → Set _
_≗_ {A = A} {B} = Setoid._≈_ (A →-setoid B)
-:→-to-Π : ∀ {a b₁ b₂} {A : Set a} {B : I.Setoid _ b₁ b₂} →
- ((x : A) → I.Setoid.Carrier B x) → Π (setoid A) B
+:→-to-Π : ∀ {a b₁ b₂} {A : Set a} {B : IndexedSetoid _ b₁ b₂} →
+ ((x : A) → IndexedSetoid.Carrier B x) → Π (setoid A) B
:→-to-Π {B = B} f = record { _⟨$⟩_ = f; cong = cong′ }
where
- open I.Setoid B using (_≈_)
+ open IndexedSetoid B using (_≈_)
cong′ : ∀ {x y} → x ≡ y → f x ≈ f y
- cong′ refl = I.Setoid.refl B
+ cong′ refl = IndexedSetoid.refl B
→-to-⟶ : ∀ {a b₁ b₂} {A : Set a} {B : Setoid b₁ b₂} →
(A → Setoid.Carrier B) → setoid A ⟶ B
→-to-⟶ = :→-to-Π
------------------------------------------------------------------------
--- The old inspect idiom
-
--- The old inspect idiom has been deprecated, and may be removed in
--- the future. Use inspect on steroids instead.
-
-module Deprecated-inspect where
-
- -- The inspect idiom can be used when you want to pattern match on
- -- the result r of some expression e, and you also need to
- -- "remember" that r ≡ e.
-
- -- The inspect idiom has a problem: sometimes you can only pattern
- -- match on the p part of p with-≡ eq if you also pattern match on
- -- the eq part, and then you no longer have access to the equality.
- -- Inspect on steroids solves this problem.
-
- data Inspect {a} {A : Set a} (x : A) : Set a where
- _with-≡_ : (y : A) (eq : x ≡ y) → Inspect x
-
- inspect : ∀ {a} {A : Set a} (x : A) → Inspect x
- inspect x = x with-≡ refl
-
- -- Example usage:
-
- -- f x y with inspect (g x)
- -- f x y | c z with-≡ eq = ...
-
-------------------------------------------------------------------------
--- The old inspect on steroids
-
--- The old inspect on steroids idiom has been deprecated, and may be
--- removed in the future. Use simplified inspect on steroids instead.
-
-module Deprecated-inspect-on-steroids where
-
- -- Inspect on steroids can be used when you want to pattern match on
- -- the result r of some expression e, and you also need to "remember"
- -- that r ≡ e.
-
- data Reveal_is_ {a} {A : Set a} (x : Hidden A) (y : A) : Set a where
- [_] : (eq : reveal x ≡ y) → Reveal x is y
+-- Inspect
- inspect : ∀ {a b} {A : Set a} {B : A → Set b}
- (f : (x : A) → B x) (x : A) → Reveal (hide f x) is (f x)
- inspect f x = [ refl ]
-
- -- Example usage:
-
- -- f x y with g x | inspect g x
- -- f x y | c z | [ eq ] = ...
-
-------------------------------------------------------------------------
--- Simplified inspect on steroids
-
--- Simplified inspect on steroids can be used when you want to pattern
--- match on the result r of some expression e, and you also need to
--- "remember" that r ≡ e.
+-- Inspect can be used when you want to pattern match on the result r
+-- of some expression e, and you also need to "remember" that r ≡ e.
record Reveal_·_is_ {a b} {A : Set a} {B : A → Set b}
(f : (x : A) → B x) (x : A) (y : B x) :
@@ -232,3 +180,38 @@ extensionality-for-lower-levels a₂ b₂ ext f≡g =
(∀ x → B₁ x ≡ B₂ x) → (∀ x → B₁ x) ≡ (∀ x → B₂ x)
∀-extensionality ext B₁ B₂ B₁≡B₂ with ext B₁≡B₂
∀-extensionality ext B .B B₁≡B₂ | refl = refl
+
+------------------------------------------------------------------------
+-- Proof irrelevance
+
+isPropositional : ∀ {a} → Set a → Set a
+isPropositional A = (a b : A) → a ≡ b
+
+≡-irrelevance : ∀ {a} {A : Set a} → Irrelevant (_≡_ {A = A})
+≡-irrelevance refl refl = refl
+
+module _ {a} {A : Set a} (_≟_ : Decidable (_≡_ {A = A})) {a b : A} where
+
+ ≡-≟-identity : (eq : a ≡ b) → a ≟ b ≡ yes eq
+ ≡-≟-identity eq with a ≟ b
+ ... | yes p = cong yes (≡-irrelevance p eq)
+ ... | no ¬p = ⊥-elim (¬p eq)
+
+ ≢-≟-identity : a ≢ b → ∃ λ ¬eq → a ≟ b ≡ no ¬eq
+ ≢-≟-identity ¬eq with a ≟ b
+ ... | yes p = ⊥-elim (¬eq p)
+ ... | no ¬p = ¬p , refl
+
+------------------------------------------------------------------------
+-- DEPRECATED NAMES
+------------------------------------------------------------------------
+-- Please use the new names as continuing support for the old names is
+-- not guaranteed.
+
+-- Version 0.15
+
+proof-irrelevance = ≡-irrelevance
+{-# WARNING_ON_USAGE proof-irrelevance
+"Warning: proof-irrelevance was deprecated in v0.15.
+Please use ≡-irrelevance instead."
+#-}
diff --git a/src/Relation/Binary/PropositionalEquality/Core.agda b/src/Relation/Binary/PropositionalEquality/Core.agda
index cd2e308..0c030d7 100644
--- a/src/Relation/Binary/PropositionalEquality/Core.agda
+++ b/src/Relation/Binary/PropositionalEquality/Core.agda
@@ -2,35 +2,53 @@
-- The Agda standard library
--
-- Propositional equality
-------------------------------------------------------------------------
-
--- This file contains some core definitions which are reexported by
+--
+-- This file contains some core definitions which are re-exported by
-- Relation.Binary.PropositionalEquality.
+------------------------------------------------------------------------
module Relation.Binary.PropositionalEquality.Core where
+open import Data.Product using (_,_)
open import Level
open import Relation.Binary.Core
-open import Relation.Binary.Consequences.Core
+open import Relation.Nullary using (¬_)
+
+------------------------------------------------------------------------
+-- Propositional equality
+
+open import Agda.Builtin.Equality public
+
+infix 4 _≢_
+_≢_ : ∀ {a} {A : Set a} → Rel A a
+x ≢ y = ¬ x ≡ y
------------------------------------------------------------------------
-- Some properties
-sym : ∀ {a} {A : Set a} → Symmetric (_≡_ {A = A})
-sym refl = refl
+module _ {a} {A : Set a} where
+
+ sym : Symmetric {A = A} _≡_
+ sym refl = refl
+
+ trans : Transitive {A = A} _≡_
+ trans refl eq = eq
+
+ subst : ∀ {p} → Substitutive {A = A} _≡_ p
+ subst P refl p = p
-trans : ∀ {a} {A : Set a} → Transitive (_≡_ {A = A})
-trans refl eq = eq
+ respˡ : ∀ {ℓ} (∼ : Rel A ℓ) → ∼ Respectsˡ _≡_
+ respˡ _∼_ refl x∼y = x∼y
-subst : ∀ {a p} {A : Set a} → Substitutive (_≡_ {A = A}) p
-subst P refl p = p
+ respʳ : ∀ {ℓ} (∼ : Rel A ℓ) → ∼ Respectsʳ _≡_
+ respʳ _∼_ refl x∼y = x∼y
-resp₂ : ∀ {a ℓ} {A : Set a} (∼ : Rel A ℓ) → ∼ Respects₂ _≡_
-resp₂ _∼_ = subst⟶resp₂ _∼_ subst
+ resp₂ : ∀ {ℓ} (∼ : Rel A ℓ) → ∼ Respects₂ _≡_
+ resp₂ _∼_ = respʳ _∼_ , respˡ _∼_
-isEquivalence : ∀ {a} {A : Set a} → IsEquivalence (_≡_ {A = A})
-isEquivalence = record
- { refl = refl
- ; sym = sym
- ; trans = trans
- }
+ isEquivalence : IsEquivalence {A = A} _≡_
+ isEquivalence = record
+ { refl = refl
+ ; sym = sym
+ ; trans = trans
+ }
diff --git a/src/Relation/Binary/PropositionalEquality/TrustMe.agda b/src/Relation/Binary/PropositionalEquality/TrustMe.agda
index 5235862..a233278 100644
--- a/src/Relation/Binary/PropositionalEquality/TrustMe.agda
+++ b/src/Relation/Binary/PropositionalEquality/TrustMe.agda
@@ -6,14 +6,14 @@
module Relation.Binary.PropositionalEquality.TrustMe where
-open import Relation.Binary.Core using (_≡_)
+open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl)
open import Agda.Builtin.TrustMe
-- trustMe {x = x} {y = y} evaluates to refl if x and y are
-- definitionally equal.
--
--- For an example of the use of trustMe, see Data.String._≟_.
+-- For an example of the use of trustMe, see Data.String.Unsafe._≟_.
trustMe : ∀ {a} {A : Set a} {x y : A} → x ≡ y
trustMe = primTrustMe
@@ -24,3 +24,17 @@ trustMe = primTrustMe
erase : ∀ {a} {A : Set a} {x y : A} → x ≡ y → x ≡ y
erase _ = trustMe
+
+-- A "postulate with a reduction": postulate[ a ↦ b ] a evaluates to b,
+-- while postulate[ a ↦ b ] a' gets stuck if a' is not definitionally
+-- equal to a. This can be used to define a postulate of type (x : A) → B x
+-- by only specifying the behaviour at B t for some t : A. Introduced in
+--
+-- Alan Jeffrey, Univalence via Agda's primTrustMe again
+-- 23 January 2015
+-- https://lists.chalmers.se/pipermail/agda/2015/007418.html
+
+postulate[_↦_] : ∀ {a b} {A : Set a}{B : A → Set b} →
+ (t : A) → B t → (x : A) → B x
+postulate[ a ↦ b ] a' with trustMe {x = a} {a'}
+postulate[ a ↦ b ] .a | refl = b
diff --git a/src/Relation/Binary/SetoidReasoning.agda b/src/Relation/Binary/SetoidReasoning.agda
index 7fb9aea..c53eada 100644
--- a/src/Relation/Binary/SetoidReasoning.agda
+++ b/src/Relation/Binary/SetoidReasoning.agda
@@ -21,9 +21,9 @@
-- ≈⟨ y≈z ⟩
-- z ∎
-open import Relation.Binary.EqReasoning as EqR using (_IsRelatedTo_)
open import Relation.Binary
-open import Relation.Binary.Core
+open import Relation.Binary.EqReasoning as EqR using (_IsRelatedTo_)
+open import Relation.Binary.PropositionalEquality
open Setoid
diff --git a/src/Relation/Binary/Sigma/Pointwise.agda b/src/Relation/Binary/Sigma/Pointwise.agda
index 51d9ee5..411bd3a 100644
--- a/src/Relation/Binary/Sigma/Pointwise.agda
+++ b/src/Relation/Binary/Sigma/Pointwise.agda
@@ -2,445 +2,11 @@
-- The Agda standard library
--
-- Pointwise lifting of binary relations to sigma types
+--
+-- This module is DEPRECATED. Please use
+-- Data.Product.Relation.Pointwise.Dependent directly.
------------------------------------------------------------------------
module Relation.Binary.Sigma.Pointwise where
-open import Data.Product as Prod
-open import Level
-open import Function
-open import Function.Equality as F using (_⟶_; _⟨$⟩_)
-open import Function.Equivalence as Eq
- using (Equivalence; _⇔_; module Equivalence)
-open import Function.Injection as Inj
- using (Injection; _↣_; module Injection; Injective)
-open import Function.Inverse as Inv
- using (Inverse; _↔_; module Inverse)
-open import Function.LeftInverse as LeftInv
- using (LeftInverse; _↞_; module LeftInverse;
- _LeftInverseOf_; _RightInverseOf_)
-open import Function.Related as Related
- using (_∼[_]_; lam; app-←; app-↢)
-open import Function.Surjection as Surj
- using (Surjection; _↠_; module Surjection)
-import Relation.Binary as B
-open import Relation.Binary.Indexed as I using (_at_)
-import Relation.Binary.HeterogeneousEquality as H
-import Relation.Binary.PropositionalEquality as P
-
-------------------------------------------------------------------------
--- Pointwise lifting
-
-infixr 4 _,_
-
-data REL {a₁ a₂ b₁ b₂ ℓ₁ ℓ₂}
- {A₁ : Set a₁} (B₁ : A₁ → Set b₁)
- {A₂ : Set a₂} (B₂ : A₂ → Set b₂)
- (_R₁_ : B.REL A₁ A₂ ℓ₁) (_R₂_ : I.REL B₁ B₂ ℓ₂) :
- B.REL (Σ A₁ B₁) (Σ A₂ B₂) (a₁ ⊔ a₂ ⊔ b₁ ⊔ b₂ ⊔ ℓ₁ ⊔ ℓ₂) where
- _,_ : {x₁ : A₁} {y₁ : B₁ x₁} {x₂ : A₂} {y₂ : B₂ x₂}
- (x₁Rx₂ : x₁ R₁ x₂) (y₁Ry₂ : y₁ R₂ y₂) →
- REL B₁ B₂ _R₁_ _R₂_ (x₁ , y₁) (x₂ , y₂)
-
-Rel : ∀ {a b ℓ₁ ℓ₂} {A : Set a} (B : A → Set b)
- (_R₁_ : B.Rel A ℓ₁) (_R₂_ : I.Rel B ℓ₂) → B.Rel (Σ A B) _
-Rel B = REL B B
-
-------------------------------------------------------------------------
--- Rel preserves many properties
-
-module _ {a b ℓ₁ ℓ₂} {A : Set a} {B : A → Set b}
- {R₁ : B.Rel A ℓ₁} {R₂ : I.Rel B ℓ₂} where
-
- refl : B.Reflexive R₁ → I.Reflexive B R₂ →
- B.Reflexive (Rel B R₁ R₂)
- refl refl₁ refl₂ {x = (x , y)} = (refl₁ , refl₂)
-
- symmetric : B.Symmetric R₁ → I.Symmetric B R₂ →
- B.Symmetric (Rel B R₁ R₂)
- symmetric sym₁ sym₂ (x₁Rx₂ , y₁Ry₂) = (sym₁ x₁Rx₂ , sym₂ y₁Ry₂)
-
- transitive : B.Transitive R₁ → I.Transitive B R₂ →
- B.Transitive (Rel B R₁ R₂)
- transitive trans₁ trans₂ (x₁Rx₂ , y₁Ry₂) (x₂Rx₃ , y₂Ry₃) =
- (trans₁ x₁Rx₂ x₂Rx₃ , trans₂ y₁Ry₂ y₂Ry₃)
-
- isEquivalence : B.IsEquivalence R₁ → I.IsEquivalence B R₂ →
- B.IsEquivalence (Rel B R₁ R₂)
- isEquivalence eq₁ eq₂ = record
- { refl = refl (B.IsEquivalence.refl eq₁)
- (I.IsEquivalence.refl eq₂)
- ; sym = symmetric (B.IsEquivalence.sym eq₁)
- (I.IsEquivalence.sym eq₂)
- ; trans = transitive (B.IsEquivalence.trans eq₁)
- (I.IsEquivalence.trans eq₂)
- }
-
-setoid : ∀ {b₁ b₂ i₁ i₂} →
- (A : B.Setoid b₁ b₂) → I.Setoid (B.Setoid.Carrier A) i₁ i₂ →
- B.Setoid _ _
-setoid s₁ s₂ = record
- { isEquivalence = isEquivalence (B.Setoid.isEquivalence s₁)
- (I.Setoid.isEquivalence s₂)
- }
-
-------------------------------------------------------------------------
--- The propositional equality setoid over sigma types can be
--- decomposed using Rel
-
-Rel↔≡ : ∀ {a b} {A : Set a} {B : A → Set b} →
- Inverse (setoid (P.setoid A) (H.indexedSetoid B))
- (P.setoid (Σ A B))
-Rel↔≡ {a} {b} {A} {B} = record
- { to = record { _⟨$⟩_ = id; cong = to-cong }
- ; from = record { _⟨$⟩_ = id; cong = from-cong }
- ; inverse-of = record
- { left-inverse-of = uncurry (λ _ _ → (P.refl , H.refl))
- ; right-inverse-of = λ _ → P.refl
- }
- }
- where
- open I using (_=[_]⇒_)
-
- to-cong : Rel B P._≡_ (λ x y → H._≅_ x y) =[ id {a = a ⊔ b} ]⇒ P._≡_
- to-cong (P.refl , H.refl) = P.refl
-
- from-cong : P._≡_ =[ id {a = a ⊔ b} ]⇒ Rel B P._≡_ (λ x y → H._≅_ x y)
- from-cong {i = (x , y)} P.refl = (P.refl , H.refl)
-
-------------------------------------------------------------------------
--- Some properties related to "relatedness"
-
-⟶ : ∀ {a₁ a₂ b₁ b₁′ b₂ b₂′}
- {A₁ : Set a₁} {A₂ : Set a₂}
- {B₁ : I.Setoid A₁ b₁ b₁′} (B₂ : I.Setoid A₂ b₂ b₂′)
- (f : A₁ → A₂) → (∀ {x} → (B₁ at x) ⟶ (B₂ at f x)) →
- setoid (P.setoid A₁) B₁ ⟶ setoid (P.setoid A₂) B₂
-⟶ {A₁ = A₁} {A₂} {B₁} B₂ f g = record
- { _⟨$⟩_ = fg
- ; cong = fg-cong
- }
- where
- open B.Setoid (setoid (P.setoid A₁) B₁)
- using () renaming (_≈_ to _≈₁_)
- open B.Setoid (setoid (P.setoid A₂) B₂)
- using () renaming (_≈_ to _≈₂_)
- open B using (_=[_]⇒_)
-
- fg = Prod.map f (_⟨$⟩_ g)
-
- fg-cong : _≈₁_ =[ fg ]⇒ _≈₂_
- fg-cong (P.refl , ∼) = (P.refl , F.cong g ∼)
-
-equivalence :
- ∀ {a₁ a₂ b₁ b₁′ b₂ b₂′}
- {A₁ : Set a₁} {A₂ : Set a₂}
- {B₁ : I.Setoid A₁ b₁ b₁′} {B₂ : I.Setoid A₂ b₂ b₂′}
- (A₁⇔A₂ : A₁ ⇔ A₂) →
- (∀ {x} → _⟶_ (B₁ at x) (B₂ at (Equivalence.to A₁⇔A₂ ⟨$⟩ x))) →
- (∀ {y} → _⟶_ (B₂ at y) (B₁ at (Equivalence.from A₁⇔A₂ ⟨$⟩ y))) →
- Equivalence (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂)
-equivalence {B₁ = B₁} {B₂} A₁⇔A₂ B-to B-from = record
- { to = ⟶ B₂ (_⟨$⟩_ (to A₁⇔A₂)) B-to
- ; from = ⟶ B₁ (_⟨$⟩_ (from A₁⇔A₂)) B-from
- } where open Equivalence
-
-private
-
- subst-cong : ∀ {i a p} {I : Set i} {A : I → Set a}
- (P : ∀ {i} → A i → A i → Set p) {i i′} {x y : A i}
- (i≡i′ : P._≡_ i i′) →
- P x y → P (P.subst A i≡i′ x) (P.subst A i≡i′ y)
- subst-cong P P.refl p = p
-
-equivalence-↞ :
- ∀ {a₁ a₂ b₁ b₁′ b₂ b₂′}
- {A₁ : Set a₁} {A₂ : Set a₂}
- (B₁ : I.Setoid A₁ b₁ b₁′) {B₂ : I.Setoid A₂ b₂ b₂′}
- (A₁↞A₂ : A₁ ↞ A₂) →
- (∀ {x} → Equivalence (B₁ at (LeftInverse.from A₁↞A₂ ⟨$⟩ x))
- (B₂ at x)) →
- Equivalence (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂)
-equivalence-↞ B₁ {B₂} A₁↞A₂ B₁⇔B₂ =
- equivalence (LeftInverse.equivalence A₁↞A₂) B-to B-from
- where
- B-to : ∀ {x} → _⟶_ (B₁ at x) (B₂ at (LeftInverse.to A₁↞A₂ ⟨$⟩ x))
- B-to = record
- { _⟨$⟩_ = λ x → Equivalence.to B₁⇔B₂ ⟨$⟩
- P.subst (I.Setoid.Carrier B₁)
- (P.sym $ LeftInverse.left-inverse-of A₁↞A₂ _)
- x
- ; cong = F.cong (Equivalence.to B₁⇔B₂) ∘
- subst-cong (λ {x} → I.Setoid._≈_ B₁ {x} {x})
- (P.sym (LeftInverse.left-inverse-of A₁↞A₂ _))
- }
-
- B-from : ∀ {y} → _⟶_ (B₂ at y) (B₁ at (LeftInverse.from A₁↞A₂ ⟨$⟩ y))
- B-from = Equivalence.from B₁⇔B₂
-
-equivalence-↠ :
- ∀ {a₁ a₂ b₁ b₁′ b₂ b₂′}
- {A₁ : Set a₁} {A₂ : Set a₂}
- {B₁ : I.Setoid A₁ b₁ b₁′} (B₂ : I.Setoid A₂ b₂ b₂′)
- (A₁↠A₂ : A₁ ↠ A₂) →
- (∀ {x} → Equivalence (B₁ at x) (B₂ at (Surjection.to A₁↠A₂ ⟨$⟩ x))) →
- Equivalence (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂)
-equivalence-↠ {B₁ = B₁} B₂ A₁↠A₂ B₁⇔B₂ =
- equivalence (Surjection.equivalence A₁↠A₂) B-to B-from
- where
- B-to : ∀ {x} → _⟶_ (B₁ at x) (B₂ at (Surjection.to A₁↠A₂ ⟨$⟩ x))
- B-to = Equivalence.to B₁⇔B₂
-
- B-from : ∀ {y} → _⟶_ (B₂ at y) (B₁ at (Surjection.from A₁↠A₂ ⟨$⟩ y))
- B-from = record
- { _⟨$⟩_ = λ x → Equivalence.from B₁⇔B₂ ⟨$⟩
- P.subst (I.Setoid.Carrier B₂)
- (P.sym $ Surjection.right-inverse-of A₁↠A₂ _)
- x
- ; cong = F.cong (Equivalence.from B₁⇔B₂) ∘
- subst-cong (λ {x} → I.Setoid._≈_ B₂ {x} {x})
- (P.sym (Surjection.right-inverse-of A₁↠A₂ _))
- }
-
-⇔ : ∀ {a₁ a₂ b₁ b₂}
- {A₁ : Set a₁} {A₂ : Set a₂}
- {B₁ : A₁ → Set b₁} {B₂ : A₂ → Set b₂}
- (A₁⇔A₂ : A₁ ⇔ A₂) →
- (∀ {x} → B₁ x → B₂ (Equivalence.to A₁⇔A₂ ⟨$⟩ x)) →
- (∀ {y} → B₂ y → B₁ (Equivalence.from A₁⇔A₂ ⟨$⟩ y)) →
- Σ A₁ B₁ ⇔ Σ A₂ B₂
-⇔ {B₁ = B₁} {B₂} A₁⇔A₂ B-to B-from =
- Inverse.equivalence (Rel↔≡ {B = B₂}) ⟨∘⟩
- equivalence A₁⇔A₂
- (Inverse.to (H.≡↔≅ B₂) ⊚ P.→-to-⟶ B-to ⊚ Inverse.from (H.≡↔≅ B₁))
- (Inverse.to (H.≡↔≅ B₁) ⊚ P.→-to-⟶ B-from ⊚ Inverse.from (H.≡↔≅ B₂))
- ⟨∘⟩
- Eq.sym (Inverse.equivalence (Rel↔≡ {B = B₁}))
- where
- open Eq using () renaming (_∘_ to _⟨∘⟩_)
- open F using () renaming (_∘_ to _⊚_)
-
-⇔-↠ : ∀ {a₁ a₂ b₁ b₂}
- {A₁ : Set a₁} {A₂ : Set a₂}
- {B₁ : A₁ → Set b₁} {B₂ : A₂ → Set b₂}
- (A₁↠A₂ : A₁ ↠ A₂) →
- (∀ {x} → _⇔_ (B₁ x) (B₂ (Surjection.to A₁↠A₂ ⟨$⟩ x))) →
- _⇔_ (Σ A₁ B₁) (Σ A₂ B₂)
-⇔-↠ {B₁ = B₁} {B₂} A₁↠A₂ B₁⇔B₂ =
- Inverse.equivalence (Rel↔≡ {B = B₂}) ⟨∘⟩
- equivalence-↠ (H.indexedSetoid B₂) A₁↠A₂
- (λ {x} → Inverse.equivalence (H.≡↔≅ B₂) ⟨∘⟩
- B₁⇔B₂ {x} ⟨∘⟩
- Inverse.equivalence (Inv.sym (H.≡↔≅ B₁))) ⟨∘⟩
- Eq.sym (Inverse.equivalence (Rel↔≡ {B = B₁}))
- where open Eq using () renaming (_∘_ to _⟨∘⟩_)
-
-injection :
- ∀ {a₁ a₂ b₁ b₁′ b₂ b₂′}
- {A₁ : Set a₁} {A₂ : Set a₂}
- {B₁ : I.Setoid A₁ b₁ b₁′} (B₂ : I.Setoid A₂ b₂ b₂′) →
- (A₁↣A₂ : A₁ ↣ A₂) →
- (∀ {x} → Injection (B₁ at x) (B₂ at (Injection.to A₁↣A₂ ⟨$⟩ x))) →
- Injection (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂)
-injection {B₁ = B₁} B₂ A₁↣A₂ B₁↣B₂ = record
- { to = to
- ; injective = inj
- }
- where
- to = ⟶ B₂ (_⟨$⟩_ (Injection.to A₁↣A₂)) (Injection.to B₁↣B₂)
-
- inj : Injective to
- inj (x , y) =
- Injection.injective A₁↣A₂ x ,
- lemma (Injection.injective A₁↣A₂ x) y
- where
- lemma :
- ∀ {x x′}
- {y : I.Setoid.Carrier B₁ x} {y′ : I.Setoid.Carrier B₁ x′} →
- P._≡_ x x′ →
- (eq : I.Setoid._≈_ B₂ (Injection.to B₁↣B₂ ⟨$⟩ y)
- (Injection.to B₁↣B₂ ⟨$⟩ y′)) →
- I.Setoid._≈_ B₁ y y′
- lemma P.refl = Injection.injective B₁↣B₂
-
-↣ : ∀ {a₁ a₂ b₁ b₂}
- {A₁ : Set a₁} {A₂ : Set a₂}
- {B₁ : A₁ → Set b₁} {B₂ : A₂ → Set b₂}
- (A₁↣A₂ : A₁ ↣ A₂) →
- (∀ {x} → B₁ x ↣ B₂ (Injection.to A₁↣A₂ ⟨$⟩ x)) →
- Σ A₁ B₁ ↣ Σ A₂ B₂
-↣ {B₁ = B₁} {B₂} A₁↣A₂ B₁↣B₂ =
- Inverse.injection (Rel↔≡ {B = B₂}) ⟨∘⟩
- injection (H.indexedSetoid B₂) A₁↣A₂
- (λ {x} → Inverse.injection (H.≡↔≅ B₂) ⟨∘⟩
- B₁↣B₂ {x} ⟨∘⟩
- Inverse.injection (Inv.sym (H.≡↔≅ B₁))) ⟨∘⟩
- Inverse.injection (Inv.sym (Rel↔≡ {B = B₁}))
- where open Inj using () renaming (_∘_ to _⟨∘⟩_)
-
-left-inverse :
- ∀ {a₁ a₂ b₁ b₁′ b₂ b₂′}
- {A₁ : Set a₁} {A₂ : Set a₂}
- (B₁ : I.Setoid A₁ b₁ b₁′) {B₂ : I.Setoid A₂ b₂ b₂′} →
- (A₁↞A₂ : A₁ ↞ A₂) →
- (∀ {x} → LeftInverse (B₁ at (LeftInverse.from A₁↞A₂ ⟨$⟩ x))
- (B₂ at x)) →
- LeftInverse (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂)
-left-inverse B₁ {B₂} A₁↞A₂ B₁↞B₂ = record
- { to = Equivalence.to eq
- ; from = Equivalence.from eq
- ; left-inverse-of = left
- }
- where
- eq = equivalence-↞ B₁ A₁↞A₂ (LeftInverse.equivalence B₁↞B₂)
-
- left : Equivalence.from eq LeftInverseOf Equivalence.to eq
- left (x , y) =
- LeftInverse.left-inverse-of A₁↞A₂ x ,
- I.Setoid.trans B₁
- (LeftInverse.left-inverse-of B₁↞B₂ _)
- (lemma (P.sym (LeftInverse.left-inverse-of A₁↞A₂ x)))
- where
- lemma :
- ∀ {x x′ y} (eq : P._≡_ x x′) →
- I.Setoid._≈_ B₁ (P.subst (I.Setoid.Carrier B₁) eq y) y
- lemma P.refl = I.Setoid.refl B₁
-
-↞ : ∀ {a₁ a₂ b₁ b₂}
- {A₁ : Set a₁} {A₂ : Set a₂}
- {B₁ : A₁ → Set b₁} {B₂ : A₂ → Set b₂}
- (A₁↞A₂ : A₁ ↞ A₂) →
- (∀ {x} → B₁ (LeftInverse.from A₁↞A₂ ⟨$⟩ x) ↞ B₂ x) →
- Σ A₁ B₁ ↞ Σ A₂ B₂
-↞ {B₁ = B₁} {B₂} A₁↞A₂ B₁↞B₂ =
- Inverse.left-inverse (Rel↔≡ {B = B₂}) ⟨∘⟩
- left-inverse (H.indexedSetoid B₁) A₁↞A₂
- (λ {x} → Inverse.left-inverse (H.≡↔≅ B₂) ⟨∘⟩
- B₁↞B₂ {x} ⟨∘⟩
- Inverse.left-inverse (Inv.sym (H.≡↔≅ B₁))) ⟨∘⟩
- Inverse.left-inverse (Inv.sym (Rel↔≡ {B = B₁}))
- where open LeftInv using () renaming (_∘_ to _⟨∘⟩_)
-
-surjection :
- ∀ {a₁ a₂ b₁ b₁′ b₂ b₂′}
- {A₁ : Set a₁} {A₂ : Set a₂}
- {B₁ : I.Setoid A₁ b₁ b₁′} (B₂ : I.Setoid A₂ b₂ b₂′) →
- (A₁↠A₂ : A₁ ↠ A₂) →
- (∀ {x} → Surjection (B₁ at x) (B₂ at (Surjection.to A₁↠A₂ ⟨$⟩ x))) →
- Surjection (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂)
-surjection {B₁} B₂ A₁↠A₂ B₁↠B₂ = record
- { to = Equivalence.to eq
- ; surjective = record
- { from = Equivalence.from eq
- ; right-inverse-of = right
- }
- }
- where
- eq = equivalence-↠ B₂ A₁↠A₂ (Surjection.equivalence B₁↠B₂)
-
- right : Equivalence.from eq RightInverseOf Equivalence.to eq
- right (x , y) =
- Surjection.right-inverse-of A₁↠A₂ x ,
- I.Setoid.trans B₂
- (Surjection.right-inverse-of B₁↠B₂ _)
- (lemma (P.sym $ Surjection.right-inverse-of A₁↠A₂ x))
- where
- lemma : ∀ {x x′ y} (eq : P._≡_ x x′) →
- I.Setoid._≈_ B₂ (P.subst (I.Setoid.Carrier B₂) eq y) y
- lemma P.refl = I.Setoid.refl B₂
-
-↠ : ∀ {a₁ a₂ b₁ b₂}
- {A₁ : Set a₁} {A₂ : Set a₂}
- {B₁ : A₁ → Set b₁} {B₂ : A₂ → Set b₂}
- (A₁↠A₂ : A₁ ↠ A₂) →
- (∀ {x} → B₁ x ↠ B₂ (Surjection.to A₁↠A₂ ⟨$⟩ x)) →
- Σ A₁ B₁ ↠ Σ A₂ B₂
-↠ {B₁ = B₁} {B₂} A₁↠A₂ B₁↠B₂ =
- Inverse.surjection (Rel↔≡ {B = B₂}) ⟨∘⟩
- surjection (H.indexedSetoid B₂) A₁↠A₂
- (λ {x} → Inverse.surjection (H.≡↔≅ B₂) ⟨∘⟩
- B₁↠B₂ {x} ⟨∘⟩
- Inverse.surjection (Inv.sym (H.≡↔≅ B₁))) ⟨∘⟩
- Inverse.surjection (Inv.sym (Rel↔≡ {B = B₁}))
- where open Surj using () renaming (_∘_ to _⟨∘⟩_)
-
-inverse :
- ∀ {a₁ a₂ b₁ b₁′ b₂ b₂′}
- {A₁ : Set a₁} {A₂ : Set a₂}
- {B₁ : I.Setoid A₁ b₁ b₁′} (B₂ : I.Setoid A₂ b₂ b₂′) →
- (A₁↔A₂ : A₁ ↔ A₂) →
- (∀ {x} → Inverse (B₁ at x) (B₂ at (Inverse.to A₁↔A₂ ⟨$⟩ x))) →
- Inverse (setoid (P.setoid A₁) B₁) (setoid (P.setoid A₂) B₂)
-inverse {B₁ = B₁} B₂ A₁↔A₂ B₁↔B₂ = record
- { to = Surjection.to surj
- ; from = Surjection.from surj
- ; inverse-of = record
- { left-inverse-of = left
- ; right-inverse-of = Surjection.right-inverse-of surj
- }
- }
- where
- surj = surjection B₂ (Inverse.surjection A₁↔A₂)
- (Inverse.surjection B₁↔B₂)
-
- left : Surjection.from surj LeftInverseOf Surjection.to surj
- left (x , y) =
- Inverse.left-inverse-of A₁↔A₂ x ,
- I.Setoid.trans B₁
- (lemma (P.sym (Inverse.left-inverse-of A₁↔A₂ x))
- (P.sym (Inverse.right-inverse-of A₁↔A₂
- (Inverse.to A₁↔A₂ ⟨$⟩ x))))
- (Inverse.left-inverse-of B₁↔B₂ y)
- where
- lemma :
- ∀ {x x′ y} → P._≡_ x x′ →
- (eq : P._≡_ (Inverse.to A₁↔A₂ ⟨$⟩ x) (Inverse.to A₁↔A₂ ⟨$⟩ x′)) →
- I.Setoid._≈_ B₁
- (Inverse.from B₁↔B₂ ⟨$⟩ P.subst (I.Setoid.Carrier B₂) eq y)
- (Inverse.from B₁↔B₂ ⟨$⟩ y)
- lemma P.refl P.refl = I.Setoid.refl B₁
-
-↔ : ∀ {a₁ a₂ b₁ b₂}
- {A₁ : Set a₁} {A₂ : Set a₂}
- {B₁ : A₁ → Set b₁} {B₂ : A₂ → Set b₂}
- (A₁↔A₂ : A₁ ↔ A₂) →
- (∀ {x} → B₁ x ↔ B₂ (Inverse.to A₁↔A₂ ⟨$⟩ x)) →
- Σ A₁ B₁ ↔ Σ A₂ B₂
-↔ {B₁ = B₁} {B₂} A₁↔A₂ B₁↔B₂ =
- Rel↔≡ {B = B₂} ⟨∘⟩
- inverse (H.indexedSetoid B₂) A₁↔A₂
- (λ {x} → H.≡↔≅ B₂ ⟨∘⟩ B₁↔B₂ {x} ⟨∘⟩ Inv.sym (H.≡↔≅ B₁)) ⟨∘⟩
- Inv.sym (Rel↔≡ {B = B₁})
- where open Inv using () renaming (_∘_ to _⟨∘⟩_)
-
-private
-
- swap-coercions :
- ∀ {k a₁ a₂ b₁ b₂}
- {A₁ : Set a₁} {A₂ : Set a₂} {B₁ : A₁ → Set b₁} (B₂ : A₂ → Set b₂)
- (A₁↔A₂ : _↔_ A₁ A₂) →
- (∀ {x} → B₁ x ∼[ k ] B₂ (Inverse.to A₁↔A₂ ⟨$⟩ x)) →
- ∀ {x} → B₁ (Inverse.from A₁↔A₂ ⟨$⟩ x) ∼[ k ] B₂ x
- swap-coercions {k} {B₁ = B₁} B₂ A₁↔A₂ eq {x} =
- B₁ (Inverse.from A₁↔A₂ ⟨$⟩ x) ∼⟨ eq ⟩
- B₂ (Inverse.to A₁↔A₂ ⟨$⟩ (Inverse.from A₁↔A₂ ⟨$⟩ x)) ↔⟨ B.Setoid.reflexive (Related.setoid Related.bijection _)
- (P.cong B₂ $ Inverse.right-inverse-of A₁↔A₂ x) ⟩
- B₂ x ∎
- where open Related.EquationalReasoning
-
-cong : ∀ {k a₁ a₂ b₁ b₂}
- {A₁ : Set a₁} {A₂ : Set a₂}
- {B₁ : A₁ → Set b₁} {B₂ : A₂ → Set b₂}
- (A₁↔A₂ : _↔_ A₁ A₂) →
- (∀ {x} → B₁ x ∼[ k ] B₂ (Inverse.to A₁↔A₂ ⟨$⟩ x)) →
- Σ A₁ B₁ ∼[ k ] Σ A₂ B₂
-cong {Related.implication} = λ A₁↔A₂ → Prod.map (_⟨$⟩_ (Inverse.to A₁↔A₂))
-cong {Related.reverse-implication} {B₂ = B₂} = λ A₁↔A₂ B₁←B₂ → lam (Prod.map (_⟨$⟩_ (Inverse.from A₁↔A₂))
- (app-← (swap-coercions B₂ A₁↔A₂ B₁←B₂)))
-cong {Related.equivalence} = ⇔-↠ ∘ Inverse.surjection
-cong {Related.injection} = ↣ ∘ Inverse.injection
-cong {Related.reverse-injection} {B₂ = B₂} = λ A₁↔A₂ B₁↢B₂ → lam (↣ (Inverse.injection (Inv.sym A₁↔A₂))
- (app-↢ (swap-coercions B₂ A₁↔A₂ B₁↢B₂)))
-cong {Related.left-inverse} = λ A₁↔A₂ → ↞ (Inverse.left-inverse A₁↔A₂) ∘ swap-coercions _ A₁↔A₂
-cong {Related.surjection} = ↠ ∘ Inverse.surjection
-cong {Related.bijection} = ↔
+open import Data.Product.Relation.Pointwise.Dependent public
diff --git a/src/Relation/Binary/Simple.agda b/src/Relation/Binary/Simple.agda
deleted file mode 100644
index dc4d8f4..0000000
--- a/src/Relation/Binary/Simple.agda
+++ /dev/null
@@ -1,34 +0,0 @@
-------------------------------------------------------------------------
--- The Agda standard library
---
--- Some simple binary relations
-------------------------------------------------------------------------
-
-module Relation.Binary.Simple where
-
-open import Relation.Binary
-open import Data.Unit
-open import Data.Empty
-open import Level
-
--- Constant relations.
-
-Const : ∀ {a b c} {A : Set a} {B : Set b} → Set c → REL A B c
-Const I = λ _ _ → I
-
--- The universally true relation.
-
-Always : ∀ {a ℓ} {A : Set a} → Rel A ℓ
-Always = Const (Lift ⊤)
-
-Always-setoid : ∀ {a ℓ} (A : Set a) → Setoid a ℓ
-Always-setoid A = record
- { Carrier = A
- ; _≈_ = Always
- ; isEquivalence = record {}
- }
-
--- The universally false relation.
-
-Never : ∀ {a ℓ} {A : Set a} → Rel A ℓ
-Never = Const (Lift ⊥)
diff --git a/src/Relation/Binary/StrictToNonStrict.agda b/src/Relation/Binary/StrictToNonStrict.agda
deleted file mode 100644
index 85434fd..0000000
--- a/src/Relation/Binary/StrictToNonStrict.agda
+++ /dev/null
@@ -1,103 +0,0 @@
-------------------------------------------------------------------------
--- The Agda standard library
---
--- Conversion of < to ≤, along with a number of properties
-------------------------------------------------------------------------
-
--- Possible TODO: Prove that a conversion ≤ → < → ≤ returns a
--- relation equivalent to the original one (and similarly for
--- < → ≤ → <).
-
-open import Relation.Binary
-
-module Relation.Binary.StrictToNonStrict
- {a ℓ₁ ℓ₂} {A : Set a}
- (_≈_ : Rel A ℓ₁) (_<_ : Rel A ℓ₂)
- where
-
-open import Relation.Nullary
-open import Relation.Binary.Consequences
-open import Function
-open import Data.Product
-open import Data.Sum
-open import Data.Empty
-
-------------------------------------------------------------------------
--- Conversion
-
--- _<_ can be turned into _≤_ as follows:
-
-_≤_ : Rel A _
-x ≤ y = (x < y) ⊎ (x ≈ y)
-
-------------------------------------------------------------------------
--- The converted relations have certain properties
--- (if the original relations have certain other properties)
-
-reflexive : _≈_ ⇒ _≤_
-reflexive = inj₂
-
-antisym : IsEquivalence _≈_ →
- Transitive _<_ →
- Irreflexive _≈_ _<_ →
- Antisymmetric _≈_ _≤_
-antisym eq trans irrefl = as
- where
- module Eq = IsEquivalence eq
-
- as : Antisymmetric _≈_ _≤_
- as (inj₂ x≈y) _ = x≈y
- as (inj₁ _) (inj₂ y≈x) = Eq.sym y≈x
- as (inj₁ x<y) (inj₁ y<x) =
- ⊥-elim (trans∧irr⟶asym {_≈_ = _≈_} Eq.refl trans irrefl x<y y<x)
-
-trans : IsEquivalence _≈_ → _<_ Respects₂ _≈_ →
- Transitive _<_ → Transitive _≤_
-trans eq <-resp-≈ <-trans = tr
- where
- module Eq = IsEquivalence eq
-
- tr : Transitive _≤_
- tr (inj₁ x<y) (inj₁ y<z) = inj₁ $ <-trans x<y y<z
- tr (inj₁ x<y) (inj₂ y≈z) = inj₁ $ proj₁ <-resp-≈ y≈z x<y
- tr (inj₂ x≈y) (inj₁ y<z) = inj₁ $ proj₂ <-resp-≈ (Eq.sym x≈y) y<z
- tr (inj₂ x≈y) (inj₂ y≈z) = inj₂ $ Eq.trans x≈y y≈z
-
-≤-resp-≈ : IsEquivalence _≈_ → _<_ Respects₂ _≈_ → _≤_ Respects₂ _≈_
-≤-resp-≈ eq <-resp-≈ = ((λ {_ _ _} → resp₁) , (λ {_ _ _} → resp₂))
- where
- module Eq = IsEquivalence eq
-
- resp₁ : ∀ {x y' y} → y' ≈ y → x ≤ y' → x ≤ y
- resp₁ y'≈y (inj₁ x<y') = inj₁ (proj₁ <-resp-≈ y'≈y x<y')
- resp₁ y'≈y (inj₂ x≈y') = inj₂ (Eq.trans x≈y' y'≈y)
-
- resp₂ : ∀ {y x' x} → x' ≈ x → x' ≤ y → x ≤ y
- resp₂ x'≈x (inj₁ x'<y) = inj₁ (proj₂ <-resp-≈ x'≈x x'<y)
- resp₂ x'≈x (inj₂ x'≈y) = inj₂ (Eq.trans (Eq.sym x'≈x) x'≈y)
-
-total : Trichotomous _≈_ _<_ → Total _≤_
-total <-tri x y with <-tri x y
-... | tri< x<y x≉y x≯y = inj₁ (inj₁ x<y)
-... | tri≈ x≮y x≈y x≯y = inj₁ (inj₂ x≈y)
-... | tri> x≮y x≉y x>y = inj₂ (inj₁ x>y)
-
-decidable : Decidable _≈_ → Decidable _<_ → Decidable _≤_
-decidable ≈-dec <-dec x y with ≈-dec x y | <-dec x y
-... | yes x≈y | _ = yes (inj₂ x≈y)
-... | no x≉y | yes x<y = yes (inj₁ x<y)
-... | no x≉y | no x≮y = no helper
- where
- helper : x ≤ y → ⊥
- helper (inj₁ x<y) = x≮y x<y
- helper (inj₂ x≈y) = x≉y x≈y
-
-decidable' : Trichotomous _≈_ _<_ → Decidable _≤_
-decidable' compare x y with compare x y
-... | tri< x<y _ _ = yes (inj₁ x<y)
-... | tri≈ _ x≈y _ = yes (inj₂ x≈y)
-... | tri> x≮y x≉y _ = no helper
- where
- helper : x ≤ y → ⊥
- helper (inj₁ x<y) = x≮y x<y
- helper (inj₂ x≈y) = x≉y x≈y
diff --git a/src/Relation/Binary/Sum.agda b/src/Relation/Binary/Sum.agda
index ee389b7..778ead0 100644
--- a/src/Relation/Binary/Sum.agda
+++ b/src/Relation/Binary/Sum.agda
@@ -2,591 +2,41 @@
-- The Agda standard library
--
-- Sums of binary relations
+--
+-- This module is DEPRECATED. Please use the Data.Sum.Relation modules
+-- directly.
------------------------------------------------------------------------
module Relation.Binary.Sum where
-open import Data.Sum as Sum
-open import Data.Product
-open import Data.Unit.Base using (⊤)
-open import Data.Empty
-open import Function
-open import Function.Equality as F using (_⟶_; _⟨$⟩_)
-open import Function.Equivalence as Eq
- using (Equivalence; _⇔_; module Equivalence)
-open import Function.Injection as Inj
- using (Injection; _↣_; module Injection)
-open import Function.Inverse as Inv
- using (Inverse; _↔_; module Inverse)
-open import Function.LeftInverse as LeftInv
- using (LeftInverse; _↞_; module LeftInverse)
-open import Function.Related
-open import Function.Surjection as Surj
- using (Surjection; _↠_; module Surjection)
-open import Level
-open import Relation.Nullary
-import Relation.Nullary.Decidable as Dec
-open import Relation.Binary
-open import Relation.Binary.PropositionalEquality as P using (_≡_)
-
-module _ {a₁ a₂} {A₁ : Set a₁} {A₂ : Set a₂} where
-
- ----------------------------------------------------------------------
- -- Sums of relations
-
- infixr 1 _⊎-Rel_ _⊎-<_
-
- -- Generalised sum.
-
- data ⊎ʳ {ℓ₁ ℓ₂} (P : Set) (_∼₁_ : Rel A₁ ℓ₁) (_∼₂_ : Rel A₂ ℓ₂) :
- A₁ ⊎ A₂ → A₁ ⊎ A₂ → Set (a₁ ⊔ a₂ ⊔ ℓ₁ ⊔ ℓ₂) where
- ₁∼₂ : ∀ {x y} (p : P) → ⊎ʳ P _∼₁_ _∼₂_ (inj₁ x) (inj₂ y)
- ₁∼₁ : ∀ {x y} (x∼₁y : x ∼₁ y) → ⊎ʳ P _∼₁_ _∼₂_ (inj₁ x) (inj₁ y)
- ₂∼₂ : ∀ {x y} (x∼₂y : x ∼₂ y) → ⊎ʳ P _∼₁_ _∼₂_ (inj₂ x) (inj₂ y)
-
- -- Pointwise sum.
-
- _⊎-Rel_ : ∀ {ℓ₁ ℓ₂} → Rel A₁ ℓ₁ → Rel A₂ ℓ₂ → Rel (A₁ ⊎ A₂) _
- _⊎-Rel_ = ⊎ʳ ⊥
-
- -- All things to the left are "smaller than" all things to the
- -- right.
-
- _⊎-<_ : ∀ {ℓ₁ ℓ₂} → Rel A₁ ℓ₁ → Rel A₂ ℓ₂ → Rel (A₁ ⊎ A₂) _
- _⊎-<_ = ⊎ʳ ⊤
-
- ----------------------------------------------------------------------
- -- Helpers
-
- private
-
- ₁≁₂ : ∀ {ℓ₁ ℓ₂} {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂} →
- ∀ {x y} → ¬ (inj₁ x ⟨ ∼₁ ⊎-Rel ∼₂ ⟩ inj₂ y)
- ₁≁₂ (₁∼₂ ())
-
- drop-inj₁ : ∀ {ℓ₁ ℓ₂} {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂} →
- ∀ {P x y} → inj₁ x ⟨ ⊎ʳ P ∼₁ ∼₂ ⟩ inj₁ y → ∼₁ x y
- drop-inj₁ (₁∼₁ x∼y) = x∼y
-
- drop-inj₂ : ∀ {ℓ₁ ℓ₂} {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂} →
- ∀ {P x y} → inj₂ x ⟨ ⊎ʳ P ∼₁ ∼₂ ⟩ inj₂ y → ∼₂ x y
- drop-inj₂ (₂∼₂ x∼y) = x∼y
-
- ----------------------------------------------------------------------
- -- Some properties which are preserved by the relation formers above
-
- _⊎-reflexive_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {∼₁ : Rel A₁ ℓ₁′}
- {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {∼₂ : Rel A₂ ℓ₂′} →
- ≈₁ ⇒ ∼₁ → ≈₂ ⇒ ∼₂ →
- ∀ {P} → (≈₁ ⊎-Rel ≈₂) ⇒ (⊎ʳ P ∼₁ ∼₂)
- refl₁ ⊎-reflexive refl₂ = refl
- where
- refl : (_ ⊎-Rel _) ⇒ (⊎ʳ _ _ _)
- refl (₁∼₁ x₁≈y₁) = ₁∼₁ (refl₁ x₁≈y₁)
- refl (₂∼₂ x₂≈y₂) = ₂∼₂ (refl₂ x₂≈y₂)
- refl (₁∼₂ ())
-
- _⊎-refl_ : ∀ {ℓ₁ ℓ₂} {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂} →
- Reflexive ∼₁ → Reflexive ∼₂ → Reflexive (∼₁ ⊎-Rel ∼₂)
- refl₁ ⊎-refl refl₂ = refl
- where
- refl : Reflexive (_ ⊎-Rel _)
- refl {x = inj₁ _} = ₁∼₁ refl₁
- refl {x = inj₂ _} = ₂∼₂ refl₂
-
- _⊎-irreflexive_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {<₁ : Rel A₁ ℓ₁′}
- {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {<₂ : Rel A₂ ℓ₂′} →
- Irreflexive ≈₁ <₁ → Irreflexive ≈₂ <₂ →
- ∀ {P} → Irreflexive (≈₁ ⊎-Rel ≈₂) (⊎ʳ P <₁ <₂)
- irrefl₁ ⊎-irreflexive irrefl₂ = irrefl
- where
- irrefl : Irreflexive (_ ⊎-Rel _) (⊎ʳ _ _ _)
- irrefl (₁∼₁ x₁≈y₁) (₁∼₁ x₁<y₁) = irrefl₁ x₁≈y₁ x₁<y₁
- irrefl (₂∼₂ x₂≈y₂) (₂∼₂ x₂<y₂) = irrefl₂ x₂≈y₂ x₂<y₂
- irrefl (₁∼₂ ()) _
-
- _⊎-symmetric_ : ∀ {ℓ₁ ℓ₂} {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂} →
- Symmetric ∼₁ → Symmetric ∼₂ → Symmetric (∼₁ ⊎-Rel ∼₂)
- sym₁ ⊎-symmetric sym₂ = sym
- where
- sym : Symmetric (_ ⊎-Rel _)
- sym (₁∼₁ x₁∼y₁) = ₁∼₁ (sym₁ x₁∼y₁)
- sym (₂∼₂ x₂∼y₂) = ₂∼₂ (sym₂ x₂∼y₂)
- sym (₁∼₂ ())
-
- _⊎-transitive_ : ∀ {ℓ₁ ℓ₂} {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂} →
- Transitive ∼₁ → Transitive ∼₂ →
- ∀ {P} → Transitive (⊎ʳ P ∼₁ ∼₂)
- trans₁ ⊎-transitive trans₂ = trans
- where
- trans : Transitive (⊎ʳ _ _ _)
- trans (₁∼₁ x∼y) (₁∼₁ y∼z) = ₁∼₁ (trans₁ x∼y y∼z)
- trans (₂∼₂ x∼y) (₂∼₂ y∼z) = ₂∼₂ (trans₂ x∼y y∼z)
- trans (₁∼₂ p) (₂∼₂ _) = ₁∼₂ p
- trans (₁∼₁ _) (₁∼₂ p) = ₁∼₂ p
-
- _⊎-antisymmetric_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {≤₁ : Rel A₁ ℓ₁′}
- {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {≤₂ : Rel A₂ ℓ₂′} →
- Antisymmetric ≈₁ ≤₁ → Antisymmetric ≈₂ ≤₂ →
- ∀ {P} → Antisymmetric (≈₁ ⊎-Rel ≈₂) (⊎ʳ P ≤₁ ≤₂)
- antisym₁ ⊎-antisymmetric antisym₂ = antisym
- where
- antisym : Antisymmetric (_ ⊎-Rel _) (⊎ʳ _ _ _)
- antisym (₁∼₁ x≤y) (₁∼₁ y≤x) = ₁∼₁ (antisym₁ x≤y y≤x)
- antisym (₂∼₂ x≤y) (₂∼₂ y≤x) = ₂∼₂ (antisym₂ x≤y y≤x)
- antisym (₁∼₂ _) ()
-
- _⊎-asymmetric_ : ∀ {ℓ₁ ℓ₂} {<₁ : Rel A₁ ℓ₁} {<₂ : Rel A₂ ℓ₂} →
- Asymmetric <₁ → Asymmetric <₂ →
- ∀ {P} → Asymmetric (⊎ʳ P <₁ <₂)
- asym₁ ⊎-asymmetric asym₂ = asym
- where
- asym : Asymmetric (⊎ʳ _ _ _)
- asym (₁∼₁ x<y) (₁∼₁ y<x) = asym₁ x<y y<x
- asym (₂∼₂ x<y) (₂∼₂ y<x) = asym₂ x<y y<x
- asym (₁∼₂ _) ()
-
- _⊎-≈-respects₂_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {∼₁ : Rel A₁ ℓ₁′}
- {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {∼₂ : Rel A₂ ℓ₂′} →
- ∼₁ Respects₂ ≈₁ → ∼₂ Respects₂ ≈₂ →
- ∀ {P} → (⊎ʳ P ∼₁ ∼₂) Respects₂ (≈₁ ⊎-Rel ≈₂)
- _⊎-≈-respects₂_ {≈₁ = ≈₁} {∼₁ = ∼₁}{≈₂ = ≈₂} {∼₂ = ∼₂}
- resp₁ resp₂ {P} =
- (λ {_ _ _} → resp¹) ,
- (λ {_ _ _} → resp²)
- where
- resp¹ : ∀ {x} → ((⊎ʳ P ∼₁ ∼₂) x) Respects (≈₁ ⊎-Rel ≈₂)
- resp¹ (₁∼₁ y≈y') (₁∼₁ x∼y) = ₁∼₁ (proj₁ resp₁ y≈y' x∼y)
- resp¹ (₂∼₂ y≈y') (₂∼₂ x∼y) = ₂∼₂ (proj₁ resp₂ y≈y' x∼y)
- resp¹ (₂∼₂ y≈y') (₁∼₂ p) = (₁∼₂ p)
- resp¹ (₁∼₂ ()) _
-
- resp² : ∀ {y}
- → (flip (⊎ʳ P ∼₁ ∼₂) y) Respects (≈₁ ⊎-Rel ≈₂)
- resp² (₁∼₁ x≈x') (₁∼₁ x∼y) = ₁∼₁ (proj₂ resp₁ x≈x' x∼y)
- resp² (₂∼₂ x≈x') (₂∼₂ x∼y) = ₂∼₂ (proj₂ resp₂ x≈x' x∼y)
- resp² (₁∼₁ x≈x') (₁∼₂ p) = (₁∼₂ p)
- resp² (₁∼₂ ()) _
-
- _⊎-substitutive_ : ∀ {ℓ₁ ℓ₂ ℓ₃} {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂} →
- Substitutive ∼₁ ℓ₃ → Substitutive ∼₂ ℓ₃ →
- Substitutive (∼₁ ⊎-Rel ∼₂) ℓ₃
- subst₁ ⊎-substitutive subst₂ = subst
- where
- subst : Substitutive (_ ⊎-Rel _) _
- subst P (₁∼₁ x∼y) Px = subst₁ (λ z → P (inj₁ z)) x∼y Px
- subst P (₂∼₂ x∼y) Px = subst₂ (λ z → P (inj₂ z)) x∼y Px
- subst P (₁∼₂ ()) Px
-
- ⊎-decidable : ∀ {ℓ₁ ℓ₂} {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂} →
- Decidable ∼₁ → Decidable ∼₂ →
- ∀ {P} → (∀ {x y} → Dec (inj₁ x ⟨ ⊎ʳ P ∼₁ ∼₂ ⟩ inj₂ y)) →
- Decidable (⊎ʳ P ∼₁ ∼₂)
- ⊎-decidable {∼₁ = ∼₁} {∼₂ = ∼₂} dec₁ dec₂ {P} dec₁₂ = dec
- where
- dec : Decidable (⊎ʳ P ∼₁ ∼₂)
- dec (inj₁ x) (inj₁ y) with dec₁ x y
- ... | yes x∼y = yes (₁∼₁ x∼y)
- ... | no x≁y = no (x≁y ∘ drop-inj₁)
- dec (inj₂ x) (inj₂ y) with dec₂ x y
- ... | yes x∼y = yes (₂∼₂ x∼y)
- ... | no x≁y = no (x≁y ∘ drop-inj₂)
- dec (inj₁ x) (inj₂ y) = dec₁₂
- dec (inj₂ x) (inj₁ y) = no (λ())
-
- _⊎-<-total_ : ∀ {ℓ₁ ℓ₂} {≤₁ : Rel A₁ ℓ₁} {≤₂ : Rel A₂ ℓ₂} →
- Total ≤₁ → Total ≤₂ → Total (≤₁ ⊎-< ≤₂)
- total₁ ⊎-<-total total₂ = total
- where
- total : Total (_ ⊎-< _)
- total (inj₁ x) (inj₁ y) = Sum.map ₁∼₁ ₁∼₁ $ total₁ x y
- total (inj₂ x) (inj₂ y) = Sum.map ₂∼₂ ₂∼₂ $ total₂ x y
- total (inj₁ x) (inj₂ y) = inj₁ (₁∼₂ _)
- total (inj₂ x) (inj₁ y) = inj₂ (₁∼₂ _)
-
- _⊎-<-trichotomous_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {<₁ : Rel A₁ ℓ₁′}
- {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {<₂ : Rel A₂ ℓ₂′} →
- Trichotomous ≈₁ <₁ → Trichotomous ≈₂ <₂ →
- Trichotomous (≈₁ ⊎-Rel ≈₂) (<₁ ⊎-< <₂)
- _⊎-<-trichotomous_ {≈₁ = ≈₁} {<₁ = <₁} {≈₂ = ≈₂} {<₂ = <₂}
- tri₁ tri₂ = tri
- where
- tri : Trichotomous (≈₁ ⊎-Rel ≈₂) (<₁ ⊎-< <₂)
- tri (inj₁ x) (inj₂ y) = tri< (₁∼₂ _) ₁≁₂ (λ())
- tri (inj₂ x) (inj₁ y) = tri> (λ()) (λ()) (₁∼₂ _)
- tri (inj₁ x) (inj₁ y) with tri₁ x y
- ... | tri< x<y x≉y x≯y =
- tri< (₁∼₁ x<y) (x≉y ∘ drop-inj₁) (x≯y ∘ drop-inj₁)
- ... | tri≈ x≮y x≈y x≯y =
- tri≈ (x≮y ∘ drop-inj₁) (₁∼₁ x≈y) (x≯y ∘ drop-inj₁)
- ... | tri> x≮y x≉y x>y =
- tri> (x≮y ∘ drop-inj₁) (x≉y ∘ drop-inj₁) (₁∼₁ x>y)
- tri (inj₂ x) (inj₂ y) with tri₂ x y
- ... | tri< x<y x≉y x≯y =
- tri< (₂∼₂ x<y) (x≉y ∘ drop-inj₂) (x≯y ∘ drop-inj₂)
- ... | tri≈ x≮y x≈y x≯y =
- tri≈ (x≮y ∘ drop-inj₂) (₂∼₂ x≈y) (x≯y ∘ drop-inj₂)
- ... | tri> x≮y x≉y x>y =
- tri> (x≮y ∘ drop-inj₂) (x≉y ∘ drop-inj₂) (₂∼₂ x>y)
-
- ----------------------------------------------------------------------
- -- Some collections of properties which are preserved
-
- _⊎-isEquivalence_ : ∀ {ℓ₁ ℓ₂} {≈₁ : Rel A₁ ℓ₁} {≈₂ : Rel A₂ ℓ₂} →
- IsEquivalence ≈₁ → IsEquivalence ≈₂ →
- IsEquivalence (≈₁ ⊎-Rel ≈₂)
- eq₁ ⊎-isEquivalence eq₂ = record
- { refl = refl eq₁ ⊎-refl refl eq₂
- ; sym = sym eq₁ ⊎-symmetric sym eq₂
- ; trans = trans eq₁ ⊎-transitive trans eq₂
- }
- where open IsEquivalence
-
- _⊎-isPreorder_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {∼₁ : Rel A₁ ℓ₁′}
- {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {∼₂ : Rel A₂ ℓ₂′} →
- IsPreorder ≈₁ ∼₁ → IsPreorder ≈₂ ∼₂ →
- ∀ {P} → IsPreorder (≈₁ ⊎-Rel ≈₂) (⊎ʳ P ∼₁ ∼₂)
- pre₁ ⊎-isPreorder pre₂ = record
- { isEquivalence = isEquivalence pre₁ ⊎-isEquivalence
- isEquivalence pre₂
- ; reflexive = reflexive pre₁ ⊎-reflexive reflexive pre₂
- ; trans = trans pre₁ ⊎-transitive trans pre₂
- }
- where open IsPreorder
-
- _⊎-isDecEquivalence_ : ∀ {ℓ₁ ℓ₂} {≈₁ : Rel A₁ ℓ₁} {≈₂ : Rel A₂ ℓ₂} →
- IsDecEquivalence ≈₁ → IsDecEquivalence ≈₂ →
- IsDecEquivalence (≈₁ ⊎-Rel ≈₂)
- eq₁ ⊎-isDecEquivalence eq₂ = record
- { isEquivalence = isEquivalence eq₁ ⊎-isEquivalence
- isEquivalence eq₂
- ; _≟_ = ⊎-decidable (_≟_ eq₁) (_≟_ eq₂) (no ₁≁₂)
- }
- where open IsDecEquivalence
-
- _⊎-isPartialOrder_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {≤₁ : Rel A₁ ℓ₁′}
- {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {≤₂ : Rel A₂ ℓ₂′} →
- IsPartialOrder ≈₁ ≤₁ → IsPartialOrder ≈₂ ≤₂ →
- ∀ {P} → IsPartialOrder (≈₁ ⊎-Rel ≈₂) (⊎ʳ P ≤₁ ≤₂)
- po₁ ⊎-isPartialOrder po₂ = record
- { isPreorder = isPreorder po₁ ⊎-isPreorder isPreorder po₂
- ; antisym = antisym po₁ ⊎-antisymmetric antisym po₂
- }
- where open IsPartialOrder
-
- _⊎-isStrictPartialOrder_ :
- ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {<₁ : Rel A₁ ℓ₁′}
- {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {<₂ : Rel A₂ ℓ₂′} →
- IsStrictPartialOrder ≈₁ <₁ → IsStrictPartialOrder ≈₂ <₂ →
- ∀ {P} → IsStrictPartialOrder (≈₁ ⊎-Rel ≈₂) (⊎ʳ P <₁ <₂)
- spo₁ ⊎-isStrictPartialOrder spo₂ = record
- { isEquivalence = isEquivalence spo₁ ⊎-isEquivalence
- isEquivalence spo₂
- ; irrefl = irrefl spo₁ ⊎-irreflexive irrefl spo₂
- ; trans = trans spo₁ ⊎-transitive trans spo₂
- ; <-resp-≈ = <-resp-≈ spo₁ ⊎-≈-respects₂ <-resp-≈ spo₂
- }
- where open IsStrictPartialOrder
-
- _⊎-<-isTotalOrder_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {≤₁ : Rel A₁ ℓ₁′}
- {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {≤₂ : Rel A₂ ℓ₂′} →
- IsTotalOrder ≈₁ ≤₁ → IsTotalOrder ≈₂ ≤₂ →
- IsTotalOrder (≈₁ ⊎-Rel ≈₂) (≤₁ ⊎-< ≤₂)
- to₁ ⊎-<-isTotalOrder to₂ = record
- { isPartialOrder = isPartialOrder to₁ ⊎-isPartialOrder
- isPartialOrder to₂
- ; total = total to₁ ⊎-<-total total to₂
- }
- where open IsTotalOrder
-
- _⊎-<-isDecTotalOrder_ :
- ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {≤₁ : Rel A₁ ℓ₁′}
- {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {≤₂ : Rel A₂ ℓ₂′} →
- IsDecTotalOrder ≈₁ ≤₁ → IsDecTotalOrder ≈₂ ≤₂ →
- IsDecTotalOrder (≈₁ ⊎-Rel ≈₂) (≤₁ ⊎-< ≤₂)
- to₁ ⊎-<-isDecTotalOrder to₂ = record
- { isTotalOrder = isTotalOrder to₁ ⊎-<-isTotalOrder isTotalOrder to₂
- ; _≟_ = ⊎-decidable (_≟_ to₁) (_≟_ to₂) (no ₁≁₂)
- ; _≤?_ = ⊎-decidable (_≤?_ to₁) (_≤?_ to₂) (yes (₁∼₂ _))
- }
- where open IsDecTotalOrder
-
- _⊎-<-isStrictTotalOrder_ :
- ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {<₁ : Rel A₁ ℓ₁′}
- {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {<₂ : Rel A₂ ℓ₂′} →
- IsStrictTotalOrder ≈₁ <₁ → IsStrictTotalOrder ≈₂ <₂ →
- IsStrictTotalOrder (≈₁ ⊎-Rel ≈₂) (<₁ ⊎-< <₂)
- sto₁ ⊎-<-isStrictTotalOrder sto₂ = record
- { isEquivalence = isEquivalence sto₁ ⊎-isEquivalence
- isEquivalence sto₂
- ; trans = trans sto₁ ⊎-transitive trans sto₂
- ; compare = compare sto₁ ⊎-<-trichotomous compare sto₂
- }
- where open IsStrictTotalOrder
-
-------------------------------------------------------------------------
--- The game can be taken even further...
-
-_⊎-setoid_ : ∀ {s₁ s₂ s₃ s₄} →
- Setoid s₁ s₂ → Setoid s₃ s₄ → Setoid _ _
-s₁ ⊎-setoid s₂ = record
- { isEquivalence = isEquivalence s₁ ⊎-isEquivalence isEquivalence s₂
- } where open Setoid
-
-_⊎-preorder_ : ∀ {p₁ p₂ p₃ p₄ p₅ p₆} →
- Preorder p₁ p₂ p₃ → Preorder p₄ p₅ p₆ → Preorder _ _ _
-p₁ ⊎-preorder p₂ = record
- { _∼_ = _∼_ p₁ ⊎-Rel _∼_ p₂
- ; isPreorder = isPreorder p₁ ⊎-isPreorder isPreorder p₂
- } where open Preorder
-
-_⊎-decSetoid_ : ∀ {s₁ s₂ s₃ s₄} →
- DecSetoid s₁ s₂ → DecSetoid s₃ s₄ → DecSetoid _ _
-ds₁ ⊎-decSetoid ds₂ = record
- { isDecEquivalence = isDecEquivalence ds₁ ⊎-isDecEquivalence
- isDecEquivalence ds₂
- } where open DecSetoid
-
-_⊎-poset_ : ∀ {p₁ p₂ p₃ p₄ p₅ p₆} →
- Poset p₁ p₂ p₃ → Poset p₄ p₅ p₆ → Poset _ _ _
-po₁ ⊎-poset po₂ = record
- { _≤_ = _≤_ po₁ ⊎-Rel _≤_ po₂
- ; isPartialOrder = isPartialOrder po₁ ⊎-isPartialOrder
- isPartialOrder po₂
- } where open Poset
-
-_⊎-<-poset_ : ∀ {p₁ p₂ p₃ p₄ p₅ p₆} →
- Poset p₁ p₂ p₃ → Poset p₄ p₅ p₆ → Poset _ _ _
-po₁ ⊎-<-poset po₂ = record
- { _≤_ = _≤_ po₁ ⊎-< _≤_ po₂
- ; isPartialOrder = isPartialOrder po₁ ⊎-isPartialOrder
- isPartialOrder po₂
- } where open Poset
-
-_⊎-<-strictPartialOrder_ :
- ∀ {p₁ p₂ p₃ p₄ p₅ p₆} →
- StrictPartialOrder p₁ p₂ p₃ → StrictPartialOrder p₄ p₅ p₆ →
- StrictPartialOrder _ _ _
-spo₁ ⊎-<-strictPartialOrder spo₂ = record
- { _<_ = _<_ spo₁ ⊎-< _<_ spo₂
- ; isStrictPartialOrder = isStrictPartialOrder spo₁
- ⊎-isStrictPartialOrder
- isStrictPartialOrder spo₂
- } where open StrictPartialOrder
-
-_⊎-<-totalOrder_ :
- ∀ {t₁ t₂ t₃ t₄ t₅ t₆} →
- TotalOrder t₁ t₂ t₃ → TotalOrder t₄ t₅ t₆ → TotalOrder _ _ _
-to₁ ⊎-<-totalOrder to₂ = record
- { isTotalOrder = isTotalOrder to₁ ⊎-<-isTotalOrder isTotalOrder to₂
- } where open TotalOrder
-
-_⊎-<-decTotalOrder_ :
- ∀ {t₁ t₂ t₃ t₄ t₅ t₆} →
- DecTotalOrder t₁ t₂ t₃ → DecTotalOrder t₄ t₅ t₆ → DecTotalOrder _ _ _
-to₁ ⊎-<-decTotalOrder to₂ = record
- { isDecTotalOrder = isDecTotalOrder to₁ ⊎-<-isDecTotalOrder
- isDecTotalOrder to₂
- } where open DecTotalOrder
-
-_⊎-<-strictTotalOrder_ :
- ∀ {p₁ p₂ p₃ p₄ p₅ p₆} →
- StrictTotalOrder p₁ p₂ p₃ → StrictTotalOrder p₄ p₅ p₆ →
- StrictTotalOrder _ _ _
-sto₁ ⊎-<-strictTotalOrder sto₂ = record
- { _<_ = _<_ sto₁ ⊎-< _<_ sto₂
- ; isStrictTotalOrder = isStrictTotalOrder sto₁
- ⊎-<-isStrictTotalOrder
- isStrictTotalOrder sto₂
- } where open StrictTotalOrder
-
-------------------------------------------------------------------------
--- Some properties related to "relatedness"
-
-private
-
- to-cong : ∀ {a b} {A : Set a} {B : Set b} →
- (_≡_ ⊎-Rel _≡_) ⇒ _≡_ {A = A ⊎ B}
- to-cong (₁∼₂ ())
- to-cong (₁∼₁ P.refl) = P.refl
- to-cong (₂∼₂ P.refl) = P.refl
-
- from-cong : ∀ {a b} {A : Set a} {B : Set b} →
- _≡_ {A = A ⊎ B} ⇒ (_≡_ ⊎-Rel _≡_)
- from-cong P.refl = P.refl ⊎-refl P.refl
-
-⊎-Rel↔≡ : ∀ {a b} (A : Set a) (B : Set b) →
- Inverse (P.setoid A ⊎-setoid P.setoid B) (P.setoid (A ⊎ B))
-⊎-Rel↔≡ _ _ = record
- { to = record { _⟨$⟩_ = id; cong = to-cong }
- ; from = record { _⟨$⟩_ = id; cong = from-cong }
- ; inverse-of = record
- { left-inverse-of = λ _ → P.refl ⊎-refl P.refl
- ; right-inverse-of = λ _ → P.refl
- }
- }
-
-_⊎-≟_ : ∀ {a b} {A : Set a} {B : Set b} →
- Decidable {A = A} _≡_ → Decidable {A = B} _≡_ →
- Decidable {A = A ⊎ B} _≡_
-(dec₁ ⊎-≟ dec₂) s₁ s₂ = Dec.map′ to-cong from-cong (s₁ ≟ s₂)
- where
- open DecSetoid (P.decSetoid dec₁ ⊎-decSetoid P.decSetoid dec₂)
-
-_⊎-⟶_ :
- ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈}
- {A : Setoid s₁ s₂} {B : Setoid s₃ s₄}
- {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} →
- A ⟶ B → C ⟶ D → (A ⊎-setoid C) ⟶ (B ⊎-setoid D)
-_⊎-⟶_ {A = A} {B} {C} {D} f g = record
- { _⟨$⟩_ = fg
- ; cong = fg-cong
- }
- where
- open Setoid (A ⊎-setoid C) using () renaming (_≈_ to _≈AC_)
- open Setoid (B ⊎-setoid D) using () renaming (_≈_ to _≈BD_)
-
- fg = Sum.map (_⟨$⟩_ f) (_⟨$⟩_ g)
-
- fg-cong : _≈AC_ =[ fg ]⇒ _≈BD_
- fg-cong (₁∼₂ ())
- fg-cong (₁∼₁ x∼₁y) = ₁∼₁ $ F.cong f x∼₁y
- fg-cong (₂∼₂ x∼₂y) = ₂∼₂ $ F.cong g x∼₂y
-
-_⊎-equivalence_ :
- ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈}
- {A : Setoid s₁ s₂} {B : Setoid s₃ s₄}
- {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} →
- Equivalence A B → Equivalence C D →
- Equivalence (A ⊎-setoid C) (B ⊎-setoid D)
-A⇔B ⊎-equivalence C⇔D = record
- { to = to A⇔B ⊎-⟶ to C⇔D
- ; from = from A⇔B ⊎-⟶ from C⇔D
- } where open Equivalence
-
-_⊎-⇔_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
- A ⇔ B → C ⇔ D → (A ⊎ C) ⇔ (B ⊎ D)
-_⊎-⇔_ {A = A} {B} {C} {D} A⇔B C⇔D =
- Inverse.equivalence (⊎-Rel↔≡ B D) ⟨∘⟩
- (A⇔B ⊎-equivalence C⇔D) ⟨∘⟩
- Eq.sym (Inverse.equivalence (⊎-Rel↔≡ A C))
- where open Eq using () renaming (_∘_ to _⟨∘⟩_)
-
-_⊎-injection_ :
- ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈}
- {A : Setoid s₁ s₂} {B : Setoid s₃ s₄}
- {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} →
- Injection A B → Injection C D →
- Injection (A ⊎-setoid C) (B ⊎-setoid D)
-_⊎-injection_ {A = A} {B} {C} {D} A↣B C↣D = record
- { to = to A↣B ⊎-⟶ to C↣D
- ; injective = inj _ _
- }
- where
- open Injection
- open Setoid (A ⊎-setoid C) using () renaming (_≈_ to _≈AC_)
- open Setoid (B ⊎-setoid D) using () renaming (_≈_ to _≈BD_)
-
- inj : ∀ x y →
- (to A↣B ⊎-⟶ to C↣D) ⟨$⟩ x ≈BD (to A↣B ⊎-⟶ to C↣D) ⟨$⟩ y →
- x ≈AC y
- inj (inj₁ x) (inj₁ y) (₁∼₁ x∼₁y) = ₁∼₁ (injective A↣B x∼₁y)
- inj (inj₂ x) (inj₂ y) (₂∼₂ x∼₂y) = ₂∼₂ (injective C↣D x∼₂y)
- inj (inj₁ x) (inj₂ y) (₁∼₂ ())
- inj (inj₂ x) (inj₁ y) ()
-
-_⊎-↣_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
- A ↣ B → C ↣ D → (A ⊎ C) ↣ (B ⊎ D)
-_⊎-↣_ {A = A} {B} {C} {D} A↣B C↣D =
- Inverse.injection (⊎-Rel↔≡ B D) ⟨∘⟩
- (A↣B ⊎-injection C↣D) ⟨∘⟩
- Inverse.injection (Inv.sym (⊎-Rel↔≡ A C))
- where open Inj using () renaming (_∘_ to _⟨∘⟩_)
-
-_⊎-left-inverse_ :
- ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈}
- {A : Setoid s₁ s₂} {B : Setoid s₃ s₄}
- {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} →
- LeftInverse A B → LeftInverse C D →
- LeftInverse (A ⊎-setoid C) (B ⊎-setoid D)
-A↞B ⊎-left-inverse C↞D = record
- { to = Equivalence.to eq
- ; from = Equivalence.from eq
- ; left-inverse-of = [ ₁∼₁ ∘ left-inverse-of A↞B
- , ₂∼₂ ∘ left-inverse-of C↞D
- ]
- }
- where
- open LeftInverse
- eq = LeftInverse.equivalence A↞B ⊎-equivalence
- LeftInverse.equivalence C↞D
-
-_⊎-↞_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
- A ↞ B → C ↞ D → (A ⊎ C) ↞ (B ⊎ D)
-_⊎-↞_ {A = A} {B} {C} {D} A↞B C↞D =
- Inverse.left-inverse (⊎-Rel↔≡ B D) ⟨∘⟩
- (A↞B ⊎-left-inverse C↞D) ⟨∘⟩
- Inverse.left-inverse (Inv.sym (⊎-Rel↔≡ A C))
- where open LeftInv using () renaming (_∘_ to _⟨∘⟩_)
-
-_⊎-surjection_ :
- ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈}
- {A : Setoid s₁ s₂} {B : Setoid s₃ s₄}
- {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} →
- Surjection A B → Surjection C D →
- Surjection (A ⊎-setoid C) (B ⊎-setoid D)
-A↠B ⊎-surjection C↠D = record
- { to = LeftInverse.from inv
- ; surjective = record
- { from = LeftInverse.to inv
- ; right-inverse-of = LeftInverse.left-inverse-of inv
- }
- }
- where
- open Surjection
- inv = right-inverse A↠B ⊎-left-inverse right-inverse C↠D
-
-_⊎-↠_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
- A ↠ B → C ↠ D → (A ⊎ C) ↠ (B ⊎ D)
-_⊎-↠_ {A = A} {B} {C} {D} A↠B C↠D =
- Inverse.surjection (⊎-Rel↔≡ B D) ⟨∘⟩
- (A↠B ⊎-surjection C↠D) ⟨∘⟩
- Inverse.surjection (Inv.sym (⊎-Rel↔≡ A C))
- where open Surj using () renaming (_∘_ to _⟨∘⟩_)
-
-_⊎-inverse_ :
- ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈}
- {A : Setoid s₁ s₂} {B : Setoid s₃ s₄}
- {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} →
- Inverse A B → Inverse C D → Inverse (A ⊎-setoid C) (B ⊎-setoid D)
-A↔B ⊎-inverse C↔D = record
- { to = Surjection.to surj
- ; from = Surjection.from surj
- ; inverse-of = record
- { left-inverse-of = LeftInverse.left-inverse-of inv
- ; right-inverse-of = Surjection.right-inverse-of surj
- }
- }
- where
- open Inverse
- surj = Inverse.surjection A↔B ⊎-surjection
- Inverse.surjection C↔D
- inv = Inverse.left-inverse A↔B ⊎-left-inverse
- Inverse.left-inverse C↔D
-
-_⊎-↔_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
- A ↔ B → C ↔ D → (A ⊎ C) ↔ (B ⊎ D)
-_⊎-↔_ {A = A} {B} {C} {D} A↔B C↔D =
- ⊎-Rel↔≡ B D ⟨∘⟩ (A↔B ⊎-inverse C↔D) ⟨∘⟩ Inv.sym (⊎-Rel↔≡ A C)
- where open Inv using () renaming (_∘_ to _⟨∘⟩_)
-
-_⊎-cong_ : ∀ {k a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
- A ∼[ k ] B → C ∼[ k ] D → (A ⊎ C) ∼[ k ] (B ⊎ D)
-_⊎-cong_ {implication} = Sum.map
-_⊎-cong_ {reverse-implication} = λ f g → lam (Sum.map (app-← f) (app-← g))
-_⊎-cong_ {equivalence} = _⊎-⇔_
-_⊎-cong_ {injection} = _⊎-↣_
-_⊎-cong_ {reverse-injection} = λ f g → lam (app-↢ f ⊎-↣ app-↢ g)
-_⊎-cong_ {left-inverse} = _⊎-↞_
-_⊎-cong_ {surjection} = _⊎-↠_
-_⊎-cong_ {bijection} = _⊎-↔_
+open import Data.Sum.Relation.Core public
+
+open import Data.Sum.Relation.Pointwise public
+ renaming
+ ( Pointwise to _⊎-Rel_
+ ; ⊎-symmetric to _⊎-symmetric_
+ ; ⊎-substitutive to _⊎-substitutive_
+ ; ⊎-isEquivalence to _⊎-isEquivalence_
+ ; ⊎-isDecEquivalence to _⊎-isDecEquivalence_
+ ; ⊎-setoid to _⊎-setoid_
+ ; ⊎-decSetoid to _⊎-decSetoid_
+ ; Pointwise-≡↔≡ to ⊎-Rel↔≡
+ )
+ hiding
+ ( ⊎-decidable
+ )
+
+open import Data.Sum.Relation.LeftOrder public
+ using ()
+ renaming
+ ( ⊎-<-total to _⊎-<-total_
+ ; ⊎-<-trichotomous to _⊎-<-trichotomous_
+ ; ⊎-<-isTotalOrder to _⊎-<-isTotalOrder_
+ ; ⊎-<-isDecTotalOrder to _⊎-<-isDecTotalOrder_
+ ; ⊎-<-isStrictTotalOrder to _⊎-<-isStrictTotalOrder_
+ ; ⊎-<-poset to _⊎-<-poset_
+ ; ⊎-<-strictPartialOrder to _⊎-<-strictPartialOrder_
+ ; ⊎-<-totalOrder to _⊎-<-totalOrder_
+ ; ⊎-<-decTotalOrder to _⊎-<-decTotalOrder_
+ ; ⊎-<-strictTotalOrder to _⊎-<-strictTotalOrder_
+ )
diff --git a/src/Relation/Binary/SymmetricClosure.agda b/src/Relation/Binary/SymmetricClosure.agda
index c45c06d..818f7d2 100644
--- a/src/Relation/Binary/SymmetricClosure.agda
+++ b/src/Relation/Binary/SymmetricClosure.agda
@@ -2,35 +2,11 @@
-- The Agda standard library
--
-- Symmetric closures of binary relations
+--
+-- This module is DEPRECATED. Please use the
+-- Relation.Binary.Construct.Closure.Symmetric module directly.
------------------------------------------------------------------------
module Relation.Binary.SymmetricClosure where
-open import Data.Sum as Sum using (_⊎_)
-open import Function using (id)
-open import Relation.Binary
-
-open Sum public using () renaming (inj₁ to fwd; inj₂ to bwd)
-
--- The symmetric closure of a relation.
-
-SymClosure : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Rel A ℓ
-SymClosure _∼_ a b = a ∼ b ⊎ b ∼ a
-
-module _ {a ℓ} {A : Set a} where
-
- -- Symmetric closures are symmetric.
-
- symmetric : (_∼_ : Rel A ℓ) → Symmetric (SymClosure _∼_)
- symmetric _ (fwd a∼b) = bwd a∼b
- symmetric _ (bwd b∼a) = fwd b∼a
-
- -- A generalised variant of map which allows the index type to change.
-
- gmap : ∀ {b ℓ₂} {B : Set b} {P : Rel A ℓ} {Q : Rel B ℓ₂} →
- (f : A → B) → P =[ f ]⇒ Q → SymClosure P =[ f ]⇒ SymClosure Q
- gmap _ g = Sum.map g g
-
- map : ∀ {ℓ₂} {P : Rel A ℓ} {Q : Rel A ℓ₂} →
- P ⇒ Q → SymClosure P ⇒ SymClosure Q
- map = gmap id
+open import Relation.Binary.Construct.Closure.Symmetric public
diff --git a/src/Relation/Binary/Vec/Pointwise.agda b/src/Relation/Binary/Vec/Pointwise.agda
index f944ea2..d1a08bd 100644
--- a/src/Relation/Binary/Vec/Pointwise.agda
+++ b/src/Relation/Binary/Vec/Pointwise.agda
@@ -1,233 +1,15 @@
------------------------------------------------------------------------
-- The Agda standard library
--
--- Pointwise lifting of relations to vectors
+-- This module is DEPRECATED.
+--
+-- Please use Data.Vec.Relation.Pointwise.Inductive
+-- and Data.Vec.Relation.Pointwise.Extensional directly.
------------------------------------------------------------------------
module Relation.Binary.Vec.Pointwise where
-open import Category.Functor
-open import Data.Fin
-open import Data.Nat
-open import Data.Plus as Plus hiding (equivalent; map)
-open import Data.Vec as Vec hiding ([_]; head; tail; map)
-import Data.Vec.Properties as VecProp
-open import Function
-open import Function.Equality using (_⟨$⟩_)
-open import Function.Equivalence as Equiv
- using (_⇔_; ⇔-setoid; module Equivalence)
-import Level
-open import Relation.Binary
-open import Relation.Binary.PropositionalEquality as P using (_≡_)
-open import Relation.Nullary
-import Relation.Nullary.Decidable as Dec
-
--- Functional definition.
-
-record Pointwise {ℓ} {A B : Set ℓ} (_∼_ : REL A B ℓ)
- {n} (xs : Vec A n) (ys : Vec B n) : Set ℓ where
- constructor ext
- field app : ∀ i → lookup i xs ∼ lookup i ys
-
--- Inductive definition.
-
-infixr 5 _∷_
-
-data Pointwise′ {ℓ} {A B : Set ℓ} (_∼_ : REL A B ℓ) :
- ∀ {n} (xs : Vec A n) (ys : Vec B n) → Set ℓ where
- [] : Pointwise′ _∼_ [] []
- _∷_ : ∀ {n x y} {xs : Vec A n} {ys : Vec B n}
- (x∼y : x ∼ y) (xs∼ys : Pointwise′ _∼_ xs ys) →
- Pointwise′ _∼_ (x ∷ xs) (y ∷ ys)
-
--- The two definitions are equivalent.
-
-equivalent : ∀ {ℓ} {A B : Set ℓ} {_∼_ : REL A B ℓ} {n}
- {xs : Vec A n} {ys : Vec B n} →
- Pointwise _∼_ xs ys ⇔ Pointwise′ _∼_ xs ys
-equivalent {A = A} {B} {_∼_} = Equiv.equivalence (to _ _) from
- where
- to : ∀ {n} (xs : Vec A n) (ys : Vec B n) →
- Pointwise _∼_ xs ys → Pointwise′ _∼_ xs ys
- to [] [] xs∼ys = []
- to (x ∷ xs) (y ∷ ys) xs∼ys =
- Pointwise.app xs∼ys zero ∷
- to xs ys (ext (Pointwise.app xs∼ys ∘ suc))
-
- nil : Pointwise _∼_ [] []
- nil = ext λ()
-
- cons : ∀ {n x y} {xs : Vec A n} {ys : Vec B n} →
- x ∼ y → Pointwise _∼_ xs ys → Pointwise _∼_ (x ∷ xs) (y ∷ ys)
- cons {x = x} {y} {xs} {ys} x∼y xs∼ys = ext helper
- where
- helper : ∀ i → lookup i (x ∷ xs) ∼ lookup i (y ∷ ys)
- helper zero = x∼y
- helper (suc i) = Pointwise.app xs∼ys i
-
- from : ∀ {n} {xs : Vec A n} {ys : Vec B n} →
- Pointwise′ _∼_ xs ys → Pointwise _∼_ xs ys
- from [] = nil
- from (x∼y ∷ xs∼ys) = cons x∼y (from xs∼ys)
-
--- Some destructors.
-
-head : ∀ {ℓ} {A B : Set ℓ} {_∼_ : REL A B ℓ} {n x y xs} {ys : Vec B n} →
- Pointwise′ _∼_ (x ∷ xs) (y ∷ ys) → x ∼ y
-head (x∼y ∷ xs∼ys) = x∼y
-
-tail : ∀ {ℓ} {A B : Set ℓ} {_∼_ : REL A B ℓ} {n x y xs} {ys : Vec B n} →
- Pointwise′ _∼_ (x ∷ xs) (y ∷ ys) → Pointwise′ _∼_ xs ys
-tail (x∼y ∷ xs∼ys) = xs∼ys
-
--- Pointwise preserves reflexivity.
-
-refl : ∀ {ℓ} {A : Set ℓ} {_∼_ : Rel A ℓ} {n} →
- Reflexive _∼_ → Reflexive (Pointwise _∼_ {n = n})
-refl rfl = ext (λ _ → rfl)
-
--- Pointwise preserves symmetry.
-
-sym : ∀ {ℓ} {A B : Set ℓ} {P : REL A B ℓ} {Q : REL B A ℓ} {n} →
- Sym P Q → Sym (Pointwise P) (Pointwise Q {n = n})
-sym sm xs∼ys = ext λ i → sm (Pointwise.app xs∼ys i)
-
--- Pointwise preserves transitivity.
-
-trans : ∀ {ℓ} {A B C : Set ℓ}
- {P : REL A B ℓ} {Q : REL B C ℓ} {R : REL A C ℓ} {n} →
- Trans P Q R →
- Trans (Pointwise P) (Pointwise Q) (Pointwise R {n = n})
-trans trns xs∼ys ys∼zs = ext λ i →
- trns (Pointwise.app xs∼ys i) (Pointwise.app ys∼zs i)
-
--- Pointwise preserves equivalences.
-
-isEquivalence :
- ∀ {ℓ} {A : Set ℓ} {_∼_ : Rel A ℓ} {n} →
- IsEquivalence _∼_ → IsEquivalence (Pointwise _∼_ {n = n})
-isEquivalence equiv = record
- { refl = refl (IsEquivalence.refl equiv)
- ; sym = sym (IsEquivalence.sym equiv)
- ; trans = trans (IsEquivalence.trans equiv)
- }
-
--- Pointwise preserves decidability.
-
-decidable : ∀ {ℓ} {A B : Set ℓ} {_∼_ : REL A B ℓ} →
- Decidable _∼_ → ∀ {n} → Decidable (Pointwise _∼_ {n = n})
-decidable {_∼_ = _∼_} dec xs ys =
- Dec.map (Setoid.sym (⇔-setoid _) equivalent) (decidable′ xs ys)
- where
- decidable′ : ∀ {n} → Decidable (Pointwise′ _∼_ {n = n})
- decidable′ [] [] = yes []
- decidable′ (x ∷ xs) (y ∷ ys) with dec x y
- ... | no ¬x∼y = no (¬x∼y ∘ head)
- ... | yes x∼y with decidable′ xs ys
- ... | no ¬xs∼ys = no (¬xs∼ys ∘ tail)
- ... | yes xs∼ys = yes (x∼y ∷ xs∼ys)
-
--- Pointwise _≡_ is equivalent to _≡_.
-
-Pointwise-≡ : ∀ {ℓ} {A : Set ℓ} {n} {xs ys : Vec A n} →
- Pointwise _≡_ xs ys ⇔ xs ≡ ys
-Pointwise-≡ {ℓ} {A} =
- Equiv.equivalence
- (to ∘ _⟨$⟩_ {f₂ = ℓ} (Equivalence.to equivalent))
- (λ xs≡ys → P.subst (Pointwise _≡_ _) xs≡ys (refl P.refl))
- where
- to : ∀ {n} {xs ys : Vec A n} → Pointwise′ _≡_ xs ys → xs ≡ ys
- to [] = P.refl
- to (P.refl ∷ xs∼ys) = P.cong (_∷_ _) $ to xs∼ys
-
--- Pointwise and Plus commute when the underlying relation is
--- reflexive.
-
-⁺∙⇒∙⁺ : ∀ {ℓ} {A : Set ℓ} {_∼_ : Rel A ℓ} {n} {xs ys : Vec A n} →
- Plus (Pointwise _∼_) xs ys → Pointwise (Plus _∼_) xs ys
-⁺∙⇒∙⁺ [ ρ≈ρ′ ] = ext (λ x → [ Pointwise.app ρ≈ρ′ x ])
-⁺∙⇒∙⁺ (ρ ∼⁺⟨ ρ≈ρ′ ⟩ ρ′≈ρ″) =
- ext (λ x → _ ∼⁺⟨ Pointwise.app (⁺∙⇒∙⁺ ρ≈ρ′ ) x ⟩
- Pointwise.app (⁺∙⇒∙⁺ ρ′≈ρ″) x)
-
-∙⁺⇒⁺∙ : ∀ {ℓ} {A : Set ℓ} {_∼_ : Rel A ℓ} {n} {xs ys : Vec A n} →
- Reflexive _∼_ →
- Pointwise (Plus _∼_) xs ys → Plus (Pointwise _∼_) xs ys
-∙⁺⇒⁺∙ {ℓ} {A} {_∼_} x∼x =
- Plus.map (_⟨$⟩_ {f₂ = ℓ} (Equivalence.from equivalent)) ∘
- helper ∘
- _⟨$⟩_ {f₂ = ℓ} (Equivalence.to equivalent)
- where
- helper : ∀ {n} {xs ys : Vec A n} →
- Pointwise′ (Plus _∼_) xs ys → Plus (Pointwise′ _∼_) xs ys
- helper [] = [ [] ]
- helper (_∷_ {x = x} {y = y} {xs = xs} {ys = ys} x∼y xs∼ys) =
- x ∷ xs ∼⁺⟨ Plus.map (λ x∼y → x∼y ∷ xs∼xs) x∼y ⟩
- y ∷ xs ∼⁺⟨ Plus.map (λ xs∼ys → x∼x ∷ xs∼ys) (helper xs∼ys) ⟩∎
- y ∷ ys ∎
- where
- xs∼xs : Pointwise′ _∼_ xs xs
- xs∼xs = _⟨$⟩_ {f₂ = ℓ} (Equivalence.to equivalent) (refl x∼x)
-
--- Note that ∙⁺⇒⁺∙ cannot be defined if the requirement of reflexivity
--- is dropped.
-
-private
-
- module Counterexample where
-
- data D : Set where
- i j x y z : D
-
- data _R_ : Rel D Level.zero where
- iRj : i R j
- xRy : x R y
- yRz : y R z
-
- xR⁺z : x [ _R_ ]⁺ z
- xR⁺z =
- x ∼⁺⟨ [ xRy ] ⟩
- y ∼⁺⟨ [ yRz ] ⟩∎
- z ∎
-
- ix : Vec D 2
- ix = i ∷ x ∷ []
-
- jz : Vec D 2
- jz = j ∷ z ∷ []
-
- ix∙⁺jz : Pointwise′ (Plus _R_) ix jz
- ix∙⁺jz = [ iRj ] ∷ xR⁺z ∷ []
-
- ¬ix⁺∙jz : ¬ Plus′ (Pointwise′ _R_) ix jz
- ¬ix⁺∙jz [ iRj ∷ () ∷ [] ]
- ¬ix⁺∙jz ((iRj ∷ xRy ∷ []) ∷ [ () ∷ yRz ∷ [] ])
- ¬ix⁺∙jz ((iRj ∷ xRy ∷ []) ∷ (() ∷ yRz ∷ []) ∷ _)
-
- counterexample :
- ¬ (∀ {n} {xs ys : Vec D n} →
- Pointwise (Plus _R_) xs ys →
- Plus (Pointwise _R_) xs ys)
- counterexample ∙⁺⇒⁺∙ =
- ¬ix⁺∙jz (Equivalence.to Plus.equivalent ⟨$⟩
- Plus.map (_⟨$⟩_ (Equivalence.to equivalent))
- (∙⁺⇒⁺∙ (Equivalence.from equivalent ⟨$⟩ ix∙⁺jz)))
-
--- Map.
-
-map : ∀ {ℓ} {A : Set ℓ} {_R_ _R′_ : Rel A ℓ} {n} →
- _R_ ⇒ _R′_ → Pointwise _R_ ⇒ Pointwise _R′_ {n}
-map R⇒R′ xsRys = ext λ i →
- R⇒R′ (Pointwise.app xsRys i)
-
--- A variant.
-
-gmap : ∀ {ℓ} {A A′ : Set ℓ}
- {_R_ : Rel A ℓ} {_R′_ : Rel A′ ℓ} {f : A → A′} {n} →
- _R_ =[ f ]⇒ _R′_ →
- Pointwise _R_ =[ Vec.map {n = n} f ]⇒ Pointwise _R′_
-gmap {_R′_ = _R′_} {f} R⇒R′ {i = xs} {j = ys} xsRys = ext λ i →
- let module M = Morphism (VecProp.lookup-functor-morphism i) in
- P.subst₂ _R′_ (P.sym $ M.op-<$> f xs)
- (P.sym $ M.op-<$> f ys)
- (R⇒R′ (Pointwise.app xsRys i))
+open import Data.Vec.Relation.Pointwise.Inductive public
+ hiding (head; tail)
+open import Data.Vec.Relation.Pointwise.Extensional public
+ using (head; tail) renaming (Pointwise to Pointwise′)
diff --git a/src/Relation/Nullary.agda b/src/Relation/Nullary.agda
index b0f08b8..8713416 100644
--- a/src/Relation/Nullary.agda
+++ b/src/Relation/Nullary.agda
@@ -8,7 +8,8 @@
module Relation.Nullary where
-open import Data.Empty
+open import Data.Empty hiding (⊥-elim)
+open import Data.Empty.Irrelevant
open import Level
-- Negation.
@@ -23,3 +24,10 @@ infix 3 ¬_
data Dec {p} (P : Set p) : Set p where
yes : ( p : P) → Dec P
no : (¬p : ¬ P) → Dec P
+
+-- Given an irrelevant proof of a decidable type, a proof can
+-- be recomputed and subsequently used in relevant contexts.
+recompute : ∀ {a} {A : Set a} → Dec A → .A → A
+recompute (yes x) _ = x
+recompute (no ¬p) x = ⊥-elim (¬p x)
+
diff --git a/src/Relation/Nullary/Decidable.agda b/src/Relation/Nullary/Decidable.agda
index ad5cadf..f1a83a3 100644
--- a/src/Relation/Nullary/Decidable.agda
+++ b/src/Relation/Nullary/Decidable.agda
@@ -78,21 +78,23 @@ module _ {a₁ a₂ b₁ b₂} {A : Setoid a₁ a₂} {B : Setoid b₁ b₂} whe
-- If a decision procedure returns "yes", then we can extract the
-- proof using from-yes.
-From-yes : ∀ {p} {P : Set p} → Dec P → Set p
-From-yes {P = P} (yes _) = P
-From-yes (no _) = Lift ⊤
+module _ {p} {P : Set p} where
-from-yes : ∀ {p} {P : Set p} (p : Dec P) → From-yes p
-from-yes (yes p) = p
-from-yes (no _) = _
+ From-yes : Dec P → Set p
+ From-yes (yes _) = P
+ From-yes (no _) = Lift p ⊤
+
+ from-yes : (p : Dec P) → From-yes p
+ from-yes (yes p) = p
+ from-yes (no _) = _
-- If a decision procedure returns "no", then we can extract the proof
-- using from-no.
-From-no : ∀ {p} {P : Set p} → Dec P → Set p
-From-no {P = P} (no _) = ¬ P
-From-no (yes _) = Lift ⊤
+ From-no : Dec P → Set p
+ From-no (no _) = ¬ P
+ From-no (yes _) = Lift p ⊤
-from-no : ∀ {p} {P : Set p} (p : Dec P) → From-no p
-from-no (no ¬p) = ¬p
-from-no (yes _) = _
+ from-no : (p : Dec P) → From-no p
+ from-no (no ¬p) = ¬p
+ from-no (yes _) = _
diff --git a/src/Relation/Nullary/Negation.agda b/src/Relation/Nullary/Negation.agda
index 1376f2b..6da57ec 100644
--- a/src/Relation/Nullary/Negation.agda
+++ b/src/Relation/Nullary/Negation.agda
@@ -6,15 +6,15 @@
module Relation.Nullary.Negation where
-open import Relation.Nullary
-open import Relation.Unary
+open import Category.Monad
open import Data.Bool.Base using (Bool; false; true; if_then_else_)
open import Data.Empty
-open import Function
open import Data.Product as Prod
-open import Data.Sum as Sum
-open import Category.Monad
+open import Data.Sum as Sum using (_⊎_; inj₁; inj₂; [_,_])
+open import Function
open import Level
+open import Relation.Nullary
+open import Relation.Unary
contradiction : ∀ {p w} {P : Set p} {Whatever : Set w} →
P → ¬ P → Whatever
diff --git a/src/Relation/Nullary/Universe.agda b/src/Relation/Nullary/Universe.agda
index c85f858..092e2cf 100644
--- a/src/Relation/Nullary/Universe.agda
+++ b/src/Relation/Nullary/Universe.agda
@@ -9,13 +9,15 @@ module Relation.Nullary.Universe where
open import Relation.Nullary
open import Relation.Nullary.Negation
open import Relation.Binary hiding (_⇒_)
-open import Relation.Binary.Simple
+import Relation.Binary.Construct.Always as Always
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; refl)
-open import Relation.Binary.Sum
-open import Relation.Binary.Product.Pointwise
+import Relation.Binary.Indexed.Heterogeneous.Construct.Trivial
+ as Trivial
open import Data.Sum as Sum hiding (map)
+open import Data.Sum.Relation.Pointwise
open import Data.Product as Prod hiding (map)
+open import Data.Product.Relation.Pointwise.NonDependent
open import Function
import Function.Equality as FunS
open import Data.Empty
@@ -46,11 +48,11 @@ mutual
setoid : ∀ {p} → PropF p → Set p → Setoid p p
setoid Id P = PropEq.setoid P
setoid (K P) _ = PropEq.setoid P
- setoid (F₁ ∨ F₂) P = (setoid F₁ P) ⊎-setoid (setoid F₂ P)
- setoid (F₁ ∧ F₂) P = (setoid F₁ P) ×-setoid (setoid F₂ P)
+ setoid (F₁ ∨ F₂) P = (setoid F₁ P) ⊎ₛ (setoid F₂ P)
+ setoid (F₁ ∧ F₂) P = (setoid F₁ P) ×ₛ (setoid F₂ P)
setoid (P₁ ⇒ F₂) P = FunS.≡-setoid P₁
- (Setoid.indexedSetoid (setoid F₂ P))
- setoid (¬¬ F) P = Always-setoid (¬ ¬ ⟦ F ⟧ P)
+ (Trivial.indexedSetoid (setoid F₂ P))
+ setoid (¬¬ F) P = Always.setoid (¬ ¬ ⟦ F ⟧ P) _
⟦_⟧ : ∀ {p} → PropF p → (Set p → Set p)
⟦ F ⟧ P = Setoid.Carrier (setoid F P)
@@ -91,7 +93,7 @@ map-∘ (¬¬ F) f g x = _
-- A variant of sequence can be implemented for ⟦ F ⟧.
sequence : ∀ {p AF} → RawApplicative AF →
- (AF (Lift ⊥) → ⊥) →
+ (AF (Lift p ⊥) → ⊥) →
({A B : Set p} → (A → AF B) → AF (A → B)) →
∀ F {P} → ⟦ F ⟧ (AF P) → AF (⟦ F ⟧ P)
sequence {AF = AF} A extract-⊥ sequence-⇒ = helper
diff --git a/src/Relation/Unary.agda b/src/Relation/Unary.agda
index 00b9976..eba770d 100644
--- a/src/Relation/Unary.agda
+++ b/src/Relation/Unary.agda
@@ -7,13 +7,13 @@
module Relation.Unary where
open import Data.Empty
-open import Function
open import Data.Unit.Base using (⊤)
open import Data.Product
-open import Data.Sum
+open import Data.Sum using (_⊎_; [_,_])
+open import Function
open import Level
open import Relation.Nullary
-open import Relation.Binary.Core using (_≡_)
+open import Relation.Binary.PropositionalEquality.Core using (_≡_)
------------------------------------------------------------------------
-- Unary relations
@@ -23,13 +23,30 @@ Pred A ℓ = A → Set ℓ
------------------------------------------------------------------------
-- Unary relations can be seen as sets
+-- i.e. they can be seen as subsets of the universe of discourse.
+
+module _ {a} {A : Set a} where
--- I.e., they can be seen as subsets of the universe of discourse.
+ ----------------------------------------------------------------------
+ -- Special sets
-module _ {a} {A : Set a} -- The universe of discourse.
- where
+ -- The empty set
+
+ ∅ : Pred A zero
+ ∅ = λ _ → ⊥
+
+ -- The singleton set
+
+ {_} : A → Pred A a
+ { x } = x ≡_
- -- Set membership.
+ -- The universe
+
+ U : Pred A zero
+ U = λ _ → ⊤
+
+ ----------------------------------------------------------------------
+ -- Membership
infix 4 _∈_ _∉_
@@ -39,68 +56,105 @@ module _ {a} {A : Set a} -- The universe of discourse.
_∉_ : ∀ {ℓ} → A → Pred A ℓ → Set _
x ∉ P = ¬ x ∈ P
- -- The empty set.
+ ----------------------------------------------------------------------
+ -- Subsets
- ∅ : Pred A zero
- ∅ = λ _ → ⊥
+ infix 4 _⊆_ _⊇_ _⊈_ _⊉_ _⊂_ _⊃_ _⊄_ _⊅_
- -- The property of being empty.
+ _⊆_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
+ P ⊆ Q = ∀ {x} → x ∈ P → x ∈ Q
- Empty : ∀ {ℓ} → Pred A ℓ → Set _
- Empty P = ∀ x → x ∉ P
+ _⊇_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
+ P ⊇ Q = Q ⊆ P
- ∅-Empty : Empty ∅
- ∅-Empty x ()
+ _⊈_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
+ P ⊈ Q = ¬ (P ⊆ Q)
- -- The singleton set.
- {_} : A → Pred A a
- { x } = _≡_ x
+ _⊉_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
+ P ⊉ Q = ¬ (P ⊇ Q)
- -- The universe, i.e. the subset containing all elements in A.
+ _⊂_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
+ P ⊂ Q = P ⊆ Q × Q ⊈ P
- U : Pred A zero
- U = λ _ → ⊤
+ _⊃_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
+ P ⊃ Q = Q ⊂ P
- -- The property of being universal.
+ _⊄_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
+ P ⊄ Q = ¬ (P ⊂ Q)
- Universal : ∀ {ℓ} → Pred A ℓ → Set _
- Universal P = ∀ x → x ∈ P
+ _⊅_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
+ P ⊅ Q = ¬ (P ⊃ Q)
- U-Universal : Universal U
- U-Universal = λ _ → _
+ -- Dashed variants of _⊆_ for when 'x' can't be inferred from 'x ∈ P'.
- -- Set complement.
+ infix 4 _⊆′_ _⊇′_ _⊈′_ _⊉′_ _⊂′_ _⊃′_ _⊄′_ _⊅′_
- ∁ : ∀ {ℓ} → Pred A ℓ → Pred A ℓ
- ∁ P = λ x → x ∉ P
+ _⊆′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
+ P ⊆′ Q = ∀ x → x ∈ P → x ∈ Q
- ∁∅-Universal : Universal (∁ ∅)
- ∁∅-Universal = λ x x∈∅ → x∈∅
+ _⊇′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
+ Q ⊇′ P = P ⊆′ Q
- ∁U-Empty : Empty (∁ U)
- ∁U-Empty = λ x x∈∁U → x∈∁U _
+ _⊈′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
+ P ⊈′ Q = ¬ (P ⊆′ Q)
- -- P ⊆ Q means that P is a subset of Q. _⊆′_ is a variant of _⊆_.
+ _⊉′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
+ P ⊉′ Q = ¬ (P ⊇′ Q)
- infix 4 _⊆_ _⊇_ _⊆′_ _⊇′_
+ _⊂′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
+ P ⊂′ Q = P ⊆′ Q × Q ⊈′ P
- _⊆_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
- P ⊆ Q = ∀ {x} → x ∈ P → x ∈ Q
+ _⊃′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
+ P ⊃′ Q = Q ⊂′ P
- _⊆′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
- P ⊆′ Q = ∀ x → x ∈ P → x ∈ Q
+ _⊄′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
+ P ⊄′ Q = ¬ (P ⊂′ Q)
- _⊇_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
- Q ⊇ P = P ⊆ Q
+ _⊅′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
+ P ⊅′ Q = ¬ (P ⊃′ Q)
- _⊇′_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
- Q ⊇′ P = P ⊆′ Q
+ ----------------------------------------------------------------------
+ -- Properties of sets
+
+ -- Emptiness
+
+ Empty : ∀ {ℓ} → Pred A ℓ → Set _
+ Empty P = ∀ x → x ∉ P
+
+ -- Satisfiable
+
+ Satisfiable : ∀ {ℓ} → Pred A ℓ → Set _
+ Satisfiable P = ∃ λ x → x ∈ P
+
+ -- Universality
+
+ infix 10 Universal IUniversal
+ Universal : ∀ {ℓ} → Pred A ℓ → Set _
+ Universal P = ∀ x → x ∈ P
- ∅-⊆ : ∀ {ℓ} → (P : Pred A ℓ) → ∅ ⊆ P
- ∅-⊆ P ()
+ IUniversal : ∀ {ℓ} → Pred A ℓ → Set _
+ IUniversal P = ∀ {x} → x ∈ P
- ⊆-U : ∀ {ℓ} → (P : Pred A ℓ) → P ⊆ U
- ⊆-U P _ = _
+ syntax Universal P = Π[ P ]
+ syntax IUniversal P = ∀[ P ]
+
+ -- Decidability
+
+ Decidable : ∀ {ℓ} → Pred A ℓ → Set _
+ Decidable P = ∀ x → Dec (P x)
+
+ -- Irrelevance
+
+ Irrelevant : ∀ {ℓ} → Pred A ℓ → Set _
+ Irrelevant P = ∀ {x} (a : P x) (b : P x) → a ≡ b
+
+ ----------------------------------------------------------------------
+ -- Operations on sets
+
+ -- Set complement.
+
+ ∁ : ∀ {ℓ} → Pred A ℓ → Pred A ℓ
+ ∁ P = λ x → x ∉ P
-- Positive version of non-disjointness, dual to inclusion.
@@ -125,14 +179,14 @@ module _ {a} {A : Set a} -- The universe of discourse.
-- Implication.
- infixl 8 _⇒_
+ infixr 8 _⇒_
_⇒_ : ∀ {ℓ₁ ℓ₂} → Pred A ℓ₁ → Pred A ℓ₂ → Pred A _
P ⇒ Q = λ x → x ∈ P → x ∈ Q
-- Infinitary union and intersection.
- infix 9 ⋃ ⋂
+ infix 10 ⋃ ⋂
⋃ : ∀ {ℓ i} (I : Set i) → (I → Pred A ℓ) → Pred A _
⋃ I P = λ x → Σ[ i ∈ I ] P i x
@@ -144,6 +198,13 @@ module _ {a} {A : Set a} -- The universe of discourse.
syntax ⋂ I (λ i → P) = ⋂[ i ∶ I ] P
+-- Update.
+
+infixr 9 _⊢_
+
+_⊢_ : ∀ {a b} {A : Set a} {B : Set b} {ℓ} → (A → B) → Pred B ℓ → Pred A ℓ
+f ⊢ P = λ x → P (f x)
+
------------------------------------------------------------------------
-- Unary relation combinators
@@ -198,9 +259,3 @@ _//_ : ∀ {a b c ℓ₁ ℓ₂} {A : Set a} {B : Set b} {C : Set c} →
_\\_ : ∀ {a b c ℓ₁ ℓ₂} {A : Set a} {B : Set b} {C : Set c} →
Pred (A × C) ℓ₁ → Pred (A × B) ℓ₂ → Pred (B × C) _
P \\ Q = (P ~ // Q ~) ~
-
-------------------------------------------------------------------------
--- Properties of unary relations
-
-Decidable : ∀ {a ℓ} {A : Set a} (P : Pred A ℓ) → Set _
-Decidable P = ∀ x → Dec (P x)
diff --git a/src/Relation/Unary/Closure/Base.agda b/src/Relation/Unary/Closure/Base.agda
new file mode 100644
index 0000000..0457d92
--- /dev/null
+++ b/src/Relation/Unary/Closure/Base.agda
@@ -0,0 +1,61 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Closures of a unary relation with respect to a binary one.
+------------------------------------------------------------------------
+
+open import Relation.Binary
+
+module Relation.Unary.Closure.Base {a b} {A : Set a} (R : Rel A b) where
+
+open import Level
+open import Relation.Unary using (Pred)
+
+------------------------------------------------------------------------
+-- Definitions
+
+-- We start with the definition of □ ("box") which is named after the box
+-- modality in modal logic. `□ T x` states that all the elements one step
+-- away from `x` with respect to the relation R satisfy `T`.
+
+□ : ∀ {t} → Pred A t → Pred A (a ⊔ b ⊔ t)
+□ T x = ∀ {y} → R x y → T y
+
+-- Use cases of □ include:
+-- * The definition of the accessibility predicate corresponding to R:
+-- data Acc (x : A) : Set (a ⊔ b) where
+-- step : □ Acc x → Acc x
+
+-- * The characterization of stability under weakening: picking R to be
+-- `Data.List.Relation.Sublist.Inductive`, `∀ {Γ} → Tm Γ → □ T Γ`
+-- corresponds to the fact that we have a notion of weakening for `Tm`.
+
+-- Closed: whenever we have a value in one context, we can get one in any
+-- related context.
+
+record Closed {t} (T : Pred A t) : Set (a ⊔ b ⊔ t) where
+ field next : ∀ {x} → T x → □ T x
+
+
+------------------------------------------------------------------------
+-- Properties
+
+module _ {t} {T : Pred A t} where
+
+ reindex : Transitive R → ∀ {x y} → R x y → □ T x → □ T y
+ reindex trans x∼y □Tx y∼z = □Tx (trans x∼y y∼z)
+
+ -- Provided that R is reflexive and Transitive, □ is a comonad
+ map : ∀ {u} {U : Pred A u} {x} → (∀ {x} → T x → U x) → □ T x → □ U x
+ map f □Tx x~y = f (□Tx x~y)
+
+ extract : Reflexive R → ∀ {x} → □ T x → T x
+ extract refl □Tx = □Tx refl
+
+ duplicate : Transitive R → ∀ {x} → □ T x → □ (□ T) x
+ duplicate trans □Tx x∼y y∼z = □Tx (trans x∼y y∼z)
+
+-- Provided that R is transitive, □ is the Closure operator
+-- i.e. for any `T`, `□ T` is closed.
+□-closed : Transitive R → ∀ {t} {T : Pred A t} → Closed (□ T)
+□-closed trans = record { next = duplicate trans }
diff --git a/src/Relation/Unary/Closure/Preorder.agda b/src/Relation/Unary/Closure/Preorder.agda
new file mode 100644
index 0000000..2d16751
--- /dev/null
+++ b/src/Relation/Unary/Closure/Preorder.agda
@@ -0,0 +1,30 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Closure of a unary relation with respect to a preorder
+------------------------------------------------------------------------
+
+open import Relation.Binary
+
+module Relation.Unary.Closure.Preorder {a r e} (P : Preorder a e r) where
+
+open Preorder P
+open import Relation.Unary using (Pred)
+
+-- Specialising the results proven generically in `Base`.
+import Relation.Unary.Closure.Base _∼_ as Base
+open Base public using (□; map; Closed)
+
+module _ {t} {T : Pred Carrier t} where
+
+ reindex : ∀ {x y} → x ∼ y → □ T x → □ T y
+ reindex = Base.reindex trans
+
+ extract : ∀ {x} → □ T x → T x
+ extract = Base.extract refl
+
+ duplicate : ∀ {x} → □ T x → □ (□ T) x
+ duplicate = Base.duplicate trans
+
+□-closed : ∀ {t} {T : Pred Carrier t} → Closed (□ T)
+□-closed = Base.□-closed trans
diff --git a/src/Relation/Unary/Closure/StrictPartialOrder.agda b/src/Relation/Unary/Closure/StrictPartialOrder.agda
new file mode 100644
index 0000000..bce595f
--- /dev/null
+++ b/src/Relation/Unary/Closure/StrictPartialOrder.agda
@@ -0,0 +1,28 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Closures of a unary relation with respect to a strict partial order
+------------------------------------------------------------------------
+
+open import Relation.Binary
+
+module Relation.Unary.Closure.StrictPartialOrder
+ {a r e} (P : StrictPartialOrder a e r) where
+
+open StrictPartialOrder P renaming (_<_ to _∼_)
+open import Relation.Unary using (Pred)
+
+-- Specialising the results proven generically in `Base`.
+import Relation.Unary.Closure.Base _∼_ as Base
+open Base public using (□; map; Closed)
+
+module _ {t} {T : Pred Carrier t} where
+
+ reindex : ∀ {x y} → x ∼ y → □ T x → □ T y
+ reindex = Base.reindex trans
+
+ duplicate : ∀ {x} → □ T x → □ (□ T) x
+ duplicate = Base.duplicate trans
+
+□-closed : ∀ {t} {T : Pred Carrier t} → Closed (□ T)
+□-closed = Base.□-closed trans
diff --git a/src/Relation/Unary/Indexed.agda b/src/Relation/Unary/Indexed.agda
new file mode 100644
index 0000000..26f06cf
--- /dev/null
+++ b/src/Relation/Unary/Indexed.agda
@@ -0,0 +1,22 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Indexed unary relations
+------------------------------------------------------------------------
+
+module Relation.Unary.Indexed where
+
+open import Data.Product using (∃; _×_)
+open import Level
+open import Relation.Nullary using (¬_)
+
+IPred : ∀ {i a} {I : Set i} → (I → Set a) → (ℓ : Level) → Set _
+IPred A ℓ = ∀ {i} → A i → Set ℓ
+
+module _ {i a} {I : Set i} {A : I → Set a} where
+
+ _∈_ : ∀ {ℓ} → (∀ i → A i) → IPred A ℓ → Set _
+ x ∈ P = ∀ i → P (x i)
+
+ _∉_ : ∀ {ℓ} → (∀ i → A i) → IPred A ℓ → Set _
+ t ∉ P = ¬ (t ∈ P)
diff --git a/src/Relation/Unary/Properties.agda b/src/Relation/Unary/Properties.agda
new file mode 100644
index 0000000..f2f1076
--- /dev/null
+++ b/src/Relation/Unary/Properties.agda
@@ -0,0 +1,101 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Properties of constructions over unary relations
+------------------------------------------------------------------------
+
+module Relation.Unary.Properties where
+
+open import Data.Product using (_×_; _,_; swap; proj₁)
+open import Data.Sum.Base using (inj₁; inj₂)
+open import Data.Unit using (tt)
+open import Relation.Binary.Core hiding (Decidable)
+open import Relation.Unary
+open import Relation.Nullary using (yes; no)
+open import Relation.Nullary.Product using (_×-dec_)
+open import Relation.Nullary.Sum using (_⊎-dec_)
+open import Relation.Nullary.Negation using (¬?)
+open import Function using (_$_; _∘_)
+
+----------------------------------------------------------------------
+-- The empty set
+
+module _ {a} {A : Set a} where
+
+ ∅? : Decidable {A = A} ∅
+ ∅? _ = no λ()
+
+ ∅-Empty : Empty {A = A} ∅
+ ∅-Empty x ()
+
+ ∁∅-Universal : Universal {A = A} (∁ ∅)
+ ∁∅-Universal = λ x x∈∅ → x∈∅
+
+----------------------------------------------------------------------
+-- The universe
+
+module _ {a} {A : Set a} where
+
+ U? : Decidable {A = A} U
+ U? _ = yes tt
+
+ U-Universal : Universal {A = A} U
+ U-Universal = λ _ → _
+
+ ∁U-Empty : Empty {A = A} (∁ U)
+ ∁U-Empty = λ x x∈∁U → x∈∁U _
+
+----------------------------------------------------------------------
+-- Subset properties
+
+module _ {a ℓ} {A : Set a} where
+
+ ∅-⊆ : (P : Pred A ℓ) → ∅ ⊆ P
+ ∅-⊆ P ()
+
+ ⊆-U : (P : Pred A ℓ) → P ⊆ U
+ ⊆-U P _ = _
+
+ ⊆-refl : Reflexive (_⊆_ {A = A} {ℓ})
+ ⊆-refl x∈P = x∈P
+
+ ⊆-trans : Transitive (_⊆_ {A = A} {ℓ})
+ ⊆-trans P⊆Q Q⊆R x∈P = Q⊆R (P⊆Q x∈P)
+
+ ⊂-asym : Asymmetric (_⊂_ {A = A} {ℓ})
+ ⊂-asym (_ , Q⊈P) = Q⊈P ∘ proj₁
+
+----------------------------------------------------------------------
+-- Decidability properties
+
+module _ {a} {A : Set a} where
+
+ ∁? : ∀ {ℓ} {P : Pred A ℓ} → Decidable P → Decidable (∁ P)
+ ∁? P? x = ¬? (P? x)
+
+ _∪?_ : ∀ {ℓ₁ ℓ₂} {P : Pred A ℓ₁} {Q : Pred A ℓ₂} →
+ Decidable P → Decidable Q → Decidable (P ∪ Q)
+ _∪?_ P? Q? x = (P? x) ⊎-dec (Q? x)
+
+ _∩?_ : ∀ {ℓ₁ ℓ₂} {P : Pred A ℓ₁} {Q : Pred A ℓ₂} →
+ Decidable P → Decidable Q → Decidable (P ∩ Q)
+ _∩?_ P? Q? x = (P? x) ×-dec (Q? x)
+
+module _ {a b} {A : Set a} {B : Set b} where
+
+ _×?_ : ∀ {ℓ₁ ℓ₂} {P : Pred A ℓ₁} {Q : Pred B ℓ₂} →
+ Decidable P → Decidable Q → Decidable (P ⟨×⟩ Q)
+ _×?_ P? Q? (a , b) = (P? a) ×-dec (Q? b)
+
+ _⊙?_ : ∀ {ℓ₁ ℓ₂} {P : Pred A ℓ₁} {Q : Pred B ℓ₂} →
+ Decidable P → Decidable Q → Decidable (P ⟨⊙⟩ Q)
+ _⊙?_ P? Q? (a , b) = (P? a) ⊎-dec (Q? b)
+
+ _⊎?_ : ∀ {ℓ} {P : Pred A ℓ} {Q : Pred B ℓ} →
+ Decidable P → Decidable Q → Decidable (P ⟨⊎⟩ Q)
+ _⊎?_ P? Q? (inj₁ a) = P? a
+ _⊎?_ P? Q? (inj₂ b) = Q? b
+
+ _~? : ∀ {ℓ} {P : Pred (A × B) ℓ} →
+ Decidable P → Decidable (P ~)
+ _~? P? = P? ∘ swap