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]:
from galactic.algebras.examples.arithmetic import PrimeFactors

PrimeFactors(12)
[1]:
$12=2^2·3$

3 is lesser than 6:

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

2 and 3 are incomparable:

[3]:
PrimeFactors(2) <= PrimeFactors(3)
[3]:
False
[4]:
PrimeFactors(3) <= PrimeFactors(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]:
PrimeFactors(1) <= PrimeFactors(6)
[5]:
True
[6]:
PrimeFactors(6) <= PrimeFactors(0)
[6]:
True
[7]:
from galactic.algebras.poset import top

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

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:

[12]:
from galactic.algebras.examples.color import Color
[13]:
Color(red=1.0, green=0.5)
[13]:
../../_images/notebooks_poset_notebook_20_0.svg
[14]:
Color(red=1.0, green=1.0)
[14]:
../../_images/notebooks_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_poset_notebook_24_0.svg

Collections

A poset is a set or partially ordered elements.

PrimeFactors example

[17]:
from galactic.algebras.poset import FinitePartiallyOrderedSet, HasseDiagram
from galactic.algebras.examples.arithmetic import PrimeFactorsRenderer

poset = FinitePartiallyOrderedSet[PrimeFactors](
    domain=[
        PrimeFactors(24),
        PrimeFactors(18),
        PrimeFactors(9),
        PrimeFactors(6),
        PrimeFactors(3),
        PrimeFactors(2),
    ]
)

poset have all classical python operations on sets:

[18]:
HasseDiagram[PrimeFactors](poset, domain_renderer=PrimeFactorsRenderer())
[18]:
../../_images/notebooks_poset_notebook_28_0.png
[19]:
len(poset)
[19]:
16
[20]:
display(*poset.cover)
(PrimeFactors(2), PrimeFactors(6))
(PrimeFactors(3), PrimeFactors(9))
(PrimeFactors(3), PrimeFactors(6))
(PrimeFactors(6), PrimeFactors(24))
(PrimeFactors(6), PrimeFactors(18))
(PrimeFactors(9), PrimeFactors(18))
[21]:
PrimeFactors(3) in poset.domain
[21]:
True
[22]:
display(*(poset.domain & {PrimeFactors(9), PrimeFactors(6), PrimeFactors(5)}))
$9=3^2$
$6=2·3$
[23]:
display(*(poset.domain | {PrimeFactors(9), PrimeFactors(6), PrimeFactors(5)}))
$24=2^3·3$
$18=2·3^2$
$2=2$
$3=3$
$6=2·3$
$9=3^2$
$5=5$
[24]:
poset.extend([PrimeFactors(9), PrimeFactors(6), PrimeFactors(5)])
HasseDiagram[PrimeFactors](poset, domain_renderer=PrimeFactorsRenderer())
[24]:
../../_images/notebooks_poset_notebook_34_0.png
[25]:
poset.extend([PrimeFactors(10)])
HasseDiagram[PrimeFactors](poset, domain_renderer=PrimeFactorsRenderer())
[25]:
../../_images/notebooks_poset_notebook_35_0.png
[26]:
poset.domain >= {PrimeFactors(9), PrimeFactors(6)}
[26]:
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.

[27]:
display(*poset.top)
$24=2^3·3$
$18=2·3^2$
$10=2·5$
[28]:
display(*poset.bottom)
$3=3$
$2=2$
$5=5$
[29]:
display(*poset.predecessors(PrimeFactors(18)))
$18=2·3^2$
$2=2$
$3=3$
$6=2·3$
$9=3^2$
[30]:
display(*poset.cover.predecessors(PrimeFactors(18)))
$9=3^2$
$6=2·3$
[31]:
display(*poset.successors(PrimeFactors(6)))
$24=2^3·3$
$18=2·3^2$
$6=2·3$
[32]:
display(*poset.cover.successors(PrimeFactors(6)))
$24=2^3·3$
$18=2·3^2$
[33]:
HasseDiagram[PrimeFactors](poset, domain_renderer=PrimeFactorsRenderer())
[33]:
../../_images/notebooks_poset_notebook_44_0.png
[34]:
HasseDiagram[PrimeFactors](
    poset.ideal(PrimeFactors(18)), domain_renderer=PrimeFactorsRenderer()
)
[34]:
../../_images/notebooks_poset_notebook_45_0.png
[35]:
HasseDiagram[PrimeFactors](
    poset.filter(PrimeFactors(3)), domain_renderer=PrimeFactorsRenderer()
)
[35]:
../../_images/notebooks_poset_notebook_46_0.png
[36]:
HasseDiagram[PrimeFactors](
    poset.filter(PrimeFactors(3)).ideal(PrimeFactors(18)),
    domain_renderer=PrimeFactorsRenderer(),
)
[36]:
../../_images/notebooks_poset_notebook_47_0.png
[37]:
HasseDiagram[PrimeFactors](
    poset.ideal(PrimeFactors(18)).filter(PrimeFactors(3)),
    domain_renderer=PrimeFactorsRenderer(),
)
[37]:
../../_images/notebooks_poset_notebook_48_0.png

Color example

Using colors, you can can test the poset collections:

[38]:
from galactic.algebras.poset import FinitePartiallyOrderedSet
from galactic.algebras.examples.color import ColorRenderer

colors = FinitePartiallyOrderedSet[Color](
    domain=[
        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),
    ]
)
[39]:
HasseDiagram[Color](colors, domain_renderer=ColorRenderer())
[39]:
../../_images/notebooks_poset_notebook_51_0.png
[40]:
len(colors)
[40]:
12
[41]:
display(*colors)
(Color(red=1.0, green=1.0, blue=0.0), Color(red=1.0, green=1.0, blue=0.0))
(Color(red=0.0, green=1.0, blue=1.0), Color(red=0.0, green=1.0, blue=1.0))
(Color(red=0.0, green=1.0, blue=0.5), Color(red=0.0, green=1.0, blue=1.0))
(Color(red=0.0, green=1.0, blue=0.5), Color(red=0.0, green=1.0, blue=0.5))
(Color(red=0.5, green=0.5, 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=0.5, green=0.5, blue=0.0))
(Color(red=0.5, green=0.0, blue=0.0), Color(red=1.0, green=1.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.5, green=0.0, blue=0.0), Color(red=0.5, green=0.0, blue=0.0))
(Color(red=0.5, green=0.0, blue=0.0), Color(red=1.0, green=0.0, blue=0.0))
(Color(red=1.0, green=0.0, blue=0.0), Color(red=1.0, green=1.0, blue=0.0))
(Color(red=1.0, green=0.0, blue=0.0), Color(red=1.0, green=0.0, blue=0.0))
[42]:
display(*colors.cover)
(Color(red=0.0, green=1.0, blue=0.5), Color(red=0.0, green=1.0, blue=1.0))
(Color(red=0.5, green=0.5, blue=0.0), Color(red=1.0, green=1.0, blue=0.0))
(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=1.0, green=0.0, blue=0.0), Color(red=1.0, green=1.0, blue=0.0))
[43]:
colors.domain >= {Color(green=1.0, blue=0.5), Color(green=1.0, blue=1.0)}
[43]:
True
[44]:
display(*colors.top)
../../_images/notebooks_poset_notebook_56_0.svg
../../_images/notebooks_poset_notebook_56_1.svg
[45]:
display(*colors.bottom)
../../_images/notebooks_poset_notebook_57_0.svg
../../_images/notebooks_poset_notebook_57_1.svg
[46]:
Color(red=0.5)
[46]:
../../_images/notebooks_poset_notebook_58_0.svg
[47]:
display(*colors.successors(Color(red=0.5)))
../../_images/notebooks_poset_notebook_59_0.svg
../../_images/notebooks_poset_notebook_59_1.svg
../../_images/notebooks_poset_notebook_59_2.svg
../../_images/notebooks_poset_notebook_59_3.svg
[48]:
display(*colors.cover.successors(Color(red=0.5)))
../../_images/notebooks_poset_notebook_60_0.svg
../../_images/notebooks_poset_notebook_60_1.svg
[49]:
Color(red=1.0)
[49]:
../../_images/notebooks_poset_notebook_61_0.svg
[50]:
display(*colors.predecessors(Color(red=1.0)))
../../_images/notebooks_poset_notebook_62_0.svg
../../_images/notebooks_poset_notebook_62_1.svg
[51]:
display(*colors.cover.predecessors(Color(red=1.0)))
../../_images/notebooks_poset_notebook_63_0.svg