galactic.algebras.lattice.core

Contents

galactic.algebras.lattice.core#

Defines types for representing lattices.

Protocols

Elements of semi-lattices and lattices:

Semi-lattices and lattices:

Functions on elements of semi-lattices and lattices

Concrete classes for semi-lattices and lattices


class Joinable(*args, **kwargs)#

Bases: PartiallyComparable, Protocol

Represents joinable elements.

For each pair of elements \((a, b)\), this class defines a unique supremum \(c = a \vee b\) (also called the least upper bound or join).

Example

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

>>> from galactic.algebras.lattice.examples.arithmetic.core import PrimeFactors
>>> PrimeFactors(24) | PrimeFactors(36)
PrimeFactors(72)
>>> PrimeFactors(24).join(PrimeFactors(36), PrimeFactors(10))
PrimeFactors(360)
abstractmethod __or__(other)#

Return the join of this element and another.

Parameters:

other (object) – The other element

Returns:

The join of this element and the other

Return type:

Self

Raises:

NotImplementedError –

join(*others)#

Return the supremum of this element and the given elements.

Parameters:

*others (Self) – The other elements

Returns:

The join of this element and the others

Return type:

Self

class Meetable(*args, **kwargs)#

Bases: PartiallyComparable, Protocol

Represents meetable elements.

For each pair of elements \((a, b)\), this type defines a unique infimum \(c = a \wedge b\) (also called the greatest lower bound or meet).

Example

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

>>> from galactic.algebras.lattice.examples.arithmetic.core import PrimeFactors
>>> PrimeFactors(24) & PrimeFactors(36)
PrimeFactors(12)
>>> PrimeFactors(24).meet(PrimeFactors(36), PrimeFactors(10))
PrimeFactors(2)
abstractmethod __and__(other)#

Return the meet of this element and another.

Parameters:

other (object) – The other element

Returns:

The meet of this element and the other

Return type:

Self

Raises:

NotImplementedError –

meet(*others)#

Return the infimum of this element and the others.

Parameters:

*others (Self) – The other elements

Returns:

The meet of this element and the others

Return type:

Self

class Element(*args, **kwargs)#

Bases: Joinable, Meetable, Protocol

Represents elements that can be members of a lattice.

class JoinSemiLattice[_J: Joinable](*args, **kwargs)#

Bases: PartiallyOrderedSet[_J], Protocol

Describes join semi-lattices.

__bool__()#

Check whether this join semi-lattice is non-empty.

Returns:

Whether this join semi-lattice is non-empty

Return type:

bool

__eq__(other)#

Check whether this join semi-lattice is equal to another.

Parameters:

other (object) – The other join semi-lattice

Returns:

Whether this join semi-lattice is equal to the other

Return type:

bool

__contains__(elem)#

Check whether an element belongs to this join semi-lattice.

Parameters:

elem (object) – The element to check

Returns:

Whether the element belongs to this join semi-lattice

Return type:

bool

__iter__()#

Iterate over the elements of this join semi-lattice [1].

Returns:

An iterator over the elements of this join semi-lattice

Return type:

Iterator[_J]

__len__()#

Return the number of elements in this join semi-lattice.

Returns:

The number of elements in this join semi-lattice

Return type:

int

__lt__(other)#

Check whether this join semi-lattice is less than another.

Parameters:

other (object) – The other join semi-lattice

Returns:

Whether this join semi-lattice is less than the other

Return type:

bool

Notes

If other is not an instance of Collection, this method returns NotImplemented.

__gt__(other)#

Check whether this join semi-lattice is greater than another.

Parameters:

other (object) – The other join semi-lattice

Returns:

Whether this join semi-lattice is greater than the other

Return type:

bool

Notes

If other is not an instance of Collection, this method returns NotImplemented.

__le__(other)#

Check whether this join semi-lattice is less than or equal to another.

Parameters:

other (object) – The other join semi-lattice

Returns:

Whether this join semi-lattice is less than or equal to the other

Return type:

bool

Notes

If other is not an instance of Collection, this method returns NotImplemented.

__ge__(other)#

Check whether this join semi-lattice is greater than or equal to another.

Parameters:

other (object) – The other join semi-lattice

Returns:

Whether this join semi-lattice is greater than or equal to the other

Return type:

bool

Notes

If other is not an instance of Collection, this method returns NotImplemented.

upper_limit(*limits, strict=False)#

Return the elements less than the given limits.

Parameters:
  • *limits (_J) – The limits

  • strict (bool, default: False) – Whether the comparison is strict

Returns:

The elements less than the limits

Return type:

Collection[_J]

lower_limit(*limits, strict=False)#

Return the elements greater than the given limits.

Parameters:
  • *limits (_J) – The limits

  • strict (bool, default: False) – Whether the comparison is strict

Returns:

The elements greater than the limits

Return type:

Collection[_J]

floor(*limits)#

Return the floor of the given elements.

Parameters:

*limits (_J) – The elements for which the floor is requested

Returns:

The floor of the given elements, or None if not found

Return type:

_J | None

greatest_join_irreducible(*limits, strict=False)#

Return the greatest join-irreducible elements smaller than the given limits.

Parameters:
  • *limits (_J) – The limits

  • strict (bool, default: False) – Whether the comparison is strict

Returns:

The greatest join-irreducible elements smaller than the limits

Return type:

Collection[_J]

abstract property co_atoms: Collection[_J]#

Get the co-atoms of this join semi-lattice.

Returns:

The co-atoms

Return type:

Collection[_J]

abstract property join_irreducible: Collection[_J]#

Get the join-irreducible elements.

Returns:

The join-irreducible elements

Return type:

Collection[_J]

Raises:

NotImplementedError –

class MeetSemiLattice[_M: Meetable](*args, **kwargs)#

Bases: PartiallyOrderedSet[_M], Protocol

Describes meet semi-lattices.

__bool__()#

Check whether this meet semi-lattice is non-empty.

Returns:

Whether this meet semi-lattice is non-empty

Return type:

bool

__eq__(other)#

Check whether this meet semi-lattice is equal to another.

Parameters:

other (object) – The other meet semi-lattice

Returns:

Whether this meet semi-lattice is equal to the other

Return type:

bool

__contains__(elem)#

Check whether an element belongs to this meet semi-lattice.

Parameters:

elem (object) – The element to check

Returns:

Whether the element belongs to this meet semi-lattice

Return type:

bool

__iter__()#

Iterate over the elements of this meet semi-lattice [1].

Returns:

An iterator over the elements of this meet semi-lattice

Return type:

Iterator[_M]

__len__()#

Return the number of elements in this meet semi-lattice.

Returns:

The number of elements in this meet semi-lattice

Return type:

int

__lt__(other)#

Check whether this meet semi-lattice is less than another.

Parameters:

other (object) – The other meet semi-lattice

Returns:

Whether this meet semi-lattice is less than the other

Return type:

bool

Notes

If other is not an instance of Collection, this method returns NotImplemented.

__gt__(other)#

Check whether this meet semi-lattice is greater than another.

Parameters:

other (object) – The other meet semi-lattice

Returns:

Whether this meet semi-lattice is greater than the other

Return type:

bool

Notes

If other is not an instance of Collection, this method returns NotImplemented.

__le__(other)#

Check whether this meet semi-lattice is less than or equal to another.

Parameters:

other (object) – The other meet semi-lattice

Returns:

Whether this meet semi-lattice is less than or equal to the other

Return type:

bool

Notes

If other is not an instance of Collection, this method returns NotImplemented.

__ge__(other)#

Check whether this meet semi-lattice is greater than or equal to another.

Parameters:

other (object) – The other meet semi-lattice

Returns:

Whether this meet semi-lattice is greater than or equal to the other

Return type:

bool

Notes

If other is not an instance of Collection, this method returns NotImplemented.

upper_limit(*limits, strict=False)#

Return the elements less than the given limits.

Parameters:
  • *limits (_M) – The limits

  • strict (bool, default: False) – Whether the comparison is strict

Returns:

The elements less than the limits

Return type:

Collection[_M]

lower_limit(*limits, strict=False)#

Return the elements greater than the given limits.

Parameters:
  • *limits (_M) – The limits

  • strict (bool, default: False) – Whether the comparison is strict

Returns:

The elements greater than the limits

Return type:

Collection[_M]

ceil(*limits)#

Return the ceil of the given elements.

Parameters:

*limits (_M) – The elements for which the ceil is requested

Returns:

The ceil of the given elements, or None if not found

Return type:

_M | None

smallest_meet_irreducible(*limits, strict=False)#

Return the smallest meet-irreducible elements smaller than the given limits.

Parameters:
  • *limits (_M) – The limits

  • strict (bool, default: False) – Whether the comparison is strict

Returns:

The smallest meet-irreducible elements greater than the limits

Return type:

Collection[_M]

abstract property atoms: Collection[_M]#

Get the co-atoms of this meet semi-lattice.

Returns:

The atoms

Return type:

Collection[_M]

abstract property meet_irreducible: Collection[_M]#

Get the meet-irreducible elements.

Returns:

The meet-irreducible elements

Return type:

Collection[_M]

Raises:

NotImplementedError –

class Lattice[_E: Element](*args, **kwargs)#

Bases: JoinSemiLattice[_E], MeetSemiLattice[_E], Protocol

Represents lattices.

__eq__(other)#

Check whether this lattice is equal to another collection.

Parameters:

other (object) – A collection of elements

Returns:

True if this lattice is equal to the other collection

Return type:

bool

__contains__(elem)#

Check whether an element belongs to the lattice.

Parameters:

elem (object) – The element to check

Returns:

True if the element belongs to the lattice

Return type:

bool

__iter__()#

Compute the concept lattice using the Close By One algorithm [1].

Returns:

An iterator over the elements in the lattice

Return type:

Iterator[_E]

References

Notes

This implementation chooses between attribute and item mode depending on the size of the context for better performance.

__len__()#

Get the number of elements in the lattice.

Returns:

The number of elements in the lattice

Return type:

int

__lt__(other)#

Check whether this lattice is a strict subset of another collection.

Parameters:

other (object) – A collection of elements

Returns:

True if this lattice is a strict subset of the other collection

Return type:

bool

Notes

If other is not an instance of Collection, this method returns NotImplemented.

__gt__(other)#

Check whether this lattice is a strict superset of another collection.

Parameters:

other (object) – A collection of elements

Returns:

True if this lattice is a strict superset of the other collection

Return type:

bool

Notes

If other is not an instance of Collection, this method returns NotImplemented.

__le__(other)#

Check whether this lattice is a subset of another collection.

Parameters:

other (object) – A collection of elements

Returns:

True if this lattice is a subset of the other collection

Return type:

bool

Notes

If other is not an instance of Collection, this method returns NotImplemented.

__ge__(other)#

Check whether this lattice is a superset of another collection.

Parameters:

other (object) – A collection of elements

Returns:

True if this lattice is a superset of the other collection

Return type:

bool

Notes

If other is not an instance of Collection, this method returns NotImplemented.

issubset(other)#

Check whether every element in the lattice is in the other iterable.

Parameters:

other (Iterable[_E]) – An iterable of pairs

Returns:

True if the lattice is a subset of the other iterable

Return type:

bool

issuperset(other)#

Check whether every element in the other iterable is in the lattice.

Parameters:

other (Iterable[_E]) – An iterable of pairs

Returns:

True if the lattice is a superset of the other iterable

Return type:

bool

upper_limit(*limits, strict=False)#

Return the elements less than the given limits.

Parameters:
  • *limits (_E) – The limits

  • strict (bool, default: False) – If True, uses strict comparison

Returns:

The elements less than the limits

Return type:

Collection[_E]

lower_limit(*limits, strict=False)#

Return the elements greater than the given limits.

Parameters:
  • *limits (_E) – The limits

  • strict (bool, default: False) – If True, uses strict comparison

Returns:

The elements greater than the limits

Return type:

Collection[_E]

interval(*limits)#

Return the interval defined by the given limits.

Parameters:

*limits (_E) – The limits for which the interval is requested

Returns:

The interval of the limits

Return type:

tuple[_E | None, _E | None]

infimum(iterable)#

Compute the infimum of meetable elements.

Parameters:

iterable (Iterable[_M]) – An iterable collection of meetable elements

Returns:

The meet of all elements in the iterable

Return type:

_M

Raises:

ValueError – If the iterable is empty

infimum_generators(iterable)#

Produce the infimum generators from an iterable of meetable elements.

Parameters:

iterable (Iterable[_M]) – The iterable collection of elements

Yields:

_M – An infimum generator

supremum(iterable)#

Compute the supremum of joinable elements.

Parameters:

iterable (Iterable[_J]) – An iterable of joinable elements

Returns:

The supremum of all elements in the iterable

Return type:

_J

Raises:

ValueError – If the iterable is empty

supremum_generators(iterable)#

Produce the supremum generators from an iterable of joinable elements.

Parameters:

iterable (Iterable[_J]) – An iterable of elements

Yields:

_J – A supremum generator

class FrozenJoinSemiLattice[_J: Joinable](*elements)#

Bases: JoinSemiLattice[_J]

Represents a concrete join semi-lattice.

An instance stores its irreducible elements in a poset.

Its memory complexity is \(O(j)\).

Parameters:

*elements (Iterable[_J]) – The initial elements

Examples

>>> from galactic.algebras.lattice.core import ExtensibleJoinSemiLattice
>>> from galactic.algebras.lattice.examples.arithmetic.core import PrimeFactors
>>> semi_lattice = ExtensibleJoinSemiLattice[PrimeFactors](
...     [
...         PrimeFactors(2*3*5),
...         PrimeFactors(3*5*7),
...         PrimeFactors(5*7*11)
...     ],
... )
>>> semi_lattice
<galactic.algebras.lattice.core.ExtensibleJoinSemiLattice object at 0x...>

You can get the maximum element.

>>> int(semi_lattice.maximum)
2310

You can iterate over the elements.

>>> sorted(list(map(int, semi_lattice)))
[30, 105, 210, 385, 1155, 2310]

You can iterate over the co-atoms.

>>> sorted(list(map(int, semi_lattice.co_atoms)))
[210, 1155]

You can iterate over the join-irreducible elements.

>>> sorted(list(map(int, semi_lattice.join_irreducible)))
[30, 105, 385]

You can iterate over the greatest join-irreducible elements smaller than a limit.

>>> sorted(
...     list(
...         map(
...             int,
...             semi_lattice.greatest_join_irreducible(PrimeFactors(2*3*5*7))
...         )
...     )
... )
[30, 105]

You can enlarge a join semi-lattice.

>>> semi_lattice.extend([PrimeFactors(13)])
>>> sorted(list(map(int, semi_lattice)))
[13, 30, 105, 210, 385, 390, 1155, 1365, 2310, 2730, 5005, 15015, 30030]
property version: int#

Get the version number.

Returns:

The version number

Return type:

int

Notes

This can be used to detect a change in the semi-lattice.

__hash__()#

Return the hash value of the join semi-lattice.

Returns:

The hash value of the join semi-lattice

Return type:

int

Notes

The hash value is computed based on the elements of the join semi-lattice. It is cached after the first computation for efficiency.

__copy__()#

Create a shallow copy of the join semi-lattice.

Returns:

The shallow copy of this join semi-lattice

Return type:

Self

copy()#

Return a copy of the join semi-lattice.

Returns:

The copy of this join semi-lattice

Return type:

Self

__len__()#

Return the number of elements in this join semi-lattice.

Returns:

The number of elements in this join semi-lattice

Return type:

int

__or__(other)#

Return the join of this join-semilattice and another.

Parameters:

other (object) – Another join-semilattice

Returns:

The join of this join-semilattice and another

Return type:

Self

Notes

If other is not an instance of Iterable, this method returns NotImplemented.

__and__(other)#

Return the meet of this join-semilattice and another.

Parameters:

other (object) – Another join-semilattice

Returns:

The meet of this join-semilattice and another

Return type:

Self

Notes

If other is not an instance of Iterable, this method returns NotImplemented.

join(*others)#

Compute the join of this join-semilattice and others.

Parameters:

*others (JoinSemiLattice[_J]) – A sequence of join-semilattice

Returns:

The join of this join-semilattice and others

Return type:

Self

meet(*others)#

Compute the meet of this join-semilattice and others.

Parameters:

*others (JoinSemiLattice[_J]) – A sequence of join-semilattice

Returns:

The meet of this join-semilattice and others

Return type:

Self

property order: Ordering[_J]#

Get the partial order of this join semi-lattice.

Returns:

The partial order

Return type:

Ordering[_J]

property cover: Ordering[_J]#

Get the covering relation of this join semi-lattice.

Returns:

The covering relation

Return type:

Ordering[_J]

property top: Collection[_J]#

Get the top elements.

The collection contains only one element, the maximum element.

Returns:

The top elements

Return type:

Collection[_J]

property bottom: Collection[_J]#

Get the bottom elements.

Returns:

The bottom elements

Return type:

Collection[_J]

filter(elem)#

Return a filter of a join semi-lattice.

Parameters:

elem (_J) – The lower limit

Returns:

A view on the lower bounded join semi-lattice

Return type:

JoinSemiLattice[_J]

Raises:

ValueError – If the element does not belong to the join semi-lattice

ideal(elem)#

Return an ideal of a join semi-lattice.

Parameters:

elem (_J) – The upper limit

Returns:

A view on the upper bounded join semi-lattice

Return type:

JoinSemiLattice[_J]

Raises:

ValueError – If the element does not belong to the join semi-lattice

property co_atoms: Collection[_J]#

Get the co-atoms of this join semi-lattice.

Returns:

The co-atoms

Return type:

Collection[_J]

property join_irreducible: Collection[_J]#

Get the join-irreducible elements of this join semi-lattice.

Returns:

The join-irreducible elements

Return type:

Collection[_J]

class FrozenMeetSemiLattice[_M: Meetable](*elements)#

Bases: MeetSemiLattice[_M]

Represents a concrete meet semi-lattice.

An instance stores its irreducible elements in a poset.

Its memory complexity is \(O(m)\).

Parameters:

*elements (Iterable[_M]) – The initial elements

Examples

>>> from galactic.algebras.lattice.core import ExtensibleMeetSemiLattice
>>> from galactic.algebras.lattice.examples.arithmetic.core import PrimeFactors
>>> semi_lattice = ExtensibleMeetSemiLattice[PrimeFactors](
...     [
...         PrimeFactors(2*3*5),
...         PrimeFactors(3*5*7),
...         PrimeFactors(5*7*11)
...     ]
... )
>>> semi_lattice
<galactic.algebras.lattice.core.ExtensibleMeetSemiLattice object at 0x...>

You can get the minimum element.

>>> int(semi_lattice.minimum)
5

You can iterate over the elements.

>>> sorted(list(map(int, semi_lattice)))
[5, 15, 30, 35, 105, 385]

You can iterate over the atoms.

>>> sorted(list(map(int, semi_lattice.atoms)))
[15, 35]

You can iterate over the meet-irreducible elements.

>>> sorted(list(map(int, semi_lattice.meet_irreducible)))
[30, 105, 385]

You can iterate over the smallest meet-irreducible elements greater than a limit.

>>> sorted(
...     list(
...         map(
...             int,
...             semi_lattice.smallest_meet_irreducible(PrimeFactors(7))
...         )
...     )
... )
[105, 385]

You can enlarge a meet semi-lattice.

>>> semi_lattice.extend([PrimeFactors(13)])
>>> sorted(list(map(int, semi_lattice)))
[1, 5, 13, 15, 30, 35, 105, 385]
property version: int#

Get the version number.

Returns:

The version number

Return type:

int

Notes

This can be used to detect changes in the semi-lattice.

__hash__()#

Return the hash value of this meet semi-lattice.

Returns:

The hash value of this meet semi-lattice

Return type:

int

Notes

The hash value is computed based on the elements of the meet semi-lattice. It is cached after the first computation.

__copy__()#

Return a shallow copy of this meet semi-lattice.

Returns:

A shallow copy of this meet semi-lattice

Return type:

Self

copy()#

Return a copy of this meet semi-lattice.

Returns:

A copy of this meet semi-lattice

Return type:

Self

__len__()#

Return the number of elements in this meet semi-lattice.

Returns:

The number of elements in this meet semi-lattice

Return type:

int

__or__(other)#

Return the join of this meet-semilattice and another.

Parameters:

other (object) – Another meet-semilattice

Returns:

The join of this meet-semilattice and another

Return type:

Self

Notes

If other is not an instance of Collection, this method returns NotImplemented.

__and__(other)#

Return the meet of this meet-semilattice and another.

Parameters:

other (object) – Another meet-semilattice

Returns:

The meet of this meet-semilattice and another

Return type:

Self

Notes

If other is not an instance of Collection, this method returns NotImplemented.

join(*others)#

Return the join of this meet semi-lattice and others.

Parameters:

*others (MeetSemiLattice[_M]) – A sequence of meet semi-lattices

Returns:

The join of this meet semi-lattice and the others

Return type:

Self

meet(*others)#

Return the meet of this meet semi-lattice and others.

Parameters:

*others (MeetSemiLattice[_M]) – A sequence of meet semi-lattices

Returns:

The meet of this meet semi-lattice and the others

Return type:

Self

property order: Ordering[_M]#

Get the partial order of this meet semi-lattice.

Returns:

The partial order

Return type:

Ordering[_M]

property cover: Ordering[_M]#

Get the covering relation of this meet semi-lattice.

Returns:

The covering relation

Return type:

Ordering[_M]

property top: Collection[_M]#

Get the top elements.

Returns:

The top elements

Return type:

Collection[_M]

property bottom: Collection[_M]#

Get the bottom elements.

The collection contains only the minimum element.

Returns:

The bottom elements

Return type:

Collection[_M]

filter(elem)#

Return a filter of the meet semi-lattice.

Parameters:

elem (_M) – The lower bound

Returns:

A view of the lower bounded meet semi-lattice

Return type:

MeetSemiLattice[_M]

Raises:

ValueError – If the element does not belong to the meet semi-lattice

ideal(elem)#

Return an ideal of the meet semi-lattice.

Parameters:

elem (_M) – The upper bound

Returns:

A view of the upper bounded meet semi-lattice

Return type:

MeetSemiLattice[_M]

Raises:

ValueError – If the element does not belong to the meet semi-lattice

property atoms: Collection[_M]#

Get the atoms of this meet semi-lattice.

Returns:

The atoms

Return type:

Collection[_M]

property meet_irreducible: Collection[_M]#

Get the meet-irreducible elements of this meet semi-lattice.

Returns:

The meet-irreducible elements

Return type:

Collection[_M]

class FrozenLattice[_E: Element](*elements)#

Bases: Lattice[_E]

Represents a frozen lattice.

Parameters:

*elements (Iterable[_E]) – The initial elements

property version: int#

Get the version number.

Returns:

The version number

Return type:

int

__hash__()#

Get the hash value of the lattice.

Returns:

The hash value of the lattice

Return type:

int

Notes

The hash value is computed based on the smaller of the join-irreducible or meet-irreducible elements for efficiency. It is cached after the first computation.

__copy__()#

Create a shallow copy of this lattice.

Returns:

A shallow copy of this lattice

Return type:

Self

copy()#

Return a copy of this lattice.

Returns:

A copy of this lattice

Return type:

Self

__len__()#

Get the number of elements in the lattice.

Returns:

The number of elements in the lattice

Return type:

int

__or__(other)#

Return the union of this lattice and an iterable of elements.

Parameters:

other (object) – Another lattice

Returns:

The union of this lattice and the other iterable

Return type:

Self

Notes

If other is not an instance of Iterable, this method returns NotImplemented.

__and__(other)#

Return the intersection of this lattice and another.

Parameters:

other (object) – Another lattice

Returns:

The intersection of this lattice and the other

Return type:

Self

Notes

If other is not an instance of Iterable, this method returns NotImplemented.

join(*others)#

Compute the join of this lattice and others.

Parameters:

*others (Lattice[_E]) – A sequence of lattices

Returns:

The join of this lattice and the others

Return type:

Self

meet(*others)#

Compute the meet of this lattice and others.

Parameters:

*others (Lattice[_E]) – A sequence of lattices

Returns:

The meet of this lattice and the others

Return type:

Self

property order: Ordering[_E]#

Get the partial order of this lattice.

Returns:

The partial order

Return type:

Ordering[_E]

property cover: Ordering[_E]#

Get the covering relation of this lattice.

Returns:

The covering relation

Return type:

Ordering[_E]

property top: Collection[_E]#

Get the top elements.

Returns:

The top elements

Return type:

Collection[_E]

property bottom: Collection[_E]#

Get the bottom elements.

Returns:

The bottom elements

Return type:

Collection[_E]

filter(elem)#

Return a filter of the lattice.

Parameters:

elem (_E) – The lower bound

Returns:

A view of the lower bounded lattice

Return type:

Lattice[_E]

Raises:

ValueError – If the element does not belong to the lattice

ideal(elem)#

Return an ideal of the lattice.

Parameters:

elem (_E) – The upper bound

Returns:

A view of the upper bounded lattice

Return type:

Lattice[_E]

Raises:

ValueError – If the element does not belong to the lattice

property meet_irreducible: Collection[_E]#

Get the meet-irreducible elements of this lattice.

Returns:

The meet-irreducible elements

Return type:

Collection[_E]

property atoms: Collection[_E]#

Get the atoms of this lattice.

Returns:

The atoms

Return type:

Collection[_E]

property join_irreducible: Collection[_E]#

Get the join-irreducible elements of this lattice.

Returns:

The join-irreducible elements

Return type:

Collection[_E]

property co_atoms: Collection[_E]#

Get the co-atoms of this lattice.

Returns:

The co-atoms

Return type:

Collection[_E]

class ExtensibleJoinSemiLattice[_J: Joinable](*elements)#

Bases: FrozenJoinSemiLattice[_J]

Represents an extensible join semi-lattice.

__ior__(other)#

In-place join of this join-semilattice and another.

Parameters:

other (object) – Another join-semilattice

Returns:

This join-semilattice after the join

Return type:

Self

Notes

If other is not an instance of Iterable, this method returns NotImplemented.

extend(iterable)#

Extend this join semi-lattice.

Parameters:

iterable (Iterable[_J]) – An iterable of elements

Return type:

None

class ExtensibleMeetSemiLattice[_M: Meetable](*elements)#

Bases: FrozenMeetSemiLattice[_M]

Represents an extensible meet semi-lattices.

__ior__(other)#

In-place join of this meet-semilattice and another.

Parameters:

other (object) – Another meet-semilattice

Returns:

This meet-semilattice after the join

Return type:

Self

Notes

If other is not an instance of Collection, this method returns NotImplemented.

extend(iterable)#

Extend this meet semi-lattice.

Parameters:

iterable (Iterable[_M]) – An iterable of elements

Return type:

None

class ExtensibleLattice[_E: Element](*elements)#

Bases: FrozenLattice[_E]

Represents extensible lattices.

The elements can be iterated from the maximum to the minimum element.

Example

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

implemented by the PrimeFactors class:

>>> from galactic.algebras.lattice.examples.arithmetic.core import PrimeFactors
>>> from galactic.algebras.lattice.core import ExtensibleLattice
>>> lattice = ExtensibleLattice[PrimeFactors](
...     [PrimeFactors(2), PrimeFactors(3)],
... )
>>> lattice
<galactic.algebras.lattice.core.ExtensibleLattice object at 0x...>
>>> list(map(int, lattice))
[1, 3, 2, 6]
__ior__(other)#

In-place union of this lattice and an iterable of elements.

Parameters:

other (object) – Another lattice

Returns:

This lattice after the union

Return type:

Self

Notes

If other is not an instance of Iterable, this method returns NotImplemented.

extend(iterable)#

Extend this lattice.

Parameters:

iterable (Iterable[_E]) – An iterable of elements

Return type:

None

class JoinSemiLatticeView[_J: Joinable](semi_lattice, *, lower=None, upper=None)#

Bases: JoinSemiLattice[_J]

Represents a bounded join semi-lattice.

This class provides a view of a join semi-lattice with specified lower and upper bounds.

Parameters:
  • semi_lattice (JoinSemiLattice[_J]) – The underlying semi-lattice

  • lower (_J | None, default: None) – The lower bound

  • upper (_J | None, default: None) – The upper bound

property version: int#

Get the version number of the semi-lattice.

Returns:

The version number

Return type:

int

Notes

This can be used to detect changes in the semi-lattice.

__len__()#

Return the number of elements in this join semi-lattice.

Returns:

The number of elements in this join semi-lattice

Return type:

int

property order: Ordering[_J]#

Get the partial order of this join semi-lattice.

Returns:

The partial order

Return type:

Ordering[_J]

property cover: Ordering[_J]#

Get the covering relation of this join semi-lattice.

Returns:

The covering relation

Return type:

Ordering[_J]

property top: Collection[_J]#

Get the top elements.

The collection contains only the maximum element.

Returns:

The top elements

Return type:

Collection[_J]

property bottom: Collection[_J]#

Get the bottom elements.

Returns:

The bottom elements

Return type:

Collection[_J]

filter(elem)#

Return a filter of the join semi-lattice.

Parameters:

elem (_J) – The lower bound

Returns:

A view of the bounded semi-lattice

Return type:

JoinSemiLattice[_J]

Raises:

ValueError – If the element does not belong to the semi-lattice

ideal(elem)#

Return an ideal of the join semi-lattice.

Parameters:

elem (_J) – The upper bound

Returns:

A view of the bounded semi-lattice

Return type:

JoinSemiLattice[_J]

Raises:

ValueError – If the element does not belong to the semi-lattice

property co_atoms: Collection[_J]#

Get the co-atoms of this join semi-lattice.

Returns:

The co-atoms

Return type:

Collection[_J]

property join_irreducible: Collection[_J]#

Get the join-irreducible elements of this join semi-lattice.

Returns:

The join-irreducible elements

Return type:

Collection[_J]

class MeetSemiLatticeView[_M: Meetable](semi_lattice, *, lower=None, upper=None)#

Bases: MeetSemiLattice[_M]

Represents a bounded meet semi-lattice.

This class provides a view of a meet semi-lattice with specified lower and upper bounds.

Parameters:
  • semi_lattice (MeetSemiLattice[_M]) – The underlying semi-lattice

  • lower (_M | None, default: None) – The lower bound

  • upper (_M | None, default: None) – The upper bound

property version: int#

Get the version number.

Returns:

The version number

Return type:

int

Notes

This can be used to detect changes in the semi-lattice.

__len__()#

Return the number of elements in this join semi-lattice.

Returns:

The number of elements in this join semi-lattice

Return type:

int

property order: Ordering[_M]#

Get the partial order of this meet semi-lattice.

Returns:

The partial order

Return type:

Ordering[_M]

property cover: Ordering[_M]#

Get the covering relation of this meet semi-lattice.

Returns:

The covering relation

Return type:

Ordering[_M]

property top: Collection[_M]#

Get the top elements.

Returns:

The top elements

Return type:

Collection[_M]

property bottom: Collection[_M]#

Get the bottom elements.

The collection contains only the minimum element.

Returns:

The bottom elements

Return type:

Collection[_M]

filter(elem)#

Return a filter of the meet semi-lattice.

Parameters:

elem (_M) – The lower bound

Returns:

A view of the lower bounded meet semi-lattice

Return type:

MeetSemiLattice[_M]

Raises:

ValueError – If the element does not belong to the meet semi-lattice

ideal(elem)#

Return an ideal of the meet semi-lattice.

Parameters:

elem (_M) – The upper bound

Returns:

A view of the upper bounded meet semi-lattice

Return type:

MeetSemiLattice[_M]

Raises:

ValueError – If the element does not belong to the meet semi-lattice

property atoms: Collection[_M]#

Get the atoms of this meet semi-lattice.

Returns:

The atoms

Return type:

Collection[_M]

property meet_irreducible: Collection[_M]#

Get the meet-irreducible elements of this meet semi-lattice.

Returns:

The meet-irreducible elements

Return type:

Collection[_M]

class LatticeView[_E: Element](lattice, *, lower=None, upper=None)#

Bases: Lattice[_E]

Represents a view of a lattice using ideal or filter construction.

Parameters:
  • lattice (Lattice[_E]) – The underlying lattice

  • lower (_E | None, default: None) – The lower bound

  • upper (_E | None, default: None) – The upper bound

property version: int#

Get the version number.

Returns:

The version number

Return type:

int

Notes

This can be used to detect changes in the lattice.

__len__()#

Get the number of elements in the lattice view.

Returns:

The number of elements in the lattice view

Return type:

int

property order: Ordering[_E]#

Get the partial order of this lattice.

Returns:

The partial order

Return type:

Ordering[_E]

property cover: Ordering[_E]#

Get the covering relation of this lattice.

Returns:

The covering relation

Return type:

Ordering[_E]

property top: Collection[_E]#

Get the top elements.

Returns:

The top elements

Return type:

Collection[_E]

property bottom: Collection[_E]#

Get the bottom elements.

Returns:

The bottom elements

Return type:

Collection[_E]

filter(elem)#

Return a filter of the lattice.

Parameters:

elem (_E) – The lower bound

Returns:

A view of the lower bounded lattice

Return type:

Lattice[_E]

Raises:

ValueError – If the element does not belong to the lattice

ideal(elem)#

Return an ideal of the lattice.

Parameters:

elem (_E) – The upper bound

Returns:

A view of the upper bounded lattice

Return type:

Lattice[_E]

Raises:

ValueError – If the element does not belong to the lattice

property atoms: Collection[_E]#

Get the atoms of this lattice.

Returns:

The atoms

Return type:

Collection[_E]

property meet_irreducible: Collection[_E]#

Get the meet-irreducible elements of this lattice.

Returns:

The meet-irreducible elements

Return type:

Collection[_E]

property co_atoms: Collection[_E]#

Get the co-atoms of this lattice.

Returns:

The co-atoms

Return type:

Collection[_E]

property join_irreducible: Collection[_E]#

Get the join-irreducible elements of this lattice.

Returns:

The join-irreducible elements

Return type:

Collection[_E]

class LatticeCoveringRelation[_E: Element](lattice)#

Bases: CoveringRelationMixin[_E]

Represents the covering relation of a lattice.

Parameters:

lattice (Lattice[_E]) – The lattice

successors(elem)#

Return the successors of an element.

Parameters:

elem (_E) – The element whose successors are requested

Returns:

The successors

Return type:

Collection[_E]

Raises:

ValueError – If the element does not belong to the lattice

predecessors(elem)#

Return the predecessors of an element.

Parameters:

elem (_E) – The element whose predecessors are requested

Returns:

The predecessors

Return type:

Collection[_E]

Raises:

ValueError – If the element does not belong to the lattice

class ReducedContext[_E: Element](lattice)#

Bases: EndoRelation[_E]

Represents the reduced context of a lattice.

It is a binary relation between the join-irreducible and meet-irreducible elements.

Parameters:

lattice (Lattice[_E]) – The lattice

__contains__(pair)#

Check whether a pair belongs to the reduced context.

Parameters:

pair (object) – A pair of join-irreducible and meet-irreducible elements

Returns:

True if the pair belongs to the reduced context

Return type:

bool

__iter__()#

Iterate over the pairs in the reduced context.

Returns:

An iterator over the pairs in the reduced context

Return type:

Iterator[tuple[_E, _E]]

__len__()#

Get the number of pairs in the reduced context.

Returns:

The number of pairs in the reduced context

Return type:

int

property universes: tuple[Collection[_E], Collection[_E]]#

Get the universes of this reduced context.

Returns:

The universes of this reduced context

Return type:

tuple[Collection[_E], Collection[_E]]

successors(elem)#

Return the successors of a join-irreducible, i.e. its attributes.

Parameters:

elem (_E) – A join-irreducible of the underlying lattice

Returns:

The successors of the element

Return type:

Collection[_E]

Raises:

ValueError – If the element does not belong to the domain of this reduced context

predecessors(elem)#

Return the predecessors of a meet-irreducible, i.e. its objects.

Parameters:

elem (_E) – A meet-irreducible of the underlying lattice

Returns:

The predecessors of the element

Return type:

Collection[_E]

Raises:

ValueError – If the element does not belong to the co-domain of this reduced context

property lattice: Lattice[_E]#

Get the underlying lattice.

Returns:

The underlying lattice

Return type:

Lattice