Partially ordered set

Elements

Partially ordered elements implements the 6 classical comparison operation:

  • \(<\)

  • \(\leq\)

  • \(>\)

  • \(\geq\)

  • \(=\)

  • \(\neq\)

They can be filtered using some special functions.

Integer example

The Integer class in the examples folder implements a partially ordered relation between positive integers using the divisor of notion.

To import the Integer class:

[1]:
from galactic.examples.arithmetic.algebras import Integer
Integer(12)
[1]:
$12=2^23^1$

3 is lesser than 6:

[2]:
Integer(3) <= Integer(6)
[2]:
True

2 and 3 are incomparable:

[3]:
Integer(2) <= Integer(3)
[3]:
False
[4]:
Integer(3) <= Integer(2)
[4]:
False

1 is lesser than all the other numbers (1 is a divisor of all numbers) and 0 is greater than all other numbers (all numbers are divisors of 0):

[5]:
Integer(1) <= Integer(6)
[5]:
True
[6]:
Integer(6) <= Integer(0)
[6]:
True
[7]:
from galactic.algebras.poset.elements import top
elements = [Integer(6), Integer(24), Integer(13)]
top(elements)
[7]:
<odict_iterator at 0x7fb9c7dc2570>

Note that the result is a python iterator. To get the list:

[8]:
display(*top(elements))
$24=2^33^1$
$13=13^1$

An analog operation is available to get the bottom elements:

[9]:
from galactic.algebras.poset.elements import bottom
display(*bottom(elements))
$6=2^13^1$
$13=13^1$

It’s possible to get the elements greater or lower than a given limit:

[10]:
from galactic.algebras.poset.elements import upper_limit
display(*upper_limit(iterable=elements, limit=Integer(6)))
$6=2^13^1$
[11]:
from galactic.algebras.poset.elements import lower_limit
display(
    *lower_limit(
        iterable=elements,
        limit=Integer(12),
        strict=True
    )
)
$24=2^33^1$

Partially ordered elements can be lower (and upper) bounded.

This is the case of the Integer class:

[12]:
Integer.minimum()
[12]:
$1$
[13]:
Integer.maximum()
[13]:
$0$

Color example

The Color class in the examples folder implements a partially ordered relation between colors.

To import the Color class:

[14]:
from galactic.examples.color.algebras import Color
[15]:
Color(red=1.0, green=0.5)
[15]:
../../../_images/notebooks_algebras_poset_notebook_23_0.png
[16]:
Color(red=1.0, green=1.0)
[16]:
../../../_images/notebooks_algebras_poset_notebook_24_0.png

The orange color is less or equal than the yellow color:

[17]:
Color(red=1.0, green=0.5) <= Color(red=1.0, green=1.0)
[17]:
True
[18]:
Color(red=0.5, green=1.0)
[18]:
../../../_images/notebooks_algebras_poset_notebook_27_0.png

Collections

A poset is a set or partially ordered elements. You can use either the BasicPartiallyOrderedSet class or the CompactPartiallyOrderedSet class.

Integer example

[19]:
from galactic.algebras.poset.collections import \
    BasicPartiallyOrderedSet, HasseDiagram
poset = BasicPartiallyOrderedSet([
    Integer(24),
    Integer(18),
    Integer(9),
    Integer(6),
    Integer(3),
    Integer(2)
])

poset have all classical python operations on sets:

[20]:
HasseDiagram(poset)
[20]:
../../../_images/notebooks_algebras_poset_notebook_31_0.png
[21]:
len(poset)
[21]:
6
[22]:
display(*poset)
$2=2^1$
$3=3^1$
$6=2^13^1$
$9=3^2$
$18=2^13^2$
$24=2^33^1$
[23]:
Integer(3) in poset
[23]:
True
[24]:
display(
    *(
        poset &
        BasicPartiallyOrderedSet(
            [Integer(9), Integer(6), Integer(5)]
        )
    )
)
$9=3^2$
$6=2^13^1$
[25]:
display(
    *(
        poset |
        BasicPartiallyOrderedSet(
            [Integer(9), Integer(6), Integer(5)]
        )
    )
)
$2=2^1$
$3=3^1$
$18=2^13^2$
$5=5^1$
$6=2^13^1$
$24=2^33^1$
$9=3^2$
[26]:
poset @= BasicPartiallyOrderedSet(
    [Integer(9), Integer(6), Integer(5)]
)
HasseDiagram(poset)
[26]:
../../../_images/notebooks_algebras_poset_notebook_37_0.png
[27]:
poset += [Integer(10)]
HasseDiagram(poset)
[27]:
../../../_images/notebooks_algebras_poset_notebook_38_0.png
[28]:
poset >= BasicPartiallyOrderedSet([Integer(9), Integer(6)])
[28]:
True

From a poset, several additional methods can be applied:

  • get the top or the bottom elements from the poset;

  • get the descendants or the ascendants of an element;

  • get the successors and predecessors of an element;

  • get the siblings, co-parents or neighbors (sibling or co-parent) of an element.

[29]:
display(*poset.top())
$10=2^15^1$
$18=2^13^2$
$24=2^33^1$
[30]:
display(*poset.bottom())
$2=2^1$
$3=3^1$
$5=5^1$
[31]:
display(*poset.descendants(Integer(18)))
[32]:
display(*poset.ascendants(Integer(6)))
$2=2^1$
$3=3^1$
[33]:
display(*poset.successors(Integer(6)))
$24=2^33^1$
$18=2^13^2$
[34]:
display(*poset.predecessors(Integer(6)))
$2=2^1$
$3=3^1$
[35]:
display(*poset.siblings(Integer(6)))
$9=3^2$
$10=2^15^1$

Color example

Using colors, you can can test the poset collections:

[36]:
from galactic.algebras.poset.collections import \
    CompactPartiallyOrderedSet
poset = CompactPartiallyOrderedSet([
    Color(red=1.0),
    Color(red=1.0, green=1.0),
    Color(red=0.5),
    Color(red=0.5, green=0.5),
    Color(green=1.0, blue=0.5),
    Color(green=1.0, blue=1.0)
])
[37]:
HasseDiagram(poset)
[37]:
../../../_images/notebooks_algebras_poset_notebook_50_0.png
[38]:
len(poset)
[38]:
6
[39]:
display(*poset)
../../../_images/notebooks_algebras_poset_notebook_52_0.png
../../../_images/notebooks_algebras_poset_notebook_52_1.png
../../../_images/notebooks_algebras_poset_notebook_52_2.png
../../../_images/notebooks_algebras_poset_notebook_52_3.png
../../../_images/notebooks_algebras_poset_notebook_52_4.png
../../../_images/notebooks_algebras_poset_notebook_52_5.png
[40]:
poset >= CompactPartiallyOrderedSet([
    Color(green=1.0, blue=0.5),
    Color(green=1.0, blue=1.0)
])
[40]:
True
[41]:
display(*poset.top())
../../../_images/notebooks_algebras_poset_notebook_54_0.png
../../../_images/notebooks_algebras_poset_notebook_54_1.png
[42]:
display(*poset.bottom())
../../../_images/notebooks_algebras_poset_notebook_55_0.png
../../../_images/notebooks_algebras_poset_notebook_55_1.png
[43]:
Color(red=0.5)
[43]:
../../../_images/notebooks_algebras_poset_notebook_56_0.png
[44]:
display(*poset.descendants(Color(red=0.5)))
../../../_images/notebooks_algebras_poset_notebook_57_0.png
../../../_images/notebooks_algebras_poset_notebook_57_1.png
../../../_images/notebooks_algebras_poset_notebook_57_2.png
[45]:
Color(red=1.0)
[45]:
../../../_images/notebooks_algebras_poset_notebook_58_0.png
[46]:
display(*poset.ascendants(Color(red=1.0)))
../../../_images/notebooks_algebras_poset_notebook_59_0.png
[47]:
display(*poset.successors(Color(red=0.5)))
../../../_images/notebooks_algebras_poset_notebook_60_0.png
../../../_images/notebooks_algebras_poset_notebook_60_1.png
[48]:
display(*poset.predecessors(Color(red=1.0)))
../../../_images/notebooks_algebras_poset_notebook_61_0.png