baseset (Abstract)

Implementation Details

  • BaseSet: Base class for algebras

  • BaseElement: Base class for elements of algebras.

class boring_math.abstract_algebra.algebras.baseset.BaseSet

Bases: ABC, Generic

abstractmethod __call__(rep: H) BaseElement

Add the unique element to the concrete algebra with the given, perhaps narrowed, rep in a uniquely deterministic way.

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.baseset.BaseElement

Bases: ABC, Generic

abstractmethod __str__() str

Return str(self).

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

class boring_math.abstract_algebra.algebras.baseset.NaturalMapping

Bases: Sized, Iterable, Container, Protocol, Generic

Similar to the collections/abc.Mapping protocol, NaturalMapping supports read-only access to dict-like objects which can be extended in a “natural” deterministic way.