Noeud: Arithmetic, Noeud « Next »: , Noeud « Previous »: Input / Output, Noeud « Up »: Built-In Predicates



Arithmetic

Arithmetic is performed by built-in predicates which take as arguments arithmetic expressions and evaluate them. An arithmetic expression is a term built from numbers, variables, and functors that represent arithmetic functions. At the time of evaluation, each variable in an arithmetic expression must be bound to a non-variable expression. An expression evaluates to a number, which may be an integer.

Only certain functors are permitted in an arithmetic expression. These are listed below, together with an indication of the functions they represent. X and Y are assumed to be arithmetic expressions. Unless stated otherwise, the arguments of an expression may be any numbers.

+(X)
The value is X.
-X
The value is the negative of X.
X+Y
The value is the sum of X and Y.
X-Y
The value is the difference of X and Y.
X*Y
The value is the product of X and Y.
X//Y
The value is the integer quotient of X and Y.
X mod Y
The value is the integer remainder after dividing X by Y, i.e. integer(X)-integer(Y)*(X//Y).
X/\Y
The value is the bitwise conjunction of the integers X and Y.
X\/Y
The value is the bitwise disjunction of the integers X and Y.
X#Y
The value is the bitwise exclusive or of the integers X and Y.
\(X)
The value is the bitwise negation of the integer X.
X<<Y
The value is the integer X shifted left by Y places.
X>>Y
The value is the integer X shifted right by Y places.
abs(X)
The value is the absolute value of X.
min(X,Y)
The value is the lesser value of X and Y.
max(X,Y)
The value is the greater value of X and Y.

Arithmetic expressions, as described above, are just data structures. If you want one evaluated you must pass it as an argument to one of the built-in predicates listed below. Note that it only evaluates one of its arguments, whereas all the comparison predicates evaluate both of theirs. In the following, X and Y stand for arithmetic expressions, and Z for some term.

Z is X
X, which must be an arithmetic expression, is evaluated and the result is unified with Z.
X =:= Y
The numeric values of X and Y are equal.
X =\= Y
The numeric values of X and Y are not equal.
X < Y
The numeric value of X is less than the numeric value of Y.
X > Y
The numeric value of X is greater than the numeric value of Y.
X =< Y
The numeric value of X is less than or equal to the numeric value of Y.
X >= Y
The numeric value of X is greater than or equal to the numeric value of Y.