abelian group

Abelian Group

Mathematically an Abelian Group is a Commutative Monoid G all of whose elements have additive inverses.

Note

Addition is used for the group operation.

Important

Contract: AbelianGroup initializer parameters must have

  • add closed, associative and commutative on reps

  • zero additive identity on reps, rep.add(zero) == rep == zero.add(rep)

  • negate must me idempotent: neg(neg(rep)) == rep

class boring_math.abstract_algebra.algebras.abelian_group.AbelianGroup

Bases: CommutativeMonoid, Generic

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

  • 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], zero: H, negate: Callable[[H], H], narrow: Callable[[H], H] | None = None)
Parameters:
  • add – Closed, commutative and associative function on reps.

  • 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) AbelianGroupElement

Add the unique element to the abelian group 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 right is 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.abelian_group.AbelianGroupElement

Bases: CommutativeMonoidElement, Generic

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

str(self) = AbelianGroupElement<rep>

__mul__(n: object) Self

Repeatedly add an element to itself n >= 0 times.

Parameters:

n – Object, usually a non-negative 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 algebra fails to have an addition method.

Multiplying an algebra element by an integer n>=0 is the same as repeated addition.

Parameters:

n – Object, usually an int or action.

Returns:

If n: int then self, or its negative, added 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 – If algebra does not have an additive identity.

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

__rmul__(n: int) Self

Repeatedly add an element to itself n > 0 times.

__neg__() Self

Negate the element.

Returns:

The unique additive inverse element to self.

Raises:

ValueError – If algebra fails to have additive inverses.

__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.

__call__() H

Warning

A trade off is being made in favor of efficiency over encapsulation. An actual reference to the wrapped rep is 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.

__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.