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
withset2
.Returns: The binary union of set1
andset2
orUndef()
ifset1
orset2
are not sets (that is, instances ofSet
).
-
static
intersect
()[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
()[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
()[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
()[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 superset ofset2
orUndef()
if not. Also returnUndef()
ifset1
orset2
are not sets (that is, instances ofSet
).
-
static
-
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
ifobj
is a set (an instance ofSet
),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
ifobj
is either a relation orUndef
,False
if not.- Return whether
-
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
ifobj
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_
orUndef()
ifset_
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
()[source]¶ Return the intersection of all members of
set_
.Returns: The intersection of all members of set_
orUndef()
ifset_
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
(set_: algebraixlib.mathobjects.set.Set)[source]¶ Return the single element of
set_
.Returns: Return the single element of set_
, orUndef()
ifset_
has not exactly one element or is not a set (that is, an instance ofSet
).
-
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_
, orUndef()
ifset_
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
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 ofset_
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 aSet
that contains exactly one element ofset_
and where there is exactly one element-Set
for every element ofset_
.
-
algebraixlib.algebras.sets.
restrict
()[source]¶ Return a set with all the elements from
set_
for which the predicateselector
returnsTrue
.Parameters: - set – 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
(set_, binary_op, is_algebra_member)[source]¶ Chain all elements of
set_
with the binary operationbinary_op
and return the result.Parameters: Returns: A member of
algebra
that is the result of chaining all elements ofset_
with the binary operationbinary_op
.