The aggregate predicates take a set of solutions and compute an
aggregate on it. The predicate aggregate_all/3 aggregates the
solution that is produced by findall/3. The predicate aggregate/3
respectively sys_collect/3 aggregates the solutions that are
produced by bagof/3 respectively sys_heapof/3.
Y = 4,
R = (5,1) ;
Y = 1,
R = (5,2)
The implementation of aggregate_all/3 takes advantage of pivots introduced in the module sequence. The other aggregate predicates take advantage of a map from variant terms to pivots. The memory usage is therefore proportional to the number of variant terms.
The following aggregate predicates are provided:
count: The result is the number of solutions.
sum(X): The result is the sum of the X values.
mul(X): The result is the product of the X values.
min(X): The result is the minimum of the X values.
max(X): The result is the maximum of the X values.
(A,B): The result is the pairing of the aggregate A and B.