Linguistics 482 - Computational Linguistics Prolog Notes A. C. Brett
Department of Linguistics
University of Victoria
Clearihue C139
Last updated: 2 November 2000


Numbers are morpheme-like entities in Prolog which carry the meaning that we normally ascribe to numbers; that is, they can be used to count things and they can be used to represent the results of measurement processes. The numbers normally used to count things are called integers, but they can also include negative quantities, while the numbers that usually result from measurements are called floating point numbers. These two varieties of numbers are distinguished because they are often represented and processed differently by the computer. They are also represented differently in a Prolog program.


The following numbers represent integers:
Note that the negative sign, -, must immediately precede the number it is marking as negative; otherwise, if there is a space, the sign is construed by the interpreter as representing the subtraction operator.

Floating Point Numbers

Floating point numbers are usually used to represent fractional quantities such as the following:
Note that numbers between 0.0 and 1.0 must be represented with a zero digit preceding the decimal point. Also, if an integer is to be represented as a floating point number, then there must be a zero digit following the decimal point.

Floating point numbers may also be represented using an exponential notation such as is shown in the following examples.

where E+10 in the first example means that the number preceding it is to be multiplied by 10 raised to the power 10.


Most dialects of Prolog support arithmetic operations, with the arithmetic operators being represented by the symbols +, -, *, and / corresponding to the addition, subtraction, multiplication, and division operations, respectively. The equal sign, =, however, is associated with an operation that is not connected with arithmetic so that a system predicate with the name is is used in its place, as illustrated in the following examples:
   X is 3 + 4 .  % X is (instantiated with) the sum of 3 and 4 .
   X is 3 - 4 .  % X is (instantiated with) the difference of 3 and 4 .
   X is 3 * 4 .  % X is (instantiated with) the product of 3 and 4 .
   X is 3 / 4 .  % X is (instantiated with) the division of 3 by 4 .
Thus, arithmetic expressions are represented with the operator sign in an infix position relative to its operands; that is, it appears between, and splits the numbers operated upon.

Arithetic expressions can also be written with the operator sign in the prefix position as follows:

   X is +(3, 4).
   X is *(3, 4).
which is close to a verbatim translation of English sentences such as "X is the sum of 3 and 4" with "the sum" translated as the operator sign, +, "of" translated as the left parenthesis, (, and with "and" translated as a comma.

The prefix position of the operator sign is also consistent with the position of the principal functor name relative to its arguments in the representation of a Prolog structure. In this connection, note that the arithmetic operator signs are actually special atoms that name system predicates which perform the arithmetic operations.
Linguistics 482 Prolog Introductory Notes Top of Page