Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Cubical/Algebra/Monoid/Instances/List.agda
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Cubical.Algebra.Monoid.Instances.List where

open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Structure

open import Cubical.Data.List

Expand All @@ -14,3 +15,46 @@ MonoidStr.ε (snd (ListMonoid _)) = []
MonoidStr._·_ (snd (ListMonoid _)) = _++_
MonoidStr.isMonoid (snd (ListMonoid (_ , pf))) = makeIsMonoid (isOfHLevelList 0 pf)
(λ x y z → sym (++-assoc x y z)) ++-unit-r (λ _ → refl)

foldlMonHom : (M : Monoid ℓ-zero) → MonoidHom (ListMonoid (fst M , MonoidStr.is-set (snd M))) M
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this only for level zero? Can't it be universe polymorphic?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why decompose M? Shouldn't ListMonoid M work?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it universe polymorphic :). I dont think ListMonoid M works because I only need fact that it's a set from the structure.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, of course!

foldlMonHom m = fn , monoidequiv refl respects∙
where _∙m_ = (MonoidStr._·_ (snd m))
fn : ⟨ ListMonoid (fst m , MonoidStr.is-set (snd m)) ⟩ → ⟨ m ⟩
fn xs = foldl (_∙m_) (MonoidStr.ε (snd m)) xs
∙foldl : (x y : (fst m)) → (xs : List (fst m)) → x ∙m (foldl _∙m_ y xs) ≡ foldl _∙m_ (x ∙m y) xs
∙foldl x y [] = refl
∙foldl x y (x₁ ∷ xs) = x ∙m foldl _∙m_ y (x₁ ∷ xs)
≡⟨ cong (x ∙m_) (sym (∙foldl y x₁ xs)) ⟩
x ∙m (y ∙m foldl _∙m_ x₁ xs)
≡⟨ MonoidStr.·Assoc (snd m) x y (foldl _∙m_ x₁ xs) ⟩
(x ∙m y) ∙m foldl _∙m_ x₁ xs
≡⟨ ∙foldl (x ∙m y) x₁ xs ⟩
foldl _∙m_ (x ∙m y) (x₁ ∷ xs) ∎
fnCons : (x : (fst m)) → (xs : List (fst m)) → x ∙m (fn xs) ≡ (fn (x ∷ xs))
fnCons x [] = MonoidStr.·IdR (snd m) x ∙ sym (MonoidStr.·IdL (snd m) x)
fnCons x (x₁ ∷ xs) = x ∙m (fn (x₁ ∷ xs))
≡⟨ cong (x ∙m_) (sym (fnCons x₁ xs)) ⟩
(x ∙m (x₁ ∙m fn xs))
≡⟨ MonoidStr.·Assoc (m .snd) x x₁ (fn xs) ⟩
((x ∙m x₁) ∙m fn xs)
≡⟨ ∙foldl (x ∙m x₁) ((MonoidStr.ε (snd m))) xs ⟩
foldl _∙m_ ((x ∙m x₁) ∙m (MonoidStr.ε (snd m))) xs
≡⟨ cong (λ l → foldl _∙m_ l xs) (MonoidStr.·IdR (snd m) (x ∙m x₁)) ⟩
foldl _∙m_ x (x₁ ∷ xs)
≡⟨ sym (cong (λ l → foldl _∙m_ l (x₁ ∷ xs)) (MonoidStr.·IdL (snd m) x)) ⟩
fn (x ∷ x₁ ∷ xs) ∎
respects∙ : (xs ys : List (fst m)) → fn (xs ++ ys) ≡ ((fn xs) ∙m (fn ys))
respects∙ [] ys = sym (MonoidStr.·IdL (snd m) (fn ys))
respects∙ xs@(_ ∷ _) [] = cong fn (++-unit-r xs) ∙ sym (MonoidStr.·IdR (snd m) (fn xs))
respects∙ (x ∷ xs) ys@(_ ∷ _) = fn (x ∷ (xs ++ ys))
≡⟨ sym (fnCons x (xs ++ ys)) ⟩
x ∙m (fn (xs ++ ys))
≡⟨ cong (x ∙m_) (respects∙ xs ys) ⟩
x ∙m ((fn xs) ∙m (fn ys))
≡⟨ MonoidStr.·Assoc (snd m) x (fn xs) (fn ys) ⟩
(x ∙m (fn xs)) ∙m (fn ys)
≡⟨ cong (_∙m (fn ys)) (fnCons x xs) ⟩
(fn (x ∷ xs)) ∙m (fn ys) ∎

mapMonHom : (A B : Σ Type isSet) → (f : (fst A) → (fst B)) → MonoidHom (ListMonoid A) (ListMonoid B)
Comment thread
eiais marked this conversation as resolved.
Outdated
mapMonHom A B f = map f , monoidequiv refl (λ x y → sym (map++ f x y))
Loading