lib/simplifyExpression/collectAndCombineSearch/addLikeTerms.js
// belonging to a subclass of Term
belonging to a subclass of Term
belonging to a subclass of Term
function addLikeTermNodes(node, termSubclass, changeType) {
  const substeps = [];
  let newNode = node.cloneDeep();
  let status = addPositiveOneCoefficient(newNode, termSubclass);
  if (status.hasChanged()) {
    substeps.push(status);
    newNode = Node.Status.resetChangeGroups(status.newNode);
  }
  status = addNegativeOneCoefficient(newNode, termSubclass);
  if (status.hasChanged()) {
    substeps.push(status);
    newNode = Node.Status.resetChangeGroups(status.newNode);
  }
  status = groupCoefficientsForAdding(newNode, termSubclass);
  substeps.push(status);
  newNode = Node.Status.resetChangeGroups(status.newNode);
  status = evaluateCoefficientSum(newNode, termSubclass);
  substeps.push(status);
  newNode = Node.Status.resetChangeGroups(status.newNode);
  return Node.Status.nodeChanged(
    changeType, node, newNode, true, substeps);
}
function addLikeTermNodes ( node , termSubclass , changeType ) { const substeps = [ ] ; let newNode = node . cloneDeep ( ) ; let status = addPositiveOneCoefficient ( newNode , termSubclass ) ; if ( status . hasChanged ( ) ) { substeps . push ( status ) ; newNode = Node . Status . resetChangeGroups ( status . newNode ) ; } status = addNegativeOneCoefficient ( newNode , termSubclass ) ; if ( status . hasChanged ( ) ) { substeps . push ( status ) ; newNode = Node . Status . resetChangeGroups ( status . newNode ) ; } status = groupCoefficientsForAdding ( newNode , termSubclass ) ; substeps . push ( status ) ; newNode = Node . Status . resetChangeGroups ( status . newNode ) ; status = evaluateCoefficientSum ( newNode , termSubclass ) ; substeps . push ( status ) ; newNode = Node . Status . resetChangeGroups ( status . newNode ) ; return Node . Status . nodeChanged ( changeType , node , newNode , true , substeps ) ; }
belonging to a subclass of Term
belonging to a subclass of Term
// STEP 1: If any nodes have no coefficient, make it have coefficient 1 // (this step only happens under certain conditions and later steps might // happen even if step 1 does not) // STEP 2: If any nodes have a unary minus, make it have coefficient -1 // (this step only happens under certain conditions and later steps might // happen even if step 2 does not) // STEP 3: group the coefficients in a sum // STEP 4: evaluate the sum (could include fractions)