# Forall/2 not what you might expect

**URL:** <https://swi-prolog.discourse.group/t/forall-2-not-what-you-might-expect/4038>\
**Category:** Nice to know\
**Created:** [June 7, 2021, 4:50pm UTC](https://swi-prolog.discourse.group/t/forall-2-not-what-you-might-expect/4038 "2021-06-07T16:50:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [June 7, 2021, 4:50pm UTC](https://swi-prolog.discourse.group/t/forall-2-not-what-you-might-expect/4038/1 "2021-06-07T16:50:51Z")

</div>

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

```prolog
?- forall(false,true).
true.

```

So ran the other variations and now it makes sense; think [material conditional](https://en.wikipedia.org/wiki/Material_conditional)

```prolog
?- forall(true,false).
false.

?- forall(false,false).
true.

?- forall(true,true).
true.

```

Some more food for thought.

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

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

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

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

```

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

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

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

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

```

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

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

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

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

```

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

```

---

<div class="post-metadata">

**Author:** ![michaelby](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@michaelby](https://swi-prolog.discourse.group/u/michaelby)\
**Post date:** [June 8, 2021, 8:44am UTC](https://swi-prolog.discourse.group/t/forall-2-not-what-you-might-expect/4038/2 "2021-06-08T08:44:11Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![grossdan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/grossdan/32/23_2.png) [@grossdan](https://swi-prolog.discourse.group/u/grossdan)\
**Post date:** [June 8, 2021, 9:23am UTC](https://swi-prolog.discourse.group/t/forall-2-not-what-you-might-expect/4038/4 "2021-06-08T09:23:57Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Boris](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/boris/32/7486_2.png) [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Post date:** [June 8, 2021, 10:55am UTC](https://swi-prolog.discourse.group/t/forall-2-not-what-you-might-expect/4038/6 "2021-06-08T10:55:52Z")

</div>

No, this is about findall most probably

---

<div class="post-metadata">

**Author:** ![grossdan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/grossdan/32/23_2.png) [@grossdan](https://swi-prolog.discourse.group/u/grossdan)\
**Post date:** [June 8, 2021, 10:57am UTC](https://swi-prolog.discourse.group/t/forall-2-not-what-you-might-expect/4038/7 "2021-06-08T10:57:26Z")

</div>

@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.

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

```
