welcome:
location: attachment:math_R_v1.htm of dlvex

## Attachment 'math_R_v1.htm'

Math_R Library

This library includes the definition of 25 external built-in predicates for the execution of mathematical calculations in the field of the Real numbers. As real numbers are not yet available in the DLV System, we use text strings to represent numbers having as C++ type the double data type.

 BUILT-IN PREDICATE DESCRIPTION #addR(number1, number2, result) Compute the addition number1+number2. #subtR(number1, number2, result) Compute the subtraction number1-number2. #divR(number1, number2, result) Compute the division number1/number2. #timesR(number1, number2, result) Compute the multiplication number1*number2. #modR(number1, number2, result) Compute the remainder of the division number1/number2. #pow(base, exponent, result) Compute the result of base power to the exponent. Compute the result of (Naperian) e power to the exponent. #log(base, number, result) Compute the logarithm of number to the given base. #log10(number, result) Compute the logarithm of number to base 10. #log2(number, result) Compute the logarithm of number to base 2. #ln(number, result) Compute the natural (Naperian)  logarithm of number. #root(index, number, result) Compute the n-th root of number (where n is equal to index) . #sqrt(number, result) Compute the square root of number. #round(number, precision, result) Round number to the specified number of digit (precision). #fabs(number, result) Compute the absolute value of number. #ceil(number, result) Compute the smallest integer greater than number. #floor(number, result) Compute the greatest integer less than number. #sin(angle, result) Compute the trigonometric function sine of the angle (measured in radians). #cos(angle, result) Compute the trigonometric function cosine of the angle (measured in radians). #tan(angle, result) Compute the trigonometric function tangent of the angle (measured in radians). #asin(sine, result) Compute the trigonometric function arcsine of the sine value. #acos(cosine, result) Compute the trigonometric function arccosine of the cosine value. #atan(tangent, result) Compute the trigonometric function arctangent of the tangent value. #deg2rad(degrees, result) Convert the measure of an angle from degrees to radians. #rad2deg(radians, result) Convert the measure of an angle from radians to degrees.

It computes the addition between two numbers.

Syntax

number1 is the first number to sum

number2 is the second number to sum

result  is the resulting sum

Available Patterns

iii (number1, number2, result) :            Returns true if result is equal to number1 + number2

iio (number1, number2, Result) :         Set Result to number1 + number2

ioi (number1, Number2, result) :          Set Number2 to the result of result  number1

oii (Number1, number2, result) :          Set Number1 to the result of result  number2

Notes

Returns false if one of the arguments is not a string.

 #subtR

It computes the subtraction between two numbers.

Syntax

#subtR(number1, number2, result)

number1 is the first operand of the subtraction

number2 is the second operand of the subtraction

result is the result of the subtraction

Available Patterns

iii (number1, number2, result) :              Returns true if result is equal to number1  number2

iio (number1, number2, Result) :            Set Result to number1  number2

ioi (number1, Number2, result) :            Set Number2 to number1  result

oii (Number1, number2, result) :            Set Number1 to result + number2

Notes

Returns false if one of the arguments is not a string.

 #divR

It computes the division between two numbers.

Syntax

#divR(number1, number2, result)

number1 is the first operand of the division

number2 is the second operand (different from zero) of the division

result is the result of the division

Available Patterns

iii (number1, number2, result) :              Returns true if result is equal to number1 / number2

iio (number1, number2, Result) :            Set Result to the result of number1 / number2

Notes

Returns false if either one of the arguments is not a string or number2 is zero.

#timesR

 #timesR

It computes the multiplication between two numbers.

Syntax

#timesR(number1, number2, result)

number1 is the first operand of the multiplication

number2 is the second operand of the multiplication

result is the result of the multiplication

Available Patterns

iii (number1, number2, result) :                     Returns true if result is equal to number1 * number2

iio (number1, number2, Result) :                   Set Result to number1 * number2

Notes

Returns false if one of the arguments is not a string.

 #modR

It computes the remainder of the division between two numbers.

Syntax

#modR(number1, number2, result)

number1 is the first operand of the division

number2 is the second operand (different from zero) of the division

result is the remainder of number1 divided by number2

Available Patterns

iii (number1, number2, result) :              Returns true if result is equal to the remainder of number1 / number2

iio (number1, number2, Result) :            Set Result to the remainder of number1 / number2

Notes

Returns false if either one of the arguments is not a string or number2 is zero.

#divR

 #pow

It raises a number to a given power.

Syntax

#pow(base, exponent, result)

base is the number to be raised to a power

exponent is the power to apply

result is the base raised to the exponent

Available Patterns

iii (base, exponent, result) :                    Returns true if result is equal to base ^ exponent

iio (base, exponent, Result) :                  Set Result to base ^ exponent

Notes

Returns false if either one of the arguments is not a string or base and exponent are zero.

 #exp

It computes the result of e power to a given exponent. The constant e is equal to 2,71828182845904, the base of the natural logarithm.

Syntax

#exp(exponent, result)

exponent is the power to apply

result is e raised to the exponent

Available Patterns

ii (exponent, result) :                               Returns true if result is equal to e ^ exponent

io (exponent, Result) :                            Set Result to e ^ exponent

Notes

Returns false if one of the arguments is not a string.

#pow, #ln

 #log

It computes the logarithm of a number to a given base.

Syntax

#log(base, number, result)

base is the base for the logarithm

number is the value we want to know the logarithm

result is the resulting value

Available Patterns

iii (base, number, result) :                       Returns true if result is the logarithm of number to the given base

iio (base, number, Result) :                    Set Result  to the logarithm of number to the given base

Notes

Returns false if either one of the arguments is not a string or base is equal to one.

#log10, #log2, #ln

 #log10

It computes the logarithm of a number to base 10.

Syntax

#log10(number, result)

number is the value we want to know the logarithm to base 10

result is the resulting value

Available Patterns

ii (number, result) :                                  Returns true if result is the logarithm of number to base 10

io (number, Result) :                               Set Result  to the logarithm of number to base 10

Notes

Returns false if one of the arguments is not a string.

#log, #log2, #ln

 #log2

It computes the logarithm of a number to base 2.

Syntax

#log2(number, result)

number is the value we want to know the logarithm to base 2

result is the resulting value

Available Patterns

ii (number, result) :                                  Returns true if result is the logarithm of number to base 2

io (number, Result) :                               Set Result  to the logarithm of number to base 2

Notes

Returns false if one of the arguments is not a string.

#log

 #ln

It computes the natural (Napierian) logarithm of a number.

Syntax

#ln(number, result)

number is the value we want to know the natural logarithm

result is the resulting value

Available Patterns

ii (number, result) :                                  Returns true if result is the natural logarithm of number

io (number, Result) :                               Set Result  to the natural logarithm of number

Notes

Returns false if either one of the arguments is not a natural number or the result is a negative number.

#log

 #root

It computes the n-th radix of a number (where n is equal to a given index).

Syntax

#root (index, number, result)

index is the root index

number is the value we want to know the root

result is the resulting value

Available Patterns

iii (index, number, result) :                      Returns true if result is the n-th root of number (where n is equal to index)

iio (index, number, Result) :                   Set Result to the n-th root of number (where n is equal to index)

Notes

Returns false if either one of the arguments is not a string or index is zero or index is even and number is negative.

 #sqrt

It computes the square root of a number.

Syntax

#sqrt (number, result)

number is the value we want to know the square root

result is the resulting value

Available Patterns

ii (number, result) :                                  Returns true if result is the square root of number

io (number, Result) :                               Set Result to the square root of number

Notes

Returns false if either one of the arguments is not a string or number is negative.

 #round

It rounds a number to the specified number of digit (precision).

Syntax

#round (number, precision, result)

number is the value to be rounded

precision is the number of digits we want

result is the rounded value

Available Patterns

iii (number, precision, result) :                Returns true if result is the number rounded to the specified precision

iio (number, precision, Result) :             Set Result to the number rounded to the specified precision

Notes

Returns false if either one of the arguments is not a string or precision is not an integer number.

#fabs

 #fabs

It computes the absolute value of a number.

Syntax

#fabs (number, result)

number is the object we want the absolute value

result is the absolute value of number

Available Patterns

ii (number, result) :                                  Returns true if result is the absolute value of number

io (number, Result) :                               Set Result to the absolute value of number

Notes

Returns false if one of the arguments is not a string.

#round

 #ceil

It computes the smallest integer greater than a given number.

Syntax

#ceil (number, result)

number is the value to be ceiled

result is the smallest integer greater than number

Available Patterns

ii (number, result) :                                  Returns true if result is the smallest integer greater than number

io (number, Result) :                               Set Result to the smallest integer greater than number

Notes

Returns false if either number is not a string or result is not an integer number.

 #floor

It computes the greatest integer less than a given number.

Syntax

#floor (number, result)

number is the value to be floored

result is the greatest integer less than number

Available Patterns

ii (number, result) :                                  Returns true if result is the greatest integer less than number

io (number, Result) :                               Set Result to the greatest integer less than number

Notes

Returns false if either number is not a string or result is not an integer number.

 #sin

It computes the trigonometric function sine.

Syntax

#sin (angle, result)

angle is the value we want to know the sine (measured in radians)

result is the sine of angle

Available Patterns

ii (angle, result) :                                     Returns true if result is the sine of angle

io (angle, Result) :                                   Set Result to the sine of angle

Notes

Returns false if one of the arguments is not a string.

#cos

 #cos

It computes the trigonometric function cosine.

Syntax

#cos (angle, result)

angle is the value we want to know the cosine (measured in radians)

result is the cosine of angle

Available Patterns

ii (angle, result) :                                     Returns true if result is the cosine of angle

io (angle, Result) :                                   Set Result to the cosine of angle

Notes

Returns false if one of the arguments is not a string.

#sin

 #tan

It computes the trigonometric function tangent.

Syntax

#tan (angle, result)

angle is the value we want to know the tangent (measured in radians)

result is the tangent of angle

Available Patterns

ii (angle, result) :                                     Returns true if result is the tangent of angle

io (angle, Result) :                                   Set Result to the tangent of angle

Notes

Returns false if one of the arguments is not a string.

#sin

 #asin

It computes the trigonometric function arcsine.

Syntax

#asin (sine, result)

sine is the value of the sine we want to know the angle

result is the angle having as sine the value sine

Available Patterns

ii (sine, result) :                                       Returns true if result is the arcsine of sine

io (sine, Result) :                                     Set Result to the arcsine of sine

Notes

Returns false if one of the arguments is not a string.

#sin

 #acos

It computes the trigonometric function arccosine.

Syntax

#acos (cosine, result)

cosine is the value of the cosine we want to know the angle

result is the angle having as cosine the value cosine

Available Patterns

ii (cosine, result) :                                   Returns true if result is the arccosine of cosine

io (cosine, Result) :                                 Set Result to the arccosine of cosine

Notes

Returns false if one of the arguments is not a string.

#cos

 #atan

It computes the trigonometric function arctangent.

Syntax

#atan (tangent, result)

tangent is the value of the tangent we want to know the angle

result is the angle having as tangent the value tangent

Available Patterns

ii (tangent, result) :                                  Returns true if result is the arctangent of tangent

io (tangent, Result) :                               Set Result to the arctangent of tangent

Notes

Returns false if one of the arguments is not a string.

#tan

It converts the measure of an angle from degrees to radians.

Syntax

degrees is the measure of an angle in degrees

result is the corresponding value in radians

Available Patterns

ii (degrees, result) :                                 Returns true if result is the measure in radians of  degrees

io (degrees, Result) :                              Set Result to the measure in radians of degrees

Notes

Returns false if one of the arguments is not a string.

It converts the measure of an angle from radians to degrees.

Syntax

result is the corresponding value in degrees

Available Patterns

ii (radians, result) :                                  Returns true if result is the measure in degrees of  radians

io (radians, Result) :                               Set Result to the measure in degrees of radians

Notes

Returns false if one of the arguments is not a string.