Skip to content

[add] Update PartialSetoid reasoning #2689

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

Merged
merged 5 commits into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ Bug-fixes
This has been deprecated in favor or `rightInverse`, and a corrected (and
correctly-named) function `leftInverse` has been added.

* The implementation of `_IsRelatedTo_` in `Relation.Binary.Reasoning.Base.Partial`
has been modified to correctly support equational reasoning at the beginning and the end.
The detail of this issue is described in [#2677](https://github.com/agda/agda-stdlib/pull/2677). Since the names of constructors
of `_IsRelatedTo_` are changed and the reduction behaviour of reasoning steps
are changed, this modification is non-backwards compatible.

Non-backwards compatible changes
--------------------------------

Expand Down
49 changes: 26 additions & 23 deletions src/Relation/Binary/Reasoning/Base/Partial.agda
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,55 @@ module Relation.Binary.Reasoning.Base.Partial
------------------------------------------------------------------------
-- Definition of "related to"

-- This seemingly unnecessary type is used to make it possible to
-- infer arguments even if the underlying equality evaluates.
-- This type allows us to track whether reasoning steps
-- include _∼_ or not.

infix 4 _IsRelatedTo_

data _IsRelatedTo_ : A → A → Set (a ⊔ ℓ) where
singleStep : ∀ x → x IsRelatedTo x
multiStep : ∀ {x y} (x∼y : x ∼ y) → x IsRelatedTo y
reflexive : ∀ {x y} → x ≡ y → x IsRelatedTo y
relTo : ∀ {x y} (x∼y : x ∼ y) → x IsRelatedTo y
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename constructors to stay closer to Single reasoning


≡-go : Trans _≡_ _IsRelatedTo_ _IsRelatedTo_
≡-go x≡y (reflexive y≡z) = reflexive (case x≡y of λ where ≡.refl → y≡z)
≡-go x≡y (relTo y∼z) = relTo (case x≡y of λ where ≡.refl → y∼z)

∼-go : Trans _∼_ _IsRelatedTo_ _IsRelatedTo_
∼-go x∼y (singleStep y) = multiStep x∼y
∼-go x∼y (multiStep y∼z) = multiStep (trans x∼y y∼z)
∼-go x∼y (reflexive y≡z) = relTo (case y≡z of λ where ≡.refl → x∼y)
∼-go x∼y (relTo y∼z) = relTo (trans x∼y y∼z)

stop : Reflexive _IsRelatedTo_
stop = singleStep _
stop = reflexive ≡.refl

------------------------------------------------------------------------
-- Types that are used to ensure that the final relation proved by the
-- chain of reasoning can be converted into the required relation.

data IsMultiStep {x y} : x IsRelatedTo y → Set (a ⊔ ℓ) where
isMultiStep : ∀ x∼y → IsMultiStep (multiStep x∼y)
data IsRelTo {x y} : x IsRelatedTo y → Set (a ⊔ ℓ) where
isRelTo : ∀ x∼y → IsRelTo (relTo x∼y)

IsMultiStep? : ∀ {x y} (x∼y : x IsRelatedTo y) → Dec (IsMultiStep x∼y)
IsMultiStep? (multiStep x<y) = yes (isMultiStep x<y)
IsMultiStep? (singleStep _) = no λ()
IsRelTo? : ∀ {x y} (x∼y : x IsRelatedTo y) → Dec (IsRelTo x∼y)
IsRelTo? (relTo x∼y) = yes (isRelTo x∼y)
IsRelTo? (reflexive _) = no λ()

extractMultiStep : ∀ {x y} {x∼y : x IsRelatedTo y} → IsMultiStep x∼y → x ∼ y
extractMultiStep (isMultiStep x≈y) = xy
extractRelTo : ∀ {x y} {x∼y : x IsRelatedTo y} → IsRelTo x∼y → x ∼ y
extractRelTo (isRelTo x∼y) = xy

multiStepSubRelation : SubRelation _IsRelatedTo_ _ _
multiStepSubRelation = record
{ IsS = IsMultiStep
; IsS? = IsMultiStep?
; extract = extractMultiStep
relToSubRelation : SubRelation _IsRelatedTo_ _ _
relToSubRelation = record
{ IsS = IsRelTo
; IsS? = IsRelTo?
; extract = extractRelTo
}

------------------------------------------------------------------------
-- Reasoning combinators

open begin-subrelation-syntax _IsRelatedTo_ multiStepSubRelation public
open ≡-noncomputing-syntax _IsRelatedTo_ public
open begin-subrelation-syntax _IsRelatedTo_ relToSubRelation public
open ≡-syntax _IsRelatedTo_ ≡-go public
open ∼-syntax _IsRelatedTo_ _IsRelatedTo_ ∼-go public
open end-syntax _IsRelatedTo_ stop public


------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
Expand All @@ -79,7 +82,7 @@ open end-syntax _IsRelatedTo_ stop public
infix 3 _∎⟨_⟩

_∎⟨_⟩ : ∀ x → x ∼ x → x IsRelatedTo x
_ ∎⟨ x∼x ⟩ = multiStep x∼x
_ ∎⟨ x∼x ⟩ = relTo x∼x
{-# WARNING_ON_USAGE _∎⟨_⟩
"Warning: _∎⟨_⟩ was deprecated in v1.6.
Please use _∎ instead if used in a chain, otherwise simply provide
Expand Down