cortex-js / compute-engine

An engine for symbolic manipulation and numeric evaluation of math formulas expressed with MathJSON
https://cortexjs.io
MIT License
373 stars 46 forks source link

How can I implement a custom function in the compute engine? #107

Closed rs-mobitech closed 1 year ago

rs-mobitech commented 1 year ago

I'm not sure if it's there, and I have missed it, or if this is not explained. I created my own custom function called AddTwice, which takes two arguments and added that as a macro.

function AddTwice(firstArg, secondArg) {
    const twoTimesFirst = 2 * firstArg;
    const twoTimesSecond = 2 * secondArg;
    const result = twoTimesFirst + twoTimesSecond;
    return result;
}

I would like this function to be known to the compute engine, and to have the engine perform an addition on the two arguments just in a similar way to other functions such as Add.

Can you give some suggestions and perhaps add the documentation, how this could be done. I believe it's something that many would like to be able to do, so I hope the process can be documented.

arnog commented 1 year ago

https://cortexjs.io/compute-engine/guides/augmenting/#evaluation