.. index:: single: cartesian_products_protocol
.. _cartesian_products_protocol/0:

.. rst-class:: right

**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)

.. contents::
   :local:
   :backlinks: top

Public predicates
-----------------

.. index:: cartesian_product/2
.. _cartesian_products_protocol/0::cartesian_product/2:

``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``


------------

.. index:: cartesian_tuple/2
.. _cartesian_products_protocol/0::cartesian_tuple/2:

``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``


------------

.. index:: cartesian_product/3
.. _cartesian_products_protocol/0::cartesian_product/3:

``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``


------------

.. index:: cartesian_tuple/3
.. _cartesian_products_protocol/0::cartesian_tuple/3:

``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``


------------

.. index:: distinct_cartesian_product/2
.. _cartesian_products_protocol/0::distinct_cartesian_product/2:

``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``


------------

.. index:: distinct_cartesian_tuple/2
.. _cartesian_products_protocol/0::distinct_cartesian_tuple/2:

``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``


------------

.. index:: distinct_cartesian_product/3
.. _cartesian_products_protocol/0::distinct_cartesian_product/3:

``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``


------------

.. index:: distinct_cartesian_tuple/3
.. _cartesian_products_protocol/0::distinct_cartesian_tuple/3:

``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``


------------

.. index:: count_cartesian_product/2
.. _cartesian_products_protocol/0::count_cartesian_product/2:

``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``


------------

.. index:: count_distinct_cartesian_product/2
.. _cartesian_products_protocol/0::count_distinct_cartesian_product/2:

``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``


------------

.. index:: nth_cartesian_tuple/3
.. _cartesian_products_protocol/0::nth_cartesian_tuple/3:

``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``


------------

.. index:: nth_cartesian_tuple/4
.. _cartesian_products_protocol/0::nth_cartesian_tuple/4:

``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``


------------

.. index:: cartesian_tuple_index/3
.. _cartesian_products_protocol/0::cartesian_tuple_index/3:

``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``


------------

.. index:: cartesian_tuple_index/4
.. _cartesian_products_protocol/0::cartesian_tuple_index/4:

``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``


------------

.. index:: nth_distinct_cartesian_tuple/3
.. _cartesian_products_protocol/0::nth_distinct_cartesian_tuple/3:

``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``


------------

.. index:: distinct_cartesian_tuple_index/3
.. _cartesian_products_protocol/0::distinct_cartesian_tuple_index/3:

``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``


------------

.. index:: random_cartesian_tuple/2
.. _cartesian_products_protocol/0::random_cartesian_tuple/2:

``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``


------------

.. index:: sample_cartesian_tuples/3
.. _cartesian_products_protocol/0::sample_cartesian_tuples/3:

``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``


------------

.. index:: random_distinct_cartesian_tuple/2
.. _cartesian_products_protocol/0::random_distinct_cartesian_tuple/2:

``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``


------------

.. index:: sample_distinct_cartesian_tuples/3
.. _cartesian_products_protocol/0::sample_distinct_cartesian_tuples/3:

``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``


------------

.. index:: next_cartesian_tuple/3
.. _cartesian_products_protocol/0::next_cartesian_tuple/3:

``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``


------------

.. index:: previous_cartesian_tuple/3
.. _cartesian_products_protocol/0::previous_cartesian_tuple/3:

``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)

