Other Agda modules in this folder (2)
Complete compiler-highlighted source. Follow a symbol to its declaration.
# Pasting comparison routes A route through a commutative diagram can be normalized by its component squares and a specified cancellation. The objects, arrows, and comparison witnesses remain parameters; these calculations use no equality of proofs. ```agda {-# OPTIONS --safe --without-K #-} open import Agda.Primitive using (Level) open import SCT.Calculus.Composition using (Composition; Laws) module SCT.Calculus.Squares {o h p : Level} (C : Composition o h p) (L : Laws C) where open Composition C open Laws L ``` For two routes joined by an intermediate comparison, first normalize their initial segment, then paste the input square, and finally cancel the specified inverse pair. Each supplied square occurs in the resulting witness. ```agda abstract comparison-route-pasting : {sβ sβ sβ sβ sβ t zβ zβ zβ z : Obj} (T : Hom t z) (R : Hom sβ t) (A : Hom sβ sβ) (G : Hom sβ sβ) (B : Hom sβ sβ) (Ξ· : Hom sβ sβ) (n : Hom sβ zβ) (W : Hom zβ zβ) (WQ : Hom sβ zβ) (changed : Hom zβ z) (corner : Hom zβ zβ) (application : Hom zβ z) (inverseApplication : Hom z zβ) (application-route : Hom sβ z) β (T β R) β ((changed β W) β n) β (corner β WQ) β (W β (n β (A β G))) β (changed β corner) β application β (WQ β (B β Ξ·)) β (inverseApplication β application-route) β (application β inverseApplication) β id z β (T β (R β (A β (G β (B β Ξ·))))) β application-route comparison-route-pasting T R A G B Ξ· n W WQ changed corner application inverseApplication application-route normal inputChange cancelCorner cancelEvaluation cancelApplication = let tail = B β Ξ· finish = trans (unitΛ‘ application-route) (trans (congr cancelApplication (refl application-route)) (trans (sym (assoc application inverseApplication application-route)) (congr (refl application) cancelEvaluation))) normalizeTail = trans (congr cancelCorner (refl (WQ β tail))) (trans (sym (assoc changed corner (WQ β tail))) (trans (congr (refl changed) (assoc corner WQ tail)) (congr (refl changed) (congr (sym inputChange) (refl tail))))) regroupInner = trans (sym (assoc W (n β (A β G)) tail)) (trans (congr (refl W) (sym (assoc n (A β G) tail))) (congr (refl W) (congr (refl n) (sym (assoc A G tail))))) regroup = trans (congr (refl changed) regroupInner) (trans (assoc changed W (n β (A β (G β tail)))) (assoc (changed β W) n (A β (G β tail)))) normalizeStart = trans (congr normal (refl (A β (G β tail)))) (sym (assoc T R (A β (G β tail)))) in trans finish (trans normalizeTail (trans regroup normalizeStart)) ``` A square may be pasted after a factored input. If the outer action cancels the top comparison, the composite reduces to the remaining two sides. ```agda abstract factored-square : {s a b c d z : Obj} (outer : Hom c z) (left : Hom b c) (right : Hom a d) (input : Hom a b) (action : Hom d c) (changed : Hom d z) (tail : Hom s a) (image : Hom s b) β (outer β action) β changed β (left β input) β (action β right) β image β (input β tail) β ((outer β left) β image) β ((changed β right) β tail) factored-square outer left right input action changed tail image cancelAction natural factor = trans (sym (assoc changed right tail)) (trans (congr cancelAction (refl (right β tail))) (trans (sym (assoc outer action (right β tail))) (trans (congr (refl outer) (assoc action right tail)) (trans (congr (refl outer) (congr natural (refl tail))) (trans (congr (refl outer) (sym (assoc left input tail))) (trans (assoc outer left (input β tail)) (congr (refl (outer β left)) factor))))))) ``` For a common frame, paste the restriction square with the naturality square, merge the two images, and cancel the supplied reverse frame comparison. The fourfold reassociation and the frame cancellation are specified inputs, so applications can retain their existing witnesses even when those arise from a different realization of the elementary laws. ```agda abstract common-frame-pasting : {sβ sβ sβ sβ sβ rβ rβ rβ z : Obj} (outer : Hom sβ z) (G : Hom sβ sβ) (A : Hom sβ sβ) (N : Hom sβ z) (pre : Hom sβ sβ) (W : Hom sβ sβ) (Wβ : Hom rβ sβ) (Wβ : Hom rβ sβ) (paired : Hom rβ rβ) (pairPre : Hom rβ rβ) (postB : Hom rβ rβ) (frame : Hom sβ rβ) (back : Hom rβ sβ) β N β (outer β (G β A)) β (A β (pre β W)) β (Wβ β (pairPre β frame)) β (G β Wβ) β (Wβ β paired) β (paired β pairPre) β postB β ((Wβ β paired) β (pairPre β frame)) β (Wβ β ((paired β pairPre) β frame)) β ((((outer β Wβ) β postB) β frame) β back) β ((outer β Wβ) β postB) β (N β (pre β (W β back))) β ((outer β Wβ) β postB) common-frame-pasting outer G A N pre W Wβ Wβ paired pairPre postB frame back splitN restriction natural merge regroupFour cancellation = let lower = trans (congr (refl outer) (trans (congr (refl Wβ) (congr merge (refl frame))) regroupFour)) (congr (refl outer) (trans (congr natural (refl (pairPre β frame))) (sym (assoc G Wβ (pairPre β frame))))) beforeCancel = trans (sym (assoc (outer β Wβ) postB frame)) (trans (sym (assoc outer Wβ (postB β frame))) (trans lower (trans (congr (refl outer) (congr (refl G) restriction)) (trans (congr (refl outer) (assoc G A (pre β W))) (trans (assoc outer (G β A) (pre β W)) (congr splitN (refl (pre β W)))))))) regroup = trans (sym (assoc N (pre β W) back)) (congr (refl N) (sym (assoc pre W back))) in trans cancellation (trans (congr beforeCancel (refl back)) regroup) ``` A normalized operation is a comparison of its inputs after restriction. For its short route, use the substitution square, iterate restriction, and combine the two input comparisons. The iteration and combination witnesses are supplied by the operation under consideration. ```agda abstract normalized-substitution-square : {sβ sβ sβ tβ tβ b z : Obj} (paired : Hom tβ z) (newPre : Hom sβ tβ) (change : Hom sβ sβ) (A : Hom sβ sβ) (changed : Hom tβ tβ) (oldPre : Hom sβ tβ) (action : Hom b tβ) (base : Hom sβ b) (inner : Hom b tβ) (whole : Hom b z) β (newPre β change) β (changed β oldPre) β (oldPre β A) β (action β base) β (changed β (action β base)) β (inner β base) β (paired β (inner β base)) β (whole β base) β ((paired β newPre) β (change β A)) β (whole β base) normalized-substitution-square paired newPre change A changed oldPre action base inner whole substituteSquare iteration combineInner combineOuter = let substitute = trans (assoc changed oldPre A) (trans (congr substituteSquare (refl A)) (sym (assoc newPre change A))) iterate = congr (refl changed) iteration in trans combineOuter (trans (congr (refl paired) (trans combineInner (trans iterate substitute))) (assoc paired newPre (change β A))) ``` For the long route, distribute restriction over the existing normalization, use the input square, then combine its output comparisons. ```agda abstract normalized-input-square : {s a b c e z : Obj} (outer : Hom e z) (middle : Hom c e) (input : Hom a c) (before : Hom s a) (output : Hom b e) (pre : Hom a b) (image : Hom s c) (whole : Hom b z) β (middle β input) β (output β pre) β image β (input β before) β (outer β (output β (pre β before))) β (whole β (pre β before)) β (outer β (middle β image)) β (whole β (pre β before)) normalized-input-square outer middle input before output pre image whole natural split combine = let exchange = trans (assoc output pre before) (trans (congr natural (refl before)) (sym (assoc middle input before))) in trans combine (trans (congr (refl outer) exchange) (congr (refl outer) (congr (refl middle) split))) ``` Changing an input and restricting it give adjacent squares. Expand the specified source comparison, paste the change square with the restriction square, then combine the two actions on the output. ```agda abstract change-restriction-square : {s a b x y zβ zβ : Obj} (leftβ² : Hom b zβ) (change : Hom a b) (middle : Hom a zβ) (first : Hom zβ zβ) (second : Hom x zβ) (pre : Hom y x) (retained : Hom s y) (tail : Hom s a) (source : Hom s b) (whole : Hom x zβ) β (first β second) β whole β (middle β tail) β (second β (pre β retained)) β (leftβ² β change) β (first β middle) β source β (change β tail) β (leftβ² β source) β ((whole β pre) β retained) change-restriction-square leftβ² change middle first second pre retained tail source whole normalizeAction restriction natural expandSource = let normalizeEnd = trans (sym (assoc whole pre retained)) (trans (congr normalizeAction (refl (pre β retained))) (sym (assoc first second (pre β retained)))) useRestriction = trans (congr (refl first) restriction) (assoc first middle tail) useChange = trans (congr natural (refl tail)) (sym (assoc leftβ² change tail)) expand = congr (refl leftβ²) expandSource in trans normalizeEnd (trans useRestriction (trans useChange expand)) ``` A factored input can be transported through a square and then combined with an outer comparison. The factorization, naturality, and combination witnesses are explicit; the calculation only supplies the reassociations. ```agda abstract compose-input-square : {s a b c e z : Obj} (outer : Hom e z) (middle : Hom c e) (input : Hom a c) (before : Hom s a) (output : Hom b e) (pre : Hom a b) (image : Hom s c) (whole : Hom b z) β (middle β input) β (output β pre) β (outer β output) β whole β image β (input β before) β (outer β (middle β image)) β (whole β (pre β before)) compose-input-square outer middle input before output pre image whole natural join split = let exchange = trans (assoc output pre before) (trans (congr natural (refl before)) (sym (assoc middle input before))) expand = congr (refl middle) split in trans (congr join (refl (pre β before))) (trans (sym (assoc outer output (pre β before))) (congr (refl outer) (trans exchange expand))) ``` A square remains commutative after adjoining the same tail to both routes. For a route with two initial comparisons, the second calculation includes its additional reassociation explicitly. ```agda abstract square-with-tail : {s a b c z : Obj} (left : Hom b z) (bottom : Hom a b) (top : Hom c z) (right : Hom a c) (tail : Hom s a) β (left β bottom) β (top β right) β (left β (bottom β tail)) β (top β (right β tail)) square-with-tail left bottom top right tail square = trans (assoc top right tail) (trans (congr square (refl tail)) (sym (assoc left bottom tail))) composite-square-with-tail : {s a b c d z : Obj} (left : Hom c z) (middle : Hom b c) (bottom : Hom a b) (top : Hom d z) (right : Hom a d) (tail : Hom s a) β ((left β middle) β bottom) β (top β right) β (left β (middle β (bottom β tail))) β (top β (right β tail)) composite-square-with-tail left middle bottom top right tail square = trans (assoc top right tail) (trans (congr square (refl tail)) (trans (sym (assoc (left β middle) bottom tail)) (sym (assoc left middle (bottom β tail))))) ``` Two successive input comparisons can be normalized along a naturality square. Supply both combination comparisons separately, so the result retains their prescribed witnesses. ```agda abstract normalize-comparison-route : {s t a b c d z : Obj} (outer : Hom d z) (first : Hom c d) (second : Hom b c) (third : Hom a b) (after : Hom t c) (e : Hom s t) (sourceAfter : Hom s b) (tail : Hom s a) (inner : Hom a c) (whole : Hom a d) β (second β (third β tail)) β (inner β tail) β (first β (inner β tail)) β (whole β tail) β (after β e) β (second β sourceAfter) β sourceAfter β (third β tail) β ((outer β (first β after)) β e) β (outer β (whole β tail)) normalize-comparison-route outer first second third after e sourceAfter tail inner whole joinInner joinOuter natural restrict = let normalize = trans joinOuter (congr (refl first) (trans joinInner (congr (refl second) restrict))) expand = trans (congr (refl outer) (trans (congr (refl first) natural) (assoc first after e))) (assoc outer (first β after) e) in trans (congr (refl outer) normalize) expand ``` For a nested input, keep the boundary routes as parameters while pasting restriction, naturality, and the two input-combination comparisons. The application-specific calculations supply these comparisons; the following assembly only performs the displayed congruences and reassociations. ```agda module NestedRoute {s n q r c d e u v z : Obj} (N : Hom n z) (Pg : Hom q n) (V : Hom s q) (changed : Hom c z) (restricted : Hom n c) (Cβ : Hom r q) (rest : Hom s r) (Cβ : Hom d c) (middle : Hom r d) (Cβ : Hom e z) (Qact : Hom d e) (Ract : Hom u d) (Uact : Hom v u) (base : Hom s v) (inner : Hom v d) (whole : Hom v e) where abstract finish : (middle β rest) β (Ract β (Uact β base)) β (Ract β (Uact β base)) β (inner β base) β (Qact β (inner β base)) β (whole β base) β (Cβ β (Qact β (middle β rest))) β (Cβ β (whole β base)) finish project combineInner combineOuter = congr (refl Cβ) (trans combineOuter (congr (refl Qact) (trans combineInner project))) begin : N β (changed β restricted) β V β (Cβ β rest) β (N β (Pg β V)) β (changed β (restricted β (Pg β (Cβ β rest)))) begin split expand = trans (assoc changed restricted (Pg β (Cβ β rest))) (congr split (congr (refl Pg) expand)) result : (Cβ β (Qact β (middle β rest))) β (Cβ β (whole β base)) β (changed β (Cβ β (middle β rest))) β (Cβ β (Qact β (middle β rest))) β (restricted β (Pg β (Cβ β rest))) β (Cβ β (middle β rest)) β (N β (Pg β V)) β (changed β (restricted β (Pg β (Cβ β rest)))) β (N β (Pg β V)) β (Cβ β (whole β base)) result finish natural restrict begin = trans finish (trans natural (trans (congr (refl changed) restrict) begin)) ``` Naturality can be transported between two chosen normalization routes. The four route squares and the central naturality square remain explicit. The conclusion retains the common final comparison, which a caller may subsequently cancel using its chosen reflection operation. ```agda abstract normalization-naturality : {xβ xβ yβ yβ uβ uβ vβ vβ : Obj} (a : Hom xβ yβ) (aβ² : Hom xβ yβ) (S : Hom xβ xβ) (T : Hom yβ yβ) (L : Hom xβ uβ) (Lβ² : Hom xβ uβ) (R : Hom yβ vβ) (Rβ² : Hom yβ vβ) (l : Hom uβ uβ) (r : Hom vβ vβ) (A : Hom uβ vβ) (Aβ² : Hom uβ vβ) β (R β a) β (A β L) β (Rβ² β aβ²) β (Aβ² β Lβ²) β (Lβ² β S) β (l β L) β (Rβ² β T) β (r β R) β (Aβ² β l) β (r β A) β (Rβ² β (aβ² β S)) β (Rβ² β (T β a)) normalization-naturality a aβ² S T L Lβ² R Rβ² l r A Aβ² route routeβ² left right central = trans (assoc Rβ² T a) (trans (congr (sym right) (refl a)) (trans (sym (assoc r R a)) (trans (congr (refl r) (sym route)) (trans (assoc r A L) (trans (congr central (refl L)) (trans (sym (assoc Aβ² l L)) (trans (congr (refl Aβ²) left) (trans (assoc Aβ² Lβ² S) (trans (congr routeβ² (refl S)) (sym (assoc Rβ² aβ² S))))))))))) ``` Changing the source and target frames of a square uses the prescribed normalization of its input and the prescribed cancellation of the target frame. No inverse operation or uniqueness of comparison proofs is assumed. ```agda abstract normalized-frame-square : {x a b y d e : Obj} (k : Hom a d) (kβ² : Hom b e) (back : Hom x a) (v : Hom b y) (reverse : Hom y b) (z : Hom a b) (w : Hom d e) (input : Hom x y) β (kβ² β z) β (w β k) β (reverse β (v β (z β back))) β (z β back) β input β (v β (z β back)) β ((kβ² β reverse) β input) β (w β (k β back)) normalized-frame-square k kβ² back v reverse z w input natural cancel normalize = trans (assoc w k back) (trans (congr natural (refl back)) (trans (sym (assoc kβ² z back)) (trans (congr (refl kβ²) cancel) (trans (assoc kβ² reverse (v β (z β back))) (congr (refl (kβ² β reverse)) normalize))))) ```