Skip to content

Classical.Bundles.Magma

Bundle bridge for magmas

This is the Classical.Bundles.Magma module of the Agda Universal Algebra Library.

This module supplies the bidirectional bridge between the Ξ£-typed core of Classical.Structures.Magma and the record-typed Algebra.Bundles.Magma in the Agda standard library. Both representations carry the same mathematical content; the bridge exists so that downstream code typed against Algebra.Bundles.Magma is reusable against the canonical agda-algebras representation without manual record-shuffling.

The round-trip is stated pointwise on the carrier, in the magma's underlying setoid equivalence, per ADR-002 v2 Β§6. The Fin 2 Ξ·-failure under --cubical-compatible would obstruct any propositional _≑_-on-the-Ξ£-type formulation; the pointwise statement sidesteps it cleanly, discharged by Setoid.refl because pair a b 0F and pair a b 1F reduce definitionally to a and b respectively.

{-# OPTIONS --cubical-compatible --exact-split --safe #-}

module Classical.Bundles.Magma where

-- Imports from the Agda Standard Library ----------------------------
open import Algebra.Bundles                        using () renaming ( Magma to stdlib-Magma )
open import Data.Fin.Patterns                      using ( 0F ; 1F )
open import Data.Product                           using ( _,_ )
open import Function                               using ( Func )
open import Level                                  using ( Level )
open import Relation.Binary                        using ( Setoid )
import Relation.Binary.PropositionalEquality as ≑

open Func renaming ( to to _⟨$⟩_ )

-- Imports from the Agda Universal Algebra Library ----------------------------
open import Classical.Signatures.Magma             using ( βˆ™-Op ; Sig-Magma )
open import Classical.Structures.Magma             using ( Magma ; module Magma-Op )
open import Setoid.Algebras.Basic {𝑆 = Sig-Magma}  using ( Algebra ; π•Œ[_] ; 𝔻[_] )
open import Setoid.Signatures                      using  ( ⟨_⟩ )
open Algebra using (Interp)

private variable α ρ : Level

Core to stdlib bundle

Going from the canonical Ξ£-typed core to the stdlib record reads off the domain's Carrier and _β‰ˆ_, exposes the operation in curried form via Classical.Structures.Magma's _βˆ™_, and constructs the IsMagma witness from the algebra's Interp.cong by unpacking the Fin 2 pattern.

⟨_βŸ©α΅α΅ƒ : Magma Ξ± ρ β†’ stdlib-Magma Ξ± ρ
⟨ 𝑴 βŸ©α΅α΅ƒ = record
  { Carrier = π•Œ[ 𝑴 ]
  ; _β‰ˆ_     = _β‰ˆ_
  ; _βˆ™_     = _βˆ™_
  ; isMagma = record
      { isEquivalence = isEquivalence
      ; βˆ™-cong = Ξ» xβ‰ˆy uβ‰ˆv β†’ cong (Interp 𝑴) (≑.refl , Ξ» { 0F β†’ xβ‰ˆy ; 1F β†’ uβ‰ˆv })
      }
  }
  where open Magma-Op 𝑴; open Setoid 𝔻[ 𝑴 ]

Stdlib bundle to core

The reverse direction reassembles the bundle's Carrier, _β‰ˆ_, and _βˆ™_ into an Algebra Sig-Magma. The interpretation of βˆ™-Op uncurries the bundle's _βˆ™_ by reading off args 0F and args 1F; the congruence of Interp is built from the bundle's βˆ™-cong applied pointwise to the argument-tuple's equivalence proof.

βŸͺ_βŸ«α΅α΅ƒ : stdlib-Magma Ξ± ρ β†’ Magma Ξ± ρ
βŸͺ M βŸ«α΅α΅ƒ = record
  { Domain = record
    { Carrier        = stdlib-Magma.Carrier M
    ; _β‰ˆ_            = stdlib-Magma._β‰ˆ_ M
    ; isEquivalence  = stdlib-Magma.isEquivalence M
    }
  ; Interp = interp
  }
  where
  interp : Func (⟨ Sig-Magma ⟩ (stdlib-Magma.setoid M)) (stdlib-Magma.setoid M)
  interp ⟨$⟩ (βˆ™-Op , args) = (M stdlib-Magma.βˆ™ (args 0F)) (args 1F)
  cong interp { βˆ™-Op , _ } { .βˆ™-Op , _ } (≑.refl , argsβ‰ˆ) = stdlib-Magma.βˆ™-cong M (argsβ‰ˆ 0F) (argsβ‰ˆ 1F)

Pointwise round-trip

Going core β†’ bundle β†’ core preserves the curried operation pointwise. The two sides reduce to the same (βˆ™-Op ^ 𝑴) (pair a b) definitionally β€” pair a b 0F and pair a b 1F reduce by the pattern matching in pair β€” so Setoid.refl discharges the obligation.

module _ {𝑴 : Magma Ξ± ρ} where
  open Magma-Op 𝑴 ; open Setoid 𝔻[ 𝑴 ]
  open Magma-Op βŸͺ ⟨ 𝑴 βŸ©α΅α΅ƒ βŸ«α΅α΅ƒ renaming ( _βˆ™_ to _βˆ™'_ )

  roundtrip-cbc-ma : (a b : π•Œ[ 𝑴 ]) β†’ (a βˆ™' b) β‰ˆ (a βˆ™ b)
  roundtrip-cbc-ma a b = refl

The reverse direction, bundle β†’ core β†’ bundle, holds pointwise on the bundle's underlying equivalence by the same reduction.

module _ {𝑴 : stdlib-Magma Ξ± ρ} where
  open stdlib-Magma 𝑴 using (_β‰ˆ_; _βˆ™_; refl) renaming (Carrier to M)
  open stdlib-Magma ⟨ βŸͺ 𝑴 βŸ«α΅α΅ƒ βŸ©α΅α΅ƒ using () renaming ( _βˆ™_ to _βˆ™'_ )

  roundtrip-bcb-ma : (a b : M) β†’ (a βˆ™ b) β‰ˆ (a βˆ™' b)
  roundtrip-bcb-ma a b = refl