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 ifobj
is not an instance ofMathObject
.
-
algebraixlib.mathobjects.mathobject.
raise_if_not_mathobjects
(*objs)[source]¶ Raise a
TypeError
exception if any member ofobjs
is not aMathObject
.
-
algebraixlib.mathobjects.mathobject.
is_mathobject_or_undef
(obj)[source]¶ Return
True
ifobj
is an instance ofMathObject
orUndef()
elseFalse
.
-
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 statesUNKNOWN
,IS
,IS_NOT
andN_A
(seeCacheStatus
). Some of these properties are set during the constructors of the classes derived fromMathObject
, others are set when a givenMathObject
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 theMathObject
.In the
MathObject
s, most cached properties are represented by two accessors that use the following naming convention (for a property with name<property>
):cached_<property>
: Return the current cached state (may beUNKNOWN
). This is a Python property accessor, so parentheses are not needed when querying the state.cache_<property>
: Set the value of the cached state. Note that the only state that may be changed isUNKNOWN
; 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_<property>
: Means “is known to be <property>”.cached_is_not_<property>
: Means “is known not to be <property>”.
(Keep in mind that while these two accessors never return
True
for both, they may returnFalse
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
andis_set
. All these properties are always eitherTrue
orFalse
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 thisMathObject
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
.
-
__call__
()[source]¶ With the syntax
mo(left)
, return the right associated withleft
.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; returnUndef()
if no couplet with the given left exists. Also returnUndef()
ifself
is not a function.
-
__getitem__
()[source]¶ With the syntax
mo[left]
, return a set of rights associated withleft
.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 matchesleft
. (This set may be empty if no couplet with the given left exists.) ReturnUndef()
ifself
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__).
-
cached_relation
¶ Return the cached state of being a relation. See [PropCache].
-
cached_is_relation
¶ Return
True
ifself
is known to be a relation. See [PropCache].
-
cached_is_not_relation
¶ Return
True
ifself
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
ifself
is known to be a clan. See [PropCache].
-
cached_is_not_clan
¶ Return
True
ifself
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
ifself
is known to be a multiclan. See [PropCache].
-
cached_is_not_multiclan
¶ Return
True
ifself
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].
-
cached_is_absolute
¶ Return
True
ifself
is known to be absolute. See [PropCache].
-
cached_is_not_absolute
¶ Return
True
ifself
is known not to be absolute. See [PropCache].
-
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
ifself
is known to be functional. See [PropCache].
-
cached_is_not_functional
¶ Return
True
ifself
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
ifself
is known to be right-functional. See [PropCache].
-
cached_is_not_right_functional
¶ Return
True
ifself
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
ifself
is known to be reflexive. See [PropCache].
-
cached_is_not_reflexive
¶ Return
True
ifself
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
ifself
is known to be symmetric. See [PropCache].
-
cached_is_not_symmetric
¶ Return
True
ifself
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
ifself
is known to be transitive. See [PropCache].
-
cached_is_not_transitive
¶ Return
True
ifself
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
ifself
is known to be regular. See [PropCache].
-
cached_is_not_regular
¶ Return
True
ifself
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
ifself
is known to be right-regular. See [PropCache].
-
cached_is_not_right_regular
¶ Return
True
ifself
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].