packages/solver/lib/simplifyExpression/stepThrough.js
function step(node) {
  let nodeStatus;

  node = flattenOperands(node);
  node = removeUnnecessaryParens(node, true);

  const simplificationTreeSearches = [
    // Basic simplifications that we always try first e.g. (...)^0 => 1
    basicsSearch,
    // Simplify any division chains so there's at most one division operation.
    // e.g. 2/x/6 -> 2/(x*6)        e.g. 2/(x/6) => 2 * 6/x
    divisionSearch,
    // Adding fractions, cancelling out things in fractions
    fractionsSearch,
    // e.g. 2 + 2 => 4
    arithmeticSearch,
    // e.g. addition: 2x + 4x^2 + x => 4x^2 + 3x
    // e.g. multiplication: 2x * x * x^2 => 2x^3
    collectAndCombineSearch,
    // e.g. (2 + x) / 4 => 2/4 + x/4
    breakUpNumeratorSearch,
    // e.g. 3/x * 2x/5 => (3 * 2x) / (x * 5)
    multiplyFractionsSearch,
    // e.g. (2x + 3)(x + 4) => 2x^2 + 11x + 12
    distributeSearch,
    // e.g. abs(-4) => 4
    functionsSearch,
  ];

  for (let i = 0; i < simplificationTreeSearches.length; i++) {
    nodeStatus = simplificationTreeSearches[i](node);
    // Always update node, since there might be changes that didn't count as
    // a step. Remove unnecessary parens, in case one a step results in more
    // parens than needed.
    node = removeUnnecessaryParens(nodeStatus.newNode, true);
    if (nodeStatus.hasChanged()) {
      node = flattenOperands(node);
      nodeStatus.newNode = clone(node);
      return nodeStatus;
    }
    else {
      node = flattenOperands(node);
    }
  }
  return Node.Status.noChange(node);
}
function step(node) {
  let nodeStatus;

  node = flattenOperands(node);
  node = removeUnnecessaryParens(node, true);

  const simplificationTreeSearches = [
    // Basic simplifications that we always try first e.g. (...)^0 => 1
    basicsSearch,
    // Simplify any division chains so there's at most one division operation.
    // e.g. 2/x/6 -> 2/(x*6)        e.g. 2/(x/6) => 2 * 6/x
    divisionSearch,
    // Adding fractions, cancelling out things in fractions
    fractionsSearch,
    // e.g. 2 + 2 => 4
    arithmeticSearch,
    // e.g. addition: 2x + 4x^2 + x => 4x^2 + 3x
    // e.g. multiplication: 2x * x * x^2 => 2x^3
    collectAndCombineSearch,
    // e.g. (2 + x) / 4 => 2/4 + x/4
    breakUpNumeratorSearch,
    // e.g. 3/x * 2x/5 => (3 * 2x) / (x * 5)
    multiplyFractionsSearch,
    // e.g. (2x + 3)(x + 4) => 2x^2 + 11x + 12
    distributeSearch,
    // e.g. abs(-4) => 4
    functionsSearch,
  ];

  for (let i = 0; i < simplificationTreeSearches.length; i++) {
    nodeStatus = simplificationTreeSearches[i](node);
    // Always update node, since there might be changes that didn't count as
    // a step. Remove unnecessary parens, in case one a step results in more
    // parens than needed.
    node = removeUnnecessaryParens(nodeStatus.newNode, true);
    if (nodeStatus.hasChanged()) {
      node = flattenOperands(node);
      nodeStatus.newNode = clone(node);
      return nodeStatus;
    }
    else {
      node = flattenOperands(node);
    }
  }
  return Node.Status.noChange(node);
}
function step ( node ) { let nodeStatus ; node = flattenOperands ( node ) ; node = removeUnnecessaryParens ( node , true ) ; const simplificationTreeSearches = [ // Basic simplifications that we always try first e.g. (...)^0 => 1 basicsSearch , // Simplify any division chains so there's at most one division operation. // e.g. 2/x/6 -> 2/(x*6)        e.g. 2/(x/6) => 2 * 6/x divisionSearch , // Adding fractions, cancelling out things in fractions fractionsSearch , // e.g. 2 + 2 => 4 arithmeticSearch , // e.g. addition: 2x + 4x^2 + x => 4x^2 + 3x // e.g. multiplication: 2x * x * x^2 => 2x^3 collectAndCombineSearch , // e.g. (2 + x) / 4 => 2/4 + x/4 breakUpNumeratorSearch , // e.g. 3/x * 2x/5 => (3 * 2x) / (x * 5) multiplyFractionsSearch , // e.g. (2x + 3)(x + 4) => 2x^2 + 11x + 12 distributeSearch , // e.g. abs(-4) => 4 functionsSearch , ] ; for ( let i = 0 ; i < simplificationTreeSearches . length ; i ++ ) { nodeStatus = simplificationTreeSearches [ i ] ( node ) ; // Always update node, since there might be changes that didn't count as // a step. Remove unnecessary parens, in case one a step results in more // parens than needed. node = removeUnnecessaryParens ( nodeStatus . newNode , true ) ; if ( nodeStatus . hasChanged ( ) ) { node = flattenOperands ( node ) ; nodeStatus . newNode = clone ( node ) ; return nodeStatus ; } else { node = flattenOperands ( node ) ; } } return Node . Status . noChange ( node ) ; }
Given a mathjs expression node, performs a single step to simplify the expression. Returns a Node.Status object.
Given a mathjs expression node performs a single step to simplify the expression . Returns a Node . Status object .