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, or Undef() if rel is not a relation.
static compose()[source]

Return the composition of rel1 with rel2.

Returns:The binary extension of composition from the algebra of couplets to the algebra of relations, applied to the relations rel1 and rel2, or Undef() if rel1 or rel2 are not relations.
static functional_union()[source]

Return the union of rel1 and rel2 if it is a function, otherwise Undef().

Returns:The functional union of the relations rel1 and rel2; that is, the union if the result is a function, otherwise Undef(). Also return Undef() if rel1 or rel2 are not relations.
static right_functional_union()[source]

Return the union of rel1 and rel2 if it is right-functional, otherwise Undef().

Returns:The right-functional union of the relations rel1 and rel2; that is, the union if the result is right-functional, otherwise Undef(). Also return Undef() if rel1 or rel2 are not relations.
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 if obj is a relation, False if not.

Note

This function may call get_ground_set() on obj. 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 if obj is either a relation or Undef, False if not.
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 if obj is an absolute relation, False if not.

Note

This function may call get_ground_set() on obj. 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 or Undef() if rel 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 or Undef() if rel 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 component left.

Returns:The right set of the relation rel associated with the left component or Undef() if rel 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, or Undef() if there is not exactly one couplet with the left component left in rel or rel 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, or Undef() if there is not exactly one couplet with the right component right in rel or rel 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 if rel is a function, False if not, or Undef() if rel is not a relation.
algebraixlib.algebras.relations.is_right_functional(rel, _checked=True) → bool[source]

Return whether rel is right-functional.

Returns:True if rel is right-functional, False if not, or Undef() if rel is not a relation.
algebraixlib.algebras.relations.is_reflexive(rel, _checked=True) → bool[source]

Return whether rel is reflexive.

Returns:True if rel is reflexive, False if it is not, or Undef() if rel is not a relation.
algebraixlib.algebras.relations.is_symmetric(rel, _checked=True) → bool[source]

Return whether rel is symmetric.

Returns:True if rel is symmetric, False if it is not, or Undef() if rel is not a relation.
algebraixlib.algebras.relations.is_transitive(rel, _checked=True) → bool[source]

Return whether rel is transitive.

Returns:True if rel is transitive, False if it is not, or Undef() if rel is not a relation.
algebraixlib.algebras.relations.fill_lefts()[source]

Return the left components in rel that are missing in renames as a diagonal unioned with renames.

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:
Returns:

A relation that contains all members of renames unioned with a diagonal that consists of all left components in rel that are missing in renames.

algebraixlib.algebras.relations.rename()[source]

Return a relation where left components in rel are renamed according to renames.

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 in rel.
Returns:

A version of rel where some left components of the member couplets are changed (renamed), according to renames.

algebraixlib.algebras.relations.swap()[source]

Return a relation where components in rel are swapped according to swaps.

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 to swaps.

algebraixlib.algebras.relations.functional_add()[source]

Add element to func and return the new functional relation.

Parameters:
Returns:

The new relation, composed of func and element.

algebraixlib.algebras.relations.from_dict()[source]

Return a relation where the couplets are the elements of dict1.

algebraixlib.algebras.relations.diag()[source]

Return the diagonal of the set comprising the elements in *args.

algebraixlib.algebras.relations.defined_at(rel, left, _checked=True)[source]

Return rel if it has a couplet with left component left else Undef().