packages/solver/lib/util/flattenOperands.js
function maybeFlattenPolynomialTerm(node) {
  // We recurse on the left side of the tree to find operands so far
  const operands = getOperands(node.args[0], '*');

  // If the last operand (so far) under * was a constant, then it's a
  // polynomial term.
  // e.g. 2*5*6x creates a tree where the top node is implicit multiplcation
  // and the left branch goes to the tree with 2*5*6, and the right operand
  // is the symbol x. We want to check that the last argument on the left (in
  // this example 6) is a constant.
  const lastOperand = operands.pop();

  // in the above example, node.args[1] would be the symbol x
  const nextOperand = flattenOperands(node.args[1]);

  // a coefficient can be constant or a fraction of constants
  if (Node.Type.isConstantOrConstantFraction(lastOperand)) {
    // we replace the constant (which we popped) with constant*symbol
    operands.push(
      Node.Creator.operator('*', [lastOperand, nextOperand], true));
  }
  // Now we know it isn't a polynomial term, it's just another seperate operand
  else {
    operands.push(lastOperand);
    operands.push(nextOperand);
  }
  return operands;
}
function maybeFlattenPolynomialTerm(node) {
  // We recurse on the left side of the tree to find operands so far
  const operands = getOperands(node.args[0], '*');

  // If the last operand (so far) under * was a constant, then it's a
  // polynomial term.
  // e.g. 2*5*6x creates a tree where the top node is implicit multiplcation
  // and the left branch goes to the tree with 2*5*6, and the right operand
  // is the symbol x. We want to check that the last argument on the left (in
  // this example 6) is a constant.
  const lastOperand = operands.pop();

  // in the above example, node.args[1] would be the symbol x
  const nextOperand = flattenOperands(node.args[1]);

  // a coefficient can be constant or a fraction of constants
  if (Node.Type.isConstantOrConstantFraction(lastOperand)) {
    // we replace the constant (which we popped) with constant*symbol
    operands.push(
      Node.Creator.operator('*', [lastOperand, nextOperand], true));
  }
  // Now we know it isn't a polynomial term, it's just another seperate operand
  else {
    operands.push(lastOperand);
    operands.push(nextOperand);
  }
  return operands;
}
function maybeFlattenPolynomialTerm ( node ) { // We recurse on the left side of the tree to find operands so far const operands = getOperands ( node . args [ 0 ] , '*' ) ; // If the last operand (so far) under * was a constant, then it's a // polynomial term. // e.g. 2*5*6x creates a tree where the top node is implicit multiplcation // and the left branch goes to the tree with 2*5*6, and the right operand // is the symbol x. We want to check that the last argument on the left (in // this example 6) is a constant. const lastOperand = operands . pop ( ) ; // in the above example, node.args[1] would be the symbol x const nextOperand = flattenOperands ( node . args [ 1 ] ) ; // a coefficient can be constant or a fraction of constants if ( Node . Type . isConstantOrConstantFraction ( lastOperand ) ) { // we replace the constant (which we popped) with constant*symbol operands . push ( Node . Creator . operator ( '*' , [ lastOperand , nextOperand ] , true ) ) ; } // Now we know it isn't a polynomial term, it's just another seperate operand else { operands . push ( lastOperand ) ; operands . push ( nextOperand ) ; } return operands ; }
Takes a node that might represent a multiplication with a polynomial term and flattens it appropriately so the coefficient and symbol are grouped together. Returns a new list of operands from this node that should be multiplied together.
Takes a node that might represent a multiplication with a polynomial term and flattens it appropriately so the coefficient and symbol are grouped together . Returns a new list of operands from this node that should be multiplied together .