📘 Posets#
Elements#
A partially ordered set (or poset) is a set equipped with a partial order. A partial order is a binary relation that is reflexive, antisymmetric, and transitive.
In Python, we can represent elements of a poset using a simple class with comparison methods.
The following PartiallyComparable protocol
of the galactic.algebras.poset.core
module defines the necessary comparison methods for elements in a poset:
The galactic.algebras.lattice.examples.arithmetic.core module define the
PrimeFactors
class that implements this protocol.
from galactic.algebras.lattice.examples.arithmetic.core import PrimeFactors
a = PrimeFactors(6)
b = PrimeFactors(30)
display(a < b, a <= b, a > b, a >= b)
True
True
False
False
Collections#
To work with collections of poset elements, we can use the
MutablePartiallyOrderedSet class from the
galactic.algebras.poset.core module. This class provides methods to add elements,
check for membership, and perform various poset operations.
Creating a poset#
from galactic.algebras.poset.core import MutablePartiallyOrderedSet
poset = MutablePartiallyOrderedSet[PrimeFactors]()
poset.add(a)
poset.add(b)
display(poset, list(poset))
display(a in poset, PrimeFactors(5) in poset)
<galactic.algebras.poset.core.MutablePartiallyOrderedSet object at 0x7e461ecc49a0>
[PrimeFactors(6), PrimeFactors(30)]
True
False
Collections of elements in a poset#
A poset handle various collections of its elements, such as:
Views of a poset#
A view on poset can be computed to using the following methods:
ideal(): returns the ideal generated by a given element.filter(): returns the filter generated by a given element.
<galactic.algebras.poset.core.PartiallyOrderedSetView object at 0x7e461ecc04a0>
[PrimeFactors(6), PrimeFactors(2)]
<galactic.algebras.poset.core.PartiallyOrderedSetView object at 0x7e461ecc0200>
[PrimeFactors(6), PrimeFactors(30)]
<galactic.algebras.poset.core.PartiallyOrderedSetView object at 0x7e461ecc0e40>
[PrimeFactors(6)]
Underlying partial order#
The underlying partial order of a poset can be accessed using the
order attribute
(and the
cover attribute
for the cover relation):
<galactic.algebras.poset.core.PartialOrder object at 0x7e461ecbefb0>
[(PrimeFactors(6), PrimeFactors(6)),
(PrimeFactors(6), PrimeFactors(30)),
(PrimeFactors(2), PrimeFactors(6)),
(PrimeFactors(2), PrimeFactors(2)),
(PrimeFactors(2), PrimeFactors(30)),
(PrimeFactors(30), PrimeFactors(30))]
<galactic...CoveringRelation object at 0x7e461ecb7020>
[(PrimeFactors(6), PrimeFactors(30)), (PrimeFactors(2), PrimeFactors(6))]