algebraixlib.structure module

The Structure of a MathObject

This module provides facilities to represent the structure of a MathObject. What we call ‘structure’ is a representation of the minimal power set a given MathObject belongs to (or should belong to) that can be expressed with the following elements.

The structural elements we use are:

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

The set M (\(M\)) is finite; essentially it is the set of all instances of MathObject that fit into a given system. This also implies that there is a power set \(P(M)\) that is not an element of \(M\). (It follows that not every ‘set of math objects’ is an element of \(M\).) Since \(A \subset M\), \(A\) is of course also finite.

Corresponding to the two genesis sets, we use two different forms to represent the structure of a MathObject:

  • Absolute structure: An absolute structure does not contain a reference to the set \(M\).
  • Relative structure: A relative structure contains a reference to the set \(M\). Such structures are typically used to compare absolute structures against them, to see whether a given absolute structure fulfills a minimal structural criterion.

Example Code

from algebraixlib.mathobjects import Set
from algebraixlib.structure import PowerSet, GenesisSetM
Set([1, 2]).get_ground_set()
# Output: PowerSet(GenesisSetA())
Set([1, 2]).get_ground_set().is_subset(PowerSet(GenesisSetM()))
# Output: True

API

class algebraixlib.structure.Structure[source]

Bases: object

Represent the ground set of a MathObject in structural terms. An instance of this class is the empty set.

Note

This class serves a double purpose. On one hand it is the base class for all nodes in the structure tree, and on the other hand it is the representative of the whole tree (where the top level node of the tree of interest is typically a subclass of this class). This is common practice and should not pose a problem, but it is probably helpful to be aware of it.

is_subset(other) → bool[source]

Return True 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.
__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.
__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 instances of MathObject. Is functionally a singleton.

Note

The set \(M\) being a superset of \(A\) means that subset checking (especially in Union) needs to ‘know’ about this relationship and take it into account. Representing \(M\) as \((A \cup A')\) (where \(A' = M \setminus A\)) would make this more straightforward, but would make the visible representation of \(M\) (as union) non-intuitive.

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

Return True 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.
__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 integers. 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)[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 GenesisSetN.
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.
__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.

Parameters:
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.
__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.

No member of this instance is a subset of another member, and no member of this union is a union itself (union arguments get ‘unioned into’ this union).

Parameters:iterable – An Iterable of one or more sets to be unioned. All elements must be an instance of Structure.
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.
__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.

Parameters:elements_struct – The structure of the elements of the set of which we are representing the power set. Must be an instance of Structure.
base_set

Read-only access to the base set of this powerset.

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

Return True 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.
__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.