count.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.
- proof_count(:Goal, -Count) is det
- 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.
- answer_count(?Var, :Goal, -Count) is det
- 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.
- answer_set(?Var, :Goal, -SortedSet) is det
- 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.
- 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.
- 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]).
- proof_count(:Goal, -Count) is det
- 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.
- answer_count(?Var, :Goal, -Count) is det
- 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.
- answer_set(?Var, :Goal, -SortedSet) is det
- 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.