Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How will Prolog interpret this?

Tags:

prolog

How will prolog interpret this expression?

a(R) :- b(R,S), b(S,R).

Does this mean that a(R) will only return true if both b(R,S) and b(S,R) are true?

like image 974
Veronica Avatar asked Dec 04 '25 17:12

Veronica


1 Answers

a(R) will only return true if both b(R,S) and b(S,R) are true?

Yes. The comma is a logical and. The rule:

a(R) :- b(R,S), b(S,R)

can thus be explained as:

"a(R) holds given there exists an S such that b(R, S) holds, and b(S, R) holds".

If for example you have a dataset like:

b(a, c).
b(a, d).
b(c, a).
b(b, c).

Then it will succeed for a(a), since b(a, c) holds and b(c, a). But it will not succeed for a(b), since b(b, c) holds, but not b(c, b).

like image 157
Willem Van Onsem Avatar answered Dec 06 '25 08:12

Willem Van Onsem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!