math
It is implemented in the library, math
. The supported mathematical operators:
computes a modulo between two parameters provided, returning a single integer value |
|
computes the square root of |
|
computes the absolute value of |
|
computes the minimum value among |
|
computes the maximum value among |
|
computes the logarithm of |
|
computes the logarithm of |
|
computes the natural logarithm of |
|
computes |
|
computes |
|
returns the closest integer to |
|
computes the smallest integer |
|
computes the largest integer |
|
computes the sine of |
|
computes the cosine of |
|
computes the tangent of |
|
returns the number Pi |
|
returns the number e |
|
produces a random double number greater than or equal to |
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.
@library("math:","math").
numbers(10, 3).
result(X) :- numbers(Y, Z), X = math:mod(Y, Z).
@output("result").
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.
@library("math:","math").
number(9).
result(X) :- number(Y), X = math:sqrt(Y).
@output("result").
result(3.0)
abs
Computes the absolute value of X
.
abs(X)
Where:
-
X
is the value to compute the absolute value of.
@library("math:","math").
number(-5).
result(X) :- number(Y), X = math:abs(Y).
@output("result").
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.
@library("math:","math").
numbers([3, 1, 2]).
result(X) :- numbers(Y), X = math:min(Y).
@output("result").
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.
@library("math:","math").
numbers([3, 1, 2]).
result(X) :- numbers(Y), X = math:max(Y).
@output("result").
result(3)
log10
Computes the logarithm of X
to base 10.
log10(X)
Where:
-
X
is the value to compute the logarithm of.
@library("math:","math").
number(100).
result(X) :- number(Y), X = math:log10(Y).
@output("result").
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.
@library("math:","math").
log_values(2, 8).
result(X) :- log_values(Y, Z), X = math:log(Y, Z).
@output("result").
result(3.0)
log2
Computes the natural logarithm of X
.
log(X)
Where:
-
X
is the value to compute the natural logarithm of.
@library("math:","math").
number(2.71828).
result(X) :- number(Y), X = math:log(Y).
@output("result").
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.
@library("math:","math").
power_values(2, 3).
result(X) :- power_values(Y, Z), X = math:pow(Y, Z).
@output("result").
result(8.0)
exp
Computes e^X
.
exp(X)
Where:
-
X
is the exponent.
@library("math:","math").
number(1).
result(X) :- number(Y), X = math:exp(Y).
@output("result").
result(2.71828)
round
Returns the closest integer to X
.
round(X)
Where:
-
X
is the value to be rounded.
@library("math:","math").
number(2.5).
result(X) :- number(Y), X = math:round(Y).
@output("result").
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.
@library("math:","math").
number(2.1).
result(X) :- number(Y), X = math:ceil(Y).
@output("result").
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.
@library("math:","math").
number(2.9).
result(X) :- number(Y), X = math:floor(Y).
@output("result").
result(2)
sin
Computes the sine of X
.
sin(X)
Where:
-
X
is the value to compute the sine of.
@library("math:","math").
number(3.14159).
result(X) :- number(Y), X = math:sin(Y).
@output("result").
result(1.0)
cos
Computes the cosine of X
.
cos(X)
Where:
-
X
is the value to compute the cosine of.
@library("math:","math").
number(3.14159).
result(X) :- number(Y), X = math:cos(Y).
@output("result").
result(-1.0)
tan
Computes the tangent of X
.
tan(X)
Where:
-
X
is the value to compute the tangent of.
@library("math:","math").
number(3.14159).
result(X) :- number(Y), X = math:tan(Y).
@output("result").
result(1.0)
PI
Returns the number Pi.
PI(X)
Where X is an arbitrary number.
@library("math:","math").
anumber(1).
result(X) :- anumber(Y), X = math:PI(Y).
@output("result").
result(3.14159)
E
Returns the number e.
E(X)
Where X is an arbitrary number.
@library("math:","math").
anumber(1).
result(X) :- anumber(Y), X = math:E(Y).
@output("result").
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.
@library("math:","math").
anumber(1).
result(X) :- anumber(Y), X = math:rand(Y).
@output("result").
result(0.54321) % Note: The actual result will vary as it is a random number.