Go to the first, previous, next, last section, table of contents.


Arithmetic

Author(s): Daniel Cabeza, Manuel Hermenegildo.

Version: 1.11#222 (2004/5/24, 13:8:7 CEST)

Version of last change: 1.11#168 (2004/2/3, 21:28:52 CET)

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

Usage and interface (arithmetic)

Documentation on exports (arithmetic)

PREDICATE: is/2:

Val is Exp * ISO *

The arithmetic expression Exp is evaluated and the result is unified with Val

General properties:

Usage: X is Exp

PREDICATE: </2:

Exp1 < Exp2 * ISO *

The numeric value of Exp1 is less than the numeric value of Exp2 when both are evaluated as arithmetic expressions.

General properties:

Usage:

PREDICATE: =</2:

Exp1 =< Exp2 * ISO *

The numeric value of Exp1 is less than or equal to the numeric value of Exp2 when both are evaluated as arithmetic expressions.

General properties:

Usage:

PREDICATE: >/2:

Exp1 > Exp2 * ISO *

The numeric value of Exp1 is greater than the numeric value of Exp2 when both are evaluated as arithmetic expressions.

General properties:

Usage:

PREDICATE: >=/2:

Exp1 >= Exp2 * ISO *

The numeric value of Exp1 is greater than or equal to the numeric value of Exp2 when both are evaluated as arithmetic expressions.

General properties:

Usage:

PREDICATE: =:=/2:

Exp1 =:= Exp2 * ISO *

The numeric values of Exp1 and Exp2 are equal when both are evaluated as arithmetic expressions.

General properties:

Usage:

PREDICATE: =\=/2:

Exp1 =\= Exp2 * ISO *

The numeric values of Exp1 and Exp2 are not equal when both are evaluated as arithmetic expressions.

General properties:

Usage:

REGTYPE: arithexpression/1:

An arithmetic expression is a term built from numbers and evaluable functors that represent arithmetic functions. An arithmetic expression evaluates to a number, which may be an integer ( int/1) or a float ( flt/1). The evaluable functors allowed in an arithmetic expression are listed below, together with an indication of the functions they represent. All evaluable functors defined in ISO-Prolog are implemented, as well as some other useful or traditional. Unless stated otherwise, an expression evaluates to a float if any of its arguments is a float, otherwise to an integer.

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.

General properties:

Usage: arithexpression(E)


Go to the first, previous, next, last section, table of contents.