nerdamer.buildFunction
nerdamer.buildFunction(x: ExpressionInput, argsArray?: string[]): (...args: number[]): numberCompiles an expression into a native JavaScript-number function for repeated evaluation.
Function calls are linked to Nerdamer's numerical implementations, including any dependencies
they require. The compiler supports scalar JavaScript-number arithmetic rather than Nerdamer's
full symbolic or structured value model. Symbolic-only operations such as indexed sums,
products, solvers, and matrix operations are rejected if they remain in the expression.
buildFunction uses new Function, so it may be unavailable under a Content Security Policy
that forbids dynamic JavaScript evaluation. When argsArray is omitted, free variables are
sorted alphabetically.
core!UnsupportedOperationError If the expression contains the imaginary unit or a function for which no matching JavaScript-number implementation is registered.
Parameters
| Name | Type | Description |
|---|---|---|
x | ExpressionInput | The expression to compile. |
argsArray | string[] | Variable names in the positional order expected by the compiled function. |
Returns
(...args: number[]): number — The compiled JavaScript-number function.
Examples
buildFunction('x-y')(9, 7); // 2
buildFunction('x-y', ['y', 'x'])(9, 7); // -2
buildFunction('erf(x)+2')(9); // 3