Re: sqrt [was: Wishlist for SPARQL 1.2: Compatible query-hints, extra math operators]

On 31 Jul 2013, at 10:06, Andy Seaborne <andy@apache.org> wrote:

> On 30/07/13 15:05, Jerven Bolleman wrote:
> ...
>> The second is an expansion of the basic math operators to include at
>> least (square)root. (square)root is very hard to implement using the
>> current SPARQL constructs yet is a very useful function. (even if not
>> exact)
> 
> The SPARQL 1.1 library was decided mainly by taking the non-sequence related functions from XQuery/XPath Functions and Operators (F&O), sorting out a few details of RDF/SPARQL evaluation, and adding some SPARQL specific functions (e.g. STRDT).
> 
> F&O is an excellent resource because it defines exactly what all the operations do.  It is (oddly?) lacking on numeric operations like sqrt and similar but there may be a good reason for that.
> 
> I agree it would be good to have sqrt.  Let's hope that implementations add it as an URI-callable function.
> 
> If we implementers decide on the URI, then queries will be portable.
> 
> http://www.w3.org/ns/sparql is supposed to be populated with URIs for every function with a keyword in SPARQL.  That action (389) got lost.
> 
> So ...
> 
> prefix http://www.w3.org/ns/sparql#
> 
> sfn:sqrt(numeric) -> double.
> 
> What else (within reason!)?

If we're winning the pain of sqrt() corner cases, might as well have exp() and pow() as well:

sfn:exp(numeric) → double    (exp(x) = e^x)
sfn:pow(numeric, numeric) → double    (pow(x, y) = x^y)

Occasionally I've found myself wanting trig functions, but I suspect every time the right answer was geoSPARQL, or something like it.

Some constants might be useful, Inf, pi, e - and/or isinf(), isnan() functions.

- Steve

Received on Wednesday, 31 July 2013 09:24:29 UTC