Other Agda modules in this section (76)

Complete compiler-highlighted source. Follow a symbol to its declaration.

# Normalizing a nested application after restriction

The following pasting is stated for arbitrary terms and endpoint
comparisons. It uses the supplied restriction square for application of
composition and the already proved naturality of that application.

```agda
{-# OPTIONS --safe --without-K #-}
open import Agda.Primitive using (Level)
open import SCT.VolumeI.Chapter01.Theory using (Theory)
import SCT.Calculus.Squares as Squares
import SCT.VolumeI.Chapter01.Section04.Substitution.ProofCalculus as Setup
import SCT.VolumeI.Chapter01.Section04.MappingAnimae as Mapping
import SCT.VolumeI.Chapter01.Section04.Composition as MapComposition
import SCT.VolumeI.Chapter01.Section04.Substitution.MappingProofCalculus as MappingProof
import SCT.VolumeI.Chapter01.Section04.CompositionCalculus.CompositionRestrictionCalculus as Restriction

module SCT.VolumeI.Chapter01.Section04.Substitution.NestedApplicationRestriction
  {c m a : Level} (𝒯 : Theory c m a) (M : Mapping.MappingAnimae 𝒯) where
open Setup 𝒯
private
  module Paste (X Y : CAT) = Squares (comparisonAlgebra X Y) (comparisonLaws X Y)
open Mapping.MappingAnimae M
open MapComposition 𝒯 M
open MappingProof 𝒯 M
open Restriction 𝒯 M using (apply-compose-natural)

module Assembly {Ξ“ R C D E : CAT}
  (gβ‚€ : MAP Ξ“ (Map D E)) (fβ‚€ : MAP Ξ“ (Map C D)) (xβ‚€ : MAP Ξ“ C)
  (s : MAP R Ξ“)
  {gβ€² : MAP R (Map D E)} {fβ€² : MAP R (Map C D)} {xβ€² : MAP R C}
  (ag : (gβ‚€ ∘ s) =₁ gβ€²) (af : (fβ‚€ ∘ s) =₁ fβ€²) (b : (xβ‚€ ∘ s) =₁ xβ€²)
  {K : MAP Ξ“ (Map C E)} (d : K =₁ (composeTerm gβ‚€ fβ‚€))
  {S : MAP Ξ“ E} {T : MAP R E}
  (Aβ‚€ : S =₁ (applyTerm K xβ‚€)) (Bβ‚€ : T =₁ (S ∘ s))
  (Cβ‚€ : (applyTerm (composeTerm gβ‚€ fβ‚€) xβ‚€) =₁ (applyTerm gβ‚€ (applyTerm fβ‚€ xβ‚€)))
  (C₁ : (applyTerm (composeTerm (gβ‚€ ∘ s) (fβ‚€ ∘ s)) (xβ‚€ ∘ s)) =₁
    (applyTerm (gβ‚€ ∘ s) (applyTerm (fβ‚€ ∘ s) (xβ‚€ ∘ s))))
  (Cβ‚‚ : (applyTerm (composeTerm gβ€² fβ€²) xβ€²) =₁ (applyTerm gβ€² (applyTerm fβ€² xβ€²))) where

  source-coordinate = composeTerm-cong ag af βˆ™
    (composeTerm-pre gβ‚€ fβ‚€ s βˆ™ (d β–· s))
  before = applyTerm-cong ag (applyTerm-cong af b βˆ™ applyTerm-pre fβ‚€ xβ‚€ s) βˆ™
    (applyTerm-pre gβ‚€ (applyTerm fβ‚€ xβ‚€) s βˆ™
      (((Cβ‚€ βˆ™ (applyTerm-cong d (idIso xβ‚€) βˆ™ Aβ‚€)) β–· s) βˆ™ Bβ‚€))
  after = Cβ‚‚ βˆ™
    (applyTerm-cong source-coordinate b βˆ™
      (applyTerm-pre K xβ‚€ s βˆ™ ((Aβ‚€ β–· s) βˆ™ Bβ‚€)))

  module Calculation
    (restriction :
      (C₁ βˆ™ (applyTerm-cong (composeTerm-pre gβ‚€ fβ‚€ s) (idIso (xβ‚€ ∘ s)) βˆ™
        applyTerm-pre (composeTerm gβ‚€ fβ‚€) xβ‚€ s)) =β‚‚
      ((applyTerm-cong (idIso (gβ‚€ ∘ s)) (applyTerm-pre fβ‚€ xβ‚€ s) βˆ™
          applyTerm-pre gβ‚€ (applyTerm fβ‚€ xβ‚€) s) βˆ™ (Cβ‚€ β–· s)))
    (naturality : (Cβ‚‚ βˆ™ applyTerm-cong (composeTerm-cong ag af) b) =β‚‚
      (applyTerm-cong ag (applyTerm-cong af b) βˆ™ C₁)) where
    Pf = applyTerm-pre fβ‚€ xβ‚€ s
    Pg = applyTerm-pre gβ‚€ (applyTerm fβ‚€ xβ‚€) s
    N = applyTerm-cong ag (applyTerm-cong af b βˆ™ Pf)
    changed = applyTerm-cong ag (applyTerm-cong af b)
    restricted = applyTerm-cong (idIso (gβ‚€ ∘ s)) Pf
    Dβ‚€ = applyTerm-cong d (idIso xβ‚€)
    tail = (Aβ‚€ β–· s) βˆ™ Bβ‚€
    rest = (Dβ‚€ β–· s) βˆ™ tail
    e = composeTerm-pre gβ‚€ fβ‚€ s
    Ract = applyTerm-cong e (idIso (xβ‚€ ∘ s))
    Pmid = applyTerm-pre (composeTerm gβ‚€ fβ‚€) xβ‚€ s
    middle-route = Ract βˆ™ Pmid
    Qact = applyTerm-cong (composeTerm-cong ag af) b
    Psource = applyTerm-pre K xβ‚€ s
    Uact = applyTerm-cong (d β–· s) (idIso (xβ‚€ ∘ s))
    base = Psource βˆ™ tail

    private
      module Route = Paste.NestedRoute R E
        N Pg (((Cβ‚€ βˆ™ (Dβ‚€ βˆ™ Aβ‚€)) β–· s) βˆ™ Bβ‚€)
        changed restricted (Cβ‚€ β–· s) rest C₁ middle-route Cβ‚‚ Qact
        Ract Uact base
        (applyTerm-cong (e βˆ™ (d β–· s)) (idIso (xβ‚€ ∘ s)))
        (applyTerm-cong source-coordinate b)

    opaque
      expandV : (((Cβ‚€ βˆ™ (Dβ‚€ βˆ™ Aβ‚€)) β–· s) βˆ™ Bβ‚€) =β‚‚ ((Cβ‚€ β–· s) βˆ™ rest)
      expandV = isoComp-cong (idIso (Cβ‚€ β–· s)) (isoComp-assoc-at (Dβ‚€ β–· s) (Aβ‚€ β–· s) Bβ‚€) βˆ™
        (isoComp-assoc-at (Cβ‚€ β–· s) ((Dβ‚€ β–· s) βˆ™ (Aβ‚€ β–· s)) Bβ‚€ βˆ™
          isoComp-cong
            (isoComp-cong (idIso (Cβ‚€ β–· s)) (preWhisker-isoComp-at Dβ‚€ Aβ‚€ s) βˆ™
              preWhisker-isoComp-at Cβ‚€ (Dβ‚€ βˆ™ Aβ‚€) s) (idIso Bβ‚€))
    opaque
      splitN : N =β‚‚ (changed βˆ™ restricted)
      splitN = apply-cong-comp ag (idIso (gβ‚€ ∘ s)) (applyTerm-cong af b) Pf βˆ™
        (apply-cong-Isoβ‚‚ (isoComp-unitΚ³-at ag) (idIso (applyTerm-cong af b βˆ™ Pf))) ⁻¹
    opaque
      useRestriction : (restricted βˆ™ (Pg βˆ™ ((Cβ‚€ β–· s) βˆ™ rest))) =β‚‚ (C₁ βˆ™ (middle-route βˆ™ rest))
      useRestriction = Paste.composite-square-with-tail R E
        restricted Pg (Cβ‚€ β–· s) C₁ middle-route rest (restriction ⁻¹)
    opaque
      useNaturality : (changed βˆ™ (C₁ βˆ™ (middle-route βˆ™ rest))) =β‚‚ (Cβ‚‚ βˆ™ (Qact βˆ™ (middle-route βˆ™ rest)))
      useNaturality = Paste.square-with-tail R E
        changed C₁ Cβ‚‚ Qact (middle-route βˆ™ rest) (naturality ⁻¹)
    opaque
      projectionNatural : (Pmid βˆ™ (Dβ‚€ β–· s)) =β‚‚ (Uact βˆ™ Psource)
      projectionNatural = isoComp-cong
          (apply-cong-Isoβ‚‚ (idIso (d β–· s)) (preWhisker-idIso xβ‚€ s)) (idIso Psource) βˆ™
        binary-pre-inputs mapEval d (idIso xβ‚€) s
    opaque
      exchange : (Pmid βˆ™ rest) =β‚‚ (Uact βˆ™ base)
      exchange = Paste.square-with-tail R E
        Pmid (Dβ‚€ β–· s) Uact Psource tail projectionNatural
    opaque
      useProjection : (middle-route βˆ™ rest) =β‚‚ (Ract βˆ™ (Uact βˆ™ base))
      useProjection = isoComp-cong (idIso Ract) exchange βˆ™
        isoComp-assoc-at Ract Pmid rest
    opaque
      combineInner : (Ract βˆ™ (Uact βˆ™ base)) =β‚‚ (applyTerm-cong (e βˆ™ (d β–· s)) (idIso (xβ‚€ ∘ s)) βˆ™ base)
      combineInner = isoComp-cong
          (apply-cong-Isoβ‚‚ (idIso (e βˆ™ (d β–· s))) (isoComp-unitΛ‘-at (idIso (xβ‚€ ∘ s))))
          (idIso base) βˆ™
        combine-apply e (idIso (xβ‚€ ∘ s)) (d β–· s) (idIso (xβ‚€ ∘ s)) base
    opaque
      combineOuter : (Qact βˆ™ (applyTerm-cong (e βˆ™ (d β–· s)) (idIso (xβ‚€ ∘ s)) βˆ™ base)) =β‚‚ (applyTerm-cong source-coordinate b βˆ™ base)
      combineOuter = isoComp-cong
          (apply-cong-Isoβ‚‚ (idIso source-coordinate) (isoComp-unitΚ³-at b)) (idIso base) βˆ™
        combine-apply (composeTerm-cong ag af) b (e βˆ™ (d β–· s)) (idIso (xβ‚€ ∘ s)) base
    opaque
      finish : (Cβ‚‚ βˆ™ (Qact βˆ™ (middle-route βˆ™ rest))) =β‚‚ after
      finish = Route.finish useProjection combineInner combineOuter
    opaque
      begin : before =β‚‚ (changed βˆ™ (restricted βˆ™ (Pg βˆ™ ((Cβ‚€ β–· s) βˆ™ rest))))
      begin = Route.begin splitN expandV
    opaque
      result : before =β‚‚ after
      result = Route.result finish useNaturality useRestriction begin
  opaque
    comparison :
      (C₁ βˆ™
        (applyTerm-cong (composeTerm-pre gβ‚€ fβ‚€ s) (idIso (xβ‚€ ∘ s)) βˆ™
          applyTerm-pre (composeTerm gβ‚€ fβ‚€) xβ‚€ s)) =β‚‚
      ((applyTerm-cong (idIso (gβ‚€ ∘ s)) (applyTerm-pre fβ‚€ xβ‚€ s) βˆ™
          applyTerm-pre gβ‚€ (applyTerm fβ‚€ xβ‚€) s) βˆ™ (Cβ‚€ β–· s))
      β†’ (Cβ‚‚ βˆ™ applyTerm-cong (composeTerm-cong ag af) b) =β‚‚
        (applyTerm-cong ag (applyTerm-cong af b) βˆ™ C₁)
      β†’ before =β‚‚ after
    comparison = Calculation.result
```