------------------------------------------------------------------------ -- The Agda standard library -- -- Syntax for the building blocks of equational reasoning modules ------------------------------------------------------------------------ {-# OPTIONS --cubical-compatible --safe #-} -- List of `Reasoning` modules that do not use this framework and so -- need to be updated manually if the syntax changes. -- -- Data/Vec/Relation/Binary/Equality/Cast -- Relation/Binary/HeterogeneousEquality -- Effect/Monad/Partiality -- Effect/Monad/Partiality/All -- Codata/Guarded/Stream/Relation/Binary/Pointwise -- Function/Reasoning module Relation.Binary.Reasoning.Syntax where open import Level using (Level; _⊔_; suc) open import Relation.Nullary.Decidable.Core using (Dec; True; toWitness) open import Relation.Nullary.Negation.Core using (contradiction) open import Relation.Binary.Core using (Rel; REL; _⇒_) open import Relation.Binary.Definitions using (_Respectsʳ_; Asymmetric; Trans; Sym; Reflexive) open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_) private variable a ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level A B C : Set a x y z : A ------------------------------------------------------------------------ -- Syntax for beginning a reasoning chain ------------------------------------------------------------------------ ------------------------------------------------------------------------ -- Basic begin syntax module begin-syntax (R : REL A B ℓ₁) {S : REL A B ℓ₂} (reflexive : R ⇒ S) where infix 1 begin_ begin_ : R x y → S x y begin_ = reflexive ------------------------------------------------------------------------ -- Begin subrelation syntax -- Sometimes we want to support sub-relations with the -- same reasoning operators as the main relations (e.g. perform equality -- proofs with non-strict reasoning operators). This record bundles all -- the parts needed to extract the sub-relation proofs. record SubRelation {A : Set a} (R : Rel A ℓ₁) ℓ₂ ℓ₃ : Set (a ⊔ ℓ₁ ⊔ suc ℓ₂ ⊔ suc ℓ₃) where field S : Rel A ℓ₂ IsS : R x y → Set ℓ₃ IsS? : ∀ (xRy : R x y) → Dec (IsS xRy) extract : ∀ {xRy : R x y} → IsS xRy → S x y module begin-subrelation-syntax (R : Rel A ℓ₁) (sub : SubRelation R ℓ₂ ℓ₃) where open SubRelation sub infix 1 begin_ begin_ : ∀ {x y} (xRy : R x y) → {s : True (IsS? xRy)} → S x y begin_ r {s} = extract (toWitness s) -- Begin equality syntax module begin-equality-syntax (R : Rel A ℓ₁) (sub : SubRelation R ℓ₂ ℓ₃) where open begin-subrelation-syntax R sub public renaming (begin_ to begin-equality_) -- Begin apartness syntax module begin-apartness-syntax (R : Rel A ℓ₁) (sub : SubRelation R ℓ₂ ℓ₃) where open begin-subrelation-syntax R sub public renaming (begin_ to begin-apartness_) -- Begin strict syntax module begin-strict-syntax (R : Rel A ℓ₁) (sub : SubRelation R ℓ₂ ℓ₃) where open begin-subrelation-syntax R sub public renaming (begin_ to begin-strict_) ------------------------------------------------------------------------ -- Begin membership syntax module begin-membership-syntax (R : Rel A ℓ₁) (_∈_ : REL B A ℓ₂) (resp : _∈_ Respectsʳ R) where infix 1 step-∈ step-∈ : ∀ (x : B) {xs ys} → R xs ys → x ∈ xs → x ∈ ys step-∈ x = resp syntax step-∈ x xs⊆ys x∈xs = x ∈⟨ x∈xs ⟩ xs⊆ys ------------------------------------------------------------------------ -- Begin contradiction syntax -- Used with asymmetric subrelations to derive a contradiction from a -- proof that an element is related to itself. module begin-contradiction-syntax (R : Rel A ℓ₁) (sub : SubRelation R ℓ₂ ℓ₃) (asym : Asymmetric (SubRelation.S sub)) where open SubRelation sub infix 1 begin-contradiction_ begin-contradiction_ : ∀ (xRx : R x x) {s : True (IsS? xRx)} → ∀ {b} {B : Set b} → B begin-contradiction_ {x} r {s} = contradiction x