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
.
-
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. ATrue
value means that the property is known to beTrue
. AFalse
value means that either the value of the property isFalse
or not known. In this case you need to examine the value of thecached_is_not_<property>
accessor to find out.cached_is_not_<property>
: Return the “known to be false” flag. ATrue
value means that the property is known to beFalse
. AFalse
value means that either the value of the property isTrue
or not known. In this case you need to examine the value of thecached_is_<property>
accessor to find out.cache_is_<property>
: Set the value of one of the cache flags, depending on the Boolean argumentvalue
. Ifvalue
isFalse
, the “is known to be false” flag is set; if it isTrue
, the “is known to be true” flag is set. Use this function if you know the state of one of these properties when creating aMathObject
. (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 ofcache_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 ofcache_is_<property>
(see for exampleSet.cache_is_relation()
).-
get_ground_set
() → algebraixlib.structure.Structure[source]¶ Return the ground set of the lowest-level algebra of this
MathObject
.
-
is_functional
() → bool[source]¶ Return whether
self
is functional orUndef()
if not applicable.
-
is_right_functional
() → bool[source]¶ Return whether
self
is right-functional orUndef()
if not applicable.
-
is_transitive
() → bool[source]¶ Return whether
self
is transitive orUndef()
if not applicable.
-
is_equivalence_relation
() → bool[source]¶ Return whether
self
is an equivalence relation orUndef()
if not applicable.
-
__call__
(*args, **kwargs) → '( M )'[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__
(left) → 'P( M )'[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_is_not_relation
¶ Return
True
ifself
is known to not be a relation. See [PropCache].
-
cached_is_relation
¶ Return
True
ifself
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
ifself
is known to not be a clan. See [PropCache].
-
cached_is_clan
¶ Return
True
ifself
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
ifself
is known to not be a multiclan. See [PropCache].
-
cached_is_multiclan
¶ Return
True
ifself
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
ifself
is known to not be functional. See [PropCache].
-
cached_is_functional
¶ Return
True
ifself
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
ifself
is known to not be right-functional. See [PropCache].
-
cached_is_right_functional
¶ Return
True
ifself
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
ifself
is known to not be regular. See [PropCache].
-
cached_is_regular
¶ Return
True
ifself
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
ifself
is known to not be reflexive. See [PropCache].
-
cached_is_reflexive
¶ Return
True
ifself
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
ifself
is known to not be symmetric. See [PropCache].
-
cached_is_symmetric
¶ Return
True
ifself
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
ifself
is known to not be transitive. See [PropCache].
-
cached_is_transitive
¶ Return
True
ifself
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.