Posets
The galactic.algebras.poset
module defines types for representing posets.
their implementations:
and their elements which are partially comparable:
with their functions:
It also defines the HasseDiagram
and HasseDiagramRenderer
classes for
drawing Hasse diagram of partially ordered sets into jupyter notebooks.
- class Neighbourhood(element: _P, successors: AbstractSet[_P], predecessors: AbstractSet[_P])
The
Neighbourhood
class.It associates an element with its direct successors and predecessors. It is a dataclass containing three fields:
element
the element whose neighbourhood is considered;successors
the immediate successors of element;predecessors
the immediate predecessors of element;
- class AbstractFiniteCoveringRelation
AbstractFiniteCoveringRelation
represents the covering relation.- property co_domain: AbstractSet[_F]
Get the co-domain of this binary relation.
This is a proxy to self.universes[1].
- Returns:
The co-domain of this binary relation.
- Return type:
- property domain: AbstractSet[_E]
Get the domain of this binary relation.
This is a proxy to self.universes[0].
- Returns:
The domain of this binary relation.
- Return type:
- isdisjoint(other)
Return True if two sets have a null intersection.
- abstract neighbourhoods() Iterable[Neighbourhood[_P]]
Get an iterator over the neighbourhoods of an element.
- Returns:
An iterable giving a triple (element, successors, predecessors) for each element in the covering relation.
- Return type:
- abstract predecessors(element: _F) AbstractSet[_E]
Get the predecessors of an element.
- Parameters:
element (_F) – The element whose predecessors are requested
- Returns:
The predecessors.
- Return type:
- Raises:
ValueError – If the element does not belong to the relation.
- abstract property sinks: AbstractSet[_P]
Get the elements with no successors.
- Returns:
The elements with no successors.
- Return type:
- abstract property sources: AbstractSet[_P]
Get the elements with no predecessors.
- Returns:
The elements with no predecessors.
- Return type:
- abstract successors(element: _E) AbstractSet[_F]
Get the successors of an element.
- Parameters:
element (_E) – The element whose successors are requested
- Returns:
The successors.
- Return type:
- Raises:
ValueError – If the element does not belong to the relation.
- abstract property universes: Tuple[AbstractSet[_P], AbstractSet[_P]]
Get the universes of this relation.
- Returns:
The universes of this relation.
- Return type:
- class AbstractFiniteReversibleCoveringRelation
The
AbstractFiniteReversibleCoveringRelation
class.It represents a reversible version of the covering relation of a poset.
- property co_domain: AbstractSet[_F]
Get the co-domain of this binary relation.
This is a proxy to self.universes[1].
- Returns:
The co-domain of this binary relation.
- Return type:
- property domain: AbstractSet[_E]
Get the domain of this binary relation.
This is a proxy to self.universes[0].
- Returns:
The domain of this binary relation.
- Return type:
- isdisjoint(other)
Return True if two sets have a null intersection.
- abstract neighbourhoods() Reversible[Neighbourhood[_P]]
Get an iterator over the neighbourhoods of an element.
- Returns:
An iterable giving a triple (element, successors, predecessors) for each element in the covering relation.
- Return type:
- abstract predecessors(element: _F) AbstractSet[_E]
Get the predecessors of an element.
- Parameters:
element (_F) – The element whose predecessors are requested
- Returns:
The predecessors.
- Return type:
- Raises:
ValueError – If the element does not belong to the relation.
- abstract property sinks: AbstractSet[_P]
Get the elements with no successors.
- Returns:
The elements with no successors.
- Return type:
- abstract property sources: AbstractSet[_P]
Get the elements with no predecessors.
- Returns:
The elements with no predecessors.
- Return type:
- abstract successors(element: _E) AbstractSet[_F]
Get the successors of an element.
- Parameters:
element (_E) – The element whose successors are requested
- Returns:
The successors.
- Return type:
- Raises:
ValueError – If the element does not belong to the relation.
- abstract property universes: Tuple[AbstractSet[_P], AbstractSet[_P]]
Get the universes of this relation.
- Returns:
The universes of this relation.
- Return type:
- class AbstractFinitePartiallyOrderedSet
The :class`AbstractFinitePartiallyOrderedSet` abstract class.
A partially ordered set is an endo-relation over a set of
PartiallyComparable
elements.- __iter__() Iterator[Tuple[_P, _P]]
Get an iterator over the elements.
- Yields:
Tuple[_P, _P]
– A couple of the relation.
- abstract property bottom: AbstractSet[_P]
Get the bottom elements.
- Returns:
The bottom elements.
- Return type:
- property co_domain: AbstractSet[_F]
Get the co-domain of this binary relation.
This is a proxy to self.universes[1].
- Returns:
The co-domain of this binary relation.
- Return type:
- abstract property cover: AbstractFiniteCoveringRelation[_P]
Get the covering relation.
- Returns:
The covering relation.
- Return type:
- property domain: AbstractSet[_E]
Get the domain of this binary relation.
This is a proxy to self.universes[0].
- Returns:
The domain of this binary relation.
- Return type:
- abstract filter(element: _P) AbstractFiniteLowerBoundedSet[_P]
Get a filter of a poset.
- Parameters:
element (_P) – The lower limit
- Returns:
The lower bounded poset.
- Return type:
- Raises:
ValueError – If the element does not belong to the poset.
- abstract ideal(element: _P) AbstractFiniteUpperBoundedSet[_P]
Get an ideal of the poset.
- Parameters:
element (_P) – The upper limit
- Returns:
The upper bounded set.
- Return type:
- isdisjoint(other)
Return True if two sets have a null intersection.
- abstract predecessors(element: _F) AbstractSet[_E]
Get the predecessors of an element.
- Parameters:
element (_F) – The element whose predecessors are requested
- Returns:
The predecessors.
- Return type:
- Raises:
ValueError – If the element does not belong to the relation.
- abstract property sinks: AbstractSet[_E]
Get the sinks of this DAG.
- Returns:
The sinks of this DAG.
- Return type:
- abstract property sources: AbstractSet[_E]
Get the sources of this DAG.
- Returns:
The sources of this DAG.
- Return type:
- abstract successors(element: _E) AbstractSet[_F]
Get the successors of an element.
- Parameters:
element (_E) – The element whose successors are requested
- Returns:
The successors.
- Return type:
- Raises:
ValueError – If the element does not belong to the relation.
- abstract property top: AbstractSet[_P]
Get the top elements.
- Returns:
The top elements.
- Return type:
- abstract property universes: Tuple[AbstractSet[_P], AbstractSet[_P]]
Get the universes of this relation.
- Returns:
The universes of this relation.
- Return type:
- class AbstractFiniteUpperBoundedSet
AbstractFiniteUpperBoundedSet
represents upper bounded posets.- __iter__() Iterator[Tuple[_P, _P]]
Get an iterator over the elements.
- Yields:
Tuple[_P, _P]
– A couple of the relation.
- abstract property bottom: AbstractSet[_P]
Get the bottom elements.
- Returns:
The bottom elements.
- Return type:
- property co_domain: AbstractSet[_F]
Get the co-domain of this binary relation.
This is a proxy to self.universes[1].
- Returns:
The co-domain of this binary relation.
- Return type:
- abstract property cover: AbstractFiniteCoveringRelation[_P]
Get the covering relation.
- Returns:
The covering relation.
- Return type:
- property domain: AbstractSet[_E]
Get the domain of this binary relation.
This is a proxy to self.universes[0].
- Returns:
The domain of this binary relation.
- Return type:
- abstract filter(element: _P) AbstractFiniteLowerBoundedSet[_P]
Get a filter of a poset.
- Parameters:
element (_P) – The lower limit
- Returns:
The lower bounded poset.
- Return type:
- Raises:
ValueError – If the element does not belong to the poset.
- abstract ideal(element: _P) AbstractFiniteUpperBoundedSet[_P]
Get an ideal of the poset.
- Parameters:
element (_P) – The upper limit
- Returns:
The upper bounded set.
- Return type:
- isdisjoint(other)
Return True if two sets have a null intersection.
- abstract property maximum: _P
Get the maximum of the poset.
- Returns:
The maximum element.
- Return type:
_P
- abstract predecessors(element: _F) AbstractSet[_E]
Get the predecessors of an element.
- Parameters:
element (_F) – The element whose predecessors are requested
- Returns:
The predecessors.
- Return type:
- Raises:
ValueError – If the element does not belong to the relation.
- abstract property sinks: AbstractSet[_E]
Get the sinks of this DAG.
- Returns:
The sinks of this DAG.
- Return type:
- abstract property sources: AbstractSet[_E]
Get the sources of this DAG.
- Returns:
The sources of this DAG.
- Return type:
- abstract successors(element: _E) AbstractSet[_F]
Get the successors of an element.
- Parameters:
element (_E) – The element whose successors are requested
- Returns:
The successors.
- Return type:
- Raises:
ValueError – If the element does not belong to the relation.
- abstract property top: AbstractSet[_P]
Get the top elements.
- Returns:
The top elements.
- Return type:
- abstract property universes: Tuple[AbstractSet[_P], AbstractSet[_P]]
Get the universes of this relation.
- Returns:
The universes of this relation.
- Return type:
- class AbstractFiniteLowerBoundedSet
AbstractFiniteLowerBoundedSet
represents lower bounded posets.- __iter__() Iterator[Tuple[_P, _P]]
Get an iterator over the elements.
- Yields:
Tuple[_P, _P]
– A couple of the relation.
- abstract property bottom: AbstractSet[_P]
Get the bottom elements.
- Returns:
The bottom elements.
- Return type:
- property co_domain: AbstractSet[_F]
Get the co-domain of this binary relation.
This is a proxy to self.universes[1].
- Returns:
The co-domain of this binary relation.
- Return type:
- abstract property cover: AbstractFiniteCoveringRelation[_P]
Get the covering relation.
- Returns:
The covering relation.
- Return type:
- property domain: AbstractSet[_E]
Get the domain of this binary relation.
This is a proxy to self.universes[0].
- Returns:
The domain of this binary relation.
- Return type:
- abstract filter(element: _P) AbstractFiniteLowerBoundedSet[_P]
Get a filter of a poset.
- Parameters:
element (_P) – The lower limit
- Returns:
The lower bounded poset.
- Return type:
- Raises:
ValueError – If the element does not belong to the poset.
- abstract ideal(element: _P) AbstractFiniteUpperBoundedSet[_P]
Get an ideal of the poset.
- Parameters:
element (_P) – The upper limit
- Returns:
The upper bounded set.
- Return type:
- isdisjoint(other)
Return True if two sets have a null intersection.
- abstract property minimum: _P
Get the minimum of the poset.
- Returns:
The minimum element.
- Return type:
_P
- abstract predecessors(element: _F) AbstractSet[_E]
Get the predecessors of an element.
- Parameters:
element (_F) – The element whose predecessors are requested
- Returns:
The predecessors.
- Return type:
- Raises:
ValueError – If the element does not belong to the relation.
- abstract property sinks: AbstractSet[_E]
Get the sinks of this DAG.
- Returns:
The sinks of this DAG.
- Return type:
- abstract property sources: AbstractSet[_E]
Get the sources of this DAG.
- Returns:
The sources of this DAG.
- Return type:
- abstract successors(element: _E) AbstractSet[_F]
Get the successors of an element.
- Parameters:
element (_E) – The element whose successors are requested
- Returns:
The successors.
- Return type:
- Raises:
ValueError – If the element does not belong to the relation.
- abstract property top: AbstractSet[_P]
Get the top elements.
- Returns:
The top elements.
- Return type:
- abstract property universes: Tuple[AbstractSet[_P], AbstractSet[_P]]
Get the universes of this relation.
- Returns:
The universes of this relation.
- Return type:
- class AbstractFiniteBoundedSet
AbstractFiniteBoundedSet
represents bounded posets.- __iter__() Iterator[Tuple[_P, _P]]
Get an iterator over the elements.
- Yields:
Tuple[_P, _P]
– A couple of the relation.
- abstract property bottom: AbstractSet[_P]
Get the bottom elements.
- Returns:
The bottom elements.
- Return type:
- property co_domain: AbstractSet[_F]
Get the co-domain of this binary relation.
This is a proxy to self.universes[1].
- Returns:
The co-domain of this binary relation.
- Return type:
- abstract property cover: AbstractFiniteCoveringRelation[_P]
Get the covering relation.
- Returns:
The covering relation.
- Return type:
- property domain: AbstractSet[_E]
Get the domain of this binary relation.
This is a proxy to self.universes[0].
- Returns:
The domain of this binary relation.
- Return type:
- abstract filter(element: _P) AbstractFiniteLowerBoundedSet[_P]
Get a filter of a poset.
- Parameters:
element (_P) – The lower limit
- Returns:
The lower bounded poset.
- Return type:
- Raises:
ValueError – If the element does not belong to the poset.
- abstract ideal(element: _P) AbstractFiniteUpperBoundedSet[_P]
Get an ideal of the poset.
- Parameters:
element (_P) – The upper limit
- Returns:
The upper bounded set.
- Return type:
- isdisjoint(other)
Return True if two sets have a null intersection.
- abstract property maximum: _P
Get the maximum of the poset.
- Returns:
The maximum element.
- Return type:
_P
- abstract property minimum: _P
Get the minimum of the poset.
- Returns:
The minimum element.
- Return type:
_P
- abstract predecessors(element: _F) AbstractSet[_E]
Get the predecessors of an element.
- Parameters:
element (_F) – The element whose predecessors are requested
- Returns:
The predecessors.
- Return type:
- Raises:
ValueError – If the element does not belong to the relation.
- abstract property sinks: AbstractSet[_E]
Get the sinks of this DAG.
- Returns:
The sinks of this DAG.
- Return type:
- abstract property sources: AbstractSet[_E]
Get the sources of this DAG.
- Returns:
The sources of this DAG.
- Return type:
- abstract successors(element: _E) AbstractSet[_F]
Get the successors of an element.
- Parameters:
element (_E) – The element whose successors are requested
- Returns:
The successors.
- Return type:
- Raises:
ValueError – If the element does not belong to the relation.
- abstract property top: AbstractSet[_P]
Get the top elements.
- Returns:
The top elements.
- Return type:
- abstract property universes: Tuple[AbstractSet[_P], AbstractSet[_P]]
Get the universes of this relation.
- Returns:
The universes of this relation.
- Return type:
- class PartiallyComparable
Partially comparable elements.
A partially ordered type sets for each pair of elements \(a\), \(b\) either:
\(a \leq b\)
\(b \leq a\)
a and b are incomparable (\(a \| b\))
The relation \(\leq\) must be:
reflexive (\(a \leq a\))
transitive (\(a \leq b\) and \(b \leq c\) implies \(a \leq c\))
anti-symmetric (\(a \leq b\) and \(b \leq a\) implies \(a = b\))
A class implementing the
PartiallyComparable
abstract class must be declared by inheriting fromPartiallyComparable
and must implement the methods:Example
Let the integers ordered by the relation \(a \leq b\): is \(a\) a divisor of \(b\)?
implemented by the
PrimeFactors
class:>>> from galactic.algebras.examples.arithmetic import PrimeFactors >>> PrimeFactors(5) <= PrimeFactors(10) # 5 is a divisor of 10 True >>> PrimeFactors(5) <= PrimeFactors(11) # 5 is not a divisor of 11 False >>> PrimeFactors(5) >= PrimeFactors(11) # 5 is not a multiple of 11 False
- abstract __eq__(other: object) bool
Test if this element is equal to the other.
- Parameters:
other (object) – the other element
- Returns:
True
– if this element is equal to the other.NotImplemented
– if the operation is not implemented between the two objects
- __ge__(other: object) bool
Test if this element is greater than or equal to the other.
- Parameters:
other (object) – the other element
- Returns:
True
– if this element is greater than or equal to the other.NotImplemented
– if the operation is not implemented between the two objects
- abstract __gt__(other: object) bool
Test if this element is greater than the other.
- Parameters:
other (object) – the other element
- Returns:
True
– if this element is greater than the other.NotImplemented
– if the operation is not implemented between the two objects
- bottom(iterable: Iterable[_P]) Iterator[_P]
Compute an iterator over the bottom elements of the iterable.
This operation computes in \(O(n^2)\) where \(n\) is the number of elements in the iterable.
- Parameters:
iterable (
Iterable[_P]
) – An iterable of partially ordered elements.- Returns:
An iterator over the bottom elements.
- Return type:
Example
>>> from galactic.algebras.poset import top >>> values = [{1, 2, 3}, {1, 2, 3, 4}, {2, 3, 4, 5}] >>> list(bottom(list(map(frozenset, values)))) [frozenset({1, 2, 3}), frozenset({2, 3, 4, 5})]
- top(iterable: Iterable[_P]) Iterator[_P]
Compute an iterator over the top elements of the iterable.
This operation computes in \(O(n^2)\) where \(n\) is the number of elements in the iterable.
- Parameters:
iterable (
Iterable[_P]
) – An iterable of partially ordered elements.- Returns:
An iterator over the top elements.
- Return type:
Example
>>> from galactic.algebras.poset import top
>>> values = [{1, 2, 3}, {1, 2, 3, 4}, {2, 3, 4, 5}] >>> list(top(list(map(frozenset, values)))) [frozenset({1, 2, 3, 4}), frozenset({2, 3, 4, 5})]
- lower_limit(iterable: Iterable[_P], limit: _P, strict: bool = False) Iterator[_P]
Compute an iterator over the elements greater than the limit.
This operation computes in \(O(n)\) where \(n\) is the number of elements in the iterable.
- Parameters:
iterable (
Iterable[_P]
) – An iterable of partially ordered elements.limit (_P) – The lower limit
strict (bool) – Is the comparison strict?
- Yields:
_P – A selected element
Example
>>> from galactic.algebras.poset import lower_limit >>> values = [{1, 2}, {1, 2, 3}, {2, 3}] >>> list(lower_limit(list(map(frozenset, values)), frozenset({2, 3}))) [frozenset({1, 2, 3}), frozenset({2, 3})]
# noqa: DAR301
- upper_limit(iterable: Iterable[_P], limit: _P, strict: bool = False) Iterator[_P]
Compute an iterator over the elements lesser than the limit.
This operation computes in \(O(n)\) where \(n\) is the number of elements in the iterable.
- Parameters:
iterable (
Iterable[_P]
) – An iterable of partially ordered elements.limit (_P) – The upper limit
strict (bool) – Is the comparison strict?
- Yields:
_P – A selected element.
Example
>>> from galactic.algebras.poset import upper_limit >>> values = [{1, 2}, {1, 2, 3}, {2, 3}] >>> list(upper_limit(list(map(frozenset, values)), frozenset({2, 3}))) [frozenset({2, 3})]
# noqa: DAR301
- class FiniteReversibleCoveringRelation(domain: Iterable[_P] | None = None)
FiniteReversibleCoveringRelation
represents the covering relation.- __copy__() FiniteReversibleCoveringRelation[_P]
Get a copy of the covering relation.
Its complexity is in \(O(n)\).
- Returns:
The copy of this covering relation.
- Return type:
- __init__(domain: Iterable[_P] | None = None) None
Initialise a
FiniteReversibleCoveringRelation
instance.The initializer can take 0 or 1 argument that should be iterable.
- Parameters:
domain (
Iterable[_P]
, optional) – The domain of the covering relation.
- property co_domain: MutableSet[_P]
Get the co-domain of this covering relation.
- Returns:
The co-domain of this covering relation.
- Return type:
Notes
The domain and the co-domain of a covering relation are identical.
- property domain: MutableSet[_P]
Get the domain of this covering relation.
- Returns:
The domain of this covering relation.
- Return type:
- extend(iterable: Iterable[_P]) None
Extend this covering relation.
- Parameters:
iterable (
Iterable[_P]
) – An iterable of values.
- isdisjoint(other)
Return True if two sets have a null intersection.
- neighbourhoods() Reversible[Neighbourhood[_P]]
Get an iterator over the neighbourhoods of an element.
- Returns:
An iterable giving a triple (element, successors, predecessors) for each element in the covering relation.
- Return type:
- predecessors(element: _P) AbstractSet[_P]
Get the predecessors of an element.
- Parameters:
element (_P) – The element whose predecessors are requested
- Returns:
The predecessors.
- Return type:
- Raises:
ValueError – If the element does not belong to the covering relation.
- property sinks: AbstractSet[_P]
Get the elements with no successors.
- Returns:
The elements with no successors.
- Return type:
- property sources: AbstractSet[_P]
Get the elements with no predecessors.
- Returns:
The elements with no predecessors.
- Return type:
- successors(element: _P) AbstractSet[_P]
Get the successors of an element.
- Parameters:
element (_P) – The element whose successors are requested
- Returns:
The successors.
- Return type:
- Raises:
ValueError – If the element does not belong to the covering relation.
- property universes: Tuple[MutableSet[_P], MutableSet[_P]]
Get the universes of this covering relation.
- Returns:
The universes of this covering relation.
- Return type:
- class FinitePartiallyOrderedSet(domain: Iterable[_P] | None = None)
FinitePartiallyOrderedSet
implements posets.A
FinitePartiallyOrderedSet
instance stores its values in two dictionaries for the immediate successors (\(\succ\)) and the immediate predecessors (\(\prec\)).Its memory complexity is in \(O(n)\).
Operation complexities:
__contains__()
: \(O(1)\)__len__()
: \(O(1)\)__iter__()
: \(O(1)\)top()
: \(O(1)\)bottom()
: \(O(1)\)successors()
: \(O(1)\)predecessors()
: \(O(1)\)
Example
>>> from galactic.algebras.poset import FinitePartiallyOrderedSet >>> from galactic.algebras.examples.arithmetic import PrimeFactors >>> poset = FinitePartiallyOrderedSet[PrimeFactors]( ... domain=[ ... PrimeFactors(2*3*5*7), ... PrimeFactors(3*5*7*11), ... PrimeFactors(3*5*7), ... PrimeFactors(3*5), ... PrimeFactors(5), ... PrimeFactors(7), ... ] ... ) >>>
It’s possible to iterate over the poset elements. The elements are iterated level by level starting from the top ones.
Example
>>> sorted(list(map(int, poset.domain))) [5, 7, 15, 105, 210, 1155]
It’s possible to know the poset length.
Example
>>> len(poset.domain) 6
It’s possible to know if an element is in the poset.
Example
>>> PrimeFactors(210) in poset.domain True >>> PrimeFactors(211) in poset.domain False
It’s possible to iterate over the top and bottom elements.
Example
>>> sorted(list(map(int, poset.top))) [210, 1155] >>> sorted(list(map(int, poset.bottom))) [5, 7]
It’s possible to iterate over the descendants and the ascendants of an element.
Example
>>> sorted(list(map(int, poset.filter(PrimeFactors(105)).domain))) [105, 210, 1155] >>> sorted(list(map(int, poset.ideal(PrimeFactors(105)).domain))) [5, 7, 15, 105]
It’s possible to iterate over the (immediate) successors and the (immediate) predecessors of an element.
Example
>>> sorted(list(map(int, poset.cover.successors(PrimeFactors(105))))) [210, 1155] >>> sorted(list(map(int, poset.successors(PrimeFactors(105))))) [105, 210, 1155] >>> sorted(list(map(int, poset.cover.predecessors(PrimeFactors(105))))) [7, 15] >>> sorted(list(map(int, poset.predecessors(PrimeFactors(105))))) [5, 7, 15, 105]
It’s possible to enlarge a partially ordered set.
Example
>>> poset.extend([PrimeFactors(13)]) >>> sorted(list(map(int, poset.domain))) [5, 7, 13, 15, 105, 210, 1155]
- __copy__() FinitePartiallyOrderedSet[_P]
Get a copy of the partially ordered set.
Its complexity is in \(O(n)\).
- Returns:
The copy of this poset.
- Return type:
PartiallyOrderedSet[_P]
- __init__(domain: Iterable[_P] | None = None) None
Initialise a
FinitePartiallyOrderedSet
instance.The initializer can take 0 or 1 argument that should be iterable.
- Parameters:
domain (
Iterable[_P]
, optional) – An iterable of values.
- __iter__() Iterator[Tuple[_P, _P]]
Get an iterator over the elements.
- Yields:
Tuple[_P, _P]
– A couple of the relation.
- property bottom: AbstractSet[_P]
Get the bottom elements.
- Returns:
The bottom elements.
- Return type:
- property co_domain: MutableSet[_P]
Get the co-domain of this poset.
- Returns:
The co-domain of this poset.
- Return type:
Notes
The domain and the co-domain of a poset are identical.
- property cover: FiniteReversibleCoveringRelation[_P]
Get the covering relation of this poset.
- Returns:
The covering relation.
- Return type:
- property domain: MutableSet[_P]
Get the domain of this poset.
- Returns:
The domain of this poset.
- Return type:
- extend(iterable: Iterable[_P]) None
Extend this poset.
- Parameters:
iterable (
Iterable[_P]
) – An iterable of values.
- filter(element: _P) AbstractFiniteLowerBoundedSet[_P]
Get a filter of a poset.
- Parameters:
element (_P) – The lower limit
- Returns:
The lower bounded poset.
- Return type:
- Raises:
ValueError – If the element does not belong to the poset.
- ideal(element: _P) AbstractFiniteUpperBoundedSet[_P]
Get an ideal of the poset.
- Parameters:
element (_P) – The upper limit
- Returns:
The upper bounded set.
- Return type:
- Raises:
ValueError – If the element does not belong to the poset.
- isdisjoint(other)
Return True if two sets have a null intersection.
- predecessors(element: _P) AbstractSet[_P]
Get the predecessors of an element.
- Parameters:
element (_P) – The element whose predecessors are requested
- Returns:
The predecessors.
- Return type:
- Raises:
ValueError – If the element does not belong to the poset.
- property sinks: AbstractSet[_P]
Get the sink elements.
- Returns:
The sink elements.
- Return type:
- property sources: AbstractSet[_P]
Get the source elements.
- Returns:
The source elements.
- Return type:
- successors(element: _P) AbstractSet[_P]
Get the successors of an element.
- Parameters:
element (_P) – The element whose successors are requested
- Returns:
The successors.
- Return type:
- Raises:
ValueError – If the element does not belong to the poset.
- property top: AbstractSet[_P]
Get the top elements.
- Returns:
The top elements.
- Return type:
- property universes: Tuple[MutableSet[_P], MutableSet[_P]]
Get the universes of this poset.
- Returns:
The universes of this poset.
- Return type:
- class HasseDiagramRenderer
HasseDiagramRenderer
renders graph attributes.Notes
- add_destination(element: _F, index: int | None = None, current: bool = False, successors: AbstractSet[_E] | None = None, predecessors: AbstractSet[_E] | None = None) None
Add a destination to the graph.
- Parameters:
element (_F) – The destination to add.
index (int, optional) – The destination index.
current (bool) – is element the current element?
successors (
AbstractSet[_E]
, optional) – The successors of the destination.predecessors (
AbstractSet[_E]
, optional) – The predecessors of the destination.
- add_edge(source: _E, destination: _F, successors: AbstractSet[_F] | None = None, predecessors: AbstractSet[_E] | None = None) None
Add an edge to the graph.
- Parameters:
source (_E) – The edge source
destination (_F) – The edge destination
successors (
AbstractSet[_F]
, optional) – The successors of source (including current destination).predecessors (
AbstractSet[_E]
, optional) – The predecessors of destination (including current source).
- add_source(element: _E, index: int | None = None, current: bool = False, successors: AbstractSet[_F] | None = None, predecessors: AbstractSet[_F] | None = None) None
Add a source to the graph.
- Parameters:
element (_E) – The source to add.
index (int, optional) – The source index.
current (bool) – is element the current element?
successors (
AbstractSet[_F]
, optional) – The successors of the source.predecessors (
AbstractSet[_F]
, optional) – The predecessors of the source.
- class DynamicDiagram(graph_renderer: HasseDiagramRenderer[_P] | None = None, domain_renderer: NodeRenderer[_P, _P] | None = None, edge_renderer: EdgeRenderer[_P, _P] | None = None)
DynamicDiagram
is designed to allow dynamic graph rendering.- __init__(graph_renderer: HasseDiagramRenderer[_P] | None = None, domain_renderer: NodeRenderer[_P, _P] | None = None, edge_renderer: EdgeRenderer[_P, _P] | None = None) None
Initialise a
DynamicDiagram
instance.- Parameters:
graph_renderer (
HasseDiagramRendererRenderer[_P]
) – A Hasse diagram renderer.domain_renderer (
NodeRenderer[_P, _P]
) – A node renderer.edge_renderer (
EdgeRenderer[_P, _P]
) – An edge renderer.
- property body: Sequence[str]
Get the current graphviz body.
- Returns:
The current body.
- Return type:
- render(filename: str) None
Render the diagram in a file.
- Parameters:
filename (str) – A file path.
- property source: str
Get the graphviz source for this diagram.
- Returns:
The graphviz output for this diagram.
- Return type:
- step(element: _P, successors: AbstractSet[_P], predecessors: AbstractSet[_P]) None
Insert a new element in the diagram.
- Parameters:
element (_P) – The new element
successors (
AbstractSet[_P]
) – The immediate successors of the element.predecessors (
AbstractSet[_P]
) – The immediate predecessors of the element.
- class HasseDiagram(poset: AbstractFinitePartiallyOrderedSet[_P], graph_renderer: HasseDiagramRenderer[_P] | None = None, domain_renderer: NodeRenderer[_P, _P] | None = None, edge_renderer: EdgeRenderer[_P, _P] | None = None)
HasseDiagram
is used for drawing Hasse diagrams.- __init__(poset: AbstractFinitePartiallyOrderedSet[_P], graph_renderer: HasseDiagramRenderer[_P] | None = None, domain_renderer: NodeRenderer[_P, _P] | None = None, edge_renderer: EdgeRenderer[_P, _P] | None = None) None
Initialise a Hasse diagram instance.
- Parameters:
poset (
AbstractFinitePartiallyOrderedSet[_P]
) – A poset.graph_renderer (
HasseDiagramRenderer[_P]
, optional) – A Hasse diagram renderer.domain_renderer (
NodeRenderer[_P, _P]
, optional) – A node renderer.edge_renderer (
EdgeRenderer[_P, _P]
, optional) – An edge renderer.
- property domain_renderer: NodeRenderer[_P, _P]
Get the domain renderer.
- Returns:
The domain renderer.
- Return type:
- property edge_renderer: EdgeRenderer[_P, _P]
Get the edge renderer.
- Returns:
The edge renderer.
- Return type:
- property graph_renderer: HasseDiagramRenderer[_P]
Get the Hasse diagram renderer.
- Returns:
The Hasse diagram renderer.
- Return type:
- property poset: AbstractFinitePartiallyOrderedSet[_P]
Get the poset.
- Returns:
The underlying poset.
- Return type:
- class IterativeDiagram(poset: AbstractFinitePartiallyOrderedSet[_P], graph_renderer: HasseDiagramRenderer[_P] | None = None, domain_renderer: NodeRenderer[_P, _P] | None = None, edge_renderer: EdgeRenderer[_P, _P] | None = None)
IterativeDiagram
allows iterative rendering.- __init__(poset: AbstractFinitePartiallyOrderedSet[_P], graph_renderer: HasseDiagramRenderer[_P] | None = None, domain_renderer: NodeRenderer[_P, _P] | None = None, edge_renderer: EdgeRenderer[_P, _P] | None = None) None
Initialise a
IterativeDiagram
instance.- Parameters:
poset (
AbstractFinitePartiallyOrderedSet[_P]
) – A poset.graph_renderer (
HasseDiagramRenderer[_P]
) – A Hasse diagram renderer renderer.domain_renderer (
NodeRenderer[_P, _P]
) – A node renderer.edge_renderer (
EdgeRenderer[_P, _P]
) – An edge renderer.