mathsparqlexponentiation

Power (exponentiation) and other math function support in SPARQL


I am trying to write a SPARQL query where I want to filter on the square of something, but I am simply unable to figure out how to square a number (x2) (except by multiplying it with itself, of course). I guessed a square root function called math:sqrt() which works, yet nothing like math:pow seems to exist.

How do I get the square of something in SPARQL and, more importantly, where can I read about it and other math functions such as math:sqrt in SPARQL?

Note: This is related to my previous question: Reverse wikipedia geotagging lookup .


Solution

  • It's now a few years later and the SPARQL 1.1 Query Language has been published. It includes many more built-in functions than the original SPARQL query language. In addition to lots of functions on strings, RDF terms, &c., there are a number of numeric functions (the section numbers indicate the section in the linked standard):

    There's still no square function here, and the quickest way to implement that will be using *, so laalto's answer still stands. The operators that SPARQL supports are described in 17.3 Operator Mapping, and for XPath arithmetic is still just the set of +, -, *, and /.