semigroup¶
Semigroup
Mathematically a Semigroup is a set S along with an associative binary operation mult: S X S -> S.
Important
Contract: Semigroup initializer parameters must have
mult closed and associative on reps
- class boring_math.abstract_algebra.algebras.semigroup.Semigroup¶
Bases:
BaseSet,Generic- Parameters:
mult – Associative function
H X H -> Hon reps.narrow – Narrow the rep type, many-to-one function. Like choosing an element from a coset of a group.
- __init__(mult: Callable[[H, H], H], narrow: Callable[[H], H] | None = None) None¶
- Parameters:
mult – Associative function
H X H -> Hon reps.narrow – Narrow the rep type, many-to-one function. Like choosing an element from a coset of a group.
- __call__(rep: H) SemigroupElement¶
Add the unique element to the semigroup with a with the given, perhaps narrowed,
rep.- Parameters:
rep – Representation to add if not already present.
- Returns:
The unique element with that representation.
- __eq__(right: object) bool¶
Compare if two algebras are the same concrete algebra.
- Parameters:
right – Object being compared to.
- Returns:
True only if
rightis the same concrete algebra. False otherwise.
- narrow_rep_type(rep: H) H¶
Narrow the type with a concrete algebra’s many-to-one type “narrowing” function.
- Parameters:
rep – Hashable value of type H.
- Returns:
The narrowed representation.
- class boring_math.abstract_algebra.algebras.semigroup.SemigroupElement¶
Bases:
BaseElement,Generic- __str__() str¶
- Returns:
str(self) = SemigroupElement<rep>
- __mul__(right: object) Self¶
Multiply two elements of the same concrete algebra together.
- Parameters:
right – An element within the same concrete algebra or a right action.
- Returns:
The product
self * rightotherwiseNotImplemented.- Raises:
ValueError – If
selfandrightare same type but different concrete algebras.
- __rmul__(left: object) Self¶
When left side of multiplication does not know how to multiply right side.
- Parameters:
left – Left side of the multiplication.
- Returns:
Never returns, otherwise
left.__mul__(right)would have worked.- Raises:
TypeError – When multiplying on left by an int.
- __pow__(n: int) Self¶
Raising element to a positive
intpower is the same as repeated multiplication.- Parameters:
n – Multiply element to itself
n > 0times.- Returns:
The product of the element n times.
- Raises:
ValueError – When
n <= 0.ValueError – If algebra does not have a mult attribute.
- __call__() H¶
Warning
A trade off is being made in favor of efficiency over encapsulation. An actual reference to the wrapped
repis returned to eliminate the overhead of a copy.- Returns:
The narrowed representation wrapped within the element.
- __eq__(right: object) bool¶
Compares if two elements, not necessarily in the same concrete algebra, contain equal representations of the same hashable type.
Warning
Any sort of difference in rep narrowing is not taken into consideration.
- Parameters:
right – Object to be compared with.
- Returns:
True if both are elements and the reps compare as equal and are of the same invariant type.