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]:
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 0x7f385c3c1ba0>
Note that the result is a python iterator. To get the list:
[8]:
display(*top(elements))
An analog operation is available to get the bottom elements:
[9]:
from galactic.algebras.poset.elements import bottom
display(*bottom(elements))
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)))
[11]:
from galactic.algebras.poset.elements import lower_limit
display(
*lower_limit(
iterable=elements,
limit=Integer(12),
strict=True
)
)
Partially ordered elements can be lower (and upper) bounded.
This is the case of the Integer
class:
[12]:
Integer.minimum()
[12]:
[13]:
Integer.maximum()
[13]:
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]:
[16]:
Color(red=1.0, green=1.0)
[16]:
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]:
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]:
[21]:
len(poset)
[21]:
6
[22]:
display(*poset)
[23]:
Integer(3) in poset
[23]:
True
[24]:
display(
*(
poset &
BasicPartiallyOrderedSet(
[Integer(9), Integer(6), Integer(5)]
)
)
)
[25]:
display(
*(
poset |
BasicPartiallyOrderedSet(
[Integer(9), Integer(6), Integer(5)]
)
)
)
[26]:
poset @= BasicPartiallyOrderedSet(
[Integer(9), Integer(6), Integer(5)]
)
HasseDiagram(poset)
[26]:
[27]:
poset += [Integer(10)]
HasseDiagram(poset)
[27]:
[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())
[30]:
display(*poset.bottom())
[31]:
display(*poset.descendants(Integer(18)))
[32]:
display(*poset.ascendants(Integer(6)))
[33]:
display(*poset.successors(Integer(6)))
[34]:
display(*poset.predecessors(Integer(6)))
[35]:
display(*poset.siblings(Integer(6)))
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]:
[38]:
len(poset)
[38]:
6
[39]:
display(*poset)
[40]:
poset >= CompactPartiallyOrderedSet([
Color(green=1.0, blue=0.5),
Color(green=1.0, blue=1.0)
])
[40]:
True
[41]:
display(*poset.top())
[42]:
display(*poset.bottom())
[43]:
Color(red=0.5)
[43]:
[44]:
display(*poset.descendants(Color(red=0.5)))
[45]:
Color(red=1.0)
[45]:
[46]:
display(*poset.ascendants(Color(red=1.0)))
[47]:
display(*poset.successors(Color(red=0.5)))
[48]:
display(*poset.predecessors(Color(red=1.0)))