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:
CartesianProduct
: The ground set of aCouplet
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:
GenesisSetA
: The set A (\(A\)) is the set of allAtom
s.GenesisSetM
: The term:set M
(\(M\)) is the ground set of allMathObject
s that can be represented in a given system.
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
ifself
is a subset ofother
.Parameters: other – Must be an instance of Structure
.Returns: Is always True
for typeStructure
.
-
get_powerset_level
(other) → int[source]¶ Return the number of power set levels between
self
andother
.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
ifself
is structurally equivalent toother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is structurally equivalent toother
.
-
-
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
ifself
is a subset ofother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is a subset ofother
.
-
get_powerset_level
(other: algebraixlib.structure.Structure) → int[source]¶ Return the number of power set levels between
self
andother
.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
ifself
is structurally equivalent toother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is structurally equivalent toother
.
-
__hash__
()[source]¶ Return a hash based on the member values. (It must match the implementation of
is_same
, to whichStructure.__eq__
redirects equality comparisons.)
-
-
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
ifself
is a subset ofother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is a subset ofother
.
-
get_powerset_level
(other)[source]¶ Return the number of power set levels between
self
andother
.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
ifself
is structurally equivalent toother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is structurally equivalent toother
.
-
__hash__
()[source]¶ Return a hash based on the member values. (It must match the implementation of
is_same
, to whichStructure.__eq__
redirects equality comparisons.)
-
-
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
ifself
is a subset ofother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is a subset ofother
.
-
get_powerset_level
(other)[source]¶ Return the number of power set levels between
self
andother
.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
ifself
is structurally equivalent toother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is structurally equivalent toother
.
-
__hash__
()[source]¶ Return a hash based on the member values. (It must match the implementation of
is_same
, to whichStructure.__eq__
redirects equality comparisons.)
-
-
class
algebraixlib.structure.
CartesianProduct
(left, right)[source]¶ Bases:
algebraixlib.structure.Structure
Represent the Cartesian product node of a structure.
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
.
-
is_subset
(other: algebraixlib.structure.Structure) → bool[source]¶ Return
True
ifself
is a subset ofother
.In order for
self
to be a subset ofother
,other
must be:- A
CartesianProduct
and both left and right components must be subsets of left and right components ofother
, or - A
Union
that contains an instance ofCartesianProduct
where both left and right component are subsets of left and right components ofother
, or GenesisSetM
(everything in our system is a subset of \(M\)).
Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is a subset ofother
.- A
-
get_powerset_level
(other: algebraixlib.structure.Structure) → int[source]¶ Return the number of power set levels between
self
andother
.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
ifself
is structurally equivalent toother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is structurally equivalent toother
.
-
__hash__
()[source]¶ Return a hash based on the member values. (It must match the implementation of
is_same
, to whichStructure.__eq__
redirects equality comparisons.) Is always cached.
- left – The ground set of the left component of a couplet. Must
be an instance of
-
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
.-
is_subset
(other: algebraixlib.structure.Structure) → bool[source]¶ Return
True
ifself
is a subset ofother
.Is
True
if every element of this union is a subset ofother
:- 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
ifother
isGenesisSetM
(everything in our system is an element of \(M\)).Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is a subset ofother
.- If
-
get_powerset_level
(other: algebraixlib.structure.Structure) → int[source]¶ Return the number of power set levels between
self
andother
.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
ifself
is structurally equivalent toother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is structurally equivalent toother
.
-
__hash__
()[source]¶ Return a hash based on the member values. (It must match the implementation of
is_same
, to whichStructure.__eq__
redirects equality comparisons.) Is always cached.
-
-
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
ifself
is a subset ofother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is a subset ofother
.
-
get_powerset_level
(other: algebraixlib.structure.Structure) → int[source]¶ Return the number of power set levels between
self
andother
.Parameters: other – Must be an instance of Structure
.Returns: The number of power set levels (>= 0) that are between self
andother
. 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
ifself
is structurally equivalent toother
.Parameters: other – Must be an instance of Structure
.Returns: True
ifself
is structurally equivalent toother
.
-
__hash__
()[source]¶ Return a hash based on the member values. (It must match the implementation of
is_same
, to whichStructure.__eq__
redirects equality comparisons.) Is always cached.
-