I had a quick question re. existential qualifier using setof in prolog (i.e. ^).
using SICStus it seems that (despite what a number of websites claim), S does indeed appear to be quantified in the code below (using the bog standard, mother of / child of facts, which i havent included here):
child(M,F,C) :- setof(X,(mother(S,X)),C).
i check the unification using:
child(M,F,C) :- setof(X-S,(mother(S,X)),C).
so the following code, with the existential operator seem to make no difference:
child(M,F,C) :- setof(X,S^(mother(S,X)),C).
Any ideas why this is? What would be a situation where you would need the unifier then?
thanks!
Ok, I'm not sure I can explain it perfectly, but let me try.
It has to do with the fact that you are querying over a 2-ary relation,
mother/2
. In that case usingX-S
as the template has a similar effect on the result setC
as usingS^
in front of the goal. InX-S
you are using both variables in the template, and therefore each possible binding of X and S is included in C. You get the same effect usingS^
in front of the goal, as this is saying "ignore bindings of S when constructing the result".But the difference between the two becomes clearer when you query over a 3-ary relation. The SWI manual has this example:
Now do similar queries as in your example
and
and you get different results.
It's not just checking unification,
X-Z
effectively changes your result set.Hope that helps.
Edit: Maybe it clarifies things when I include the results of the two queries above. The first one goes like this:
The second one yields: