Algebraix Technology Core Library¶
algebraixlib
is a library that provides constructs and facilities to harness the fundamentals
of data algebra. You find us:
- On PyPI. Here you find the
pip
installer. Install aspip install algebraixlib
(system-wide) orpip install algebraixlib --user <username>
(for a single user) or download the package. - On GitHub. Here you find “Getting Started” quick-start instructions, the full sources and can use the bug tracker.
- On Algebraix Data’s GitHub project page. Here you find support information.
Also check out our tutorials and example code in the examples directory on GitHub.
API Documentation¶
algebraixlib package¶
The top-level package for the library algebraixlib
.
Sub-packages:
algebras
: Modules that represent algebras and their operations.io
: Modules with facilities for importing and exporting data.mathobjects
: Modules that define the classes that represent data.util
: Miscellaneous utility modules.
Modules:
extension
: Facilities for extending operations from one algebra to another.partition
: Operations for partitioning sets and multisets.structure
: Representation of the structure of aMathObject
.undef
: Facilities for representing and working with the concept of “undefined”.
Subpackages¶
algebraixlib.algebras package¶
This package contains modules that represent algebras and their operations.
The algebra modules contain a class Algebra
that contains the operations that are formally part
of the given algebra (that is, they are closed within that algebra). For convenience, these
functions are also exposed at the module level. (We collect them in the Algebra
class mainly
for documentation purposes.)
Besides the mathematical operations of a given algebra (in Algebra
), we also provide the
following types of functions that are related to the algebra, but are not members of it:
- Functions that return metadata. For example, all our algebras contain an
is_member
function that returnsTrue
if the argument is a member of the given algebra’s ground set. This function is not mathematically an operation of the algebra. - Other functions that are mathematically related, but have arguments or return results that are
not members of the ground set. For example, the
get_lefts()
function of the algebra of relations returns a result that is not an element of the algebra’s ground set.
The algebras that are provided are:
sets
: The algebra of sets.couplets
: The algebra of couplets.relations
: The algebra of relations. (A relation is a set of couplets).clans
: The algebra of clans. (A clan is a set of relations; that is, a set of sets of couplets).multisets
: The algebra of multisets.multiclans
: The algebra of multiclans. (A multiclan is a multiset of relations; that is, a multiset of sets of couplets).
Additional modules:
properties
: Functions that return the value of a property for a givenMathObject
. They redirect to the appropriate algebra.
Submodules¶
This module contains the algebra of clans and related functionality.
A clan is also a set (of relations), and inherits all operations
of the algebra of sets. These are provided in sets
.
-
class
algebraixlib.algebras.clans.
Algebra
[source]¶ Bases:
object
Provide the operations and relations that are members of the algebra of clans.
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 clans. All member functions are also available at the enclosing module scope.
-
static
transpose
(clan: 'PP(M x M)', _checked=True) → 'PP(M x M)'[source]¶ Return a clan where all relations have their left and right components swapped.
Returns: The unary extension of transposition from the algebra of relations to the algebra of clans, applied to clan
, orUndef()
ifclan
is not a clan.
-
static
compose
(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'[source]¶ Return the composition of
clan1
withclan2
.Returns: The binary extension of composition from the algebra of relations to the algebra of clans, applied to clan1
andclan2
, orUndef()
ifclan1
orclan2
are not clans.
-
static
cross_union
(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'[source]¶ Return the cross-union of
clan1
andclan2
.The cross-union of two clans is a clan that contains the result of unioning every relation from one clan with every relation from the other clan.
Returns: The binary extension of union from the algebra of relations (which inherits it from the algebra of sets) to the algebra of clans applied to clan1
andclan2
, orUndef()
ifclan1
orclan2
are not clans.
-
static
cross_functional_union
(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'[source]¶ Return the cross-functional union of
clan1
andclan2
.The cross-functional union of two clans is the cross-union of these clans, but removing all resulting relations that are not functions.
Returns: The binary extension of the functional union from the algebra of relations to the algebra of clans, applied to clan1
andclan2
, orUndef()
ifclan1
orclan2
are not clans.
-
static
lhs_cross_functional_union
(lhs: 'PP( MxM )', rhs: 'PP( MxM )', _checked=True) → 'PP(M x M)'[source]¶ Return the lhs-cross-functional union (‘left join’) of
lhs
andrhs
.This operation results in a clan that contains every relation of a cross-functional union, but also contains all relations in
lhs
that are not already part of one of the resulting relations.Parameters: lhs – All relations in this clan are guaranteed to be represented in the result. Returns: The resulting clan or Undef()
iflhs
orrhs
are not clans.
-
static
cross_right_functional_union
(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'[source]¶ Return the cross-right-functional union of
clan1
andclan2
.The cross-right-functional union of two clans is the cross-union of these clans, but removing all resulting relations that are not right-functional.
Returns: The binary extension of the right-functional union from the algebra of relations to the algebra of clans, applied to clan1
andclan2
, orUndef()
ifclan1
orclan2
are not clans.
-
static
cross_intersect
(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'[source]¶ Return the cross-intersection of
clan1
andclan2
.The cross-intersection of two clans is a clan that contains the result of intersecting every relation from one clan with every relation from the other clan.
Returns: The binary extension of intersection from the algebra of relations (which inherits it from the algebra of sets) to the algebra of clans applied to clan1
andclan2
, orUndef()
ifclan1
orclan2
are not clans.
-
static
substrict
(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'[source]¶ Return the substriction of
clan1
andclan2
.The substriction of two clans is a clan that contains all relations from
clan1
that are a subset of a relation fromclan2
.Returns: The binary extension of substriction from the algebra of sets to the algebra of clans applied to clan1
andclan2
, orUndef()
ifclan1
orclan2
are not clans.
-
static
superstrict
(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'[source]¶ Return the superstriction of
clan1
andclan2
.The superstriction of two clans is a clan that contains all relations from
clan1
that are a superset of a relation fromclan2
.Returns: The binary extension of superstriction from the algebra of sets to the algebra of clans applied to clan1
andclan2
, orUndef()
ifclan1
orclan2
are not clans.
-
static
-
algebraixlib.algebras.clans.
transpose
(clan: 'PP(M x M)', _checked=True) → 'PP(M x M)'¶ Convenience redirection to
Algebra.transpose
.
-
algebraixlib.algebras.clans.
compose
(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'¶ Convenience redirection to
Algebra.compose
.
-
algebraixlib.algebras.clans.
cross_union
(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'¶ Convenience redirection to
Algebra.cross_union
.
-
algebraixlib.algebras.clans.
cross_functional_union
(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'¶ Convenience redirection to
Algebra.cross_functional_union
.
-
algebraixlib.algebras.clans.
lhs_cross_functional_union
(lhs: 'PP( MxM )', rhs: 'PP( MxM )', _checked=True) → 'PP(M x M)'¶ Convenience redirection to
Algebra.lhs_cross_functional_union
.
-
algebraixlib.algebras.clans.
cross_right_functional_union
(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'¶ Convenience redirection to
Algebra.cross_right_functional_union
.
-
algebraixlib.algebras.clans.
cross_intersect
(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'¶ Convenience redirection to
Algebra.cross_intersect
.
-
algebraixlib.algebras.clans.
substrict
(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'¶ Convenience redirection to
Algebra.substrict
.
-
algebraixlib.algebras.clans.
superstrict
(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'¶ Convenience redirection to
Algebra.superstrict
.
-
algebraixlib.algebras.clans.
get_name
() → str[source]¶ Return the name and ground set of this algebra in string form.
-
algebraixlib.algebras.clans.
get_ground_set
() → algebraixlib.structure.Structure[source]¶ Return the ground set of this algebra.
-
algebraixlib.algebras.clans.
get_absolute_ground_set
() → algebraixlib.structure.Structure[source]¶ Return the absolute ground set of this algebra.
-
algebraixlib.algebras.clans.
is_member
(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]¶ Return whether
obj
is a member of the ground set of this algebra.return: True
ifobj
is a clan,False
if not.Note
This function may call
get_ground_set()
onobj
. The result of this operation is cached.
-
algebraixlib.algebras.clans.
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.clans.
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 clan,False
if not.Note
This function may call
get_ground_set()
onobj
. The result of this operation is cached.
-
algebraixlib.algebras.clans.
get_lefts
(clan: 'PP(M x M)', _checked=True) → 'P( M )'[source]¶ Return the set of the left components of all couplets in all relations in
clan
.Returns: The union of the left sets of all relations in clan
orUndef()
ifclan
is not a clan.
-
algebraixlib.algebras.clans.
get_rights
(clan: 'PP(M x M)', _checked=True) → 'P( M )'[source]¶ Return the set of the right components of all couplets in all relations in
clan
.Returns: The union of the right sets of all relations in clan
orUndef()
ifclan
is not a clan.
-
algebraixlib.algebras.clans.
is_functional
(clan, _checked=True) → bool[source]¶ Return whether
clan
is functional.Returns: True
if every relation inclan
is functional (is a function),False
if not, orUndef()
ifclan
is not a clan.
-
algebraixlib.algebras.clans.
is_right_functional
(clan, _checked=True) → bool[source]¶ Return whether
clan
is right-functional.Returns: True
if every relation inclan
is right-functional,False
if not, orUndef()
ifclan
is not a clan.
-
algebraixlib.algebras.clans.
is_regular
(clan, _checked=True) → bool[source]¶ Return whether
clan
is (left-)regular.Returns: True
ifclan
is regular,False
if not, orUndef()
ifclan
is not a clan.
-
algebraixlib.algebras.clans.
is_right_regular
(clan, _checked=True) → bool[source]¶ Return whether
clan
is right-regular.Returns: True
ifclan
is right-regular,False
if not, orUndef()
ifclan
is not a clan.
-
algebraixlib.algebras.clans.
is_reflexive
(clan, _checked=True) → bool[source]¶ Return whether
clan
is reflexive.Returns: True
if every relation inclan
is reflexive,False
if not, orUndef()
ifclan
is not a clan.
-
algebraixlib.algebras.clans.
is_symmetric
(clan, _checked=True) → bool[source]¶ Return whether
clan
is symmetric.Returns: True
if every relation inclan
is symmetric,False
if not, orUndef()
ifclan
is not a clan.
-
algebraixlib.algebras.clans.
is_transitive
(clan, _checked=True) → bool[source]¶ Return whether
clan
is transitive.Returns: True
if every relation inclan
is transitive,False
if not, orUndef()
ifclan
is not a clan.
-
algebraixlib.algebras.clans.
project
(clan: 'PP(M x M)', *lefts) → 'PP(M x M)'[source]¶ Return a clan that contains only the couplets with lefts from
clan
that matchlefts
.Parameters: - clan – The source data. Must be a clan.
- lefts – The names of the left components to match. (If you want to pass in an
iterable, you need to prefix it with an asterisk
*
.)
Returns: The projection of
clan
(a clan that contains only couplets with left components as indicated bylefts
), orUndef()
ifclan
is not a clan.
-
algebraixlib.algebras.clans.
from_set
(left: '( M )', *values: '( M )') → 'PP(M x M)'[source]¶ Return a clan where all relations contain a single couplet with the same left component.
Parameters: - left – The left component of all couplets in the returned clan.
- values – The right components of the couplets in the returned clan. (If you want
to pass in an iterable, you need to prefix it with an asterisk
*
.)
Returns: A clan where every relation consists of a single couplet with a left component of
left
and a right component fromvalues
.
-
algebraixlib.algebras.clans.
from_dict
(dict1: dict) → 'PP(M x M)'[source]¶ Return a clan with a single relation where the couplets are the elements of
dict1
.
-
algebraixlib.algebras.clans.
diag
(*args, _checked=True) → 'PP(M x M)'[source]¶ Return a clan diagonal of the arguments.
Parameters: args – Pass in the elements from which the clan diagonal is formed. (If you want to pass in an iterable, you need to prefix it with an asterisk *
.)
This module contains the algebra of couplets and related functionality.
-
class
algebraixlib.algebras.couplets.
Algebra
[source]¶ Bases:
object
Provide the operations and relations that are members of the algebra of couplets.
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 couplets. All member functions are also available at the enclosing module scope.
-
static
transpose
(couplet: '(M x M)', _checked=True) → '(M x M)'[source]¶ Return the transposition of
couplet
(right and left components swapped).Returns: The transposition of couplet
orUndef()
ifcouplet
is not an instance ofCouplet
.
-
static
compose
(couplet1: '(M x M)', couplet2: '(M x M)', _checked=True) → '(M x M)'[source]¶ Return the composition of
couplet1
withcouplet2
.Returns: The composition of couplet1
withcouplet2
(which may be undefined, in which case the result isUndef()
) orUndef()
ifcouplet1
orcouplet2
are not instances ofCouplet
.
-
static
-
algebraixlib.algebras.couplets.
transpose
(couplet: '(M x M)', _checked=True) → '(M x M)'¶ Convenience redirection to
Algebra.transpose
.
-
algebraixlib.algebras.couplets.
compose
(couplet1: '(M x M)', couplet2: '(M x M)', _checked=True) → '(M x M)'¶ Convenience redirection to
Algebra.compose
.
-
algebraixlib.algebras.couplets.
get_name
() → str[source]¶ Return the name and ground set of this algebra in string form.
-
algebraixlib.algebras.couplets.
get_ground_set
() → algebraixlib.structure.Structure[source]¶ Return the ground set of this algebra.
-
algebraixlib.algebras.couplets.
get_absolute_ground_set
() → algebraixlib.structure.Structure[source]¶ Return the absolute ground set of this algebra.
-
algebraixlib.algebras.couplets.
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 couplet (an instance ofCouplet
),False
if not.
-
algebraixlib.algebras.couplets.
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 couplet (an instance ofCouplet
) orUndef
,False
if not.- Return whether
-
algebraixlib.algebras.couplets.
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 couplet,False
if not.
This module contains the algebra of multiclans and related functionality.
A multiclan is also a multiset (of relations), and inherits all operations
of the algebra of multisets. These are provided in multisets
.
-
class
algebraixlib.algebras.multiclans.
Algebra
[source]¶ Bases:
object
Provide the operations and relations that are members of the algebra of multiclans.
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 multiclans. All member functions are also available at the enclosing module scope.
-
static
transpose
(multiclan: 'P(P(M x M) x N)', _checked=True) → 'P(P(M x M) x N)'[source]¶ Return a multiclan where all relations have their left and right components swapped.
Returns: The unary multi-extension of transposition from the algebra of relations to the algebra of multiclans, applied to multiclan
, orUndef()
ifmulticlan
is not a multiclan.
-
static
compose
(multiclan1: 'P(P(M x M) x N)', multiclan2: 'P(P(M x M) x N)', _checked=True) → 'P(P(M x M) x N)'[source]¶ Return the composition of
multiclan1
withmulticlan2
.Returns: The binary multi-extension of composition from the algebra of relations to the algebra of multiclans, applied to multiclan1
andmulticlan2
, orUndef()
ifmulticlan1
ormulticlan2
are not multiclans.
-
static
cross_union
(mclan1: 'P(P(M x M) x N)', mclan2: 'P(P(M x M) x N)', _checked=True) → 'P(P(M x M) x N)'[source]¶ Return the cross-union of
mclan1
andmclan2
.Returns: The binary multi-extension of union from the algebra of relations (which inherits it from the algebra of sets) to the algebra of multiclans applied to mclan1
andmclan2
, orUndef()
ifmclan1
ormclan2
are not multiclans.
-
static
cross_functional_union
(mclan1: 'P(P(M x M) x N)', mclan2: 'P(P(M x M) x N)', _checked=True) → 'P(P(M x M) x N)'[source]¶ Return the cross-functional union of
mclan1
andmclan2
.Returns: The binary multi-extension of the functional union from the algebra of relations to the algebra of multiclans, applied to mclan1
andmclan2
, orUndef()
ifmclan1
ormclan2
are not multiclans.
-
static
cross_right_functional_union
(multiclan1: 'P(P(M x M) x N)', multiclan2: 'P(P(M x M) x N)', _checked=True) → 'P(P(M x M) x N)'[source]¶ Return the cross-right-functional union of
multiclan1
andmulticlan2
.Returns: The binary multi-extension of the right-functional union from the algebra of relations to the algebra of multiclans, applied to multiclan1
andmulticlan2
, orUndef()
ifmulticlan1
ormulticlan2
are not multiclans.
-
static
cross_intersect
(multiclan1: 'P(P(M x M) x N)', multiclan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'[source]¶ Return the cross-intersection of
multiclan1
andmulticlan2
.Returns: The binary multi-extension of intersection from the algebra of relations (which inherits it from the algebra of sets) to the algebra of multiclans applied to multiclan1
andmulticlan2
, orUndef()
ifmulticlan1
ormulticlan2
are not multiclans.
-
static
substrict
(multiclan1: 'P(P(M x M) x N)', multiclan2: 'P(P(M x M) x N)', _checked=True) → 'P(P(M x M) x N)'[source]¶ Return the substriction of
multiclan1
andmulticlan2
.The substriction of two multiclans is a multiclan that contains all relations from
multiclan1
that are a submultiset of a relation frommulticlan2
.Returns: The binary multi-extension of substriction from the algebra of relations (which inherits it from the algebra of sets) to the algebra of multiclans applied to multiclan1
andmulticlan2
, orUndef()
ifmulticlan1
ormulticlan2
are not multiclans.
-
static
superstrict
(multiclan1: 'P(P(M x M) x N)', multiclan2: 'P(P(M x M) x N)', _checked=True) → 'P(P(M x M) x N)'[source]¶ Return the superstriction of
multiclan1
andmulticlan2
.The superstriction of two multiclans is a multiclan that contains all relations from
multiclan1
that are a supermultiset of a relation frommulticlan2
.Returns: The binary multi-extension of superstriction from the algebra of relations (which inherits it from the algebra of sets) to the algebra of multiclans applied to multiclan1
andmulticlan2
, orUndef()
ifmulticlan1
ormulticlan2
are not multiclans.
-
static
-
algebraixlib.algebras.multiclans.
transpose
(multiclan: 'P(P(M x M) x N)', _checked=True) → 'P(P(M x M) x N)'¶ Convenience redirection to
Algebra.transpose
.
-
algebraixlib.algebras.multiclans.
compose
(multiclan1: 'P(P(M x M) x N)', multiclan2: 'P(P(M x M) x N)', _checked=True) → 'P(P(M x M) x N)'¶ Convenience redirection to
Algebra.compose
.
-
algebraixlib.algebras.multiclans.
cross_union
(mclan1: 'P(P(M x M) x N)', mclan2: 'P(P(M x M) x N)', _checked=True) → 'P(P(M x M) x N)'¶ Convenience redirection to
Algebra.cross_union
.
-
algebraixlib.algebras.multiclans.
cross_functional_union
(mclan1: 'P(P(M x M) x N)', mclan2: 'P(P(M x M) x N)', _checked=True) → 'P(P(M x M) x N)'¶ Convenience redirection to
Algebra.cross_functional_union
.
-
algebraixlib.algebras.multiclans.
cross_right_functional_union
(multiclan1: 'P(P(M x M) x N)', multiclan2: 'P(P(M x M) x N)', _checked=True) → 'P(P(M x M) x N)'¶ Convenience redirection to
Algebra.cross_right_functional_union
.
-
algebraixlib.algebras.multiclans.
cross_intersect
(multiclan1: 'P(P(M x M) x N)', multiclan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'¶ Convenience redirection to
Algebra.cross_intersect
.
-
algebraixlib.algebras.multiclans.
substrict
(multiclan1: 'P(P(M x M) x N)', multiclan2: 'P(P(M x M) x N)', _checked=True) → 'P(P(M x M) x N)'¶ Convenience redirection to
Algebra.substrict
.
-
algebraixlib.algebras.multiclans.
superstrict
(multiclan1: 'P(P(M x M) x N)', multiclan2: 'P(P(M x M) x N)', _checked=True) → 'P(P(M x M) x N)'¶ Convenience redirection to
Algebra.superstrict
.
-
algebraixlib.algebras.multiclans.
get_name
() → str[source]¶ Return the name and ground set of this algebra in string form.
-
algebraixlib.algebras.multiclans.
get_ground_set
() → algebraixlib.structure.Structure[source]¶ Return the ground set of this algebra.
-
algebraixlib.algebras.multiclans.
get_absolute_ground_set
() → algebraixlib.structure.Structure[source]¶ Return the absolute ground set of this algebra.
-
algebraixlib.algebras.multiclans.
is_member
(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]¶ Return whether
obj
is a member of the ground set of this algebra.return: True
ifobj
is a multiclan,False
if not.Note
This function may call
get_ground_set()
onobj
. The result of this operation is cached.
-
algebraixlib.algebras.multiclans.
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.multiclans.
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 clan,False
if not.Note
This function may call
get_ground_set()
onobj
. The result of this operation is cached.
-
algebraixlib.algebras.multiclans.
get_lefts
(mclan: 'P(P(M x M) x N)', _checked=True) → 'P( M )'[source]¶ Return the set of the left components of all couplets in all relations in
mclan
.Returns: The union of the left sets of all relations in mclan
orUndef()
ifmclan
is not a multiclan.
-
algebraixlib.algebras.multiclans.
get_rights
(mclan: 'P(P(M x M) x N)', _checked=True) → 'P( M )'[source]¶ Return the set of the right components of all couplets in all relations in
mclan
.Returns: The union of the right sets of all relations in mclan
orUndef()
ifmclan
is not a multiclan.
-
algebraixlib.algebras.multiclans.
get_rights_for_left
(mclan: 'P(P(M x M) x N)', left: '( M )', _checked=True) → 'P(M x N)'[source]¶ Return the multiset of the right components of all couplets in the multiclan
mclan
associated with the left componentleft
.Returns: The right multiset of the multiclan mclan
associated with the left componentleft
orUndef()
ifmclan
is not a multiclan.
-
algebraixlib.algebras.multiclans.
is_functional
(mclan, _checked=True) → bool[source]¶ Return whether
mclan
is functional.Returns: True
if every relation inmclan
is functional (is a function),False
if not, orUndef()
ifmclan
is not a multiclan.
-
algebraixlib.algebras.multiclans.
is_right_functional
(mclan, _checked=True) → bool[source]¶ Return whether
mclan
is right-functional.Returns: True
if every relation inmclan
is right-functional,False
if not, orUndef()
ifmclan
is not a multiclan.
-
algebraixlib.algebras.multiclans.
is_regular
(mclan, _checked=True) → bool[source]¶ Return whether
mclan
is (left-)regular.Returns: True
ifmclan
is regular,False
if not, orUndef()
ifmclan
is not a multiclan.
-
algebraixlib.algebras.multiclans.
is_right_regular
(mclan, _checked=True) → bool[source]¶ Return whether
mclan
is right-regular.Returns: True
ifmclan
is right-regular,False
if not, orUndef()
ifmclan
is not a multiclan.
-
algebraixlib.algebras.multiclans.
is_reflexive
(mclan, _checked=True) → bool[source]¶ Return whether
mclan
is reflexive.Returns: True
ifmclan
is reflexive,False
if it is not, orUndef()
ifmclan
is not a multiclan.
-
algebraixlib.algebras.multiclans.
is_symmetric
(mclan, _checked=True) → bool[source]¶ Return whether
mclan
is symmetric.Returns: True
ifmclan
is symmetric,False
if it is not, orUndef()
ifmclan
is not a multiclan.
-
algebraixlib.algebras.multiclans.
is_transitive
(mclan, _checked=True) → bool[source]¶ Return whether
mclan
is transitive.Returns: True
ifmclan
is transitive,False
if it is not, orUndef()
ifmclan
is not a multiclan.
-
algebraixlib.algebras.multiclans.
project
(mclan: 'P(P(M x M) x N)', *lefts) → 'P(P(M x M) x N)'[source]¶ Return a multiclan that contains only the couplets with lefts from
mclan
that matchlefts
.Parameters: - mclan – The source data. Must be a multiclan.
- lefts – The names of the left components to match. (If you want to pass in an
iterable, you need to prefix it with an asterisk
*
.)
Returns: The projection of
mclan
(a multiclan that contains only couplets with left components as indicated bylefts
), orUndef()
ifmclan
is not a multiclan.
-
algebraixlib.algebras.multiclans.
multiclan_to_listgen
(mclan: 'P(P(M x M) x N)', offset: '( A )', limit: '( A )', _checked: bool=True) → [()][source]¶ Return a generator expression for a list of tuples that contains the relations with indices
offset <= index < offset + limit
. Note that because of the lack of order the result is not deterministic when usingoffset
orlimit
. (See alsoorder_slice_to_listgen
.) Each tuple contains a relation and its multiplicity.Parameters: - mclan – The source data. Must be a multiclan.
- offset – An atom with an integer value that indicates the index of the first
relation (after sorting the multiclan) in the result. Set to
Atom(0)
if you want to start with the first relation of the sorted multiclan. - limit – An atom with an integer value that indicates how many relations should be in
the resulting multiclan. When
limit
isfloat('inf')
, all relations are returned.
-
algebraixlib.algebras.multiclans.
order_slice_to_listgen
(mclan: 'P(P(M x M) x N)', less_than_f, offset: '( A )', limit: '( A )', _checked: bool=True) → [()][source]¶ Return a generator expression for a list of tuples that contains the relations with indices
offset <= index < offset + limit
, after having been ordered according toorder
. Each tuple contains a relation and its multiplicity.Parameters: - mclan – The source data. Must be a multiclan.
- less_than_f – A function that accepts two relations as arguments and returns
True
if the first one is less than the second one. - offset – An atom with an integer value that indicates the index of the first
relation (after sorting the multiclan) in the result. Set to
Atom(0)
if you want to start with the first relation of the sorted multiclan. - limit – An atom with an integer value that indicates how many relations should be in
the resulting multiclan. When
limit
isfloat('inf')
, all relations are returned.
Note
Eventually we may add a
MathObject
representation for sequences (‘ordered sets’). Until we do, we can’t split the application of offset and limit from the ordering/sorting.
-
algebraixlib.algebras.multiclans.
order_slice
(mclan: 'P(P(M x M) x N)', less_than_f, offset: '( A )', limit: '( A )', _checked: bool=True) → 'P(P(M x M) x N)'[source]¶ Return a multiclan that contains the relations with indices
offset <= index < offset + limit
, after having been ordered according toorder
.Parameters: - mclan – The source data. Must be a multiclan.
- less_than_f – A function that accepts two relations as arguments and returns
True
if the first one is less than the second one. - offset – An atom with an integer value that indicates the index of the first
relation (after sorting the multiclan) in the result. Set to
Atom(0)
if you want to start with the first relation of the sorted multiclan. - limit – An atom with an integer value that indicates how many relations should be in
the resulting multiclan. When
limit
isfloat('inf')
, all relations are returned.
-
algebraixlib.algebras.multiclans.
from_dict
(dict1: dict) → 'P(P(M x M) x N)'[source]¶ Return a multiclan with a single relation where the couplets are the elements of
dict1
.
-
algebraixlib.algebras.multiclans.
diag
(*args, _checked=True) → 'P(P(M x M) x N)'[source]¶ Return a multiclan diagonal of the arguments.
Parameters: args – Pass in the elements from which the clan diagonal is formed. (If you want to pass in an iterable, you need to prefix it with an asterisk *
.)
This module contains the algebra of multisets and related functionality.
-
class
algebraixlib.algebras.multisets.
Algebra
[source]¶ Bases:
object
Provide the operations and relations that are members of the algebra of multisets.
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 multisets. All member functions are also available at the enclosing module scope.
-
static
union
(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'[source]¶ Return the multiset union of
multiset1
withmultiset2
.Returns: The multiset union of multiset1
andmultiset2
orUndef()
ifmultiset1
ormultiset2
are not instances ofMultiset
.
-
static
intersect
(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'[source]¶ Return the multiset intersection of
multiset1
withmultiset2
.Returns: The multiset intersection of multiset1
andmultiset2
orUndef()
ifmultiset1
ormultiset2
are not instances ofMultiset
.
-
static
minus
(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'[source]¶ Return the multiset difference of
multiset1
andmultiset2
.Returns: The multiset difference of multiset1
andmultiset2
orUndef()
ifmultiset1
ormultiset2
are not instances ofMultiset
.
-
static
add
(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'[source]¶ Return the multiset addition of
multiset1
andmultiset2
.Returns: The multiset addition of multiset1
andmultiset2
orUndef()
ifmultiset1
ormultiset2
are not instances ofMultiset
.
-
static
substrict
(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'[source]¶ Return
multiset1
ifmultiset1
is a subset ofmultiset2
orUndef()
if not.Returns: The substriction of multiset1
andmultiset2
(may returnUndef()
). Also returnUndef()
ifmultiset1
ormultiset2
are not instances ofMultiset
.
-
static
superstrict
(multiset1: 'P( M x N )', multiset2: 'P( M X N )', _checked=True) → 'P( M X N )'[source]¶ Return
multiset1
ifmultiset1
is a superset ofmultiset2
orUndef()
if not.Returns: The superstriction of multiset1
andmultiset2
(may returnUndef()
). Also returnUndef()
ifmultiset1
ormultiset2
are not instances ofMultiset
.
-
static
is_subset_of
(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → bool[source]¶ Return whether
multiset1
is a submultiset ofmultiset2
.Returns: True
ifmultiset1
is a submultiset ofmultiset2
,False
if not. ReturnUndef()
ifmultiset1
ormultiset2
are not instances ofMultiset
.
-
static
is_superset_of
(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → bool[source]¶ Return whether
multiset1
is a supermultiset ofmultiset2
.Returns: True
ifmultiset1
is a supermultiset ofmultiset2
,False
if not. ReturnUndef()
ifmultiset1
ormultiset2
are not instances ofMultiset
.
-
static
-
algebraixlib.algebras.multisets.
union
(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'¶ Convenience redirection to
Algebra.union
.
-
algebraixlib.algebras.multisets.
intersect
(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'¶ Convenience redirection to
Algebra.intersect
.
-
algebraixlib.algebras.multisets.
minus
(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'¶ Convenience redirection to
Algebra.minus
.
-
algebraixlib.algebras.multisets.
add
(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'¶ Convenience redirection to
Algebra.add
.
-
algebraixlib.algebras.multisets.
substrict
(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'¶ Convenience redirection to
Algebra.substrict
.
-
algebraixlib.algebras.multisets.
superstrict
(multiset1: 'P( M x N )', multiset2: 'P( M X N )', _checked=True) → 'P( M X N )'¶ Convenience redirection to
Algebra.superstrict
.
-
algebraixlib.algebras.multisets.
is_subset_of
(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → bool¶ Convenience redirection to
Algebra.is_subset_of
.
-
algebraixlib.algebras.multisets.
is_superset_of
(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → bool¶ Convenience redirection to
Algebra.is_superset_of
.
-
algebraixlib.algebras.multisets.
get_name
() → str[source]¶ Return the name and ground set of this algebra in string form.
-
algebraixlib.algebras.multisets.
get_ground_set
() → algebraixlib.structure.Structure[source]¶ Return the ground set of this algebra.
-
algebraixlib.algebras.multisets.
get_absolute_ground_set
() → algebraixlib.structure.Structure[source]¶ Return the absolute ground set of this algebra.
-
algebraixlib.algebras.multisets.
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 multiset (an instance ofMultiset
),False
if not.
-
algebraixlib.algebras.multisets.
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.multisets.
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 multiset,False
if not.
-
algebraixlib.algebras.multisets.
demultify
(multiset: 'P( M x N )', _checked=True) → 'P( M )'[source]¶ Return a set based on
multiset
that contains all elements without multiples.
-
algebraixlib.algebras.multisets.
big_union
(set_of_multisets: 'PP( M x N )', _checked=True) → 'P( M x N )'[source]¶ Return the set_of_multisets union of all members of
set_of_multisets
.Returns: The multiset union of all members of set_of_multisets
orUndef()
ifset_of_multisets
is not aSet
or any of its members are not instances ofMultiset
.
-
algebraixlib.algebras.multisets.
big_intersect
(set_of_multisets: 'PP( M x N )', _checked=True) → 'P( M x N )'[source]¶ Return the multiset intersection of all members of
multiset
.Returns: The multiset intersection of all members of set_of_multisets
orUndef()
ifset_of_multisets
is not aSet
or any of its members are not instances ofMultiset
.
-
algebraixlib.algebras.multisets.
single
(mset: algebraixlib.mathobjects.multiset.Multiset)[source]¶ Return the single element of
mset
.Returns: Return the single element of mset
, orUndef()
ifmset
has not exactly one element with a multiplicity of 1 or is not a multiset (that is, an instance ofMultiset
).
-
algebraixlib.algebras.multisets.
some
(mset: algebraixlib.mathobjects.multiset.Multiset)[source]¶ Return ‘some’ element of
mset
. Use with caution - may be non-deterministic.Returns: Some element of mset
, orUndef()
ifmset
is empty or is not a multiset (that is, an instance ofMultiset
).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
mset
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
mset
is retrieved, because the expressions that consume that value will be invariant with respect to the exact element ofmset
that is returned.
Accessors for the properties of a generic MathObject
that redirect to the appropriate algebra.
The accessors here check what algebra a given MathObject
belongs to, then call the property
function of this algebra.
-
algebraixlib.algebras.properties.
is_functional
(mo: algebraixlib.mathobjects.mathobject.MathObject, _checked: bool=True) → bool[source]¶ Return whether
mo
is functional orUndef()
if not applicable.Is implemented for relations, clans, multiclans and sets of (sets of ...) clans. Is also defined (but not yet implemented) for any combination of sets or multisets of relations.
-
algebraixlib.algebras.properties.
is_right_functional
(mo: algebraixlib.mathobjects.mathobject.MathObject, _checked: bool=True) → bool[source]¶ Return whether
mo
is right-functional orUndef()
if not applicable.Is implemented for relations, clans, multiclans and sets of (sets of ...) clans. Is also defined (but not yet implemented) for any combination of sets or multisets of relations.
-
algebraixlib.algebras.properties.
is_bijective
(mo: algebraixlib.mathobjects.mathobject.MathObject, _checked: bool=True) → bool[source]¶ Return whether
mo
is bijective orUndef()
if not applicable.Is implemented for relations, clans, multiclans and sets of (sets of ...) clans. Is also defined (but not yet implemented) for any combination of sets or multisets of relations.
-
algebraixlib.algebras.properties.
is_reflexive
(mo: algebraixlib.mathobjects.mathobject.MathObject, _checked: bool=True) → bool[source]¶ Return whether
mo
is reflexive orUndef()
if not applicable.Is implemented for couplets, relations, clans, multiclans and sets of (sets of ...) clans. Is also defined (but not yet implemented) for any combination of sets or multisets of relations.
-
algebraixlib.algebras.properties.
is_symmetric
(mo: algebraixlib.mathobjects.mathobject.MathObject, _checked: bool=True) → bool[source]¶ Return whether
mo
is symmetric orUndef()
if not applicable.Is implemented for relations, clans, multiclans and sets of (sets of ...) clans. Is also defined (but not yet implemented) for any combination of sets or multisets of relations.
-
algebraixlib.algebras.properties.
is_transitive
(mo: algebraixlib.mathobjects.mathobject.MathObject, _checked: bool=True) → bool[source]¶ Return whether
mo
is transitive orUndef()
if not applicable.Is implemented for relations, clans, multiclans and sets of (sets of ...) clans. Is also defined (but not yet implemented) for any combination of sets or multisets of relations.
-
algebraixlib.algebras.properties.
is_equivalence_relation
(mo: algebraixlib.mathobjects.mathobject.MathObject, _checked: bool=True) → bool[source]¶ Return whether
mo
is an equivalence relation orUndef()
if not applicable.Is implemented for relations, clans, multiclans and sets of (sets of ...) clans. Is also defined (but not yet implemented) for any combination of sets or multisets of relations.
-
algebraixlib.algebras.properties.
is_regular
(mo: algebraixlib.mathobjects.mathobject.MathObject, _checked: bool=True) → bool[source]¶ Return whether
mo
is regular orUndef()
if not applicable.Is implemented for clans, multiclans and sets of (sets of ...) clans. Is also defined (but not yet implemented) for any combination of sets or multisets of clans.
-
algebraixlib.algebras.properties.
is_right_regular
(mo: algebraixlib.mathobjects.mathobject.MathObject, _checked: bool=True) → bool[source]¶ Return whether
mo
is right-regular orUndef()
if not applicable.Is implemented for clans, multiclans and sets of (sets of ...) clans. Is also defined (but not yet implemented) for any combination of sets or multisets of clans.
This module contains the algebra of relations and related functionality.
A relation is also a set (of couplets), and inherits all operations
of the algebra of sets. These are provided in sets
.
-
class
algebraixlib.algebras.relations.
Algebra
[source]¶ Bases:
object
Provide the operations and relations that are members of the algebra of relations.
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 relations. All member functions are also available at the enclosing module scope.
-
static
transpose
(rel: 'P(M x M)', _checked=True) → 'P(M x M)'[source]¶ Return a relation where all couplets have their left and right components swapped.
Returns: The unary extension of transposition from the algebra of couplets to the algebra of relations, applied to the relation rel
, orUndef()
ifrel
is not a relation.
-
static
compose
(rel1: 'P(M x M)', rel2: 'P(M x M)', _checked=True) → 'P(M x M)'[source]¶ Return the composition of
rel1
withrel2
.Returns: The binary extension of composition from the algebra of couplets to the algebra of relations, applied to the relations rel1
andrel2
, orUndef()
ifrel1
orrel2
are not relations.
-
static
functional_union
(rel1: 'P(M x M)', rel2: 'P(M x M)', _checked=True) → 'P(M x M)'[source]¶ Return the union of
rel1
andrel2
if it is a function, otherwiseUndef()
.Returns: The functional union of the relations rel1
andrel2
; that is, the union if the result is a function, otherwiseUndef()
. Also returnUndef()
ifrel1
orrel2
are not relations.
-
static
right_functional_union
(rel1: 'P(M x M)', rel2: 'P(M x M)', _checked=True) → 'P(M x M)'[source]¶ Return the union of
rel1
andrel2
if it is right-functional, otherwiseUndef()
.Returns: The right-functional union of the relations rel1
andrel2
; that is, the union if the result is right-functional, otherwiseUndef()
. Also returnUndef()
ifrel1
orrel2
are not relations.
-
static
-
algebraixlib.algebras.relations.
transpose
(rel: 'P(M x M)', _checked=True) → 'P(M x M)'¶ Convenience redirection to
Algebra.transpose
.
-
algebraixlib.algebras.relations.
compose
(rel1: 'P(M x M)', rel2: 'P(M x M)', _checked=True) → 'P(M x M)'¶ Convenience redirection to
Algebra.compose
.
-
algebraixlib.algebras.relations.
functional_union
(rel1: 'P(M x M)', rel2: 'P(M x M)', _checked=True) → 'P(M x M)'¶ Convenience redirection to
Algebra.functional_union
.
-
algebraixlib.algebras.relations.
right_functional_union
(rel1: 'P(M x M)', rel2: 'P(M x M)', _checked=True) → 'P(M x M)'¶ Convenience redirection to
Algebra.right_functional_union
.
-
algebraixlib.algebras.relations.
get_name
() → str[source]¶ Return the name and ground set of this algebra in string form.
-
algebraixlib.algebras.relations.
get_ground_set
() → algebraixlib.structure.Structure[source]¶ Return the ground set of this algebra.
-
algebraixlib.algebras.relations.
get_absolute_ground_set
() → algebraixlib.structure.Structure[source]¶ Return the absolute ground set of this algebra.
-
algebraixlib.algebras.relations.
is_member
(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]¶ Return whether
obj
is a member of the ground set of this algebra.return: True
ifobj
is a relation,False
if not.Note
This function may call
get_ground_set()
onobj
. The result of this operation is cached.
-
algebraixlib.algebras.relations.
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.relations.
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 relation,False
if not.Note
This function may call
get_ground_set()
onobj
. The result of this operation is cached.
-
algebraixlib.algebras.relations.
get_lefts
(rel: 'P(M x M)', _checked=True) → 'P( M )'[source]¶ Return the set of the left components of all couplets in the relation
rel
.Returns: The left set of the relation rel
orUndef()
ifrel
is not a relation.
-
algebraixlib.algebras.relations.
get_rights
(rel: 'P(M x M)', _checked=True) → 'P( M )'[source]¶ Return the set of the right components of all couplets in the relation
rel
.Returns: The right set of the relation rel
orUndef()
ifrel
is not a relation.
-
algebraixlib.algebras.relations.
get_rights_for_left
(rel: 'P(M x M)', left: '( M )', _checked=True) → 'P( M )'[source]¶ Return the set of the right components of all couplets in the relation
rel
associated with the left componentleft
.Returns: The right set of the relation rel
associated with the left component orUndef()
ifrel
is not a relation.
-
algebraixlib.algebras.relations.
get_right
(rel: 'P(M x M)', left: '( M )', _checked=True) → '( M )'[source]¶ Return the right component of the couplet that has a left component of
left
.In general, use with functions; that is, relations where all left components appear at most once.
Returns: The right component of the couplet that has a left component of left
, orUndef()
if there is not exactly one couplet with the left componentleft
inrel
orrel
is not a relation.
-
algebraixlib.algebras.relations.
get_left
(rel: 'P(M x M)', right: '( M )', _checked=True) → '( M )'[source]¶ Return the left component of the couplet that has a right component of
right
.In general, use with right-functional relations; that is, relations where all right components appear at most once.
Returns: The left component of the couplet that has a right component of right
, orUndef()
if there is not exactly one couplet with the right componentright
inrel
orrel
is not a relation.
-
algebraixlib.algebras.relations.
is_functional
(rel, _checked=True) → bool[source]¶ Return whether
rel
is left-functional (is a function).Returns: True
ifrel
is a function,False
if not, orUndef()
ifrel
is not a relation.
-
algebraixlib.algebras.relations.
is_right_functional
(rel, _checked=True) → bool[source]¶ Return whether
rel
is right-functional.Returns: True
ifrel
is right-functional,False
if not, orUndef()
ifrel
is not a relation.
-
algebraixlib.algebras.relations.
is_reflexive
(rel, _checked=True) → bool[source]¶ Return whether
rel
is reflexive.Returns: True
ifrel
is reflexive,False
if it is not, orUndef()
ifrel
is not a relation.
-
algebraixlib.algebras.relations.
is_symmetric
(rel, _checked=True) → bool[source]¶ Return whether
rel
is symmetric.Returns: True
ifrel
is symmetric,False
if it is not, orUndef()
ifrel
is not a relation.
-
algebraixlib.algebras.relations.
is_transitive
(rel, _checked=True) → bool[source]¶ Return whether
rel
is transitive.Returns: True
ifrel
is transitive,False
if it is not, orUndef()
ifrel
is not a relation.
-
algebraixlib.algebras.relations.
fill_lefts
(rel: 'P(M x M)', renames: 'P(M x M)', _checked=True) → 'P(M x M)'[source]¶ Return the left components in
rel
that are missing inrenames
as a diagonal unioned withrenames
.The purpose is to create a relation that can be used with the composition operation to change (rename) one or more left components and leave the rest alone.
Parameters: - rel – The relation that provides the full left set.
- renames – A relation where the right components are meant to be composition ‘origins’ and the left components composition ‘targets’.
Returns: A relation that contains all members of
renames
unioned with a diagonal that consists of all left components inrel
that are missing inrenames
.
-
algebraixlib.algebras.relations.
rename
(rel: 'P(M x M)', renames: 'P(M x M)', _checked=True) → 'P(M x M)'[source]¶ Return a relation where left components in
rel
are renamed according torenames
.Parameters: - rel – The relation with the left components to rename.
- renames – A relation where the right components are the current left components
in
rel
and the left components are the new left components to use inrel
.
Returns: A version of
rel
where some left components of the member couplets are changed (renamed), according torenames
.
-
algebraixlib.algebras.relations.
swap
(rel: 'P(M x M)', swaps: 'P(M x M)', _checked=True) → 'P(M x M)'[source]¶ Return a relation where components in
rel
are swapped according toswaps
.Parameters: - rel – The relation with the left components to swap.
- swaps – A relation where both right components and left components are current
left components in
rel
. These left components are swapped.
Returns: A version of
rel
where some left components of the member couplets are swapped, according toswaps
.
-
algebraixlib.algebras.relations.
functional_add
(func: 'P(M x M)', element: 'M x M') → 'P(M x M)'[source]¶ Add
element
tofunc
and return the new functional relation.Parameters: - func – The source data. Must be a function. It must not contain a couplet
with the same left component as
element
. - element – The element to be added to
func
. Must be aCouplet
and its left component must not be a left component infunc
.
Returns: The new relation, composed of
func
andelement
.- func – The source data. Must be a function. It must not contain a couplet
with the same left component as
-
algebraixlib.algebras.relations.
from_dict
(dict1: dict) → 'P(M x M)'[source]¶ Return a relation where the couplets are the elements of
dict1
.
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 superset 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 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
(set_: 'P( M )', _checked=True) → 'P( M x N )'[source]¶ Return a multiset based on
set_
where all multiples are set to 1.
-
algebraixlib.algebras.sets.
big_union
(set_: 'PP( M )', _checked=True) → 'P( M )'[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
(set_: 'PP( M )', _checked=True) → 'P( M )'[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
(set_: 'P( M )', selector: collections.abc.Callable) → 'P( M )'[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
.
algebraixlib.io package¶
This package contains modules with facilities for importing and exporting data.
Supported formats are:
csv
: Export regular clans as CSV data and import CSV data into clans.json
: Import hierarchical JSON data into nested relations.mojson
: Export constructs that containMathObject
s to JSON and import that data. This format is guaranteed to round-trip.rdf
: Import RDF graphs in the formats N-Triples and Turtle. Export tabular results as RDF-CSV and RDF-JSON.xml
: Import hierarchical XML data into nested relations.
All these import/export facilities are not meant to be full, standard-compliant implementations. They are rather examples for how these formats can be represented in and converted to data algebra, missing details and features notwithstanding.
Submodules¶
Import regular clans from and export them to CSV data.
-
algebraixlib.io.csv.
export_csv
(absolute_clan_or_multiclan, file_or_path, ordered_lefts=None, sort_key=None)[source]¶ Export an absolute clan or absolute multiclan as CSV file with header row.
The left components of the clan or term:
multiclan
are interpreted as column names and are exported as header row. Every relation in the input becomes a data row in the CSV file.Parameters: - absolute_clan_or_multiclan – An absolute clan or term:
absolute multiclan
. If it is not regular,ordered_lefts
must be given. - file_or_path – Either a file path (in this case the CSV data is written to a file at this
location) or a file object (in this case the CSV data is written to its
.write()
function). - ordered_lefts – (Optional) A
Sequence
of lefts that are exported in the given order. Default is the sequence that is the lexically sorted left set of the (multi)clan. This parameter is required ifabsolute_clan_or_multiclan
is not term:regular
. - sort_key – (Optional) A function that compares two row-relations and provides an
order (for use with
sorted()
). The output is not sorted ifsort_key
is missing.
Returns: True
if the CSV export succeeded,False
if not.- absolute_clan_or_multiclan – An absolute clan or term:
-
algebraixlib.io.csv.
import_csv
(csv_file_or_filepath, types: {}=None, skip_rows: int=0, index_column: str=None, has_dup_rows: bool=False, columns: []=None) → 'PP( A x M )'[source]¶ Import the file
csv_file_or_filepath
as CSV data and return a clan or multiclan.Parameters: - csv_file_or_filepath – The file path or file object (for example
StringIO
buffer) to import. - types – (Optional) A dictionary of type conversions. The keys are the column names; the
values are functors (or types) that receive the string from the CSV cell and return the
value to be imported. Example:
{'foo': int, 'bar': float}
. By default all values are interpreted asstring
s. - skip_rows – (Optional) A number of lines to skip (default 0). Some CSV files have a preamble that can be skipped with this option.
- index_column – (Optional) A name for an index column. (No index column is created if this
argument is not specified.) The index starts with 0. (This option is not compatible with the
has_dup_rows
option.) - has_dup_rows – (Optional) If
True
, allow duplicate rows and return a multiclan instead of a clan. By default, the value isFalse
and a clan is returned. (This option is not compatible with the optionindex_column
.) - columns – (Optional) A list of column names. If present, this list is used as the sequence of columns (and all lines in the data are loaded). If missing, the first line of the data must be a header that contains the column names (and this header line is not loaded as data).
Returns: A clan (if
has_dup_rows is ``False
or not provided) or a multiclan (ifhas_dup_rows
isTrue
).- csv_file_or_filepath – The file path or file object (for example
Import data from JSON.
-
algebraixlib.io.json.
import_json
(json_file_or_filepath) → 'P( A x M )'[source]¶ Import the file
json_file_or_filepath
as JSON file and return nested relations.Parameters: json_file_or_filepath – A file path or a file object of the file to be imported. Returns: A nested relation that represents the JSON document.
Extend json
so that it can convert constructs that contain MathObject
s and a few
other normally not supported types to and from JSON. A lossless round-trip is supported.
Supported types:
- The
MathObject
typesAtom
,Couplet
,Set
andMultiset
. - The Python types
bytes
,complex
,frozenset
,range
. - The Python types
list
andtuple
are already supported by the base implementation, but it can’t distinguish between them. Our implementation can.
-
algebraixlib.io.mojson.
encode
(obj)[source]¶ Encode
obj
as construct of objects known to the JSON encoder or return it as-is. Ifobj
is not known to the JSON encoder, it will fail on it.
-
algebraixlib.io.mojson.
decode
(obj)[source]¶ obj
is a representation of a straightforward translation of JSON into Python. For a known special construct, convert it into its correct object representation and return it. Otherwise returnobj
as-is.
-
algebraixlib.io.mojson.
object_hook_f
(obj)[source]¶ obj
is a representation of a straightforward translation of JSON into Python. For a known special construct (must be adict
), convert it into its correct object representation and return it. Otherwise returnobj
as-is. (May be used asobject_hook
function for the various JSON decoder APIs.)
-
class
algebraixlib.io.mojson.
ExportJson
(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶ Bases:
json.encoder.JSONEncoder
Export a construct that may contain
MathObject
s and other normally not supported types as a custom JSON format that allows a round-trip.Constructor for JSONEncoder, with sensible defaults.
If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, float or None. If skipkeys is True, such items are simply skipped.
If ensure_ascii is true, the output is guaranteed to be str objects with all incoming non-ASCII characters escaped. If ensure_ascii is false, the output can contain non-ASCII characters.
If check_circular is true, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an OverflowError). Otherwise, no such check takes place.
If allow_nan is true, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats.
If sort_keys is true, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis.
If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.
If specified, separators should be an (item_separator, key_separator) tuple. The default is (‘, ‘, ‘: ‘) if indent is
None
and (‘,’, ‘: ‘) otherwise. To get the most compact JSON representation, you should specify (‘,’, ‘:’) to eliminate whitespace.If specified, default is a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a
TypeError
.
-
class
algebraixlib.io.mojson.
ImportJson
(object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None)[source]¶ Bases:
json.decoder.JSONDecoder
Import the JSON format created by
ExportJson
and create an object from it.The arguments are the same as for
_json.JSONDecoder
, except for the ones listed here:Parameters: object_hook – If this argument is not set, the function object_hook_f
is used.
Import and export facilities for RDF data.
-
algebraixlib.io.rdf.
import_graph
(graph_file_or_filepath, rdf_format: str=None) → 'PP(A x A)'[source]¶ Return an absolute clan that represents the RDF graph
graph_file_or_filepath
.- The graph is represented by a regular, absolute clan.
- The left components are ‘s’ (subject), ‘p’ (predicate) and ‘o’ (object) (see triple).
- Blank nodes are converted to IRIs (skolemization).
- URI references are represented as
rdflib.URIRef
instances (embedded in anAtom
). - Literals are converted to intuitive native Python types (embedded in an
Atom
).
Parameters: - graph_file_or_filepath – A string that is a path (relative or absolute) to the file to
be imported, or a file object (like
StringIO
). - rdf_format – The format of the RDF graph that is being imported. See Pluginparsers for a list of supported formats and their corresponding strings. If none is given, the file name’s extension is used to guess a format. If that fails, Turtle is used as default.
Returns: An absolute clan that represents the RDF graph that has been imported.
-
algebraixlib.io.rdf.
export_table
(file_or_path, lefts: 'P( A )', table: 'PP(A x A)', out_format: str='csv')[source]¶ Return a serialized table as string in a supported RDF format for table serialization.
Limitations: - Leading ‘?’ and ‘$’ are not stripped from lefts (variable names). - Non-printable characters are backslash-escaped. -
table
must be an absolute graph.Parameters: - file_or_path – Either a file path (in this case the data is written to a file at this
location) or a file object (in this case the data is written to its
.write()
function). - lefts – The set of the left components in
table
that is exported. - table – An absolute clan that contains the data to be exported.
- out_format – A supported RDF table format. Supported are
'csv'
(SPARQL 1.1 Query Results CSV and TSV Formats) and'json'
(SPARQL 1.1 Query Results JSON Format).
- file_or_path – Either a file path (in this case the data is written to a file at this
location) or a file object (in this case the data is written to its
Import data from XML.
-
algebraixlib.io.xml.
import_xml
(xml_file_or_filepath, convert_numerics: bool=False) → 'P( A x M )'[source]¶ Import the file
xml_file_or_filepath
as XML file and return nested relations.Parameters: - xml_file_or_filepath – A file path or a file object of the file to be imported.
- convert_numerics – If
True
, numeric values (integers, floating-point numbers) are imported as number types. IfFalse
(default), everything is imported as string.
Returns: A nested relation starting with a relation that contains a single couplet that represents the single XML root element.
-
algebraixlib.io.xml.
xml_to_str
(xml_file_or_filepath, indent_text=' ', truncate=True, max_line_len=95, pre_len=0, post_len=0)[source]¶ Return an XML file or string into a consistently formatted XML string.
Parameters: - xml_file_or_filepath – A file path or a file object to be converted.
- indent_text – A string of characters used as indent.
- truncate – When
True
, truncate converted text usingmax_line_len
. - max_line_len – The maximum number of characters per line when truncation is used.
- pre_len – The maximum length, in characters, the first part of the converted string is
allowed to be. (The part between
pre_len
andpost_len
is replaced with a line that contains an ellipsis.) Ignored if 0 or ifpost_len
is 0. - post_len – The maximum length, in characters, the last part of the converted string is
allowed to be. (The part between
pre_len
andpost_len
is replaced with a line that contains an ellipsis.) Ignored if 0 or ifpre_len
is 0.
algebraixlib.mathobjects package¶
This package contains the modules that define the classes that represent data.
The modules that contain classes that represent data are:
mathobject
: Contains the abstract base classMathObject
. It is the base class of all other data classes and can’t be instantiated.It also provides the utility functions
raise_if_not_mathobject()
andraise_if_not_mathobjects()
that raise aTypeError
if the argument is not an instance ofMathObject
(resp. is not a collection of such instances).atom
: Contains the classAtom
. Instances of this class represent atoms; that is, values of non-math objects, like numbers, strings or any immutable Python value. All instances ofAtom
are members of set A (\(A\)), or conversely, set A is the set of all instances ofAtom
.It also provides the utility function
auto_convert()
that makes sure that its argument is always an instance ofMathObject
; if it isn’t, it converts it into anAtom
.couplet
: Contains the classCouplet
that represents a couplet.multiset
: Contains the classMultiset
that represents a multiset.utils
: Provides various utilities for the other modules in this package.
In addition to the modules with classes that represent data, there is a private module
_flags
. It contains the class _flags.Flags
that provides a mechanism to cache
certain properties of MathObject
s. It is used by property accessors like
cached_relation
and is not meant to be used by itself. (See also
[PropCache].)
All module-level symbols (functions and classes, except _flags.Flags
) are exposed at the
package level, so if you import mathobjects
(the package), these module-level symbols are
imported. (Similarly, from mathobjects import ...
can be used to import individual symbols
from the package.)
Submodules¶
Provide the class Atom
that represents atoms and the function
auto_convert()
that passes through instances of MathObject
s and converts other types into
Atom
instances.
-
algebraixlib.mathobjects.atom.
auto_convert
(arg)[source]¶ Return always a
MathObject
. Ifarg
is not aMathObject
, make it anAtom
.This function is used in several constructors as convenience wrapper to allow the creation of
MathObject
instances from non-MathObject
values.
-
class
algebraixlib.mathobjects.atom.
Atom
(value, direct_load=False)[source]¶ Bases:
algebraixlib.mathobjects.mathobject.MathObject
Represent a value (of a non-
MathObject
, hashable type) like numbers or strings.All instances of
Atom
are members of set A (\(A\)), or conversely, set A is the set of all instances ofAtom
.Note
Instances of
Atom
are immutable and hashable. Therefore they only accept immutable and hashable values.Parameters: - value – The value of this instance. May not be an instance of
MathObject
other thanAtom
. (If it is of typeAtom
, the instance is re-used; see__new__
.)value
must be immutable and hashable. - direct_load – Set to
True
if you can be sure thatvalue
is not an instance ofMathObject
. Default isFalse
.
Raise: TypeError
ifvalue
is not hashable.-
static
__new__
(value, direct_load=False)[source]¶ If
value
is an instance ofAtom
, reuse it.This mechanism is used to reduce the number of created
Atom
instances. We then need to check in__init__
whether we have an already initialized instance or still have to initialize it.__init__
is always called after__new__
.Returns: value
if it is an instance ofAtom
(in this case we simply reuse it). If not, follow the normal path for creating an instance.
-
type
¶ Read-only; return the type of this instance.
-
get_ground_set
() → algebraixlib.structure.Structure[source]¶ Return the ground set of the lowest-level algebra of
self
. Is always \(A\).
-
__eq__
(other)[source]¶ A value-based comparison for equality. Return
True
if types and values match.Type-matching follows Python rules, so
not Atom(1) == Atom(1.0)
.
- value – The value of this instance. May not be an instance of
Provide the class Couplet
; it represents a couplet.
-
algebraixlib.mathobjects.couplet.
make_couplet_unchecked
(*args)[source]¶ Factory wrapper to create a
Couplet
(unchecked version).
-
class
algebraixlib.mathobjects.couplet.
Couplet
(left, right=None, direct_load=False)[source]¶ Bases:
algebraixlib.mathobjects.mathobject.MathObject
A couplet containing a left component and a right component.
Parameters: - left – The left component of the couplet, and the default value for the
right component (see
right
). If this argument is not aMathObject
, it is converted into anAtom
. - right – (Optional) The right component of the couplet. If this argument is
not a
MathObject
, it is converted into anAtom
. If this argument is missing, the value ofleft
is used and a reflexive couplet where left and right are the same is created. - direct_load – (Optional) Set to
True
if you know that bothleft
andright
are instances ofMathObject
.
-
left
¶ Read-only property; return the left component of this instance.
-
right
¶ Read-only property; return the right component of this instance.
-
get_ground_set
() → algebraixlib.structure.Structure[source]¶ Return the ground set of the lowest-level algebra of
self
.
-
__eq__
(other)[source]¶ A value-based comparison for equality. Return
True
if type and both members match.
- left – The left component of the couplet, and the default value for the
right component (see
This module contains the abstract base class for all classes that represent data.
The class MathObject
is the base class of all other data classes and can’t be
instantiated.
This module also provides the utility functions raise_if_not_mathobject()
and
raise_if_not_mathobjects()
that raise a TypeError
if the argument is not an instance
of MathObject
(resp. is not a collection of such instances).
-
algebraixlib.mathobjects.mathobject.
raise_if_not_mathobject
(obj)[source]¶ Raise a
TypeError
exception ifobj
is not an instance ofMathObject
.
-
algebraixlib.mathobjects.mathobject.
raise_if_not_mathobjects
(*objs)[source]¶ Raise a
TypeError
exception if any member ofobjs
is not aMathObject
.
-
algebraixlib.mathobjects.mathobject.
is_mathobject_or_undef
(obj)[source]¶ Return
True
ifobj
is an instance ofMathObject
orUndef()
elseFalse
.
-
class
algebraixlib.mathobjects.mathobject.
MathObject
(cached_flags: int=0)[source]¶ Bases:
abc.ABC
An abstract base class (see the base class
abc.ABC
) for all classes that represent data.This class uses
_flags.Flags
to cache a number of properties of all data classes. See also [PropCache].Note
This class can’t be instantiated. Only derived classes that implement all abstract methods can be instantiated. Since derived classes are expected to be hashable, they must be immutable.
[PropCache] (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45) Several Boolean properties are automatically cached when first requested. For this we use a caching mechanism based on the class
_flags.Flags
that provides a 2-bit field for each Boolean property, with the statesUNKNOWN
,IS
,IS_NOT
andN_A
(seeCacheStatus
). Some of these properties are set during the constructors of the classes derived fromMathObject
, others are set when a givenMathObject
is created by an operation. They also may be set by user code when a property’s state is known due to the characteristics of theMathObject
.In the
MathObject
s, most cached properties are represented by two accessors that use the following naming convention (for a property with name<property>
):cached_<property>
: Return the current cached state (may beUNKNOWN
). This is a Python property accessor, so parentheses are not needed when querying the state.cache_<property>
: Set the value of the cached state. Note that the only state that may be changed isUNKNOWN
; all others cannot be changed once set. (Setting it again to the same value is unnecessary but not an error.)
Several properties have also convenience accessors of the following forms:
cached_is_<property>
: Means “is known to be <property>”.cached_is_not_<property>
: Means “is known not to be <property>”.
(Keep in mind that while these two accessors never return
True
for both, they may returnFalse
for both. This happens if the property’s state is unknown or if it doesn’t apply to the given object. Only use them for questions of the “is known (not) to be ...” variety.)Then there are four special cases:
is_atom
,is_couplet
,is_multiset
andis_set
. All these properties are always eitherTrue
orFalse
and they are set during object construction and never can be set again. Therefore, for these four properties, all we have are these Boolean read accessors.Note
The serialized values of the structure where these bits are stored depends on the system’s byte order (endianness). Without specific measures, serialized data can’t be exchanged between systems with different byte order.
-
is_empty
¶ Return
True
if thisMathObject
is empty,False
if not.Returns: Always False
unless overridden by a derived class.
-
get_ground_set
() → algebraixlib.structure.Structure[source]¶ Return the ground set of the lowest-level algebra of this
MathObject
.
-
__call__
(*args, **kwargs) → '( M )'[source]¶ With the syntax
mo(left)
, return the right associated withleft
.Parameters: - args – Exactly one argument is expected; it is the left component of the couplet of which the right component is returned.
- kwargs – Named arguments are not supported. It is part of the function signature.
Returns: If
self
is a function, return the right component of the couplet that has as left component the single argument if one exists; returnUndef()
if no couplet with the given left exists. Also returnUndef()
ifself
is not a function.
-
__getitem__
(left) → 'P( M )'[source]¶ With the syntax
mo[left]
, return a set of rights associated withleft
.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 that matchesleft
. (This set may be empty if no couplet with the given left exists.) ReturnUndef()
ifself
is not a relation.
-
__hash__
() → int[source]¶ Return a hash based on the member values (must match the implementation of
__eq__
).Note
The fact that we calculate a hash of an instance requires that instances of classes derived from this class are immutable (see also Immutable Sequence Types) and all its contained elements hashable (see also object.__hash__).
-
cached_relation
¶ Return the cached state of being a relation. See [PropCache].
-
cached_is_relation
¶ Return
True
ifself
is known to be a relation. See [PropCache].
-
cached_is_not_relation
¶ Return
True
ifself
is known not to be a relation. See [PropCache].
-
cache_relation
(value: int)[source]¶ Set the cached state of being a relation. See [PropCache].
-
cached_clan
¶ Return the cached state of being a clan. See [PropCache].
-
cached_is_clan
¶ Return
True
ifself
is known to be a clan. See [PropCache].
-
cached_is_not_clan
¶ Return
True
ifself
is known not to be a clan. See [PropCache].
-
cache_clan
(value: int)[source]¶ Set the cached state of being a clan. See [PropCache].
-
cached_multiclan
¶ Return the cached state of being a multiclan. See [PropCache].
-
cached_is_multiclan
¶ Return
True
ifself
is known to be a multiclan. See [PropCache].
-
cached_is_not_multiclan
¶ Return
True
ifself
is known not to be a multiclan. See [PropCache].
-
cache_multiclan
(value: int)[source]¶ Set the cached state of being a multiclan. See [PropCache].
-
cached_absolute
¶ Return the cached state of being absolute. See [PropCache].
-
cached_is_absolute
¶ Return
True
ifself
is known to be absolute. See [PropCache].
-
cached_is_not_absolute
¶ Return
True
ifself
is known not to be absolute. See [PropCache].
-
cache_absolute
(value: int)[source]¶ Set the cached state of being absolute. See [PropCache].
-
cached_functional
¶ Return the cached state of being functional. See [PropCache].
-
cached_is_functional
¶ Return
True
ifself
is known to be functional. See [PropCache].
-
cached_is_not_functional
¶ Return
True
ifself
is known not to be functional. See [PropCache].
-
cache_functional
(value: int)[source]¶ Set the cached state of being functional. See [PropCache].
-
cached_right_functional
¶ Return the cached state of being right-functional. See [PropCache].
-
cached_is_right_functional
¶ Return
True
ifself
is known to be right-functional. See [PropCache].
-
cached_is_not_right_functional
¶ Return
True
ifself
is known not to be right-functional. See [PropCache].
-
cache_right_functional
(value: int)[source]¶ Set the cached state of being right-functional. See [PropCache].
-
cached_reflexive
¶ Return the cached state of being reflexive. See [PropCache].
-
cached_is_reflexive
¶ Return
True
ifself
is known to be reflexive. See [PropCache].
-
cached_is_not_reflexive
¶ Return
True
ifself
is known not to be reflexive. See [PropCache].
-
cache_reflexive
(value: int)[source]¶ Set the cached state of being reflexive. See [PropCache].
-
cached_symmetric
¶ Return the cached state of being symmetric. See [PropCache].
-
cached_is_symmetric
¶ Return
True
ifself
is known to be symmetric. See [PropCache].
-
cached_is_not_symmetric
¶ Return
True
ifself
is known not to be symmetric. See [PropCache].
-
cache_symmetric
(value: int)[source]¶ Set the cached state of being symmetric. See [PropCache].
-
cached_transitive
¶ Return the cached state of being transitive. See [PropCache].
-
cached_is_transitive
¶ Return
True
ifself
is known to be transitive. See [PropCache].
-
cached_is_not_transitive
¶ Return
True
ifself
is known not to be transitive. See [PropCache].
-
cache_transitive
(value: int)[source]¶ Set the cached state of being transitive. See [PropCache].
-
cached_regular
¶ Return the cached state of being regular. See [PropCache].
-
cached_is_regular
¶ Return
True
ifself
is known to be regular. See [PropCache].
-
cached_is_not_regular
¶ Return
True
ifself
is known not to be regular. See [PropCache].
-
cache_regular
(value: int)[source]¶ Set the cached state of being regular. See [PropCache].
-
cached_right_regular
¶ Return the cached state of being right-regular. See [PropCache].
-
cached_is_right_regular
¶ Return
True
ifself
is known to be right-regular. See [PropCache].
-
cached_is_not_right_regular
¶ Return
True
ifself
is known not to be right-regular. See [PropCache].
-
cache_right_regular
(value: int)[source]¶ Set the cached state of being right-regular. See [PropCache].
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.Parameters: - 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 typestr
is an iterable, but it is considered a single, non-iterable argument.) Arguments of typeCounter
are loaded directly, and arguments of typedict
must map values or instances ofMathObject
to integers; the integers are interpreted as multiplicity values for the given keys. (In order to create aMultiset
that contains aCounter
ordict
, put theCounter
ordict
in anAtom
or an array first.) - direct_load – (Optional) Set to
True
if you know that all arguments (or all elements of the iterable) are instances ofMathObject
.
-
data
¶ Read-only; return the elements of this instance as a
Counter
ofMathObject
instances.Note
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).
-
has_element
(elem: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]¶ Return whether
elem
is an element of this multiset.elem
must be aMathObject
.For a more relaxed version (that auto-converts non-
MathObject
arguments into instances ofAtom
) see__contains__
and the constructelem in Multiset
.
-
get_multiplicity
(elem: algebraixlib.mathobjects.mathobject.MathObject) → int[source]¶ Return
int
ifelem
is an element of thisMultiset
where the value is the number of multiples forelem
.elem
must be aMathObject
.
-
get_ground_set
() → algebraixlib.structure.Structure[source]¶ Return the ground set of the lowest-level algebra of this
Multiset
.
-
get_left_set
() → 'P( M )'[source]¶ Get the left set for this
Multiset
. ReturnUndef()
if not applicable.Todo
Once multipowersets are fully implemented, see
get_left_set()
.
-
get_right_set
() → 'P( M )'[source]¶ Get the right set for this
Multiset
. ReturnUndef()
if not applicable.Todo
Once multipowersets are fully implemented, see
get_right_set()
.
-
__contains__
(item)[source]¶ Return
True
ifitem
is a member of this multiset. Ifitem
is not aMathObject
, it is converted into anAtom
.This allows Boolean expressions of the form
element in Multiset
.
-
__getitem__
(left)[source]¶ With the syntax
mo[left]
, return a set of rights associated withleft
.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 matchesleft
. (The returned multiset may be empty if no couplet with the given left exists.) ReturnUndef()
ifself
is not a multi-relation.
- args – Zero or more unnamed arguments that are placed into the created
Provide the class Set
; it represents a set.
-
algebraixlib.mathobjects.set.
make_set_unchecked
(*args)[source]¶ 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.Parameters: - 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 typestr
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 ofMathObject
.
-
data
¶ Read-only; return the elements of this instance as a
frozenset
ofMathObject
instances.
-
has_element
(elem: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]¶ Return whether
elem
is an element of this set.elem
must be aMathObject
.For a more relaxed version (that auto-converts non-
MathObject
arguments into instances ofAtom
) see__contains__
and the constructelem in Set
.
-
get_ground_set
() → algebraixlib.structure.Structure[source]¶ Return the ground set of the lowest-level algebra of this
Set
.
-
get_right_set
() → 'P( M )'[source]¶ Get the right set for this
Set
. ReturnUndef()
if not applicable.
-
__ne__
(other)[source]¶ Implement value-based inequality. Return
True
if type or set elements don’t match.
-
__contains__
(item)[source]¶ Return
True
ifitem
is a member of this set. Ifitem
is not aMathObject
, it is converted into anAtom
.This allows Boolean expressions of the form
element in Set
.
-
__call__
(*args, **kwargs) → '( M )'[source]¶ With the syntax
mo(left)
, return the right associated withleft
.Parameters: Returns: If
self
is a function, return the right component of the couplet that has as left the single argument if one exists; returnUndef()
if no couplet with the given left exists. Also returnUndef()
ifself
is not a function.
-
__getitem__
(left) → 'P( M )'[source]¶ With the syntax
mo[left]
, return a set of rights associated withleft
.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 matchesleft
. Ifself
is a clan, return a set that contains the right(s) of all couplets in all relations that have a left component that matchesleft
. (The returned set may be empty if no couplet with the given left exists.) ReturnUndef()
ifself
is neither a relation nor a clan.
- args – Zero or more unnamed arguments that are placed into the created
Various utilities for the mathobjects
package.
-
class
algebraixlib.mathobjects.utils.
CacheStatus
[source]¶ Bases:
object
Provide the 4 states that we use for caching the property values for
MathObject
s.In
_flags.Flags
we provide 2-bit bitfields that store the cached value of properties that are associated with theMathObject
instances. This class provides symbols for the values that we store in these bitfields and functions that work on them.See also [PropCache].
-
UNKNOWN
= 0¶ Value of the 2-bit bitfield if the associated property is unknown. When accessed, it will be evaluated and set to one of the other states. This is the only state that can change. This value is special in that it sets both bits of the 2-bit bitfield to 0. There is logic elsewhere that depends on all bits being 0 meaning ‘all properties are unknown’. This is in alignment with the default state of a structure without any explicit initialization; it seems to be ‘all bits 0’. (We didn’t find documentation that confirms this, but it seems to be the case.)
-
IS
= 1¶ Value of the 2-bit bitfield if the associated property is known to be true. Once a bitfield is set to this state, its value cannot change anymore.
-
IS_NOT
= 2¶ Value of the 2-bit bitfield if the associated property is known to be false. Once a bitfield is set to this state, its value cannot change anymore.
-
N_A
= 3¶ Value of the 2-bit bitfield if the associated property is known to be undefined (that is, it doesn’t apply). For example, functional is not defined for sets of atoms. Once a bitfield is set to this state, its value cannot change anymore. (The name
N_A
has been chosen instead ofUNDEFINED
to avoid confusion withUNKNOWN
and to simplify working with IDEs.)
-
algebraixlib.util package¶
This package contains utility modules:
html
: PresentMathObject
s as HTML pages.latexprinter
: PresentMathObject
s as LaTeX markup.miscellaneous
: Miscellaneous utility functions and classes.rdf
: RDF-specific data manipulation facilities.test
: Test utilities.
Submodules¶
Utilities that present MathObject
s as HTML pages.
-
class
algebraixlib.util.html.
DataAlgebraHtmlDescriptor
(input_title, data_algebra_construct, description_brief)¶ Bases:
tuple
Named
tuple
for collecting information about aMathObject
. It contains: -input_title
: (Optional) A string that can serve as a name, origin expression or title. -data_algebra_construct
: TheMathObject
or container ofMathObject
s. -description_brief
: (Optional) A string to display more detail.-
static
__new__
(_cls, input_title, data_algebra_construct, description_brief)¶ Create new instance of DataAlgebraHtmlDescriptor(input_title, data_algebra_construct, description_brief)
-
__repr__
()¶ Return a nicely formatted representation string
-
data_algebra_construct
¶ Alias for field number 1
-
description_brief
¶ Alias for field number 2
-
input_title
¶ Alias for field number 0
-
static
-
algebraixlib.util.html.
math_object_as_html
(title: str, data_algebra_html_descriptors: [], header_template: str=None, footer_template: str=None, mathobject_template: str=None) → str[source]¶ Return the contents of an HTML webpage representing a
MathObject
, using templates.Parameters: - title – The title for this page of
MathObject
s. - data_algebra_html_descriptors – An array of
DataAlgebraHtmlDescriptor
instances (containing math objects and their related descriptive strings). - header_template – HTML markup that starts the webpage. May contain the template variable
page_title
; it is set to the value oftitle
. - footer_template – HTML markup that ends the page.
- mathobject_template – The HTML markup that is emited for each math object. May contain
the template variables
input_title
,description_brief
anddata_algebra_construct
, which are replaced with the respective values in the associatedDataAlgebraHtmlDescriptor
.
- title – The title for this page of
-
algebraixlib.util.html.
as_html_handle_basic_parameter
(html_input: str) → str[source]¶ Return the string of
html_input
, properly escaped for using it in HTML.
-
algebraixlib.util.html.
as_html_handle_data_algebra
(mathobj)[source]¶ Return
mathobj
converted into a string safe to be used in HTML.- If
mathobj
is aMathObject
, it will be represented as LaTeX markup and wrapped in the mathjax escape token. - If it is a container of
MathObject
s, then each one will be represented as LaTeX markup and displayed on its own line. - If it is not a
MathObject
then thestr
function will be invoked.
- If
-
algebraixlib.util.html.
build_descriptors_from_math_obj
(mathobjects)[source]¶ Return an array of simple
DataAlgebraHtmlDescriptor
of the objects inmathobjects
.Parameters: mathobjects – List of objects from which to create descriptors.
-
algebraixlib.util.html.
create_simple_web_page
(mathobj: algebraixlib.mathobjects.mathobject.MathObject) → str[source]¶ Return an HTML string for a simple HTML page from a single
MathObject
.
Conversion utilities that present a MathObject
as LaTeX markup.
The main entry point is the function math_object_to_latex
; it delegates to the appropriate
conversion function according to the argument type.
-
class
algebraixlib.util.latexprinter.
Config
[source]¶ Bases:
object
A static class with module configuration values.
-
colorize_output
= True¶ If
True
, add colors to the output. IfFalse
, print black only.
-
short_atom_len
= 10¶ Number of characters to print for ‘short’ length of
Atom
values. The remainder of the elements is represented by an ellipsis (‘...’). Seemath_object_to_latex
andiprint_latex
.
-
short_set_len
= 4¶ Number of elements to print for ‘short’ length of
Set
s andMultiset
s. The remainder of the elements is represented by an ellipsis, followed by the number of not shown elements in parentheses (for example ‘... (15)’). Seemath_object_to_latex
andiprint_latex
.
-
-
algebraixlib.util.latexprinter.
math_object_to_latex
(mobj, short: bool=False, _depth: int=0)[source]¶ Return a
string
that represents aMathObject
onUndef()
in LaTeX markup.This function sorts the input
mobj
if it is aSet
or aMultiset
to make the output consistent, so be careful with big (multi)sets. (Such large (multi)sets where this is a problem may not be suitable to display in LaTeX anyway.)Parameters: - mobj – The instance that you want to translate into LaTeX. It must be a
MathObject
orUndef()
. - short – (Optional) When set to
True
, a short version of the content is generated. Longer parts are abbreviated with ellipses (‘...’). Defaults toFalse
. See alsoConfig.short_atom_len
andConfig.short_set_len
. - _depth – (Optional) Internal use only. Indicate levels of nested (multi)sets. Is incremented for every nesting level. Default is 0.
- mobj – The instance that you want to translate into LaTeX. It must be a
-
algebraixlib.util.latexprinter.
iprint_latex
(variable_name: str, variable_value=None, short: bool=False)[source]¶ Display variables in IPython notebooks using LaTeX markup. Uses
math_object_to_latex
.This function sorts the input
mobj
if it is aSet
or aMultiset
to make the output consistent, so be careful with big (multi)sets. (Such large (multi)sets where this is a problem may not be suitable to display in LaTeX anyway.)Parameters: - variable_name – The name of the variable to display.
- variable_value – (Optional) The value of the variable. If it is missing, the variable
value is fetched from the caller’s frame; a variable with the name
variable_name
is assumed to exist in this case. - short – (Optional) When set to
True
, a short version of the content is generated. Longer parts are abbreviated with ellipses (‘...’). Defaults toFalse
. See alsoConfig.short_atom_len
andConfig.short_set_len
.
Note
This function imports from
IPython
and expects IPython to be installed. This is generally given when running in an IPython notebook.
-
algebraixlib.util.latexprinter.
atom_to_latex
(atom: algebraixlib.mathobjects.atom.Atom, short: bool=False)[source]¶ Return a
string
that represents the value of an Atom in LaTeX markup.Parameters: - atom – The
Atom
to be represented in LaTeX markup. - short – (Optional) When set to
True
, a short version of the content is generated. Longer parts are abbreviated with ellipses (‘...’). Defaults toFalse
. See alsoConfig.short_atom_len
.
- atom – The
-
algebraixlib.util.latexprinter.
couplet_to_latex
(couplet: algebraixlib.mathobjects.couplet.Couplet, short: bool=False)[source]¶ Return a
string
that represents a Couplet in LaTeX markup.Parameters: - couplet – The
Couplet
to be represented in LaTeX markup. - short – (Optional) When set to
True
, a short version of the content is generated. Longer parts are abbreviated with ellipses (‘...’). Defaults toFalse
. See alsoConfig.short_atom_len
andConfig.short_set_len
. (Even though this doesn’t affect aCouplet
directly, it may affect the left and right components of it.)
- couplet – The
-
algebraixlib.util.latexprinter.
set_to_latex
(set_: algebraixlib.mathobjects.set.Set, short: bool=False, _depth: int=0)[source]¶ Return a
string
that represents a Set in LaTeX markup.This function sorts the input
set_
to make the output consistent, so be careful with big sets. (Such large sets where this is a problem may not be suitable to display in LaTeX anyway.)Parameters: - set – The
Set
to be represented in LaTeX markup. - short – (Optional) When set to
True
, a short version of the content is generated. Longer parts are abbreviated with ellipses (‘...’). Defaults toFalse
. See alsoConfig.short_set_len
. - _depth – (Optional) Internal use only. Indicate levels of nested (multi)sets. Is incremented for every nesting level. Default is 0.
- set – The
-
algebraixlib.util.latexprinter.
mset_to_latex
(mset: algebraixlib.mathobjects.multiset.Multiset, short: bool=False, _depth: int=0)[source]¶ Return a
string
that represents a Multiset in LaTeX markup.This function sorts the input
mset
to make the output consistent, so be careful with big sets. (Such large multisets where this is a problem may not be suitable to display in LaTeX anyway.)Parameters: - mset – The
Multiset
to be represented in LaTeX markup. - short – (Optional) When set to
True
, a short version of the content is generated. Longer parts are abbreviated with ellipses (‘...’). Defaults toFalse
. See alsoConfig.short_set_len
. - _depth – (Optional) Internal use only. Indicate levels of nested (multi)sets. Is incremented for every nesting level. Default is 0.
- mset – The
Pretty-printing of MathObject
s.
-
algebraixlib.util.mathobjectprinter.
mo_to_str
(math_object: algebraixlib.mathobjects.mathobject.MathObject, abbreviated=False, indent_text=' ', indent='', max_line_len=95)[source]¶ Return the contents of the
MathObject
math_object
as a readable string.Parameters: - abbreviated – If
False
spell outMathObject
names; ifTrue
use shorter symbols. - indent_text – The string used when indenting.
- indent – The accumulated indent that is increased using
indent_text
during recursive calls. - max_line_len – The maximum number of characters per line. Longer lines are truncated.
- abbreviated – If
Miscellaneous utility functions and classes.
-
algebraixlib.util.miscellaneous.
get_full_class_name
(obj: object) → str[source]¶ Get the fully qualified name of a class.
Parameters: obj – An object. Returns: The class name of obj
, fully qualified with package and module name(s).
-
algebraixlib.util.miscellaneous.
get_hash
(*args) → int[source]¶ Create a hash of the arguments.
Parameters: args – Any number of arguments. Returns: A hash of args
. The hash is an integer with the width of hashes on the system.
-
algebraixlib.util.miscellaneous.
get_single_iter_elem
(iterable)[source]¶ Get the single element of
iterable
.Parameters: iterable – An iterable that is expected to have a single element. Returns: The single element of iterable
. (Assert if there isn’t exactly one element.)Raise: StopIteration
ifiterable
doesn’t contain at least one element;TypeError
ifiterable
isn’t iterable.
-
algebraixlib.util.miscellaneous.
get_variable
(variable_name: str, frames_up: int)[source]¶ Return the variable with name
variable_name
, fromframes_up
frames upwards.Parameters: - variable_name – The name of the variable to retrieve and return.
- frames_up – The number of call stack frames up (relative to the caller of this function).
Returns: The variable with the name
variable_name
,frames_up
frames up.
-
algebraixlib.util.miscellaneous.
open_webpage_from_html_str
(html: str)[source]¶ Open the HTML content string
html
in the system default browser.
-
algebraixlib.util.miscellaneous.
print_var
(variable_name, frames_up: int=0, skip: bool=False, short: bool=False, max_length: int=10000, append: str='', indent=None, indent_first=None)[source]¶ Print a variable, given its name
variable_name
and its location in the call stack.Parameters: - variable_name – The name of the variable to print.
- frames_up – The number of call stacks up (relative to the caller of this function) where
the variable is located. (If the caller wants to print a local variable,
frames_up
can be left at its default of 0.) - skip – Set to
True
to skip printing the variable. Use to control a number of calls toprint_var
with a single variable. - short – Set to
True
to print a short version (only name and len if applicable). - max_length – The maximum length of the string to be printed. Set to
None
if you always want everything. - append – A string that is appended to the generated string.
- indent – Indent all lines with this string. Default is no indent.
- indent_first – Indent first line with this string. Default is the value of
indent
.
-
algebraixlib.util.miscellaneous.
write_to_file_or_path
(file_or_path, data_functor)[source]¶ If
file_or_path
is a string, open a file and calldata_functor
on it. If it is not a string, assume it is a file-like object (with a.write()
function) and calldata_functor
on it.Parameters: - file_or_path – A string or a file-like object (with a .write() function).
- data_functor – A function-like object with one argument that is the writer.
-
class
algebraixlib.util.miscellaneous.
FunctionTimer
(is_function: bool=True, quiet: bool=False, args: []=None, notime: bool=False, walltime: bool=False)[source]¶ Bases:
object
Time a function (and parts of it), with provisions for call hierarchies of functions.
Example code:
from algebraixlib.util.miscellaneous import FunctionTimer def foo(): skip_laps = False # Set to True to skip lap prints. timer1 = FunctionTimer() var1 = 'something' # Do some work. timer1.lap('var1', skip=skip_laps) var2 = 'something else' # Do some more work. timer1.lap('var2', skip=skip_laps) result = 'laboriously calculated' # Do still more work. timer1.end('result') return result timer = FunctionTimer(is_function=False) foo() timer.lap(desc='after first call') foo() timer.lap(desc='after second call')
Store time and caller’s function name, increase indent, print caller’s arguments.
-
lap
(variable_name: str=None, desc: str=None, skip: bool=False, short: bool=False, max_length: int=10000)[source]¶ Print the currently elapsed time and optionally a variable value, properly indented.
Parameters: - variable_name – The name of the variable to be printed. Defaults to
None
. - desc – A description for this lap. Only used if
variable_name
isNone
. - skip – Set to
True
to skip this lap. Defaults toFalse
. - short – Print a short lap result without the full content of
variable_name
. - max_length – Maximal length of print. Defaults to 10000 characters.
- variable_name – The name of the variable to be printed. Defaults to
-
end
(variable_name: str=None, desc: str=None, short: bool=False, max_length: int=10000)[source]¶ Decrease indent, print the elapsed time and optionally a variable value.
Parameters: - variable_name – The name of the variable to be printed. Defaults to
None
. - desc – A description for this lap. Only used if
variable_name
isNone
. - short – Print a short lap result without the full content of
variable_name
. - max_length – Maximal length of print. Defaults to 10000 characters.
- variable_name – The name of the variable to be printed. Defaults to
-
-
algebraixlib.util.miscellaneous.
core
(string: str, begin_len: int=0, end_len: int=0) → str[source]¶ Remove characters in the middle of a string by specifying the length of the beginning of the string and the length of the ending of the string. Ellipses are inserted in place of the core of the string that is being removed.
Parameters: - string – The string to process.
- begin_len – The length, in characters, of the beginning part of the string.
- end_len – The length, in characters, of the ending part of the string.
RDF-specific data manipulation facilities.
The code is RDF/SPARQL-inspired but does not officially implement any RDF standards.
- triple
- A function with three members, with the left components
's'
,'p'
,'o'
. A generic triple is an element of \(P(A \times M)\); an RDF triple is an element of \(P(A \times A)\). (See also set A and set M.) - graph
- A clan where every relation it contains is a triple. A generic graph is an element of \(P^2(A \times M)\); an RDF graph is an element of \(P^2(A \times A)\). (See also set A and set M.)
-
algebraixlib.util.rdf.
is_file_url
(path_or_url: str) → bool[source]¶ Return
True
ifpath_or_url
is a file URL,False
if not.As valid file URL we consider any URL that starts with
'file://'
).
-
algebraixlib.util.rdf.
get_file_url
(path: str) → str[source]¶ Return the file URL that corresponds to the file path
path
.If
path
is relative, it is converted into an absolute path before being converted into a file URL.
-
algebraixlib.util.rdf.
is_triple
(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]¶ Return
True
ifobj
is a validtriple
,False
if not.
-
algebraixlib.util.rdf.
is_absolute_triple
(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]¶
-
algebraixlib.util.rdf.
make_triple
(subject: '( M )', predicate: '( M )', object_: '( M )') → 'P(A x M)'[source]¶ Return an RDF
triple
, created fromsubject
,predicate
andobject_
.Each of the arguments must be an instance of
MathObject
or a Python type that automatically converts to anAtom
in theCouplet
constructor.
-
algebraixlib.util.rdf.
is_graph
(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]¶ Return
True
ifobj
is agraph
,False
if not.
-
algebraixlib.util.rdf.
is_absolute_graph
(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]¶
-
algebraixlib.util.rdf.
triple_match
(rdf_graph: 'PP(A x M)', subject=None, predicate=None, object_=None) → 'PP(A x M)'[source]¶ Evaluate SPARQL-like triple pattern matches.
Treat string values for subject, predicate, object that begin with
'?'
or'$'
similarly to SPARQL variables; they define the projection (output) lefts. Other values are used for matching.Parameters: - rdf_graph – The
graph
on which to operate. - subject – Handle the subjects in
rdf_graph
: a variable name (create output), a value that’s not a variable name (match) orNone
(ignore). - predicate – Handle the predicates in
rdf_graph
: a variable name (create output), a value that’s not a variable name (match) orNone
(ignore). - object – Handle the objects in
rdf_graph
: a variable name (create output), a value that’s not a variable name (match) orNone
(ignore).
Returns: A clan with the matches.
- rdf_graph – The
-
algebraixlib.util.rdf.
join
(rdf_solution1, rdf_solution2, *rdf_solutions)[source]¶ Return the cross-functional union of all arguments.
This is a thin wrapper around
clans.cross_functional_union()
.
Test utilities.
-
algebraixlib.util.test.
create_test_object
(obj: object, msg: str, val: object=None) → object[source]¶ Add the content of
msg
and optionallyval
as properties toobj
.Parameters: - obj – The object to be ‘decorated’.
- msg – Added as property ‘_test_msg’ to obj.
- val – If present, added as property ‘_test_val’ to obj.
Returns: The ‘decorated’ obj.
-
algebraixlib.util.test.
assert_mathobjects
(mo: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]¶ Return
True
if and only if all elements inmo
are instances ofMathObject
.
-
algebraixlib.util.test.
get_test_file_name
(test_module: str, file_id: str) → str[source]¶ Return the file name of a test file.
Test file names are composed of the test
test_module
file’s base name with an appended dash (‘-‘) and an identifyingfile_id
.file_id
should end with the desired file extension.Parameters: - test_module – The name of the test to which the test file belongs. Typically
this will be passed as
__file__
. - file_id – The identification of the file (final part of the name, including extension). This function guarantees that there are no conflicts with outher test modules.
- test_module – The name of the test to which the test file belongs. Typically
this will be passed as
-
algebraixlib.util.test.
get_test_file_path
(test_module: str, file_id: str) → str[source]¶ Return the (absolute) file path of a test file.
The file name is generated with
get_test_file_name
.Parameters: - test_module – The name of the test to which the test file belongs. Typically
this will be passed as
__file__
. - file_id – The identification of the file (final part of the name, including extension).
- test_module – The name of the test to which the test file belongs. Typically
this will be passed as
Submodules¶
algebraixlib.extension module¶
Facilities for extending operations from one algebra to another.
-
algebraixlib.extension.
binary_extend
(set1: 'P( M )', set2: 'P( M )', op, _checked=True) → 'P( M )'[source]¶ Return the binary extension of
op
from one algebra to another algebra.For this extension, the elements of the extended algebra must be sets of the elements of the original algebra.
Parameters: - set1 – A set with elements on which
op
operates. - set2 – A set with elements on which
op
operates. - op – A binary operation that operates on the elements of
set1
andset2
.
Returns: A set that consists of the defined results of
op
when executed on all combinations of the elements ofset1
andset2
, orUndef()
if either set is not aSet
.- set1 – A set with elements on which
-
algebraixlib.extension.
binary_multi_extend
(multiset1: 'P( M x N )', multiset2: 'P( M x N )', op, _checked=True) → 'P( M x N )'[source]¶ Return the binary extension of
op
from one algebra to another algebra.For this extension, the elements of the extended algebra must be multisets of the elements of the original algebra.
Parameters: - multiset1 – A multiset with elements on which
op
operates. - multiset2 – A multiset with elements on which
op
operates. - op – A binary operation that operates on the elements of
multiset1
andmultiset2
.
Returns: A multiset that consists of the defined results of
op
when executed on all combinations of the elements ofmultiset1
andmultiset2
, orUndef()
if either set is not aMultiset
.- multiset1 – A multiset with elements on which
-
algebraixlib.extension.
unary_extend
(set_: 'P( M )', op, _checked=True) → 'P( M )'[source]¶ Return the unary extension of
op
from one algebra to another algebra.For this extension, the elements of the extended algebra must be sets of the elements of the original algebra.
Parameters: - set – A set with elements on which
op
operates. - op – A unary operation that operates on the elements of
set_
.
Returns: A set that consists of the defined results of
op
when executed on the elements ofset_
, orUndef()
ifset_
is not aSet
.- set – A set with elements on which
-
algebraixlib.extension.
unary_multi_extend
(set_or_mset, op, _checked=True) → 'P( M x N )'[source]¶ Return the unary extension of
op
from one algebra to another algebra.For this extension, the elements of the extended algebra must be multisets of the elements of the original algebra.
Parameters: - set_or_mset – A set or a multiset with elements on which
op
operates. - op – A unary operation that operates on the elements of
set_or_mset
.
Returns: A set that consists of the defined results of
op
when executed on the elements ofset_or_mset
, orUndef()
ifset_or_mset
is neither a set nor a multiset.- set_or_mset – A set or a multiset with elements on which
algebraixlib.partition module¶
Operations for partitioning sets and multisets.
-
algebraixlib.partition.
partition
(set_or_mset, class_invariant_func)[source]¶ Return
set_or_mset
partitioned according toclass_invariant_func
.Parameters: - set_or_mset – The set or multiset that is to be partitioned.
- class_invariant_func –
A function from elements of
set_or_mset
toMathObject
s. It defines an equivalence relation onset_or_mset
such that\[x, y \in set\_or\_mset : x \equiv y \iff class\_invariant\_func(x) = class\_invariant\_func(y)\]
Returns: A set with structure \(P(set\_or\_mset.ground\_set)\) that defines a partition on
set_or_mset
, imposed by the equivalence relation defined by the functionclass_invariant_func
.
-
algebraixlib.partition.
make_labeled_partition
(set_or_mset, class_invariant_func)[source]¶ Return a ‘labeled’ partition of
set_or_mset
, partitioned according toclass_invariant_func
.Parameters: - set_or_mset – The set or multiset that is to be partitioned.
- class_invariant_func –
A function from elements of
set_or_mset
toMathObject
s. It defines an equivalence relation onset_or_mset
such that\[x, y \in set\_or\_mset : x \equiv y \iff class\_invariant\_func(x) = class\_invariant\_func(y)\]
Returns: A function with structure \(P(range(class\_invariant\_func) \times P(set\_or\_mset.ground\_set))\) that maps the range of
class_invariant_func
when applied toset_or_mset
to sets of elements ofset_or_mset
that belong to the given equivalence class.
algebraixlib.structure module¶
The Structure of a MathObject
¶
This module provides facilities to represent the structure of a MathObject
. What we call
‘structure’ is a representation of the minimal power set a given MathObject
belongs to
(or should belong to) that can be expressed with the following elements.
The structural elements we use are:
CartesianProduct
: The ground set of aCouplet
is the Cartesian product of the ground sets of the left and right component.PowerSet
: The ground set of a set is the power set of the ground set of its elements.Union
: The ground set of the elements of a set is the union of the ground sets of the individual elements.
Depending on the type of structure, we use one or two genesis sets:
GenesisSetA
: The set A (\(A\)) is the set of allAtom
s.GenesisSetM
: The term:set M
(\(M\)) is the ground set of allMathObject
s that can be represented in a given system.
In addition to these, there is the structure of an empty set. It is represented by an instance of
Structure
and is the only case that is represented by an instance of that class. It is a subset
of all other structures.
Note
The set M (\(M\)) is finite; essentially it is the set of all instances of
MathObject
that fit into a given system. This also implies that there is a power set
\(P(M)\) that is not an element of \(M\). (It follows that not every ‘set of math
objects’ is an element of \(M\).) Since \(A \subset M\), \(A\) is of course also
finite.
Corresponding to the two genesis sets, we use two different forms to represent the structure of a
MathObject
:
- Absolute structure: An absolute structure does not contain a reference to the set \(M\).
- Relative structure: A relative structure contains a reference to the set \(M\). Such structures are typically used to compare absolute structures against them, to see whether a given absolute structure fulfills a minimal structural criterion.
Example Code¶
from algebraixlib.mathobjects import Set
from algebraixlib.structure import PowerSet, GenesisSetM
Set([1, 2]).get_ground_set()
# Output: PowerSet(GenesisSetA())
Set([1, 2]).get_ground_set().is_subset(PowerSet(GenesisSetM()))
# Output: True
API¶
-
class
algebraixlib.structure.
Structure
[source]¶ Bases:
object
Represent the ground set of a
MathObject
in structural terms. An instance of this class is the empty set.Note
This class serves a double purpose. On one hand it is the base class for all nodes in the structure tree, and on the other hand it is the representative of the whole tree (where the top level node of the tree of interest is typically a subclass of this class). This is common practice and should not pose a problem, but it is probably helpful to be aware of it.
-
is_subset
(other) → bool[source]¶ Return
True
ifself
is a subset ofother
.Parameters: other – Must be an instance of Structure
.Returns: Is always True
for typeStructure
.
-
get_powerset_level
(other) → int[source]¶ Return the number of power set levels between
self
andother
.Parameters: other – Must be an instance of Structure
.Returns: An integer >= 0. Is always 0 for type Structure
.
-
is_same
(other) → bool[source]¶ Return
True
ifself
is structurally equivalent toother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is structurally equivalent toother
.
-
-
class
algebraixlib.structure.
GenesisSetA
[source]¶ Bases:
algebraixlib.structure.Structure
The set of all atoms. Is functionally a singleton.
-
is_subset
(other: algebraixlib.structure.Structure) → bool[source]¶ Return
True
ifself
is a subset ofother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is a subset ofother
.
-
get_powerset_level
(other: algebraixlib.structure.Structure) → int[source]¶ Return the number of power set levels between
self
andother
.Parameters: other – Must be an instance of Structure
.Returns: An integer >= 0. Is always 0 for type GenesisSetA
.
-
is_same
(other: algebraixlib.structure.Structure) → bool[source]¶ Return
True
ifself
is structurally equivalent toother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is structurally equivalent toother
.
-
__hash__
()[source]¶ Return a hash based on the member values. (It must match the implementation of
is_same
, to whichStructure.__eq__
redirects equality comparisons.)
-
-
class
algebraixlib.structure.
GenesisSetM
[source]¶ Bases:
algebraixlib.structure.Structure
The set of all instances of
MathObject
. Is functionally a singleton.Note
The set \(M\) being a superset of \(A\) means that subset checking (especially in
Union
) needs to ‘know’ about this relationship and take it into account. Representing \(M\) as \((A \cup A')\) (where \(A' = M \setminus A\)) would make this more straightforward, but would make the visible representation of \(M\) (as union) non-intuitive.-
is_subset
(other: algebraixlib.structure.Structure) → bool[source]¶ Return
True
ifself
is a subset ofother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is a subset ofother
.
-
get_powerset_level
(other)[source]¶ Return the number of power set levels between
self
andother
.Parameters: other – Must be an instance of Structure
.Returns: An integer >= 0. Is always 0 for type GenesisSetM
.
-
is_same
(other: algebraixlib.structure.Structure) → bool[source]¶ Return
True
ifself
is structurally equivalent toother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is structurally equivalent toother
.
-
__hash__
()[source]¶ Return a hash based on the member values. (It must match the implementation of
is_same
, to whichStructure.__eq__
redirects equality comparisons.)
-
-
class
algebraixlib.structure.
GenesisSetN
[source]¶ Bases:
algebraixlib.structure.Structure
The set of all integers. Is functionally a singleton.
-
is_subset
(other: algebraixlib.structure.Structure) → bool[source]¶ Return
True
ifself
is a subset ofother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is a subset ofother
.
-
get_powerset_level
(other)[source]¶ Return the number of power set levels between
self
andother
.Parameters: other – Must be an instance of Structure
.Returns: An integer >= 0. Is always 0 for type GenesisSetN
.
-
is_same
(other: algebraixlib.structure.Structure) → bool[source]¶ Return
True
ifself
is structurally equivalent toother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is structurally equivalent toother
.
-
__hash__
()[source]¶ Return a hash based on the member values. (It must match the implementation of
is_same
, to whichStructure.__eq__
redirects equality comparisons.)
-
-
class
algebraixlib.structure.
CartesianProduct
(left, right)[source]¶ Bases:
algebraixlib.structure.Structure
Represent the Cartesian product node of a structure.
Parameters: - left – The ground set of the left component of a couplet. Must
be an instance of
Structure
. - right – The ground set of the right component of a couplet. Must be an
instance of
Structure
.
-
is_subset
(other: algebraixlib.structure.Structure) → bool[source]¶ Return
True
ifself
is a subset ofother
.In order for
self
to be a subset ofother
,other
must be:- A
CartesianProduct
and both left and right components must be subsets of left and right components ofother
, or - A
Union
that contains an instance ofCartesianProduct
where both left and right component are subsets of left and right components ofother
, or GenesisSetM
(everything in our system is a subset of \(M\)).
Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is a subset ofother
.- A
-
get_powerset_level
(other: algebraixlib.structure.Structure) → int[source]¶ Return the number of power set levels between
self
andother
.Parameters: other – Must be an instance of Structure
.Returns: An integer >= 0. Is always 0 for type CartesianProduct
.
-
is_same
(other: algebraixlib.structure.Structure) → bool[source]¶ Return
True
ifself
is structurally equivalent toother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is structurally equivalent toother
.
-
__hash__
()[source]¶ Return a hash based on the member values. (It must match the implementation of
is_same
, to whichStructure.__eq__
redirects equality comparisons.) Is always cached.
- left – The ground set of the left component of a couplet. Must
be an instance of
-
class
algebraixlib.structure.
Union
(iterable)[source]¶ Bases:
algebraixlib.structure.Structure
Represent the union node of a structure.
No member of this instance is a subset of another member, and no member of this union is a union itself (union arguments get ‘unioned into’ this union).
Parameters: iterable – An Iterable of one or more sets to be unioned. All elements must be an instance of Structure
.-
is_subset
(other: algebraixlib.structure.Structure) → bool[source]¶ Return
True
ifself
is a subset ofother
.Is
True
if every element of this union is a subset ofother
:- If
other
is a union, we compare against each element of it. - If
other
is not a union, we compare directly against it.
Is also
True
ifother
isGenesisSetM
(everything in our system is an element of \(M\)).Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is a subset ofother
.- If
-
get_powerset_level
(other: algebraixlib.structure.Structure) → int[source]¶ Return the number of power set levels between
self
andother
.Parameters: other – Must be an instance of Structure
.Returns: An integer >= 0. Is always 0 for type CartesianProduct
.
-
is_same
(other: algebraixlib.structure.Structure) → bool[source]¶ Return
True
ifself
is structurally equivalent toother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is structurally equivalent toother
.
-
__hash__
()[source]¶ Return a hash based on the member values. (It must match the implementation of
is_same
, to whichStructure.__eq__
redirects equality comparisons.) Is always cached.
-
-
class
algebraixlib.structure.
PowerSet
(elements_struct)[source]¶ Bases:
algebraixlib.structure.Structure
Represent the power set node of a structure.
Parameters: elements_struct – The structure of the elements of the set of which we are representing the power set. Must be an instance of Structure
.-
base_set
¶ Read-only access to the base set of this powerset.
-
is_subset
(other: algebraixlib.structure.Structure) → bool[source]¶ Return
True
ifself
is a subset ofother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is a subset ofother
.
-
get_powerset_level
(other: algebraixlib.structure.Structure) → int[source]¶ Return the number of power set levels between
self
andother
.Parameters: other – Must be an instance of Structure
.Returns: The number of power set levels (>= 0) that are between self
andother
. A result of 0 may mean that the two ground sets are equal or that they are not related.
-
is_same
(other: algebraixlib.structure.Structure) → bool[source]¶ Return
True
ifself
is structurally equivalent toother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is structurally equivalent toother
.
-
__hash__
()[source]¶ Return a hash based on the member values. (It must match the implementation of
is_same
, to whichStructure.__eq__
redirects equality comparisons.) Is always cached.
-
algebraixlib.undef module¶
Facilities for representing and working with the concept of “undefined”.
Most operations are not defined for all types of data: set operations may not be defined on
couplets, multiset operations may not be defined on sets, and so on. When an
operation is not defined for a given input, it returns the singleton Undef()
. This return value
can then be taken into account by the caller. In some cases it is an error, in other cases the
result is simply ignored.
-
class
algebraixlib.undef.
Undef
[source]¶ Bases:
object
A singleton class that represents the concept of “undefined”.
Instances of this class are not treated as a value by the operations in this library; specifically, it will never appear as the value of an
Atom
.-
cached_relation
¶ Return the cached state of being a relation. See [PropCache].
-
cached_is_relation
¶ Return
False
sinceself
is known not to be a relation. See [PropCache].
-
cached_is_not_relation
¶ Return
True
sinceself
is known not to be a relation. See [PropCache].
-
cached_clan
¶ Return the cached state of being a clan. See [PropCache].
-
cached_is_clan
¶ Return
False
sinceself
is known not to be a clan. See [PropCache].
-
cached_is_not_clan
¶ Return
True
sinceself
is known not to be a clan. See [PropCache].
-
cached_multiclan
¶ Return the cached state of being a multiclan. See [PropCache].
-
cached_is_multiclan
¶ Return
False
sinceself
is known to not be a multiclan. See [PropCache].
-
cached_is_not_multiclan
¶ Return
True
sinceself
is known not to be a multiclan. See [PropCache].
-
cached_absolute
¶ Return the cached state of being absolute. See [PropCache].
-
cached_is_absolute
¶ Return
False
sinceself
is known not to be absolute. See [PropCache].
-
cached_is_not_absolute
¶ Return
True
sinceself
is known not to be absolute. See [PropCache].
-
cached_functional
¶ Return the cached state of being functional. See [PropCache].
-
cached_is_functional
¶ Return
False
since functional does not apply. See [PropCache].
-
cached_is_not_functional
¶ Return
False
since functional does not apply. See [PropCache].
-
cached_right_functional
¶ Return the cached state of being right-functional. See [PropCache].
-
cached_is_right_functional
¶ Return
False
since right-functional does not apply. See [PropCache].
-
cached_is_not_right_functional
¶ Return
False
since right-functional does not apply. See [PropCache].
-
cached_reflexive
¶ Return the cached state of being reflexive. See [PropCache].
-
cached_is_reflexive
¶ Return
False
since reflexive does not apply. See [PropCache].
-
cached_is_not_reflexive
¶ Return
False
since reflexive does not apply. See [PropCache].
-
cached_symmetric
¶ Return the cached state of being symmetric. See [PropCache].
-
cached_is_symmetric
¶ Return
False
since symmetric does not apply. See [PropCache].
-
cached_is_not_symmetric
¶ Return
False
since symmetric does not apply. See [PropCache].
-
cached_transitive
¶ Return the cached state of being transitive. See [PropCache].
-
cached_is_transitive
¶ Return
False
since transitive does not apply. See [PropCache].
-
cached_is_not_transitive
¶ Return
False
since transitive does not apply. See [PropCache].
-
cached_regular
¶ Return the cached state of being regular. See [PropCache].
-
cached_is_regular
¶ Return
False
since regular does not apply. See [PropCache].
-
cached_is_not_regular
¶ Return
False
since regular does not apply. See [PropCache].
-
cached_right_regular
¶ Return the cached state of being right-regular. See [PropCache].
-
cached_is_right_regular
¶ Return
False
since right-regular does not apply. See [PropCache].
-
cached_is_not_right_regular
¶ Return
False
since right-regular does not apply. See [PropCache].
-
__hash__
= None¶
-
-
class
algebraixlib.undef.
RaiseOnUndef
[source]¶ Bases:
object
Manage the level for
make_or_raise_undef
. Implemented as static class.-
static
get_level
()[source]¶ Return the current level for raising an
UndefException
.The exception is raised if the
level
argument ofmake_or_raise_undef
is less than or equal to the value returned here.
-
static
set_level
(temp_value)[source]¶ Set the level for raising an
UndefException
temporarily totemp_value
.
-
static
reset
()[source]¶ Reset the level for raising an
UndefException
back to its initial value.
-
static
-
exception
algebraixlib.undef.
UndefException
[source]¶ Bases:
Exception
This exception is raised when the
level
argument ofmake_or_raise_undef
is less than or equal to theRaiseOnUndef
level.
-
algebraixlib.undef.
make_or_raise_undef
(level=1)[source]¶ Raise
UndefException
iflevel
is less than or equal to theRaiseOnUndef
level, otherwise returnUndef()
.Parameters: level – An integer >= 1. Default is 1. Note
Use 1 (or no argument) for the cases that are most likely to be errors (like wrong argument types). Use higher numbers for cases that may return
Undef()
on purpose.
-
algebraixlib.undef.
make_or_raise_undef2
(obj)[source]¶ Raise
UndefException
iflevel
is less than or equal to theRaiseOnUndef
level, otherwise returnUndef()
.Parameters: obj – Causes level
argument tomake_or_raise_undef
to be 2 ifUndef()
Algebra Documentation¶
A Beginner’s Introduction to Data Algebra¶
The purpose of this section is to provide a brief introduction to data algebra. In particular, we would like to motivate the various definitions and terms in a way that is not daunting to beginners, and shows the usefulness of the data algebra framework. Note that this introduction will make use of set notation, of which there is a short primer at Set Notation if needed.
We will do this by taking a dataset and analyze it using data algebra. Consider the following table of information:
year | providedScientificName | ITISscientificName | ITIScommonName | ITIStsn | validAcceptedITIStsn | decimalLatitude | decimalLongitude |
---|---|---|---|---|---|---|---|
1970 | Micrurus tener Baird & Girard, 1853 | Micrurus tener | Texas Coralsnake | 683040 | 683040 | 30.43099976 | -98.05999756 |
2008 | Masticophis taeniatus Hallowell, 1852 | Masticophis taeniatus | Culebra-chirriadora adornada;Striped Whipsnake | 174240 | 174240 | 30.43399048 | -97.96090698 |
1951 | Kinosternon flavescens Agassiz, 1857 | Kinosternon flavescens | Tortuga-pecho quebrado amarilla;Yellow Mud Turtle | 173766 | 173766 | 30.43678093 | -97.66889191 |
1951 | Acris crepitans Baird, 1854 | Acris crepitans | Northern Cricket Frog;Rana-grillo norte | 173520 | 173520 | 30.43678093 | -97.66889191 |
2011 | Parus bicolor Linnaeus, 1766 | Baeolophus bicolor | Carbonero cresta negra;Tufted Titmouse | 178738 | 554138 | 30.4736805 | -97.96916962 |
Table Sightings is taken from BISON (Biodiversity Information Serving Our Nation) [1], a publicly available dataset from the US Geological Survey, and consists of animal sightings in Travis County, TX.
Couplets: The Basic Pieces of Data¶
Every data entry, or datum, is represented in data algebra using couplets. The idea being any piece of data consists of two pieces of information. For example in table Sightings 2011 refers to a year, and 30.7436805 is a decimalLatitude. In data algebra notation we write these as
and
The object before the arrow is called the left component, and the object after the arrow is called the right component. For example the couplet \(year{\mapsto}2011\) has left component \(year\) and right right component \(2011\).
Relations: Sets of Couplets¶
Each row of Sightings is a set of couplets, which we call a relation. For example, the first row of Sightings, let us denote it by \(R_1\), is the relation
While there are other ways of forming relations from the table, for our purposes we will use rows to form relations. One reason we will do this is that each row relation is in fact a function in this case. It is often the case that row relations are functional.
Getting Data from a Relation¶
One of our primary methods of extracting information from a dataset is composition. Let us say we want to know the \(ITIScommonName\) of the first row of Sightings. What we can do is compose \(R_1\) with the relation
Just like function composition, the output of the first relation becomes the input for the next relation. In this case, our first relation has only one output, or right component, which corresponds to only one input, or left component, in \(R_1\), hence
which tells us that \(ITIScommonName\) for the first row is \(Texas\ Coralsnake\). (Note that, just like with functions, compositions are evaluated from right to left. In particular, given relation composition \(r_2 \circ r_1\) we would apply \(r_1\) first, and then \(r_2\).)
Clans: Sets of Relations¶
A set of relations is called a clan. In particular, any table can be divided up into a set of row relations, which means any table can be represented by a clan. We will refer to the table Sightings as a clan whose relations are the row relations. Once again, we can use composition to extract data out of our clan.
Getting Data from a Clan¶
For example, if we want the projection (in terms of relational algebra) of Sightings over \(ITISscientificName\) and \(ITIScommonName\), we can form the relation
Let us use \(\mathbb{S}\) to denote the Sightings clan. If we use \(R_k\) to denote the \(k\)th row of Sightings, then
Note that
and \(R_k \circ D\) will give you the \(ITISscientificName\) and \(ITIScommonName\) in the \(k\)th row of Sightings. In particular we have
which is the projection of Sightings onto \(ITISscientificName\) and \(ITIScommonName\) as we wanted.
[1] | BISON can be accessed at http://bison.usgs.ornl.gov To obtain the data in the table, on the map click on Texas, then on Travis county, and one can then download all of the wildlife sightings recorded for Travis county. The above table is only a small subset of the many sightings in Travis county. |
Algebra Reference¶
- absolute
Applied to couplets, sets, constructs derived from them (like relations) and algebras. Such a construct is called absolute if its ground set is based on set A (\(A\)).
See for example absolute set.
- A relation that has only members that are elements of the Cartesian product \(A \times A\) is an ‘absolute relation’. Example: \(\{a{\mapsto}1, b{\mapsto}2\}\). (However, an absolute relation is not an absolute set; the members of the relation are couplets, not atoms.)
- The relation \(\{a{\mapsto}1, b{\mapsto}\{2\}\}\) is not an absolute relation, as one of the right elements of the member couplets is not an atom (it is a set \(\{2\}\)).
- absolute clan
- An absolute clan is a clan that is an element of the second power set of the Cartesian product of set A (\(A\)) (\(P^2(A \times A)\)). Such a clan has only atoms as members of the couplets in the relations. Example: \(\{ \{2{\mapsto}1, 3{\mapsto}2\}, \{5{\mapsto}4, 9{\mapsto}7\} \}\).
- absolute couplet
- An absolute couplet is a couplet that is an element of the Cartesian product of set A (\(A\)) (\(A \times A\)). Such a couplet has only atoms as members. Example: \(2{\mapsto}1\).
- absolute ground set
Our algebras normally have a ground set and an absolute ground set. The absolute ground set is the ground set with the elements of the algebra being expressed in terms of set A (\(A\)).
For example, the ground set of the algebra of relations is \(P(M \times M)\); this allows sets and couplets as elements of the couplets that form the relations. The absolute ground set of the algebra of relations is \(P(A \times A)\); this requires atoms to form the couplets that form the relations.
- absolute multiclan
- An absolute multiclan is a multiclan that has only atoms as members of the couplets in the relations. See also absolute clan.
- absolute multiset
- An absolute multiset is a multiset that is an element of the power set of the Cartesian product of set A (\(A\)) with set N (\(N\)) (\(P(A \times N)\). Such a multiset has only atoms as elements. Example: \(\{1{:}3, 'a'{:}5\}\).
- absolute relation
- An absolute relation is a set that is an element of the power set of the Cartesian product of set A (\(A\)) (\(P(A \times A)\). Such a set has only couplets as elements that consist only of atoms. Example: \(\{2{\mapsto}1, 5{\mapsto}2\}\).
- absolute set
- An absolute set is a set that is an element of the power set of set A (\(A\)) (\(P(A)\). Such a set has only atoms as elements. Example: \(\{1, 2\}\).
- algebra
- An algebra is a set together with one or more operations defined on it. For a more detailed definition see Algebras.
- algebra of clans
- The algebra of clans is the algebra on sets of relations. As a result its ground set is the second power set of couplets, which allows us to use more operations in addition to those on an algebra of sets. See Algebra of Clans for a more detailed explanation.
- algebra of couplets
- Given a collection of couplets we define an algebra on it by including the operations of composition and transposition. See Algebra of Couplets for a more detailed definition.
- algebra of multiclans
- An algebra defined on multisets of relations. This algebra is similar to the algebra of clans, but takes into account multiplicities of relations. See Algebra of Multiclans for more information.
- algebra of multisets
- An algebra on the set of all multisets of set M (\(M\)) with the operations of multiset union, multiset intersection, multiset addition, multiset difference, and submultiset. See Multiset Algebra for more detailed information.
- algebra of relations
- The algebra of relations is an algebra on a set of couplets under the operations of composition and transposition. See Algebra of Relations for a more detailed definition.
- algebra of sets
- Also called set algebra, is the algebra formed by taking the power set of a set and applying the operations of union and intersection. See Algebra of Sets for a more detailed definition.
- atom
- An atom is a datum that is not a set or a couplet. The set of all atoms is set A (\(A\)).
- bijective
- A relation is bijective if it is both left-functional and right-functional.
- binary extension
A binary extension is an extension of a binary operation from a given algebra to an extension of the algebra that consists of sets of the elements of the original algebra:
\[binaryExtn(op, S1, S2) := \{op(s1, s2)\ :\ s1 \in S1 \text{ and } s2 \in S2 \text{ where } op(s1, s2) \text{ is defined}\}\]- binary intersection
- A binary intersection is an intersection of two sets. See intersection for a complete definition.
- binary multi-extension
A binary multi-extension is an extension of a binary operation from a given algebra to an extension of the algebra that consists of multisets of the elements of the original algebra:
\[binMultiExtn(op, S1, S2) := \{op(s1, s2){:}(\dot{S1}(s1) \cdot \dot{S2}(s2))\ :\ s1 \in S1 \text{ and } s2 \in S2 \text{ where } op(s1, s2) \text{ is defined}\}\]- binary operation
- A binary operation is an operation with two arguments, typically with a result that belongs to the same ground set as the arguments (when the operation is a member of an algebra).
- binary relation
- We represent a binary relation as a set where every member is a couplet. We also call this simply a relation.
- binary union
- A binary union is a union of two sets. See union for more information.
- Cartesian product
- The Cartesian product of two sets \(X \times Y\) is the set of all couplets where the first member of the couplet is a member of \(X\) and the second member of the couplet is a member of \(Y\).
- clan
- A clan is a set of relations.
- clan diagonal
- A clan diagonal is a clan with a single relation that is a diagonal.
- complement
The complement of a given set is the collection of elements not in the given set. This definition depends on a choice of a larger set in which context every other set is a subset of. In particular, given an algebra of sets whose ground set is the power set \(P(U)\) and \(X\in P(U)\), then the complement of \(X\) is:
\[X' := \{x \in U: x \not\in X\} = U - X\]- composition
The composition of the couplets \(a{\mapsto}b\) and \(c{\mapsto}d\) is defined as:
\[\begin{split}c{\mapsto}d \circ a{\mapsto}b := \begin{cases} a{\mapsto}d & \text{if } b = c \\ \text{undefined} & \text{if } b \ne c \end{cases}\end{split}\]The operation may be extended to extended algebras using the binary extension and – if there is no danger of ambiguities – is then also called simply ‘composition’.
Specific extensions:
Algebra of relations: \(R_2 \circ R_1 := \{c_2 \circ c_1\ :\ c_1 \in R_1,\ c_2 \in R_2\}\)
(\(R_1\) and \(R_2\) are relations; \(c_1\) and \(c_2\) are couplets.)
Algebra of clans: \(C_2 \circ C_1 := \{R_2 \circ R_1\ :\ R_1 \in C_1,\ R_2 \in C_2\}\)
(\(C_1\) and \(C_2\) are clans; \(R_1\) and \(R_2\) are relations.)
Algebra of multiclans: \(\dot{C}_2 \circ \dot{C}_1 := \{(R_2 \circ R_1){:}(\dot{C}_2(R_2) \cdot \dot{C}_1(R_1))\ :\ R_1 \in \dot{C}_1,\ R_2 \in \dot{C}_2\}\)
(\(\dot{C}_1\) and \(\dot{C}_2\) are multiclans; \(R_1\) and \(R_2\) are relations.)
- couplet
- A couplet is an ordered pair, following the Kuratowski definition of an ordered pair defined as \(\{\{l\}, \{l, r\}\}\). It is the mathematical object used to represent a datum or data point. We denote it by \(l{\mapsto}r\), with \(l\) called the left component, and \(r\) the right component.
- cross-functional union
- A short name for cross-left-functional union in cases where no ambiguities are expected.
- cross-intersection
The cross-intersection is an extension of intersection (or multiset intersection). Depending on the specific form of extension, it may be a binary extension (when extending to an algebra of sets) or a binary multi-extension (when extending to an algebra of multisets).
In the specific context, cross-intersection is the binary extension of intersection from an algebra of sets to an algebra of sets of sets (for example, from the algebra of relations to the algebra of clans). The cross-intersection of the sets (of sets) \(\mathbb{S}\) and \(\mathbb{T}\) is defined as:
\[\mathbb{S} \blacktriangle \mathbb{T} = \{X \cap Y\ : X \in \mathbb{S} \text{ and } Y \in \mathbb{T}\}\]For the version of cross-intersection on the algebra of multiclans and on an algebra of multisets in general see multi-cross-intersection.
- cross-left-functional union
The cross-left-functional union, (or cross-functional union), of two clans \(\mathbb{C}\) and \(\mathbb{D}\) is a binary extension of the left-functional union from the algebra of relations to the algebra of clans:
\[\mathbb{C} \underset{f}{\blacktriangledown} \mathbb{D} = \{R \underset{f}{\cup} Q\ : R \in \mathbb{C} \text{ and } Q \in \mathbb{D}\}\]- cross-right-functional union
The cross-right-functional union of two clans \(\mathbb{C}\) and \(\mathbb{D}\) is a binary extension of the right-functional union from the algebra of relations to the algebra of clans:
\[\mathbb{C} \underset{rf}{\blacktriangledown} \mathbb{D} = \{R \underset{rf}{\cup} Q\ : R \in \mathbb{C} \text{ and } Q \in \mathbb{D}\}\]- cross-substriction
The cross-substriction is a binary extension of substriction from an algebra of sets to an algebra of sets of sets (for example, from the algebra of relations to the algebra of clans). The cross-substriction of the sets (of sets) \(\mathbb{S}\) and \(\mathbb{T}\) is defined as:
\[\mathbb{S} \blacktriangleleft \mathbb{T} = \{X \vartriangleleft Y\ : X \in \mathbb{S} \text{ and } Y \in \mathbb{T}\} = \{X : X \in \mathbb{S} \text{ and } X \subset Y \text{ for some } Y \in \mathbb{T} \}\]We also have a binary multi-extension of cross-substriction called the multi-cross-substriction.
- cross-superstriction
The cross-superstriction is a binary extension of superstriction from an algebra of sets to an algebra of sets of sets (for example, from the algebra of relations to the algebra of clans). The cross-superstriction of the sets (of sets) \(\mathbb{S}\) and \(\mathbb{T}\) is defined as:
\[\mathbb{S} \blacktriangleright \mathbb{T} = \{X \vartriangleright Y\ : X \in \mathbb{S} \text{ and } Y \in \mathbb{T}\} = \{X : X \in \mathbb{S} \text{ and } X \supset Y \text{ for some } Y \in \mathbb{T} \}\]We also have a binary multi-extension of cross-superstriction called the multi-cross-superstriction.
- cross-union
The cross-union is a binary extension of union from an algebra of sets to an algebra of sets of sets (for example, from the algebra of relations to the algebra of clans). The cross-union of the sets (of sets) \(\mathbb{S}\) and \(\mathbb{T}\) is defined as:
\[\mathbb{S} \blacktriangledown \mathbb{T} = \{X \cup Y\ : X \in \mathbb{S} \text{ and } Y \in \mathbb{T}\}\]We also have a binary multi-extension of cross-union called the multi-cross-union.
- diagonal
The diagonal is an equivalence relation. The diagonal of a set \(S\) is defined as:
\[D_S = \{x{\mapsto}x \in S \times S\ : x \in S\}\]- difference
The difference of two sets \(S\) and \(T\) is the set of elements in \(S\) but not in \(T\) (see also Wikipedia: Relative complement). The definition is:
\[\begin{split}S \setminus T = \{x: x \in S\ \&\ x \notin T\}\end{split}\]- equivalence relation
- A relation is said to be an equivalence relation if it is reflexive, symmetric and transitive.
- extension
- An extension of a given set or algebra, is an extension of the set or algebra either by expanding the ground set, the set of operations on the set or both. For a more detailed definition, see Extension.
- finite intersection
- A finite intersection is the intersection of a finite collection of sets. See intersection for a complete definition.
- finite union
- A finite union is the union of a finite collection of sets. See union for a more detailed explanation.
- function
- A function is a left-functional relation.
- functional
- A short name for left-functional in cases where no ambiguities are expected.
- functional union
- A short name for left-functional union in cases where no ambiguities are expected.
- ground set
- The set that contains all the elements of an algebra.
- identity element
- The element of the ground set of an algebra that, when used as one of the arguments of a binary operation produces the other argument of the operation as result of the operation.
- intersection
An operation on sets that creates a set by collecting the elements in common to two or more individual sets into a new set. In mathematical terms, if \(\mathbb{S}\) is a collection of sets, then the intersection of all of the sets in \(\mathbb{S}\) is denoted:
\[\bigcap \mathbb{S} = \bigcap_{T\in\mathbb{S}}T,\]and is the set \(\{x\ : \forall T \in \mathbb{S},\ x \in T\}\). If \(\mathbb{S}\) consists of only two sets, the intersection is called a binary intersection. If \(\mathbb{S}\) consists of a finite collection of sets, the intersection is called a finite intersection. See also Wikipedia: Intersection.
- left
- A short name for left component where no ambiguity is expected.
- left component
- Given a couplet represented by \(l{\mapsto}r\), the component \(l\) is called the left component.
- left set
The left set of a relation \(R\) is the set of all left components of its members:
\[left(R) = \{ l\ : l{\mapsto}r \in R \}\]The left set of a clan \(\mathbb{C}\) is the union of all left sets of its member relations:
\[left(\mathbb{C}) = \underset{R\ \in\ \mathbb{C}}{\bigcup} left(R)\]- left-functional
A relation \(R\) is said to be left-functional, or simply functional, if:
\[\begin{split}x{\mapsto}y \in R\ \& \ x{\mapsto}z \in R \implies y = z\end{split}\]A clan \(\mathbb{C}\) is said to be (left-)functional if all its relations are functional:
\[\forall R \in \mathbb{C}: R \text{ is left-functional}\]- left-functional union
The left-functional union (or functional union) of two functions \(R\) and \(Q\) is the union of the two relations if the result is left-functional, otherwise the result is not defined:
\[\begin{split}R \underset{f}{\cup} Q = \begin{cases} R \cup Q & \text{if }R \cup Q \text{ is left-functional} \\ \text{undefined} & \text{if it is not left-functional} \end{cases}\end{split}\]- left-regular
A clan \(\mathbb{C}\) is said to be left-regular (or short regular) if it is left-functional and the left sets of all its relations are the same:
\[\begin{split}\begin{align*} \forall R \in \mathbb{C}&: R \text{ is left-functional} \text{ and } \\ \forall R, Q \in \mathbb{C}&: left(R) = left(Q) \end{align*}\end{split}\]- lhs-cross-functional union
- A short name for lhs-cross-left-functional union in cases where no ambiguities are expected.
- lhs-cross-left-functional union
Given two clans the lhs-cross-left-functional union (or lhs-cross-functional union) takes the cross-left-functional union, then any relations in the clan on the left side of the operation that resulted in the empty set are collected by taking their union and combined with the result of the cross-left-functional union. Mathematically, if \(\mathbb{C}\) and \(\mathbb{D}\) are the two clans in question, then their lhs-cross-left-functional union is:
\[\begin{split}\mathbb{C} \overrightarrow{\underset{f}\blacktriangledown} \mathbb{D} = \mathbb{C} \underset{f}{\blacktriangledown} \mathbb{D} \bigcup\{T : T\in\mathbb{C}\ \& \ T \underset{f}{\blacktriangledown} \mathbb{D} = \varnothing \}\end{split}\]- multi-cross-intersection
Let \(\dot{\mathbb{S}}\) and \(\dot{\mathbb{T}}\) be multisets of sets with \(X \in \dot{\mathbb{S}}\) and \(Y \in \dot{\mathbb{T}}\), then their multi-cross-intersection is defined in the same way as the cross-intersection with the multiplicities satisfying:
\[\dot{\mathbb{S}} \blacktriangle \dot{\mathbb{T}}(X \cap Y) = \dot{\mathbb{S}}(X) \cdot \dot{\mathbb{T}}(Y)\]Where there is no ambiguity we will refer to the multi-cross-intersection simply as the cross-intersection.
- multi-cross-substriction
Let \(\dot{\mathbb{S}}\) and \(\dot{\mathbb{T}}\) be multisets of sets with \(X \in \dot{\mathbb{S}}\) and \(Y \in \dot{\mathbb{T}}\), then their multi-cross-substriction is defined in the same way as the cross-substriction with the multiplicities satisfying:
\[\dot{\mathbb{S}} \blacktriangleleft \dot{\mathbb{T}}(X \vartriangleleft Y) = \dot{\mathbb{S}}(X)\]Where there is no ambiguity we will refer to the multi-cross-substriction simply as the cross-substriction.
- multi-cross-superstriction
Let \(\dot{\mathbb{S}}\) and \(\dot{\mathbb{T}}\) be multisets of sets with \(X \in \dot{\mathbb{S}}\) and \(Y \in \dot{\mathbb{T}}\), then their multi-cross-superstriction is defined in the same way as the cross-superstriction with the multiplicities satisfying:
\[\dot{\mathbb{S}} \blacktriangleright \dot{\mathbb{T}}(X \vartriangleright Y) = \dot{\mathbb{S}}(X)\]Where there is no ambiguity we will refer to the multi-cross-superstriction simply as the cross-superstriction.
- multi-cross-union
Let \(\dot{\mathbb{S}}\) and \(\dot{\mathbb{T}}\) be multisets of sets with \(X \in \dot{\mathbb{S}}\) and \(Y \in \dot{\mathbb{T}}\), then their multi-cross-union is defined in the same way as the cross-union with the multiplicities satisfying:
\[\dot{\mathbb{S}} \blacktriangledown \dot{\mathbb{T}}(X \cup Y) = \dot{\mathbb{S}}(X) \cdot \dot{\mathbb{T}}(Y)\]Where there is no ambiguity we will refer to the multi-cross-union simply as the cross-union.
- multiclan
- A multiclan is a multiset of relations.
- multiplicity
- Given an element of a multiset, the multiplicity of that element is the number of times the element appears in the multiset. See Multiset for more information.
- multiset
- A multiset, also sometimes called a bag, is a generalization of the idea of a set where multiple instances of the same element are allowed. See Multiset for more information.
- multiset addition
The multiset addition of two multisets \(\dot{S}\) and \(\dot{T}\) is defined as follows:
\[\big(\dot{S} + \dot{T}\big)(x) = \dot{S}(x) + \dot{T}(x)\]for any \(x\), where here we take \(\dot{S}(x)=0\) for \(x \not\in \dot{S}\), and \(\dot{T}(x)=0\) for \(x \not\in \dot{T}\).
- multiset difference
The multiset difference of two multisets \(\dot{S}\) and \(\dot{T}\) is defined as follows:
\[\begin{split}\big(\dot{S} \setminus \dot{T}\big)(x) = \begin{cases} \dot{S}(x) - \dot{T}(x) & \text{if } \dot{S}(x) - \dot{T}(x)>0 \\ \text{undefined} & \text{if } \dot{S}(x) - \dot{T}(x) \leq 0 \end{cases}\end{split}\]for any \(x\), where here we take \(\dot{S}(x)=0\) for \(x \not\in \dot{S}\), and \(\dot{T}(x)=0\) for \(x \not\in \dot{T}\).
- multiset intersection
We define the multiset intersection of two multisets \(\dot{S}\) and \(\dot{T}\) to be:
\[\big(\dot{S} \cap \dot{T}\big)(x) = min \big(\dot{S}(x), \dot{T}(x)\big)\]for any \(x\), where here we take \(\dot{S}(x)=0\) for \(x \not\in \dot{S}\), and \(\dot{T}(x)=0\) for \(x \not\in \dot{T}\).
- multiset union
We define the multiset union of two multisets \(\dot{S}\) and \(\dot{T}\) to be:
\[\big(\dot{S} \cup \dot{T}\big)(x) = max \big(\dot{S}(x), \dot{T}(x)\big)\]for any \(x\), where here we take \(\dot{S}(x)=0\) for \(x \not\in \dot{S}\), and \(\dot{T}(x)=0\) for \(x \not\in \dot{T}\).
- partition
- A partition of a set is the splitting of a set into a collection of smaller subsets. Mathematically, given a set \(S\), we create a set of subsets of \(S\) such that the union of those sets is \(S\), and whose pairwise intersection is the empty set (another term for this is that any two sets are disjoint).
- power set
- The power set of any set \(S\), written \(P(S)\), is the set of all subsets of \(S\), including the empty set and \(S\) itself. We also use the expressions ‘second power set’, ‘third power set’ and so on to mean successive application of the power set operation for the indicated number of times: ‘power set of the power set of the ... of \(S\). (Adapted from Wikipedia: Power set.)
- projection
Given a clan, call it \(C\), and a collection of elements, call it \(lefts\), the projection of \(C\) onto \(lefts\) is a new clan where all of the left components of all of the couplets of the relations of \(C\) are in the set \(lefts\).
To obtain the projection of \(C\) onto \(lefts\) mathematically we can do this as follows:
\[\begin{split}D_{lefts} := \{l{\mapsto}l\ : l\in lefts \} \\ project(C,lefts) = \{ R \circ D_{lefts}\ : R\in C\}\end{split}\]- reflexive
A relation \(R\) is said to be reflexive if:
\[\forall x \in left(R) \cup right(R): x{\mapsto}x \in R\]A couplet can also be reflexive if it is of the form \(x{\mapsto}x\).
- regular
- A short name for left-regular in cases where no ambiguities are expected.
- relation
- A relation is a set of couplets. See also binary relation.
- right
- A short name for right component where no ambiguity is expected.
- right component
- Given a couplet represented by \(l{\mapsto}r\) the component \(r\) is the right component.
- right multiset
The right multiset of a multiclan \(\mathbb{C}\) is the multiset addition of all right sets of its member relations:
\[right(\mathbb{C}) = \underset{R\ \in\ \mathbb{C}}{+} right(R)\]- right set
The right set of a relation \(R\) is the set of all right components of its members:
\[right(R) = \{ r\ : l{\mapsto}r \in R \}\]The right set of a clan \(\mathbb{C}\) is the union of all right sets of its member relations:
\[right(\mathbb{C}) = \underset{R\ \in\ \mathbb{C}}{\bigcup} right(R)\]- right-functional
A relation \(R\) is said to be right-functional if:
\[\begin{split}y{\mapsto}x \in R\ \&\ z{\mapsto}x \in R \implies y = z\end{split}\]- right-functional union
The right-functional union of two right-functional relations \(R\) and \(Q\) is the union of the two relations if the result is right-functional, otherwise the result is not defined:
\[\begin{split}R \underset{rf}{\cup} Q = \begin{cases} R \cup Q & \text{if }R \cup Q \text{ is right-functional} \\ \text{undefined} & \text{if it is not right-functional} \end{cases}\end{split}\]- right-regular
A clan \(\mathbb{C}\) is said to be right-regular if the right sets of all its relations are the same:
\[\forall R, Q \in \mathbb{C}: right(R) = right(Q)\]- set
- A set is a collection of distinct objects. Each object of a set is called an element of the set. In particular, if \(X\) is a set, then we denote the fact that \(x\) is an element of \(X\) by writing \(x\in X\). We will apply the axioms of Zermelo-Fraenkel set theory with choice (ZFC) to the sets. See also Set Notation for more information about set notation
- set A
- The set \(A\) is the set of all atoms. It is a subset of the set M (\(M\)).
- set M
- The set \(M\) is the set of all elements that can be represented in a given system, including atoms, couplets and sets. (A consequence of this is that the power set of \(M\) \(P(M)\) cannot be represented in a given system, and therefore is not an element of \(M\).)
- set N
- The set \(N\) is the set of all positive integers.
- submultiset
The submultiset relation is a binary relation of multisets. A multiset \(\dot{S}\) is a submultiset of a multiset \(\dot{T}\) if the following holds:
\[\dot{S} \subset \dot{T} \iff \forall x \in \dot{S}, \: \dot{S}(x) \leq \dot{T}(x).\]- subset
The subset relation is a binary relation of sets. A set \(S\) is a subset of a set \(T\) if every element of \(S\) is also an element of \(T\):
\[S \subset T \implies \forall x\ [\ x \in S\ \implies\ x \in T\ ]\]- substriction
Substriction is a partial binary operation on sets and multisets. The substriction of two sets or multisets \(S\) and \(T\) is defined as:
\[S \vartriangleleft T = S\ \ \text{if}\ \ S \subset T\](When extended to an algebra of sets of sets (for example, the algebra of clans), we obtain the cross-substriction, which is also sometimes called ‘substriction’.)
- supermultiset
The supermultiset relation is a binary relation of multisets. A multiset \(\dot{S}\) is a supermultiset of a multiset \(\dot{T}\) if the following holds:
\[\dot{S} \supset \dot{T} \iff \forall x \in \dot{T}, \: \dot{S}(x) \geq \dot{T}(x).\]- superset
The superset relation is a binary relation of sets. A set \(S\) is a superset of a set \(T\) if every element of \(T\) is also an element of \(S\):
\[S \supset T \implies \forall x\ [\ x \in T\ \implies\ x \in S\ ]\]- superstriction
Superstriction is a partial binary operation on sets and multisets. The superstriction of two sets or multisets \(S\) and \(T\) is defined as:
\[S \vartriangleright T := S\ \ \text{if}\ \ S \supset T\](When extended to an algebra of sets of sets (for example, the algebra of clans), we obtain the cross-superstriction, which is also sometimes called ‘superstriction’.)
- symmetric
A relation \(R\) is said to be symmetric if:
\[\forall x, y \in left(R) \cup right(R): x{\mapsto}y \in R \implies y{\mapsto}x \in R\]- symmetric difference
The symmetric difference of two sets \(S\) and \(T\) is the set of elements that are only in one of the sets. The definition is:
\[S \vartriangle T = (S \cup T) \setminus (S \cap T)\]- transitive
A relation \(R\) is said to be transitive if:
\[\begin{split}\forall x, y, z \in left(R) \cup right(R): (x{\mapsto}y \in R \ \& \ y{\mapsto}z \in R) \implies x{\mapsto}z \in R\end{split}\]- transposition
Transposition is a unary operation on couplets. The transposition of a couplet \(a{\mapsto}b\) is defined as:
\[\overleftrightarrow{a{\mapsto}b} = b{\mapsto}a\]The operation may be extended to extended algebras (like the algebra of relations) using the unary extension and – if there is no danger of ambiguities – is then also called simply ‘transposition’.
In multisets and multiclans the operation is the same and the multiplicities do not change.
- unary extension
The unary extension is the operation that extends a unary operation from its algebra to an extended algebra (which is an algebra of sets):
\[unaryExtn(op, S) := \{op(s)\ :\ s \in S \text{ where } op(s) \text{ is defined}\}\]- unary multi-extension
The unary multi-extension is the operation that extends a unary operation from its algebra to an extended algebra (which is an algebra of multisets). For this extension, the multiplicities do not change:
\[unaryExtn(op, \dot{S}) := \{op(s){:}\dot{S}(s)\ :\ s \in S \text{ where } op(s) \text{ is defined}\}\]- unary operation
- An operation with only one argument, typically with a result that belongs to the same ground set as the argument (when the operation is a member of an algebra).
- union
An operation on sets that creates a set by collecting the elements of two or more individual sets into a new set. In mathematical terms, if \(\mathbb{S}\) is a collection of sets, then the union of all of the sets in \(\mathbb{S}\) is denoted:
\[\bigcup \mathbb{S} = \bigcup_{T\in\mathbb{S}}T,\]and is the set \(\{x\ : \exists T \in \mathbb{S},\ x \in T\}\). If \(\mathbb{S}\) consists of only two sets, the union is called a binary union. If \(\mathbb{S}\) consists of a finite collection of sets, the union is called a finite union. See also Wikipedia: Union.
- Zermelo-Fraenkel set theory with choice (ZFC)
- A system of axioms on sets that is the standard form of set theory and the foundation of much of modern mathematics. See also Wikipedia: Zermelo-Fraenkel set theory with choice (ZFC).
Algebras¶
Definition
In mathematics (abstract algebra), an algebra (also referred to as an algebraic structure consists of a set (called the ground set, which is the set that contains the elements to which the algebra applies) with one or more operations (finitary operation) on the set such as:
- A set of binary operations (each with an optional identity element).
- A set of unary operations.
- A set of relations defined on the ground set.
The ground set combined with the set of operations and identity elements together is called the signature of the algebra.
Some types of algebras:
A semigroup is a non-empty set \(X\) together with a binary operation \(\ast\) which is associative.
A monoid is a semigroup \(X\) with an identity element \(e\) under \(\ast\). We call \(e\) and identity element if: \(\begin{equation*} x\ast e=e\ast x\text{ for all }x\in X. \end{equation*}\)
A group is a monoid where every element has an inverse under \(\ast\), namely, for each \(x\in X\) there exists a \(y\in X\) such that \(x\ast y=e=y\ast x\).
A Boolean algebra consists of a non-empty set \(B\) together with two binary operations we will call \(\oplus\) and \(\odot\), a unary operation \(^{*}\), and two distinguished elements \(\mathbf{0}\) and \(\mathbf{1}\) (these are not, in general, the integers 0 and 1) such that:
- \(\oplus\) and \(\odot\) are each commutative and associative, and each distributes over the other.
- For each \(x\in B\)
\[\begin{split}\begin{equation*} \begin{array}{lll} x\oplus \mathbf{0}=x & \text{ } & x\odot \mathbf{0}=\mathbf{0} \\ x\oplus \mathbf{1}=\mathbf{1} & \text{ } & x\odot \mathbf{1}=x \\ x\oplus x\text{*}=\mathbf{1} & \text{ } & x\odot x\text{*}=\mathbf{0}% \end{array}% . \end{equation*}\end{split}\]- For all \(x,y\in B\)
\[\begin{split}\begin{equation*} \begin{array}{lll} x\odot (x\oplus y)=x & \text{ } & x\oplus (x\odot y)=x% \end{array}% . \end{equation*}\end{split}\]
Algebra of Sets¶
Definition:
The algebra of sets is an algebra with the signature
Its ground set is the power set of set M (\(M\)). The binary operations are union (\(\cup\), with the identity element \(\varnothing\), the empty set) and intersection (\(\cap\), with the identity element \(M\)), the one unary operation is the complement (\('\)) and the one relation is the subset relation.
Other binary operations (that can be derived from the basic operations and relations) include difference, substriction and superstriction; other relations include the superset relation.
Remark and useful fact: The algebra of any non-empty set is always a Boolean algebra. This means that in particular the algebra on set M (\(M\)) is a Boolean algebra. It also true that any Boolean algebra with a finite ground set \(B\) is the algebra of some set.
Other useful operations on sets:
- The difference of two sets.
- The symmetric difference of two sets.
This gives us two alternative algebras of sets where we use difference and symmetric difference:
\[\bigg[ P(M),[-],[\bigtriangleup ],\subset ,^{\prime }\bigg]\]
and an extension
\[\bigg[ P(M), [\cup ,\varnothing ], [\cap ,M],[-], [\bigtriangleup ],\subset ,^{\prime } \bigg].\]
Identities concerning difference and symmetric difference: Given subsets \(S,T\) and \(U\) of set M (\(M\)):
- \(S-T=S\cap T^{\prime }\).
- \(S-S=\varnothing\).
- \(S-\varnothing =S\).
- \(\varnothing -S=\varnothing\).
- \(S-M=\varnothing\).
- \(M-S=S^{\prime }\).
- \(S\bigtriangleup T=T\bigtriangleup S\). (\(\bigtriangleup\) is commutative.)
- \(S\bigtriangleup (T\bigtriangleup U)=(S\bigtriangleup T)\bigtriangleup U\). (\(\bigtriangleup\) is associative.)
- \(S\bigtriangleup S=\varnothing\).
- \(S\bigtriangleup \varnothing =S\).
- \(S\bigtriangleup M=M-S=S^{\prime }\).
Algebra of Multisets¶
Multiset¶
Definition
A multiset is a set that allows multiple instances of any given element. We define it as a function from a given subset of set M (\(M\)) to the positive integers. In particular, we call \(\dot{S}\) a multiset of \(M\) if for certain \(x\in M\) we have \(\dot{S}(x)\) is a positive integer that we call the multiplicity of \(x\).
Example
Let \(M=\{a,b,c\}\) and \(\dot{S}\) represent the multiset \(\{a,a,a,b,b\}\), then we have \(\dot{S}(a)=3\), \(\dot{S}(b)=2\), and \(\dot{S}(c)\) is not defined. In this case \(a\) has multiplicity 3, and \(b\) has multiplicity 2.
Multiset Algebra¶
Definition
Let \(\dot{P}(M)\) represent the set of all multisets of \(M\). Using the definitions of multiset union, multiset addition, multiset intersection, and submultiset as applied to multisets we have an algebra on multisets with the following signature:
Algebra of Couplets¶
The algebra of couplets is an algebra with the signature
\[\bigg[ M \times M , \big\{\ \circ\ \big\} , \big\{ \leftrightarrow \big\} \bigg]\]
Its ground set is the Cartesian product of set M (\(M\)) with itself. The only binary operation is composition (\(\circ\), without identity element) and the only unary operation is the transposition (\(\leftrightarrow\)).
Algebra of Relations¶
Definition
The algebra of relations is the algebra of sets of couplets; its signature is
\[\bigg[ P(M \times M) , \big\{ [ \circ, D_M ] \big\} , \big\{ \leftrightarrow \big\} \bigg]\]
Its ground set is the power set of the Cartesian product of set M (\(M\)) with itself. The only binary operation is composition (\(\circ\), with the identity element \(D_M\), which is the diagonal on set M (\(M\))) and the only unary operation is the transposition (\(\leftrightarrow\)).
The binary operations union and intersection, the unary operation complement and the subset relation are implicitly present, inherited from the algebra of sets (since the algebra of relations is also an algebra of sets).
Other operations and relations (that can be derived from the basic operations and relations) include the binary operations difference, substriction, superstriction, left-functional union and right-functional union and the superset relation.
Algebra of Clans¶
Definition
The algebra of clans is the algebra of sets of relations, which is sets of sets couplets. Its ground set is therefore the second power set of the Cartesian product of set M (\(M\)) with itself. As a result of being a second power set, the operations of cross-union and cross-intersection can be applied, in addition to the operations on an algebra of sets. Moreover, the operations transposition and composition from the algebra of relations extend in a natural way to the algebra of clans. We also include substriction, superstriction, cross-substriction and cross-superstriction. As a result, it has the following signature:
Note that included in the operations of union and cross-union are the special left-functional and right-functional cases of cross-left-functional union and cross-right-functional union.
Algebra of Multiclans¶
Definition
The algebra of multiclans is an algebra that generalizes the algebra of clans. Since we use \(P(M \times M)\) to denote the set of couplets, a multiset of relations is a multiset of sets of couplets, so we will use \(\dot{P}(P(M \times M))\) to denote the multiset of relations. Combining the multiset algebra with the clan algebra we have
Here the binary operations are all binary multi-extensions of the operations from the algebra of clans, with the exception of multiset addition, and subset is replaced with submultiset. For example, cross-substriction is replaced with multi-cross-substriction. Note that there is no extension of the complement operation. As in the case of clans, the multiset versions of the operations of cross-left-functional union and cross-right-functional union are implied.
Extension¶
Definition
Given a set, or algebra \(S\), we say that \(T\) is an extension of \(S\), or extends \(S\), if one or more of the following holds:
- \(S \subseteq T\) and \(T\) has operations that \(S\) does not.
- \(S \subset T\) and any operation \(op\) on \(S\) can be obtained from an operation \(OP\) on \(T\) by restricting \(OP\) to elements only in \(S\).
For the purposes of data algebra, we will deal almost exclusively with algebras of sets and their extensions. Mathematically an algebra can be extended in many different ways. Below are some general examples, as well as some specific to data algebra.
Examples of extensions¶
Basic examples¶
- Any set \(S\) with no pre-defined operations on it extends to its set algebra: \(\bigg[P(S), \big \{ [ \cup, \varnothing ] , [ \cap, M ] \big\} , \big\{\ '\ \big\} , \big\{ \subset \big\} \bigg]\).
- Let \(\mathbb{Z}\) represent the set of integers, and \(\mathbb{Q}\) represent the set of rational numbers. The set \(\mathbb{Z}\) has a natural algebra under addition, and multiplication, and negation with signature: \(\bigg[ \mathbb{Z}, \big \{[+,0],[\cdot ,1]\}, \big \{-\}, \bigg]\). This algebra naturally extends to an algebra on the rational numbers with signature: \(\bigg[ \mathbb{Q}, \big \{[+,0],[\cdot ,1]\}, \big \{-\}, \bigg]\).
Examples from data algebra¶
The algebra of couplets on a set \(M\) with signature \(\bigg[ M \times M , \big\{\ \circ\ \big\} , \big\{ \leftrightarrow \big\} \bigg]\) extends to the algebra of relations \(\bigg[P(M \times M),\big\{[ \circ, D_M ] \big\} , \big\{ \leftrightarrow \big\}\bigg]\), where \(\circ\) is composition, \(\leftrightarrow\) is transposition, and \(D_M\) is the diagonal of \(M\).
The power set of a power set has an algebra given by the algebra of sets. Hence, if \(U\) is a set, we have an algebra with signature \(\bigg[ P^{2}(U),[\cup ,\varnothing ],[\mathbb{\cap },P(U)],\subset ,\prime \bigg]\). This algebra extends to the algebra \(\bigg[ P^{2}(U),[\cup ,\varnothing ],[\mathbb{\cap },P(U)], [\blacktriangledown ,\{\varnothing\}],[\mathbb{\blacktriangle },\{U\}],\subset ,\prime \bigg]\), where \(\blacktriangledown\) is the cross-intersection and \(\blacktriangle\) is the cross-union, which are binary extensions of intersection and union resprectively from \(P(U)\) to \(P^{2}(U)\). This is how we extend the algebra of relations to the algebra of clans.
An algebra of sets can also be extended to an algebra of multisets. In particular we can simply take binary multi-extensions of all of the binary operations, and replace subset with submultiset. We can also include multiset addition, but we will have to take out complement, as there is not multiset equivalent of that. Therefore, the algebra
\[\bigg[ P(M) , \big\{ [ \cup, \varnothing ] , [ \cap, M ] \big\} , \big\{\ '\ \big\} , \big\{ \subset \big\} \bigg]\]extends to
\[\bigg[\dot{P}(M), [\cup,\varnothing], [+,\varnothing],\cap,\subset \bigg].\]Similar to the previous example an algebra of clans can extend to an algebra of multiclans, by taking binary multi-extensions of all the operations. Hence, an algebra of clans with signature:
\[\bigg[ P^{2}(M \times M),[\cup ,\varnothing ],[\mathbb{\cap },P(M \times M)], [\blacktriangledown ,\{\varnothing\}],[\mathbb{\blacktriangle },\{M \times M\}], \vartriangleleft, \vartriangleright, \blacktriangleleft, \blacktriangleright, \subset , \prime \bigg]\]can be extended to an algebra of multiclans with signature
\[\bigg[ \dot{P}(P(M \times M)),[\cup ,\varnothing ],[+,\varnothing],\mathbb{\cap }, [\blacktriangledown ,\{\varnothing\}],[\mathbb{\blacktriangle },\{M \times M\}], \vartriangleleft, \vartriangleright, \blacktriangleleft, \blacktriangleright, \subset \bigg].\]
An example of adding set operations to an algebra with no given set structure¶
Let us take the algebra of integers with signature \(\bigg[ \mathbb{Z}, \big \{[+,0],[\cdot ,1]\}, \big \{-\}, \bigg]\) as in an earlier example. Since \(\mathbb{Z}\) is a set, it also posesses the set algebra \(\bigg[P(\mathbb{Z}), \big \{ [ \cup, \varnothing ] , [ \cap, M ] \big\} , \big\{\ '\ \big\} , \big\{ \subset \big\} \bigg]\). We can extend \(\bigg[ \mathbb{Z}, \big \{[+,0],[\cdot ,1]\}, \big \{-\}, \bigg]\) to the set algebra by defining addition, multiplication, and negation on subsets of \(\mathbb{Z}\) as follows: Given subsets \(A,B\subset\mathbb{Z}\)
\[\begin{split}\begin{align*} A + B &:= \{c \in \mathbb{Z} : c = a + b \text{ for some }a \in A \text{ and for some } b \in B\} \\ A \cdot B &:= \{c \in \mathbb{Z} : c = a \cdot b \text{ for some } a \in A \text{ and for some } b \in B\} \\ -A &:= \{c \in \mathbb{Z} : c = -a \text{ for some } a \in A\} \end{align*}\end{split}\]In words, the above equations say that over the integers:
- The sum of sets is the set of sums.
- The product of sets the set of products.
- The negative of a set is the set of negatives.
So for example if \(A=\{3,-5,9\}\) and \(B=\{4,12\}\), then
\[\begin{split}\begin{eqnarray*} \{3,-5,9\}+\{4,12\} &=&\left\{ \begin{array}{c} 3+4,3+12, \\ -5+4,-5+12, \\ 9+4,9+12% \end{array}% \right\} \\ &=&\left\{ \begin{array}{c} 7,15, \\ -1,7, \\ 13,21% \end{array}% \right\} \\ &=&\{7,15,-1,13,21\}. \end{eqnarray*}\end{split}\]and,
\[\begin{split}\begin{eqnarray*} \{3,-5,9\}\cdot \{4,12\} &=&\left\{ \begin{array}{c} 3\cdot 4,3\cdot 12, \\ -5\cdot 4,-5\cdot 12, \\ 9\cdot 4,9\cdot 12% \end{array}% \right\} \\ &=&\left\{ \begin{array}{c} 12,36, \\ -20,-60, \\ 36,108% \end{array}% \right\} \\ &=&\{12,36,-20,-60,36,108\}. \end{eqnarray*}\end{split}\]and
\[-A=-\{3,-5,9\}=\{-3,5,-9\}\]In conclusion, this shows that the algebra \(\bigg[ \mathbb{Z}, \big \{[+,0],[\cdot ,1]\}, \big \{-\}, \bigg]\) extends to the algebra
\[\begin{equation*} \bigg[ P(\mathbb{Z}),\{[\cup ,\varnothing ],[\mathbb{\cap },% \mathbb{Z}],[+,\{0\}],[\cdot ,\{1\}]\},\{-,^{\prime }\},\{\subset \}\bigg] , \end{equation*}\]
This page is here to help review notation and terminology for those new to, or requiring a refresher, of sets and set theory.
Set Notation¶
Recall that a set is a collection of distinct objects. In any given set each object in the set is called an element of the set.
For example, if \(S\) represents a set, and \(a\) is an element of set \(S\), we denote this by writing
\[a \in S.\]
If \(a\) is not an element of set \(S\), we write it as
\[a \not\in S.\]
We can more explicitly write out what the specific elements of a set are by using braces: \(\{,\}\). For example, if I wanted \(S\) to be the set of integers between 2 and 6 inclusively, then I can write
\[S = \{2,3,4,5,6\}.\]
There is also the set with no elements at all in it, and it is called the empty set, and is denoted by \(\emptyset\). Other ways of denoting are by using \(\varnothing\), or even \(\{\}\).
We also use colons to represent conditions on elements in a particular set. This lets us build up more complicated sets. For example, if I use \(\mathbb{Z}\) to represent the set of all integers, then if I want \(T\) to represent the set of all integers greater than five, I can write it as
\[\begin{split}T = \{n \in \mathbb{Z} : n > 5\}.\end{split}\]
Colons in combination with braces and \(\in\) is called set builder notation and lets us create very complicated sets. Let’s say I want to create the set of all irrational numbers, then I can do this by starting with the sets of real numbers, rational numbers, and using set builder notation:
Let \(\mathbb{R}\) represent the set of real numbers, and \(\mathbb{Q}\) the set of rational numbers, then if we use \(X\) to represent the set of irrational numbers, we can write it as
\[X = \{ r \in \mathbb{R} : r \not\in \mathbb{Q} \}.\]
We can add even more conditions. Let us use \(Y\) to represent the set of negative rational numbers, then we can write it as
\[\begin{split}Y = \{ r \in\mathbb{R} : r\not\in\mathbb{Q}\ \&\ r<0 \},\end{split}\]
or alternatively by going back to \(X\) and saying
\[\begin{split}Y = \{ x \in X : x<0 \}.\end{split}\]
To help write conditions precisely without creating too much clutter, we will sometimes use symbols to represent logical quantifiers such as \(\exists\) to say “there exists” or \(\forall\) to represent “for all”. For example, if we wanted to say that a set \(S\) was a subset of a set \(T\), that is, any element of \(S\) is also an element of \(T\), we can write that as
\[\forall x, x \in S \implies x \in T.\]
See also set notation and set (mathematics) for more information.