Articles 16
Tags 19

PROLOG - Part 6

“Logic: The art of thinking and reasoning in strict accordance with the limitations and incapacities of the human misunderstanding.” Ambrose Bierce

Power PROLOG \o/

In my last post we finally wrote our “Hello World!” in PROLOG. I hope you all bare with me, so we can finally start to explore the fun and powerful features of PROLOG. In this post, I am going to write about Backtracking.


When PROLOG is looking for instances that satisfies a clause, it will, whenever it is needed, perform what we call Backtrack.

PROLOG - Part 5

Against logic there is no armor like ignorance.


Until the last post, we saw how to build rules and query facts. But all we can see as “answer” until now are some ‘yes’ or ‘false’. Pretty boring hum… But as in other languages, PROLOG also offers I/O support: please meet the methods read() and write().

Finally our PROLOG “Hello world!”

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 clauses. In this post I am giving an introduction 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!

PROLOG - Part 3

Logic will get you from A to B. Imagination will take you everywhere.

More theory …

After last post theoretical questions were open and the time for the writing was out. I will try to answer some of them now =)

First order logic and Unification

First-order logic (FOL) or also called predicate logic has one or more arguments for each predicate and utilizes quantifiers (“for all” and “at least one”). First-order logic is simple but enough to formalize all classic mathematics. A first-order theorem, for example, consists in a set of axioms and sentences that we can reduce from them.

PROLOG is based on FOL and for that, in PROLOG one has the first-order unification algorithm implicit. Unification in logic is nothing more than an algorithmic process to solve systems of symbolic expressions. The solution of an unification problem is like a map of symbolic values for each variable in the system.

PROLOG - Part 2

PROLOG was created in 1972 and it has been used since then, mostly in relational databases, natural languages comprehension and automation.

Continuing …

Continuing from the last post, I will again start with some theory before continuing to write our family code.

Logical programming

In logical programming, we are focused on knowledge and not in the algorithms. That is also why the code sometimes looks like a database. This programming paradigm (which one could also include PROLOG) is based on formal logic, more specific based on predicate logic.

This means that PROLOG has a set of sentences in logic form, called clauses. All clauses that we wrote in the last post are facts. They are the simplest type of clauses, also known as Horn clauses.