How to sum all rather than just distinct values in clingo?

Viewed 222

The following code produces x(3) rather than x(4) because it adds 1 and 2 together even though 1 appears twice. What is the right way of obtaining total sums in clingo?

p(0,1;1,1;2,2).
x(X) :- X = #sum { Y: p(_,Y) }.
1 Answers

Still not quite sure why this works but it does:

x(X) :- X = #sum { Y, Z: p(Z,Y) }.

So, it seems you have to write out the entire "unique key" but only the first value is summed up. I don't this explained or even mentioned in the documentation.

Related