Skip to content

Examples.Classical.Magma

Worked example: (โ„•, +) as a magma

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

The natural numbers under addition form the canonical first magma to exhibit. Beyond demonstrating that the M3-3 deliverable type-checks, this module is the home for all future magma-specific worked examples: alternative magmas on โ„• (under multiplication, under truncated subtraction), small finite magmas as Cayley tables, free magmas over a generating set, magmas that fail to be semigroups, and so on. Subsequent additions should land here rather than alongside the core structure file.

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

module Examples.Classical.Magma where

-- Imports from Agda and the Agda Standard Library ----------------------------
open import Data.Nat                               using ( โ„• ; _+_ )
open import Relation.Binary.PropositionalEquality  using ( _โ‰ก_ ; refl )

-- Imports from the Agda Universal Algebra Library ----------------------------
open import Classical.Bundles.Magma           using ( โŸจ_โŸฉแตแตƒ ; โŸช_โŸซแตแตƒ )
open import Classical.Small.Structures.Magma  using ( Magma ; opsToMagma )

import Classical.Structures.Magma as Polymorphic

The magma (โ„•, +)

โ„•-magma : Magma
โ„•-magma = opsToMagma โ„• _+_

open Polymorphic.Magma-Op โ„•-magma using ( _โˆ™_ )

Acceptance checks

โˆ™-Op interpreted in โ„•-magma reduces definitionally to _+_: no opacity from the opsToMagma construction, no opacity from the Curryโ‚‚ wrapping in the named accessor. Discharged by refl.

โˆ™-is-+-ma : โˆ€ (a b : โ„•) โ†’ a โˆ™ b โ‰ก a + b
โˆ™-is-+-ma a b = refl

The bundle bridge round-trips on โ„•-magma pointwise. Both directions reduce by pair a b 0F โ‡‰ a and pair a b 1F โ‡‰ b, so propositional refl discharges the obligation at the curried form (per ADR-002 v2 ยง6).

open Polymorphic.Magma-Op โŸช โŸจ โ„•-magma โŸฉแตแตƒ โŸซแตแตƒ using () renaming ( _โˆ™_ to _ยท_ )

roundtrip-โ„•-ma : โˆ€ (a b : โ„•) โ†’ a ยท b โ‰ก a + b
roundtrip-โ„•-ma a b = refl