{-# OPTIONS --safe --lossy-unification #-}
module Cubical.Homotopy.Whitehead where

open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.GroupoidLaws

open import Cubical.Data.Nat
open import Cubical.Data.Sigma
open import Cubical.Data.Unit

open import Cubical.HITs.Susp renaming (toSusp to σ)
open import Cubical.HITs.Pushout
open import Cubical.HITs.Sn
open import Cubical.HITs.Sn.Multiplication
open import Cubical.HITs.Join
open import Cubical.HITs.Wedge
open import Cubical.HITs.SetTruncation

open import Cubical.Homotopy.Group.Base
open import Cubical.Homotopy.Loopspace

open Iso
open 3x3-span

-- Whitehead product (main definition)
[_∣_]-pre :  {} {X : Pointed } {n m : }
        (S₊∙ (suc n) →∙ X)
        (S₊∙ (suc m) →∙ X)
        join∙ (S₊∙ n) (S₊∙ m) →∙ X
fst ([_∣_]-pre {X = X} {n = n} {m = m} f g) (inl x) = pt X
fst ([_∣_]-pre {X = X} {n = n} {m = m} f g) (inr x) = pt X
fst ([_∣_]-pre {n = n} {m = m} f g) (push a b i) =
  (Ω→ g .fst (σS b)  Ω→ f .fst (σS a)) i
snd ([_∣_]-pre {n = n} {m = m} f g) = refl

[_∣_] :  {} {X : Pointed } {n m : }
        (S₊∙ (suc n) →∙ X)
        (S₊∙ (suc m) →∙ X)
        S₊∙ (suc (n + m)) →∙ X
[_∣_] {n = n} {m = m} f g =
  [ f  g ]-pre ∘∙ (sphere→Join n m , IsoSphereJoin⁻Pres∙ n m)

-- Whitehead product (as a composition)
joinTo⋁ :  { ℓ'} {A : Pointed } {B : Pointed ℓ'}
  join (typ A) (typ B)
  (Susp (typ A) , north)  (Susp (typ B) , north)
joinTo⋁ (inl x) = inr north
joinTo⋁ (inr x) = inl north
joinTo⋁ {A = A} {B = B} (push a b i) =
     ((λ i  inr (σ B b i))
  ∙∙ sym (push tt)
  ∙∙ λ i  inl (σ A a i)) i

[_∣_]comp :  {} {X : Pointed } {n m : }
        (S₊∙ (suc n) →∙ X)
        (S₊∙ (suc m) →∙ X)
        S₊∙ (suc (n + m)) →∙ X
[_∣_]comp {n = n} {m = m} f g =
    (((f ∘∙ (inv (IsoSucSphereSusp n) , IsoSucSphereSusp∙ n))
  ∨→ (g ∘∙ (inv (IsoSucSphereSusp m) , IsoSucSphereSusp∙ m))
    , cong (fst f) (IsoSucSphereSusp∙ n)  snd f)
  ∘∙ ((joinTo⋁ {A = S₊∙ n} {B = S₊∙ m} , sym (push tt))))
  ∘∙ (inv (IsoSphereJoin n m) , IsoSphereJoin⁻Pres∙ n m)

[]comp≡[] :  {} {X : Pointed } {n m : }
        (f : (S₊∙ (suc n) →∙ X))
        (g : (S₊∙ (suc m) →∙ X))
        [ f  g ]comp  [ f  g ]
[]comp≡[] {X = X} {n = n} {m} f g =
  cong (_∘∙ (sphere→Join n m , IsoSphereJoin⁻Pres∙ n m)) (main n m f g)
    where
    ∨fun : {n m : } (f : (S₊∙ (suc n) →∙ X)) (g : (S₊∙ (suc m) →∙ X))
       ((_ , inl north) →∙ X)
    ∨fun {n = n} {m} f g =
       ((f ∘∙ (inv (IsoSucSphereSusp n) , IsoSucSphereSusp∙ n)) ∨→
       (g ∘∙ (inv (IsoSucSphereSusp m) , IsoSucSphereSusp∙ m))
       , cong (fst f) (IsoSucSphereSusp∙ n)  snd f)

    open import Cubical.Foundations.Path
    main : (n m : ) (f : (S₊∙ (suc n) →∙ X)) (g : (S₊∙ (suc m) →∙ X))
       (∨fun f g ∘∙ (joinTo⋁ {A = S₊∙ n} {B = S₊∙ m} , sym (push tt)))
       [ f  g ]-pre
    main n m f g =
      ΣPathP ((funExt  { (inl x)  rp
                         ; (inr x)  lp
                         ; (push a b i) j  pushcase a b j i}))
          , ((cong₂ _∙_ (symDistr _ _) refl
           sym (assoc _ _ _)
           cong (rp ∙_) (rCancel _)
           sym (rUnit rp))
           λ i j  rp (i  j)))
      where
      lp = cong (fst f) (IsoSucSphereSusp∙ n)  snd f
      rp = cong (fst g) (IsoSucSphereSusp∙ m)  snd g

      help : (n : ) (a : _)
         Square (cong (inv (IsoSucSphereSusp n)) (σ (S₊∙ n) a)) (σS a)
                  (IsoSucSphereSusp∙ n) (IsoSucSphereSusp∙ n)
      help zero a = cong-∙ SuspBool→S¹ (merid a) (sym (merid (pt (S₊∙ zero))))
                   sym (rUnit _)
      help (suc n) a = refl

      ∙∙Distr∙ :  {} {A : Type } {x y z w u : A}
                 {p : x  y} {q : y  z} {r : z  w} {s : w  u}
                p ∙∙ q  r ∙∙ s  ((p  q)  r  s)
      ∙∙Distr∙ = doubleCompPath≡compPath _ _ _
                assoc _ _ _
                cong₂ _∙_ (assoc _ _ _) refl
                sym (assoc _ _ _)


      pushcase : (a : S₊ n) (b : S₊ m)
         Square (cong (∨fun f g .fst  joinTo⋁ {A = S₊∙ n} {B = S₊∙ m}) (push a b))
                  (cong (fst [ f  g ]-pre) (push a b))
                  rp lp
      pushcase a b =
        (cong-∙∙ (∨fun f g .fst) _ _ _
          i  cong (fst g) (PathP→compPathR∙∙ (help _ b) i)
              ∙∙ symDistr lp (sym rp) i
              ∙∙ cong (fst f) (PathP→compPathR∙∙ (help _ a) i))
          i  cong (fst g)
                      (IsoSucSphereSusp∙ m
                     ∙∙ σS b
                     ∙∙  j  IsoSucSphereSusp∙ m (~ j  i)))
              ∙∙ compPath-filler' (cong (fst g) (IsoSucSphereSusp∙ m)) (snd g) (~ i)
                sym (compPath-filler' (cong (fst f) (IsoSucSphereSusp∙ n)) (snd f) (~ i))
              ∙∙ cong (fst f)
                      ((λ j  IsoSucSphereSusp∙ n (i  j))
                      ∙∙ σS a
                      ∙∙ sym (IsoSucSphereSusp∙ n))))
        compPathR→PathP∙∙
           ( ∙∙Distr∙
           cong₂ _∙_ (cong₂ _∙_ (cong (cong (fst g)) (sym (compPath≡compPath' _ _)))
                                 refl)
                      refl
           cong₂ _∙_ (cong (_∙ snd g) (cong-∙ (fst g) (IsoSucSphereSusp∙ m) (σS b))
                                      sym (assoc _ _ _))
                      (cong (sym (snd f) ∙_)
                        (cong-∙ (fst f) (σS a)
                          (sym (IsoSucSphereSusp∙ n)))
                          assoc _ _ _)
           sym ∙∙Distr∙
           cong₃ _∙∙_∙∙_ refl (cong₂ _∙_ refl (compPath≡compPath' _ _)) refl
          λ i  compPath-filler (cong (fst g) (IsoSucSphereSusp∙ m)) (snd g) i
               ∙∙ ((λ j  snd g (~ j  i)) ∙∙ cong (fst g) (σS b) ∙∙ snd g)
                 (sym (snd f) ∙∙ cong (fst f) (σS a) ∙∙ λ j  snd f (j  i))
               ∙∙ sym (compPath-filler (cong (fst f) (IsoSucSphereSusp∙ n)) (snd f) i))

-- Homotopy group version
[_∣_]π' :  {} {X : Pointed } {n m : }
        π' (suc n) X  π' (suc m) X
        π' (suc (n + m)) X
[_∣_]π' = elim2  _ _  squash₂) λ f g   [ f  g ] ∣₂

-- We prove that the function joinTo⋁ used in the definition of the whitehead
-- product gives an equivalence between (Susp A × Susp B) and the
-- appropriate cofibre of joinTo⋁ (last two theorems in the following
-- module).

module _ (A B : Type) (a₀ : A) (b₀ : B) where
  private
    W = joinTo⋁ {A = (A , a₀)} {B = (B , b₀)}

  A∨B = (Susp A , north)  (Susp B , north)

  σB = σ (B , b₀)
  σA = σ (A , a₀)

  cofibW = Pushout W λ _  tt

  whitehead3x3 :  3x3-span
  A00 whitehead3x3 = Susp A
  A02 whitehead3x3 = B
  A04 whitehead3x3 = Unit
  A20 whitehead3x3 = B
  A22 whitehead3x3 = A × B
  A24 whitehead3x3 = A
  A40 whitehead3x3 = B
  A42 whitehead3x3 = B
  A44 whitehead3x3 = Unit
  f10 whitehead3x3 _ = south
  f12 whitehead3x3 = snd
  f14 whitehead3x3 _ = tt
  f30 whitehead3x3 = idfun B
  f32 whitehead3x3 = snd
  f34 whitehead3x3 _ = tt
  f01 whitehead3x3 _ = north
  f21 whitehead3x3 = snd
  f41 whitehead3x3 = idfun B
  f03 whitehead3x3 _ = tt
  f23 whitehead3x3 = fst
  f43 whitehead3x3 _ = tt
  H11 whitehead3x3 x = merid (fst x)
  H13 whitehead3x3 _ = refl
  H31 whitehead3x3 _ = refl
  H33 whitehead3x3 _ = refl

  A0□→A∨B : A0□ whitehead3x3  A∨B
  A0□→A∨B (inl x) = inl x
  A0□→A∨B (inr x) = inr north
  A0□→A∨B (push a i) = (push tt  λ i  inr (σB a (~ i))) i

  A∨B→A0□ : A∨B  A0□ whitehead3x3
  A∨B→A0□ (inl x) = inl x
  A∨B→A0□ (inr north) = inl north
  A∨B→A0□ (inr south) = inl north
  A∨B→A0□ (inr (merid b i)) = (push b₀  sym (push b)) i
  A∨B→A0□ (push a i) = inl north

  Iso-A0□-⋁ : Iso (A0□ whitehead3x3) A∨B
  fun Iso-A0□-⋁ = A0□→A∨B
  inv Iso-A0□-⋁ = A∨B→A0□
  rightInv Iso-A0□-⋁ (inl x) = refl
  rightInv Iso-A0□-⋁ (inr north) = push tt
  rightInv Iso-A0□-⋁ (inr south) = push tt  λ i  inr (merid b₀ i)
  rightInv Iso-A0□-⋁ (inr (merid a i)) j = lem j i
    where
    lem : PathP  i  push tt i  (push tt   i  inr (merid b₀ i))) i)
              (cong A0□→A∨B (cong A∨B→A0□ λ i  inr (merid a i)))
               i  inr (merid a i))
    lem = (cong-∙ A0□→A∨B (push b₀) (sym (push a))
       cong₂ _∙_ (cong (push tt ∙_)
                   j i  inr (rCancel (merid b₀) j (~ i)))
                  sym (rUnit (push tt)))
                  (symDistr (push tt)  i  inr (σB a (~ i)))))
       λ i j  hcomp  k 
                  λ { (i = i0)  compPath-filler' (push tt)
                                 (compPath-filler  i  inr (σB a i))
                                                  (sym (push tt)) k) k j
                    ; (i = i1)  inr (merid a j)
                    ; (j = i0)  push tt (i  ~ k)
                    ; (j = i1)  compPath-filler' (push tt)
                                                   i  inr (merid b₀ i)) k i})
                        (inr (compPath-filler (merid a)
                                              (sym (merid b₀)) (~ i) j))

  rightInv Iso-A0□-⋁ (push a i) j = push tt (i  j)
  leftInv Iso-A0□-⋁ (inl x) = refl
  leftInv Iso-A0□-⋁ (inr tt) = push b₀
  leftInv Iso-A0□-⋁ (push b i) j = help j i
    where
    help : PathP  i  inl north  push b₀ i)
                 (cong A∨B→A0□ (cong A0□→A∨B (push b)))
                 (push b)
    help = (cong-∙ A∨B→A0□ (push tt)  i  inr (σB b (~ i)))
           i  lUnit (sym (cong-∙ (A∨B→A0□  inr)
                               (merid b) (sym (merid b₀)) i)) (~ i))
          cong sym (cong ((push b₀  sym (push b)) ∙_)
                      (cong sym (rCancel (push b₀))))
          cong sym (sym (rUnit (push b₀  sym (push b)))))
          λ i j  compPath-filler' (push b₀) (sym (push b)) (~ i) (~ j)

  Iso-A2□-join : Iso (A2□ whitehead3x3) (join A B)
  fun Iso-A2□-join (inl x) = inr x
  fun Iso-A2□-join (inr x) = inl x
  fun Iso-A2□-join (push (a , b) i) = push a b (~ i)
  inv Iso-A2□-join (inl x) = inr x
  inv Iso-A2□-join (inr x) = inl x
  inv Iso-A2□-join (push a b i) = push (a , b) (~ i)
  rightInv Iso-A2□-join (inl x) = refl
  rightInv Iso-A2□-join (inr x) = refl
  rightInv Iso-A2□-join (push a b i) = refl
  leftInv Iso-A2□-join (inl x) = refl
  leftInv Iso-A2□-join (inr x) = refl
  leftInv Iso-A2□-join (push a i) = refl

  isContrA4□ : isContr (A4□ whitehead3x3)
  fst isContrA4□ = inr tt
  snd isContrA4□ (inl x) = sym (push x)
  snd isContrA4□ (inr x) = refl
  snd isContrA4□ (push a i) j = push a (i  ~ j)

  A4□≃Unit : A4□ whitehead3x3  Unit
  A4□≃Unit = isContr→≃Unit isContrA4□

  Iso-A□0-Susp : Iso (A□0 whitehead3x3) (Susp A)
  fun Iso-A□0-Susp (inl x) = x
  fun Iso-A□0-Susp (inr x) = north
  fun Iso-A□0-Susp (push a i) = merid a₀ (~ i)
  inv Iso-A□0-Susp x = inl x
  rightInv Iso-A□0-Susp x = refl
  leftInv Iso-A□0-Susp (inl x) = refl
  leftInv Iso-A□0-Susp (inr x) =  i  inl (merid a₀ i))  push x
  leftInv Iso-A□0-Susp (push a i) j =
    hcomp  k  λ { (i = i0)  inl (merid a₀ (k  j))
                    ; (i = i1)  compPath-filler
                                    i₁  inl (merid a₀ i₁))
                                   (push (idfun B a)) k j
                    ; (j = i0)  inl (merid a₀ (~ i  k))
                    ; (j = i1)  push a (i  k)})
          (inl (merid a₀ j))

  Iso-A□2-Susp× : Iso (A□2 whitehead3x3) (Susp A × B)
  fun Iso-A□2-Susp× (inl x) = north , x
  fun Iso-A□2-Susp× (inr x) = south , x
  fun Iso-A□2-Susp× (push a i) = merid (fst a) i , (snd a)
  inv Iso-A□2-Susp× (north , y) = inl y
  inv Iso-A□2-Susp× (south , y) = inr y
  inv Iso-A□2-Susp× (merid a i , y) = push (a , y) i
  rightInv Iso-A□2-Susp× (north , snd₁) = refl
  rightInv Iso-A□2-Susp× (south , snd₁) = refl
  rightInv Iso-A□2-Susp× (merid a i , snd₁) = refl
  leftInv Iso-A□2-Susp× (inl x) = refl
  leftInv Iso-A□2-Susp× (inr x) = refl
  leftInv Iso-A□2-Susp× (push a i) = refl

  Iso-A□4-Susp : Iso (A□4 whitehead3x3) (Susp A)
  fun Iso-A□4-Susp (inl x) = north
  fun Iso-A□4-Susp (inr x) = south
  fun Iso-A□4-Susp (push a i) = merid a i
  inv Iso-A□4-Susp north = inl tt
  inv Iso-A□4-Susp south = inr tt
  inv Iso-A□4-Susp (merid a i) = push a i
  rightInv Iso-A□4-Susp north = refl
  rightInv Iso-A□4-Susp south = refl
  rightInv Iso-A□4-Susp (merid a i) = refl
  leftInv Iso-A□4-Susp (inl x) = refl
  leftInv Iso-A□4-Susp (inr x) = refl
  leftInv Iso-A□4-Susp (push a i) = refl

  Iso-PushSusp×-Susp×Susp :
    Iso (Pushout {A = Susp A × B} fst fst) (Susp A × Susp B)
  Iso-PushSusp×-Susp×Susp = theIso
    where
    F : Pushout {A = Susp A × B} fst fst
      Susp A × Susp B
    F (inl x) = x , north
    F (inr x) = x , north
    F (push (x , b) i) = x , σB b i

    G : Susp A × Susp B  Pushout {A = Susp A × B} fst fst
    G (a , north) = inl a
    G (a , south) = inr a
    G (a , merid b i) = push (a , b) i

    retr : retract F G
    retr (inl x) = refl
    retr (inr x) = push (x , b₀)
    retr (push (a , b) i) j = help j i
      where
      help : PathP  i  Path (Pushout fst fst) (inl a) (push (a , b₀) i))
                   (cong G  i  a , σB b i))
                   (push (a , b))
      help = cong-∙  x  G (a , x)) (merid b) (sym (merid b₀))
                   λ i j  compPath-filler
                               (push (a , b))
                               (sym (push (a , b₀)))
                               (~ i) j

    theIso : Iso (Pushout fst fst) (Susp A × Susp B)
    fun theIso = F
    inv theIso = G
    rightInv theIso (a , north) = refl
    rightInv theIso (a , south) = ΣPathP (refl , merid b₀)
    rightInv theIso (a , merid b i) j =
      a , compPath-filler (merid b) (sym (merid b₀)) (~ j) i
    leftInv theIso = retr

  Iso-A□○-PushSusp× :
    Iso (A□○ whitehead3x3) (Pushout {A = Susp A × B} fst fst)
  Iso-A□○-PushSusp× =
    pushoutIso _ _ fst fst
      (isoToEquiv Iso-A□2-Susp×)
      (isoToEquiv Iso-A□0-Susp)
      (isoToEquiv Iso-A□4-Susp)
      (funExt  { (inl x)  refl
                 ; (inr x)  merid a₀
                 ; (push a i) j  help₁ a j i}))
      (funExt λ { (inl x)  refl
                ; (inr x)  refl
                ; (push a i) j
                   fun Iso-A□4-Susp (rUnit (push (fst a)) (~ j) i)})
    where
    help₁ : (a : A × B)
       PathP  i  north  merid a₀ i)
               (cong (fun Iso-A□0-Susp)
                 (cong (f□1 whitehead3x3) (push a)))
               (merid (fst a))
    help₁ a =
        (cong-∙∙ (fun Iso-A□0-Susp)
                  i  inl (merid (fst a) i))
                 (push (snd a))
                 refl)
        i j  hcomp  k  λ {(i = i1)  merid (fst a) (j  ~ k)
                                 ; (j = i0)  merid (fst a) (~ k)
                                 ; (j = i1)  merid a₀ i})
                        (merid a₀ (i  ~ j)))

  Iso-A□○-Susp×Susp : Iso (A□○ whitehead3x3) (Susp A × Susp B)
  Iso-A□○-Susp×Susp = compIso Iso-A□○-PushSusp× Iso-PushSusp×-Susp×Susp

  Iso-A○□-cofibW : Iso (A○□ whitehead3x3) cofibW
  Iso-A○□-cofibW =
    pushoutIso _ _
      W  _  tt)
      (isoToEquiv Iso-A2□-join) (isoToEquiv Iso-A0□-⋁)
      A4□≃Unit
      (funExt lem)
      λ _ _  tt
    where
    lem : (x : A2□ whitehead3x3)
       A0□→A∨B (f1□ whitehead3x3 x)  W (fun Iso-A2□-join x)
    lem (inl x) =  i  inl (merid a₀ (~ i)))
    lem (inr x) = refl
    lem (push (a , b) i) j = help j i
      where
      help : PathP  i  Path (Pushout  _  north)  _  north))
                                ((inl (merid a₀ (~ i))))
                                (inr north))
                   (cong A0□→A∨B (cong (f1□ whitehead3x3) (push (a , b))))
                   (cong W (cong (fun Iso-A2□-join) (push (a , b))))
      help = (cong-∙∙ A0□→A∨B  i  inl (merid a (~ i))) (push b) refl
             λ j   i₂  inl (merid a (~ i₂)))
                   ∙∙ compPath-filler (push tt)  i  inr (σB b (~ i))) (~ j)
                   ∙∙ λ i  inr (σB b (~ i  j)))
             j   i  inl (sym (compPath-filler
                                       (merid a) (sym (merid a₀)) j) i))
                   ∙∙ push tt
                   ∙∙ λ i  inr (σB b (~ i)))

  Iso₁-Susp×Susp-cofibW : Iso (Susp A × Susp B) cofibW
  Iso₁-Susp×Susp-cofibW =
    compIso (invIso Iso-A□○-Susp×Susp)
            (compIso (3x3-Iso whitehead3x3) Iso-A○□-cofibW)

  -- Main iso
  Iso-Susp×Susp-cofibJoinTo⋁ : Iso (Susp A × Susp B) cofibW
  Iso-Susp×Susp-cofibJoinTo⋁ =
    compIso (Σ-cong-iso-snd  _  invSuspIso))
            Iso₁-Susp×Susp-cofibW

  -- The induced function A ∨ B → Susp A × Susp B satisfies
  -- the following identity
  Susp×Susp→cofibW≡ : Path (A∨B  Susp A × Susp B)
                      (Iso.inv Iso-Susp×Susp-cofibJoinTo⋁  inl)
                      ⋁↪
  Susp×Susp→cofibW≡ =
    funExt λ { (inl x)  ΣPathP (refl , (sym (merid b₀)))
             ; (inr north)  ΣPathP (refl , (sym (merid b₀)))
             ; (inr south)  refl
             ; (inr (merid a i)) j  lem₂ a j i
             ; (push a i) j  north , (merid b₀ (~ j))}
    where
    f₁ = fun Iso-PushSusp×-Susp×Susp
    f₂ = fun Iso-A□○-PushSusp×
    f₃ = backward-l whitehead3x3
    f₄ = fun (Σ-cong-iso-snd  _  invSuspIso))

    lem : (b : B)
       cong (f₁  f₂  f₃) (push b)
        i  north , σB b i)
    lem b = cong (cong f₁) (sym (rUnit (push (north , b))))

    lem₂ : (a : B)
       PathP  i  (north , merid b₀ (~ i))  (north , south))
               (cong (f₄  f₁  f₂  f₃  A∨B→A0□  inr) (merid a))
               λ i  north , merid a i
    lem₂ a =
         cong (cong f₄) (cong-∙ (f₁  f₂  f₃) (push b₀) (sym (push a))
      ∙∙ cong₂ _∙_ (lem b₀   j i  north , rCancel (merid b₀) j i))
                   (cong sym (lem a))
      ∙∙ sym (lUnit  i₁  north , σB a (~ i₁))))
         i j  north , cong-∙ invSusp (merid a) (sym (merid b₀)) i (~ j) )
         λ i j  north , compPath-filler (sym (merid a)) (merid b₀) (~ i) (~ j)

-- Generalised Whitehead products
module _ { ℓ' ℓ''} {A : Pointed }
         {B : Pointed ℓ'} {C : Pointed ℓ''}
         (f : Susp∙ (typ A) →∙ C) (g : Susp∙ (typ B) →∙ C) where

  _·w_ : join∙ A B →∙ C
  fst _·w_ (inl x) = pt C
  fst _·w_ (inr x) = pt C
  fst _·w_ (push a b i) = (Ω→ g .fst (σ B b)  Ω→ f .fst (σ A a)) i
  snd _·w_ = refl

  -- The generalised Whitehead product vanishes under suspension
  isConst-Susp·w : suspFun∙ (_·w_ .fst)  const∙ _ _
  isConst-Susp·w = Susp·w∙
                  cong suspFun∙ (cong fst isConst-const*)
                  ΣPathP ((suspFunConst (pt C)) , refl)
    where
    const* : join∙ A B →∙ C
    fst const* (inl x) = pt C
    fst const* (inr x) = pt C
    fst const* (push a b i) =
      (Ω→ f .fst (σ A a)  Ω→ g .fst (σ B b)) i
    snd const* = refl

    isConst-const* : const*  const∙ _ _
    fst (isConst-const* i) (inl x) = Ω→ f .fst (σ A x) i
    fst (isConst-const* i) (inr x) = Ω→ g .fst (σ B x) (~ i)
    fst (isConst-const* i) (push a b j) =
      compPath-filler'' (Ω→ f .fst (σ A a)) (Ω→ g .fst (σ B b)) (~ i) j
    snd (isConst-const* i) j =
      (cong (Ω→ f .fst) (rCancel (merid (pt A)))  Ω→ f .snd) j i

    Susp·w : suspFun (fst _·w_)  suspFun (fst const*)
    Susp·w i north = north
    Susp·w i south = south
    Susp·w i (merid (inl x) j) = merid (pt C) j
    Susp·w i (merid (inr x) j) = merid (pt C) j
    Susp·w i (merid (push a b k) j) =
      hcomp  r 
        λ {(i = i0)  fill₁ k (~ r) j
         ; (i = i1)  fill₂ k (~ r) j
         ; (j = i0)  north
         ; (j = i1)  merid (pt C) r
         ; (k = i0)  compPath-filler (merid (snd C)) (merid (pt C) ⁻¹) (~ r) j
         ; (k = i1)  compPath-filler (merid (snd C)) (merid (pt C) ⁻¹) (~ r) j})
       (hcomp  r 
        λ {(i = i0)  doubleCompPath-filler
                         (sym (rCancel (merid (pt C))))
                          k  fill₁ k i1)
                         (rCancel (merid (pt C))) (~ r) k j
         ; (i = i1)  doubleCompPath-filler
                         (sym (rCancel (merid (pt C))))
                          k  fill₂ k i1)
                         (rCancel (merid (pt C))) (~ r) k j
         ; (j = i0)  north
         ; (j = i1)  north
         ; (k = i0)  rCancel (merid (pt C)) (~ r) j
         ; (k = i1)  rCancel (merid (pt C)) (~ r) j})
           (main i k j))
      where
      F : Ω C .fst  (Ω^ 2) (Susp∙ (fst C)) .fst
      F p = sym (rCancel (merid (pt C)))
         ∙∙ cong (σ C) p
         ∙∙ rCancel (merid (pt C))

      F-hom : (p q : _)  F (p  q)  F p  F q
      F-hom p q =
          cong (sym (rCancel (merid (pt C)))
               ∙∙_∙∙ rCancel (merid (pt C)))
               (cong-∙ (σ C) p q)
         doubleCompPath≡compPath (sym (rCancel (merid (pt C)))) _ _
         cong (sym (rCancel (merid (pt C))) ∙_)
               (sym (assoc _ _ _))
         assoc _ _ _
          i  (sym (rCancel (merid (pt C)))
                 compPath-filler (cong (σ C) p) (rCancel (merid (pt C))) i)
                 compPath-filler' (sym (rCancel (merid (pt C))))
                                   (cong (σ C) q  rCancel (merid (pt C))) i)
         cong₂ _∙_ (sym (doubleCompPath≡compPath _ _ _))
                    (sym (doubleCompPath≡compPath _ _ _))

      main : F ((Ω→ g .fst (σ B b)  Ω→ f .fst (σ A a)))
            F ((Ω→ f .fst (σ A a)  Ω→ g .fst (σ B b)))
      main = F-hom (Ω→ g .fst (σ B b)) (Ω→ f .fst (σ A a))
            EH 0 _ _
            sym (F-hom (Ω→ f .fst (σ A a)) (Ω→ g .fst (σ B b)))

      fill₁ : (k : I)  _
      fill₁ k = compPath-filler
                (merid ((Ω→ g .fst (σ B b)
                        Ω→ f .fst (σ A a)) k))
                (merid (pt C) ⁻¹)

      fill₂ : (k : I)  _
      fill₂ k = compPath-filler
                (merid ((Ω→ f .fst (σ A a)
                        Ω→ g .fst (σ B b)) k))
                (merid (pt C) ⁻¹)

    Susp·w∙ : suspFun∙ (_·w_ .fst)  suspFun∙ (fst const*)
    Susp·w∙ = ΣPathP (Susp·w , refl)