algebraixlib.algebras.sets module

This module contains the algebra of sets and related functionality.

class algebraixlib.algebras.sets.Algebra[source]

Bases: object

Provide the operations and relations that are members of the algebra of sets.

This class contains only static member functions. Its main purpose is to provide a namespace for and highlight the operations and relations that belong to the algebra of sets. All member functions are also available at the enclosing module level.

static union()[source]

Return the union of set1 with set2.

Returns:The binary union of set1 and set2 or Undef() if set1 or set2 are not sets (that is, instances of Set).
static intersect()[source]

Return the intersection of set1 with set2.

Returns:The binary intersection of set1 and set2 or Undef() if set1 or set2 are not sets (that is, instances of Set).
static minus()[source]

Return the set difference of set1 and set2.

Returns:The difference of set1 and set2 or Undef() if set1 or set2 are not sets (that is, instances of Set).
static substrict()[source]

Return set1 if it is a subset of set2, otherwise return Undef().

Returns:Return the substriction of set1 and set1; that is, return set1 if it is a subset of set2 or Undef() if not. Also return Undef() if set1 or set2 are not sets (that is, instances of Set).
static superstrict()[source]

Return set1 if it is a superset of set2, otherwise return Undef().

Returns:Return the superstriction of set1 and set1; that is, return set1 if it is a superset of set2 or Undef() if not. Also return Undef() if set1 or set2 are not sets (that is, instances of Set).
static is_subset_of()[source]

Return whether set1 is a subset of set2.

Returns:True if set1 is a subset of set2, False if not. Return Undef() if set1 or set2 are not sets (that is, instances of Set).
static is_superset_of()[source]

Return whether set1 is a superset of set2.

Returns:True if set1 is a superset of set2, False if not. Return Undef() if set1 or set2 are not sets (that is, instances of Set).
algebraixlib.algebras.sets.union()

Convenience redirection to Algebra.union.

algebraixlib.algebras.sets.intersect()

Convenience redirection to Algebra.intersect.

algebraixlib.algebras.sets.minus()

Convenience redirection to Algebra.minus.

algebraixlib.algebras.sets.substrict()

Convenience redirection to Algebra.substrict.

algebraixlib.algebras.sets.superstrict()

Convenience redirection to Algebra.superstrict.

algebraixlib.algebras.sets.is_subset_of()

Convenience redirection to Algebra.is_subset_of.

algebraixlib.algebras.sets.is_superset_of()

Convenience redirection to Algebra.is_superset_of.

algebraixlib.algebras.sets.get_name() → str[source]

Return the name and ground set of this algebra in string form.

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

Return the ground set of this algebra.

algebraixlib.algebras.sets.get_absolute_ground_set() → algebraixlib.structure.Structure[source]

Return the absolute ground set of this algebra.

algebraixlib.algebras.sets.is_member(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return whether obj is a member of the ground set of this algebra.

Returns:True if obj is a set (an instance of Set), False if not.
algebraixlib.algebras.sets.is_member_or_undef(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]
Return whether obj is either a member of the ground set of this algebra
or Undef.
Returns:True if obj is either a relation or Undef, False if not.
algebraixlib.algebras.sets.is_absolute_member(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return whether obj is a member of the absolute ground set of this algebra.

Returns:True if obj is an absolute set, False if not.
algebraixlib.algebras.sets.multify()[source]

Return a multiset based on set_ where all multiples are set to 1.

algebraixlib.algebras.sets.big_union()[source]

Return the union of all members of set_.

Returns:The union of all members of set_ or Undef() if set_ or any of its members are not instances of Set.

Example code:

from algebraixlib.mathobjects import Set
from algebraixlib.algebras.sets import big_union
big_union(Set(Set('a', 'b'), Set('b', 'c')))
# Output: Set(Atom('a'), Atom('b'), Atom('c'))
big_union(Set(Set('a', 'b'), 'a'))
# Output: <algebraixlib.undef.Undef at 0x4004978>
algebraixlib.algebras.sets.big_intersect()[source]

Return the intersection of all members of set_.

Returns:The intersection of all members of set_ or Undef() if set_ or any of its members are not instances of Set.

Example code:

from algebraixlib.mathobjects import Set
from algebraixlib.algebras.sets import big_intersect
big_intersect(Set(Set('a', 'b'), Set('b', 'c')))
# Output: Set(Atom('b'))
big_intersect(Set(Set('a', 'b'), 'a'))
# Output: <algebraixlib.undef.Undef at 0x4004978>
algebraixlib.algebras.sets.single(set_: algebraixlib.mathobjects.set.Set)[source]

Return the single element of set_.

Returns:Return the single element of set_, or Undef() if set_ has not exactly one element or is not a set (that is, an instance of Set).
algebraixlib.algebras.sets.some(set_: algebraixlib.mathobjects.set.Set)[source]

Return ‘some’ element of set_. Use with caution - may be non-deterministic.

Returns:Some element of set_, or Undef() if set_ is empty or is not a set (that is, an instance of Set).

Note

This function should only be used in contexts where the way the return value will be utilized by the calling function is invariant of the particular element returned; the element of set_ that is returned is non-deterministic.

This function is only intended to be used in (mostly implementation) scenarios where it does not matter which element of set_ is retrieved, because the expressions that consume that value will be invariant with respect to the exact element of set_ that is returned.

algebraixlib.algebras.sets.power_set(set_: algebraixlib.mathobjects.set.Set)[source]

Return the power set of set_.

algebraixlib.algebras.sets.power_up(set_: algebraixlib.mathobjects.set.Set)[source]

‘Add a set of braces’ around the elements of set_.

Returns:A Set where every element is a Set that contains exactly one element of set_ and where there is exactly one element-Set for every element of set_.
algebraixlib.algebras.sets.restrict()[source]

Return a set with all the elements from set_ for which the predicate selector returns True.

Parameters:
  • set – The source data. Must be a set.
  • selector – A Callable that accepts as single argument a MathObject and returns a bool that indicates whether the element is in the result set (True) or not (False).
algebraixlib.algebras.sets.chain_binary_operation(set_, binary_op, is_algebra_member)[source]

Chain all elements of set_ with the binary operation binary_op and return the result.

Parameters:
  • set – A set of sets or multisets.
  • binary_op – The operation through which the members of set_ are chained. It must be commutative and associative.
  • is_algebra_member – The is_member() function of the algebra of which the elements of set_ must be members.
Returns:

A member of algebra that is the result of chaining all elements of set_ with the binary operation binary_op.