protocol

# `cartesian_products_protocol`

Protocol for Cartesian-product operations over lists.

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

## Public predicates

### `cartesian_product/2`

Generates the Cartesian product of a list of lists using default order.

Compilation flags:
`static`
Template:
`cartesian_product(Lists,Product)`
Mode and number of proofs:
`cartesian_product(+list(list),-list)` - `one`

### `cartesian_tuple/2`

True iff the second argument is a tuple obtained by selecting one element from each list in the first argument using default order.

Compilation flags:
`static`
Template:
`cartesian_tuple(Lists,Tuple)`
Mode and number of proofs:
`cartesian_tuple(+list(list),-list)` - `one_or_more`

### `cartesian_product/3`

Generates the Cartesian product with the given order: `default` or `lexicographic`.

Compilation flags:
`static`
Template:
`cartesian_product(Lists,Order,Product)`
Mode and number of proofs:
`cartesian_product(+list(list),+atom,-list)` - `one`

### `cartesian_tuple/3`

True iff the third argument is a Cartesian-product tuple with the given order: `default` or `lexicographic`.

Compilation flags:
`static`
Template:
`cartesian_tuple(Lists,Order,Tuple)`
Mode and number of proofs:
`cartesian_tuple(+list(list),+atom,-list)` - `one_or_more`

### `distinct_cartesian_product/2`

Generates the Cartesian product after deduplicating repeated values in each factor list using default order.

Compilation flags:
`static`
Template:
`distinct_cartesian_product(Lists,Product)`
Mode and number of proofs:
`distinct_cartesian_product(+list(list),-list)` - `one`

### `distinct_cartesian_tuple/2`

True iff the second argument is a tuple in the distinct Cartesian product of the factor lists using default order.

Compilation flags:
`static`
Template:
`distinct_cartesian_tuple(Lists,Tuple)`
Mode and number of proofs:
`distinct_cartesian_tuple(+list(list),-list)` - `one_or_more`

### `distinct_cartesian_product/3`

Generates the distinct Cartesian product with the given order: `default` or `lexicographic`.

Compilation flags:
`static`
Template:
`distinct_cartesian_product(Lists,Order,Product)`
Mode and number of proofs:
`distinct_cartesian_product(+list(list),+atom,-list)` - `one`

### `distinct_cartesian_tuple/3`

True iff the third argument is a tuple in the distinct Cartesian product with the given order: `default` or `lexicographic`.

Compilation flags:
`static`
Template:
`distinct_cartesian_tuple(Lists,Order,Tuple)`
Mode and number of proofs:
`distinct_cartesian_tuple(+list(list),+atom,-list)` - `one_or_more`

### `count_cartesian_product/2`

Counts the number of tuples in the Cartesian product of a list of lists.

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

### `count_distinct_cartesian_product/2`

Counts the number of tuples in the distinct Cartesian product after deduplicating repeated values in each factor list.

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

### `nth_cartesian_tuple/3`

Returns the Cartesian-product tuple at a given zero-based index using default order.

Compilation flags:
`static`
Template:
`nth_cartesian_tuple(Lists,Index,Tuple)`
Mode and number of proofs:
`nth_cartesian_tuple(+list(list),+integer,-list)` - `zero_or_one`

### `nth_cartesian_tuple/4`

Returns the Cartesian-product tuple at a given zero-based index in the given order: `default` or `lexicographic`.

Compilation flags:
`static`
Template:
`nth_cartesian_tuple(Lists,Order,Index,Tuple)`
Mode and number of proofs:
`nth_cartesian_tuple(+list(list),+atom,+integer,-list)` - `zero_or_one`

### `cartesian_tuple_index/3`

Returns the zero-based index of a Cartesian-product tuple using default order.

Compilation flags:
`static`
Template:
`cartesian_tuple_index(Lists,Tuple,Index)`
Mode and number of proofs:
`cartesian_tuple_index(+list(list),+list,-integer)` - `zero_or_one`

### `cartesian_tuple_index/4`

Returns the zero-based index of a Cartesian-product tuple in the given order: `default` or `lexicographic`.

Compilation flags:
`static`
Template:
`cartesian_tuple_index(Lists,Order,Tuple,Index)`
Mode and number of proofs:
`cartesian_tuple_index(+list(list),+atom,+list,-integer)` - `zero_or_one`

### `nth_distinct_cartesian_tuple/3`

Returns the distinct Cartesian-product tuple at a given zero-based index in default generation order.

Compilation flags:
`static`
Template:
`nth_distinct_cartesian_tuple(Lists,Index,Tuple)`
Mode and number of proofs:
`nth_distinct_cartesian_tuple(+list(list),+integer,-list)` - `zero_or_one`

### `distinct_cartesian_tuple_index/3`

Returns the zero-based index of a distinct Cartesian-product tuple in default generation order.

Compilation flags:
`static`
Template:
`distinct_cartesian_tuple_index(Lists,Tuple,Index)`
Mode and number of proofs:
`distinct_cartesian_tuple_index(+list(list),+list,-integer)` - `zero_or_one`

### `random_cartesian_tuple/2`

Returns a random Cartesian-product tuple.

Compilation flags:
`static`
Template:
`random_cartesian_tuple(Lists,Tuple)`
Mode and number of proofs:
`random_cartesian_tuple(+list(list),-list)` - `zero_or_one`

### `sample_cartesian_tuples/3`

Returns SampleCount random Cartesian-product tuples, sampled with replacement.

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

### `random_distinct_cartesian_tuple/2`

Returns a random tuple from the distinct Cartesian product after deduplicating repeated values in each factor list.

Compilation flags:
`static`
Template:
`random_distinct_cartesian_tuple(Lists,Tuple)`
Mode and number of proofs:
`random_distinct_cartesian_tuple(+list(list),-list)` - `zero_or_one`

### `sample_distinct_cartesian_tuples/3`

Returns SampleCount random tuples from the distinct Cartesian product, sampled with replacement.

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

### `next_cartesian_tuple/3`

Returns the next distinct Cartesian-product tuple in lexicographic order induced by the factor lists.

Compilation flags:
`static`
Template:
`next_cartesian_tuple(Lists,Tuple,Next)`
Mode and number of proofs:
`next_cartesian_tuple(+list(list),+list,-list)` - `zero_or_one`

### `previous_cartesian_tuple/3`

Returns the previous distinct Cartesian-product tuple in lexicographic order induced by the factor lists.

Compilation flags:
`static`
Template:
`previous_cartesian_tuple(Lists,Tuple,Previous)`
Mode and number of proofs:
`previous_cartesian_tuple(+list(list),+list,-list)` - `zero_or_one`

## Protected predicates

(none)

## Private predicates

(none)

## Operators

(none)