/** * Background: * * Expression trees are commonly parsed as binary trees, and mathjs does this too. * That means that a mathjs expression tree likely looks like: * http://collegelabs.co/clabs/nld/images/524px-Expression_Tree.svg.png * * e.g. 2+2+2 is parsed by mathjs as 2 + 2+2 (a plus node with children 2 and 2+2) * However... * 1. This is more complicated than needed. 2+2+2 is the same as 2+(2+2) * 2. To collect like terms, we actually *need* it to be flat. e.g. with 2x+(2+2x), * there's no easy way to know that there are two 2x's to collect without * running up and down the tree. If we flatten to 2x+2+2x, it becomes a lot * easier to collect like terms to (2x+2x) + 2, which would then be combined to * 4x + 2 * The purpose of flatteOperands is to flatten the tree in this way. * * e.g. an expression that is grouped in the tree like * (2 + ((4 * ((1 + 2) + (3 + 4))) * 8)) * should be flattened to look like: * (2 + (4 * (1 + 2 + 3 + 4) * 8)) * * Subtraction and division are also flattened, though that gets a bit more * complicated and you may as well start reading through the code if you're * interested in how that works * */ /** * Flattens the tree accross the same operation (just + and * for now) * e.g. 2+2+2 is parsed by mathjs as 2+(2+2), but this would change that to * 2+2+2, ie one + node that has three children. * Input: an expression tree * Output: the expression tree updated with flattened operations * */ export declare function flattenOperands(node: any): any;