pufferffish / agda-symmetries

MIT License
5 stars 1 forks source link

Write generic lemma about compatibility between lookup and sharp #52

Open github-actions[bot] opened 1 year ago

github-actions[bot] commented 1 year ago

lemma : (f : MonSym) (x : 𝔛 .carrier) (xs : List (𝔛 .carrier)) (a : Arity (length xs))

-> lookup (x ∷ xs) (fsuc a) ≑ sharp MonSig 𝔛 {!!} (lookup {!!} a)

lemma f \= {!!}

https://api.github.com/pufferffish/agda-symmetries/blob/0ff92bdb19aba58e89e9690583a23f811cdcca95/Cubical/Structures/Set/Mon/Desc.agda#L147


MonSig : Sig β„“-zero β„“-zero
MonSig = finSig MonFinSig

MonStruct : βˆ€ {n} -> Type (β„“-suc n)
MonStruct {n} = struct n MonSig

module MonStruct {β„“} (𝔛 : MonStruct {β„“}) where
  e : 𝔛 .carrier
  e = 𝔛 .algebra (`e , lookup [])

  e-eta : {i j : Arity 0 -> 𝔛 .carrier} -> 𝔛 .algebra (`e , i) ≑ 𝔛 .algebra (`e , j)
  e-eta {i} = cong (\j -> 𝔛 .algebra (`e , j)) (funExt Ξ» z -> lookup [] z)

  infixr 40 _βŠ•_
  _βŠ•_ : 𝔛 .carrier -> 𝔛 .carrier -> 𝔛 .carrier
  _βŠ•_ x y = 𝔛 .algebra (`βŠ• , lookup (x ∷ y ∷ []))

  βŠ•-eta : βˆ€ {β„“} {A : Type β„“} (i : Arity 2 -> A) (_β™― : A -> 𝔛 .carrier) -> 𝔛 .algebra (`βŠ• , (Ξ» w -> i w β™―)) ≑ (i fzero β™―) βŠ• (i fone β™―)
  βŠ•-eta i _β™― = cong (Ξ» z -> 𝔛 .algebra (`βŠ• , z)) (funExt lemma)
    where
    lemma : (x : Arity 2) -> (i x β™―) ≑ lookup ((i fzero β™―) ∷ (i fone β™―) ∷ []) x
    lemma (zero , p) = cong (_β™― ∘ i) (Σ≑Prop (Ξ» _ -> isProp≀) refl)
    lemma (suc zero , p) = cong (_β™― ∘ i) (Σ≑Prop (Ξ» _ -> isProp≀) refl)
    lemma (suc (suc n) , p) = βŠ₯.rec (Β¬m+n<m {m = 2} p)

data MonEq : Type where
  `unitl `unitr `assocr : MonEq

MonEqFree : MonEq -> β„•
MonEqFree `unitl = 1
MonEqFree `unitr = 1
MonEqFree `assocr = 3

MonEqSig : EqSig β„“-zero β„“-zero
MonEqSig = finEqSig (MonEq , MonEqFree)

monEqLhs : (eq : MonEq) -> FinTree MonFinSig (MonEqFree eq)
monEqLhs `unitl = node (`βŠ• , lookup (node (`e , lookup []) ∷ leaf fzero ∷ []))
monEqLhs `unitr = node (`βŠ• , lookup (leaf fzero ∷ node (`e , lookup []) ∷ []))
monEqLhs `assocr = node (`βŠ• , lookup (node (`βŠ• , lookup (leaf fzero ∷ leaf fone ∷ [])) ∷ leaf ftwo ∷ []))

monEqRhs : (eq : MonEq) -> FinTree MonFinSig (MonEqFree eq)
monEqRhs `unitl = leaf fzero
monEqRhs `unitr = leaf fzero
monEqRhs `assocr = node (`βŠ• , lookup (leaf fzero ∷ node (`βŠ• , lookup (leaf fone ∷ leaf ftwo ∷ [])) ∷ []))

MonSEq : seq MonSig MonEqSig
MonSEq n = monEqLhs n , monEqRhs n

module MonSEq {β„“} (𝔛 : MonStruct {β„“}) (Ο• : 𝔛 ⊨ MonSEq) where
  open MonStruct 𝔛 public

  unitl : βˆ€ m -> e βŠ• m ≑ m
  unitl m =
      e βŠ• m
    β‰‘βŸ¨βŸ©
      𝔛 .algebra (`βŠ• , lookup (𝔛 .algebra (`e , _) ∷ m ∷ []))
    β‰‘βŸ¨ cong (\w -> 𝔛 .algebra (`βŠ• , w)) (funExt lemma) ⟩
      𝔛 .algebra (`βŠ• , (Ξ» x -> sharp (finSig (MonSym , MonAr)) 𝔛 (lookup (m ∷ [])) (lookup (node (`e , _) ∷ leaf fzero ∷ []) x)))
    β‰‘βŸ¨ Ο• `unitl (lookup [ m ]) ⟩
      m ∎
    where
      lemma : (w : MonSig .arity `βŠ•) -> lookup (𝔛 .algebra (`e , (Ξ» num β†’ βŠ₯.rec (Β¬Fin0 num))) ∷ m ∷ []) w ≑ sharp (finSig (MonSym , MonAr)) 𝔛 (lookup (m ∷ [])) (lookup (node (`e , (Ξ» num β†’ βŠ₯.rec (Β¬Fin0 num))) ∷ leaf fzero ∷ []) w)
      lemma (zero , p) = sym e-eta
      lemma (suc zero , p) = refl
      lemma (suc (suc n) , p) = βŠ₯.rec (Β¬m+n<m {m = 2} p)

  unitr : βˆ€ m -> m βŠ• e ≑ m
  unitr m =
      m βŠ• e
    β‰‘βŸ¨βŸ©
      𝔛 .algebra (`βŠ• , lookup (m ∷ 𝔛 .algebra (`e , _) ∷ []))  
    β‰‘βŸ¨ cong (\w -> 𝔛 .algebra (`βŠ• , w)) (funExt lemma) ⟩
      𝔛 .algebra (`βŠ• , (Ξ» x -> sharp MonSig 𝔛 (lookup [ m ]) (lookup (leaf fzero ∷ node (`e , (Ξ» num β†’ βŠ₯.rec (Β¬Fin0 num))) ∷ []) x)))
    β‰‘βŸ¨ Ο• `unitr (lookup [ m ]) ⟩
      m ∎
    where
      lemma : (x : MonSig .arity `βŠ•) -> lookup (m ∷ 𝔛 .algebra (`e , (Ξ» num β†’ βŠ₯.rec (Β¬Fin0 num))) ∷ []) x ≑ sharp MonSig 𝔛 (lookup [ m ]) (lookup (leaf fzero ∷ node (`e , (Ξ» num β†’ βŠ₯.rec (Β¬Fin0 num))) ∷ []) x)
      lemma (zero , p) = refl
      lemma (suc zero , p) = sym e-eta
      lemma (suc (suc n) , p) = βŠ₯.rec (Β¬m+n<m {m = 2} p)

  assocr : βˆ€ m n o -> (m βŠ• n) βŠ• o ≑ m βŠ• (n βŠ• o)
  assocr m n o =
      (m βŠ• n) βŠ• o
    β‰‘βŸ¨βŸ©
      𝔛 .algebra (`βŠ• , lookup (𝔛 .algebra (`βŠ• , lookup (m ∷ n ∷ [])) ∷ o ∷ []))
    β‰‘βŸ¨ cong (\w -> 𝔛 .algebra (`βŠ• , w)) (funExt lemma1) ⟩
      𝔛 .algebra (`βŠ• , (\w -> sharp MonSig 𝔛 (lookup (m ∷ n ∷ o ∷ [])) (lookup (node (`βŠ• , lookup (leaf fzero ∷ leaf fone ∷ [])) ∷ leaf ftwo ∷ []) w)))
    β‰‘βŸ¨ Ο• `assocr (lookup (m ∷ n ∷ o ∷ [])) ⟩
      𝔛 .algebra (`βŠ• , (Ξ» w -> sharp MonSig 𝔛 (lookup (m ∷ n ∷ o ∷ [])) (lookup (leaf fzero ∷ node (`βŠ• , lookup (leaf fone ∷ leaf ftwo ∷ [])) ∷ []) w)))
    β‰‘βŸ¨ cong (\w -> 𝔛 .algebra (`βŠ• , w)) (sym (funExt lemma3)) ⟩
      𝔛 .algebra (`βŠ• , lookup (m ∷ 𝔛 .algebra (`βŠ• , lookup (n ∷ o ∷ [])) ∷ []))
    β‰‘βŸ¨βŸ©
      m βŠ• (n βŠ• o) ∎
    where
      lemma1 : (w : MonSig .arity `βŠ•) -> lookup (𝔛 .algebra (`βŠ• , lookup (m ∷ n ∷ [])) ∷ o ∷ []) w ≑ sharp MonSig 𝔛 (lookup (m ∷ n ∷ o ∷ [])) (lookup (node (`βŠ• , lookup (leaf fzero ∷ leaf fone ∷ [])) ∷ leaf ftwo ∷ []) w)
      lemma2 : (w : MonSig .arity `βŠ•) -> lookup (m ∷ n ∷ []) w ≑ sharp MonSig 𝔛 (lookup (m ∷ n ∷ o ∷ [])) (lookup (leaf fzero ∷ leaf fone ∷ []) w)

      lemma1 (zero , p) = cong (Ξ» o β†’ 𝔛 .algebra (`βŠ• , o)) (funExt lemma2)
      lemma1 (suc zero , p) = refl
      lemma1 (suc (suc n) , p) = βŠ₯.rec (Β¬m+n<m {m = 2} p)

      lemma2 (zero , p) = refl
      lemma2 (suc zero , p) = refl
      lemma2 (suc (suc n) , p) = βŠ₯.rec (Β¬m+n<m {m = 2} p)

      lemma3 : (w : MonSig .arity `βŠ•) -> lookup (m ∷ 𝔛 .algebra (`βŠ• , lookup (n ∷ o ∷ [])) ∷ []) w ≑ sharp MonSig 𝔛 (lookup (m ∷ n ∷ o ∷ [])) (lookup (leaf fzero ∷ node (`βŠ• , lookup (leaf fone ∷ leaf ftwo ∷ [])) ∷ []) w)
      lemma4 : (w : MonSig .arity `βŠ•) -> lookup (n ∷ o ∷ []) w ≑ sharp MonSig 𝔛 (lookup (m ∷ n ∷ o ∷ [])) (lookup (leaf fone ∷ leaf ftwo ∷ []) w)

      lemma3 (zero , p) = refl
      lemma3 (suc zero , p) = cong (Ξ» w β†’ 𝔛 .algebra (`βŠ• , w)) (funExt lemma4)
      lemma3 (suc (suc n) , p) = βŠ₯.rec (Β¬m+n<m {m = 2} p)

      lemma4 (zero , p) = refl
      lemma4 (suc zero , p) = refl
      lemma4 (suc (suc n) , p) = βŠ₯.rec (Β¬m+n<m {m = 2} p)

  -- TODO: Write generic lemma about compatibility between lookup and sharp
  -- lemma : (f : MonSym) (x : 𝔛 .carrier) (xs : List (𝔛 .carrier)) (a : Arity (length xs))
  --      -> lookup (x ∷ xs) (fsuc a) ≑ sharp MonSig 𝔛 {!!} (lookup {!!} a)
  -- lemma f = {!!}

module Examples where

  β„•-MonStr : MonStruct
  carrier β„•-MonStr = β„•
  algebra β„•-MonStr (`e , _) = 0
  algebra β„•-MonStr (`βŠ• , i) = i fzero + i fone

  β„•-MonStr-MonSEq : β„•-MonStr ⊨ MonSEq
  β„•-MonStr-MonSEq `unitl ρ = refl
  β„•-MonStr-MonSEq `unitr ρ = +-zero (ρ fzero)
  β„•-MonStr-MonSEq `assocr ρ = sym (+-assoc (ρ fzero) (ρ fone) (ρ ftwo))