lib/simplifyExpression/fractionsSearch/simplifyPolynomialFraction.js
// returns the new simplified node in a Node.Status object
returns the new simplified node in a Node.Status object
returns the new simplified node in a Node . Status object
function simplifyPolynomialFraction(node) {
  if (!Node.PolynomialTerm.isPolynomialTerm(node)) {
    return Node.Status.noChange(node);
  }
  const polyNode = new Node.PolynomialTerm(node.cloneDeep());
  if (!polyNode.hasFractionCoeff()) {
    return Node.Status.noChange(node);
  }
  const coefficientSimplifications = [
    divideByGCD, 
    arithmeticSearch, 
  ];
  for (let i = 0; i < coefficientSimplifications.length; i++) {
    const coefficientFraction = polyNode.getCoeffNode(); 
    const newCoeffStatus = coefficientSimplifications[i](coefficientFraction);
    if (newCoeffStatus.hasChanged()) {
      let newCoeff = Node.Status.resetChangeGroups(newCoeffStatus.newNode);
      if (newCoeff.value === '1') {
        newCoeff = null;
      }
      const exponentNode = polyNode.getExponentNode();
      const newNode = Node.Creator.polynomialTerm(
          polyNode.getSymbolNode(), exponentNode, newCoeff);
      return Node.Status.nodeChanged(newCoeffStatus.changeType, node, newNode);
    }
  }
  return Node.Status.noChange(node);
}
function simplifyPolynomialFraction ( node ) { if ( ! Node . PolynomialTerm . isPolynomialTerm ( node ) ) { return Node . Status . noChange ( node ) ; } const polyNode = new Node . PolynomialTerm ( node . cloneDeep ( ) ) ; if ( ! polyNode . hasFractionCoeff ( ) ) { return Node . Status . noChange ( node ) ; } const coefficientSimplifications = [ divideByGCD , arithmeticSearch , ] ; for ( let i = 0 ; i < coefficientSimplifications . length ; i ++ ) { const coefficientFraction = polyNode . getCoeffNode ( ) ; const newCoeffStatus = coefficientSimplifications [ i ] ( coefficientFraction ) ; if ( newCoeffStatus . hasChanged ( ) ) { let newCoeff = Node . Status . resetChangeGroups ( newCoeffStatus . newNode ) ; if ( newCoeff . value === '1' ) { newCoeff = null ; } const exponentNode = polyNode . getExponentNode ( ) ; const newNode = Node . Creator . polynomialTerm ( polyNode . getSymbolNode ( ) , exponentNode , newCoeff ) ; return Node . Status . nodeChanged ( newCoeffStatus . changeType , node , newNode ) ; } } return Node . Status . noChange ( node ) ; }
returns the new simplified node in a Node.Status object
returns the new simplified node in a Node . Status object
// for integer fractions // for decimal fractions // a division node // we need to reset change groups because we're creating a new node