protocol

# `combinations_protocol`

Protocol for combinations operations over lists.

Availability:
`logtalk_load(combinations(loader))`
Author: Paulo Moura
Version: 2:0:0
Date: 2026-05-12
Compilation flags:
`static`
Dependencies:
(none)
Remarks:
(none)
Inherited public predicates:
(none)

## Public predicates

### `combinations/3`

Generates all K-element combinations of a list using default order.

Compilation flags:
`static`
Template:
`combinations(K,List,Combinations)`
Mode and number of proofs:
`combinations(+integer,+list,-list)` - `one`

### `combination/3`

True iff the third argument is a K-element combination of a list using default order.

Compilation flags:
`static`
Template:
`combination(K,List,Combination)`
Mode and number of proofs:
`combination(+integer,+list,-list)` - `one_or_more`

### `combinations/4`

Generates all K-element combinations with the given order: `default`, `lexicographic`, or `shortlex`.

Compilation flags:
`static`
Template:
`combinations(K,List,Order,Combinations)`
Mode and number of proofs:
`combinations(+integer,+list,+atom,-list)` - `one`

### `combination/4`

True iff the fourth argument is a K-element combination with the given order: `default`, `lexicographic`, or `shortlex`.

Compilation flags:
`static`
Template:
`combination(K,List,Order,Combination)`
Mode and number of proofs:
`combination(+integer,+list,+atom,-list)` - `one_or_more`

### `distinct_combinations/3`

Generates all distinct K-element combinations of a list (deduplicating equal-valued combinations) using default order.

Compilation flags:
`static`
Template:
`distinct_combinations(K,List,Combinations)`
Mode and number of proofs:
`distinct_combinations(+integer,+list,-list)` - `one`

### `distinct_combination/3`

True iff the third argument is a distinct K-element combination of a list using default order.

Compilation flags:
`static`
Template:
`distinct_combination(K,List,Combination)`
Mode and number of proofs:
`distinct_combination(+integer,+list,-list)` - `one_or_more`

### `distinct_combinations/4`

Generates all distinct K-element combinations with the given order: `default`, `lexicographic`, or `shortlex`.

Compilation flags:
`static`
Template:
`distinct_combinations(K,List,Order,Combinations)`
Mode and number of proofs:
`distinct_combinations(+integer,+list,+atom,-list)` - `one`

### `distinct_combination/4`

True iff the fourth argument is a distinct K-element combination with the given order: `default`, `lexicographic`, or `shortlex`.

Compilation flags:
`static`
Template:
`distinct_combination(K,List,Order,Combination)`
Mode and number of proofs:
`distinct_combination(+integer,+list,+atom,-list)` - `one_or_more`

### `nth_combination/4`

Returns the combination at a given zero-based index using default order.

Compilation flags:
`static`
Template:
`nth_combination(K,List,Index,Combination)`
Mode and number of proofs:
`nth_combination(+integer,+list,+integer,-list)` - `zero_or_one`

### `nth_combination/5`

Returns the combination at a given zero-based index in the given order: `default`, `lexicographic`, or `shortlex`.

Compilation flags:
`static`
Template:
`nth_combination(K,List,Order,Index,Combination)`
Mode and number of proofs:
`nth_combination(+integer,+list,+atom,+integer,-list)` - `zero_or_one`

### `combination_index/4`

Returns the zero-based index of a combination using default order.

Compilation flags:
`static`
Template:
`combination_index(K,List,Combination,Index)`
Mode and number of proofs:
`combination_index(+integer,+list,+list,-integer)` - `zero_or_one`

### `combination_index/5`

Returns the zero-based index of a combination in the given order: `default`, `lexicographic`, or `shortlex`.

Compilation flags:
`static`
Template:
`combination_index(K,List,Order,Combination,Index)`
Mode and number of proofs:
`combination_index(+integer,+list,+atom,+list,-integer)` - `zero_or_one`

### `count_combinations/3`

Counts the number of K-element combinations of a list.

Compilation flags:
`static`
Template:
`count_combinations(K,List,Count)`
Mode and number of proofs:
`count_combinations(+integer,+list,-integer)` - `one`

### `count_distinct_combinations/3`

Counts the number of distinct K-element combinations of a list (deduplicating equal-valued combinations).

Compilation flags:
`static`
Template:
`count_distinct_combinations(K,List,Count)`
Mode and number of proofs:
`count_distinct_combinations(+integer,+list,-integer)` - `one`

### `nth_distinct_combination/4`

Returns the distinct combination at a given zero-based index in default generation order.

Compilation flags:
`static`
Template:
`nth_distinct_combination(K,List,Index,Combination)`
Mode and number of proofs:
`nth_distinct_combination(+integer,+list,+integer,-list)` - `zero_or_one`

### `distinct_combination_index/4`

Returns the zero-based index of a distinct combination in default generation order.

Compilation flags:
`static`
Template:
`distinct_combination_index(K,List,Combination,Index)`
Mode and number of proofs:
`distinct_combination_index(+integer,+list,+list,-integer)` - `zero_or_one`

### `random_combination/3`

Returns a random K-element combination of a list.

Compilation flags:
`static`
Template:
`random_combination(K,List,Combination)`
Mode and number of proofs:
`random_combination(+integer,+list,-list)` - `zero_or_one`

### `sample_combinations/4`

Returns SampleCount random K-element combinations of a list, sampled with replacement.

Compilation flags:
`static`
Template:
`sample_combinations(K,List,SampleCount,Samples)`
Mode and number of proofs:
`sample_combinations(+integer,+list,+integer,-list)` - `zero_or_one`

### `random_distinct_combination/3`

Returns a random distinct K-element combination of a list (deduplicating equal-valued combinations).

Compilation flags:
`static`
Template:
`random_distinct_combination(K,List,Combination)`
Mode and number of proofs:
`random_distinct_combination(+integer,+list,-list)` - `zero_or_one`

### `sample_distinct_combinations/4`

Returns SampleCount random distinct K-element combinations of a list, sampled with replacement after deduplicating equal-valued combinations.

Compilation flags:
`static`
Template:
`sample_distinct_combinations(K,List,SampleCount,Samples)`
Mode and number of proofs:
`sample_distinct_combinations(+integer,+list,+integer,-list)` - `zero_or_one`

### `next_combination/3`

Returns the next distinct combination value in lexicographic order induced by the first argument.

Compilation flags:
`static`
Template:
`next_combination(List,Combination,Next)`
Mode and number of proofs:
`next_combination(+list,+list,-list)` - `zero_or_one`

### `previous_combination/3`

Returns the previous distinct combination value in lexicographic order induced by the first argument.

Compilation flags:
`static`
Template:
`previous_combination(List,Combination,Previous)`
Mode and number of proofs:
`previous_combination(+list,+list,-list)` - `zero_or_one`

## Protected predicates

(none)

## Private predicates

(none)

## Operators

(none)