packages/solver/lib/solveEquation/stepThrough.js
function addSimplificationSteps(steps, equation, debug=false) {
  let oldEquation = equation.clone();

  const leftSteps = simplifyExpressionNode(equation.leftNode, false);
  const leftSubSteps = [];
  for (let i = 0; i < leftSteps.length; i++) {
    const step = leftSteps[i];
    leftSubSteps.push(EquationStatus.addLeftStep(equation, step));
  }
  if (leftSubSteps.length === 1) {
    const step = leftSubSteps[0];
    step.changeType = ChangeTypes.SIMPLIFY_LEFT_SIDE;
    if (debug) {
      logSteps(step);
    }
    steps.push(step);
  }
  else if (leftSubSteps.length > 1) {
    const lastStep = leftSubSteps[leftSubSteps.length - 1];
    const finalEquation = EquationStatus.resetChangeGroups(lastStep.newEquation);
    // no change groups are set here - too much is changing for it to be useful
    const simplifyStatus = new EquationStatus(
      ChangeTypes.SIMPLIFY_LEFT_SIDE,
      oldEquation, finalEquation, leftSubSteps);
    if (debug) {
      logSteps(step);
    }
    steps.push(simplifyStatus);
  }

  // update `equation` to have the new simplified left node
  if (steps.length > 0) {
    equation = EquationStatus.resetChangeGroups(
      steps[steps.length - 1 ].newEquation);
  }

  // the updated equation from simplifing the left side is the old equation
  // (ie the "before" of the before and after) for simplifying the right side.
  oldEquation = equation.clone();

  const rightSteps = simplifyExpressionNode(equation.rightNode, false);
  const rightSubSteps = [];
  for (let i = 0; i < rightSteps.length; i++) {
    const step = rightSteps[i];
    rightSubSteps.push(EquationStatus.addRightStep(equation, step));
  }
  if (rightSubSteps.length === 1) {
    const step = rightSubSteps[0];
    step.changeType = ChangeTypes.SIMPLIFY_RIGHT_SIDE;
    if (debug) {
      logSteps(step);
    }
    steps.push(step);
  }
  else if (rightSubSteps.length > 1) {
    const lastStep = rightSubSteps[rightSubSteps.length - 1];
    const finalEquation = EquationStatus.resetChangeGroups(lastStep.newEquation);
    // no change groups are set here - too much is changing for it to be useful
    const simplifyStatus = new EquationStatus(
     ChangeTypes.SIMPLIFY_RIGHT_SIDE,
     oldEquation, finalEquation, rightSubSteps);
    if (debug) {
      logSteps(simplifyStatus);
    }
    steps.push(simplifyStatus);
  }

  return steps;
}
function addSimplificationSteps(steps, equation, debug=false) {
  let oldEquation = equation.clone();

  const leftSteps = simplifyExpressionNode(equation.leftNode, false);
  const leftSubSteps = [];
  for (let i = 0; i < leftSteps.length; i++) {
    const step = leftSteps[i];
    leftSubSteps.push(EquationStatus.addLeftStep(equation, step));
  }
  if (leftSubSteps.length === 1) {
    const step = leftSubSteps[0];
    step.changeType = ChangeTypes.SIMPLIFY_LEFT_SIDE;
    if (debug) {
      logSteps(step);
    }
    steps.push(step);
  }
  else if (leftSubSteps.length > 1) {
    const lastStep = leftSubSteps[leftSubSteps.length - 1];
    const finalEquation = EquationStatus.resetChangeGroups(lastStep.newEquation);
    // no change groups are set here - too much is changing for it to be useful
    const simplifyStatus = new EquationStatus(
      ChangeTypes.SIMPLIFY_LEFT_SIDE,
      oldEquation, finalEquation, leftSubSteps);
    if (debug) {
      logSteps(step);
    }
    steps.push(simplifyStatus);
  }

  // update `equation` to have the new simplified left node
  if (steps.length > 0) {
    equation = EquationStatus.resetChangeGroups(
      steps[steps.length - 1 ].newEquation);
  }

  // the updated equation from simplifing the left side is the old equation
  // (ie the "before" of the before and after) for simplifying the right side.
  oldEquation = equation.clone();

  const rightSteps = simplifyExpressionNode(equation.rightNode, false);
  const rightSubSteps = [];
  for (let i = 0; i < rightSteps.length; i++) {
    const step = rightSteps[i];
    rightSubSteps.push(EquationStatus.addRightStep(equation, step));
  }
  if (rightSubSteps.length === 1) {
    const step = rightSubSteps[0];
    step.changeType = ChangeTypes.SIMPLIFY_RIGHT_SIDE;
    if (debug) {
      logSteps(step);
    }
    steps.push(step);
  }
  else if (rightSubSteps.length > 1) {
    const lastStep = rightSubSteps[rightSubSteps.length - 1];
    const finalEquation = EquationStatus.resetChangeGroups(lastStep.newEquation);
    // no change groups are set here - too much is changing for it to be useful
    const simplifyStatus = new EquationStatus(
     ChangeTypes.SIMPLIFY_RIGHT_SIDE,
     oldEquation, finalEquation, rightSubSteps);
    if (debug) {
      logSteps(simplifyStatus);
    }
    steps.push(simplifyStatus);
  }

  return steps;
}
function addSimplificationSteps ( steps , equation , debug = false ) { let oldEquation = equation . clone ( ) ; const leftSteps = simplifyExpressionNode ( equation . leftNode , false ) ; const leftSubSteps = [ ] ; for ( let i = 0 ; i < leftSteps . length ; i ++ ) { const step = leftSteps [ i ] ; leftSubSteps . push ( EquationStatus . addLeftStep ( equation , step ) ) ; } if ( leftSubSteps . length === 1 ) { const step = leftSubSteps [ 0 ] ; step . changeType = ChangeTypes . SIMPLIFY_LEFT_SIDE ; if ( debug ) { logSteps ( step ) ; } steps . push ( step ) ; } else if ( leftSubSteps . length > 1 ) { const lastStep = leftSubSteps [ leftSubSteps . length - 1 ] ; const finalEquation = EquationStatus . resetChangeGroups ( lastStep . newEquation ) ; // no change groups are set here - too much is changing for it to be useful const simplifyStatus = new EquationStatus ( ChangeTypes . SIMPLIFY_LEFT_SIDE , oldEquation , finalEquation , leftSubSteps ) ; if ( debug ) { logSteps ( step ) ; } steps . push ( simplifyStatus ) ; } // update `equation` to have the new simplified left node if ( steps . length > 0 ) { equation = EquationStatus . resetChangeGroups ( steps [ steps . length - 1 ] . newEquation ) ; } // the updated equation from simplifing the left side is the old equation // (ie the "before" of the before and after) for simplifying the right side. oldEquation = equation . clone ( ) ; const rightSteps = simplifyExpressionNode ( equation . rightNode , false ) ; const rightSubSteps = [ ] ; for ( let i = 0 ; i < rightSteps . length ; i ++ ) { const step = rightSteps [ i ] ; rightSubSteps . push ( EquationStatus . addRightStep ( equation , step ) ) ; } if ( rightSubSteps . length === 1 ) { const step = rightSubSteps [ 0 ] ; step . changeType = ChangeTypes . SIMPLIFY_RIGHT_SIDE ; if ( debug ) { logSteps ( step ) ; } steps . push ( step ) ; } else if ( rightSubSteps . length > 1 ) { const lastStep = rightSubSteps [ rightSubSteps . length - 1 ] ; const finalEquation = EquationStatus . resetChangeGroups ( lastStep . newEquation ) ; // no change groups are set here - too much is changing for it to be useful const simplifyStatus = new EquationStatus ( ChangeTypes . SIMPLIFY_RIGHT_SIDE , oldEquation , finalEquation , rightSubSteps ) ; if ( debug ) { logSteps ( simplifyStatus ) ; } steps . push ( simplifyStatus ) ; } return steps ; }
Simplifies the equation and returns the simplification steps
Simplifies the equation and returns the simplification steps