PublicShow sourcecount.pl -- This module provides various ways to count solutions

This module is based on a similar collection introduces in the first ClioPatria release. Most names have been changed to describe the semantics more accurately.

The predicates in this library provide space-efficient solutions, avoiding findall/setof. Most predicates come with a variant that allows limiting the number of answers.

To be done
- The current implementation is often based on library(nb_set), which implements unbalanced binary trees. We should either provide a balanced version or use Paul Tarau's interactors to solve these problems without destructive datastructures.
Source proof_count(:Goal, -Count) is det
Source proof_count(:Goal, +Max, -Count) is det
True if Count is the number of times Goal succeeds. Note that this is not the same as the number of answers. E.g, repeat/0 has infinite proofs that all have the same -empty- answer substitution.
See also
- answer_count/3
Source answer_count(?Var, :Goal, -Count) is det
Source answer_count(?Var, :Goal, +Max, -Count) is det
Count number of unique answers of Var Goal produces. Enumeration stops if Max solutions have been found, unifying Count to Max.
Source answer_set(?Var, :Goal, -SortedSet) is det
Source answer_set(?Var, :Goal, +MaxResults, -SortedSet) is det
SortedSet is the set of bindings for Var for which Goal is true. The predicate answer_set/3 is the same as findall/3 followed by sort/2. The predicate answer_set/4 limits the result to the first MaxResults. Note that this is not the same as the first MaxResults from the entire answer set, which would require computing the entire set.
Source answer_pair_set(Var, :Goal, +MaxKeys, +MaxPerKey, -Group)
Bounded find of Key-Value pairs. MaxKeys bounds the maximum number of keys. MaxPerKey bounds the maximum number of answers per key.
Source unique_solution(:Goal, -Solution) is semidet
True if Goal produces exactly one solution for Var. Multiple solutions are compared using =@=/2. This is semantically the same as the code below, but fails early if a second nonequal solution for Var is found.
findall(Var, Goal, Solutions), sort(Solutions, [Solution]).
Source proof_count(:Goal, -Count) is det
Source proof_count(:Goal, +Max, -Count) is det
True if Count is the number of times Goal succeeds. Note that this is not the same as the number of answers. E.g, repeat/0 has infinite proofs that all have the same -empty- answer substitution.
See also
- answer_count/3
Source answer_count(?Var, :Goal, -Count) is det
Source answer_count(?Var, :Goal, +Max, -Count) is det
Count number of unique answers of Var Goal produces. Enumeration stops if Max solutions have been found, unifying Count to Max.
Source answer_set(?Var, :Goal, -SortedSet) is det
Source answer_set(?Var, :Goal, +MaxResults, -SortedSet) is det
SortedSet is the set of bindings for Var for which Goal is true. The predicate answer_set/3 is the same as findall/3 followed by sort/2. The predicate answer_set/4 limits the result to the first MaxResults. Note that this is not the same as the first MaxResults from the entire answer set, which would require computing the entire set.