protocol

# `combinations_protocol`

Protocol for combinations operations over lists.

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

## Public predicates

### `combinations/3`

Generates all K-element combinations of a list.

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.

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`

### `combinations_with_replacement/3`

Generates all K-element combinations with replacement.

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

### `combinations_with_replacement/4`

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

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

### `combination_with_replacement/3`

True iff the third argument is a K-element combination with replacement.

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

### `combination_with_replacement/4`

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

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

### `distinct_combinations/3`

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

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.

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.

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

### `combination_index/4`

Returns the zero-based index of a combination.

Compilation flags:
`static`
Template:
`combination_index(K,List,Combination,Index)`
Mode and number of proofs:
`combination_index(+integer,+list,+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_combinations_with_replacement/3`

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

Compilation flags:
`static`
Template:
`count_combinations_with_replacement(K,List,Count)`
Mode and number of proofs:
`count_combinations_with_replacement(+integer,+list,-integer)` - `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`

## Protected predicates

(none)

## Private predicates

(none)

## Operators

(none)