Reputation: 3736
In clingo you can use aggregates, such as #min
, #max
and #sum
. I assume there is no aggregate for products, so how would I implement a product for varying number of atoms? Preferably without introducing aux predicates. Example:
total(1,4).
total(2,8).
total(3,9).
I'm searching for a functionality which outputs 288
, since 4*8*9 = 288
.
Upvotes: 0
Views: 97
Reputation: 2662
One solution is the following, but it uses auxiliary predicates. Maybe it can be improved...
total(1,4).
total(2,8).
total(3,9).
n(1..N-2):- N = #count{K : total(K,_)}.
prod(0,P):- total(1,P0), total(2,P1), P = P0*P1.
prod(N,P):- n(N), prod(N-1,P0), total(N+2,P1), P = P0*P1.
yielding
total(1,4) total(2,8) total(3,9) n(1) prod(0,32) prod(1,288)
Upvotes: 0