math

It is implemented in the library, math. The supported mathematical operators:

mod

computes a modulo between two parameters provided, returning a single integer value

sqrt

computes the square root of X, returning a single double value

abs

computes the absolute value of X

min

computes the minimum value among X1, …​, Xn. These parameters must be of the same type

max

computes the maximum value among X1, …​, Xn. These parameters must be of the same type

log10

computes the logarithm of X to base 10

log

computes the logarithm of Y to base X. X cannot be 0 or 1

log2

computes the natural logarithm of X

pow

computes X to the power of Y, returns a value of type double

exp

computes e^X

round

returns the closest integer to X

ceil

computes the smallest integer Y that is equal to or greater than X

floor

computes the largest integer Y that is equal to or smaller than X

sin

computes the sine of X

cos

computes the cosine of X

tan

computes the tangent of X

PI

returns the number Pi

E

returns the number e

rand

produces a random double number greater than or equal to 0.0 and less than 1.0

mod

Computes a modulo between two parameters provided, returning a single integer value.

mod(X, Y)

Where:

  • X is the dividend.

  • Y is the divisor.

Example
@library("math:","math").
numbers(10, 3).
result(X) :- numbers(Y, Z), X = math:mod(Y, Z).
@output("result").
Expected results
result(1)

sqrt

Computes the square root of X, returning a single double value.

sqrt(X)

Where:

  • X is the value to compute the square root of.

Example
@library("math:","math").
number(9).
result(X) :- number(Y), X = math:sqrt(Y).
@output("result").
Expected results
result(3.0)

abs

Computes the absolute value of X.

abs(X)

Where:

  • X is the value to compute the absolute value of.

Example
@library("math:","math").
number(-5).
result(X) :- number(Y), X = math:abs(Y).
@output("result").
Expected results
result(5)

min

Computes the minimum value among X1, …​, Xn. These parameters must be of the same type.

min(X1, ..., Xn)

Where:

  • X1, …​, Xn are the values to find the minimum among.

Example
@library("math:","math").
numbers([3, 1, 2]).
result(X) :- numbers(Y), X = math:min(Y).
@output("result").
Expected results
result(1)

max

Computes the maximum value among X1, …​, Xn. These parameters must be of the same type.

max(X1, ..., Xn)

Where:

  • X1, …​, Xn are the values to find the maximum among.

Example
@library("math:","math").
numbers([3, 1, 2]).
result(X) :- numbers(Y), X = math:max(Y).
@output("result").
Expected results
result(3)

log10

Computes the logarithm of X to base 10.

log10(X)

Where:

  • X is the value to compute the logarithm of.

Example
@library("math:","math").
number(100).
result(X) :- number(Y), X = math:log10(Y).
@output("result").
Expected results
result(2.0)

log

Computes the logarithm of Y to base X. X cannot be 0 or 1.

log(X, Y)

Where:

  • X is the base of the logarithm.

  • Y is the value to compute the logarithm of.

Example
@library("math:","math").
log_values(2, 8).
result(X) :- log_values(Y, Z), X = math:log(Y, Z).
@output("result").
Expected results
result(3.0)

log2

Computes the natural logarithm of X.

log(X)

Where:

  • X is the value to compute the natural logarithm of.

Example
@library("math:","math").
number(2.71828).
result(X) :- number(Y), X = math:log(Y).
@output("result").
Expected results
result(1.0)

pow

Computes X to the power of Y. Returns a value of type double.

pow(X, Y)

Where:

  • X is the base.

  • Y is the exponent.

Example
@library("math:","math").
power_values(2, 3).
result(X) :- power_values(Y, Z), X = math:pow(Y, Z).
@output("result").
Expected results
result(8.0)

exp

Computes e^X.

exp(X)

Where:

  • X is the exponent.

Example
@library("math:","math").
number(1).
result(X) :- number(Y), X = math:exp(Y).
@output("result").
Expected results
result(2.71828)

round

Returns the closest integer to X.

round(X)

Where:

  • X is the value to be rounded.

Example
@library("math:","math").
number(2.5).
result(X) :- number(Y), X = math:round(Y).
@output("result").
Expected results
result(3)

ceil

Computes the smallest integer Y that is equal to or greater than X.

ceil(X)

Where:

  • X is the value to be ceiled.

Example
@library("math:","math").
number(2.1).
result(X) :- number(Y), X = math:ceil(Y).
@output("result").
Expected results
result(3)

floor

Computes the largest integer Y that is equal to or smaller than X.

floor(X)

Where:

  • X is the value to be floored.

Example
@library("math:","math").
number(2.9).
result(X) :- number(Y), X = math:floor(Y).
@output("result").
Expected results
result(2)

sin

Computes the sine of X.

sin(X)

Where:

  • X is the value to compute the sine of.

Example
@library("math:","math").
number(3.14159).
result(X) :- number(Y), X = math:sin(Y).
@output("result").
Expected results
result(1.0)

cos

Computes the cosine of X.

cos(X)

Where:

  • X is the value to compute the cosine of.

Example
@library("math:","math").
number(3.14159).
result(X) :- number(Y), X = math:cos(Y).
@output("result").
Expected results
result(-1.0)

tan

Computes the tangent of X.

tan(X)

Where:

  • X is the value to compute the tangent of.

Example
@library("math:","math").
number(3.14159).
result(X) :- number(Y), X = math:tan(Y).
@output("result").
Expected results
result(1.0)

PI

Returns the number Pi.

PI(X)

Where X is an arbitrary number.

Example
@library("math:","math").
anumber(1).
result(X) :- anumber(Y), X = math:PI(Y).
@output("result").
Expected results
result(3.14159)

E

Returns the number e.

E(X)

Where X is an arbitrary number.

Example
@library("math:","math").
anumber(1).
result(X) :- anumber(Y), X = math:E(Y).
@output("result").
Expected results
result(2.71828)

rand

Produces a random double number greater than or equal to 0.0 and less than 1.0.

rand(X)

Where X is an arbitrary number.

Example
@library("math:","math").
anumber(1).
result(X) :- anumber(Y), X = math:rand(Y).
@output("result").
Expected results
result(0.54321)  % Note: The actual result will vary as it is a random number.