{-# OPTIONS --cubical --safe --no-import-sorts #-}
module Cubical.Algebra.CommAlgebra.Examples where

open import Cubical.Foundations.Everything
open import Cubical.Foundations.HLevels

open import Cubical.Data.Unit

open import Cubical.Algebra.CommRing
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Algebra.Base using (algebrahom)
open import Cubical.Algebra.CommAlgebra.Base
open import Cubical.Algebra.CommAlgebra.Morphism

private
  variable
     : Level

module CommAlgebraExamples ((R , str) : CommRing {}) where

  initial : CommAlgebra (R , str)
  initial =
    let open CommRingStr str
    in commalgebra R _ _ _ _ _  r x  r · x)
                    (makeIsCommAlgebra (isSetRing (CommRing→Ring (R , str)))
                       +Assoc +Rid +Rinv +Comm
                       ·Assoc ·Lid
                       ·Ldist+ ·-comm
                         x y z  sym (·Assoc x y z)) ·Ldist+ ·Rdist+ ·Lid λ x y z  sym (·Assoc x y z))


  module _ (A : CommAlgebra (R , str)) where
    open CommAlgebra ⦃... 
    instance
      _ : CommAlgebra (R , str)
      _ = A
      _ : CommAlgebra (R , str)
      _ = initial

    _*_ : R   A ⟩a   A ⟩a
    r * a = CommAlgebra._⋆_ A r a

    initialMap : CAlgHom initial A
    initialMap =
      algebrahom  r  r * 1a)
                  x y  ⋆-ldist x y 1a)
                  x y   (x · y) * 1a ≡⟨ ⋆-assoc _ _ _ 
                           x * (y * 1a)                   ≡[ i ]⟨ x * (·Lid (y * 1a) (~ i)) 
                           x * (1a · (y * 1a))            ≡⟨ sym (⋆-lassoc _ _ _) 
                           (x * 1a) · (y * 1a) )
                 (⋆-lid _)
                 λ r x  (r · x) * 1a   ≡⟨ ⋆-assoc _ _ _ 
                         (r * (x * 1a)) 


    initialMapEq : (f : CAlgHom initial A)
                    f  initialMap
    initialMapEq f = homEq initial A f initialMap
                            r  f $a r         ≡[ i ]⟨ f $a (·Rid r (~ i)) 
                                  f $a (r · 1a)    ≡⟨ AlgebraHom.comm⋆ f r 1a 
                                  r * (f $a 1a)    ≡[ i ]⟨ r * (AlgebraHom.pres1 f i) 
                                  r * 1a )

    isInitial : CAlgHom initial A  Unit*
    isInitial =
      isoToPath (iso  _  tt*)
                      _  initialMap)
                      {tt*x  refl})
                     λ f  sym (initialMapEq f))