File "aggregate"
This a faster implementation of partly from ISO core standard and
of partly the corresponding SICStus predicates.What is covered by
the ISO core standard are the predicates bagof/3 and setof/3. The
notion of a existentially quantified goal is also already present
in the ISO core standard. Our implementation is faster since we
use a hash table underneath.
Example:
p(5).
p(2).
p(3).
?- aggregate_all((sum(X),count),p(X),R).
R = (10, 3).
The following aggregate predicates are provided:
- bagof(T, Q, L): [ISO 8.10.2]
- The predicate determines all the solutions to the quantified
goal Q, whereby collecting copies of the template T and the
witness to the quantified goal Q. The predicate then repeatedly
succeeds for the witness and the list of associated templates in
L.
- setof(T, Q, L): [ISO 8.10.3]
- The predicate determines all the solutions to the quantified
goal Q, whereby collecting copies of the template T and the
witness to the quantified goal Q. The predicate then repeatedly
succeeds for the witness and the set of associated templates in
L.
- aggregate_all(A, G, R):
- The predicate aggregates A for the solutions of the goal G and
unifies the result with R. Works like findall/3, without witness
grouping. The following aggregates are supported:
count: Returns the solution count.
- sum(X): Returns the sum of X.
- mul(X): Returns the product of X.
- min(X): Returns the minimum of X.
- max(X): Returns the maximum of X.
- bag(X): Returns the list of X.
set(X): Returns the sorted list of X.
- (F,G): Returns the pair of the aggregate functions F and G.
- aggregate(A, Q, R):
- The predicate aggregates A for the solutions of the quantified
goal Q and unifies the result with R. Works like bagof/3, with
witness grouping.
Kommentare