# algebraixlib.mathobjects.mathobject module¶

This module contains the abstract base class for all classes that represent data.

The class MathObject is the base class of all other data classes and can’t be instantiated.

This module also provides the utility functions raise_if_not_mathobject() and raise_if_not_mathobjects() that raise a TypeError if the argument is not an instance of MathObject (resp. is not a collection of such instances).

algebraixlib.mathobjects.mathobject.raise_if_not_mathobject(obj)[source]

Raise a TypeError exception if obj is not an instance of MathObject.

algebraixlib.mathobjects.mathobject.raise_if_not_mathobjects(*objs)[source]

Raise a TypeError exception if any member of objs is not a MathObject.

algebraixlib.mathobjects.mathobject.is_mathobject_or_undef(obj)[source]

Return True if obj is an instance of MathObject or Undef() else False.

class algebraixlib.mathobjects.mathobject.MathObject(cached_flags: int = 0)[source]

Bases: abc.ABC

An abstract base class (see the base class abc.ABC) for all classes that represent data.

This class uses _flags.Flags to cache a number of properties of all data classes. See also [PropCache].

Note

This class can’t be instantiated. Only derived classes that implement all abstract methods can be instantiated. Since derived classes are expected to be hashable, they must be immutable.

 [PropCache] (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45) Several Boolean properties are automatically cached when first requested. For this we use a caching mechanism based on the class _flags.Flags that provides a 2-bit field for each Boolean property, with the states UNKNOWN, IS, IS_NOT and N_A (see CacheStatus). Some of these properties are set during the constructors of the classes derived from MathObject, others are set when a given MathObject is created by an operation. They also may be set by user code when a property’s state is known due to the characteristics of the MathObject. In the MathObjects, most cached properties are represented by two accessors that use the following naming convention (for a property with name ): cached_: Return the current cached state (may be UNKNOWN). This is a Python property accessor, so parentheses are not needed when querying the state. cache_: Set the value of the cached state. Note that the only state that may be changed is UNKNOWN; all others cannot be changed once set. (Setting it again to the same value is unnecessary but not an error.) Several properties have also convenience accessors of the following forms: cached_is_: Means “is known to be ”. cached_is_not_: Means “is known not to be ”. (Keep in mind that while these two accessors never return True for both, they may return False for both. This happens if the property’s state is unknown or if it doesn’t apply to the given object. Only use them for questions of the “is known (not) to be ...” variety.) Then there are four special cases: is_atom, is_couplet, is_multiset and is_set. All these properties are always either True or False and they are set during object construction and never can be set again. Therefore, for these four properties, all we have are these Boolean read accessors. Note The serialized values of the structure where these bits are stored depends on the system’s byte order (endianness). Without specific measures, serialized data can’t be exchanged between systems with different byte order.
is_empty

Return True if this MathObject is empty, False if not.

Returns: Always False unless overridden by a derived class.
get_ground_set() → algebraixlib.structure.Structure[source]

Return the ground set of the lowest-level algebra of this MathObject.

get_left_set()[source]

Return the left set or Undef() if not applicable.

get_right_set()[source]

Return the right set or Undef() if not applicable.

__eq__(other) → bool[source]

Return whether self and other are equal, based on their values.

__ne__(other) → bool[source]

Return whether self and other are not equal, based on their values.

__call__()[source]

With the syntax mo(left), return the right associated with left.

Parameters: args – Exactly one argument is expected; it is the left component of the couplet of which the right component is returned. kwargs – Named arguments are not supported. It is part of the function signature. If self is a function, return the right component of the couplet that has as left component the single argument if one exists; return Undef() if no couplet with the given left exists. Also return Undef() if self is not a function.
__getitem__()[source]

With the syntax mo[left], return a set of rights associated with left.

Parameters: left – The left component of the couplet(s) of which the right component(s) are returned. If self is a relation, return a set that contains the right(s) of the couplet(s) that have a left that matches left. (This set may be empty if no couplet with the given left exists.) Return Undef() if self is not a relation.
__hash__() → int[source]

Return a hash based on the member values (must match the implementation of __eq__).

Note

The fact that we calculate a hash of an instance requires that instances of classes derived from this class are immutable (see also Immutable Sequence Types) and all its contained elements hashable (see also object.__hash__).

__repr__() → str[source]

Return the instance’s code representation.

__str__() → str[source]

Return the instance’s string representation.

is_atom

Return True if self is an Atom, False otherwise.

is_couplet

Return True if self is a Couplet, False otherwise.

is_multiset

Return True if self is a Multiset, False otherwise.

is_set

Return True if self is a Set, False otherwise.

cached_relation

Return the cached state of being a relation. See [PropCache].

cached_is_relation

Return True if self is known to be a relation. See [PropCache].

cached_is_not_relation

Return True if self is known not to be a relation. See [PropCache].

cache_relation(value: int)[source]

Set the cached state of being a relation. See [PropCache].

cached_clan

Return the cached state of being a clan. See [PropCache].

cached_is_clan

Return True if self is known to be a clan. See [PropCache].

cached_is_not_clan

Return True if self is known not to be a clan. See [PropCache].

cache_clan(value: int)[source]

Set the cached state of being a clan. See [PropCache].

cached_multiclan

Return the cached state of being a multiclan. See [PropCache].

cached_is_multiclan

Return True if self is known to be a multiclan. See [PropCache].

cached_is_not_multiclan

Return True if self is known not to be a multiclan. See [PropCache].

cache_multiclan(value: int)[source]

Set the cached state of being a multiclan. See [PropCache].

cached_absolute

Return the cached state of being absolute. See [PropCache].

Note

Keep in mind that this does not tell you what kind of absolute algebra member this is. For example, an absolute relation is a non-absolute set.

cached_is_absolute

Return True if self is known to be absolute. See [PropCache].

Note

Keep in mind that this does not tell you what kind of absolute algebra member this is known to be. For example, an absolute relation is a non-absolute set.

cached_is_not_absolute

Return True if self is known not to be absolute. See [PropCache].

Note

Keep in mind that this does not tell you what kind of absolute algebra member this is known not to be. For example, an absolute relation is a non-absolute set.

cache_absolute(value: int)[source]

Set the cached state of being absolute. See [PropCache].

cached_functional

Return the cached state of being functional. See [PropCache].

cached_is_functional

Return True if self is known to be functional. See [PropCache].

cached_is_not_functional

Return True if self is known not to be functional. See [PropCache].

cache_functional(value: int)[source]

Set the cached state of being functional. See [PropCache].

cached_right_functional

Return the cached state of being right-functional. See [PropCache].

cached_is_right_functional

Return True if self is known to be right-functional. See [PropCache].

cached_is_not_right_functional

Return True if self is known not to be right-functional. See [PropCache].

cache_right_functional(value: int)[source]

Set the cached state of being right-functional. See [PropCache].

cached_reflexive

Return the cached state of being reflexive. See [PropCache].

cached_is_reflexive

Return True if self is known to be reflexive. See [PropCache].

cached_is_not_reflexive

Return True if self is known not to be reflexive. See [PropCache].

cache_reflexive(value: int)[source]

Set the cached state of being reflexive. See [PropCache].

cached_symmetric

Return the cached state of being symmetric. See [PropCache].

cached_is_symmetric

Return True if self is known to be symmetric. See [PropCache].

cached_is_not_symmetric

Return True if self is known not to be symmetric. See [PropCache].

cache_symmetric(value: int)[source]

Set the cached state of being symmetric. See [PropCache].

cached_transitive

Return the cached state of being transitive. See [PropCache].

cached_is_transitive

Return True if self is known to be transitive. See [PropCache].

cached_is_not_transitive

Return True if self is known not to be transitive. See [PropCache].

cache_transitive(value: int)[source]

Set the cached state of being transitive. See [PropCache].

cached_regular

Return the cached state of being regular. See [PropCache].

cached_is_regular

Return True if self is known to be regular. See [PropCache].

cached_is_not_regular

Return True if self is known not to be regular. See [PropCache].

cache_regular(value: int)[source]

Set the cached state of being regular. See [PropCache].

cached_right_regular

Return the cached state of being right-regular. See [PropCache].

cached_is_right_regular

Return True if self is known to be right-regular. See [PropCache].

cached_is_not_right_regular

Return True if self is known not to be right-regular. See [PropCache].

cache_right_regular(value: int)[source]

Set the cached state of being right-regular. See [PropCache].