Linguistics 482 - Computational Linguistics Prolog Notes A. C. Brett acbrett@uvic.ca
Department of Linguistics
University of Victoria
Clearihue C139
Last updated: 20 October 2005

Operators

Operators are special Prolog structures that have operator signs as their names. Since they are structures, operators are word-like entities in the Prolog language.

The Prolog interpreter treats operator signs as special atoms that can be the names of structures. Operators can be represented according to the customary format for structures, that is, by writing the structure name followed by its arguments, with these being enclosed in parentheses and separated by commas. Thus, an operator can be represented as

   op_sign(op1, op2)
where the operator sign, op_sign, is followed by its operands, op1 and op2.

For example, the name of the addition operator is the plus sign, "+". The operands of the addition operator, that is, the numbers that are to be added together, are the arguments of the structure named by the plus sign. Hence, the addition of two numbers, such as 3 and 4, can be represented as follows:

   +(3, 4)
The arguments or operands of an arithmetic operator such as addition must, of course, be numbers.

The representation of an operator with the operator sign preceding its operands is described as prefix notation or format. The Prolog interpreter also permits operator structures with two arguments to be represented in an infix format, that is, with the operator sign between its operands. Thus, the addition of two numbers such as 3 and 4 can be represented in the more familiar format as

   3 + 4
When one undertakes an arithmetic operation such as addition, one normally requires access to the result. Conventional use sees the equal sign, "=", being employed as an operator to direct or assign the result of an arithmetic operation. In most dialects of Prolog, however, the equal sign names the unification operator. The arithmetic assignment operation is performed by a system predicate with the name is. The is/2 predicate can be used in infix format. Thus, a query such as the following:
   X is 3 + 4.
which might be translated into English as "What is the sum of 3 an 4?", will cause the sum of 3 and 4 to be instantiated on the variable X. (Note that the period following the number 4 in the foregoing query is not a decimal point; it is the period that must end all Prolog clauses and queries.)

Further information about Prolog operators is available under the Terms topic in the Amzi! Prolog Language Reference, which is accessible through the Logic Explorer help system. There is also information under the Manipulating Terms topic of the Language Reference about such operators as the term equality operator. See the Equality of Terms section. Also, see the Comparison of Terms section under the same topic for descriptions of the operators that represent relationships between terms such as less than and less than or equal to which have the operator signs @< and @=<, respectively.

Linguistics 482 Prolog Introductory Notes Top of Page