algebraixlib.mathobjects.multiset module

Provide the class Multiset; it represents a multiset.

class algebraixlib.mathobjects.multiset.Multiset(*args, direct_load=False)[source]

Bases: algebraixlib.mathobjects.mathobject.MathObject

A multiset consisting of zero or more different MathObject instances.

  • args – Zero or more unnamed arguments that are placed into the created Multiset. 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 multiset is created. (A Python string of type str is an iterable, but it is considered a single, non-iterable argument.) Arguments of type Counter are loaded directly, and arguments of type dict must map values or instances of MathObject to integers; the integers are interpreted as multiplicity values for the given keys. (In order to create a Multiset that contains a Counter or dict, put the Counter or dict in an Atom or an array first.)
  • 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 Counter of MathObject instances.


Even though the returned data is a dict and can be modified, this should be avoided if at all possible, and if needed, it should be done with care. It may only be done as long as the instance has not been read by code other than the modifying code, and as long as the hash has not yet been calculated. Modifying the data must follow the ‘as-if’ rule: the modification must be done in a way as if the instance were immutable (for all relevant purposes).


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


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

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

Return whether elem is an element of this multiset. 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 Multiset.

get_multiplicity(elem: algebraixlib.mathobjects.mathobject.MathObject) → int[source]

Return int if elem is an element of this Multiset where the value is the number of multiples for elem. elem must be a MathObject.

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

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


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


Once multipowersets are fully implemented, see get_left_set().


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


Once multipowersets are fully implemented, see get_right_set().


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


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


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

This allows Boolean expressions of the form element in Multiset.


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.

__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 multi-relation, return a multiset that contains the right(s) of the couplet(s) that have a left component that matches left. (The returned multiset may be empty if no couplet with the given left exists.) Return Undef() if self is not a multi-relation.