The fundamental units of Prolog syntax are: atoms, variables, numbers, and structures [4]. They are known as terms. An atom begins with a lowercase letter and can contain letters, digits or the underscore. If an atom is enclosed in single quotes it does not have to begin with a lowercase letter.
A structure is an atom, or consists of: an atom, the opening parenthesis, one or more arguments, and the closing parenthesis. The arguments are structures. The atom at the beginning is called the functor of the structure. If there are arguments which are structures, the atom at the very beginning is called the principal functor. Variables begin with a capital letter or underscore and consist of letters, digits, and underscores.
Knowledge in Prolog is represented by predicates. A predicate is a structure which is analogous to a relation in the Relational Model (see Section 3.1). This is a prototype (or a model) which should be filled with data. A predicate is identified uniquely by a pair: its name, which is a functor, and number of arguments, which is called arity. It is usually denoted as: name/arity (it is analogous to Datalog, see Chapter 4). Each single, atomic fact or rule is given as a clause of the certain predicate. Knowledge is stored in two ways: as simple clauses and complex ones.
A simple clause represents a fact. There could be many simple clauses of a single predicate which are similar to many tuples in a single relation. Simple clauses define Extensional Knowledge.
An example of family relationships is given in Figure 6.1. There are seven simple clauses of predicate parent/2. The first clause denotes that james is john's parent, the second one denotes that james is mary's parent, and so on.
A complex clause describes relationships in knowledge, thus it provides Intensional Knowledge. Such a clause is a structure or set of structures which form a logical expression. It consists of a head and body. The head is a conclusion. The body contains preconditions. These structures are valid predicates which are defined by simple or complex clauses. Complex clauses could also use build-in predicates, which provide for example logical and arithmetical operations.
Figure 6.2 shows complex claues which provide Intensional Knowledge regarding family relationships such as: a sibling and cousin.
A comma stands for logical AND, \==
stands for not equal.
Complex clauses may be recursive, as it is shown for the last clause in Figure 6.2.
There is also a logical OR operator which is denoted by a semicolon (;), but it is rarely used. A logical OR in a single rule may be replaced by two rules, which provides simpler, more readable syntax. The clause cousin/2 from Figure 6.2 may be expressed with a logical OR. The result is given in Figure 6.3. Parentheses enforce operator precedence.
Prolog introduces also a negation predicate. It is denoted as + (some Prolog dialects use not/1) and called negation as failure. A negative fact cannot be stated in Prolog. But the negation predicate can be used in the body of a complex clause to limit already instantiated variables (for the instantiation see Section 6.2). It cannot be used for the instantiation. For more details see [4].
Simple and complex clauses form a complete Prolog program, which is a Logic Program. Both simple and complex clauses are based on Horn Clauses (see Chapter 4).
Igor Wojnicki 2005-11-07