1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768-------------------------------------------------------------------------- The Agda standard library---- Symmetric closures of binary relations------------------------------------------------------------------------ {-# OPTIONS --cubical-compatible --safe #-} module Relation.Binary.Construct.Closure.Symmetric where open import Function.Base using (id; _on_)open import Level using (Level)open import Relation.Binary.Core using (Rel; _=[_]⇒_; _⇒_)open import Relation.Binary.Definitions using (Symmetric)import Relation.Binary.Construct.On as On private variable a ℓ ℓ₁ ℓ₂ : Level A B : Set a R S : Rel A ℓ -------------------------------------------------------------------------- Definition data SymClosure {A : Set a} (R : Rel A ℓ) (a b : A) : Set ℓ where fwd : R a b → SymClosure R a b bwd : R b a → SymClosure R a b -------------------------------------------------------------------------- Properties -- Symmetric closures are symmetric.symmetric : (R : Rel A ℓ) → Symmetric (SymClosure R)symmetric _ (fwd aRb) = bwd aRbsymmetric _ (bwd bRa) = fwd bRa -------------------------------------------------------------------------- Operations -- A generalised variant of `map` which allows the index type to change.gmap : (f : A → B) → R =[ f ]⇒ S → SymClosure R =[ f ]⇒ SymClosure Sgmap _ g (fwd aRb) = fwd (g aRb)gmap _ g (bwd bRa) = bwd (g bRa) map : R ⇒ S → SymClosure R ⇒ SymClosure Smap = gmap id fold : Symmetric S → R ⇒ S → SymClosure R ⇒ Sfold S-sym R⇒S (fwd aRb) = R⇒S aRbfold S-sym R⇒S (bwd bRa) = S-sym (R⇒S bRa) -- A generalised variant of `fold`.gfold : Symmetric S → (f : A → B) → R =[ f ]⇒ S → SymClosure R =[ f ]⇒ Sgfold {S = S} S-sym f R⇒S = fold (On.symmetric f S S-sym) R⇒S -- `return` could also be called `singleton`.return : R ⇒ SymClosure Rreturn = fwd -- `join` could also be called `concat`.join : SymClosure (SymClosure R) ⇒ SymClosure Rjoin = fold (symmetric _) id infix 10 _⋆ _⋆ : R ⇒ SymClosure S → SymClosure R ⇒ SymClosure S_⋆ f m = join (map f m)