algebraixlib.mathobjects.atom module¶
Provide the class Atom
that represents atoms and the function
auto_convert()
that passes through instances of MathObject
s and converts other types into
Atom
instances.
-
algebraixlib.mathobjects.atom.
auto_convert
(arg)[source]¶ Return always a
MathObject
. Ifarg
is not aMathObject
, make it anAtom
.This function is used in several constructors as convenience wrapper to allow the creation of
MathObject
instances from non-MathObject
values.
-
class
algebraixlib.mathobjects.atom.
Atom
(value, direct_load=False)[source]¶ Bases:
algebraixlib.mathobjects.mathobject.MathObject
Represent a value (of a non-
MathObject
, hashable type) like numbers or strings.All instances of
Atom
are members of set A (\(A\)), or conversely, set A is the set of all instances ofAtom
.Note
Instances of
Atom
are immutable and hashable. Therefore they only accept immutable and hashable values.Parameters: - value – The value of this instance. May not be an instance of
MathObject
other thanAtom
. (If it is of typeAtom
, the instance is re-used; see__new__
.)value
must be immutable and hashable. - direct_load – Set to
True
if you can be sure thatvalue
is not an instance ofMathObject
. Default isFalse
.
Raise: TypeError
ifvalue
is not hashable.-
static
__new__
(value, direct_load=False)[source]¶ If
value
is an instance ofAtom
, reuse it.This mechanism is used to reduce the number of created
Atom
instances. We then need to check in__init__
whether we have an already initialized instance or still have to initialize it.__init__
is always called after__new__
.Returns: value
if it is an instance ofAtom
(in this case we simply reuse it). If not, follow the normal path for creating an instance.
-
type
¶ Read-only; return the type of this instance.
-
get_ground_set
() → algebraixlib.structure.Structure[source]¶ Return the ground set of the lowest-level algebra of
self
. Is always \(A\).
-
__eq__
(other)[source]¶ A value-based comparison for equality. Return
True
if types and values match.Type-matching follows Python rules, so
not Atom(1) == Atom(1.0)
.
-
__ne__
(other)[source]¶ A value-based comparison for inequality. Return
True
if types or values don’t match.Type-matching follows Python rules, so
Atom(1) != Atom(1.0)
.
-
__le__
(other, NotImplemented=NotImplemented)¶ Return a <= b. Computed by @total_ordering from (a < b) or (a == b).
- value – The value of this instance. May not be an instance of