commutative_semigroup¶
Additive Semigroup
Mathematically an Additive Semigroup is a set S along with an associative binary operation add: S X S -> S.
Important
Contract: Group initializer parameters must have
add closed, commutative and associative on reps
- class boring_math.abstract_algebra.algebras.commutative_semigroup.CommutativeSemigroup(add: ~collections.abc.Callable[[H, H], H], process: ~collections.abc.Callable[[H], H] = <function CommutativeSemigroup.<lambda>>)¶
- __init__(add: ~collections.abc.Callable[[H, H], H], process: ~collections.abc.Callable[[H], H] = <function CommutativeSemigroup.<lambda>>) None¶
- __call__(rep: H) CommutativeSemigroupElement¶
Add the unique element to the additive semigroup with a given rep.
- Parameters:
rep – Representation to add if not already present.
- Returns:
The unique element with that representation.
- class boring_math.abstract_algebra.algebras.commutative_semigroup.CommutativeSemigroupElement(rep: H, algebra: CommutativeSemigroup[H])¶
- __init__(rep: H, algebra: CommutativeSemigroup[H]) None¶
- __add__(other: int | Self) Self¶
Add two elements of the same concrete additive semigroup together.
- Parameters:
other – Another element within the same additive semigroup or an
int.- Returns:
The sum
self + other.- Raises:
ValueError – If
selfandotherare same type but different concrete additive semigroups.TypeError – If
selfandotherare different types.
- __radd__(other: object) 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 left side does not know how to add the additive semigroup element.
- __mul__(n: int | Self) Self¶
Multiplying additive semigroup element by a positive
intis the same as repeated addition.- Parameters:
n – Add additive semigroup element to itself
n > 0times.- Returns:
The sum of the semigroup element n times.
- Raises:
ValueError – When
n <= 0.ValueError – If for some reason an add method was not defined on the semigroup.