Arithmetic can be divided into some special purpose integer predicates and a series of general predicates for floating point and integer arithmetic as appropriate. The integer predicates are as ``logical'' as possible. Their usage is recommended whenever applicable, resulting in faster and more ``logical'' programs.
The general arithmetic predicates are optionally compiled now (see set_prolog_flag/2 and the -O command line option). Compiled arithmetic reduces global stack requirements and improves performance. Unfortunately compiled arithmetic cannot be traced, which is why it is optional.
The general arithmetic predicates all handle expressions. An expression is either a simple number or a function. The arguments of a function are expressions. The functions are described in section 4.27.
not_less_than_zero
if called with a negative integer. E.g. succ(X, 0)
fails
silently and succ(X, -1)
raises a domain-error. (38)
Note that normally, is/2 will be used with unbound left operand. If equality is to be tested, =:=/2 should be used. For example:
?- 1.0 is sin(pi/2). | Fails!. sin(pi/2) evaluates to 1.0, but is/2 will represent this as the integer 1, after which unify will fail. |
?- 1.0 is float(sin(pi/2)). | Succeeds, as the float/1 function forces the result to be float. |
?- 1.0 =:= sin(pi/2). | Succeeds as expected. |