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:
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
()[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
()[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
()[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
()[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
()¶ 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
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
()[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
()[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
()[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
()[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
()[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
()[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
()[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
()[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
()[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
()[source]¶ Return a relation where the couplets are the elements of
dict1
.