Arithmetic Domains

The Jekejeke Prolog interpreter accepts numbers and internally represents them as integers, floats or decimals. The implementation represents floats and decimals as pairs of a mantissa and a scale. For floats the scale is binary, for decimals the scale is decimal:

float = mantissa * 2scale
decimal = mantissa * 10scale
Examples:
     1.0 = 100.0E-2
0d0.01 = 0d1E-2
0d123.4 = 0d1.234E2
0d1.0 \= 0d100E-2

If an integral value is between -2^31 and 2^31-1 then the Java Integer is used instead of the Java BigInteger. Similarly if a decimal value has scale 0 and a mantissa between -2^63 and 2^63-1 then the Java Long is used instead of the Java BigDecimal. The decimal scale is restricted to 31 bits.

The float mantissa is bounded and approximated to the precision. The small respectively large float binary scale is restricted to 8 bits respectively 11 bits. A negative zero is mapped to a positive zero. A NaN or infinity, irrespective of its sign, is considered outside of the domain and leads to an error.

Example:
?- [user].
factorial(0, 1).
factorial(X, Y) :- X>0, H is X-1, factorial(H, J), Y is X*J.
^D
?- X is factorial(4).
X = 24

The predicate is/2 can be used to evaluate a term consisting of evaluable functions and number constants. Thanks to bridging an evaluable function can also be defined by ordinary Prolog clauses for the corresponding predicate. The evaluable function will only deliver the first result of the corresponding predicate.

The following built-in predicates are provided for arithmetic domains:

X is Y: [ISO 8.6.1]
The predicate succeeds when X unifies with the evaluation of Y.
X [Y1, .., Yn, Z]:
The predicate succeeds when Z unifies with the element of term with the subscripts Y1, .., Yn for 1 ≤ n ≤ 7. The term X need not be homogenously shaped and the indexes start with one.

The following Prolog flags for arithmetic domains are provided:

bounded: [ISO 7.11.1.1]
Legal values are true [ISO] and false [ISO]. The flag indicates whether the integer domain is bounded. Default value is false. Currently the value cannot be changed.

Kommentare