Module: builtins

is/2 — evaluates an arithmetic expression

ISO Standard Predicate


Result is Expression


Expression should be a ground term that can be evaluated. Numbers evaluate as themselves, and a list evaluates as the first element of the list. The operators listed in Arithmetic Operators and Arithmetic Functions can also be evaluated when their arguments can be evaluated. If Result is an unbound variable, then it will be bound to the numeric value of Expression. If Result is not unbound, then it will be evaluated, and the value of the Result will be unified with the value of Expression.

      Arithmetic Operators

Operator Description
-X unary minus
X div Y integer division
X mod Y X(integer) modulo Y
X xor Y X exclusive or Y
X * Y multiplication
X + Y addition
X-Y subtraction
X/Y division
X//Y integer division
X/\Y integer bitwise conjunction
X « Y integer bitwise left of X by Y places
X » Y integer bitwise right shift of X by Y places
X\/Y integer bitwise disjunction
X^Y X to the power Y
\X not(X) integer bitwise negation
0 ‘ Char the ASCII code of Char

      Arithmetic Functions

Function Description
abs(X) absolute value
acos(X) arc cosine
asin(X) arc sine
atan(X) arc tangent
cos(X) cosine
cputime CPU time in seconds since ALS Prolog started.
exp(X) natural exponential function
exp10(X) base 10 exponential function
floor(X) the largest integer not greater than X
heapused heap space in use, in bytes
j0(X) Bessel function of order 0
j1(X) Bessel function of order 1
log(X) natural logarithm
log10(X) base 10 logarithm
random returns a random floating point number such that 0.0 ≤ X < 1.0
realtime actual time in seconds since ALS Prolog started
round(X) integer rounding of X
sin(X) sine
sqrt(X) square root
tan(X) tangent
trunc(X) the largest integer not greater than X
y0(X) Bessel function of second kind of order 0
y1(X) Bessel function of second kind of order 1


?- 2 is 3-1.


?- X is 6*7



?- X is 2.5+3.5.



?- Result is sqrt(2).




is/2 fails when it attempts to evaluate an unknown operator, or if Expression is not ground. Failure also occurs if there are any arithmetic faults, such as overflow, underflow, or division by zero.


ALS Prolog complies to the ISO Prolog Standard regarding errors. A calculation error will be thrown on overflow, underflow, division by zero, or use of an unrecognized arithmetic operator.