📘 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:

class PartiallyComparable(Protocol):
    def __lt__(self, other: object) -> bool: ...
    def __gt__(self, other: object) -> bool: ...
    def __le__(self, other: object) -> bool: ...
    def __ge__(self, other: object) -> bool: ...

The galactic.algebras.lattice.examples.arithmetic.core module define the PrimeFactors class that implements this protocol.

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 0x75a4a01c38e0>
[PrimeFactors(6), PrimeFactors(30)]
True
False

Collections of elements in a poset#

A poset handle various collections of its elements, such as:

  • top: the greatest elements in the poset.

  • bottom: The least elements in the poset.

display(poset.top, list(poset.top), poset.bottom, list(poset.bottom))
<galactic...Collection object at 0x75a4a020c6b0>
[PrimeFactors(30)]
<galactic...Collection object at 0x75a4a020c6e0>
[PrimeFactors(6)]

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.

poset.add(PrimeFactors(2))
display(poset.ideal(a), list(poset.ideal(a)))
display(poset.filter(a), list(poset.filter(a)))
display(poset.filter(a).ideal(a), list(poset.filter(a).ideal(a)))
<galactic.algebras.poset.core.PartiallyOrderedSetView object at 0x75a4a018be60>
[PrimeFactors(6), PrimeFactors(2)]
<galactic.algebras.poset.core.PartiallyOrderedSetView object at 0x75a4a01f8120>
[PrimeFactors(6), PrimeFactors(30)]
<galactic.algebras.poset.core.PartiallyOrderedSetView object at 0x75a4a01f8ba0>
[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):

display(poset.order, list(poset.order))
display(poset.cover, list(poset.cover))
<galactic.algebras.poset.core.PartialOrder object at 0x75a4a0559660>
[(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 0x75a4a01f5900>
[(PrimeFactors(6), PrimeFactors(30)), (PrimeFactors(2), PrimeFactors(6))]