Complete compiler-highlighted source. Follow a symbol to its declaration.
# Composition and cancellation We separate composition from its laws. The comparison type retains the specified witnesses: it is not Agda equality, and no uniqueness of comparison proofs is assumed. These records are interfaces for calculations, not a new definition of synthetic category. ```agda {-# OPTIONS --safe --without-K #-} module SCT.Calculus.Composition where open import Agda.Primitive using (Level; lsuc; _β_) record Composition (o h p : Level) : Set (lsuc (o β h β p)) where infixr 30 _β_ infix 10 _β_ field Obj : Set o Hom : Obj β Obj β Set h _β_ : {x y : Obj} β Hom x y β Hom x y β Set p id : (x : Obj) β Hom x x _β_ : {x y z : Obj} β Hom y z β Hom x y β Hom x z refl : {x y : Obj} (f : Hom x y) β f β f sym : {x y : Obj} {f g : Hom x y} β f β g β g β f trans : {x y : Obj} {f g h : Hom x y} β g β h β f β g β f β h congr : {x y z : Obj} {g gβ² : Hom y z} {f fβ² : Hom x y} β g β gβ² β f β fβ² β (g β f) β (gβ² β fβ²) record Laws {o h p : Level} (C : Composition o h p) : Set (o β h β p) where open Composition C field assoc : {w x y z : Obj} (h : Hom y z) (g : Hom x y) (f : Hom w x) β ((h β g) β f) β (h β (g β f)) unitΛ‘ : {x y : Obj} (f : Hom x y) β (id y β f) β f unitΚ³ : {x y : Obj} (f : Hom x y) β (f β id x) β f ``` Cancellation needs only the displayed inverse comparison. It does not require an inverse operation or a global choice of inverses. Reassociate, apply that comparison, and remove the identity. ```agda module Calculation {o h p : Level} (C : Composition o h p) (L : Laws C) where open Composition C open Laws L abstract cancel-left : {x y z : Obj} (r : Hom z y) (s : Hom y z) (f : Hom x y) β (r β s) β id y β (r β (s β f)) β f cancel-left r s f inverse = trans (unitΛ‘ f) (trans (congr inverse (refl f)) (sym (assoc r s f))) cancel-right : {x y z : Obj} (f : Hom y z) (s : Hom x y) (r : Hom y x) β (s β r) β id y β ((f β s) β r) β f cancel-right f s r inverse = trans (unitΚ³ f) (trans (congr (refl f) inverse) (assoc f s r)) reassociate-four : {v w x y z : Obj} (k : Hom y z) (h : Hom x y) (g : Hom w x) (f : Hom v w) β (((k β h) β g) β f) β (k β (h β (g β f))) reassociate-four k h g f = trans (assoc k h (g β f)) (assoc (k β h) g f) ```