| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- The basic code for equational reasoning with a non-reflexive relation |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
open import Function.Base using (case_of_) |
| 10 |
open import Level using (_⊔_) |
| 11 |
open import Relation.Binary.Core using (Rel) |
| 12 |
open import Relation.Binary.Definitions using (Transitive; Trans; Reflexive) |
| 13 |
open import Relation.Nullary.Decidable using (Dec; yes; no) |
| 14 |
open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_) |
| 15 |
open import Relation.Binary.Reasoning.Syntax |
| 16 |
|
| 17 |
|
| 18 |
module Relation.Binary.Reasoning.Base.Partial |
| 19 |
{a ℓ} {A : Set a} (_∼_ : Rel A ℓ) (trans : Transitive _∼_) |
| 20 |
where |
| 21 |
|
| 22 |
------------------------------------------------------------------------ |
| 23 |
-- Definition of "related to" |
| 24 |
|
| 25 |
-- This type allows us to track whether reasoning steps |
| 26 |
-- include _∼_ or not. |
| 27 |
|
| 28 |
infix 4 _IsRelatedTo_ |
| 29 |
|
| 30 |
data _IsRelatedTo_ : A → A → Set (a ⊔ ℓ) where |
| 31 |
reflexive : ∀ {x y} → x ≡ y → x IsRelatedTo y |
| 32 |
relTo : ∀ {x y} (x∼y : x ∼ y) → x IsRelatedTo y |
| 33 |
|
| 34 |
≡-go : Trans _≡_ _IsRelatedTo_ _IsRelatedTo_ |
| 35 |
≡-go x≡y (reflexive y≡z) = reflexive (case x≡y of λ where ≡.refl → y≡z) |
| 36 |
≡-go x≡y (relTo y∼z) = relTo (case x≡y of λ where ≡.refl → y∼z) |
| 37 |
|
| 38 |
∼-go : Trans _∼_ _IsRelatedTo_ _IsRelatedTo_ |
| 39 |
∼-go x∼y (reflexive y≡z) = relTo (case y≡z of λ where ≡.refl → x∼y) |
| 40 |
∼-go x∼y (relTo y∼z) = relTo (trans x∼y y∼z) |
| 41 |
|
| 42 |
stop : Reflexive _IsRelatedTo_ |
| 43 |
stop = reflexive ≡.refl |
| 44 |
|
| 45 |
------------------------------------------------------------------------ |
| 46 |
-- Types that are used to ensure that the final relation proved by the |
| 47 |
-- chain of reasoning can be converted into the required relation. |
| 48 |
|
| 49 |
data IsRelTo {x y} : x IsRelatedTo y → Set (a ⊔ ℓ) where |
| 50 |
isRelTo : ∀ x∼y → IsRelTo (relTo x∼y) |
| 51 |
|
| 52 |
IsRelTo? : ∀ {x y} (x∼y : x IsRelatedTo y) → Dec (IsRelTo x∼y) |
| 53 |
IsRelTo? (relTo x∼y) = yes (isRelTo x∼y) |
| 54 |
IsRelTo? (reflexive _) = no λ() |
| 55 |
|
| 56 |
extractRelTo : ∀ {x y} {x∼y : x IsRelatedTo y} → IsRelTo x∼y → x ∼ y |
| 57 |
extractRelTo (isRelTo x∼y) = x∼y |
| 58 |
|
| 59 |
relToSubRelation : SubRelation _IsRelatedTo_ _ _ |
| 60 |
relToSubRelation = record |
| 61 |
{ IsS = IsRelTo |
| 62 |
; IsS? = IsRelTo? |
| 63 |
; extract = extractRelTo |
| 64 |
} |
| 65 |
|
| 66 |
------------------------------------------------------------------------ |
| 67 |
-- Reasoning combinators |
| 68 |
|
| 69 |
open begin-subrelation-syntax _IsRelatedTo_ relToSubRelation public |
| 70 |
open ≡-syntax _IsRelatedTo_ ≡-go public |
| 71 |
open ∼-syntax _IsRelatedTo_ _IsRelatedTo_ ∼-go public |
| 72 |
open end-syntax _IsRelatedTo_ stop public |
| 73 |
|
| 74 |
------------------------------------------------------------------------ |
| 75 |
-- DEPRECATED NAMES |
| 76 |
------------------------------------------------------------------------ |
| 77 |
-- Please use the new names as continuing support for the old names is |
| 78 |
-- not guaranteed. |
| 79 |
|
| 80 |
-- Version 1.6 |
| 81 |
|
| 82 |
infix 3 _∎⟨_⟩ |
| 83 |
|
| 84 |
_∎⟨_⟩ : ∀ x → x ∼ x → x IsRelatedTo x |
| 85 |
_ ∎⟨ x∼x ⟩ = relTo x∼x |
| 86 |
{-# WARNING_ON_USAGE _∎⟨_⟩ |
| 87 |
"Warning: _∎⟨_⟩ was deprecated in v1.6. |
| 88 |
Please use _∎ instead if used in a chain, otherwise simply provide |
| 89 |
the proof of reflexivity directly without using these combinators." |
| 90 |
#-} |