OptionalisCreate a deep clone of the node. Both the node as well as all its childs are cloned recursively.
Compile an expression into optimized JavaScript code. compile returns an object with a function evaluate([scope]) to evaluate. Example:
Test whether this node equals an other node. Does a deep comparison of the values of both nodes.
Compile and eval an expression, this is the equivalent of doing node.compile().evaluate(scope). Example:
Optionalscope: MathScope<any>Filter nodes in an expression tree. The callback function is called as callback(node: MathNode, path: string, parent: MathNode) : boolean for every node in the tree, and must return a boolean. The function filter returns an array with nodes for which the test returned true. Parameter path is a string containing a relative JSON Path.
Example:
var node = math.parse('x^2 + x/4 + 3*y');
var filtered = node.filter(function (node) {
return node.isSymbolMathNode && node.name == 'x';
});
// returns an array with two entries: two SymbolMathNodes 'x'
The callback function is called as callback(node: MathNode, path: string, parent: MathNode) : boolean for every node in the tree, and must return a boolean. The function filter returns an array with nodes for which the test returned true. Parameter path is a string containing a relative JSON Path.
Returns an array with nodes for which test returned true
Transform a node. Creates a new MathNode having it’s child's be the
results of calling the provided callback function for each of the
child's of the original node. The callback function is called as
callback(child: MathNode, path: string, parent: MathNode) and must
return a MathNode. Parameter path is a string containing a relative
JSON Path.
See also transform, which is a recursive version of map.
Get a HTML representation of the parsed expression.
Optionaloptions: objectGet a string representation of the parsed expression. This is not exactly the same as the original input.
Optionaloptions: objectGet a LaTeX representation of the expression.
Optionaloptions: objectRecursively transform an expression tree via a transform function. Similar to Array.map, but recursively executed on all nodes in the expression tree. The callback function is a mapping function accepting a node, and returning a replacement for the node or the original node. Function callback is called as callback(node: MathNode, path: string, parent: MathNode) for every node in the tree, and must return a MathNode. Parameter path is a string containing a relative JSON Path.
For example, to replace all nodes of type SymbolMathNode having name ‘x’ with a ConstantMathNode with value 3:
var node = math.parse('x^2 + 5*x');
var transformed = node.transform(function (node, path, parent) {
if (node.SymbolMathNode && node.name == 'x') {
return new math.expression.node.ConstantMathNode(3);
}
else {
return node;
}
});
transformed.toString(); // returns '(3 ^ 2) + (5 * 3)'
traverse(callback)
Recursively traverse all nodes in a node tree. Executes given callback for this node and each of its child nodes. Similar to Array.forEach, except recursive. The callback function is a mapping function accepting a node, and returning a replacement for the node or the original node. Function callback is called as callback(node: MathNode, path: string, parent: MathNode) for every node in the tree. Parameter path is a string containing a relative JSON Path. Example:
var node = math.parse('3 * x + 2');
node.traverse(function (node, path, parent) {
switch (node.type) {
case 'OperatorMathNode': console.log(node.type, node.op); break;
case 'ConstantMathNode': console.log(node.type, node.value); break;
case 'SymbolMathNode': console.log(node.type, node.name); break;
default: console.log(node.type);
}
});
// outputs:
// OperatorMathNode +
// OperatorMathNode *
// ConstantMathNode 3
// SymbolMathNode x
// ConstantMathNode 2
Create a shallow clone of the node. The node itself is cloned, its childs are not cloned.