datalogclingo

Preventing symetric pairs in datalog logic


I am running a datalog rule with clingo in jupyter notebook against graph nodes checking for nodes that share the same direct ancestor as follows:

ancestor(A,B).
ancestor(A,C).
sibs(X,Y) = ancestor(Z,X), ancestor(Z,Y), X!=Y.

This gives me 2 simetric pairs namely

sibs(B,C) sibs(C,B)

How to I restrict the generation of sibs to only have either of these two results?


Solution

  • Managed to track down the issue. To ensure you do not return both results change this:

    sibs(X,Y) = ancestor(Z,X), ancestor(Z,Y), X!=Y.

    to this:

    sibs(X,Y) = ancestor(Z,X), ancestor(Z,Y), X<Y.