Abelian Group

An Abelian group (or commutative group) is an algebraic structure that combines the properties of a group and commutativity.

Thus, an abelian group is a group in which the operation \(\cdot\) is commutative. That is:

Examples of abelian groups

Abelian groups play an important role in mathematics and its applications:

Formal Definition

AbelianGroup[A] is an "abelian group", a group that is commutative.

In addition to the laws of a group:

the following law must hold:

Code

trait AbelianGroup[A] extends Group[A], CMonoid[A]

Laws

Laws are inherited from group and commutative monoid.

Exercises

Exercise 1.4.1: Implementation of an abelian group for integers by addition.

Repository with exercises and instructions for completion

Fill in the missing parts (???):

given AbelianGroup[Int] with
  val empty: Int = ???

  def combine(x: Int, y: Int): Int = ???

  extension (a: Int)
    def inverse: Int = ???

🔍 Show solution

given AbelianGroup[Int] with
  val empty = 0

  def combine(x: Int, y: Int): Int = x + y

  extension (a: Int)
    def inverse: Int = -a   

Example calls:

AbelianGroup[Int].combine(5, 3)
// 8
AbelianGroup[Int].combine(3, 5)
// 8
AbelianGroup[Int].empty
// 0
AbelianGroup[Int].inverse(5)
// -5

Diagram

classDiagram
    class Semigroup~A~{
        +combine(x: A, y: A) A
    } 
    class Monoid~A~{
        +empty() A
    }
    Semigroup <|-- Monoid
    class CommutativeSemigroup~A~
    Semigroup <|-- CommutativeSemigroup  
    class Group~A~{
      +inverse(x: A) A
    }  
    Monoid <|-- Group 
    class CommutativeMonoid~A~
    Monoid <|-- CommutativeMonoid
    CommutativeSemigroup <|-- CommutativeMonoid
    class AbelianGroup~A~
    Group <|-- AbelianGroup
    CommutativeMonoid <|-- AbelianGroup

Implementation in Libraries

Implementation in Spire

AbGroup[A] is an "abelian group", a group that is commutative.

import spire.algebra.AbGroup

AbGroup[Int].inverse(1) // -1

References: