We start with two types of simple entities, variables and constants. The convention is that variables start with a capital letter--X, Y, Name, ..., while constants start with a lower case letter--ball, node, graph, a, b, ....
Constants are, in general, ``uninterpreted''--that is, they are not further organized into types like Char and Float with underlying meaning. However, for convenience, we will allow ourselves to use natural numbers as a special type of constant and compute arithmetic expressions over these numbers.
A Prolog program defines a relation through facts and rules. For instance, consider a directed graph with five nodes.
We can represent its edge relation using the following facts.
edge(3,4). edge(4,5). edge(5,1). edge(1,2). edge(3,5). edge(3,2).
Each fact just lists out explicitly a concrete tuple that belongs to the relation edge.
We can now define another relation path using a set of rules, as follows:
path(X,Y) :- edge(X,Y). path(X,Y) :- edge(X,Z), path(Z,Y).
These rules are to be read as follows:
Thus, each rule is of the form ``Conclusion if Premise and Premise ...and Premise''. This special type of logical formula is called a Horn Clause. In Prolog, the ``if'' is written as :- and the ands on the right hand side are written as commas. The left hand side of a rule is called the goal.
Notice the implicit quantification of variables--variables that appear in the goal are universally quantified (for example, X and Y above) while variables that appear in the premises are existentially quantified (for example, Z above).