Next: Arithmetic and Coroutining
Up: Arithmetic Evaluation
Previous: Low Level Arithmetic Builtins
  Index
The Multi-Directional Predicates plus/3 and times/3
A drawback of arithmetic using is/2 is that the right hand side must
be fully instantiated at evaluation time.
Often it is desirable to have predicates that define true logic
relationships between their arguments like ``Z is the sum of X and Y''.
For integer addition and multiplication this is provided as:
- plus(X, Y, Z)
- True if the sum of X and Y is Z. At most one of X, Y, Z can be a variable.
- times(X, Y, Z)
- True if the product of X and Y is Z. At most one of X, Y, Z can be a variable.
They work only with integer arguments but any single argument
can be a variable which is then instantiated so that the relation holds.
If more than one argument is uninstantiated, an instantiation fault is produced.
Note that if one of the first two arguments is a variable,
a solution doesn't necessarily exist. For example, the following goal has
no integer solution :
[eclipse 1]: times(2, X, 3).
no (more) solution.
Since any one of the arguments of these two predicates can be a variable,
it does not make much sense to use them in arithmetic expressions
where always the first arguments are taken as input and the last
one as output.
Next: Arithmetic and Coroutining
Up: Arithmetic Evaluation
Previous: Low Level Arithmetic Builtins
  Index
Warwick Harvey
2004-08-07