commutative semigroup

Commutative Semigroup

Commutative Semigroup

Mathematically a Commutative Semigroup is a set S along with an associative binary operation + such that

(∀x S)(∀y S)(∀z S) => (x+(y+z)) = ((x+y)+z)

Important

Contract: Group initializer parameters must have

  • add closed, commutative and associative on reps

class boring_math.abstract_algebra.algebras.commutative_semigroup.CommutativeSemigroup

Bases: BaseSet, Generic

Parameters:
  • add – Closed commutative and associative function reps.

  • narrow – Narrow the rep type, many-to-one function. Like choosing an element from a coset of a group.

__init__(add: Callable[[H, H], H], narrow: Callable[[H], H] | None = None) None
Parameters:
  • add – Closed commutative and associative function reps.

  • narrow – Narrow the rep type, many-to-one function. Like choosing an element from a coset of a group.

class boring_math.abstract_algebra.algebras.commutative_semigroup.CommutativeSemigroupElement

Bases: BaseElement, Generic

__init__(rep: H, algebra: CommutativeSemigroup[H]) None
__str__() str
Returns:

str(self) = CommutativeSemigroupElement<rep>

__add__(right: Self) Self

Add two elements of the same concrete algebra together.

Parameters:

other – Another element within the same algebra.

Returns:

The sum self + other.

Raises:
  • ValueError – If self and other are same type but different concrete algebras.

  • TypeError – If Addition not defined on the algebra of the elements.

  • TypeError – If self and right are different types.

__radd__(left: Self) Self

When left side of addition does not know how to add right side.

Parameters:

other – Left side of the addition.

Returns:

Never returns, otherwise left.__add__(right) would have worked.

Raises:

TypeError – When right side does not know how to add the left side to itself.

__mul__(n: object) Self

Repeatedly add an element to itself n > 0 times.

Parameters:

n – Object, usually a positive int or action.

Returns:

If n: int then self added to itself n times else NotImplemented.

Raises:
  • ValueError – When n <= 0.

  • ValueError – If self and other are same type but different concrete algebras.

  • TypeError – If an add method was not defined on the algebra.

  • TypeError – Element multiplication attempted but algebra is not multiplicative.

__rmul__(n: int) Self

Repeatedly add an element to itself n > 0 times.