Arithmetic is performed by built-in predicates which take as arguments arithmetic expressions (see arithexpression/1) and evaluate them. Terms representing arithmetic expressions can be created dynamically, but at the time of evaluation, each variable in an arithmetic expression must be bound to a non-variable expression (the term must be ground). For example, given the code in the first line a possible shell interaction follows:
evaluate(Expression, Answer) :- Answer is Expression. ?- _X=24*9, evaluate(_X+6, Ans). Ans = 222 ? yes
The arithmetic expression Exp is evaluated and the result is unified with Val
Usage 1:A is B
Usage 2:A is B
Usage 3:A is B
Usage 4:A is B
The numeric value of Exp1 is less than the numeric value of Exp2 when both are evaluated as arithmetic expressions.
Usage:A<B
The numeric value of Exp1 is less than or equal to the numeric value of Exp2 when both are evaluated as arithmetic expressions.
Usage:A=<B
The numeric value of Exp1 is greater than the numeric value of Exp2 when both are evaluated as arithmetic expressions.
Usage:A>B
The numeric value of Exp1 is greater than or equal to the numeric value of Exp2 when both are evaluated as arithmetic expressions.
Usage:A>=B
The numeric values of Exp1 and Exp2 are equal when both are evaluated as arithmetic expressions.
Usage:A=:=B
The numeric values of Exp1 and Exp2 are not equal when both are evaluated as arithmetic expressions.
Usage:A=\=B
In addition to these functors, a list of just a number evaluates to this number. Since a quoted string is just a list of integers, this allows a quoted character to be used in place of its ASCII code; e.g. "A" behaves within arithmetic expressions as the integer 65. Note that this is not ISO-compliant, and that can be achieved by using the ISO notation 0'A.
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 arithmetic predicates defined in this library.
Usage:arithexpression(E)
E is an arithmetic expression.
Usage:intexpression(E)
E is an integer expression.