Rules


Rules allow us to make conditional statements about our world. Each rule can have several variations, called clauses. These clauses give us different choices about how to perform inference about our world. Consider
     “All men are mortal.”
We can express this as the following Prolog rule
     mortal( X ) :- human( X ).
The clause can be read in two ways (called either a declarative or a procedural interpretation). The declarative interpretation is “For a given X, X is mortal if X is human.” The procedural interpretation is “To prove the main goal that X is mortal, prove the subgoal that X is human.”

Rule II
To continue our previous example, lets us define the fact “Socrates is human” so that our program now looks as follows:
     mortal( X ) :- human( X ).
     human( socrates ).
If we now pose the question to Prolog
     ?- mortal( socrates ).
The Prolog interpreter would respond as follows:
     yes
In order to prove someone mortal, we had to prove them to be human. Thus from the goal Prolog generates the subgoal of showing human(socrates). We were able to match human(socrates) against the database. In Prolog we say that the subgoal succeeded, and as a result the overall goal succeeded. We know when this happens because Prolog prints yes.