algebraixlib.algebras.relations module¶
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:
objectProvide 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()[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()ifrelis not a relation.
-
static
compose()[source]¶ Return the composition of
rel1withrel2.Returns: The binary extension of composition from the algebra of couplets to the algebra of relations, applied to the relations rel1andrel2, orUndef()ifrel1orrel2are not relations.
-
static
functional_union()[source]¶ Return the union of
rel1andrel2if it is a function, otherwiseUndef().Returns: The functional union of the relations rel1andrel2; that is, the union if the result is a function, otherwiseUndef(). Also returnUndef()ifrel1orrel2are not relations.
-
static
right_functional_union()[source]¶ Return the union of
rel1andrel2if it is right-functional, otherwiseUndef().Returns: The right-functional union of the relations rel1andrel2; that is, the union if the result is right-functional, otherwiseUndef(). Also returnUndef()ifrel1orrel2are not relations.
-
static
-
algebraixlib.algebras.relations.transpose()¶ Convenience redirection to
Algebra.transpose.
-
algebraixlib.algebras.relations.compose()¶ Convenience redirection to
Algebra.compose.
-
algebraixlib.algebras.relations.functional_union()¶ Convenience redirection to
Algebra.functional_union.
-
algebraixlib.algebras.relations.right_functional_union()¶ 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
objis a member of the ground set of this algebra.return: Trueifobjis a relation,Falseif 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
objis either a member of the ground set of this algebra - or
Undef.
Returns: Trueifobjis either a relation orUndef,Falseif not.- Return whether
-
algebraixlib.algebras.relations.is_absolute_member(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]¶ Return whether
objis a member of the absolute ground set of this algebra.return: Trueifobjis an absolute relation,Falseif not.Note
This function may call
get_ground_set()onobj. The result of this operation is cached.
-
algebraixlib.algebras.relations.get_lefts()[source]¶ Return the set of the left components of all couplets in the relation
rel.Returns: The left set of the relation relorUndef()ifrelis not a relation.
-
algebraixlib.algebras.relations.get_rights()[source]¶ Return the set of the right components of all couplets in the relation
rel.Returns: The right set of the relation relorUndef()ifrelis not a relation.
-
algebraixlib.algebras.relations.get_rights_for_left()[source]¶ Return the set of the right components of all couplets in the relation
relassociated with the left componentleft.Returns: The right set of the relation relassociated with the left component orUndef()ifrelis not a relation.
-
algebraixlib.algebras.relations.get_right()[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 componentleftinrelorrelis not a relation.
-
algebraixlib.algebras.relations.get_left()[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 componentrightinrelorrelis not a relation.
-
algebraixlib.algebras.relations.is_functional(rel, _checked=True) → bool[source]¶ Return whether
relis left-functional (is a function).Returns: Trueifrelis a function,Falseif not, orUndef()ifrelis not a relation.
-
algebraixlib.algebras.relations.is_right_functional(rel, _checked=True) → bool[source]¶ Return whether
relis right-functional.Returns: Trueifrelis right-functional,Falseif not, orUndef()ifrelis not a relation.
-
algebraixlib.algebras.relations.is_reflexive(rel, _checked=True) → bool[source]¶ Return whether
relis reflexive.Returns: Trueifrelis reflexive,Falseif it is not, orUndef()ifrelis not a relation.
-
algebraixlib.algebras.relations.is_symmetric(rel, _checked=True) → bool[source]¶ Return whether
relis symmetric.Returns: Trueifrelis symmetric,Falseif it is not, orUndef()ifrelis not a relation.
-
algebraixlib.algebras.relations.is_transitive(rel, _checked=True) → bool[source]¶ Return whether
relis transitive.Returns: Trueifrelis transitive,Falseif it is not, orUndef()ifrelis not a relation.
-
algebraixlib.algebras.relations.fill_lefts()[source]¶ Return the left components in
relthat are missing inrenamesas 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
renamesunioned with a diagonal that consists of all left components inrelthat are missing inrenames.
-
algebraixlib.algebras.relations.rename()[source]¶ Return a relation where left components in
relare 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
reland the left components are the new left components to use inrel.
Returns: A version of
relwhere some left components of the member couplets are changed (renamed), according torenames.
-
algebraixlib.algebras.relations.swap()[source]¶ Return a relation where components in
relare 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
relwhere some left components of the member couplets are swapped, according toswaps.
-
algebraixlib.algebras.relations.functional_add()[source]¶ Add
elementtofuncand 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 aCoupletand its left component must not be a left component infunc.
Returns: The new relation, composed of
funcandelement.- 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()[source]¶ Return a relation where the couplets are the elements of
dict1.