algebraixlib.mathobjects.atom module

Provide the class Atom that represents atoms and the function auto_convert() that passes through instances of MathObjects and converts other types into Atom instances.

algebraixlib.mathobjects.atom.auto_convert(arg)[source]

Return always a MathObject. If arg is not a MathObject, make it an Atom.

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 of Atom.

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 than Atom. (If it is of type Atom, the instance is re-used; see __new__.) value must be immutable and hashable.
  • direct_load – Set to True if you can be sure that value is not an instance of MathObject. Default is False.
Raise:

TypeError if value is not hashable.

static __new__(value, direct_load=False)[source]

If value is an instance of Atom, 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 of Atom (in this case we simply reuse it). If not, follow the normal path for creating an instance.
value

Read-only; return the value of this instance. Is always a member of set A.

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).

__hash__()[source]

Return a hash based on the value calculated during construction.

__repr__()[source]

Return the instance’s code representation.

__str__()[source]

Return the instance’s string representation.

__le__(other, NotImplemented=NotImplemented)

Return a <= b. Computed by @total_ordering from (a < b) or (a == b).