combinatorics
combinatorics
¶
E = TypeVar('E')
module-attribute
¶
S = TypeVar('S')
module-attribute
¶
maximal_elements(elements: Iterable[E], compare: Callable[[E, E], bool]) -> Sequence[E]
¶
Enumerate maximal elements with respect to compare.
compare(e1, e2) == True
iff e1
smaller or equal to e2
.
Source code in src/cosy/combinatorics.py
minimal_covers(sets: Sequence[S], to_cover: Iterable[E], contains: Callable[[S, E], bool]) -> list[list[S]]
¶
List minimal covers of elements in to_cover using given sets.
Properties of each cover: list[S]
- for every e: E
in to_cover
there is at least one s: S
in cover
such that contains(s, e) == True
- no s: S
can be removed from cover
Source code in src/cosy/combinatorics.py
partition(predicate: Callable[[E], bool], elements: Iterable[E]) -> tuple[deque[E], deque[E]]
¶
Partition elements of an Iterable according to a predicate. Narrowing types.
Returns: (elements not satisfying predicate, elements satisfying predicate).