(operator) is/2

Arithmetic assignment: Computes an arithmetic expression

Integer is Expression

The arithmetic assignment operator 'is/2' is defined as op(700,xfx,"is"). It is not a unification operator, so the free variable at the left side is not allowed.

Example

A is 2+3.

A=5

1 Solution

?Result <number> or <variable>

+Expression <expr>

Remarks:

1. Please be patient, if you discover that a few of the operators that follow are not yet implemented (in G.I.S. Prolog version 1.01). Version 1.02 will be out in a few days (mid-March 2005) and will contain all the new operators, tested thoroughly, and also checked for 100% compatibility with all the following Prolog compilers: LPA Win-Prolog, Swindon Prolog, and Visual Prolog.

2. The operator "is/2" evaluates the given arithmetic Expression and unifies the solution with Result. The Expression may be anything from a simple number to a deeply nested term containing one or more of the subterms, representing functions and operators. These can be split into two groups, the first of which can be applied to any numbers (integer or floating point) and the second of which are limited to use on integers. The following table shows the general functions and operators, which are compatible with LPA Win-Prolog, Swindon Prolog, Visual Prolog, and many other Prologs:

Term Function

X + Y adds X to Y

X - Y subtracts Y from X

- X returns the negative of X

X * Y multiplies X by Y

X / Y divides X by Y

X // Y performs integer division of X by Y, truncating the result towards zero

X div Y performs integer division of X by Y, truncating the result towards zero

X mod Y computes X modulo Y, where the result has the same sign as Y

X ^ Y raises X to the power of Y

abs(X) computes the absolute value of X

acos(X) computes the arccosine of X (degrees)

aln(X) computes the natural antilogarithm of X

alog(X) computes the common antilogarithm of X

asin(X) computes the arcsine of X (degrees)

atan(X) computes the arctangent of X (degrees)

cos(X) computes the cosine of X (degrees)

fp(X) computes the fractional part of X (this has the same sign as X)

int(X) computes the nearest integer less than or equal to X (truncates towards -infinity)

ip(X) computes the integer part of X (truncated towards zero; this has the same sign as X)

ln(X) computes the natural logarithm of X

log(X) computes the common logarithm of X

max(X,Y) computes the maximum of X and Y (the nearest to +infinity)

min(X,Y) computes the minimum of X and Y (the nearest to -infinity)

rand(X) computes a pseudo random floating point number between zero and X

sign(X) computes the sign of X (-1, 0, or 1 for negative, zero or positive respectively)

sin(X) computes the sine of X (degrees)

sqrt(X) computes the square root of X

tan(X) computes the tangent of X (degrees)

The following table shows the bit manipuation operators, all of which are specific to 32-bit signed integers (whole numbers in the range [-2147483648..2147483647]:

Term Function

I /\ J computes the bitwise "and" I and J

I \/ J computes the bitwise "inclusive or" I and J

I << J computes the arithmetic shift left of I by J bits (vacated bits are cleared to zero)

I >> J computes the arithmetic shift right of I by J bits (the original most significant bit is propagated into the vacated bits)

\(I) computes the bitwise "not" of I

a(I,J) computes the bitwise "and" I and J (this is the same as "I /\ J")

l(I,J) computes the left rotation of the I by J bits

o(I,J) computes the bitwise "inclusive or" I and J (this is the same as "I \/ J")

r(I,J) computes the right rotation of the I by J bits

x(I,J) computes the bitwise "exclusive or" I and J

See Also:

op/3

seed/1

randominit/1