\import Algebra.Group
\import Algebra.Monoid
\import Algebra.Monoid.Product
\import Algebra.Pointed
\import Data.Array
\import Paths

\instance ProductGroup (G H : Group) : Group
  | Monoid => ProductMonoid G H
  | inverse p => (inverse p.1, inverse p.2)
  | inverse-left => pmap2 (__,__) inverse-left inverse-left
  | inverse-right => pmap2 (__,__) inverse-right inverse-right

\instance ProductAddGroup (A B : AddGroup) : AddGroup
  | AddMonoid => ProductAddMonoid A B
  | negative p => (negative p.1, negative p.2)
  | negative-left => pmap2 (__,__) negative-left negative-left
  | negative-right => pmap2 (__,__) negative-right negative-right

\instance ProductCGroup (G H : CGroup) : CGroup
  | Group => ProductGroup G H
  | CMonoid => ProductCMonoid G H

\instance ProductAbGroup (A B : AbGroup) : AbGroup
  | AddGroup => ProductAddGroup A B
  | AbMonoid => ProductAbMonoid A B

-- | The product of `n` copies of an abelian group.
\instance ArrayAbGroup (n : Nat) (A : AbGroup) : AbGroup (Array A n)
  | zro _ => 0
  | + f g j => f j + g j
  | zro-left => arrayExt (\lam j => zro-left)
  | zro-right => arrayExt (\lam j => zro-right)
  | +-assoc => arrayExt (\lam j => +-assoc)
  | negative f j => negative (f j)
  | negative-left => arrayExt (\lam j => negative-left)
  | +-comm => arrayExt (\lam j => +-comm)