Lattices¶
The galactic.algebras.lattice
module defines types for representing lattices.
Elements of semi-lattices and lattices:
Joinable
for joinable elements;Meetable
for meetable elements;Element
for joinable and meetable elements.
Function on elements of semi-lattices and lattices:
Abstract classes of semi-lattices and lattices:
and their implementations:
It also defines the ReducedContextDiagram
class for drawing sagittal diagram of
reduced context lattices.
-
class
Element
(*args, **kwds)¶ The
Element
class describes elements that can be member of a lattice.-
abstract
__and__
(other: Any) → galactic.algebras.lattice.Meetable¶ Return the meet of this element and the other.
-
__ge__
(other: Any) → bool¶ Test if this element is greater than or equal to the other.
- Parameters
other – 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: Any) → bool¶ Test if this element is greater than the other.
- Parameters
other – the other element
- Returns
True
– if this element is greater than the other.NotImplemented
– if the operation is not implemented between the two objects
-
__le__
(other: Any) → bool¶ Test if this element is lesser than or equal to the other.
- Parameters
other – the other element
- Returns
True
– if this element is lesser than or equal to the other.NotImplemented
– if the operation is not implemented between the two objects
-
abstract
__lt__
(other: Any) → bool¶ Test if this element is lesser than the other.
- Parameters
other – the other element
- Returns
True
– if this element is lesser than the other.NotImplemented
– if the operation is not implemented between the two objects
-
abstract
__or__
(other: Any) → galactic.algebras.lattice.Joinable¶ Return the join of this element and the other.
-
intersection
(*args: Any) → galactic.algebras.lattice.Meetable¶ Return the intersection of this element and the others.
-
union
(*args: Any) → galactic.algebras.lattice.Joinable¶ Return the union of this element and the others.
-
abstract
-
class
Joinable
(*args, **kwds)¶ The
Joinable
class.This class sets for each pair of elements a, b an unique supremum \(c = a \vee b\) (also called a least upper bound or join).
A class implementing the:class:Joinable abstract class must be declared by inheriting from
Joinable
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
Integer
class:>>> from galactic.examples.arithmetic import Integer >>> Integer(24) | Integer(36) Integer(72) >>> Integer(24).union(Integer(36), Integer(10)) Integer(360)
-
__ge__
(other: Any) → bool¶ Test if this element is greater than or equal to the other.
- Parameters
other – 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: Any) → bool¶ Test if this element is greater than the other.
- Parameters
other – the other element
- Returns
True
– if this element is greater than the other.NotImplemented
– if the operation is not implemented between the two objects
-
__le__
(other: Any) → bool¶ Test if this element is lesser than or equal to the other.
- Parameters
other – the other element
- Returns
True
– if this element is lesser than or equal to the other.NotImplemented
– if the operation is not implemented between the two objects
-
abstract
__lt__
(other: Any) → bool¶ Test if this element is lesser than the other.
- Parameters
other – the other element
- Returns
True
– if this element is lesser than the other.NotImplemented
– if the operation is not implemented between the two objects
-
abstract
__or__
(other: Any) → galactic.algebras.lattice.Joinable¶ Return the join of this element and the other.
-
union
(*args: Any) → galactic.algebras.lattice.Joinable¶ Return the union of this element and the others.
-
-
class
Meetable
(*args, **kwds)¶ The
Meetable
class.This type sets for each pair of elements a, b an unique infimum \(c = a \wedge b\) (also called a greatest lower bound or meet).
A class implementing the
Meetable
abstract class must be declared by inheriting fromMeetable
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
Integer
class:>>> from galactic.examples.arithmetic import Integer >>> Integer(24) & Integer(36) Integer(12) >>> Integer(24).intersection(Integer(36), Integer(10)) Integer(2)
-
abstract
__and__
(other: Any) → galactic.algebras.lattice.Meetable¶ Return the meet of this element and the other.
-
__ge__
(other: Any) → bool¶ Test if this element is greater than or equal to the other.
- Parameters
other – 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: Any) → bool¶ Test if this element is greater than the other.
- Parameters
other – the other element
- Returns
True
– if this element is greater than the other.NotImplemented
– if the operation is not implemented between the two objects
-
__le__
(other: Any) → bool¶ Test if this element is lesser than or equal to the other.
- Parameters
other – the other element
- Returns
True
– if this element is lesser than or equal to the other.NotImplemented
– if the operation is not implemented between the two objects
-
abstract
__lt__
(other: Any) → bool¶ Test if this element is lesser than the other.
- Parameters
other – the other element
- Returns
True
– if this element is lesser than the other.NotImplemented
– if the operation is not implemented between the two objects
-
intersection
(*args: Any) → galactic.algebras.lattice.Meetable¶ Return the intersection of this element and the others.
-
abstract
-
infimum
(iterable: Iterable[_M]) → galactic.algebras.lattice.Meetable¶ Compute the infimum of meetable elements.
- Parameters
iterable (
Iterable[_M]
) – An iterable collection of meetable elements.- Returns
The intersection of all elements from the iterable collection.
- Return type
- Raises
ValueError – If the iterable is empty.
-
supremum
(iterable: Iterable[_J]) → galactic.algebras.lattice.Joinable¶ Compute the supremum of joinable elements.
- Parameters
iterable (
Iterable[_J]
) – An iterable collection of joinable elements.- Returns
The union of all elements from the iterable collection.
- Return type
- Raises
ValueError – If the iterable is empty.
-
infimum_generators
(iterable: Iterable[_M]) → Iterator[_M]¶ Produce the infimum generators from an iterable of meetable elements.
- Parameters
iterable (
Iterable[_M]
) – The iterable collection of elements.- Returns
An iterator over the infimum generators.
- Return type
-
supremum_generators
(iterable: Iterable[_J]) → Iterator[_J]¶ Produce the supremum generators from an iterable of joinable elements.
- Parameters
iterable (
Iterable[_J]
) – The iterable collection of elements.- Returns
An iterator over the supremum generators.
- Return type
-
class
AbstractJoinSemiLattice
(*args, **kwds)¶ The
AbstractJoinSemiLattice
class describes finite join semi-lattices.-
__iter__
() → Iterator[Tuple[_P, _P]]¶ Get an iterator over the elements.
- Returns
An iterator over the elements
- Return type
-
abstract property
bottom
¶ Get the bottom elements.
- Returns
The bottom elements.
- Return type
-
abstract property
co_atoms
¶ Get the co-atoms of this join semi-lattice.
- Returns
The co-atoms.
- Return type
-
property
co_domain
¶ 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
¶ Get the covering relation.
- Returns
The covering relation.
- Return type
AbstractCoveringRelation[_P]
-
property
domain
¶ 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) → galactic.algebras.poset.AbstractLowerBoundedSet[_P]¶ Get a filter of a poset.
- Parameters
element (
_P
) – The lower limit- Returns
The lower bounded poset.
- Return type
AbstractLowerBoundedSet[_P]
- Raises
ValueError – If the element does not belong to the poset.
-
abstract
greatest_join_irreducible
(element: _J) → AbstractSet[_J]¶ Get the greatest join irreducible smaller than an element.
- Parameters
element (
_J
) – The element whose greatest join irreducible are requested- Returns
The greatest join irreducible smaller than the element.
- Return type
- Raises
ValueError – If the element does not belong to the join semi-lattice.
-
abstract
ideal
(element: _P) → galactic.algebras.poset.AbstractUpperBoundedSet[_P]¶ Get an ideal of the poset.
- Parameters
element (
_P
) – The upper limit- Returns
The upper bounded set.
- Return type
AbstractUpperBoundedSet[_P]
-
isdisjoint
(other)¶ Return True if two sets have a null intersection.
-
abstract property
join_irreducible
¶ Get the join irreducible elements.
- Returns
The join irreducible elements.
- Return type
-
abstract property
maximum
¶ Get the maximum of the poset.
- Returns
The maximum element.
- 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
¶ Get the sinks of this DAG.
- Returns
The sinks of this DAG.
- Return type
-
abstract property
sources
¶ 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
¶ Get the top elements.
- Returns
The top elements.
- Return type
-
abstract property
universes
¶ Get the universes of this relation.
- Returns
The universes of this relation.
- Return type
-
-
class
AbstractLowerBoundedJoinSemiLattice
(*args, **kwds)¶ The
AbstractLowerBoundedJoinSemiLattice
class.It represents abstract lower bounded join semi-lattices.
-
__iter__
() → Iterator[Tuple[_P, _P]]¶ Get an iterator over the elements.
- Returns
An iterator over the elements
- Return type
-
abstract property
bottom
¶ Get the bottom elements.
- Returns
The bottom elements.
- Return type
-
abstract property
co_atoms
¶ Get the co-atoms of this join semi-lattice.
- Returns
The co-atoms.
- Return type
-
property
co_domain
¶ 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
¶ Get the covering relation.
- Returns
The covering relation.
- Return type
AbstractCoveringRelation[_P]
-
property
domain
¶ 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) → galactic.algebras.poset.AbstractLowerBoundedSet[_P]¶ Get a filter of a poset.
- Parameters
element (
_P
) – The lower limit- Returns
The lower bounded poset.
- Return type
AbstractLowerBoundedSet[_P]
- Raises
ValueError – If the element does not belong to the poset.
-
abstract
greatest_join_irreducible
(element: _J) → AbstractSet[_J]¶ Get the greatest join irreducible smaller than an element.
- Parameters
element (
_J
) – The element whose greatest join irreducible are requested- Returns
The greatest join irreducible smaller than the element.
- Return type
- Raises
ValueError – If the element does not belong to the join semi-lattice.
-
abstract
ideal
(element: _P) → galactic.algebras.poset.AbstractUpperBoundedSet[_P]¶ Get an ideal of the poset.
- Parameters
element (
_P
) – The upper limit- Returns
The upper bounded set.
- Return type
AbstractUpperBoundedSet[_P]
-
isdisjoint
(other)¶ Return True if two sets have a null intersection.
-
abstract property
join_irreducible
¶ Get the join irreducible elements.
- Returns
The join irreducible elements.
- Return type
-
abstract property
maximum
¶ Get the maximum of the poset.
- Returns
The maximum element.
- Return type
-
abstract property
minimum
¶ Get the minimum of the poset.
- Returns
The minimum element.
- 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
¶ Get the sinks of this DAG.
- Returns
The sinks of this DAG.
- Return type
-
abstract property
sources
¶ 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
¶ Get the top elements.
- Returns
The top elements.
- Return type
-
abstract property
universes
¶ Get the universes of this relation.
- Returns
The universes of this relation.
- Return type
-
-
class
JoinSemiLattice
(domain: Iterable[_J])¶ The
JoinSemiLattice
class.It implements methods of
AbstractJoinSemiLattice
.A
JoinSemiLattice
instance stores its irreducible in aPartiallyOrderedSet
.Its memory complexity is in \(O(j)\)
Example
>>> from galactic.algebras.lattice import MeetSemiLattice >>> from galactic.examples.arithmetic import Integer >>> m = MeetSemiLattice[Integer]( ... domain = [ ... Integer(2*3*5), ... Integer(3*5*7), ... Integer(5*7*11) ... ] ... ) >>>
It’s possible to get the minimum element.
Example
>>> int(m.minimum) 5
It’s possible to iterate over the elements.
Example
>>> sorted(list(map(int, m.domain))) [5, 15, 30, 35, 105, 385]
It’s possible to iterate over the atoms.
Example
>>> sorted(list(map(int, m.atoms))) [15, 35]
It’s possible to iterate over the meet irreducible.
Example
>>> sorted(list(map(int, m.meet_irreducible))) [30, 105, 385]
It’s possible to iterate over the smallest meet irreducible greater than an element.
Example
>>> sorted(list(map(int, m.smallest_meet_irreducible(Integer(5*7))))) [105, 385]
It’s possible to enlarge a meet semi-lattice.
Example
>>> m.extend([Integer(13)]) >>> sorted(list(map(int, m.domain))) [1, 5, 13, 15, 30, 35, 105, 385]
-
__copy__
() → galactic.algebras.lattice.JoinSemiLattice[_J]¶ Get a copy of the join semi-lattice.
This operation is in \(O(j)\).
- Returns
The copy of this join semi-lattice.
- Return type
-
__init__
(domain: Iterable[_J])¶ Initialise a
JoinSemiLattice
instance.- Parameters
domain (
Optional[Iterable[_J]]
) – An initial domain.- Raises
ValueError – If the iterable is empty.
-
__iter__
() → Iterator[Tuple[_J, _J]]¶ Get an iterator over the elements.
- Returns
an iterator over the elements
- Return type
-
property
bottom
¶ Get the bottom elements.
- Returns
The bottom elements.
- Return type
-
property
co_atoms
¶ Get the co-atoms of this join semi-lattice.
- Returns
The co-atoms.
- Return type
-
property
co_domain
¶ Get the co-domain of this semi-lattice.
- Returns
The co-domain of this semi-lattice.
- Return type
-
property
cover
¶ Get the covering relation of this join semi-lattice.
- Returns
The covering relation.
- Return type
-
property
domain
¶ Get the domain of this semi-lattice.
- Returns
The domain of this semi-lattice.
- Return type
-
extend
(iterable: Iterable[_J]) → None¶ Extend this join semi-lattice.
- Parameters
iterable (
Iterable[_M]
) – An iterable of values.
-
filter
(element: _J) → galactic.algebras.lattice.AbstractLowerBoundedJoinSemiLattice[_J]¶ Get a filter of a join semi-lattice.
- Parameters
element (
_J
) – The lower limit- Returns
The lower bounded join semi-lattice.
- Return type
- Raises
ValueError – If the element does not belong to the poset.
-
greatest_join_irreducible
(element: _J) → AbstractSet[_J]¶ Get the greatest join irreducible smaller than an element.
- Parameters
element (
_J
) – The element whose greatest join irreducible are requested- Returns
The greatest join irreducible smaller than the element.
- Return type
- Raises
ValueError – If the element does not belong to the join semi-lattice.
-
ideal
(element: _J) → galactic.algebras.lattice.AbstractJoinSemiLattice[_J]¶ Get an ideal of a join semi-lattice.
- Parameters
element (
_J
) – The upper limit- Returns
The upper bounded join semi-lattice.
- Return type
- Raises
ValueError – If the element does not belong to the poset.
-
isdisjoint
(other)¶ Return True if two sets have a null intersection.
-
property
join_irreducible
¶ Get the join-irreducible elements of this join semi-lattice.
- Returns
The join-irreducible elements.
- Return type
-
lower_limit
(limit: _J, strict: bool = False) → AbstractSet[_J]¶ Get the elements greater than a
limit
.- Parameters
- Returns
The selected elements.
- Return type
-
property
maximum
¶ Get the maximum element of this join semi-lattice.
- Returns
The maximum element
- Return type
-
predecessors
(element: _J) → AbstractSet[_J]¶ Get the predecessors of an
element
.- Parameters
element (
_J
) – The element whose predecessors are requested- Returns
The predecessors.
- Return type
- Raises
ValueError – If the element does not belong to the semi-lattice.
-
property
sinks
¶ Get the sink elements.
The collection contains only one element, the maximum element.
- Returns
The sink elements.
- Return type
-
property
sources
¶ Get the source elements.
- Returns
The source elements.
- Return type
-
successors
(element: _J) → AbstractSet[_J]¶ Get the successors of an
element
.- Parameters
element (
_J
) – The element whose successors are requested- Returns
The successors.
- Return type
- Raises
ValueError – If the element does not belong to the semi-lattice.
-
property
top
¶ Get the top elements.
The collection contains only one element, the maximum element.
- Returns
The top elements.
- Return type
-
property
universes
¶ Get the universes of this join semi-lattice.
- Returns
The universes.
- Return type
-
-
class
AbstractMeetSemiLattice
(*args, **kwds)¶ The
AbstractMeetSemiLattice
class describes finite meet semi-lattices.-
__iter__
() → Iterator[Tuple[_P, _P]]¶ Get an iterator over the elements.
- Returns
An iterator over the elements
- Return type
-
abstract property
atoms
¶ Get the atoms of this meet semi-lattice.
- Returns
The atoms.
- Return type
-
abstract property
bottom
¶ Get the bottom elements.
- Returns
The bottom elements.
- Return type
-
property
co_domain
¶ 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
¶ Get the covering relation.
- Returns
The covering relation.
- Return type
AbstractCoveringRelation[_P]
-
property
domain
¶ 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) → galactic.algebras.poset.AbstractLowerBoundedSet[_P]¶ Get a filter of a poset.
- Parameters
element (
_P
) – The lower limit- Returns
The lower bounded poset.
- Return type
AbstractLowerBoundedSet[_P]
- Raises
ValueError – If the element does not belong to the poset.
-
abstract
ideal
(element: _P) → galactic.algebras.poset.AbstractUpperBoundedSet[_P]¶ Get an ideal of the poset.
- Parameters
element (
_P
) – The upper limit- Returns
The upper bounded set.
- Return type
AbstractUpperBoundedSet[_P]
-
isdisjoint
(other)¶ Return True if two sets have a null intersection.
-
abstract property
meet_irreducible
¶ Get the meet irreducible elements.
- Returns
The meet irreducible elements.
- Return type
-
abstract property
minimum
¶ Get the minimum of the poset.
- Returns
The minimum element.
- 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
¶ Get the sinks of this DAG.
- Returns
The sinks of this DAG.
- Return type
-
abstract
smallest_meet_irreducible
(element: _M) → AbstractSet[_M]¶ Get the smallest meet irreducible greater than an element.
- Parameters
element (
_M
) – The element whose smallest meet irreducible are requested- Returns
The smallest meet irreducible greater than the element.
- Return type
- Raises
ValueError – If the element does not belong to the meet semi-lattice.
-
abstract property
sources
¶ 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
¶ Get the top elements.
- Returns
The top elements.
- Return type
-
abstract property
universes
¶ Get the universes of this relation.
- Returns
The universes of this relation.
- Return type
-
-
class
AbstractUpperBoundedMeetSemiLattice
(*args, **kwds)¶ The
AbstractUpperBoundedMeetSemiLattice
class.It represents abstract upper bounded meet semi-lattices.
-
__iter__
() → Iterator[Tuple[_P, _P]]¶ Get an iterator over the elements.
- Returns
An iterator over the elements
- Return type
-
abstract property
atoms
¶ Get the atoms of this meet semi-lattice.
- Returns
The atoms.
- Return type
-
abstract property
bottom
¶ Get the bottom elements.
- Returns
The bottom elements.
- Return type
-
property
co_domain
¶ 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
¶ Get the covering relation.
- Returns
The covering relation.
- Return type
AbstractCoveringRelation[_P]
-
property
domain
¶ 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) → galactic.algebras.poset.AbstractLowerBoundedSet[_P]¶ Get a filter of a poset.
- Parameters
element (
_P
) – The lower limit- Returns
The lower bounded poset.
- Return type
AbstractLowerBoundedSet[_P]
- Raises
ValueError – If the element does not belong to the poset.
-
abstract
ideal
(element: _P) → galactic.algebras.poset.AbstractUpperBoundedSet[_P]¶ Get an ideal of the poset.
- Parameters
element (
_P
) – The upper limit- Returns
The upper bounded set.
- Return type
AbstractUpperBoundedSet[_P]
-
isdisjoint
(other)¶ Return True if two sets have a null intersection.
-
abstract property
maximum
¶ Get the maximum of the poset.
- Returns
The maximum element.
- Return type
-
abstract property
meet_irreducible
¶ Get the meet irreducible elements.
- Returns
The meet irreducible elements.
- Return type
-
abstract property
minimum
¶ Get the minimum of the poset.
- Returns
The minimum element.
- 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
¶ Get the sinks of this DAG.
- Returns
The sinks of this DAG.
- Return type
-
abstract
smallest_meet_irreducible
(element: _M) → AbstractSet[_M]¶ Get the smallest meet irreducible greater than an element.
- Parameters
element (
_M
) – The element whose smallest meet irreducible are requested- Returns
The smallest meet irreducible greater than the element.
- Return type
- Raises
ValueError – If the element does not belong to the meet semi-lattice.
-
abstract property
sources
¶ 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
¶ Get the top elements.
- Returns
The top elements.
- Return type
-
abstract property
universes
¶ Get the universes of this relation.
- Returns
The universes of this relation.
- Return type
-
-
class
MeetSemiLattice
(domain: Iterable[_M])¶ The
MeetSemiLattice
class.It implements methods of
AbstractMeetSemiLattice
.A
MeetSemiLattice
instance stores its irreducible in aPartiallyOrderedSet
.Its memory complexity is in \(O(m)\)
Example
>>> from galactic.algebras.lattice import MeetSemiLattice >>> from galactic.examples.arithmetic import Integer >>> m = MeetSemiLattice[Integer]( ... domain = [ ... Integer(2*3*5), ... Integer(3*5*7), ... Integer(5*7*11) ... ] ... ) >>>
It’s possible to get the minimum element.
Example
>>> int(m.minimum) 5
It’s possible to iterate over the elements.
Example
>>> sorted(list(map(int, m.domain))) [5, 15, 30, 35, 105, 385]
It’s possible to iterate over the atoms.
Example
>>> sorted(list(map(int, m.atoms))) [15, 35]
It’s possible to iterate over the meet irreducible.
Example
>>> sorted(list(map(int, m.meet_irreducible))) [30, 105, 385]
It’s possible to iterate over the smallest meet irreducible greater than an element.
Example
>>> sorted(list(map(int, m.smallest_meet_irreducible(Integer(5*7))))) [105, 385]
It’s possible to enlarge a meet semi-lattice.
Example
>>> m.extend([Integer(13)]) >>> sorted(list(map(int, m.domain))) [1, 5, 13, 15, 30, 35, 105, 385]
-
__copy__
() → galactic.algebras.lattice.MeetSemiLattice[_M]¶ Get a copy of the meet semi-lattice.
This operation is in \(O(m)\).
- Returns
The copy of this meet semi-lattice.
- Return type
-
__init__
(domain: Iterable[_M])¶ Initialise a
MeetSemiLattice
instance.- Parameters
domain (
Optional[Iterable[_M]]
) – An initial domain.- Raises
ValueError – If the iterable is empty.
-
__iter__
() → Iterator[Tuple[_M, _M]]¶ Get an iterator over the elements.
- Returns
an iterator over the elements
- Return type
-
property
atoms
¶ Get the atoms of this meet semi-lattice.
- Returns
The atoms.
- Return type
-
property
bottom
¶ Get the bottom elements.
The collection contains only one element, the minimum element.
- Returns
The bottom elements.
- Return type
-
property
co_domain
¶ Get the co-domain of this semi-lattice.
- Returns
The co-domain of this semi-lattice.
- Return type
-
property
cover
¶ Get the covering relation of this meet semi-lattice.
- Returns
The covering relation.
- Return type
-
property
domain
¶ Get the domain of this semi-lattice.
- Returns
The domain of this semi-lattice.
- Return type
-
extend
(iterable: Iterable[_M]) → None¶ Extend this meet semi-lattice.
- Parameters
iterable (
Iterable[_M]
) – An iterable of values.
-
filter
(element: _M) → galactic.algebras.lattice.AbstractMeetSemiLattice[_M]¶ Get a filter of a meet semi-lattice.
- Parameters
element (
_M
) – The lower limit- Returns
The lower bounded join semi-lattice.
- Return type
- Raises
ValueError – If the element does not belong to the poset.
-
ideal
(element: _M) → galactic.algebras.lattice.AbstractUpperBoundedMeetSemiLattice[_M]¶ Get an ideal of a meet semi-lattice.
- Parameters
element (
_M
) – The upper limit- Returns
The upper bounded meet semi-lattice.
- Return type
- Raises
ValueError – If the element does not belong to the poset.
-
isdisjoint
(other)¶ Return True if two sets have a null intersection.
-
lower_limit
(limit: _M, strict: bool = False) → AbstractSet[_M]¶ Get the elements greater than a
limit
.- Parameters
- Returns
The selected elements.
- Return type
-
property
meet_irreducible
¶ Get the meet-irreducible elements of this meet semi-lattice.
- Returns
The meet-irreducible elements.
- Return type
-
property
minimum
¶ Get the minimum element of this meet semi-lattice.
- Returns
The minimum element
- Return type
-
predecessors
(element: _M) → AbstractSet[_M]¶ Get the predecessors of an
element
.- Parameters
element (
_M
) – The element whose predecessors are requested- Returns
The predecessors.
- Return type
- Raises
ValueError – If the element does not belong to the semi-lattice.
-
property
sinks
¶ Get the sink elements.
- Returns
The sink elements.
- Return type
-
smallest_meet_irreducible
(element: _M) → AbstractSet[_M]¶ Get the smallest meet irreducible greater than an element.
- Parameters
element (
_M
) – The element whose smallest meet irreducible are requested- Returns
The smallest meet irreducible greater than the element.
- Return type
- Raises
ValueError – If the element does not belong to the meet semi-lattice.
-
property
sources
¶ Get the source elements.
The collection contains only one element, the minimum element.
- Returns
The source elements.
- Return type
-
successors
(element: _M) → AbstractSet[_M]¶ Get the successors of an
element
.- Parameters
element (
_M
) – The element whose successors are requested- Returns
The successors.
- Return type
- Raises
ValueError – If the element does not belong to the semi-lattice.
-
property
top
¶ Get the top elements.
- Returns
The top elements.
- Return type
-
property
universes
¶ Get the universes of this meet semi-lattice.
- Returns
The universes.
- Return type
-
-
class
AbstractLattice
(*args, **kwds)¶ The
AbstractLattice
class describes finite lattices.-
__iter__
() → Iterator[Tuple[_P, _P]]¶ Get an iterator over the elements.
- Returns
An iterator over the elements
- Return type
-
abstract property
atoms
¶ Get the atoms of this meet semi-lattice.
- Returns
The atoms.
- Return type
-
abstract property
bottom
¶ Get the bottom elements.
- Returns
The bottom elements.
- Return type
-
abstract property
co_atoms
¶ Get the co-atoms of this join semi-lattice.
- Returns
The co-atoms.
- Return type
-
property
co_domain
¶ 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
¶ Get the covering relation.
- Returns
The covering relation.
- Return type
AbstractCoveringRelation[_P]
-
property
domain
¶ 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) → galactic.algebras.poset.AbstractLowerBoundedSet[_P]¶ Get a filter of a poset.
- Parameters
element (
_P
) – The lower limit- Returns
The lower bounded poset.
- Return type
AbstractLowerBoundedSet[_P]
- Raises
ValueError – If the element does not belong to the poset.
-
abstract
greatest_join_irreducible
(element: _J) → AbstractSet[_J]¶ Get the greatest join irreducible smaller than an element.
- Parameters
element (
_J
) – The element whose greatest join irreducible are requested- Returns
The greatest join irreducible smaller than the element.
- Return type
- Raises
ValueError – If the element does not belong to the join semi-lattice.
-
abstract
ideal
(element: _P) → galactic.algebras.poset.AbstractUpperBoundedSet[_P]¶ Get an ideal of the poset.
- Parameters
element (
_P
) – The upper limit- Returns
The upper bounded set.
- Return type
AbstractUpperBoundedSet[_P]
-
isdisjoint
(other)¶ Return True if two sets have a null intersection.
-
abstract property
join_irreducible
¶ Get the join irreducible elements.
- Returns
The join irreducible elements.
- Return type
-
abstract property
maximum
¶ Get the maximum of the poset.
- Returns
The maximum element.
- Return type
-
abstract property
meet_irreducible
¶ Get the meet irreducible elements.
- Returns
The meet irreducible elements.
- Return type
-
abstract property
minimum
¶ Get the minimum of the poset.
- Returns
The minimum element.
- 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
reduced_context
¶ Get the reduced context from this lattice.
- Returns
The reduced context.
- Return type
-
abstract property
sinks
¶ Get the sinks of this DAG.
- Returns
The sinks of this DAG.
- Return type
-
abstract
smallest_meet_irreducible
(element: _M) → AbstractSet[_M]¶ Get the smallest meet irreducible greater than an element.
- Parameters
element (
_M
) – The element whose smallest meet irreducible are requested- Returns
The smallest meet irreducible greater than the element.
- Return type
- Raises
ValueError – If the element does not belong to the meet semi-lattice.
-
abstract property
sources
¶ 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
¶ Get the top elements.
- Returns
The top elements.
- Return type
-
abstract property
universes
¶ Get the universes of this relation.
- Returns
The universes of this relation.
- Return type
-
-
class
Lattice
(domain: Iterable[_E])¶ The
Lattice
store a compact version of a lattice.It uses its join irreducible and meet irreducible elements.
The domain elements of a
Lattice
can be iterated from the maximum element to the minimum element or from the minimum element to the maximum element using thereversed
built-in function. It is not guaranteed that the order will be exactly the reverse order, but it is guaranteed that an element will always be iterated before its successors.Example
Let the integers ordered by the relation \(a \leq b\): is \(a\) a divisor of \(b\)?
implemented by the
Integer
class:>>> from galactic.examples.arithmetic import Integer >>> from galactic.algebras.lattice import Lattice >>> lattice = Lattice[Integer](domain=[Integer(2), Integer(3)]) >>> list(map(int, lattice.domain)) [6, 2, 3, 1]
-
__copy__
() → galactic.algebras.lattice.Lattice[_E]¶ Get a copy of the lattice.
The operation is in \(O(j+m)\).
- Returns
The copy of this lattice.
- Return type
-
__init__
(domain: Iterable[_E])¶ Initialise a
Lattice>
instance.- Parameters
domain (
Iterable[_E]
) – An iterable of elements- Raises
ValueError – If the iterable is empty.
-
__iter__
() → Iterator[Tuple[_P, _P]]¶ Get an iterator over the elements.
- Returns
An iterator over the elements
- Return type
-
property
atoms
¶ Get the atoms of this lattice.
- Returns
The atoms
- Return type
-
property
bottom
¶ Get the bottom elements.
The collection contains only one element, the minimum element.
- Returns
The bottom elements.
- Return type
-
property
co_atoms
¶ Get the co-atoms of this lattice.
- Returns
The co-atoms.
- Return type
-
property
co_domain
¶ Get the co-domain of this lattice.
- Returns
The co-domain of this lattice.
- Return type
-
property
cover
¶ Get the covering relation of this lattice.
- Returns
The covering relation.
- Return type
-
property
domain
¶ Get the domain of this lattice.
- Returns
The domain of this lattice.
- Return type
-
extend
(iterable: Iterable[_E]) → None¶ In-place enlarge the lattice with an iterable of elements.
- Parameters
iterable (
Iterable[_E]
) – An iterable of elements
-
filter
(element: _E) → galactic.algebras.lattice.AbstractLattice[_E]¶ Get a filter of a lattice.
- Parameters
element (
_E
) – The lower limit- Returns
The lower bounded lattice.
- Return type
- Raises
ValueError – If the element does not belong to the poset.
-
greatest_join_irreducible
(element: _E) → AbstractSet[_E]¶ Get the greatest join irreducible smaller than an element.
- Parameters
element (
_E
) – The element whose greatest join irreducible are requested- Returns
The greatest join irreducible smaller than the element.
- Return type
- Raises
ValueError – If the element does not belong to the lattice.
-
ideal
(element: _E) → galactic.algebras.lattice.AbstractLattice[_E]¶ Get an ideal of a lattice.
- Parameters
element (
_E
) – The upper limit- Returns
The upper bounded lattice.
- Return type
- Raises
ValueError – If the element does not belong to the poset.
-
isdisjoint
(other)¶ Return True if two sets have a null intersection.
-
property
join_irreducible
¶ Get the join irreducible elements.
- Returns
The join irreducible elements
- Return type
-
lower_limit
(limit: _E, strict: bool = Ellipsis) → AbstractSet[_E]¶ Get the elements greater than a
limit
.- Parameters
- Returns
The selected elements.
- Return type
-
property
maximum
¶ Get the maximum element of this lattice.
- Returns
the maximum element
- Return type
-
property
meet_irreducible
¶ Get the meet irreducible elements.
- Returns
The meet irreducible elements
- Return type
-
property
minimum
¶ Get the minimum element of this lattice.
- Returns
The minimum element
- Return type
-
predecessors
(element: _E) → AbstractSet[_E]¶ Get the predecessors of an
element
.- Parameters
element (
_E
) – The element whose predecessors are requested- Returns
The predecessors.
- Return type
- Raises
ValueError – If the element does not belong to the poset.
-
property
reduced_context
¶ Get the reduced context from this lattice.
- Returns
The reduced context.
- Return type
-
property
sinks
¶ Get the sink elements.
The collection contains only one element, the maximum element.
- Returns
The sink elements.
- Return type
-
smallest_meet_irreducible
(element: _E) → AbstractSet[_E]¶ Get the smallest meet irreducible greater than an element.
- Parameters
element (
_E
) – The element whose greatest join irreducible are requested- Returns
The smallest meet irreducible smaller than the element.
- Return type
- Raises
ValueError – If the element does not belong to the lattice.
-
property
sources
¶ Get the source elements.
The collection contains only one element, the minimum element.
- Returns
The source elements.
- Return type
-
successors
(element: _E) → AbstractSet[_E]¶ 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 poset.
-
property
top
¶ Get the top elements.
The collection contains only one element, the maximum element.
- Returns
The top elements.
- Return type
-
property
universes
¶ Get the universes of this lattice.
- Returns
The universes.
- Return type
-
-
class
ReducedContextDiagram
(lattice: galactic.algebras.lattice.Lattice[_E], domain_renderer: Optional[galactic.algebras.relational.NodeRenderer[_E, _E]] = None, co_domain_renderer: Optional[galactic.algebras.relational.NodeRenderer[_E, _E]] = None, edge_renderer: Optional[galactic.algebras.relational.EdgeRenderer[_E, _E]] = None)¶ The
ReducedContextDiagram
class is used for drawing sagittal diagrams.It is useful for drawing sagittal diagrams of lattice reduced context in jupyter notebooks.
-
__init__
(lattice: galactic.algebras.lattice.Lattice[_E], domain_renderer: Optional[galactic.algebras.relational.NodeRenderer[_E, _E]] = None, co_domain_renderer: Optional[galactic.algebras.relational.NodeRenderer[_E, _E]] = None, edge_renderer: Optional[galactic.algebras.relational.EdgeRenderer[_E, _E]] = None) → None¶ Initialise a
ReducedContextDiagram
instance.- Parameters
lattice (
Lattice[_E]
) – The lattice.domain_renderer (
NodeRenderer[_E, _E]
) – The domain renderer.co_domain_renderer (
NodeRenderer[_E, _E]
) – The domain renderer.edge_renderer (
EdgeRenderer[_E, _E]
) – The edge renderer.
-
property
co_domain_renderer
¶ Get the co-domain renderer.
- Returns
The co-domain renderer.
- Return type
NodeRenderer[_F, _E]
-
property
domain_renderer
¶ Get the domain renderer.
- Returns
The domain renderer.
- Return type
NodeRenderer[_E, _F]
-
property
edge_renderer
¶ Get the edge renderer.
- Returns
The edge renderer.
- Return type
EdgeRenderer[_E, _F]
-
property
relation
¶ Get the relation.
- Returns
The underlying relation.
- Return type
-