{-# OPTIONS --safe #-}
module Cubical.Algebra.CommRing.Instances.Pointwise where

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

open import Cubical.Algebra.CommRing.Base

private
  variable
     ℓ' : Level

pointwiseRing : (X : Type ) (R : CommRing ℓ')  CommRing _
pointwiseRing X R = (X  fst R) , str
    where
      open CommRingStr (snd R)

      isSetX→R = isOfHLevelΠ 2  _  is-set)

      str : CommRingStr (X  fst R)
      CommRingStr.0r str = λ _  0r
      CommRingStr.1r str = λ _  1r
      CommRingStr._+_ str = λ f g   x  f x + g x)
      CommRingStr._·_ str = λ f g   x  f x · g x)
      CommRingStr.- str = λ f   x  - f x)
      CommRingStr.isCommRing str =
        makeIsCommRing
           isSetX→R
            f g h i x  +Assoc (f x) (g x) (h x) i)
            f i x  +IdR (f x) i)
            f i x  +InvR (f x) i)
            f g i x  +Comm (f x) (g x) i)
            f g h i x  ·Assoc (f x) (g x) (h x) i)
            f i x  ·IdR (f x) i)
            f g h i x  ·DistR+ (f x) (g x) (h x) i)
           λ f g i x  ·Comm (f x) (g x) i