ring¶
Ring
Mathematically a Ring is an abelian group under addition and a
Monoid under multiplication. The additive and multiplicative
identities are denoted one and zero respectfully.
By convention one != zero, otherwise the algebra consists
of just one unique element.
Important
Contract: Ring initializer parameters must have
add closed, commutative and associative on reps
mult closed and associative on reps
one an identity on reps,
rep*one == rep == one*repzero an identity on reps,
rep+zero == rep == zero+repnegate maps
rep -> -rep,rep + negate(rep) == zerozero
!=one
- class boring_math.abstract_algebra.algebras.ring.Ring¶
Bases:
AbelianGroup,Generic- Parameters:
add – Closed commutative and associative function reps.
mult – Closed associative function reps.
one – Representation for multiplicative identity.
zero – Representation for additive identity.
negate – Function mapping element representation to the representation of corresponding negated element.
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], mult: Callable[[H, H], H], one: H, zero: H, negate: Callable[[H], H], narrow: Callable[[H], H] | None = None)¶
- Parameters:
add – Closed commutative and associative function reps.
mult – Closed associative function reps.
one – Representation for multiplicative identity.
zero – Representation for additive identity.
negate – Function mapping element representation to the representation of corresponding negated element.
narrow – Narrow the rep type, many-to-one function. Like choosing an element from a coset of a group.
- __call__(rep: H) RingElement¶
Add the unique element to the ring 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.ring.RingElement¶
Bases:
AbelianGroupElement,Generic- __str__() str¶
- Returns:
str(self) = RingElement<rep>
- __mul__(right: object) Self¶
Left multiplication for
*operator.- Parameters:
right – Object
leftshould be an element of same concrete algebra or anint.- Returns:
Algebra product, the sum of the element
righttimes, orNotImplemented.- Raises:
ValueError – If either right not an element of the same concrete algebra or
right: int < 0.TypeError – Multiplication nor defined on the algebra that
selfis a member of.
- __rmul__(left: object) Self¶
Right multiplication for
*operator.- Parameters:
left – Object
leftshould be anint.- Returns:
The sum of the element
lefttimes.- Raises:
TypeError – If object on left does not act on object on right
- __pow__(n: int) Self¶
Raise element to power to the
intpower ofn>=0.- Parameters:
n – The
intpower to raise the element to.- Returns:
The element raised to the non-negative integer
npower.- Raises:
ValueError – If algebra is not multiplicative.
ValueError – If algebra does not have a multiplicative identity element.
ValueError – If
n < 0.
- __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
selfandotherare same type but different concrete algebras.TypeError – If Addition not defined on the algebra of the elements.
TypeError – If
selfandrightare different types.
- __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.
- __neg__() Self¶
Negate the element.
- Returns:
The unique additive inverse element to
self.- Raises:
ValueError – If algebra fails to have additive inverses.
- __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.