DEV Community

Talha Munir 🇵🇸
Talha Munir 🇵🇸

Posted on

Logarithmic functions

In this article we will discuss logarithmic functions in Apache age.
Following are some of the logarithmic functions used in age. It represents the name of the function, description, syntax, what is returned by the function and a sample query.

e:

Description:

Returns the base of the natural logarithm

Syntax:

e()

Returns:

The function returns an agtype float.

A sample Query:

SELECT *
FROM cypher('your_graph_name', $$
    RETURN e()
$$) as (e agtype);
Enter fullscreen mode Exit fullscreen mode

It will return the value of e i.e. 2.71828182845905.

sqrt:

Description:

The function returns the square root of the provided number.

Syntax:

sqrt(expression)
here the expression represents any number or expression of numbers.

Returns:

It returns an agtype float.

A sample Query:

SELECT *
FROM cypher('your_graph_name', $$
    RETURN sqrt(144)
$$) as (results agtype);
Enter fullscreen mode Exit fullscreen mode

The above query will return 12 as the square root of 144.

exp:

Description:

The function returns e^n. where e is the base of the natural logarithm and n is the value of the argument expression.

Syntax:

e(expression)
here the expression represents any number or expression of numbers.

Returns:

It returns an agtype float.

A sample Query:

SELECT *
FROM cypher('graph_name', $$
    RETURN exp(2)
$$) as (e agtype);
Enter fullscreen mode Exit fullscreen mode

The above query will return a floating point result of e^2.

log:

Description:

The function returns the natural logarithm of the provided number.

Syntax:

log(expression)
here the expression represents any number or expression of numbers.

Returns:

It returns an agtype float.

A sample Query:

SELECT *
FROM cypher('graph_name', $$
    RETURN log(27)
$$) as (natural_logarithm agtype);
Enter fullscreen mode Exit fullscreen mode

The above query will return natural logarithm of 27.

log10:

Description:

The function returns the common logarithm(base10) of a number.

Syntax:

log10(expression)
here the expression represents any number or expression of numbers.

Returns:

It returns an agtype float.

A sample Query:

SELECT *
FROM cypher('your_graph_name', $$
    RETURN log10(27)
$$) as (common_logarithm agtype);
Enter fullscreen mode Exit fullscreen mode

The above query will calculate the natural/common logarithm of 27.

References:

  1. https://age.apache.org/age-manual/master/intro/overview.html
  2. https://github.com/apache/age

Top comments (0)