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
(set1: 'P( M )', set2: 'P( M )', _checked=True) → 'P( M )'[source]¶ Return the union of
set1
withset2
.Returns: The binary union of set1
andset2
orUndef()
ifset1
orset2
are not sets (that is, instances ofSet
).
-
static
intersect
(set1: 'P( M )', set2: 'P( M )', _checked=True) → 'P( M )'[source]¶ Return the intersection of
set1
withset2
.Returns: The binary intersection of set1
andset2
orUndef()
ifset1
orset2
are not sets (that is, instances ofSet
).
-
static
minus
(set1: 'P( M )', set2: 'P( M )', _checked=True) → 'P( M )'[source]¶ Return the set difference of
set1
andset2
.Returns: The difference of set1
andset2
orUndef()
ifset1
orset2
are not sets (that is, instances ofSet
).
-
static
substrict
(set1: 'P( M )', set2: 'P( M )', _checked=True) → 'P( M )'[source]¶ Return
set1
if it is a subset ofset2
, otherwise returnUndef()
.Returns: Return the substriction of set1
andset1
; that is, returnset1
if it is a subset ofset2
orUndef()
if not. Also returnUndef()
ifset1
orset2
are not sets (that is, instances ofSet
).
-
static
superstrict
(set1: 'P( M )', set2: 'P( M )', _checked=True) → 'P( M )'[source]¶ Return
set1
if it is a superset ofset2
, otherwise returnUndef()
.Returns: Return the superstriction of set1
andset1
; that is, returnset1
if it is a subset ofset2
orUndef()
if not. Also returnUndef()
ifset1
orset2
are not sets (that is, instances ofSet
).
-
static
-
algebraixlib.algebras.sets.
union
(set1: 'P( M )', set2: 'P( M )', _checked=True) → 'P( M )'¶ Convenience redirection to
Algebra.union
.
-
algebraixlib.algebras.sets.
intersect
(set1: 'P( M )', set2: 'P( M )', _checked=True) → 'P( M )'¶ Convenience redirection to
Algebra.intersect
.
-
algebraixlib.algebras.sets.
minus
(set1: 'P( M )', set2: 'P( M )', _checked=True) → 'P( M )'¶ Convenience redirection to
Algebra.minus
.
-
algebraixlib.algebras.sets.
substrict
(set1: 'P( M )', set2: 'P( M )', _checked=True) → 'P( M )'¶ Convenience redirection to
Algebra.substrict
.
-
algebraixlib.algebras.sets.
superstrict
(set1: 'P( M )', set2: 'P( M )', _checked=True) → 'P( M )'¶ Convenience redirection to
Algebra.superstrict
.
-
algebraixlib.algebras.sets.
is_subset_of
(set1: 'P( M )', set2: 'P( M )', _checked=True) → bool¶ Convenience redirection to
Algebra.is_subset_of
.
-
algebraixlib.algebras.sets.
is_superset_of
(set1: 'P( M )', set2: 'P( M )', _checked=True) → bool¶ 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
ifobj
is an instance ofSet
,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.return: True
ifobj
is an absolute set,False
if not.Note
This function calls
get_ground_set()
onobj
.
-
algebraixlib.algebras.sets.
multify
(set1: 'P( M )', _checked=True) → 'P( M x N )'[source]¶ Return a multiset based on
set1
where all multiples are set to 1.
-
algebraixlib.algebras.sets.
big_union
(set1: 'PP( M )', _checked=True) → 'P( M )'[source]¶ Return the union of all members of
set1
.Returns: The union of all members of set1
orUndef()
ifset1
or any of its members are not instances ofSet
.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
(set1: 'PP( M )', _checked=True) → 'P( M )'[source]¶ Return the intersection of all members of
set1
.Returns: The intersection of all members of set1
orUndef()
ifset1
or any of its members are not instances ofSet
.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
(set1: algebraixlib.mathobjects.set.Set)[source]¶ Return the single element of
set1
.Returns: Return the single element of set1
, orUndef()
ifset1
has not exactly one element or is not a set (that is, an instance ofSet
).
-
algebraixlib.algebras.sets.
some
(set1: algebraixlib.mathobjects.set.Set)[source]¶ Return ‘some’ element of
set1
. Use with caution - may be non-deterministic.Returns: Some element of set1
, orUndef()
ifset1
is empty or is not a set (that is, an instance ofSet
).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
set1
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
set1
is retrieved, because the expressions that consume that value will be invariant with respect to the exact element ofset1
that is returned.
-
algebraixlib.algebras.sets.
power_set
(set1: algebraixlib.mathobjects.set.Set)[source]¶ Return the power set of
set1
.
-
algebraixlib.algebras.sets.
power_up
(set1: algebraixlib.mathobjects.set.Set)[source]¶ ‘Add a set of braces’ around the elements of
set1
.Returns: A Set
where every element is aSet
that contains exactly one element ofset1
and where there is exactly one element-Set
for every element ofset1
.
-
algebraixlib.algebras.sets.
restrict
(set1: 'P( M )', selector: collections.abc.Callable) → 'P( M )'[source]¶ Return a set with all the elements from
set1
for which the predicateselector
returnsTrue
.Parameters: - set1 – The source data. Must be a set.
- selector – A
Callable
that accepts as single argument aMathObject
and returns abool
that indicates whether the element is in the result set (True
) or not (False
).
-
algebraixlib.algebras.sets.
chain_binary_operation
(set1, binary_op, is_algebra_member)[source]¶ Chain all elements of
set1
with the binary operationbinary_op
and return the result.Parameters: Returns: A member of
algebra
that is the result of chaining all elements ofset1
with the binary operationbinary_op
.