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.

class algebraixlib.mathobjects.mathobject.MathObject[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)

Several Boolean properties are automatically cached when first requested. For this we use a caching mechanism based on the class _flags.Flags that provides two flags for each Boolean property: one that indicates whether the property is “known to be true”, and one that indicates whether it is “known to be false”. Both flags are initially cleared. When the property is read and the value is not yet known, it is calculated and then cached. The flags may also be set by an explicit setter function.

Each cached property is represented by three accessor functions that use the following naming convention (for a property with name <property>):

  • cached_is_<property>: Return the “known to be true” flag. A True value means that the property is known to be True. A False value means that either the value of the property is False or not known. In this case you need to examine the value of the cached_is_not_<property> accessor to find out.
  • cached_is_not_<property>: Return the “known to be false” flag. A True value means that the property is known to be False. A False value means that either the value of the property is True or not known. In this case you need to examine the value of the cached_is_<property> accessor to find out.
  • cache_is_<property>: Set the value of one of the cache flags, depending on the Boolean argument value. If value is False, the “is known to be false” flag is set; if it is True, the “is known to be true” flag is set. Use this function if you know the state of one of these properties when creating a MathObject. (The flag setters in _flags.Flags assert that an already cached property isn’t set to a different value.)

MathObject provides a default implementation for these methods. The implementations of cache_is_<property> only allow the “is known to be false” flag to be set. This works for derived classes for which a given property is always false. Derived classes for which a given property may be true must provide their own implementations of cache_is_<property> (see for example Set.cache_is_relation()).

get_ground_set() → algebraixlib.structure.Structure[source]

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

get_left_set() → 'P( M )'[source]

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

get_right_set() → 'P( M )'[source]

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

is_regular() → bool[source]

Return whether self is regular or Undef() if not applicable.

is_functional() → bool[source]

Return whether self is functional or Undef() if not applicable.

is_right_functional() → bool[source]

Return whether self is right-functional or Undef() if not applicable.

is_bijective() → bool[source]

Return whether self is bijective or Undef() if not applicable.

is_reflexive() → bool[source]

Return whether self is reflexive or Undef() if not applicable.

is_symmetric() → bool[source]

Return whether self is symmetric or Undef() if not applicable.

is_transitive() → bool[source]

Return whether self is transitive or Undef() if not applicable.

is_equivalence_relation() → bool[source]

Return whether self is an equivalence relation 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__(*args, **kwargs) → '( M )'[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.
Returns:

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__(left) → 'P( M )'[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.
Returns: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.

cached_is_not_relation

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

cached_is_relation

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

cache_is_relation(value: bool)[source]

Cache whether self is or is not a relation. See [PropCache].

cached_is_not_clan

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

cached_is_clan

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

cache_is_clan(value: bool)[source]

Cache whether self is or is not a clan. See [PropCache].

cached_is_not_multiclan

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

cached_is_multiclan

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

cache_is_multiclan(value: bool)[source]

Cache whether self is or is not a multiclan. See [PropCache].

cached_is_not_functional

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

cached_is_functional

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

cache_is_functional(value: bool)[source]

Cache whether self is or is not functional. See [PropCache].

This function shouldn’t be called. Override in a derived class where it applies.

cached_is_not_right_functional

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

cached_is_right_functional

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

cache_is_right_functional(value: bool)[source]

Cache whether self is or is not a right-functional. See [PropCache].

This function shouldn’t be called. Override in a derived class where it applies.

cached_is_not_regular

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

cached_is_regular

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

cache_is_regular(value: bool)[source]

Cache whether self is or is not regular. See [PropCache].

This function shouldn’t be called. Override in a derived class where it applies.

cached_is_not_reflexive

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

cached_is_reflexive

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

cache_is_reflexive(value: bool)[source]

Cache whether self is or is not reflexive. See [PropCache].

This function shouldn’t be called. Override in a derived class where it applies.

cached_is_not_symmetric

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

cached_is_symmetric

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

cache_is_symmetric(value: bool)[source]

Cache whether self is or is not symmetric. See [PropCache].

This function shouldn’t be called. Override in a derived class where it applies.

cached_is_not_transitive

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

cached_is_transitive

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

cache_is_transitive(value: bool)[source]

Cache whether self is or is not transitive. See [PropCache].

This function shouldn’t be called. Override in a derived class where it applies.

copy_flags(other)[source]

Set the cached flags of self to the value of the cached flags of other.