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. Install as pip install algebraixlib or download the package.
  • On GitHub. Here you can get the full sources and use the bug tracker.
  • On Wakari.io. Some of the IPython notebooks that are published on GitHub are available here.
  • On Algebraix Data Corporation‘s project page. Here you find support information.

API Documentation

algebraixlib package

The top-level package for algebraixlib.

Subpackages

algebraixlib.algebras package

This package contains modules that represent algebras and their operations.

To the mathematical operations of a given algebra, we also add:

  • Functions that return metadata. (For example, all our algebras contain an is_member function that returns True 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 based on sets that are provided are:

The algebras based on multisets that are provided are:

Submodules
algebraixlib.algebras.clans module

This module contains the algebra of clans.

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 the transposition of the clan clan.

Returns:The unary extension of transposition from the algebra of relations to the algebra of clans, applied to clan, or Undef() if clan 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 with clan2.

Returns:The binary extension of composition from the algebra of relations to the algebra of clans, applied to clan1 and clan2, or Undef() if clan1 or clan2 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 and clan2.

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 and clan2, or Undef() if clan1 or clan2 are not clans.
static functional_cross_union(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'[source]

Return the left-functional cross-union of clan1 and clan2.

Returns:The binary extension of the left-functional union from the algebra of relations to the algebra of clans, applied to clan1 and clan2, or Undef() if clan1 or clan2 are not clans.
static lhs_functional_cross_union(lhs: 'PP( MxM )', rhs: 'PP( MxM )', _checked=True)[source]

This data manipulations preforms a left functional cross union, then unions the left hand side elements that were not cross unioned.

Parameters:
  • lhs – The priority left hand clan for this operation
  • rhs – The right hand clan to preform the cross union with
Returns:

PP(MxM) resulting math object

static right_functional_cross_union(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'[source]

Return the right-functional cross-union of clan1 and clan2.

Returns:The binary extension of the right-functional union from the algebra of relations to the algebra of clans, applied to clan1 and clan2, or Undef() if clan1 or clan2 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 and clan2.

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 and clan2, or Undef() if clan1 or clan2 are not clans.
static substrict(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'[source]

Return the binary extension of substriction of clan1 and clan2.

Returns:The binary extension of substriction from the algebra of relations (which inherits it from the algebra of sets) to the algebra of clans applied to clan1 and clan2, or Undef() if clan1 or clan2 are not clans.
static superstrict(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'[source]

Return a Set of every element of clan1 that is a superset of any element of clan2.

Returns:The binary extension of superstriction from the algebra of relations (which inherits it from the algebra of sets) to the algebra of clans applied to clan1 and clan2, or Undef() if clan1 or clan2 are not clans.
algebraixlib.algebras.clans.transpose(clan: 'PP(M x M)', _checked=True) → 'PP(M x M)'

Return the transposition of the clan clan.

Returns:The unary extension of transposition from the algebra of relations to the algebra of clans, applied to clan, or Undef() if clan is not a clan.
algebraixlib.algebras.clans.compose(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'

Return the composition of clan1 with clan2.

Returns:The binary extension of composition from the algebra of relations to the algebra of clans, applied to clan1 and clan2, or Undef() if clan1 or clan2 are not clans.
algebraixlib.algebras.clans.cross_union(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'

Return the cross-union of clan1 and clan2.

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 and clan2, or Undef() if clan1 or clan2 are not clans.
algebraixlib.algebras.clans.functional_cross_union(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'

Return the left-functional cross-union of clan1 and clan2.

Returns:The binary extension of the left-functional union from the algebra of relations to the algebra of clans, applied to clan1 and clan2, or Undef() if clan1 or clan2 are not clans.
algebraixlib.algebras.clans.lhs_functional_cross_union(lhs: 'PP( MxM )', rhs: 'PP( MxM )', _checked=True)

This data manipulations preforms a left functional cross union, then unions the left hand side elements that were not cross unioned.

Parameters:
  • lhs – The priority left hand clan for this operation
  • rhs – The right hand clan to preform the cross union with
Returns:

PP(MxM) resulting math object

algebraixlib.algebras.clans.right_functional_cross_union(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'

Return the right-functional cross-union of clan1 and clan2.

Returns:The binary extension of the right-functional union from the algebra of relations to the algebra of clans, applied to clan1 and clan2, or Undef() if clan1 or clan2 are not clans.
algebraixlib.algebras.clans.cross_intersect(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'

Return the cross-intersection of clan1 and clan2.

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 and clan2, or Undef() if clan1 or clan2 are not clans.
algebraixlib.algebras.clans.substrict(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'

Return the binary extension of substriction of clan1 and clan2.

Returns:The binary extension of substriction from the algebra of relations (which inherits it from the algebra of sets) to the algebra of clans applied to clan1 and clan2, or Undef() if clan1 or clan2 are not clans.
algebraixlib.algebras.clans.superstrict(clan1: 'PP(M x M)', clan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'

Return a Set of every element of clan1 that is a superset of any element of clan2.

Returns:The binary extension of superstriction from the algebra of relations (which inherits it from the algebra of sets) to the algebra of clans applied to clan1 and clan2, or Undef() if clan1 or clan2 are not clans.
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 True if obj is a member of the ground set of this algebra.

Note

This function calls get_ground_set() on obj.

algebraixlib.algebras.clans.is_absolute_member(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return True if obj is a member of the absolute ground set of this algebra.

return:True if obj is an absolute clan.

Note

This function calls get_ground_set() on obj.

algebraixlib.algebras.clans.get_lefts(clan: 'PP(M x M)', _checked=True) → 'P( M )'[source]

Return the left set of this clan.

Returns:The union of the left sets of all relations in the clan or Undef() if clan is not a clan.
algebraixlib.algebras.clans.get_rights(clan: 'PP(M x M)', _checked=True) → 'P( M )'[source]

Return the right set of this clan.

Returns:The union of the right sets of all relations in the clan or Undef() if clan is not a clan.
algebraixlib.algebras.clans.is_left_regular(clan, _checked=True) → bool[source]

Return True if clan is left-regular.

Returns:True if clan is left-regular or Undef() if clan is not a clan.
algebraixlib.algebras.clans.project(clan: 'PP(M x M)', *lefts) → 'PP(M x M)'[source]

Return a clan with the left components from clan with the values in lefts. See project.

Parameters:
  • clan – The source data. Must be a clan.
  • lefts – The names of the lefts to return. (If you want to pass in an iterable, you need to prefix it with a *.)
Returns:

A clan with only the lefts as indicated by lefts.

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

A clan where every relation consists of a single couplet with a left component of left and a right component from values.

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) → 'PP(M x M)'[source]

Return a ‘clan diagonal‘ of the arguments.

algebraixlib.algebras.clans.defined_at(clan, left)[source]

Return the portion of clan where relations in clan are defined for left

algebraixlib.algebras.couplets module

This module contains the algebra of couplets.

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.

Returns:The transposition of couplet or Undef() if couplet is not an instance of Couplet.
static compose(couplet1: '(M x M)', couplet2: '(M x M)', _checked=True) → '(M x M)'[source]

Return the composition of couplet1 with couplet2.

Returns:The composition of couplet1 with couplet2 (which may be undefined, in which case the result is Undef()) or Undef() if couplet1 or couplet2 are not instances of Couplet.
algebraixlib.algebras.couplets.transpose(couplet: '(M x M)', _checked=True) → '(M x M)'

Return the transposition of couplet.

Returns:The transposition of couplet or Undef() if couplet is not an instance of Couplet.
algebraixlib.algebras.couplets.compose(couplet1: '(M x M)', couplet2: '(M x M)', _checked=True) → '(M x M)'

Return the composition of couplet1 with couplet2.

Returns:The composition of couplet1 with couplet2 (which may be undefined, in which case the result is Undef()) or Undef() if couplet1 or couplet2 are not instances of Couplet.
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 True if obj is a member of the ground set of this algebra.

Returns:True if obj is an instance of Couplet.
algebraixlib.algebras.couplets.is_absolute_member(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return True if obj is a member of the absolute ground set of this algebra.

return:True if obj is an absolute couplet.

Note

This function calls get_ground_set() on obj.

algebraixlib.algebras.multiclans module

This module contains the algebra of multiclans.

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 the transposition of the multiclan multiclan.

Returns:The unary extension of transposition from the algebra of relations to the algebra of multiclans, applied to multiclan, or Undef() if multiclan 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 with multiclan2.

Returns:The binary multi-extension of composition from the algebra of relations to the algebra of multiclans, applied to multiclan1 and multiclan2, or Undef() if multiclan1 or multiclan2 are not multiclans.
static cross_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-union of multiclan1 and multiclan2.

Returns:The binary multi-extension of union from the algebra of relations (which inherits it from the algebra of multisets) to the algebra of multiclans applied to multiclan1 and multiclan2, or Undef() if multiclan1 or multiclan2 are not multiclans.
static functional_cross_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 left-functional cross-union of multiclan1 and multiclan2.

Returns:The binary multi-extension of the left-functional union from the algebra of relations to the algebra of multiclans, applied to multiclan1 and multiclan2, or Undef() if multiclan1 or multiclan2 are not multiclans.
static right_functional_cross_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 right-functional cross-union of multiclan1 and multiclan2.

Returns:The binary multi-extension of the right-functional union from the algebra of relations to the algebra of multiclans, applied to multiclan1 and multiclan2, or Undef() if multiclan1 or multiclan2 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 and multiclan2.

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 and multiclan2, or Undef() if multiclan1 or multiclan2 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 binary extension of substriction of multiclan1 and multiclan2.

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 and multiclan2, or Undef() if multiclan1 or multiclan2 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 binary multi-extension of superstriction of multiclan1
and multiclan2.
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 and multiclan2, or Undef() if multiclan1 or multiclan2 are not multiclans.
algebraixlib.algebras.multiclans.transpose(multiclan: 'P(P(M x M) x N)', _checked=True) → 'P(P(M x M) x N)'

Return the transposition of the multiclan multiclan.

Returns:The unary extension of transposition from the algebra of relations to the algebra of multiclans, applied to multiclan, or Undef() if multiclan is not a multiclan.
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)'

Return the composition of multiclan1 with multiclan2.

Returns:The binary multi-extension of composition from the algebra of relations to the algebra of multiclans, applied to multiclan1 and multiclan2, or Undef() if multiclan1 or multiclan2 are not multiclans.
algebraixlib.algebras.multiclans.cross_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)'

Return the cross-union of multiclan1 and multiclan2.

Returns:The binary multi-extension of union from the algebra of relations (which inherits it from the algebra of multisets) to the algebra of multiclans applied to multiclan1 and multiclan2, or Undef() if multiclan1 or multiclan2 are not multiclans.
algebraixlib.algebras.multiclans.functional_cross_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)'

Return the left-functional cross-union of multiclan1 and multiclan2.

Returns:The binary multi-extension of the left-functional union from the algebra of relations to the algebra of multiclans, applied to multiclan1 and multiclan2, or Undef() if multiclan1 or multiclan2 are not multiclans.
algebraixlib.algebras.multiclans.right_functional_cross_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)'

Return the right-functional cross-union of multiclan1 and multiclan2.

Returns:The binary multi-extension of the right-functional union from the algebra of relations to the algebra of multiclans, applied to multiclan1 and multiclan2, or Undef() if multiclan1 or multiclan2 are not multiclans.
algebraixlib.algebras.multiclans.cross_intersect(multiclan1: 'P(P(M x M) x N)', multiclan2: 'PP(M x M)', _checked=True) → 'PP(M x M)'

Return the cross-intersection of multiclan1 and multiclan2.

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 and multiclan2, or Undef() if multiclan1 or multiclan2 are not multiclans.
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)'

Return the binary extension of substriction of multiclan1 and multiclan2.

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 and multiclan2, or Undef() if multiclan1 or multiclan2 are not multiclans.
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)'
Return the binary multi-extension of superstriction of multiclan1
and multiclan2.
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 and multiclan2, or Undef() if multiclan1 or multiclan2 are not multiclans.
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 True if obj is a member of the ground set of this algebra.

Note

This function calls get_ground_set() on obj.

algebraixlib.algebras.multiclans.is_absolute_member(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return True if obj is a member of the absolute ground set of this algebra.

return:True if obj is an absolute clan.

Note

This function calls get_ground_set() on obj.

algebraixlib.algebras.multisets module

This module contains the algebra of multisets.

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 binary union of multiset1 with multiset2.

Returns:The union of multiset1 and multiset2 or Undef() if multiset1 or multiset2 are not instances of Multiset.
static intersect(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'[source]

Return the binary intersection of multiset1 with multiset2.

Returns:The intersection of multiset1 and multiset2 or Undef() if multiset1 or multiset2 are not instances of Multiset.
static minus(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'[source]

Return the difference of multiset1 and multiset2.

Returns:The difference of multiset1 and multiset2 or Undef() if multiset1 or multiset2 are not instances of Multiset.
static addition(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'[source]

Return the addition of multiset1 and multiset2.

Returns:The addition of multiset1 and multiset2 or Undef() if multiset1 or multiset2 are not instances of Multiset.
static substrict(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'[source]

Return the substriction of multiset1 and multiset2.

Returns:multiset1 if multiset1 is a subset of multiset2 or Undef() if not. Also return Undef() if multiset1 or multiset2 are not instances of Set.
static superstrict(multiset1: 'P( M x N )', multiset2: 'P( M X N )', _checked=True) → 'P( M X N )'[source]

Return the superstriction of multiset1 and multiset2.

Returns:multiset1 if multiset1 is a superset of multiset2 or Undef() if not. Also return Undef() if multiset1 or multiset2 are not instances of Multiset.
static is_subset_of(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → bool[source]

Return whether multiset1 is a subset of multiset2.

Returns:True if multiset1 is a subset of multiset2, False if not. Return Undef() if multiset1 or multiset2 are not instances of Multiset.
static is_superset_of(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → bool[source]

Return whether multiset1 is a superset of multiset2.

Returns:True if multiset1 is a superset of multiset2, False if not. Return Undef() if multiset1 or multiset2 are not instances of Multiset.

Note

Reasonably up to date up to here. I haven’t yet worked on the rest.

algebraixlib.algebras.multisets.union(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'

Return the binary union of multiset1 with multiset2.

Returns:The union of multiset1 and multiset2 or Undef() if multiset1 or multiset2 are not instances of Multiset.
algebraixlib.algebras.multisets.intersect(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'

Return the binary intersection of multiset1 with multiset2.

Returns:The intersection of multiset1 and multiset2 or Undef() if multiset1 or multiset2 are not instances of Multiset.
algebraixlib.algebras.multisets.minus(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'

Return the difference of multiset1 and multiset2.

Returns:The difference of multiset1 and multiset2 or Undef() if multiset1 or multiset2 are not instances of Multiset.
algebraixlib.algebras.multisets.addition(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'

Return the addition of multiset1 and multiset2.

Returns:The addition of multiset1 and multiset2 or Undef() if multiset1 or multiset2 are not instances of Multiset.
algebraixlib.algebras.multisets.substrict(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → 'P( M x N )'

Return the substriction of multiset1 and multiset2.

Returns:multiset1 if multiset1 is a subset of multiset2 or Undef() if not. Also return Undef() if multiset1 or multiset2 are not instances of Set.
algebraixlib.algebras.multisets.superstrict(multiset1: 'P( M x N )', multiset2: 'P( M X N )', _checked=True) → 'P( M X N )'

Return the superstriction of multiset1 and multiset2.

Returns:multiset1 if multiset1 is a superset of multiset2 or Undef() if not. Also return Undef() if multiset1 or multiset2 are not instances of Multiset.
algebraixlib.algebras.multisets.is_subset_of(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → bool

Return whether multiset1 is a subset of multiset2.

Returns:True if multiset1 is a subset of multiset2, False if not. Return Undef() if multiset1 or multiset2 are not instances of Multiset.
algebraixlib.algebras.multisets.is_superset_of(multiset1: 'P( M x N )', multiset2: 'P( M x N )', _checked=True) → bool

Return whether multiset1 is a superset of multiset2.

Returns:True if multiset1 is a superset of multiset2, False if not. Return Undef() if multiset1 or multiset2 are not instances of Multiset.

Note

Reasonably up to date up to here. I haven’t yet worked on the rest.

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 True if obj is a member of the ground set of this algebra.

Returns:True if obj is an instance of Multiset.
algebraixlib.algebras.multisets.is_absolute_member(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return True if obj is a member of the absolute ground set of this algebra.

return:True if obj is an absolute set.

Note

This function calls get_ground_set() on obj.

algebraixlib.algebras.multisets.demultify(multiset: 'P( M x N )', _checked=True) → 'P( M )'[source]
algebraixlib.algebras.multisets.big_union(multiset: 'PP( M x N )', _checked=True) → 'P( M x N )'[source]

Return the union of all members of multiset.

Returns:The union of all members of multiset or Undef() if multiset or any of its members are not instances of Multiset.
algebraixlib.algebras.multisets.big_intersect(multisets: 'PP( M x N )', _checked=True) → 'P( M x N )'[source]

Return the intersection of all members of multiset.

Returns:The intersection of all members of multiset or Undef() if multiset or any of its members are not instances of Multiset.
algebraixlib.algebras.relations module

This module contains the algebra of relations and related functionality.

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 the left components and right components of all couplets are 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(rel1: 'P(M x M)', rel2: 'P(M x M)', _checked=True) → 'P(M x M)'[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(rel1: 'P(M x M)', rel2: 'P(M x M)', _checked=True) → 'P(M x M)'[source]

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

Returns:The left-functional union of the relations rel1 and rel2; that is, the union if the result is left-functional, otherwise Undef(). Also return Undef() if rel1 or rel2 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 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(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 True if obj is a member of the ground set of this algebra.

Note

This function may call get_ground_set() on obj. The result of this operation is cached.

algebraixlib.algebras.relations.is_absolute_member(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return True if obj is a member of the absolute ground set of this algebra.

return:True if obj is an absolute relation.

Note

This function calls get_ground_set() on obj.

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 or Undef() if rel 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 or Undef() if rel is not a relation.
algebraixlib.algebras.relations.get_right(rel: 'P(M x M)', left: '( M )', _checked=True) → '( M )'[source]

Return the single right component associated with the left component left.

In general, use with left-functional relations; that is, relations where all left components appear at most once.

Returns:The single right component associated with the left component left, or Undef() if there is not exactly one element with the left component left in rel or rel is not a relation.
algebraixlib.algebras.relations.get_left(rel: 'P(M x M)', right: '( M )', _checked=True) → '( M )'[source]

Return the single left component associated with the right component right.

In general, use with right-functional relations; that is, relations where all right components appear at most once.

Returns:The single left component associated with the right component right, or Undef() if there is not exactly one element with the right component right in rel or rel is not a relation.
algebraixlib.algebras.relations.is_left_functional(rel, _checked=True) → bool[source]

Return True if rel is left-functional.

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

Return True if rel is right-functional.

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

Return True if rel is reflexive.

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

Return True if rel is symmetric.

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

Return True if rel is transitive.

Returns:True if rel is transitive or Undef() if rel 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 in renames as a diagonal unioned with renames.

Parameters:
Returns:

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

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 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 the left components of the member couplets are renamed.

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 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 the left components of the member couplets are swapped.

algebraixlib.algebras.relations.functional_add(rel: 'P(M x M)', element: 'M x M') → 'P(M x M)'[source]

Add element to rel and return the new relation.

Parameters:
Returns:

The new relation, composed of rel and element.

algebraixlib.algebras.relations.from_dict(dict1: dict) → 'P(M x M)'[source]

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

algebraixlib.algebras.relations.diag(*args) → 'P(M x M)'[source]

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

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

Return the rel if it is defined at left else Undef().

algebraixlib.algebras.sets module

This module contains the algebra of sets and related functionality.

class algebraixlib.algebras.sets.Algebra[source]

Bases: object

Provide the operations and relations that are members of the algebra of sets.

This class contains only static member functions. Its main purpose is to provide a namespace for and highlight the operations and relations that belong to the algebra of sets. All member functions are also available at the enclosing module level.

static union(set1: 'P( M )', set2: 'P( M )', _checked=True) → 'P( M )'[source]

Return the union of set1 with set2.

Returns:The binary union of set1 and set2 or Undef() if set1 or set2 are not sets (that is, instances of Set).
static intersect(set1: 'P( M )', set2: 'P( M )', _checked=True) → 'P( M )'[source]

Return the intersection of set1 with set2.

Returns:The binary intersection of set1 and set2 or Undef() if set1 or set2 are not sets (that is, instances of Set).
static minus(set1: 'P( M )', set2: 'P( M )', _checked=True) → 'P( M )'[source]

Return the set difference of set1 and set2.

Returns:The difference of set1 and set2 or Undef() if set1 or set2 are not sets (that is, instances of Set).
static substrict(set1: 'P( M )', set2: 'P( M )', _checked=True) → 'P( M )'[source]

Return set1 if it is a subset of set2, otherwise return Undef().

Returns:Return the substriction of set1 and set1; that is, return set1 if it is a subset of set2 or Undef() if not. Also return Undef() if set1 or set2 are not sets (that is, instances of Set).
static superstrict(set1: 'P( M )', set2: 'P( M )', _checked=True) → 'P( M )'[source]

Return set1 if it is a superset of set2, otherwise return Undef().

Returns:Return the superstriction of set1 and set1; that is, return set1 if it is a subset of set2 or Undef() if not. Also return Undef() if set1 or set2 are not sets (that is, instances of Set).
static is_subset_of(set1: 'P( M )', set2: 'P( M )', _checked=True) → bool[source]

Return whether set1 is a subset of set2.

Returns:True if set1 is a subset of set2, False if not. Return Undef() if set1 or set2 are not sets (that is, instances of Set).
static is_superset_of(set1: 'P( M )', set2: 'P( M )', _checked=True) → bool[source]

Return whether set1 is a superset of set2.

Returns:True if set1 is a superset of set2, False if not. Return Undef() if set1 or set2 are not sets (that is, instances of Set).
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 True if obj is a member of the ground set of this algebra.

Returns:True if obj is an instance of Set.
algebraixlib.algebras.sets.is_absolute_member(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return True if obj is a member of the absolute ground set of this algebra.

return:True if obj is an absolute set.

Note

This function calls get_ground_set() on obj.

algebraixlib.algebras.sets.multify(set1: 'P( M )', _checked=True) → 'P( M x N )'[source]

Return a multiset based on set1 where all multiples are set to 1.

algebraixlib.algebras.sets.big_union(set1: 'PP( M )', _checked=True) → 'P( M )'[source]

Return the union of all members of set1.

Returns:The union of all members of set1 or Undef() if set1 or any of its members are not instances of Set.

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(set1: 'PP( M )', _checked=True) → 'P( M )'[source]

Return the intersection of all members of set1.

Returns:The intersection of all members of set1 or Undef() if set1 or any of its members are not instances of Set.

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(set1: algebraixlib.mathobjects.set.Set)[source]

Return the single element of set1.

Returns:Return the single element of set1, or Undef() if set1 has not exactly one element or is not a set (that is, an instance of Set).
algebraixlib.algebras.sets.some(set1: algebraixlib.mathobjects.set.Set)[source]

Return ‘some’ element of set1. Use with caution - may be non-deterministic.

Returns:Some element of set1, or Undef() if set1 is empty or is not a set (that is, an instance of Set).

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 set1 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 set1 is retrieved, because the expressions that consume that value will be invariant w.r.t. some of set1.

algebraixlib.algebras.sets.power_set(set1: algebraixlib.mathobjects.set.Set)[source]

Return the power set of set1.

algebraixlib.algebras.sets.power_up(set1: algebraixlib.mathobjects.set.Set)[source]

‘Add a set of braces’ around the elements of set1.

Returns:A Set where every element is a Set that contains exactly one element of set1 and where there is exactly one element-Set for every element of set1.
algebraixlib.algebras.sets.restrict(set1: 'P( M )', selector: collections.abc.Callable) → 'P( M )'[source]

Return a set with all the elements from set1 for which the predicate selector returns True.

Parameters:
  • set1 – The source data. Must be a set.
  • selector – A Callable that accepts as single argument a MathObject and returns a bool that indicates whether the element is in the result set (True) or not (False).
algebraixlib.io package

This package contains modules with facilities for importing and exporting data.

Submodules
algebraixlib.io.csv module

Import clans from and export them to CSV data.

algebraixlib.io.csv.export_csv(absolute_clan: 'PP(A x A)', file_or_path, column_order=None, sort_key=None)[source]

This function takes an absolute, left regular clan and produces a CSV file, where the left components are in the header line and the rows are the individual relations.

Parameters:
  • absolute_clan – A algebraixlib.mathobjects.set.Set. It must be an absolute and left-regular clan.
  • 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).
  • column_order – The optional left set to be exported in the specified order.
  • sort_key – The optional key to be provided to sorted (sorted not called if None).
Returns:

True if the CSV export succeeded.

algebraixlib.io.csv.import_csv(csv_file_or_filepath, types=None, skip_rows=0, index_column=None, has_dup_rows=False) → 'PP( A x M )'[source]

Import the file csv_file_or_filepath as CSV data and return a clan.

Parameters:
  • csv_file_or_filepath – The file path or file object (for example StringIO buffer) to import.
  • types – An optional 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}.
  • skip_rows – An optional number of lines to skip (default 0). Some CSV files have a preamble that can be skipped with this option.
  • index_column – An optional name for an index column. (No index column is created if this argument is not specified.) The index starts with 0.
  • has_dup_rows – An optional flag to return a multiclan instead of a clan. This option will count the duplicate rows of relations and store the quantities in a multiset. It can not be used in conjunction with the index_column option.
algebraixlib.io.json module

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.
algebraixlib.io.mojson module

Import a MathObject from and export it to a custom JSON format that allows a round-trip.

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

Custom json encoder. Manages encoding math objects and supported built in data types.

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.

default(o)[source]
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

Custom json decoder. Manages decoding json into math objects and hashable data types.

object_hook, if specified, will be called with the result of every JSON object decoded and its return value will be used in place of the given dict. This can be used to provide custom deserializations (e.g. to support JSON-RPC class hinting).

object_pairs_hook, if specified will be called with the result of every JSON object decoded with an ordered list of pairs. The return value of object_pairs_hook will be used instead of the dict. This feature can be used to implement custom decoders that rely on the order that the key and value pairs are decoded (for example, collections.OrderedDict will remember the order of insertion). If object_hook is also defined, the object_pairs_hook takes priority.

parse_float, if specified, will be called with the string of every JSON float to be decoded. By default this is equivalent to float(num_str). This can be used to use another datatype or parser for JSON floats (e.g. decimal.Decimal).

parse_int, if specified, will be called with the string of every JSON int to be decoded. By default this is equivalent to int(num_str). This can be used to use another datatype or parser for JSON integers (e.g. float).

parse_constant, if specified, will be called with one of the following strings: -Infinity, Infinity, NaN. This can be used to raise an exception if invalid JSON numbers are encountered.

If strict is false (true is the default), then control characters will be allowed inside strings. Control characters in this context are those with character codes in the 0-31 range, including '\t' (tab), '\n', '\r' and '\0'.

decode(s, _w=<built-in method match of _sre.SRE_Pattern object>)[source]
WHITESPACE = re.compile('[ \\t\\n\\r]*', re.MULTILINE|re.DOTALL|re.VERBOSE)
algebraixlib.io.rdf module

Import and export facilities for RDF data.

algebraixlib.io.rdf.import_graph(input_file=None, input_data: str=None, rdf_format: str=None) → 'PP(A x A)'[source]

Return an absolute graph into which the RDF graph input_file has been imported.

  • 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 an Atom).
  • Literals are converted to intuitive native Python types (embedded in an Atom).
Parameters:
  • input_file – A string that is a path (relative or absolute) to the file to be imported, or a StringIO instance. Exactly one of input_file and input_data must be given.
  • input_data – The input data as string. Exactly one of input_file and input_data must be given.
  • 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 graph with the data from 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 – A clan that contains the data to be exported.
  • out_format – A supported RDF table format. Supported are 'csv' (SPARQL1.1QueryResultsCSVandTSVFormats) and 'json' (SPARQL1.1QueryResultsJSONFormat).
algebraixlib.io.xml module

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. If False (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.mathobjects package

This package contains the modules that define the classes that represent data.

The modules are:

  • mathobject: Contains the abstract base class MathObject. 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() 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).
  • atom: Contains the class Atom. Instances of this class represent atoms; that is, values (of non-math objects, like numbers, strings or any immutable Python value). All instances of Atom are members of set A (\(A\)), or conversely, set A is the set of all instances of Atom. It also provides the utility function auto_convert() that makes sure that its argument is always an instance of MathObject; if it isn’t, it converts it into an Atom.
  • couplet: Contains the class Couplet that represents a couplet.
  • set: Contains the class Set that represents a set.

If you import mathobjects (the package), all module-level symbols (functions, classes) are imported.

Submodules
algebraixlib.mathobjects.atom module

An atomic math object that represents a value.

algebraixlib.mathobjects.atom.auto_convert(arg)[source]

Return always a MathObject. If arg is not a MathObject, make it an Atom.

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

An atomic math object. It represents a value (of a non-MathObject, hashable type).

Note

Instances of Atom are considered immutable. Therefore they only accept immutable values. Since an Atom also needs to be hashable, the value itself also needs to be hashable.

Construct an instance with the given value.

Parameters:value – The value of the Atom. May not be an instance of MathObject other than Atom. (If it is of type Atom, this Atom is used.) The value must be immutable and hashable.
static __new__(value, direct_load=False)[source]

If value is an Atom, return that Atom, else return a new Atom initialized with value.

Note

This is used to reduce the number of created Atom instances, but doesn’t make the check in __init__ unnecessary. __init__ is always called after __new__.

value

Read-only; return the value of this instance.

get_ground_set()[source]

Return the ground set of the lowest-level algebra of this MathObject. Is always \(A\).

get_repr()[source]

Return the instance’s code representation.

get_str()[source]

Return the instance’s string representation (the string representation of the value).

__eq__(other)[source]

A value-based comparison for equality. Return True if types and values match. NOTE: Atom(1) != Atom(1.0)

__ne__(other)[source]

A value-based comparison for inequality. Return True if types or values don’t match. NOTE: Atom(1) != Atom(1.0)

__hash__()[source]

Return a hash based on the value calculated during construction.

__repr__()[source]

Return the instance’s code representation.

__str__()[source]

Return the instance’s string representation.

algebraixlib.mathobjects.couplet module

A math object that represents a couplet.

class algebraixlib.mathobjects.couplet.Couplet(left, right=None, direct_load=False)[source]

Bases: algebraixlib.mathobjects.mathobject.MathObject

A couplet, consisting of a ‘left component’ MathObject and a ‘right’ MathObject.

Construct an instance, consisting of two MathObject instances left and right.

If either of the arguments is not a MathObject, make it an Atom with the argument as value.

left

Read-only property; return the left component of this instance.

right

Read-only property; return the right of this instance.

get_ground_set()[source]

Return the ground set of the lowest-level algebra of this MathObject.

is_reflexive()[source]

Return True if this Couplet is reflexive.

Reflexive means that left and right are equal.

is_symmetric()[source]

Return True if this Couplet is symmetric.

Reflexive means that left and right are equal.

get_repr()[source]

Return the instance’s code representation.

get_str()[source]

Return the instance’s string representation (the string representation of the value).

__eq__(other)[source]

A value-based comparison for equality. Return True if type and both members match.

__ne__(other)[source]

A value-based comparison for inequality. Return True if type or members don’t match.

__hash__()[source]

Return a hash based on the value that is calculated on demand and cached.

__repr__()[source]

Return the instance’s code representation.

__str__()[source]

Return the instance’s string representation.

algebraixlib.mathobjects.flags module

This module contains

class algebraixlib.mathobjects.flags.Flags[source]

Bases: _ctypes.Structure

The bits only convey information if they are True...False only indicates not initialized. For instance to determine if a Set() is a Clan use “Set().is_clan()”. To verify that a Set() is not a clan do not use “not Set().is_clan()”, but instead use Set().is_not_clan()

not_relation
relation
not_clan
clan
not_multiclan
multiclan
not_left_functional
left_functional
not_right_functional
right_functional
not_left_regular
left_regular
not_reflexive
reflexive
not_symmetric
symmetric
not_transitive
transitive
algebraixlib.mathobjects.mathobject module

The abstract base class for all math objects.

algebraixlib.mathobjects.mathobject.raise_if_not_mathobject(obj)[source]

Raise a TypeError exception if obj is not an instance of MathObject.

algebraixlib.mathobjects.mathobject.raise_if_not_mathobjects(*objs)[source]

Raise a TypeError exception if any member of objs is not a MathObject.

class algebraixlib.mathobjects.mathobject.MathObject[source]

Bases: abc.ABC

An abstract base class (see the base class abc.ABC) for all classes that represent data.

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.

get_ground_set() → algebraixlib.structure.Structure[source]

Return the ground set of the lowest-level algebra of this MathObject.

get_left_set() → bool[source]

Return the left set or Undef() if not applicable.

get_right_set() → bool[source]

Return the right set or Undef() if not applicable.

is_left_regular() → bool[source]

Return True if left-regular or Undef() if not applicable.

is_left_functional() → bool[source]

Return True if left-functional or Undef() if not applicable.

is_right_functional() → bool[source]

Return True if right-functional or Undef() if not applicable.

is_bijection() → bool[source]

Return True if left- and right-functional or Undef() if not applicable.

is_reflexive() → bool[source]

Return True if reflexive or Undef() if not applicable.

is_symmetric() → bool[source]

Return True if symmetric or Undef() if not applicable.

is_transitive() → bool[source]

Return True if transitive or Undef() if not applicable.

is_equivalence_relation() → bool[source]

Return True if equivalence relation or Undef() if not applicable.

get_repr() → str[source]

Return the instance’s code representation.

get_str() → str[source]

Return the instance’s string representation.

__eq__(other) → bool[source]

Return True if self and other are equal, based on their values.

__ne__(other) → bool[source]

Return True if self and other are not equal, based on their values.

__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__).

__repr__() → str[source]

Return the instance’s code representation.

__str__() → str[source]

Return the instance’s string representation.

cached_is_not_relation
cached_is_relation
cache_is_relation(value: bool)[source]
cached_is_not_clan
cached_is_clan
cache_is_clan(value: bool)[source]
cached_is_not_multiclan
cached_is_multiclan
cache_is_multiclan(value: bool)[source]
cached_is_not_left_functional
cached_is_left_functional
cache_is_left_functional(value: bool)[source]
cached_is_not_right_functional
cached_is_right_functional
cache_is_right_functional(value: bool)[source]
cached_is_not_left_regular
cached_is_left_regular
cache_is_left_regular(value: bool)[source]
cached_is_not_reflexive
cached_is_reflexive
cache_is_reflexive(value: bool)[source]
cached_is_not_symmetric
cached_is_symmetric
cache_is_symmetric(value: bool)[source]
cached_is_not_transitive
cached_is_transitive
cache_is_transitive(value: bool)[source]
algebraixlib.mathobjects.multiset module

A math object that 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.

Construct a Multiset from a single MathObject or value or an iterable collection of
such.
Parameters:
  • args – Zero or more unnamed arguments that are placed into the created Multiset.
  • direct_load – Flag they allows bypassing the normal auto-converting of elements. The elements must all be instances of MathObject.

The prefered argument type will be a dictionary whose keys are mapped to positive integers. The keys will be auto-converted based on the direct_load parameter.

Note

A string is an iterable, so an explicit conversion to an Atom (or wrapping it into brackets or braces) is required for multi-character strings.

data

Read-only; return the elements of this instance as a Counter of MathObject instances.

is_left_regular() → bool[source]

Return True if this Multiset is left-regular. Return Undef if not applicable.

cardinality

Read-only; return the number of elements in the Multiset.

is_empty

Return True if this Multiset is empty.

has_element(elem: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return True if elem is an element of this Multiset. elem must be a MathObject.

For a more relaxed version (that auto-converts non-MathObject arguments into instances of Atom) see __contains__ and the construct elem in Multiset.

get_multiplicity(elem: algebraixlib.mathobjects.mathobject.MathObject) → int[source]

Return int if elem is an element of this Multiset where the value is the number of multiples for elem. elem must be a MathObject.

get_ground_set() → algebraixlib.structure.Structure[source]

Return the ground Multiset of the lowest-level algebra of this Multiset.

get_repr() → str[source]

Return the instance’s code representation.

get_str() → str[source]

Return the instance’s string representation.

__eq__(other)[source]

Implement value-based equality. Return True if type and data match.

__ne__(other)[source]

Implement value-based inequality. Return True if type or data don’t match.

__contains__(item)[source]

Return True if item is a member of this Multiset. If item is not a MathObject, it is converted into an Atom.

This allows Boolean expressions of the form element in Multiset.

__hash__()[source]

Return a hash based on the value that is calculated on demand and cached.

__repr__()[source]

Return the instance’s code representation.

__str__()[source]

Return the instance’s string representation.

cache_is_multiclan(value: bool)[source]
algebraixlib.mathobjects.set module

A math object that represents a set.

class algebraixlib.mathobjects.set.Set(*args, direct_load=False)[source]

Bases: algebraixlib.mathobjects.mathobject.MathObject

A set consisting of zero or more different MathObject instances.

Construct a Set from a single MathObject or value or an iterable collection of
such.
Parameters:
  • args – Zero or more unnamed arguments that are placed into the created set.
  • direct_load – Flag they allows bypassing the normal auto-converting of elements. The elements must all be instances of MathObject.

If no argument is given or the given iterable is empty, an empty set is created.

Note

A string is an iterable, so an explicit conversion to an Atom (or wrapping it into brackets or braces) is required for multi-character strings.

data

Read-only; return the elements of this instance as a frozenset of MathObject instances.

cardinality

Read-only; return the number of elements in the set.

is_empty

Return True if this set is empty.

has_element(elem: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return True if elem is an element of this set. elem must be a MathObject.

For a more relaxed version (that auto-converts non-MathObject arguments into instances of Atom) see __contains__ and the construct elem in Set.

get_ground_set() → algebraixlib.structure.Structure[source]

Return the ground set of the lowest-level algebra of this Set.

get_left_set() → 'P( A )'[source]

Get the left set for this Set. Return Undef if not applicable.

get_right_set() → 'P( A )'[source]

Get the right set for this Set. Return Undef if not applicable.

is_left_regular() → bool[source]

Return True if this Set is left-regular. Return Undef if not applicable.

is_left_functional() → bool[source]

Return True if this Set is left-functional. Return Undef if not applicable.

is_right_functional() → bool[source]

Return True if this Set is right-functional. Return Undef if not applicable.

is_bijection() → bool[source]

Return True if this Set is both left and right-functional. Return Undef if not applicable.

is_reflexive() → bool[source]

Return True if this Set is reflexive. Return Undef if not applicable.

is_symmetric() → bool[source]

Return True if this Set is symmetric. Return Undef if not applicable.

is_transitive() → bool[source]

Return True if this Set is transitive. Return Undef if not applicable.

is_equivalence_relation() → bool[source]

Return True if this Set is reflexive, symmetric, and transitive. Return Undef if not applicable.

get_repr() → str[source]

Return the instance’s code representation.

get_str() → str[source]

Return the instance’s string representation.

__eq__(other)[source]

Implement value-based equality. Return True if type and set elements match.

__ne__(other)[source]

Implement value-based inequality. Return True if type or set elements don’t match.

__contains__(item)[source]

Return True if item is a member of this set. If item is not a MathObject, it is converted into an Atom.

This allows Boolean expressions of the form element in set.

__hash__()[source]

Return a hash based on the value that is calculated on demand and cached.

__repr__()[source]

Return the instance’s code representation.

__str__()[source]

Return the instance’s string representation.

cache_is_relation(value: bool)[source]
cache_is_clan(value: bool)[source]
cache_is_left_functional(value: bool)[source]
cache_is_right_functional(value: bool)[source]
cache_is_left_regular(value: bool)[source]
cache_is_reflexive(value: bool)[source]
cache_is_symmetric(value: bool)[source]
cache_is_transitive(value: bool)[source]
algebraixlib.util package

This package contains miscellaneous utility modules.

Submodules
algebraixlib.util.html module

A conversion utility that manipulates a math object into a LaTeX representation.

class algebraixlib.util.html.DataAlgebraHtmlDescriptor(input_title, data_algebra_construct, description_brief)

Bases: tuple

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

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 math object, using templates.

Parameters:
  • title – The title for this page of math objects.
  • 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 page_title; it is set to the value of title.
  • footer_template – HTML markup that ends the page.
  • mathobject_template – The HTML markup that is emited for each math object. May contain the templates input_title, description_brief and data_algebra_construct, which are replaced with the respective values in the associated DataAlgebraHtmlDescriptor.
Returns:

The final HTML webpage.

algebraixlib.util.html.as_html_handle_basic_parameter(html_input: str) → str[source]

Convert the string of html_input into an HTML-safe character sequence.

Parameters:html_input – The value to convert so that it can be added to HTML content.
Returns:An HTML-safe string.
algebraixlib.util.html.as_html_handle_data_algebra(mathobj)[source]

Add some logic to allow the client to provide the math object in several ways:

  • If it is a mathobject, it will be turnied into LaTeX and wrapped in the mathjax escape token.
  • If it is a container of mathobjects, then each one will be turned into LaTeX and presented on its own line.
  • If it is not a mathobject then the str function will be invoked.
Parameters:mathobj – The data algebra construct to be rendered on HTML
Returns:The HTML snippet of the mathobject.
algebraixlib.util.html.build_descriptors_from_math_obj(mathobjects)[source]

A utility function if a client does not wish to create their own descriptor objects. This function will create a descriptor array from a list of mathobjects.

Parameters:mathobjects – List to build descriptors out of.
Returns:DataAlgebraHtmlDescriptors
algebraixlib.util.html.create_simple_web_page(mathobj: algebraixlib.mathobjects.mathobject.MathObject) → str[source]

Convert a math object into an HTML file. This does not offer much client specification or HTML injection. Create a basic webpage for one mathobject.

Parameters:mathobj – The mathobject to create a webpage for.
Returns:The web page (HTML) for mathobj.
class algebraixlib.util.html.DataAlgToWebTest(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the latex printer functions.

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

test_data_alg_to_web_simple()[source]
test_data_alg_to_web()[source]
algebraixlib.util.latexprinter module

A conversion utility that manipulates a MathObject into a LaTeX representation.

The main entry point is the math_object_to_latex function; it delegates to the appropriate conversion function according to the argument type.

class algebraixlib.util.latexprinter.Config[source]

Bases: object

Module configuration values.

colorize_output = True
short_atom_len = 10
short_set_len = 4
algebraixlib.util.latexprinter.nested_set_helper(depth)[source]

This function inserts the appropriate number of spaces for indentation, based on how many nests sets of sets that are currently being printed. :param depth: Indicates the current number of nests of sets :return: A snippet of LaTeX representing the correct amount of space when starting a new line of printing.

algebraixlib.util.latexprinter.set_hasa_set(a_set)[source]

A interim function for determining the structure of a set.

Parameters:a_set – The set to test.
Returns:True if the set provided contains elements which are also sets.
algebraixlib.util.latexprinter.math_object_to_latex(mobj, short: bool=False, _depth: int=0)[source]

Prints a math object formatted in LaTeX. If it is not provided with a specific math object, returns an error string.

Parameters:
  • mobj – The object that you want to translate into LaTeX. It must be a Set, Atom, Couplet or Undef().
  • short – When set to True, a short version of the content is generated. Longer parts are abbreviated with ellipses (‘...’). Defaults to False.
  • _depth – Defaults to 0, to not be exposed to a caller. Is incremented when the provided math object is a set that contains a set.
Returns:

string of LaTeX markup representing the provided math object.

algebraixlib.util.latexprinter.iprint_latex(variable_name: str, variable_value=None, short: bool=False)[source]

A utility to display variables in IPython notebooks.

Parameters:
  • variable_name – The name of the variable to display.
  • variable_value – The optional 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 – When set to True, a short version of the content is generated. Longer parts are abbreviated with ellipses (‘...’). Defaults to False.
algebraixlib.util.latexprinter.atom_to_latex(atom, short: bool=False)[source]

Prints an atom formatted in LaTeX. For example the “atom(“scooby”)” will be represented in LaTeX as “mbox{scooby}”

The atom is wrapped in mbox tag to enforce that it remains on one line. Note, currently the str function on a atom returns the value wrapped in single quotes.

Returns an error string if the atom is not of type Atom.

Parameters:
  • atom – The atom to be turned into LaTeX.
  • short – When set to True, a short version of the content is generated. Longer parts are abbreviated with ellipses (‘...’). Defaults to False.
Returns:

The LaTeX markup of the atom.

algebraixlib.util.latexprinter.couplet_to_latex(couplet, short: bool=False)[source]

Prints a couplet formatted in LaTeX.

Note, currently this implementation only supports couplets which contain atoms. The LaTeX of a couplet which contains non atom math objects might look malformed.

For example the “Couplet(left=atom(“scooby”), right=atom(“doo”)” will be represented in LaTeX as “(mbox{scooby}{mapsto}{mbox{doo}})”

Returns an error string if the couplet is not of type Couplet.

Parameters:
  • couplet – The couplet to be turned into LaTeX.
  • short – When set to True, a short version of the content is generated. Longer parts are abbreviated with ellipses (‘...’). Defaults to False.
Returns:

The LaTeX markup of the couplet.

algebraixlib.util.latexprinter.set_to_latex(mobj_set, short: bool=False, depth=0)[source]

Prints a set formatted in LaTeX.

The function checks to see if a set contains another set, if it does, then the elements are printed by row on new lines, instead of horizontally. The elements are also indented under the outer brackets. This indentation is continued until the nesting stops.

Returns an error string if the couplet is not an algebraixlib.mathobjects.couplet.Couplet.

Parameters:
  • mobj_set – The set to be turned into LaTeX.
  • short – When set to True, a short version of the content is generated. Longer parts are abbreviated with ellipses (‘...’). Defaults to False.
  • depth – A counter of how many tabs to insert when printing the elements; default is 0.
Returns:

The LaTeX markup of the set or an error message.

algebraixlib.util.latexprinter.mset_to_latex(mobj_mset, short: bool=False, depth=0)[source]
algebraixlib.util.miscellaneous module

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 if iterable doesn’t contain at least one element; TypeError if iterable isn’t iterable.
algebraixlib.util.miscellaneous.get_variable(variable_name: str, frames_up: int)[source]

Return the variable with name variable_name, from frames_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='')[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 to print_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.
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 call data_functor on it. If it is not a string, assume it is a file-like object (with a .write() function) and call data_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)[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 is None.
  • skip – Set to True to skip this lap. Defaults to False.
  • short – Print a short lap result without the full content of variable_name.
  • max_length – Maximal length of print. Defaults to 10000 characters.
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 is None.
  • short – Print a short lap result without the full content of variable_name.
  • max_length – Maximal length of print. Defaults to 10000 characters.
get_elapsed_time()[source]

Return the time elapsed since construction in seconds (see __init__()).

static get_indent()[source]

Return the current indent as string of spaces.

algebraixlib.util.rdf module

This module contains RDF-specific data manipulation facilities. The code is RDF/SPARQL-inspired but does not officially implement any RDF standards.

Glossary
triple
A relation 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.)
API
algebraixlib.util.rdf.is_file_url(path_or_url: str) → bool[source]

Return True if path_or_url is a file URL (that is, 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 if obj is a triple.

algebraixlib.util.rdf.is_absolute_triple(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return True if obj is an absolute triple.

algebraixlib.util.rdf.make_triple(subject: '( M )', predicate: '( M )', object_: '( M )') → 'P(A x M)'[source]

Return an RDF triple, created from subject, predicate and object_.

Each of the arguments must be an instance of MathObject or a Python type that automatically converts to an Atom in the Couplet constructor.

algebraixlib.util.rdf.is_graph(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return True if obj is a graph.

algebraixlib.util.rdf.is_absolute_graph(obj: algebraixlib.mathobjects.mathobject.MathObject) → bool[source]

Return True if obj is an absolute graph.

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) or None (ignore).
  • predicate – Handle the predicates in rdf_graph: a variable name (create output), a value that’s not a variable name (match) or None (ignore).
  • object – Handle the objects in rdf_graph: a variable name (create output), a value that’s not a variable name (match) or None (ignore).
Returns:

A clan with the matches.

algebraixlib.util.rdf.join(rdf_solution1, rdf_solution2, *rdf_solutions)[source]

Return the functional cross union (multiclans.functional_cross_union()) of all arguments.

algebraixlib.util.rdf.match_and_project(graph: 'PP( AxA )', pattern: dict=None, projection: dict=None)[source]

Return all relations in graph that contain all members of pattern. Rename their lefts according to the members of projection.

Parameters:
  • graph – An absolute clan.
  • pattern – A dictionary where the keys are the lefts and the values the rights that will be matched.
  • projection – A dictionary where the values are the new names and the keys the existing names of the lefts to be renamed.
algebraixlib.util.rdf.pattern_match(graph: 'PP( AxA )', pattern: dict)[source]

Return all relations in graph that contain all members of pattern.

Parameters:
  • graph – An absolute clan.
  • pattern – A dictionary where the keys are the lefts and the values the rights that will be matched.
algebraixlib.util.test module

Addition to unittest to be able to create non-failing ‘expect’-like tests.

algebraixlib.util.test.create_test_object(obj: object, msg: str, val: object=None) → object[source]

Add the content of msg and optionally val as properties to obj.

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 in mo are instances of MathObject.

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 identifying file_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 __file__.
  • file_id – The identification of the file (final part of the name, including extension).
algebraixlib.util.test.get_test_file_path(test_module: str, file_id: str) → str[source]

Return the (absolute) file path of a test file. Test file names are composed

Parameters:
  • test_module – The name of the test test_module to which the test file belongs. Typically this will be __file__.
  • file_id – The identification of the file (final part of the name, including extension).

Submodules

algebraixlib.extension module

Definitions for extending and other set operations that P(M) is not closed under.

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.

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 and set2.
Returns:

A set that consists of the defined results of op when executed on all combinations of the elements of set1 and set2, or Undef() if either set is not a Set.

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.

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 and multiset2.
Returns:

A multiset that consists of the defined results of op when executed on all combinations of the elements of multiset1 and multiset2, or Undef() if either set is not a Multiset.

algebraixlib.extension.unary_extend(set1: 'P( M )', op, _checked=True) → 'P( M )'[source]

Return the unary extension of op from one algebra to another algebra.

Parameters:
  • set1 – A set with elements on which op operates.
  • op – A unary operation that operates on the elements of set1.
Returns:

A set that consists of the defined results of op when executed on the elements of set1, or Undef() if set1 is not a Set.

algebraixlib.extension.unary_multi_extend(multiset1: 'P( M x N )', op, _checked=True) → 'P( M x N )'[source]

Return the unary extension of op from one algebra to another algebra.

Parameters:
  • multiset1 – A multiset with elements on which op operates.
  • op – A unary operation that operates on the elements of multiset1.
Returns:

A set that consists of the defined results of op when executed on the elements of multiset1, or Undef() if set1 is not a Multiset.

algebraixlib.partition module

Definitions for partitioning and other set operations that P(M) is not closed under.

algebraixlib.partition.partition(set1, equivalence_relation)[source]

Returns a set with structure P(set1.ground_set) that defines a partition on set1, imposed by the equivalence relation defined by the equivalence_relation function: a function from elements of set1 to MathObjects.

algebraixlib.partition.left_equiv_relation(set1, equivalence_relation)[source]

Returns a set with structure P(set1.ground_set) that defines a partition on set1, imposed by the equivalence relation defined by the equivalence_relation function: a function from elements of set1 to a value that can be placed in a Atom.

algebraixlib.structure module
The Structure of a MathObject

Note

Not fully up to the latest standard.

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 math object 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 a Couplet 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:

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

\(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\). The structures of instances of Set are always absolute structures.
  • 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.

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 if self is a subset of other.

Parameters:other – Must be an instance of Structure.
Returns:Is always True for type Structure.
get_powerset_level(other) → int[source]

Return the number of power set levels between self and other.

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 if self is structurally equivalent to other.

Parameters:other – Must be an instance of Structure.
Returns:True if self is structurally equivalent to other.
get_repr() → str[source]

Return the instance’s code representation.

get_str() → str[source]

Return the instance’s string representation.

__eq__(other)[source]

Map to is_same. Is called for the operator ==.

__ne__(other)[source]

Map to the negation of is_same. Is called for the operator !=.

__le__(other)[source]

Map to is_subset. Is called for the operator <=.

__hash__()[source]

Return a hash based on the member values. (It must match the implementation of is_same, to which __eq__ redirects equality comparisons.)

__repr__()[source]

Return the instance’s code representation.

__str__()[source]

Return the instance’s string representation.

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 if self is a subset of other.

Parameters:other – Must be an instance of Structure.
Returns:True if self is a subset of other.
get_powerset_level(other: algebraixlib.structure.Structure) → int[source]

Return the number of power set levels between self and other.

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 if self is structurally equivalent to other.

Parameters:other – Must be an instance of Structure.
Returns:True if self is structurally equivalent to other.
get_repr() → str[source]

Return the instance’s code representation. Is always ‘GenesisSetA()’.

get_str() → str[source]

Return the instance’s string representation. Is always 'A'.

__hash__()[source]

Return a hash based on the member values. (It must match the implementation of is_same, to which Structure.__eq__ redirects equality comparisons.)

__repr__()[source]

Return the instance’s code representation.

__str__()[source]

Return the instance’s string representation.

class algebraixlib.structure.GenesisSetM[source]

Bases: algebraixlib.structure.Structure

The set of all math objects. 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 if self is a subset of other.

Parameters:other – Must be an instance of Structure.
Returns:True if self is a subset of other.
get_powerset_level(other)[source]

Return the number of power set levels between self and other.

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 if self is structurally equivalent to other.

Parameters:other – Must be an instance of Structure.
Returns:True if self is structurally equivalent to other.
get_repr() → str[source]

Return the instance’s code representation. Is always 'GenesisSetM()'.

get_str() → str[source]

Return the instance’s string representation. Is always 'M'.

__hash__()[source]

Return a hash based on the member values. (It must match the implementation of is_same, to which Structure.__eq__ redirects equality comparisons.)

__repr__()[source]

Return the instance’s code representation.

__str__()[source]

Return the instance’s string representation.

class algebraixlib.structure.GenesisSetN[source]

Bases: algebraixlib.structure.Structure

The set of all numerals. Is functionally a single number.

is_subset(other: algebraixlib.structure.Structure) → bool[source]

Return True if self is a subset of other.

Parameters:other – Must be an instance of Structure.
Returns:True if self is a subset of other.
get_powerset_level(other)[source]

Return the number of power set levels between self and other.

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 if self is structurally equivalent to other.

Parameters:other – Must be an instance of Structure.
Returns:True if self is structurally equivalent to other.
get_repr() → str[source]

Return the instance’s code representation. Is always 'GenesisSetN()'.

get_str() → str[source]

Return the instance’s string representation. Is always 'M'.

__hash__()[source]

Return a hash based on the member values. (It must match the implementation of is_same, to which Structure.__eq__ redirects equality comparisons.)

__repr__()[source]

Return the instance’s code representation.

__str__()[source]

Return the instance’s string representation.

class algebraixlib.structure.CartesianProduct(left, right)[source]

Bases: algebraixlib.structure.Structure

Represent the cartesian product node of a structure.

Create an instance of CartesianProduct.

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.
left

Read-only access to the left structure.

right

Read-only access to the right structure.

is_subset(other: algebraixlib.structure.Structure) → bool[source]

Return True if self is a subset of other.

In order for self to be a subset of other, other must be:

  • A CartesianProduct and both left and right components must be subsets of left and right components of other, or
  • A Union that contains an instance of CartesianProduct where both left and right component are subsets of left and right components of other, or
  • GenesisSetM (everything in our system is a subset of \(M\)).
Parameters:other – Must be an instance of Structure.
Returns:True if self is a subset of other.
get_powerset_level(other: algebraixlib.structure.Structure) → int[source]

Return the number of power set levels between self and other.

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 if self is structurally equivalent to other.

Parameters:other – Must be an instance of Structure.
Returns:True if self is structurally equivalent to other.
get_repr() → str[source]

Return the instance’s code representation.

get_str() → str[source]

Return the instance’s string representation.

__hash__()[source]

Return a hash based on the member values. (It must match the implementation of is_same, to which Structure.__eq__ redirects equality comparisons.) Is always cached.

__repr__()[source]

Return the instance’s code representation.

__str__()[source]

Return the instance’s string representation.

class algebraixlib.structure.Union(iterable)[source]

Bases: algebraixlib.structure.Structure

Represent the union node of a structure.

Create an instance of Union.

The result is so that no member of this union 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.
data

Read-only access to the raw collection (frozenset) of the union members.

is_subset(other: algebraixlib.structure.Structure) → bool[source]

Return True if self is a subset of other.

Is True if every element of this union is a subset of other:

  • 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 if other is GenesisSetM (everything in our system is an element of \(M\)).

Parameters:other – Must be an instance of Structure.
Returns:True if self is a subset of other.
get_powerset_level(other: algebraixlib.structure.Structure) → int[source]

Return the number of power set levels between self and other.

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 if self is structurally equivalent to other.

Parameters:other – Must be an instance of Structure.
Returns:True if self is structurally equivalent to other.
get_repr() → str[source]

Return the instance’s code representation.

get_str()[source]

Return the instance’s string representation.

__hash__()[source]

Return a hash based on the member values. (It must match the implementation of is_same, to which Structure.__eq__ redirects equality comparisons.) Is always cached.

__repr__()[source]

Return the instance’s code representation.

__str__()[source]

Return the instance’s string representation.

class algebraixlib.structure.PowerSet(elements_struct)[source]

Bases: algebraixlib.structure.Structure

Represent the power set node of a structure.

Create an instance of PowerSet.

Parameters:elements_struct – The structure of the elements of the 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 if self is a subset of other.

Parameters:other – Must be an instance of Structure.
Returns:True if self is a subset of other.
get_powerset_level(other: algebraixlib.structure.Structure) → int[source]

Return the number of power set levels between self and other.

Parameters:other – Must be an instance of Structure.
Returns:The number of power set levels (>= 0) that are between self and other. 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 if self is structurally equivalent to other.

Parameters:other – Must be an instance of Structure.
Returns:True if self is structurally equivalent to other.
get_repr() → str[source]

Return the instance’s code representation.

get_str() → str[source]

Return the instance’s string representation.

__hash__()[source]

Return a hash based on the member values. (It must match the implementation of is_same, to which Structure.__eq__ redirects equality comparisons.) Is always cached.

__repr__()[source]

Return the instance’s code representation.

__str__()[source]

Return the instance’s string representation.

algebraixlib.undef module

Class Undef (represents the concept of ‘undefined’) and associated constructs.

class algebraixlib.undef.Undef[source]

Bases: object

A singleton class that represents the concept of “undefined”. It can’t be treated as a value by the Data Algebra library and specifically it will never appear as the value of an Atom.

static __new__()[source]

Override __new__ to create a singleton class.

__str__()[source]

Pretty-print Undef.

__eq__(other)[source]

Prevent comparisons on Undef; raise a TypeError.

__ne__(other)[source]

Prevent comparisons on Undef; raise a TypeError.

__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 of make_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 to ‘temp_value’.

static reset()[source]

Reset the level for raising an UndefException back to its initial value.

exception algebraixlib.undef.UndefException[source]

Bases: Exception

This exception is raised when the ‘level’ argument of make_or_raise_undef() is less than or equal to the RaiseOnUndef level.

algebraixlib.undef.make_or_raise_undef(level=1)[source]

Raise UndefException if level is less than or equal to the RaiseOnUndef level, otherwise return Undef().

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.

Algebra Documentation

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 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)\). Sukch a set has only atoms as elements. Example: \(\{1, 2\}\).
addition

An operation defined only on multisets. Given multisets \(\dot{A}\) and \(\dot{B}\) we define \(\dot{A}+\dot{B}\) as follows:

\[\big(\dot{A} + \dot{B}\big)(x) = \dot{A}(x) + \dot{B}(x)\]

for any \(x\in M\).

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 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, intersections, addition, difference, and subset. 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.
arbitrary intersection
An arbitrary intersection is the intersection of two or more sets. See intersection for a complete definition.
atom
An atom is a datum that is not a set or a couplet. The set of all atoms is set A (\(A\)).
binary extension

A binary extension is an extension of a binary operation from a given algebra to a extension of the 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 on multisets. In particular, in addition to the requirements on a standard binary extension the multi-extension must extend the operation on multiplicities in a way that is well-defined.
binary operation
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.
binary union
A binary union is a union of two sets. See union for more information.
Cartesian product
The Cartesian product of two sets \(A \times B\) is the set of all couplets where the first member of the couplet is a member of \(A\) and the second member of the couplet is a member of \(B\).
clan
A set of relations.
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(M)\) and \(A\in P(M)\), the the complement of \(A\), denoted \(A'\) is

\[\{x \in M: x \not\in A\}.\]

Using set difference, it is true that \(A'=M-A\).

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^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.)

For multiclans the operation is the same, but with the multiplicity of the resulting relations being the product of the multiplicities of the individual 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-intersection

The cross-intersection is a 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 multisets and multiclans the multiplicity of any set or relation in the result is the product of the multiplicities of the individual sets or relations.

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 \triangleright Y\ : X \in \mathbb{S} \text{ and } Y \in \mathbb{T}\}\]
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}\}\]

For multisets and multiclans the multiplicity of any set or relation in the result is the product of the multiplicities of the individual sets or relations.

diagonal

The diagonal is an equality 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}\]

For multisets there is a separate multiset difference defined as follows: Given two multisets \(\dot{A}\) and \(\dot{B}\) we define

\[\big(\dot{A} \setminus \dot{B}\big)(x) = \max \big(\dot{A}(x) - \dot{B}(x), 0\big)\]

where \(x\) is any element of \(M\).

equivalence relation
A relation \(R\) 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 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.
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. Otherwise, the intersection is referred to as an arbitrary intersection. See also Wikipedia: Intersection.

For multisets, say \(\dot{A}\) and \(\dot{B}\), we define the multiset intersection to be

\[\big(\dot{A}\cap\dot{B}\big)(x)=min\big(\dot{A}(x),\dot{B}(x)\big)\]

for \(x\in M\).

This term is used to name two related operations: the binary intersection of two sets, and the arbitrary intersection of one or more sets.

left component
Given a couplet represented by \(l{\mapsto}r\), the element \(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}\]
left-functional cross-union

The left-functional cross-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}\}\]
left-functional union

The left-functional union of two relations \(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 if the left sets of all its relations are the same:

\[\forall R, Q \in \mathbb{C}: left(R) = left(Q)\]
lhs-functional cross-union

Given two clans the lhs-functional cross-union takes the left-functional cross-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 left-functional cross-union. Mathematically, if \(\mathbb{C}\) and \(\mathbb{D}\) are the two clans in question, then their lhs-functional cross-union is

\[\begin{split}\mathbb{C} \underset{f}{\blacktriangledown} \mathbb{D} \bigcup\{T : T\in\mathbb{C}\ \& \ T \underset{f}{\blacktriangledown} \mathbb{D} = \varnothing \}\end{split}\]
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.
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.)
project

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\]

See also left set, right set.

relation
A set of couplets. See also binary relation.
right component
Given a couplet represented by \(l{\mapsto}r\) the element \(r\) is the right component.
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 cross-union

The right-functional cross-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}\}\]
right-functional union

The right-functional union of two 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\).)
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\ ]\]

Given multisets \(\dot{A}\) and \(\dot{B}\), we can define \(\dot{A}\) to be a submultiset of \(\dot{B}\) if the following holds:

\[\dot{A} \subset \dot{B} \iff \forall x\in M \: \dot{A}(x) \leq \dot{B}(x).\]
substriction

Substriction is a partial binary operation on sets. The substriction of two sets \(S\) and \(T\) is defined as:

\[S \triangleleft T = S\ \ \text{if}\ \ S \subset T\]
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. The superstriction of two sets \(S\) and \(T\) is defined as:

\[S \triangleright 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\]

See also left set, right set.

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}\]

See also left set, right set.

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.

\[unaryExtn(op, S1) := \{op(s1)\ :\ s1 \in S1 \text{ where } op(s1) \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. Otherwise, the union is referred to as an arbitrary union. See also Wikipedia: Union.

For multisets, say \(\dot{A}\) and \(\dot{B}\), we define the multiset union to be

\[\big(\dot{A}\cup\dot{B}\big)(x)=max\big(\dot{A}(x),\dot{B}(x)\big)\]

for \(x\in M\).

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:

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:

    1. \(\oplus\) and \(\odot\) are each commutative and associative, and each distributes over the other.
    2. 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}\]
    1. 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

\[\bigg[ P(M) , \big\{ [ \cup, \varnothing ] , [ \cap, M ] \big\} , \big\{\ '\ \big\} , \big\{ \subset \big\} \bigg]\]

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:

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\)):

  1. \(S-T=S\cap T^{\prime }\).
  2. \(S-S=\varnothing\).
  3. \(S-\varnothing =S\).
  4. \(\varnothing -S=\varnothing\).
  5. \(S-M=\varnothing\).
  6. \(M-S=S^{\prime }\).
  7. \(S\bigtriangleup T=T\bigtriangleup S\). (\(\bigtriangleup\) is commutative.)
  8. \(S\bigtriangleup (T\bigtriangleup U)=(S\bigtriangleup T)\bigtriangleup U\). (\(\bigtriangleup\) is associative.)
  9. \(S\bigtriangleup S=\varnothing\).
  10. \(S\bigtriangleup \varnothing =S\).
  11. \(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 set M (\(M\)) to the nonnegative integers, or from a given subset of set M (\(M\)) to the positive integers. In particular, we call \(\dot{S}\) a multiset of \(M\) if for any \(x\in M\) we have \(\dot{S}(x)\) is a nonnegative 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)=0\). 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 union, addition, intersection, and subset as applied to multisets we have an algebra on multisets with the following signature:

\[\bigg[\dot{P}(M), [\cup,\varnothing], [+,\varnothing],\cap,\subset \bigg].\]

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, and cross-superstriction. As a result, it has the following signature:

\[\bigg[ P^{2}(M \times M),[\cup ,\varnothing ],[\mathbb{\cap },P(M \times M)], [\blacktriangledown ,\{\varnothing\}],[\mathbb{\blacktriangle },\{M \times M\}], \triangleleft, \triangleright, \blacktriangleright, \subset , \prime \bigg].\]

Note that included in the operations of union and cross-union are the special left-functional and right-functional cases of left-functional cross-union and right-functional cross-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

\[\bigg[ \dot{P}(P(M \times M)),[\cup ,\varnothing ],[+,\varnothing],\mathbb{\cap }, [\blacktriangledown ,\{\varnothing\}],[\mathbb{\blacktriangle },\{M \times M\}], \triangleleft, \triangleright, \blacktriangleright, \subset , \prime \bigg].\]

As in the case of clans, the operations of left-functional cross-union and right-functional cross-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\).

Examples of extensions

  • 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]\).

  • Let us take the algebra of integers with signature \(\bigg[ \mathbb{Z}, \big \{[+,0],[\cdot ,1]\}, \big \{-\}, \bigg]\) as in the previous 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}\)

    \[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\text{\ }\}.\]

    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]\) extendss to the algebra

    \[\begin{equation*} \bigg[ P(\mathbb{Z}),\{[\cup ,\varnothing ],[\mathbb{\cap },% \mathbb{Z}],[+,\{0\}],[\cdot ,\{1\}]\},\{-,^{\prime }\},\{\subset \}\bigg] , \end{equation*}\]
  • 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.

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, eny 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.