# Morphisms of spans on families of types

```agda
module foundation.morphisms-spans-families-of-types where
```

<details><summary>Imports</summary>

```agda
open import foundation.commuting-triangles-of-homotopies
open import foundation.dependent-pair-types
open import foundation.equality-dependent-function-types
open import foundation.fundamental-theorem-of-identity-types
open import foundation.homotopy-induction
open import foundation.spans-families-of-types
open import foundation.structure-identity-principle
open import foundation.universe-levels
open import foundation.whiskering-homotopies-composition

open import foundation-core.commuting-triangles-of-maps
open import foundation-core.equivalences
open import foundation-core.homotopies
open import foundation-core.identity-types
open import foundation-core.torsorial-type-families
```

</details>

## Idea

Consider two [spans](foundation.spans-families-of-types.md) `๐’ฎ := (S , f)` and
`๐’ฏ := (T , g)` on a family of types `A : I โ†’ ๐’ฐ`. A
{{#concept "morphism" Disambiguation="span on a family of types" Agda=hom-span-type-family}}
from `๐’ฎ` to `๐’ฏ` consists of a map `h : S โ†’ T` and a
[homotopy](foundation-core.homotopies.md) witnessing that the triangle

```text
        h
    S ----> T
     \     /
  f i \   / g i
       โˆจ โˆจ
       A i
```

[commutes](foundation-core.commuting-triangles-of-maps.md) for every `i : I`.

## Definitions

### Morphisms of spans on families of types

```agda
module _
  {l1 l2 l3 l4 : Level} {I : UU l1} {A : I โ†’ UU l2}
  (๐’ฎ : span-type-family l3 A) (๐’ฏ : span-type-family l4 A)
  where

  hom-span-type-family : UU (l1 โŠ” l2 โŠ” l3 โŠ” l4)
  hom-span-type-family =
    ฮฃ ( spanning-type-span-type-family ๐’ฎ โ†’
        spanning-type-span-type-family ๐’ฏ)
      ( ฮป h โ†’
        (i : I) โ†’
        coherence-triangle-maps
          ( map-span-type-family ๐’ฎ i)
          ( map-span-type-family ๐’ฏ i)
          ( h))

module _
  {l1 l2 l3 l4 : Level} {I : UU l1} {A : I โ†’ UU l2}
  (๐’ฎ : span-type-family l3 A) (๐’ฏ : span-type-family l4 A)
  (h : hom-span-type-family ๐’ฎ ๐’ฏ)
  where

  map-hom-span-type-family :
    spanning-type-span-type-family ๐’ฎ โ†’
    spanning-type-span-type-family ๐’ฏ
  map-hom-span-type-family = pr1 h

  coherence-triangle-hom-span-type-family :
    (i : I) โ†’
    coherence-triangle-maps
      ( map-span-type-family ๐’ฎ i)
      ( map-span-type-family ๐’ฏ i)
      ( map-hom-span-type-family)
  coherence-triangle-hom-span-type-family =
    pr2 h
```

### Homotopies of morphisms of spans on families of types

Consider two spans `๐’ฎ := (S , f)` and `๐’ฏ := (T , g)` on a family of types
`A : I โ†’ ๐’ฐ`, and consider two morphisms `(h , H)` and `(k , K)` between them. A
{{#concept "homotopy" Disambiguation="morphism between spans on families of types" Agda=htpy-hom-span-type-family}}
is a pair `(ฮฑ , ฮฒ)` consisting of a homotopy

```text
  ฮฑ : h ~ k
```

and a family `ฮฒ` of homotopies witnessing that the triangle

```text
              f i
             /   \
        H i / ฮฒ i \ K i
           โˆจ       โˆจ
  (g i โˆ˜ h) ------> (g i โˆ˜ k)
            g i ยท ฮฑ
```

commutes for each `i : I`.

```agda
module _
  {l1 l2 l3 l4 : Level} {I : UU l1} {A : I โ†’ UU l2}
  (๐’ฎ : span-type-family l3 A) (๐’ฏ : span-type-family l4 A)
  (h k : hom-span-type-family ๐’ฎ ๐’ฏ)
  where

  coherence-htpy-hom-span-type-family :
    map-hom-span-type-family ๐’ฎ ๐’ฏ h ~ map-hom-span-type-family ๐’ฎ ๐’ฏ k โ†’
    UU (l1 โŠ” l2 โŠ” l3)
  coherence-htpy-hom-span-type-family ฮฑ =
    (i : I) โ†’
    coherence-triangle-homotopies'
      ( coherence-triangle-hom-span-type-family ๐’ฎ ๐’ฏ k i)
      ( map-span-type-family ๐’ฏ i ยทl ฮฑ)
      ( coherence-triangle-hom-span-type-family ๐’ฎ ๐’ฏ h i)

  htpy-hom-span-type-family : UU (l1 โŠ” l2 โŠ” l3 โŠ” l4)
  htpy-hom-span-type-family =
    ฮฃ ( map-hom-span-type-family ๐’ฎ ๐’ฏ h ~ map-hom-span-type-family ๐’ฎ ๐’ฏ k)
      ( coherence-htpy-hom-span-type-family)

  module _
    (ฮฑ : htpy-hom-span-type-family)
    where

    htpy-htpy-hom-span-type-family :
      map-hom-span-type-family ๐’ฎ ๐’ฏ h ~ map-hom-span-type-family ๐’ฎ ๐’ฏ k
    htpy-htpy-hom-span-type-family = pr1 ฮฑ

    coh-htpy-hom-span-type-family :
      coherence-htpy-hom-span-type-family htpy-htpy-hom-span-type-family
    coh-htpy-hom-span-type-family = pr2 ฮฑ
```

### The reflexivity homotopy on a morphism of spans on families of types

```agda
module _
  {l1 l2 l3 l4 : Level} {I : UU l1} {A : I โ†’ UU l2}
  (๐’ฎ : span-type-family l3 A) (๐’ฏ : span-type-family l4 A)
  (h : hom-span-type-family ๐’ฎ ๐’ฏ)
  where

  refl-htpy-hom-span-type-family :
    htpy-hom-span-type-family ๐’ฎ ๐’ฏ h h
  pr1 refl-htpy-hom-span-type-family = refl-htpy
  pr2 refl-htpy-hom-span-type-family i = right-unit-htpy
```

## Properties

### Characterization of identifications of morphisms of spans on families of types

```agda
module _
  {l1 l2 l3 l4 : Level} {I : UU l1} {A : I โ†’ UU l2}
  (๐’ฎ : span-type-family l3 A) (๐’ฏ : span-type-family l4 A)
  (h : hom-span-type-family ๐’ฎ ๐’ฏ)
  where

  htpy-eq-hom-span-type-family :
    (k : hom-span-type-family ๐’ฎ ๐’ฏ) โ†’
    h ๏ผ k โ†’ htpy-hom-span-type-family ๐’ฎ ๐’ฏ h k
  htpy-eq-hom-span-type-family .h refl =
    refl-htpy-hom-span-type-family ๐’ฎ ๐’ฏ h

  is-torsorial-htpy-hom-span-type-family :
    is-torsorial (htpy-hom-span-type-family ๐’ฎ ๐’ฏ h)
  is-torsorial-htpy-hom-span-type-family =
    is-torsorial-Eq-structure
      ( is-torsorial-htpy _)
      ( map-hom-span-type-family ๐’ฎ ๐’ฏ h , refl-htpy)
      ( is-torsorial-Eq-ฮ  (ฮป i โ†’ is-torsorial-htpy _))

  is-equiv-htpy-eq-hom-span-type-family :
    (k : hom-span-type-family ๐’ฎ ๐’ฏ) โ†’
    is-equiv (htpy-eq-hom-span-type-family k)
  is-equiv-htpy-eq-hom-span-type-family =
    fundamental-theorem-id
      ( is-torsorial-htpy-hom-span-type-family)
      ( htpy-eq-hom-span-type-family)

  extensionality-hom-span-type-family :
    (k : hom-span-type-family ๐’ฎ ๐’ฏ) โ†’
    (h ๏ผ k) โ‰ƒ htpy-hom-span-type-family ๐’ฎ ๐’ฏ h k
  pr1 (extensionality-hom-span-type-family k) =
    htpy-eq-hom-span-type-family k
  pr2 (extensionality-hom-span-type-family k) =
    is-equiv-htpy-eq-hom-span-type-family k

  eq-htpy-hom-span-type-family :
    (k : hom-span-type-family ๐’ฎ ๐’ฏ) โ†’
    htpy-hom-span-type-family ๐’ฎ ๐’ฏ h k โ†’ h ๏ผ k
  eq-htpy-hom-span-type-family k =
    map-inv-equiv (extensionality-hom-span-type-family k)
```