Elements

The galactic.algebras.poset.elements module defines essential type for representing partially ordered elements.

class galactic.algebras.poset.elements.PartiallyOrdered

Bases: collections.abc.Hashable

A partially ordered type sets for each pair of elements \(a\), \(b\) either:

  • \(a \leq b\)

  • \(b \leq a\)

  • a and b are incomparable

The relation \(\leq\) must be:

  • reflexive (\(a \leq a\))

  • transitive (\(a \leq b\) and \(b \leq c\) implies \(a \leq c\))

  • anti-symmetric (\(a \leq b\) and \(b \leq a\) implies \(a = b\))

A class implementing the PartiallyOrdered abstract class must be declared by inheriting from PartiallyOrdered with itself as a parameter and must implement the methods:

Example

Let the integers ordered by the relation \(a \leq b\): is \(a\) a divisor of \(b\)?

implemented by the Integer class:

>>> from galactic.examples.arithmetic.algebras import Integer
>>> Integer(5) <= Integer(10)
True
>>> Integer(5) <= Integer(11)
False
>>>
abstract __lt__(other)

Test if this element is lesser than the other.

Parameters

other – the other element

Returns

  • boolTrue if this element is lesser than the other.

  • NotImplementedType – if the operation is not implemented between the two objects

abstract __gt__(other)

Test if this element is greater than the other.

Parameters

other – the other element

Returns

  • boolTrue if this element is greater than the other.

  • NotImplementedType – if the operation is not implemented between the two objects

abstract __eq__(other)

Test if this element is equal to the other.

Parameters

other – the other element

Returns

  • boolTrue if this element is equal to the other.

  • NotImplementedType – if the operation is not implemented between the two objects

abstract __le__(other)

Test if this element is lesser than or equal to the other.

Parameters

other – the other element

Returns

  • boolTrue if this element is lesser than or equal to the other.

  • NotImplementedType – if the operation is not implemented between the two objects

__ge__(other)

Test if this element is greater than or equal to the other.

Parameters

other – the other element

Returns

  • boolTrue if this element is greater than or equal to the other.

  • NotImplementedType – if the operation is not implemented between the two objects

class galactic.algebras.poset.elements.UpperBounded

Bases: galactic.algebras.poset.elements.PartiallyOrdered

The UpperBounded type defines a maximum value for instances.

abstract classmethod maximum() → galactic.algebras.poset.elements.UpperBounded

Returns the maximum element of this type.

Returns

the maximum element

Return type

UpperBounded

class galactic.algebras.poset.elements.LowerBounded

Bases: galactic.algebras.poset.elements.PartiallyOrdered

The LowerBounded type defines a minimum value for instances.

abstract classmethod minimum() → galactic.algebras.poset.elements.LowerBounded

Returns the minimum element of this type

Returns

the minimum element

Return type

LowerBounded

galactic.algebras.poset.elements.top(iterable: Iterable[galactic.algebras.poset.elements.PartiallyOrdered] = None) → Iterator[galactic.algebras.poset.elements.PartiallyOrdered]

The top() function computes an iterator over the top elements of the iterable collection. This operation computes in \(O(n^2)\) where \(n\) is the number of elements in the iterable.

Keyword Arguments

iterable (Iterable[PartiallyOrdered]) – An iterable of partially ordered elements.

Returns

An iterator over the top elements.

Return type

Iterator[PartiallyOrdered]

Example

>>> from galactic.algebras.poset.elements import top
>>> values = [{1, 2, 3}, {1, 2, 3, 4}, {2, 3, 4, 5}]
>>> list(top(iterable=[frozenset(value) for value in values]))
[frozenset({1, 2, 3, 4}), frozenset({2, 3, 4, 5})]
galactic.algebras.poset.elements.bottom(iterable: Iterable[galactic.algebras.poset.elements.PartiallyOrdered] = None) → Iterator[galactic.algebras.poset.elements.PartiallyOrdered]

The bottom() function computes an iterator over the bottom elements of the iterable collection. This operation computes in \(O(n^2)\) where \(n\) is the number of elements in the iterable.

Keyword Arguments

iterable (Iterable[PartiallyOrdered]) – An iterable of partially ordered elements.

Returns

An iterator over the bottom elements.

Return type

Iterator[PartiallyOrdered]

Example

>>> from galactic.algebras.poset.elements import top
>>> values = [{1, 2, 3}, {1, 2, 3, 4}, {2, 3, 4, 5}]
>>> list(bottom(iterable=[frozenset(value) for value in values]))
[frozenset({1, 2, 3}), frozenset({2, 3, 4, 5})]
galactic.algebras.poset.elements.upper_limit(iterable: Iterable[galactic.algebras.poset.elements.PartiallyOrdered] = None, limit: galactic.algebras.poset.elements.PartiallyOrdered = None, strict: bool = False) → Iterator[galactic.algebras.poset.elements.PartiallyOrdered]

The upper_limit() function computes an iterator over the elements lesser than the limit. This operation computes in \(O(n)\) where \(n\) is the number of elements in the iterable.

Keyword Arguments
  • iterable (Iterable[PartiallyOrdered]) – An iterable of partially ordered elements.

  • limit – The upper limit

  • strict (bool) – Is the comparison strict?

Returns

An iterator over the selected elements.

Return type

Iterator[PartiallyOrdered]

Example

>>> from galactic.algebras.poset.elements import upper_limit
>>> list(upper_limit(iterable=[{1, 2}, {1, 2, 3}, {2, 3}], limit={2, 3}))
[{2, 3}]
galactic.algebras.poset.elements.lower_limit(iterable: Iterable[galactic.algebras.poset.elements.PartiallyOrdered] = None, limit: galactic.algebras.poset.elements.PartiallyOrdered = None, strict: bool = False) → Iterator[galactic.algebras.poset.elements.PartiallyOrdered]

The lower_limit() function computes an iterator over the elements greater than the limit. This operation computes in \(O(n)\) where \(n\) is the number of elements in the iterable.

Keyword Arguments
  • iterable (Iterable[PartiallyOrdered]) – An iterable of partially ordered elements.

  • limit – The lower limit

  • strict (bool) – Is the comparison strict?

Returns

An iterator over the selected elements.

Return type

Iterator[PartiallyOrdered]

Example

>>> from galactic.algebras.poset.elements import lower_limit
>>> list(lower_limit(iterable=[{1, 2}, {1, 2, 3}, {2, 3}], limit={2, 3}))
[{1, 2, 3}, {2, 3}]