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


Arithmetic

Author(s): Daniel Cabeza, Manuel Hermenegildo.

Version: 1.5#118 (2000/4/19, 18:13:43 CEST)

Version of last change: 0.9#18 (1999/3/23, 21:6:13 MET)

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

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

Usage 2: * ISO *

PREDICATE: </2:

Exp1 < Exp2

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

Usage 2: * ISO *

PREDICATE: =</2:

Exp1 =< Exp2

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

Usage 2: * ISO *

PREDICATE: >/2:

Exp1 > Exp2

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

Usage 2: * ISO *

PREDICATE: >=/2:

Exp1 >= Exp2

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

Usage 2: * ISO *

PREDICATE: =:=/2:

Exp1 =:= Exp2

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

Usage 2: * ISO *

PREDICATE: =\=/2:

Exp1 =\= Exp2

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

Usage 2: * ISO *

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 notation 0'A (which is ISO).

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 here.

Usage 1: arithexpression(E)

Usage 2: arithexpression(E)


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