Noeud: Arithmetic, Noeud « Next »: Comparison of Terms, Noeud « Previous »: Input / Output, Noeud « Up »: Built-In Predicates
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)
-X
X+Y
X-Y
X*Y
X//Y
X mod Y
integer(X)-integer(Y)*(X//Y).
X/\Y
X\/Y
X#Y
\(X)
X<<Y
X>>Y
abs(X)
min(X,Y)
max(X,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 =:= Y
X =\= Y
X < Y
X > Y
X =< Y
X >= Y