algebraixlib.mathobjects.set module

Provide the class Set; it represents a set.


Factory wrapper to create a Set.


Factory wrapper to create a Set (unchecked version).

class algebraixlib.mathobjects.set.Set(*args, direct_load=False)[source]

Bases: algebraixlib.mathobjects.mathobject.MathObject

A set containing zero or more different MathObject instances.

  • args – Zero or more unnamed arguments that are placed into the created Set. If you want to pass in an iterable, you need to prefix it with an asterisk *. If no argument is given or the given iterable is empty, an empty set is created. (A Python string of type str is an iterable, but it is considered a single, non-iterable argument.)
  • direct_load – (Optional) Set to True if you know that all arguments (or all elements of the iterable) are instances of MathObject.

Read-only; return the elements of this instance as a frozenset of MathObject instances.


Read-only; return the number of elements in the set.


Return True if this set is empty, False if not.

has_element(elem: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return whether elem is an element of this set. elem must be a MathObject.

For a more relaxed version (that auto-converts non-MathObject arguments into instances of Atom) see __contains__ and the construct elem in Set.

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

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


Get the left set for this Set. Return Undef() if not applicable.


Get the right set for this Set. Return Undef() if not applicable.


Implement value-based equality. Return True if type and set elements match.


Implement value-based inequality. Return True if type or set elements don’t match.


Return True if item is a member of this set. If item is not a MathObject, it is converted into an Atom.

This allows Boolean expressions of the form element in Set.


Return a hash based on the value that is calculated on demand and cached.


Return the instance’s code representation.


Return the instance’s string representation.


With the syntax mo(left), return the right associated with left.

  • args – Exactly one argument is expected; it is the left of the couplet of which the right is returned.
  • kwargs – Named arguments are not supported.

If self is a function, return the right component of the couplet that has as left 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.

__le__(other, NotImplemented=NotImplemented)

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


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 component that matches left. If self is a clan, return a set that contains the right(s) of all couplets in all relations that have a left component that matches left. (The returned set may be empty if no couplet with the given left exists.) Return Undef() if self is neither a relation nor a clan.