I am baffled by the following results. I am using SWI-Prolog.
?- bagof(Q, (Q=A, (A=[a,_] ; A=[_,b])), X).
A = [_G16898, b],
X = [[_G16898, b]] ;
A = [a, _G16892],
X = [[a, _G16892]].
Notice that [a,_]
and [_,b]
are not unified to produce an answer A = [a,b], X=[[a,b],[a,b]]
.
Now, lets try the same with arithmetic constraints:
?- bagof(Q, (Q=A, (A in 1..5 ; A in 3..8)), X).
X = [A, A],
A in 3..5.
Strangely, this time the arithmetic constraints are taken together but there are no answers A in 1..5, X=[A]
and A in 3..8, X=[A]
.
Now lets try this in yet another way:
?- bagof(Q, (Q=A, ((1 #=< A, A #=< 5) ; (3 #=< A, A #=< 8))), X).
X = [A],
A in 3..5 ;
X = [A],
A in 3..5.
The arithmetic constraints are combined like before, but we have two answers instead of one.
How can all this be explained?
EDIT: Some more strange results. Compare this:
?- A=[_,_], bagof(Q, K1^K2^(Q=A, (A=[a,K1] ; A=[K2,b])), X).
A = [_G16886, b],
X = [[_G16886, b]] ;
A = [a, _G16889],
X = [[a, _G16889]].
with this:
?- A=[a,b], bagof(Q, K1^K2^(Q=A, (A=[a,K1] ; A=[K2,b])), X).
A = [a, b],
X = [[a, b], [a, b]].