All,
I am trying to call the sqrt() function from the math.js library.
I have successfully created my own .js files and called functions with those, however calling functions from math.js seems to be a bit different
The math.js file is in my workspace.
I have created different subclasses to spin:Functions called:
ex:math.sqrt
ex:sqrt
ex:_sqrtNumber
For example, in my ontology is the definition for sqrt:
ex:sqrt
rdf:type spin:Function ;
spin:constraint [
rdf:type spl:Argument ;
spl:predicate sp:arg1 ;
spl:valueType rdfs:Literal ;
rdfs:comment "The number to compute the square root of." ;
] ;
spin:returnType xsd:float ;
rdfs:subClassOf spin:Functions ;
.
I am trying to do a bind in my sparql - none of which work....
BIND (ex:math.sqrt(10) as ?root ).
BIND (ex:_sqrtNumber (9) as ?sqrt) .
BIND (ex:sqrt(9) as ?sqrt2) .
The actual function in the math.js file looks something like this:
function factory (type, config, load, typed) {
/**
* Calculate the square root of a value.
*
* For matrices, the function is evaluated element wise.
*
* Syntax:
*
* math.sqrt(x)
*
* Examples:
*
* math.sqrt(25); // returns 5
* math.square(5); // returns 25
* math.sqrt(-4); // returns Complex 2i
*
* See also:
*
* square, multiply, cube, cbrt
*
* @param {number | BigNumber | Complex | Array | Matrix | Unit} x
* Value for which to calculate the square root.
* @return {number | BigNumber | Complex | Array | Matrix | Unit}
* Returns the square root of `x`
*/
var sqrt = typed('sqrt', {
'number': _sqrtNumber,
'Complex': function (x) {
return x.sqrt();
},
With a private function below:
/**
* Calculate sqrt for a number
* @param {number} x
* @returns {number | Complex} Returns the square root of x
* @private
*/
function _sqrtNumber(x) {
if (x >= 0 || config.predictable) {
return Math.sqrt(x);
}
else {
return new type.Complex(x, 0).sqrt();
}
}
How can I successfully call the sqrt() function?
I hope to be able to do the same with additional functions.
Thanks,
Michael