protocol

integer_partitions_protocol

Protocol for integer partition operations.

Availability:
logtalk_load(integer_partitions(loader))
Author: Paulo Moura
Version: 1:0:0
Date: 2026-07-27
Compilation flags:
static
Dependencies:
(none)
Remarks:
(none)
Inherited public predicates:
(none)

Public predicates

partitions/2

Generates all partitions of a non-negative integer using default order. Partitions are represented as non-increasing lists of positive integers that sum to the given integer. Zero has one partition, represented by the empty list of parts.

Compilation flags:
static
Template:
partitions(N,Partitions)
Mode and number of proofs:
partitions(+non_negative_integer,-list) - one

partition/2

True iff the second argument is a partition of a non-negative integer using default order.

Compilation flags:
static
Template:
partition(N,Partition)
Mode and number of proofs:
partition(+non_negative_integer,-list) - one_or_more

partitions/3

Generates either all partitions of an integer with the given order (when the second argument is default or lexicographic) or all partitions with an exact number of parts using default order (when the second argument is an integer). Note that, unlike the partitions library (where the size constraint can occupy the first argument position, distinguishing it from a list by type), here the integer being partitioned and the exact part count are both integers, so the part count is always given as the second argument, distinguished from the order by type.

Compilation flags:
static
Template:
partitions(N,KOrOrder,Partitions)
Mode and number of proofs:
partitions(+non_negative_integer,+atom,-list) - one
partitions(+non_negative_integer,+non_negative_integer,-list) - one

partition/3

True iff the third argument is a partition generated either in the given order or with the given exact number of parts using default order.

Compilation flags:
static
Template:
partition(N,KOrOrder,Partition)
Mode and number of proofs:
partition(+non_negative_integer,+atom,-list) - one_or_more
partition(+non_negative_integer,+non_negative_integer,-list) - one_or_more

partitions/4

Generates all partitions of an integer with an exact number of parts and the given order: default or lexicographic.

Compilation flags:
static
Template:
partitions(N,K,Order,Partitions)
Mode and number of proofs:
partitions(+non_negative_integer,+non_negative_integer,+atom,-list) - one

partition/4

True iff the fourth argument is a partition with an exact number of parts and the given order: default or lexicographic.

Compilation flags:
static
Template:
partition(N,K,Order,Partition)
Mode and number of proofs:
partition(+non_negative_integer,+non_negative_integer,+atom,-list) - one_or_more

distinct_partitions/2

Generates all partitions of a non-negative integer into distinct (non-repeating) parts using default order. Unlike the partitions library, where “distinct” deduplicates equal-valued results from a position-sensitive generator, an integer partition has no position-sensitive input to begin with; here “distinct” is the standard integer partition notion of parts that are pairwise different (also known as strict partitions).

Compilation flags:
static
Template:
distinct_partitions(N,Partitions)
Mode and number of proofs:
distinct_partitions(+non_negative_integer,-list) - one

distinct_partition/2

True iff the second argument is a partition of a non-negative integer into distinct parts using default order.

Compilation flags:
static
Template:
distinct_partition(N,Partition)
Mode and number of proofs:
distinct_partition(+non_negative_integer,-list) - one_or_more

distinct_partitions/3

Generates either all partitions into distinct parts with the given order (when the second argument is default or lexicographic) or all partitions into an exact number of distinct parts using default order (when the second argument is an integer).

Compilation flags:
static
Template:
distinct_partitions(N,KOrOrder,Partitions)
Mode and number of proofs:
distinct_partitions(+non_negative_integer,+atom,-list) - one
distinct_partitions(+non_negative_integer,+non_negative_integer,-list) - one

distinct_partition/3

True iff the third argument is a partition into distinct parts generated either in the given order or with the given exact number of parts using default order.

Compilation flags:
static
Template:
distinct_partition(N,KOrOrder,Partition)
Mode and number of proofs:
distinct_partition(+non_negative_integer,+atom,-list) - one_or_more
distinct_partition(+non_negative_integer,+non_negative_integer,-list) - one_or_more

distinct_partitions/4

Generates all partitions of an integer into an exact number of distinct parts and the given order: default or lexicographic.

Compilation flags:
static
Template:
distinct_partitions(N,K,Order,Partitions)
Mode and number of proofs:
distinct_partitions(+non_negative_integer,+non_negative_integer,+atom,-list) - one

distinct_partition/4

True iff the fourth argument is a partition into an exact number of distinct parts and the given order: default or lexicographic.

Compilation flags:
static
Template:
distinct_partition(N,K,Order,Partition)
Mode and number of proofs:
distinct_partition(+non_negative_integer,+non_negative_integer,+atom,-list) - one_or_more

count_partitions/2

Counts the number of partitions of a non-negative integer.

Compilation flags:
static
Template:
count_partitions(N,Count)
Mode and number of proofs:
count_partitions(+non_negative_integer,-non_negative_integer) - one

count_partitions/3

Counts the number of partitions of a non-negative integer with an exact number of parts.

Compilation flags:
static
Template:
count_partitions(N,K,Count)
Mode and number of proofs:
count_partitions(+non_negative_integer,+non_negative_integer,-non_negative_integer) - zero_or_one

count_distinct_partitions/2

Counts the number of partitions of a non-negative integer into distinct parts.

Compilation flags:
static
Template:
count_distinct_partitions(N,Count)
Mode and number of proofs:
count_distinct_partitions(+non_negative_integer,-non_negative_integer) - one

count_distinct_partitions/3

Counts the number of partitions of a non-negative integer into an exact number of distinct parts.

Compilation flags:
static
Template:
count_distinct_partitions(N,K,Count)
Mode and number of proofs:
count_distinct_partitions(+non_negative_integer,+non_negative_integer,-non_negative_integer) - zero_or_one

nth_partition/3

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

Compilation flags:
static
Template:
nth_partition(N,Index,Partition)
Mode and number of proofs:
nth_partition(+non_negative_integer,+integer,-list) - zero_or_one

nth_partition/4

Returns either the partition at a given zero-based index in the given order (when the second argument is default or lexicographic) or the partition with an exact number of parts at a given zero-based index using default order (when the second argument is an integer).

Compilation flags:
static
Template:
nth_partition(N,KOrOrder,Index,Partition)
Mode and number of proofs:
nth_partition(+non_negative_integer,+atom,+integer,-list) - zero_or_one
nth_partition(+non_negative_integer,+non_negative_integer,+integer,-list) - zero_or_one

nth_partition/5

Returns the partition with an exact number of parts at a given zero-based index in the given order: default or lexicographic.

Compilation flags:
static
Template:
nth_partition(N,K,Order,Index,Partition)
Mode and number of proofs:
nth_partition(+non_negative_integer,+non_negative_integer,+atom,+integer,-list) - zero_or_one

partition_index/3

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

Compilation flags:
static
Template:
partition_index(N,Partition,Index)
Mode and number of proofs:
partition_index(+non_negative_integer,+list,-integer) - zero_or_one

partition_index/4

Returns either the zero-based index of a partition in the given order (when the second argument is default or lexicographic) or the zero-based index of a partition with an exact number of parts using default order (when the second argument is an integer).

Compilation flags:
static
Template:
partition_index(N,KOrOrder,Partition,Index)
Mode and number of proofs:
partition_index(+non_negative_integer,+atom,+list,-integer) - zero_or_one
partition_index(+non_negative_integer,+non_negative_integer,+list,-integer) - zero_or_one

partition_index/5

Returns the zero-based index of a partition with an exact number of parts in the given order: default or lexicographic.

Compilation flags:
static
Template:
partition_index(N,K,Order,Partition,Index)
Mode and number of proofs:
partition_index(+non_negative_integer,+non_negative_integer,+atom,+list,-integer) - zero_or_one

nth_distinct_partition/3

Returns the partition into distinct parts at a given zero-based index using default order.

Compilation flags:
static
Template:
nth_distinct_partition(N,Index,Partition)
Mode and number of proofs:
nth_distinct_partition(+non_negative_integer,+integer,-list) - zero_or_one

nth_distinct_partition/4

Returns either the partition into distinct parts at a given zero-based index in the given order (when the second argument is default or lexicographic) or the partition with an exact number of distinct parts at a given zero-based index using default order (when the second argument is an integer).

Compilation flags:
static
Template:
nth_distinct_partition(N,KOrOrder,Index,Partition)
Mode and number of proofs:
nth_distinct_partition(+non_negative_integer,+atom,+integer,-list) - zero_or_one
nth_distinct_partition(+non_negative_integer,+non_negative_integer,+integer,-list) - zero_or_one

nth_distinct_partition/5

Returns the partition with an exact number of distinct parts at a given zero-based index in the given order: default or lexicographic.

Compilation flags:
static
Template:
nth_distinct_partition(N,K,Order,Index,Partition)
Mode and number of proofs:
nth_distinct_partition(+non_negative_integer,+non_negative_integer,+atom,+integer,-list) - zero_or_one

distinct_partition_index/3

Returns the zero-based index of a partition into distinct parts using default order.

Compilation flags:
static
Template:
distinct_partition_index(N,Partition,Index)
Mode and number of proofs:
distinct_partition_index(+non_negative_integer,+list,-integer) - zero_or_one

distinct_partition_index/4

Returns either the zero-based index of a partition into distinct parts in the given order (when the second argument is default or lexicographic) or the zero-based index of a partition with an exact number of distinct parts using default order (when the second argument is an integer).

Compilation flags:
static
Template:
distinct_partition_index(N,KOrOrder,Partition,Index)
Mode and number of proofs:
distinct_partition_index(+non_negative_integer,+atom,+list,-integer) - zero_or_one
distinct_partition_index(+non_negative_integer,+non_negative_integer,+list,-integer) - zero_or_one

distinct_partition_index/5

Returns the zero-based index of a partition with an exact number of distinct parts in the given order: default or lexicographic.

Compilation flags:
static
Template:
distinct_partition_index(N,K,Order,Partition,Index)
Mode and number of proofs:
distinct_partition_index(+non_negative_integer,+non_negative_integer,+atom,+list,-integer) - zero_or_one

random_partition/2

Returns a random partition of a non-negative integer.

Compilation flags:
static
Template:
random_partition(N,Partition)
Mode and number of proofs:
random_partition(+non_negative_integer,-list) - one

random_partition/3

Returns a random partition of a non-negative integer with an exact number of parts.

Compilation flags:
static
Template:
random_partition(N,K,Partition)
Mode and number of proofs:
random_partition(+non_negative_integer,+non_negative_integer,-list) - zero_or_one

sample_partitions/3

Returns SampleCount random partitions of a non-negative integer, sampled with replacement.

Compilation flags:
static
Template:
sample_partitions(N,SampleCount,Samples)
Mode and number of proofs:
sample_partitions(+non_negative_integer,+non_negative_integer,-list) - zero_or_one

sample_partitions/4

Returns SampleCount random partitions of a non-negative integer with an exact number of parts, sampled with replacement.

Compilation flags:
static
Template:
sample_partitions(N,K,SampleCount,Samples)
Mode and number of proofs:
sample_partitions(+non_negative_integer,+non_negative_integer,+non_negative_integer,-list) - zero_or_one

random_distinct_partition/2

Returns a random partition of a non-negative integer into distinct parts.

Compilation flags:
static
Template:
random_distinct_partition(N,Partition)
Mode and number of proofs:
random_distinct_partition(+non_negative_integer,-list) - one

random_distinct_partition/3

Returns a random partition of a non-negative integer with an exact number of distinct parts.

Compilation flags:
static
Template:
random_distinct_partition(N,K,Partition)
Mode and number of proofs:
random_distinct_partition(+non_negative_integer,+non_negative_integer,-list) - zero_or_one

sample_distinct_partitions/3

Returns SampleCount random partitions of a non-negative integer into distinct parts, sampled with replacement.

Compilation flags:
static
Template:
sample_distinct_partitions(N,SampleCount,Samples)
Mode and number of proofs:
sample_distinct_partitions(+non_negative_integer,+non_negative_integer,-list) - zero_or_one

sample_distinct_partitions/4

Returns SampleCount random partitions of a non-negative integer with an exact number of distinct parts, sampled with replacement.

Compilation flags:
static
Template:
sample_distinct_partitions(N,K,SampleCount,Samples)
Mode and number of proofs:
sample_distinct_partitions(+non_negative_integer,+non_negative_integer,+non_negative_integer,-list) - zero_or_one

next_partition/3

Returns the next partition value of a non-negative integer in lexicographic order.

Compilation flags:
static
Template:
next_partition(N,Partition,Next)
Mode and number of proofs:
next_partition(+non_negative_integer,+list,-list) - zero_or_one

next_partition/4

Returns the next partition value of a non-negative integer with an exact number of parts in lexicographic order.

Compilation flags:
static
Template:
next_partition(N,K,Partition,Next)
Mode and number of proofs:
next_partition(+non_negative_integer,+non_negative_integer,+list,-list) - zero_or_one

previous_partition/3

Returns the previous partition value of a non-negative integer in lexicographic order.

Compilation flags:
static
Template:
previous_partition(N,Partition,Previous)
Mode and number of proofs:
previous_partition(+non_negative_integer,+list,-list) - zero_or_one

previous_partition/4

Returns the previous partition value of a non-negative integer with an exact number of parts in lexicographic order.

Compilation flags:
static
Template:
previous_partition(N,K,Partition,Previous)
Mode and number of proofs:
previous_partition(+non_negative_integer,+non_negative_integer,+list,-list) - zero_or_one

next_distinct_partition/3

Returns the next partition-into-distinct-parts value of a non-negative integer in lexicographic order.

Compilation flags:
static
Template:
next_distinct_partition(N,Partition,Next)
Mode and number of proofs:
next_distinct_partition(+non_negative_integer,+list,-list) - zero_or_one

next_distinct_partition/4

Returns the next partition-into-distinct-parts value of a non-negative integer with an exact number of parts in lexicographic order.

Compilation flags:
static
Template:
next_distinct_partition(N,K,Partition,Next)
Mode and number of proofs:
next_distinct_partition(+non_negative_integer,+non_negative_integer,+list,-list) - zero_or_one

previous_distinct_partition/3

Returns the previous partition-into-distinct-parts value of a non-negative integer in lexicographic order.

Compilation flags:
static
Template:
previous_distinct_partition(N,Partition,Previous)
Mode and number of proofs:
previous_distinct_partition(+non_negative_integer,+list,-list) - zero_or_one

previous_distinct_partition/4

Returns the previous partition-into-distinct-parts value of a non-negative integer with an exact number of parts in lexicographic order.

Compilation flags:
static
Template:
previous_distinct_partition(N,K,Partition,Previous)
Mode and number of proofs:
previous_distinct_partition(+non_negative_integer,+non_negative_integer,+list,-list) - zero_or_one

Protected predicates

(none)

Private predicates

(none)

Operators

(none)