Math Functions
This topic describes the mathematical functions in Anzo.
Typographical Conventions
This documentation uses the following conventions in function syntax:
CAPS
: Although SPARQL is case-insensitive, function names and other keywords are written in uppercase for readability.
[ argument ]
: Brackets are used to indicate optional arguments. Arguments without brackets are required.
Functions
- ABS: Calculates the absolute value of the specified number.
- ADD: Adds two numeric values.
- AVERAGEIF: Calculates the average of the range of values that meet the specified criterion.
- AVERAGEIFS: Calculates the averages of the ranges of values that meet the specified criteria.
- AVG: Calculates the average (arithmetic mean) value for a group of numbers.
- CEILING: Rounds up a numeric value to the nearest integer.
- COS: Calculates the cosine of an angle.
- DIVIDE: Divides a number by another number.
- EQUAL: Evaluates whether two values are equal.
- EXP: Raises e to the specified power.
- FACT: Calculates the factorial of the specified number.
- FLOOR: Rounds down a numeric value to the nearest integer.
- GE: Evaluates whether one value is greater than or equal to (>=) another value.
- GT: Evaluates whether one value is greater than (>) another value.
- HAMMING_DIST: Calculates the hamming distance between two values.
- HAVERSINE_DIST: Computes the haversine distance between two latitude and longitude values.
- LE: Evaluates whether one value is less than or equal to (<=) another value.
- LN: Calculates the natural logarithm of a double value.
- LOG: Calculates the specified base logarithm of a double value.
- LOG2: Calculates the base two logarithm of a double value.
- LT: Evaluates whether one value is less than (<) another value.
- MAXVAL: Determines the maximum value from the given literal values.
- MINVAL: Determines the minimum value from the given literal values.
- MOD: Calculates the modulo of the division between two numbers.
- MULTIPLY: Multiplies two number values.
- NOT_EQUAL: Evaluates whether two values are not equal.
- NPV: Calculates the net present value of an investment.
- NUMERIC-ADD: Adds two numeric values.
- NUMERIC-SUBTRACT: Subtracts one numeric value from another numeric value.
- PI: Returns the value for PI.
- POWER: Raises the specified number to the specified power.
- PRODUCT: Calculates the product of a group of numbers.
- QUOTIENT: Calculates the quotient between two numbers.
- RAD: Converts to radians an angle value that is in degrees.
- RAND: Returns a random double value between 0 and 1.
- RANDBETWEEN: Returns a random integer that falls between two specified integers.
- ROUND: Rounds a numeric value to the nearest integer.
- ROUNDDOWN: Rounds a numeric value down to the specified number of digits.
- ROUNDUP: Rounds a numeric value up to the specified number of digits.
- SIN: Calculates the sine of an angle.
- SQRT: Calculates the square root of a number.
- SUBTRACT: Subtracts one RDF term from another RDF term type value.
- SUM: Calculates the sum of the numbers within a group.
- SUMIF: Calculates the sum of the range of values that meet the specified criterion.
- SUMIFS: Calculates the sums of the ranges of values that meet the specified criteria.
- SUMPRODUCT: Multiplies the numbers in a group and adds the results.
- SUMSQ: Calculates the square root of each number in a group and adds the results.
- TAN: Calculates the tangent of an angle.
ABS
This function calculates the absolute value of the specified number.
Syntax
ABS(number)
Argument |
Data Type |
Description |
number |
numeric |
The numeric value for which to calculate the absolute value. |
Returns
Data Type |
Description |
number |
The absolute value. |
ADD
This function adds two numeric values.
Syntax
ADD(value1, value2)
Argument |
Data Type |
Description |
value1 |
numeric |
The first numeric value to add. |
value2 |
numeric |
The second numeric value to add. |
Returns
Data Type |
Description |
number |
The result of the addition operation. |
AVERAGEIF
This function calculates the average of the range of values that meet the specified criterion.
You can use AVERAGEIFS to specify multiple value ranges and conditions.
Syntax
AVERAGEIF(values_to_test, criterion [, range_of_values ])
Argument |
Data Type |
Description |
values_to_test |
RDF term |
The literal, URI, or blank node value that defines the values to test against the criteria . |
criterion |
RDF term |
The literal, URI, or blank node value that defines the condition to test values against. |
range_of_values |
numeric |
An optional number that defines the range of values to average. When omitted, values_to_test is used. |
Returns
Data Type |
Description |
number |
The average value from the range of values that meet the criterion. |
AVERAGEIFS
This function calculates the averages of the ranges of values that meet the specified criteria. Unlike AVERAGEIF, this function enables you to specify multiple ranges and multiple conditions.
Syntax
AVERAGEIFS(values_to_average, value_range1, criteria1,
value_range2, criteria2
[, value_rangeN, criteriaN ])
Argument |
Data Type |
Description |
values_to_average |
numeric |
The numeric value that defines the overall range of values to evaluate. |
value_range1–N |
RDF term |
The literal, URI, or blank node value that defines the range of values to test against the corresponding criteria . |
criteria1–N |
RDF term |
The literal, URI, or blank node value that defines the condition to test the corresponding value_range against. |
Returns
Data Type |
Description |
number |
The average values from the ranges of values that meet the criteria. |
AVG
This function calculates the average (arithmetic mean) value for a group of numbers.
Syntax
AVG(number)
Argument |
Data Type |
Description |
number |
numeric |
The numeric value for which to calculate the average. |
Returns
Data Type |
Description |
number |
The arithmetic mean of the input values. |
CEILING
This function rounds up a numeric value to the nearest integer if the value has a fractional part. CEILING returns the value itself if it is a whole number.
Syntax
CEILING(number)
Argument |
Data Type |
Description |
number |
numeric |
The numeric value to round up. |
Returns
Data Type |
Description |
number |
The rounded up value. |
COS
This function calculates the cosine of the specified angle.
Syntax
COS(angle)
Argument |
Data Type |
Description |
angle |
double |
The angle in radians (double data type) to calculate the cosine for. If you have angle values in degrees, you can use RAD to convert the degrees to radians. |
Returns
Data Type |
Description |
double |
The cosine of the angle. |
DIVIDE
This function divides one number by another number.
Syntax
DIVIDE(value1, value2)
Argument |
Data Type |
Description |
value1 |
numeric |
The number that is the dividend in the equation. |
value2 |
numeric |
The number to divide value1 by. |
Returns
Data Type |
Description |
number |
The result of the division operation. |
EQUAL
This function evaluates whether value1 is equal to value2.
Syntax
EQUAL(value1, value2)
Argument |
Data Type |
Description |
value1 |
numeric, boolean, dateTime, RDF term |
The number, boolean, datetime, literal, URI, or blank node value to compare to value2 . |
value2 |
numeric, boolean, dateTime, RDF term |
The number, boolean, datetime, literal, URI, or blank node value to compare to value1 . |
Returns
Data Type |
Description |
boolean |
True if the values are equal and false if they are not. |
EXP
This function raises the base of the natural logarithms, e, to the specified power.
Syntax
EXP(power)
Argument |
Data Type |
Description |
power |
numeric |
The number to raise e to. |
Returns
Data Type |
Description |
number |
E raised to the specified power. |
FACT
This function calculates the factorial of the specified number.
Syntax
FACT(number)
Argument |
Data Type |
Description |
number |
int |
The number for which to calculate the factorial. |
Returns
Data Type |
Description |
int |
The factorial of the input values. |
FLOOR
This function rounds down a numeric value to the nearest integer if the value has a fractional part. FLOOR returns the value itself if it is a whole number.
Syntax
FLOOR(number)
Argument |
Data Type |
Description |
number |
numeric |
The numeric value to round down. |
Returns
Data Type |
Description |
number |
The rounded down value. |
GE
This function evaluates whether value1 is greater than or equal to (>=) value2.
Syntax
GE(value1, value2)
Argument |
Data Type |
Description |
value1 |
numeric, boolean, dateTime, RDF term |
The number, boolean, datetime, literal, URI, or blank node value to compare to value2 . This is the value that will be checked to see if it is greater than or equal to value2. |
value2 |
numeric, boolean, dateTime, RDF term |
The number, boolean, datetime, literal, URI, or blank node value to compare to value1 . |
Returns
Data Type |
Description |
boolean |
True if value1 >= value2. False if not. |
GT
This function evaluates whether value1 is greater than (>) value2.
Syntax
GE(value1, value2)
Argument |
Data Type |
Description |
value1 |
numeric, boolean, dateTime, RDF term |
The number, boolean, datetime, literal, URI, or blank node value to compare to value2 . This is the value that will be checked to see if it is greater than value2. |
value2 |
numeric, boolean, dateTime, RDF term |
The number, boolean, datetime, literal, URI, or blank node value to compare to value1 . |
Returns
Data Type |
Description |
boolean |
True if value1 > value2. False if not. |
HAMMING_DIST
This function calculates the hamming distance between two values.
Syntax
HAMMING_DIST(number1, number2)
Argument |
Data Type |
Description |
number1 |
long |
The first number. |
number2 |
long |
The second number. |
Returns
Data Type |
Description |
int |
The hamming distance. |
HAVERSINE_DIST
This function computes the haversine distance between two latitude and longitude values and returns the distance in kilometers. The function uses the Haversine formula, which is accurate for most purposes but assumes a spherical Earth. Since the Earth is elliptical, distances involving points near the poles will be more inaccurate than other points.
Syntax
HAVERSINE_DIST(latitude1, longitude1, latitude2, longitude2)
Argument |
Data Type |
Description |
latitude1 |
double |
The first latitude value. |
longitude1 |
double |
The first longitude value. |
latitude2 |
double |
The second latitude value. |
longitude2 |
double |
The second longitude value. |
Returns
Data Type |
Description |
double |
The distance in kilometers. |
LE
This function evaluates whether value1 is less than or equal to (<=) value2.
Syntax
LE(value1, value2)
Argument |
Data Type |
Description |
value1 |
numeric, boolean, dateTime, RDF term |
The number, boolean, datetime, literal, URI, or blank node value to compare to value2 . This is the value that will be evaluated to see if it is less than or equal to value2. |
value2 |
numeric, boolean, dateTime, RDF term |
The number, boolean, datetime, literal, URI, or blank node value to compare to value1 . |
Returns
Data Type |
Description |
boolean |
True if value1 <= value2. False if not. |
LN
This function calculates the natural logarithm of a double value.
Syntax
LN(number)
Argument |
Data Type |
Description |
number |
double |
The double value for which to calculate the natural logarithm. |
Returns
Data Type |
Description |
double |
The natural logarithm of the input value. |
LOG
This function calculates the specified base logarithm of a double value.
Syntax
LOG(number [, base ])
Argument |
Data Type |
Description |
number |
double |
The double value for which to calculate the base logarithm. |
base |
double |
An optional double value that specifies the base for the logarithm. If omitted, base e is used. |
Returns
Data Type |
Description |
double |
The base logarithm of the input value. |
LOG2
This function calculates the base two logarithm of a double value.
Syntax
LOG2(number)
Argument |
Data Type |
Description |
number |
double |
The double value for which to calculate the base 2 logarithm. |
Returns
Data Type |
Description |
double |
The base two logarithm of the input value. |
LT
This function evaluates whether value1 is less than (<) value2.
Syntax
LT(value1, value2)
Argument |
Data Type |
Description |
value1 |
numeric, boolean, dateTime, RDF term |
The number, boolean, datetime, or RDF term type value to compare to value2 . This is the value that will be evaluated to see if it is less than value2. |
value2 |
numeric, boolean, dateTime, RDF term |
The number, boolean, datetime, or RDF term type value to compare to value1 . |
Returns
Data Type |
Description |
boolean |
True if value1 < value2. False if not. |
MAXVAL
This function determines the maximum value from the given literal values.
Syntax
MAXVAL(value1 [, value2 ] [, valueN ])
Argument |
Data Type |
Description |
value1–N |
literal |
A literal value from which you want to find the maximum value. |
Returns
Data Type |
Description |
literal |
The maximum value. |
MINVAL
This function determines the minimum value from the given literal values.
Syntax
MINVAL(value1 [, value2 ] [, valueN ])
Argument |
Data Type |
Description |
value1–N |
literal |
A literal value from which you want to find the minimum value. |
Returns
Data Type |
Description |
literal |
The minimum value. |
MOD
This function calculates the modulo or remainder of the division between two numbers.
Syntax
MOD(number, divisor)
Argument |
Data Type |
Description |
number |
numeric |
The number that is the dividend in the equation. |
divisor |
numeric |
The number to divide the dividend by. |
Returns
Data Type |
Description |
number |
The modulo between the input numbers. |
MULTIPLY
This function multiplies two numbers.
Syntax
MULTIPLY(value1, value2)
Argument |
Data Type |
Description |
value1 |
numeric |
The first number in the multiplication equation. |
value2 |
numeric |
The number to multiply value1 by. |
Returns
Data Type |
Description |
number |
The result of the multiplication operation. |
NOT_EQUAL
This function evaluates whether value1 is not equal to value2.
Syntax
NOT_EQUAL(value1, value2)
Argument |
Data Type |
Description |
value1 |
numeric, boolean, dateTime, RDF term |
The number, boolean, datetime, literal, URI, or blank node value to compare to value2 . |
value2 |
numeric, boolean, dateTime, RDF term |
The number, boolean, datetime, literal, URI, or blank node value to compare to value1 . |
Returns
Data Type |
Description |
boolean |
True if value1 is not equal to value2. False if they are equal. |
NPV
This function calculates the net present value of an investment by using a discount rate and a series of future payments (negative values) and income (positive values).
Syntax
NPV(rate, year, value)
Argument |
Data Type |
Description |
rate |
double |
A double value that defines the discount rate to use in the calculation. |
year |
double |
A double value that indicates which year the value is in. |
value |
double |
The double values that represent payments and income. |
Returns
Data Type |
Description |
double |
The net present value. |
NUMERIC-ADD
This function adds two numeric values.
Syntax
NUMERIC-ADD(value1, value2)
Argument |
Data Type |
Description |
value1 |
numeric |
The first number in the addition equation. |
value2 |
numeric |
The number to add to value1 . |
Returns
Data Type |
Description |
number |
The result of the addition operation. |
NUMERIC-SUBTRACT
This function subtracts one numeric value from another numeric value.
Syntax
NUMERIC-SUBTRACT(value1, value2)
Argument |
Data Type |
Description |
value1 |
numeric |
The first number in the subtraction equation. |
value2 |
numeric |
The number to subtract from value1 . |
Returns
Data Type |
Description |
number |
The result of the subtraction operation. |
PI
This function returns the value for PI.
Syntax
PI()
Returns
Data Type |
Description |
double |
The PI value. |
POWER
This function raises the specified number to the specified power.
Syntax
POWER(value, power)
Argument |
Data Type |
Description |
value |
numeric |
The number to raise by the power . |
power |
numeric |
The number to raise value by. |
Returns
Data Type |
Description |
number |
The result of value raised to the specified power . |
PRODUCT
This function calculates the product of a group of numbers.
Syntax
PRODUCT(number)
Argument |
Data Type |
Description |
number |
numeric |
The group of numbers to multiply. |
Returns
Data Type |
Description |
number |
The product of the group. |
QUOTIENT
This function calculates the quotient between two numbers.
Syntax
QUOTIENT(numerator, denominator)
Argument |
Data Type |
Description |
numerator |
numeric |
The number to divide by the denominator . |
denominator |
numeric |
The number to divide the numerator by. |
Returns
Data Type |
Description |
long |
The quotient between the input values. |
RAD
This function converts to radians an angle value that is in degrees.
Syntax
RAD(angle)
Argument |
Data Type |
Description |
angle |
double |
The angle value to convert to radians. |
Returns
Data Type |
Description |
double |
The angle in radians. |
RAND
This function returns a random double value between 0 and 1.
Syntax
RAND()
Returns
Data Type |
Description |
double |
The random value between 0 and 1. |
RANDBETWEEN
This function returns a random integer that falls between the two specified integers. The two integers are included as options to be returned.
Syntax
RANDBETWEEN(low_number, high_number)
Argument |
Data Type |
Description |
low_number |
int |
The lowest integer in the range of values. |
high_number |
int |
The highest integer in the range of values. |
If the arguments are decimal values, Anzo returns a random integer between CEIL(low_number)
and FLOOR(high_number)
.
Returns
Data Type |
Description |
int |
The random value between the given low and high numbers. |
ROUND
This function rounds a numeric value to the nearest integer.
Syntax
ROUND(number)
Argument |
Data Type |
Description |
number |
numeric |
The number to round to the nearest integer. |
Returns
Data Type |
Description |
long |
The rounded value. |
ROUNDDOWN
This function rounds a numeric value down to the specified number of digits.
Syntax
ROUNDDOWN(number, num_digits)
Argument |
Data Type |
Description |
number |
numeric |
The number to round down. |
num_digits |
int |
An integer that specifies the number of digits to round down to. |
Returns
Data Type |
Description |
number |
The rounded down value. |
ROUNDUP
This function rounds a numeric value up to the specified number of digits.
Syntax
ROUNDUP(number, num_digits)
Argument |
Data Type |
Description |
number |
numeric |
The number to round up. |
num_digits |
int |
An integer that specifies the number of digits to round up to. |
Returns
Data Type |
Description |
number |
The rounded up value. |
SIN
This function calculates the sine of the specified angle.
Syntax
SIN(angle)
Argument |
Data Type |
Description |
angle |
double |
The angle in radians to calculate the sine for. If you have angle values in degrees, you can use RAD to convert the degrees to radians. |
Returns
Data Type |
Description |
double |
The sine of the angle. |
SQRT
This function calculates the square root of the specified number.
Syntax
SQRT(number)
Argument |
Data Type |
Description |
number |
numeric |
The number for which to calculate the square root. |
Returns
Data Type |
Description |
double |
The square root of the input value. |
SUBTRACT
This function subtracts one RDF term type (a literal value, URI, or blank node) value from another RDF term type value.
Syntax
SUBTRACT(term1, term2)
Argument |
Data Type |
Description |
term1 |
RDF term |
The literal, URI, or blank node value that term2 will be subtracted from. |
term2 |
RDF term |
The literal, URI, or blank node value to subtract from term1 . |
Returns
Data Type |
Description |
REF term |
The result of the subtraction operation. |
SUM
This function calculates the sum of the numbers within a group.
Syntax
SUM(number)
Argument |
Data Type |
Description |
number |
numeric |
The group of numbers to sum. |
Returns
Data Type |
Description |
number |
The sum of the values in the group. |
SUMIF
This function calculates the sum of the range of values that meet the specified criterion.
You can use SUMIFS to specify multiple value ranges and conditions.
Syntax
SUMIF(values_to_test, criterion [, range_of_values ])
Argument |
Data Type |
Description |
values_to_test |
RDF term |
The literal, URI, or blank node value that defines the values to test against the criterion . |
criterion |
RDF term |
The literal, URI, or blank node value that defines the condition to test values against. |
range_of_values |
numeric |
An optional number that defines the range of values to sum. When omitted, values_to_test is used. |
Returns
Data Type |
Description |
number |
The sum of the range of values. |
SUMIFS
This function calculates the sums of the ranges of values that meet the specified criteria. Unlike SUMIF, this function enables you to specify multiple ranges and multiple conditions.
Syntax
SUMIFS(values_to_sum, value_range1, criteria1,
value_range2, criteria2
[, value_rangeN, criteriaN ])
Argument |
Data Type |
Description |
values_to_sum |
numeric |
The numeric value that defines the overall range of values to evaluate. |
value_range1–N |
RDF term |
The literal, URI, or blank node value that defines the range of values to test against the corresponding criteria . |
criteria1–N |
RDF term |
The literal, URI, or blank node value that defines the condition to test the corresponding value_range against. |
Returns
Data Type |
Description |
number |
The sums of the ranges of values. |
SUMPRODUCT
This function multiplies the numbers in a group and adds the results.
Syntax
SUMPRODUCT(number)
Argument |
Data Type |
Description |
number |
numeric |
The group of numbers to multiply and then sum the results. |
Returns
Data Type |
Description |
number |
The sum of the product of the numbers in the group. |
SUMSQ
This function calculates the square root of each number in a group and adds the results.
Syntax
SUMSQ(number)
Argument |
Data Type |
Description |
number |
numeric |
The group of numbers for which to calculate the square root and then sum the results. |
Returns
Data Type |
Description |
number |
The sum of the square root of the numbers in the group. |
TAN
This function calculates the tangent of the specified angle.
Syntax
TAN(angle)
Argument |
Data Type |
Description |
angle |
double |
The angle in radians to calculate the tangent for. If you have angle values in degrees, you can use RAD to convert the degrees to radians. |
Returns
Data Type |
Description |
double |
The tangent of the angle. |