Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Systematise relational definitions at all arities #2259

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,20 @@ Additions to existing modules

* In `Function.Bundles`, added `_⟶ₛ_` as a synonym for `Func` that can
be used infix.

* Added new definitions in `Relation.Binary`
```
Stable : Pred A ℓ → Set _
```

* Added new definitions in `Relation.Nullary`
```
Recomputable : Set _
WeaklyDecidable : Set _
```

* Added new definitions in `Relation.Unary`
```
Stable : Pred A ℓ → Set _
WeaklyDecidable : Pred A ℓ → Set _
```
43 changes: 23 additions & 20 deletions src/Relation/Binary/Definitions.agda
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ module Relation.Binary.Definitions where

open import Agda.Builtin.Equality using (_≡_)

open import Data.Maybe.Base using (Maybe)
open import Data.Product.Base using (_×_; ∃-syntax)
open import Data.Sum.Base using (_⊎_)
open import Function.Base using (_on_; flip)
open import Level
open import Relation.Binary.Core
open import Relation.Nullary.Decidable.Core using (Dec)
open import Relation.Nullary.Negation.Core using (¬_)
open import Relation.Nullary as Nullary using (¬_; Dec)

private
variable
Expand Down Expand Up @@ -206,35 +204,40 @@ P Respects₂ _∼_ = (P Respectsʳ _∼_) × (P Respectsˡ _∼_)
Substitutive : Rel A ℓ₁ → (ℓ₂ : Level) → Set _
Substitutive {A = A} _∼_ p = (P : A → Set p) → P Respects _∼_

-- Decidability - it is possible to determine whether a given pair of
-- elements are related.
-- Irrelevancy - all proofs that a given pair of elements are related
-- are indistinguishable.

Decidable : REL A B ℓ → Set _
Decidable _∼_ = ∀ x y → Dec (x ∼ y)
Irrelevant : REL A B ℓ → Set _
Irrelevant _∼_ = ∀ {x y} → Nullary.Irrelevant (x ∼ y)

-- Recomputability - we can rebuild a relevant proof given an
-- irrelevant one.

Recomputable : REL A B ℓ → Set _
Recomputable _∼_ = ∀ {x y} → Nullary.Recomputable (x ∼ y)

-- Stability

Stable : REL A B ℓ → Set _
Stable _∼_ = ∀ x y → Nullary.Stable (x ∼ y)

-- Weak decidability - it is sometimes possible to determine if a given
-- pair of elements are related.

WeaklyDecidable : REL A B ℓ → Set _
WeaklyDecidable _∼_ = ∀ x y → Maybe (x ∼ y)
WeaklyDecidable _∼_ = ∀ x y → Nullary.WeaklyDecidable (x ∼ y)

-- Decidability - it is possible to determine whether a given pair of
-- elements are related.

Decidable : REL A B ℓ → Set _
Decidable _∼_ = ∀ x y → Dec (x ∼ y)

-- Propositional equality is decidable for the type.

DecidableEquality : (A : Set a) → Set _
DecidableEquality A = Decidable {A = A} _≡_

-- Irrelevancy - all proofs that a given pair of elements are related
-- are indistinguishable.

Irrelevant : REL A B ℓ → Set _
Irrelevant _∼_ = ∀ {x y} (a b : x ∼ y) → a ≡ b

-- Recomputability - we can rebuild a relevant proof given an
-- irrelevant one.

Recomputable : REL A B ℓ → Set _
Recomputable _∼_ = ∀ {x y} → .(x ∼ y) → x ∼ y

-- Universal - all pairs of elements are related

Universal : REL A B ℓ → Set _
Expand Down
13 changes: 12 additions & 1 deletion src/Relation/Nullary.agda
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

module Relation.Nullary where

open import Agda.Builtin.Equality
open import Agda.Builtin.Equality using (_≡_)
open import Agda.Builtin.Maybe public
using (nothing; just)
MatthewDaggitt marked this conversation as resolved.
Show resolved Hide resolved
renaming (Maybe to WeaklyDecidable)
MatthewDaggitt marked this conversation as resolved.
Show resolved Hide resolved

------------------------------------------------------------------------
-- Re-exports
Expand All @@ -24,3 +27,11 @@ open import Relation.Nullary.Decidable.Core public

Irrelevant : ∀ {p} → Set p → Set p
Irrelevant P = ∀ (p₁ p₂ : P) → p₁ ≡ p₂

------------------------------------------------------------------------
-- Recomputability - we can rebuild a relevant proof given an
-- irrelevant one.

Recomputable : ∀ {p} → Set p → Set p
Recomputable P = .P → P

37 changes: 23 additions & 14 deletions src/Relation/Unary.agda
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ open import Data.Product.Base using (_×_; _,_; Σ-syntax; ∃; uncurry; swap)
open import Data.Sum.Base using (_⊎_; [_,_])
open import Function.Base using (_∘_; _|>_)
open import Level using (Level; _⊔_; 0ℓ; suc; Lift)
open import Relation.Nullary.Decidable.Core using (Dec; True)
open import Relation.Nullary.Negation.Core using (¬_)
open import Relation.Nullary as Nullary using (¬_; Dec; True)
open import Relation.Binary.PropositionalEquality.Core using (_≡_)

private
Expand Down Expand Up @@ -162,6 +161,28 @@ IUniversal P = ∀ {x} → x ∈ P

syntax IUniversal P = ∀[ P ]

-- Irrelevance - any two proofs that an element satifies P are
-- indistinguishable.

Irrelevant : Pred A ℓ → Set _
Irrelevant P = ∀ {x} → Nullary.Irrelevant (P x)

-- Recomputability - we can rebuild a relevant proof given an
-- irrelevant one.

Recomputable : Pred A ℓ → Set _
Recomputable P = ∀ {x} → Nullary.Recomputable (P x)

-- Weak Decidability

Stable : Pred A ℓ → Set _
Stable P = ∀ x → Nullary.Stable (P x)

-- Weak Decidability

WeaklyDecidable : Pred A ℓ → Set _
WeaklyDecidable P = ∀ x → Nullary.WeaklyDecidable (P x)

-- Decidability - it is possible to determine if an arbitrary element
-- satisfies P.

Expand All @@ -174,18 +195,6 @@ Decidable P = ∀ x → Dec (P x)
⌊_⌋ : {P : Pred A ℓ} → Decidable P → Pred A ℓ
⌊ P? ⌋ a = Lift _ (True (P? a))

-- Irrelevance - any two proofs that an element satifies P are
-- indistinguishable.

Irrelevant : Pred A ℓ → Set _
Irrelevant P = ∀ {x} (a : P x) (b : P x) → a ≡ b

-- Recomputability - we can rebuild a relevant proof given an
-- irrelevant one.

Recomputable : Pred A ℓ → Set _
Recomputable P = ∀ {x} → .(P x) → P x

------------------------------------------------------------------------
-- Operations on sets

Expand Down
Loading