Did you know ... | Search Documentation: |
Arithmetic constraints |
In modern Prolog systems, arithmetic constraints subsume and supersede low-level predicates over integers. The main advantage of arithmetic constraints is that they are true relations and can be used in all directions. For most programs, arithmetic constraints are the only predicates you will ever need from this library.
The most important arithmetic constraint is #=/2,
which subsumes both
(is)/2
and (=:=)/2
over integers. Use #=/2
to make your programs more general. See declarative integer arithmetic (section
A.9.3).
In total, the arithmetic constraints are:
Expr1 #=
Expr2Expr1 equals Expr2 Expr1 #\=
Expr2Expr1 is not equal to Expr2 Expr1 #>=
Expr2Expr1 is greater than or equal to Expr2 Expr1 #=<
Expr2Expr1 is less than or equal to Expr2 Expr1 #>
Expr2Expr1 is greater than Expr2 Expr1 #<
Expr2Expr1 is less than Expr2
Expr1 and Expr2 denote arithmetic expressions, which are:
integer Given value variable Unknown integer ?(variable) Unknown integer -Expr Unary minus Expr + Expr Addition Expr * Expr Multiplication Expr - Expr Subtraction Expr ^
ExprExponentiation min(Expr,Expr)
Minimum of two expressions max(Expr,Expr)
Maximum of two expressions Expr mod
ExprModulo induced by floored division Expr rem
ExprModulo induced by truncated division abs(Expr)
Absolute value Expr //
ExprTruncated integer division Expr div Expr Floored integer division
where Expr again denotes an arithmetic expression.
The bitwise operations (\)/1
, (/\)/2
, (\/)/2
, (>>)/2
,
(<<)/2
, lsb/1, msb/1, popcount/1
and (xor)/2
are also supported.