fcapy.poset.lattice

The module provides a lattice object from Order theory and its upper/lower semilattices.

An upper semilattice is a poset that contains a single top (join) element. A lower semilattice is a poset that contains a single bottom (meet) element. A lattice contains both a single top and a single bottom elements.

Classes

Lattice(elements, leq_func, ~typing.Any], ...)

A class to represent a Lattice

LowerSemiLattice(elements, leq_func, ...)

A class to represent Meet (or Lower) Semilattice

UpperSemiLattice(elements, leq_func, ...)

A class to represent Join (or Upper) Semilattice

class fcapy.poset.lattice.Lattice(elements: ~typing.Collection[~typing.Any], leq_func: ~typing.Callable[[~typing.Any, ~typing.Any], bool] = <function UpperSemiLattice.<lambda>>, use_cache: bool = True, children_dict: ~typing.Optional[~typing.Dict[int, ~typing.Tuple[int, ...]]] = None)

A class to represent a Lattice

A lattice is a POSet with a single top (the biggest) and a single bottom (the smallest) elements

add(element: Any, fill_up_cache: bool = True)

Add an element to semilattice. Automatically fill up the comparison caches if needed

ancestors(element_index: int) FrozenSet[int]

Return a set of indexes of elements of POSet bigger than element #``element_index``

property ancestors_dict: Dict[int, FrozenSet[int]]

list`[indexes of all elements bigger than `element_idx]

Type

A dictionary of kind {element_idx

property bottom: int

An index of the bottom (the smallest) element of a semilattice

property bottoms: List[int]

A list of indexes of the bottom (the smallest) elements of a semilattice

children(element_index: int) FrozenSet[int]

Return a set of indexes of the biggest elements smaller than #``element_index``

Element a is a direct sub element of element b if a``<``b and there is no element c such that a``<``c``<``b

property children_dict: Dict[int, FrozenSet[int]]

list`[indexes of the biggest elements smaller than `element_idx]

Type

A dictionary of kind {element_idx

descendants(element_index: int) FrozenSet[int]

Return a set of indexes of elements of POSet smaller than element #``element_index``

property descendants_dict: Dict[int, FrozenSet[int]]

list`[indexes of all elements smaller than `element_idx]

Type

A dictionary of kind {element_idx

property elements: List[Any]

A list of elements of the POSet

fill_up_ancestors_cache()

Compute all ancestors of each element in a POSet

fill_up_caches()

Fill up each cache of POSet

fill_up_children_cache()

Compute children of each element in a POSet

fill_up_descendants_cache()

Compute all descendants of each element in a POSet

fill_up_leq_cache()

Compare all the elements of POSet at once

fill_up_parents_cache()

Compute parents of each element in a POSet

index(element: Any) int

Returns an index of the element in the list of POSet.elements

infimum(element_indexes: Optional[Collection[int]] = None) Optional[int]

Alias for self.meet(element_indexes)

join(element_indexes: Optional[Collection[int]] = None) Optional[int]

Return the smallest element from POSet bigger than all elements from element_indexes

leq_elements(a_index: int, b_index: int) bool

Compare two elements of POSet by their indexes

property leq_func: Callable[[Any, Any], bool]

A function to compare whether element a` from the POSet is smaller than ``b or not

meet(element_indexes: Optional[Collection[int]] = None) Optional[int]

Return the biggest element from POSet smaller than all elements from element_indexes

parents(element_index: int) FrozenSet[int]

Return a set of indexes of the smallest elements bigger than #``element_index``

Element a is a direct super element of element b if a>``b`` and there is no element c such that a>``c``>``b``

property parents_dict: Dict[int, FrozenSet[int]]

list`[indexes of the smallest elements bigger than `element_idx]

Type

A dictionary of kind {element_idx

remove(element: Any)

Remove and element from the semilattice

supremum(element_indexes: Optional[Collection[int]] = None) Optional[int]

Alias for self.join(element_indexes)

to_networkx(direction: str = 'down')

Construct networkx.Graph (or DiGraph) based on POSet relations and direction

property top: int

An index of the single top (the biggest) element of the semilattice

property tops: List[int]

The set of indexes of the top (the biggest) elements of the semilattice

trace_element(element: Any, direction: str) Tuple[Set[int], Set[int]]

Get the sets of descendants and children (or ancestors and parents) of an element in the POSet

Parameters
  • element – An element to compare POSet elements with (not necessary from the POSet itself)

  • direction ({'up', 'down'}) – If set ‘up’ then compute all (and direct) descendants of an element, if set ‘down’ then compute all (and direct) ancestors of an element

Returns

  • final_elements (set) – A set of children (or parents) of element in the POSet

  • traced_elements (set) – A set of descendants (or ancestors) of element in the POSet

class fcapy.poset.lattice.LowerSemiLattice(elements: ~typing.Collection[~typing.Any], leq_func: ~typing.Callable[[~typing.Any, ~typing.Any], bool] = <function LowerSemiLattice.<lambda>>, use_cache: bool = True, children_dict: ~typing.Optional[~typing.Dict[int, ~typing.Tuple[int, ...]]] = None)

A class to represent Meet (or Lower) Semilattice

A meet (or lower) semilattice is a POSet with a single bottom (meet) element

add(element: Any, fill_up_cache: bool = True)

Add an element to semilattice. Automatically fill up the comparison caches if needed

ancestors(element_index: int) FrozenSet[int]

Return a set of indexes of elements of POSet bigger than element #``element_index``

property ancestors_dict: Dict[int, FrozenSet[int]]

list`[indexes of all elements bigger than `element_idx]

Type

A dictionary of kind {element_idx

property bottom: int

An index of the bottom (the smallest) element of a semilattice

property bottoms: List[int]

A list of indexes of the bottom (the smallest) elements of a semilattice

children(element_index: int) FrozenSet[int]

Return a set of indexes of the biggest elements smaller than #``element_index``

Element a is a direct sub element of element b if a``<``b and there is no element c such that a``<``c``<``b

property children_dict: Dict[int, FrozenSet[int]]

list`[indexes of the biggest elements smaller than `element_idx]

Type

A dictionary of kind {element_idx

descendants(element_index: int) FrozenSet[int]

Return a set of indexes of elements of POSet smaller than element #``element_index``

property descendants_dict: Dict[int, FrozenSet[int]]

list`[indexes of all elements smaller than `element_idx]

Type

A dictionary of kind {element_idx

property elements: List[Any]

A list of elements of the POSet

fill_up_ancestors_cache()

Compute all ancestors of each element in a POSet

fill_up_caches()

Fill up each cache of POSet

fill_up_children_cache()

Compute children of each element in a POSet

fill_up_descendants_cache()

Compute all descendants of each element in a POSet

fill_up_leq_cache()

Compare all the elements of POSet at once

fill_up_parents_cache()

Compute parents of each element in a POSet

index(element: Any) int

Returns an index of the element in the list of POSet.elements

infimum(element_indexes: Optional[Collection[int]] = None) Optional[int]

Alias for self.meet(element_indexes)

join(element_indexes: Optional[Collection[int]] = None) Optional[int]

Return the smallest element from POSet bigger than all elements from element_indexes

leq_elements(a_index: int, b_index: int) bool

Compare two elements of POSet by their indexes

property leq_func: Callable[[Any, Any], bool]

A function to compare whether element a` from the POSet is smaller than ``b or not

meet(element_indexes: Optional[Collection[int]] = None) Optional[int]

Return the biggest element from POSet smaller than all elements from element_indexes

parents(element_index: int) FrozenSet[int]

Return a set of indexes of the smallest elements bigger than #``element_index``

Element a is a direct super element of element b if a>``b`` and there is no element c such that a>``c``>``b``

property parents_dict: Dict[int, FrozenSet[int]]

list`[indexes of the smallest elements bigger than `element_idx]

Type

A dictionary of kind {element_idx

remove(element: Any)

Remove and element from the semilattice

supremum(element_indexes: Optional[Collection[int]] = None) Optional[int]

Alias for self.join(element_indexes)

to_networkx(direction: str = 'down')

Construct networkx.Graph (or DiGraph) based on POSet relations and direction

property tops: List[int]

A list of the top (the biggest) elements in a POSet

trace_element(element: Any, direction: str) Tuple[Set[int], Set[int]]

Get the sets of descendants and children (or ancestors and parents) of an element in the POSet

Parameters
  • element – An element to compare POSet elements with (not necessary from the POSet itself)

  • direction ({'up', 'down'}) – If set ‘up’ then compute all (and direct) descendants of an element, if set ‘down’ then compute all (and direct) ancestors of an element

Returns

  • final_elements (set) – A set of children (or parents) of element in the POSet

  • traced_elements (set) – A set of descendants (or ancestors) of element in the POSet

class fcapy.poset.lattice.UpperSemiLattice(elements: ~typing.Collection[~typing.Any], leq_func: ~typing.Callable[[~typing.Any, ~typing.Any], bool] = <function UpperSemiLattice.<lambda>>, use_cache: bool = True, children_dict: ~typing.Optional[~typing.Dict[int, ~typing.Tuple[int, ...]]] = None)

A class to represent Join (or Upper) Semilattice

A join (or upper) semilattice is a POSet with a single top (join) element

add(element: Any, fill_up_cache: bool = True)

Add an element to semilattice. Automatically fill up the comparison caches if needed

ancestors(element_index: int) FrozenSet[int]

Return a set of indexes of elements of POSet bigger than element #``element_index``

property ancestors_dict: Dict[int, FrozenSet[int]]

list`[indexes of all elements bigger than `element_idx]

Type

A dictionary of kind {element_idx

property bottoms: List[int]

A list of the bottom (the smallest) elements in a POSet

children(element_index: int) FrozenSet[int]

Return a set of indexes of the biggest elements smaller than #``element_index``

Element a is a direct sub element of element b if a``<``b and there is no element c such that a``<``c``<``b

property children_dict: Dict[int, FrozenSet[int]]

list`[indexes of the biggest elements smaller than `element_idx]

Type

A dictionary of kind {element_idx

descendants(element_index: int) FrozenSet[int]

Return a set of indexes of elements of POSet smaller than element #``element_index``

property descendants_dict: Dict[int, FrozenSet[int]]

list`[indexes of all elements smaller than `element_idx]

Type

A dictionary of kind {element_idx

property elements: List[Any]

A list of elements of the POSet

fill_up_ancestors_cache()

Compute all ancestors of each element in a POSet

fill_up_caches()

Fill up each cache of POSet

fill_up_children_cache()

Compute children of each element in a POSet

fill_up_descendants_cache()

Compute all descendants of each element in a POSet

fill_up_leq_cache()

Compare all the elements of POSet at once

fill_up_parents_cache()

Compute parents of each element in a POSet

index(element: Any) int

Returns an index of the element in the list of POSet.elements

infimum(element_indexes: Optional[Collection[int]] = None) Optional[int]

Alias for self.meet(element_indexes)

join(element_indexes: Optional[Collection[int]] = None) Optional[int]

Return the smallest element from POSet bigger than all elements from element_indexes

leq_elements(a_index: int, b_index: int) bool

Compare two elements of POSet by their indexes

property leq_func: Callable[[Any, Any], bool]

A function to compare whether element a` from the POSet is smaller than ``b or not

meet(element_indexes: Optional[Collection[int]] = None) Optional[int]

Return the biggest element from POSet smaller than all elements from element_indexes

parents(element_index: int) FrozenSet[int]

Return a set of indexes of the smallest elements bigger than #``element_index``

Element a is a direct super element of element b if a>``b`` and there is no element c such that a>``c``>``b``

property parents_dict: Dict[int, FrozenSet[int]]

list`[indexes of the smallest elements bigger than `element_idx]

Type

A dictionary of kind {element_idx

remove(element: Any)

Remove and element from the semilattice

supremum(element_indexes: Optional[Collection[int]] = None) Optional[int]

Alias for self.join(element_indexes)

to_networkx(direction: str = 'down')

Construct networkx.Graph (or DiGraph) based on POSet relations and direction

property top: int

An index of the single top (the biggest) element of the semilattice

property tops: List[int]

The set of indexes of the top (the biggest) elements of the semilattice

trace_element(element: Any, direction: str) Tuple[Set[int], Set[int]]

Get the sets of descendants and children (or ancestors and parents) of an element in the POSet

Parameters
  • element – An element to compare POSet elements with (not necessary from the POSet itself)

  • direction ({'up', 'down'}) – If set ‘up’ then compute all (and direct) descendants of an element, if set ‘down’ then compute all (and direct) ancestors of an element

Returns

  • final_elements (set) – A set of children (or parents) of element in the POSet

  • traced_elements (set) – A set of descendants (or ancestors) of element in the POSet