Partially ordered set

Elements

Partially ordered elements implements the 6 classical comparison operation:

  • \(<\)

  • \(\leq\)

  • \(>\)

  • \(\geq\)

  • \(=\)

  • \(\neq\)

They can be filtered using some special functions.

PrimeFactors example

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

To import the PrimeFactors class:

[1]:
$12=2^2·3$

3 is lesser than 6:

[2]:
[2]:
True

2 and 3 are incomparable:

[3]:
[3]:
False
[4]:
[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]:
[5]:
True
[6]:
[6]:
True
[7]:
from galactic.algebras.poset import top

elements = [PrimeFactors(6), PrimeFactors(24), PrimeFactors(13)]
top(elements)
[7]:
<odict_iterator at 0x70bffc770fe0>

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

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

An analog operation is available to get the bottom elements:

[9]:
from galactic.algebras.poset import bottom

display(*bottom(elements))
$6=2·3$
$13=13$

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

[10]:
from galactic.algebras.poset import upper_limit

display(*upper_limit(iterable=elements, limit=PrimeFactors(6)))
$6=2·3$
[11]:
from galactic.algebras.poset import lower_limit

display(*lower_limit(iterable=elements, limit=PrimeFactors(12), strict=True))
$24=2^3·3$

Color example

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

To import the Color class:

[13]:
Color(red=1.0, green=0.5)
[13]:
../../../_images/notebooks_algebras_poset_notebook_20_0.svg
[14]:
Color(red=1.0, green=1.0)
[14]:
../../../_images/notebooks_algebras_poset_notebook_21_0.svg

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

[15]:
Color(red=1.0, green=0.5) <= Color(red=1.0, green=1.0)
[15]:
True
[16]:
Color(red=0.5, green=1.0)
[16]:
../../../_images/notebooks_algebras_poset_notebook_24_0.svg

Collections

A poset is a set or partially ordered elements.

PrimeFactors example

poset have all classical python operations on sets:

[18]:
HasseDiagram[PrimeFactors](poset, domain_renderer=PrimeFactorsRenderer())
[18]:
../../../_images/notebooks_algebras_poset_notebook_28_0.png
[19]:
len(poset)
[19]:
6
[20]:
display(*poset.cover)
(PrimeFactors(3), PrimeFactors(9))
(PrimeFactors(3), PrimeFactors(6))
(PrimeFactors(2), PrimeFactors(6))
(PrimeFactors(9), PrimeFactors(18))
(PrimeFactors(6), PrimeFactors(24))
(PrimeFactors(6), PrimeFactors(18))
[21]:
PrimeFactors(3) in poset.cover.domain
[21]:
True
[22]:
poset.extend([PrimeFactors(9), PrimeFactors(6), PrimeFactors(5)])
HasseDiagram[PrimeFactors](poset, domain_renderer=PrimeFactorsRenderer())
[22]:
../../../_images/notebooks_algebras_poset_notebook_32_0.png
[23]:
poset.extend([PrimeFactors(10)])
HasseDiagram[PrimeFactors](poset, domain_renderer=PrimeFactorsRenderer())
[23]:
../../../_images/notebooks_algebras_poset_notebook_33_0.png
[24]:
poset >= {PrimeFactors(9), PrimeFactors(6)}
[24]:
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 filter and an ideal of an element.

[25]:
display(*poset.top)
$10=2·5$
$18=2·3^2$
$24=2^3·3$
[26]:
display(*poset.bottom)
$3=3$
$2=2$
$5=5$
[27]:
display(*poset.cover.predecessors(PrimeFactors(18)))
$9=3^2$
$6=2·3$
[28]:
display(*poset.order.predecessors(PrimeFactors(18)))
$9=3^2$
$6=2·3$
$3=3$
$2=2$
$18=2·3^2$
[29]:
display(*poset.cover.successors(PrimeFactors(6)))
$24=2^3·3$
$18=2·3^2$
[30]:
display(*poset.order.successors(PrimeFactors(6)))
$6=2·3$
$24=2^3·3$
$18=2·3^2$
[31]:
HasseDiagram[PrimeFactors](poset, domain_renderer=PrimeFactorsRenderer())
[31]:
../../../_images/notebooks_algebras_poset_notebook_42_0.png
[32]:
HasseDiagram[PrimeFactors](
    poset.ideal(PrimeFactors(18)),
    domain_renderer=PrimeFactorsRenderer(),
)
[32]:
../../../_images/notebooks_algebras_poset_notebook_43_0.png
[33]:
HasseDiagram[PrimeFactors](
    poset.filter(PrimeFactors(3)),
    domain_renderer=PrimeFactorsRenderer(),
)
[33]:
../../../_images/notebooks_algebras_poset_notebook_44_0.png
[34]:
HasseDiagram[PrimeFactors](
    poset.filter(PrimeFactors(3)).ideal(PrimeFactors(18)),
    domain_renderer=PrimeFactorsRenderer(),
)
[34]:
../../../_images/notebooks_algebras_poset_notebook_45_0.png
[35]:
HasseDiagram[PrimeFactors](
    poset.ideal(PrimeFactors(18)).filter(PrimeFactors(3)),
    domain_renderer=PrimeFactorsRenderer(),
)
[35]:
../../../_images/notebooks_algebras_poset_notebook_46_0.png

Color example

Using colors, you can can test the poset collections:

[36]:
from galactic.algebras.examples.color.renderer import ColorRenderer
from galactic.algebras.poset import MutableFinitePartiallyOrderedSet

colors = MutableFinitePartiallyOrderedSet[Color](
    elements=[
        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[Color](colors, domain_renderer=ColorRenderer())
[37]:
../../../_images/notebooks_algebras_poset_notebook_49_0.png
[38]:
len(colors)
[38]:
6
[39]:
display(*colors)
../../../_images/notebooks_algebras_poset_notebook_51_0.svg
../../../_images/notebooks_algebras_poset_notebook_51_1.svg
../../../_images/notebooks_algebras_poset_notebook_51_2.svg
../../../_images/notebooks_algebras_poset_notebook_51_3.svg
../../../_images/notebooks_algebras_poset_notebook_51_4.svg
../../../_images/notebooks_algebras_poset_notebook_51_5.svg
[40]:
display(*colors.cover)
(Color(red=0.5, green=0.0, blue=0.0), Color(red=1.0, green=0.0, blue=0.0))
(Color(red=0.5, green=0.0, blue=0.0), Color(red=0.5, green=0.5, blue=0.0))
(Color(red=0.0, green=1.0, blue=0.5), Color(red=0.0, green=1.0, blue=1.0))
(Color(red=1.0, green=0.0, blue=0.0), Color(red=1.0, green=1.0, blue=0.0))
(Color(red=0.5, green=0.5, blue=0.0), Color(red=1.0, green=1.0, blue=0.0))
[41]:
colors.cover.domain >= {Color(green=1.0, blue=0.5), Color(green=1.0, blue=1.0)}
[41]:
True
[42]:
display(*colors.top)
../../../_images/notebooks_algebras_poset_notebook_54_0.svg
../../../_images/notebooks_algebras_poset_notebook_54_1.svg
[43]:
display(*colors.bottom)
../../../_images/notebooks_algebras_poset_notebook_55_0.svg
../../../_images/notebooks_algebras_poset_notebook_55_1.svg
[44]:
Color(red=0.5)
[44]:
../../../_images/notebooks_algebras_poset_notebook_56_0.svg
[45]:
display(*colors.cover.successors(Color(red=0.5)))
../../../_images/notebooks_algebras_poset_notebook_57_0.svg
../../../_images/notebooks_algebras_poset_notebook_57_1.svg
[46]:
display(*colors.order.successors(Color(red=0.5)))
../../../_images/notebooks_algebras_poset_notebook_58_0.svg
../../../_images/notebooks_algebras_poset_notebook_58_1.svg
../../../_images/notebooks_algebras_poset_notebook_58_2.svg
../../../_images/notebooks_algebras_poset_notebook_58_3.svg
[47]:
Color(red=1.0)
[47]:
../../../_images/notebooks_algebras_poset_notebook_59_0.svg
[48]:
display(*colors.cover.predecessors(Color(red=1.0)))
../../../_images/notebooks_algebras_poset_notebook_60_0.svg
[49]:
display(*colors.order.predecessors(Color(red=1.0)))
../../../_images/notebooks_algebras_poset_notebook_61_0.svg
../../../_images/notebooks_algebras_poset_notebook_61_1.svg