--------------------------------------------------------------------------------
Ettore Aldrovandi, ealdrovandi@fsu.edu

Started: November 2022
Revision: June 2023
--------------------------------------------------------------------------------

Port of [HoTT-Agda](https://github.com/HoTT/HoTT-Agda) `PathSeq`
library to TypeTopology.

\begin{code}

{-# OPTIONS --without-K --safe #-}

module PathSequences.Concat where

open import MLTT.Spartan
open import UF.Base
open import PathSequences.Type

\end{code}

This module handles concatenation of path sequences. The developmenet
is very close to the module `Concat` in the original repository, with
a couple of extra items.

\begin{code}

_βˆ™β‰‘_ : {X : 𝓀 Μ‡ } {x y z : X}
     β†’ x ≑ y β†’ y ≑ z β†’ x ≑ z
[] βˆ™β‰‘ t = t
(p β—ƒβˆ™ s) βˆ™β‰‘ t = p β—ƒβˆ™ (s βˆ™β‰‘ t)

βˆ™β‰‘-assoc : {X : 𝓀 Μ‡ } {x y z w : X}
         β†’ (s : x ≑ y) (t : y ≑ z) (u : z ≑ w)
         β†’ (s βˆ™β‰‘ t) βˆ™β‰‘ u = s βˆ™β‰‘ (t βˆ™β‰‘ u)
βˆ™β‰‘-assoc [] t u = refl
βˆ™β‰‘-assoc (p β—ƒβˆ™ s) t u = ap (p β—ƒβˆ™_) (βˆ™β‰‘-assoc s t u)

\end{code}

The following is not in the original module, but it seems one should
have a proof of associativity for the direct equality _=ₛ_ between
path sequences.

\begin{code}

βˆ™β‰‘-assoc-=ₛ : {X : 𝓀 Μ‡ } {x y z w : X}
            β†’ (s : x ≑ y) (t : y ≑ z) (u : z ≑ w)
            β†’ ((s βˆ™β‰‘ t) βˆ™β‰‘ u) =ₛ (s βˆ™β‰‘ (t βˆ™β‰‘ u))
βˆ™β‰‘-assoc-=ₛ s t u = =ₛ-in (ap (Ξ» v β†’ [ v ↓]) (βˆ™β‰‘-assoc s t u))

\end{code}

We see βˆ™β‰‘-assoc is more fundamental.
Resuming…

\begin{code}

[]-βˆ™β‰‘-right-neutral : {X : 𝓀 Μ‡ } {x y : X}
                    β†’ (s : x ≑ y)
                    β†’ s βˆ™β‰‘ [] = s
[]-βˆ™β‰‘-right-neutral [] = refl
[]-βˆ™β‰‘-right-neutral (p β—ƒβˆ™ s) = ap (p β—ƒβˆ™_) ([]-βˆ™β‰‘-right-neutral s)

[]-βˆ™β‰‘-right-neutral-=ₛ : {X : 𝓀 Μ‡ } {x y : X}
                       β†’ (s : x ≑ y)
                       β†’ s βˆ™β‰‘ [] =ₛ s
[]-βˆ™β‰‘-right-neutral-=ₛ s =
 =ₛ-in (ap (Ξ» v β†’ [ v ↓]) ([]-βˆ™β‰‘-right-neutral s))


_βˆ™β–Ή_ : {X : 𝓀 Μ‡ } {x y z : X}
     β†’ x ≑ y β†’ y = z β†’ x ≑ z
s βˆ™β–Ή p = s βˆ™β‰‘ (p β—ƒβˆŽ)

≑-to-=-hom : {X : 𝓀 Μ‡ } {x y z : X}
            β†’ (s : x ≑ y) (t : y ≑ z)
            β†’ ([ s ↓]) βˆ™ ([ t ↓]) = [ (s βˆ™β‰‘ t) ↓]
≑-to-=-hom [] t = refl-left-neutral
≑-to-=-hom (p β—ƒβˆ™ s) [] =
 [ (p β—ƒβˆ™ s) ↓] βˆ™ [ [] ↓]  =⟨ refl-right-neutral [ (p β—ƒβˆ™ s) ↓] ⁻¹ ⟩
 [ (p β—ƒβˆ™ s) ↓]            =⟨ ap (Ξ» v β†’ [ v ↓]) Οƒ ⟩
 [ (p β—ƒβˆ™ s βˆ™β‰‘ []) ↓]       ∎
  where
   Οƒ = ([]-βˆ™β‰‘-right-neutral (p β—ƒβˆ™ s)) ⁻¹
≑-to-=-hom (p β—ƒβˆ™ s) (q β—ƒβˆ™ t) =
 [ (p β—ƒβˆ™ s) ↓] βˆ™ [ (q β—ƒβˆ™ t) ↓]  =⟨ refl ⟩
 (p βˆ™ [ s ↓]) βˆ™ [ (q β—ƒβˆ™ t) ↓]   =⟨ βˆ™assoc p [ s ↓]  [ q β—ƒβˆ™ t ↓] ⟩
 p βˆ™ ([ s ↓] βˆ™ [ q β—ƒβˆ™ t ↓])     =⟨ ap (p βˆ™_) (≑-to-=-hom s (q β—ƒβˆ™ t)) ⟩
 p βˆ™ [ s βˆ™β‰‘  (q β—ƒβˆ™ t) ↓]         =⟨ refl ⟩
 [ p β—ƒβˆ™ s βˆ™β‰‘ q β—ƒβˆ™ t ↓]           ∎

[↓]-hom = ≑-to-=-hom

\end{code}


Fixities

\begin{code}

infixr 80 _βˆ™β‰‘_
infixl 80 _βˆ™β–Ή_

\end{code}