welcome:
location: attachment:math_N_v1.htm of dlvex

## Attachment 'math_N_v1.htm'

Math_N Library

This library includes the definition of 23 external built-in predicates for the execution of mathematical calculations in the field of the Natural numbers. All the predicates in the library have as suffix Nat.

 BUILT-IN PREDICATE DESCRIPTION #addNat(number1, number2,result) Compute the addition number1+number2. #subNat(number1, number2, result) Compute the subtraction number1-number2. #divNat(number1, number2, result) Compute the division number1/number2. #multNat(number1, number2, result) Compute the multiplication number1*number2. #modNat(number1, number2, result) Compute the remainder of the division number1/number2. #powNat(base, exponent, result) Compute the result of base power to the exponent. #logNat(base, number, result) Compute the logarithm of number to the given base. #log10Nat(number, result) Compute the logarithm of number to base 10. #log2Nat(number, result) Compute the logarithm of number to base 2. #lnNat(number, result) Compute the natural (Napierian)  logarithm of number. #rootNat(index, number, result) Compute the n-th root of number (where n is equal to index) . #sqrtNat(number, result) Compute the square root of number. #gcdNat(number1, number2, result) Compute the greatest common divisor for number1 and number2. #lcmNat(number1, number2, result) Compute the least common multiple for number1 and number2. #factNat(number, result) Compute the factorial of number . #s2nNat(string_num, number) Convert the text string_num, representing a natural number, into the corresponding number. #n2sNat(number, string_num) Convert the natural number into the corresponding text string_num. #b2dNat(string_bin, number) Convert the text string_bin, representing a binary number, into the corresponding decimal number. #d2bNat(number, string_bin) Convert the decimal number into the text stringa_bin representing  the corresponding binary value. #evenNat(number) Return true if number is even. #oddNat(number) Return true if number is odd. #combNat(number1, number2, result) Compute the number of combinations or groupings of number1 things taken number2 at a time. #permNat(number1, number2, result) Compute the number of permutations or arrangements of number1 things taken number2 at a time.

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 either one of the arguments is not a natural number or the result is greater than the maximum allowed integer number.

 #subNat

It computes the subtraction between two numbers.

Syntax

#subNat(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 either one of the arguments is not a natural number or number1 is less than number2 .

 #divNat

It computes the division between two numbers.

Syntax

#divNat(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 natural number or number2 is zero.

 #multNat

It computes the multiplication between two numbers.

Syntax

#multNat(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 either one of the arguments is not a natural number or the result is greater than the maximum allowed integer number.

 #modNat

It computes the remainder of the division between two numbers.

Syntax

#modNat(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 natural number or number2 is zero.

 #powNat

It raises a number to a given power.

Syntax

#powNat(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 natural number or base and exponent are zero.

 #logNat

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

Syntax

#logNat(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 natural number or the result is a negative number.

 #log10Nat

It computes the logarithm of a number to base 10.

Syntax

#log10Nat(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 either one of the arguments is not a natural number or the result is a negative number.

 #log2Nat

It computes the logarithm of a number to base 2.

Syntax

#log2Nat(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 either one of the arguments is not a natural number or the result is a negative number.

 #lnNat

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

Syntax

#lnNat(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.

 #rootNat

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

Syntax

#rootNat(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 natural number or index is zero.

 #sqrtNat

It computes the square root of a number.

Syntax

#sqrtNat(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 one of the arguments is not a natural number.

 #gcdNat

It computes the Greatest Common Divisor (GCD) for two numbers.

Syntax

#gcdNat(number1, number2, result)

number1 and number2 are the numbers we want to compute the GCD

result is the GCD for number1 and number2

Available Patterns

iii (number1, number2, result) :              Returns true if result is the GCD for numbe1 and number2

iio (number1, number2, Result) :            Set Result to the GCD for number1 and number2

Notes

Returns false if one of the arguments is not a natural number.

 #lcmNat

It computes the Least Common Multiple (LCM) for two numbers.

Syntax

#lcmNat(number1, number2, result)

number1 and number2 are the numbers we want to compute the LCM

result is the LCM for number1 and number2

Available Patterns

iii (number1, number2, result) :              Returns true if result is the LCM for numbe1 and number2

iio (number1, number2, Result) :            Set Result to the LCM for number1 and number2

Notes

Returns false if one of the arguments is not a natural number.

 #factNat

It computes the factorial of a number.

Syntax

#factNat(number, result)

number is the number we want to compute the factorial

result is the factorial of number

Available Patterns

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

io (number, Result) :                               Set Result to the factorial of number

Notes

Returns false if one of the arguments is not a natural number.

 #s2nNat

It converts a string, representing a natural number, into the corresponding number.

Syntax

#s2nNat(string_num, number)

string_num is the text string representing number

number is the numerical value corresponding to the text string_num

Available Patterns

ii (string_num, number) :                        Returns true if number is the numerical value represented by string_num

io (string_num, Number) :                       Set Number to the numerical value represented by string_num

oi (String_num, number) :                       Set String_num to the text corresponding to the value of number

Notes

Returns false if either string_num is not a text string or number is not a natural number.

 #n2sNat

It converts a number into the corresponding string.

Syntax

#n2sNat(number, string_num)

number is the numerical value corresponding to the text string_num

string_num is the text string representing number

Available Patterns

ii (number, string_num) :                        Returns true if string_num is the text corresponding to the numerical value of number

io (number, String_num) :                       Set String_num to the text corresponding to the value of number

oi (Number, string_num) :                       Set Number to the numerical value represented by string_num

Notes

Returns false if either number is not a natural number or string_num is not a text string.

 #b2dNat

It converts a string, representing a binary number, into the corresponding decimal number.

Syntax

#b2dNat(string_bin, number)

string_bin is the string representing number with the binary radix

number is the decimal value corresponding to the binary value represented by string_bin

Available Patterns

ii (string_bin, number) :                          Returns true if the value represented by string_bin is equal to the binary value of number

io (string_bin, Number) :                         Set Number to the decimal value corresponding to the binary value represented by string_bin

oi (String_bin, number) :                         Set String_bin to the text representing the binary value corresponding to the decimal value of number

Notes

Returns false if either string_bin is not a text string or number is not a natural number.

 #d2bNat

It converts a decimal number into the string representing the corresponding binary value.

Syntax

#d2bNat(number, string_bin)

number is the decimal value corresponding to the binary value represented by string_bin

string_bin is the string representing number with the binary radix

Available Patterns

ii (number, string_bin) :                          Returns true if number is equal to the decimal value of the binary number represented by string_bin

io (number, String_bin) :                         Set String_bin to the text representing the binary value corresponding to the decimal value of number

oi (Number, string_bin) :                         Set Number to the decimal value corresponding to the binary value represented by string_bin

Notes

Returns false if either number is not a natural number or string_bin is not a text string.

 #evenNat

It returns true if a number is even.

Syntax

#evenNat(number)

number is the number to be checked

Available Patterns

i (number) :                                             Returns true if number is even.

Notes

Returns false if number is not a natural number.

 #oddNat

It returns true if a number is odd.

Syntax

#oddNat(number)

number is the number to be checked

Available Patterns

i (number) :                                             Returns true if number is odd.

Notes

Returns false if number is not a natural number.

 #combNat

It computes the number of combinations or groupings.

Syntax

#combNat(number1, number2, result)

number1 is the number of elements to consider

number2 is the number of elements in each combination

result is the number of achievable combinations

Available Patterns

iii (number1, number2, result) :              Return true if result is equal to the number of achievable combinations of number1 things taken number2 at a time

iio (number1, number2, Result) :            Set Result to the number of achievable combinations of number1 things taken number2 at a time

Notes

Returns false if either one of the arguments is not a natural number or  number1 is less than number2.

 #permNat

It computes the number of permutations or arrangement.

Syntax

#permNat(number1, number2, result)

number1 is the number of elements to consider

number2 is the number of elements in each permutation

result is the number of achievable permutations

Available Patterns

iii (number1, number2, result) :              Return true if result is equal to the number of achievable permutations of number1 things taken number2 at a time

iio (number1, number2, Result) :            Set Result to the number of achievable permutations of number1 things taken number2 at a time

Notes

Returns false if either one of the arguments is not a natural number or  number1 is less than number2.