ring

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*rep

  • zero an identity on reps, rep+zero == rep == zero+rep

  • negate maps rep -> -rep, rep + negate(rep) == zero

  • zero != one

class boring_math.abstract_algebra.algebras.ring.Ring

Bases: AbelianGroup, Generic

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

init

param add:

Closed commutative and associative function reps.

param mult:

Closed associative function reps.

param one:

Representation for multiplicative identity.

param zero:

Representation for additive identity.

param negate:

Function mapping element representation to the representation of corresponding negated element.

param 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.ring.RingElement

Bases: AbelianGroupElement, Generic

__init__(rep: H, algebra: Ring[H]) → None

init

param rep:

Coset element to be narrowed.

param algebra:

Abelian group to which element belongs.

__str__() → str

user string

Construct the string ‘RingElement<rep_str>’ where rep_str = str(rep).

returns:

A string meaningful to an end user.

__mul__(right: object) → Self

mul

Left multiplication for * operator.

param right:

Object right should be an element of same concrete algebra or an int.

returns:

Algebra product, the sum of the element right times, or NotImplemented.

raises ValueError:

If either right not an element of the same concrete algebra or right: int < 0.

raises TypeError:

Multiplication not defined on the algebra that self is a member of.

__rmul__(left: object) → Self

rmul

Right multiplication for * operator.

param left:

Object left should be an int.

returns:

The sum of the element left times.

raises TypeError:

If object on left does not act on object on right

__pow__(n: int) → Self

pow

Raise element to power to the integer power of n>=0.

param n:

The int power to raise the element to.

returns:

The element raised to the non-negative integer n power.

raises ValueError:

If algebra is not multiplicative.

raises ValueError:

If algebra does not have a multiplicative identity element.

raises ValueError:

If n < 0.