Forall/2 not what you might expect

In trying to better understand forall/2 tried the following query and was a bit surprised by the result.

?- forall(false,true).
true.

So ran the other variations and now it makes sense; think material conditional

?- forall(true,false).
false.

?- forall(false,false).
true.

?- forall(true,true).
true.

Some more food for thought.

?- forall(true,(true;true)).
true.

?- forall(true,(true;false)).
true.

?- forall(true,(false;true)).
true.

?- forall(true,(false;false)).
false.
?- forall((true;true),true).
true.

?- forall((true;false),true).
true.

?- forall((false;true),true).
true.

?- forall((false;false),true).
true.
?- forall((true;true),false).
false.

?- forall((true;false),false).
false.

?- forall((false;true),false).
false.

?- forall((false;false),false).
true.
?- forall((true;false),(true;false)).
true.

I think it’s worth keeping the definition in mind:

forall(A, B) :- \+ (A, \+ B).
2 Likes

Btw, in terms of failure vs. empty list result semantics:

O’Keefe has a section on forall vs. setof – and why setof without results should fail rather than return an empty list – as forall does.

Edit:

I meant chapter 11 “All Solutions” in the Crafts of Prolog book (p355).

No, this is about findall most probably

1 Like

@Boris

Absolutely, right – I confused them …

Edit:

This now explains to me why I felt something missing when briefly glancing at the expanded term – the list aspect.

forall(A, B) :- \+ (A, \+ B).