barbie's notes - PROLOG - Part 4

“Bad reasoning as well as good reasoning is possible; and this fact is the foundation of the practical side of logic.”” Charles Sanders Peirce

Including rules

Until the last post, we have been working with simple clausels. In this post I am introducting the concept of rules.

Back to our family example

Right now we have a list of parents. If we want, we can also implement the same list for children, exchanging the order of the names inside the property. OR we can do it a bit better: Using rules!

Defining children in a PROLOGish way, we think in logic: if X is parent of Y then Y is children of X. In PROLOG :- parent(X,Y). ```. We add this line to our family.pl code.

1234567891011

It's important to notice the differences between facts and rules in PROLOG. Facts are always ```true``` and rules become ```true```, if and only if the conditions are satisfied. On the left side you have the _head_ of the rule, that describes the conclusion and on the right side you have the _body_ of the rule, which lists the conditions to be meet. Now we can ask PROLOG if Ismail is Abe's son like that:```bash?- consult("family.pl").true.?- children(ismail, abe).true.?-

Using the same idea, it’s possible to define mother as following: . This means that if X is female and parent of Y, then X is mother of Y. Adding this line to our family.pl file we can ask PROLOG more questions: