Prolog is a general purpose logic programming language associated with artificial intelligence and computational linguistics (Wikipedia Definition @ http://en.wikipedia.org/wiki/Prolog).
Prolog, LISP and many other languages depend on logic syntax and are represented as facts and rules. If you have any experience in programming using languages such as C#, JAVA or C++, then you need to change the way that you are using to write your codes.
How to start?
First of all, you need to download some tools to execute your commands; one of them is Amzi Development Environment. You can find it here: http://www.amzi.com/
What you have to do is just to open new file and write down your commands, then from Listener->Start you can start execute your code.
As we said in the beginning of this lesson, prolog depends on logical relationships, like:
This means that Ahmed and Khaled are humans. And Toyota is a car.
Let’s test those three lines; go to Listener -> Start then Listener -> Consult.
And in execution window, type the following question:
Here we ask to show all humans and put it in array named V, you can press enter to quit or “;” to continue.
*** Note: (V) must be capital. All variables in Prolog must be capital.
The second type of questions is the Yes/No questions, like this:
And you will get the answer depending on if you have added Ahmed to humans or not.
In addition to previous, we can describe relationships between two items:
So if we ask the engine this question:
We will have all Ahmed's sons in U list.
That is the point where we will start get benefit from prolog, this is the way that human brain works when thinking. For example (all cars have a door and all planes also):
Then let's declare some planes and cars:
If we ask if mazda have a door or not, prolog engine will be smart enough to answer with yes.
More about Prolog:
This is just simple introduction to Prolog. There are a lot of features in Prolog you can start with from this link:
Einstein Problem, one of the famous puzzles. Where the puzzle author (Einstein or anybody else) said that 98% of peoples can’t solve this problem:
There are 5 houses sitting next to each other, each with a different color, occupied by 5 guys, each from a different country, and with a favorite drink, cigarette, and pet. Here are the facts:
The Brit lives in the red house
The Swede keeps dogs as pets.
The Dane drinks tea
The green house is on the left of the white house
The green house's owner drinks coffee
The person who smokes Pall Mall rears birds
The owner of the yellow house smokes Dunhill
The man living in the center house drinks milk
The Norwegian lives in the first house
The man who smokes Blends lives next to the one who keeps cats
The man who keeps horses lives next to the man who smokes Dunhill
The owner who smokes Bluemaster drinks beer
The German smokes Prince
The Norwegian lives next to the blue house
The man who smokes Blend has a neighbor who drinks water
The question is: Who owns the fish?
If we try to translate this problem into Prolog group of facts, rules and relationships, it will be like this:
Then if you ask prolog this question:
You will have the right solution, try to use your mind to solve it and correct it with Prolog solution, if your answer not German, so you are Candidate to join the 98% club. It is not so bad :)