.. index:: single: derangements_protocol
.. _derangements_protocol/0:

.. rst-class:: right

**protocol**

``derangements_protocol``
=========================

Protocol for derangement operations over lists.

| **Availability:** 
|    ``logtalk_load(derangements(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:: derangements/2
.. _derangements_protocol/0::derangements/2:

``derangements/2``
^^^^^^^^^^^^^^^^^^

Generates all derangements of a list using default order.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``derangements(List,Derangements)``
| **Mode and number of proofs:**
|    ``derangements(+list,-list)`` - ``one``


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

.. index:: derangement/2
.. _derangements_protocol/0::derangement/2:

``derangement/2``
^^^^^^^^^^^^^^^^^

True iff the second argument is a derangement of the first argument using default order.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``derangement(List,Derangement)``
| **Mode and number of proofs:**
|    ``derangement(+list,-list)`` - ``zero_or_more``


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

.. index:: derangements/3
.. _derangements_protocol/0::derangements/3:

``derangements/3``
^^^^^^^^^^^^^^^^^^

Generates all derangements with the given order: ``default``, ``lexicographic``, or ``shortlex``.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``derangements(List,Order,Derangements)``
| **Mode and number of proofs:**
|    ``derangements(+list,+atom,-list)`` - ``one``


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

.. index:: derangement/3
.. _derangements_protocol/0::derangement/3:

``derangement/3``
^^^^^^^^^^^^^^^^^

True iff the third argument is a derangement with the given order: ``default``, ``lexicographic``, or ``shortlex``.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``derangement(List,Order,Derangement)``
| **Mode and number of proofs:**
|    ``derangement(+list,+atom,-list)`` - ``zero_or_more``


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

.. index:: distinct_derangements/2
.. _derangements_protocol/0::distinct_derangements/2:

``distinct_derangements/2``
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Generates all distinct derangements of a list using default order.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``distinct_derangements(List,Derangements)``
| **Mode and number of proofs:**
|    ``distinct_derangements(+list,-list)`` - ``one``


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

.. index:: distinct_derangement/2
.. _derangements_protocol/0::distinct_derangement/2:

``distinct_derangement/2``
^^^^^^^^^^^^^^^^^^^^^^^^^^

True iff the second argument is a distinct derangement of the first argument using default order.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``distinct_derangement(List,Derangement)``
| **Mode and number of proofs:**
|    ``distinct_derangement(+list,-list)`` - ``zero_or_more``


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

.. index:: distinct_derangements/3
.. _derangements_protocol/0::distinct_derangements/3:

``distinct_derangements/3``
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Generates all distinct derangements with the given order: ``default``, ``lexicographic``, or ``shortlex``.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``distinct_derangements(List,Order,Derangements)``
| **Mode and number of proofs:**
|    ``distinct_derangements(+list,+atom,-list)`` - ``one``


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

.. index:: distinct_derangement/3
.. _derangements_protocol/0::distinct_derangement/3:

``distinct_derangement/3``
^^^^^^^^^^^^^^^^^^^^^^^^^^

True iff the third argument is a distinct derangement with the given order: ``default``, ``lexicographic``, or ``shortlex``.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``distinct_derangement(List,Order,Derangement)``
| **Mode and number of proofs:**
|    ``distinct_derangement(+list,+atom,-list)`` - ``zero_or_more``


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

.. index:: nth_derangement/3
.. _derangements_protocol/0::nth_derangement/3:

``nth_derangement/3``
^^^^^^^^^^^^^^^^^^^^^

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

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``nth_derangement(List,Index,Derangement)``
| **Mode and number of proofs:**
|    ``nth_derangement(+list,+integer,-list)`` - ``zero_or_one``


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

.. index:: nth_derangement/4
.. _derangements_protocol/0::nth_derangement/4:

``nth_derangement/4``
^^^^^^^^^^^^^^^^^^^^^

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

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``nth_derangement(List,Order,Index,Derangement)``
| **Mode and number of proofs:**
|    ``nth_derangement(+list,+atom,+integer,-list)`` - ``zero_or_one``


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

.. index:: derangement_index/3
.. _derangements_protocol/0::derangement_index/3:

``derangement_index/3``
^^^^^^^^^^^^^^^^^^^^^^^

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

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``derangement_index(List,Derangement,Index)``
| **Mode and number of proofs:**
|    ``derangement_index(+list,+list,-integer)`` - ``zero_or_one``


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

.. index:: derangement_index/4
.. _derangements_protocol/0::derangement_index/4:

``derangement_index/4``
^^^^^^^^^^^^^^^^^^^^^^^

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

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``derangement_index(List,Order,Derangement,Index)``
| **Mode and number of proofs:**
|    ``derangement_index(+list,+atom,+list,-integer)`` - ``zero_or_one``


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

.. index:: count_derangements/2
.. _derangements_protocol/0::count_derangements/2:

``count_derangements/2``
^^^^^^^^^^^^^^^^^^^^^^^^

Counts the number of derangements of a list.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``count_derangements(List,Count)``
| **Mode and number of proofs:**
|    ``count_derangements(+list,-integer)`` - ``one``


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

.. index:: count_partial_derangements/3
.. _derangements_protocol/0::count_partial_derangements/3:

``count_partial_derangements/3``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Counts the number of permutations of a list with exactly the given number of fixed points.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``count_partial_derangements(FixedPoints,List,Count)``
| **Mode and number of proofs:**
|    ``count_partial_derangements(+integer,+list,-integer)`` - ``one``


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

.. index:: count_distinct_derangements/2
.. _derangements_protocol/0::count_distinct_derangements/2:

``count_distinct_derangements/2``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Counts the number of distinct derangements of a list (deduplicating equal-valued derangements).

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``count_distinct_derangements(List,Count)``
| **Mode and number of proofs:**
|    ``count_distinct_derangements(+list,-integer)`` - ``one``


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

.. index:: nth_distinct_derangement/3
.. _derangements_protocol/0::nth_distinct_derangement/3:

``nth_distinct_derangement/3``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``nth_distinct_derangement(List,Index,Derangement)``
| **Mode and number of proofs:**
|    ``nth_distinct_derangement(+list,+integer,-list)`` - ``zero_or_one``


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

.. index:: distinct_derangement_index/3
.. _derangements_protocol/0::distinct_derangement_index/3:

``distinct_derangement_index/3``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``distinct_derangement_index(List,Derangement,Index)``
| **Mode and number of proofs:**
|    ``distinct_derangement_index(+list,+list,-integer)`` - ``zero_or_one``


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

.. index:: random_derangement/2
.. _derangements_protocol/0::random_derangement/2:

``random_derangement/2``
^^^^^^^^^^^^^^^^^^^^^^^^

Returns a random derangement of a list.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``random_derangement(List,Derangement)``
| **Mode and number of proofs:**
|    ``random_derangement(+list,-list)`` - ``zero_or_one``


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

.. index:: sample_derangements/3
.. _derangements_protocol/0::sample_derangements/3:

``sample_derangements/3``
^^^^^^^^^^^^^^^^^^^^^^^^^

Returns SampleCount random derangements of a list, sampled with replacement.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``sample_derangements(List,SampleCount,Samples)``
| **Mode and number of proofs:**
|    ``sample_derangements(+list,+integer,-list)`` - ``zero_or_one``


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

.. index:: random_distinct_derangement/2
.. _derangements_protocol/0::random_distinct_derangement/2:

``random_distinct_derangement/2``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Returns a random distinct derangement of a list (deduplicating equal-valued derangements).

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``random_distinct_derangement(List,Derangement)``
| **Mode and number of proofs:**
|    ``random_distinct_derangement(+list,-list)`` - ``zero_or_one``


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

.. index:: sample_distinct_derangements/3
.. _derangements_protocol/0::sample_distinct_derangements/3:

``sample_distinct_derangements/3``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``sample_distinct_derangements(List,SampleCount,Samples)``
| **Mode and number of proofs:**
|    ``sample_distinct_derangements(+list,+integer,-list)`` - ``zero_or_one``


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

.. index:: next_derangement/3
.. _derangements_protocol/0::next_derangement/3:

``next_derangement/3``
^^^^^^^^^^^^^^^^^^^^^^

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

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``next_derangement(List,Derangement,Next)``
| **Mode and number of proofs:**
|    ``next_derangement(+list,+list,-list)`` - ``zero_or_one``


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

.. index:: previous_derangement/3
.. _derangements_protocol/0::previous_derangement/3:

``previous_derangement/3``
^^^^^^^^^^^^^^^^^^^^^^^^^^

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

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``previous_derangement(List,Derangement,Previous)``
| **Mode and number of proofs:**
|    ``previous_derangement(+list,+list,-list)`` - ``zero_or_one``


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

Protected predicates
--------------------

(none)

Private predicates
------------------

(none)

Operators
---------

(none)

