If `node` is a fraction with a numerator that is a sum, breaks up the fraction e.g. (2+x)/5 -> (2/5 + x/5) Returns a Node.Status object
549456
function breakUpNumerator(node) {
  if (!Node.Type.isOperator(node) || node.op !== '/') {
    return Node.Status.noChange(node);
  }
  let numerator = node.args[0];
  if (Node.Type.isParenthesis(numerator)) {
    numerator = numerator.content;
  }
  if (!Node.Type.isOperator(numerator) || numerator.op !== '+') {
    return Node.Status.noChange(node);
  }

  // At this point, we know that node is a fraction and its numerator is a sum
  // of terms that can't be collected or combined, so we should break it up.
  const fractionList = [];
  const denominator = node.args[1];
  numerator.args.forEach(arg => {
    const newFraction = Node.Creator.operator('/', [arg, denominator]);
    newFraction.changeGroup = 1;
    fractionList.push(newFraction);
  });

  let newNode = Node.Creator.operator('+', fractionList);
  // Wrap in parens for cases like 2*(2+3)/5 => 2*(2/5 + 3/5)
  newNode = Node.Creator.parenthesis(newNode);
  node.changeGroup = 1;
  return Node.Status.nodeChanged(
    ChangeTypes.BREAK_UP_FRACTION, node, newNode, false);
}
368505
function arithmetic(node) {
  if (!Node.Type.isOperator(node)) {
    return Node.Status.noChange(node);
  }
  if (!node.args.every(child => Node.Type.isConstant(child, true))) {
    return Node.Status.noChange(node);
  }

  // we want to eval each arg so unary minuses around constant nodes become
  // constant nodes with negative values
  node.args.forEach((arg, i) => {
    node.args[i] = Node.Creator.constant(arg.eval());
  });

  // Only resolve division of integers if we get an integer result.
  // Note that a fraction of decimals will be divided out.
  if (Node.Type.isIntegerFraction(node)) {
    const numeratorValue = parseInt(node.args[0]);
    const denominatorValue = parseInt(node.args[1]);
    if (numeratorValue % denominatorValue === 0) {
      const newNode = Node.Creator.constant(numeratorValue/denominatorValue);
      return Node.Status.nodeChanged(
        ChangeTypes.SIMPLIFY_ARITHMETIC, node, newNode);
    }
    else {
      return Node.Status.noChange(node);
    }
  }
  else {
    const evaluatedValue = evaluateAndRound(node);
    const newNode = Node.Creator.constant(evaluatedValue);
    return Node.Status.nodeChanged(ChangeTypes.SIMPLIFY_ARITHMETIC, node, newNode);
  }
}
256033
def get_node_age_sum(self, age=None):
        
        if age is None:
            age = self.age

        return pow(self.comp, age)
357694
def Xnor(*xs, simplify=True):
    
    xs = [Expression.box(x).node for x in xs]
    y = exprnode.not_(exprnode.xor(*xs))
    if simplify:
        y = y.simplify()
    return _expr(y)
33098
def split(self, frac):
        
        from .. import preprocess
        split_obj = getattr(preprocess, '_Split')(fraction=frac)
        return split_obj.transform(self)
280718
function processMultiplyDivide(tokenizer, scope) {
  let node = processUnary(tokenizer, scope);

  while (tokenizer.token.match(types.MULTIPLY_DIVIDE)) {
    node = createOperatorNode(tokenizer.token.value, [node, processUnary(tokenizer.skipToken(), scope)]);
  }

  return node;
}
1029411
private static boolean isDistinct(AggregationNode node)
    {
        return node.getAggregations().isEmpty() &&
                node.getOutputSymbols().size() == node.getGroupingKeys().size() &&
                node.getOutputSymbols().containsAll(node.getGroupingKeys());
    }
357124
function removeUnnecessaryParens(node, rootNode=false) {
  // Parens that wrap everything are redundant.
  // NOTE: removeUnnecessaryParensSearch recursively removes parens that aren't
  // needed, while this step only applies to the very top level expression.
  // e.g. (2 + 3) * 4 can't become 2 + 3 * 4, but if (2 + 3) as a top level
  // expression can become 2 + 3
  if (rootNode) {
    while (Node.Type.isParenthesis(node)) {
      node = node.content;
    }
  }
  return removeUnnecessaryParensSearch(node);
}
180822
def _do_pi(self, node):
        '''
        '''
        if not _in_subset(self.subset, node): return
        W = self.write
        if self.documentOrder == _GreaterElement: W('\n')
        W('<?')
        W(node.nodeName)
        s = node.data
        if s:
            W(' ')
            W(s)
        W('?>')
        if self.documentOrder == _LesserElement: W('\n')
1041566
def parse(node)
      node.xpath('*').each do |node_child|
        case node_child.name
        when 'r'
          @formula_run << MathRun.new(parent: self).parse(node_child)
        when 'box', 'borderBox'
          @formula_run << Box.new(parent: self).parse(node_child)
        when 'func'
          @formula_run << Function.new(parent: self).parse(node_child)
        when 'rad'
          @formula_run << Radical.new(parent: self).parse(node_child)
        when 'e', 'eqArr'
          @formula_run << DocxFormula.new(parent: self).parse(node_child)
        when 'nary'
          @formula_run << Nary.new(parent: self).parse(node_child)
        when 'd'
          @formula_run << Delimiter.new(parent: self).parse(node_child)
        when 'sSubSup', 'sSup', 'sSub'
          @formula_run << Index.new(parent: self).parse(node_child)
        when 'f'
          @formula_run << Fraction.new(parent: self).parse(node_child)
        when 'm'
          @formula_run << Matrix.new(parent: self).parse(node_child)
        when 'bar'
          @formula_run << Bar.new(parent: self).parse(node_child)
        when 'acc'
          @formula_run << Accent.new(parent: self).parse(node_child)
        when 'groupChr'
          @formula_run << GroupChar.new(parent: self).parse(node_child)
        when 'argPr'
          @argument_properties = ArgumentProperties.new(parent: self).parse(node_child)
        when 'sPre'
          @formula_run << PreSubSuperscript.new(parent: self).parse(node_child)
        when 'limUpp', 'limLow'
          @formula_run << Limit.new(parent: self).parse(node_child)
        end
      end
      return nil if @formula_run.empty?

      self
    end
303500
public static float getHypothesis(ProbabilisticNetwork bn, String nodeName,
            String status) throws ShanksException {
        ProbabilisticNode node = ShanksAgentBayesianReasoningCapability
                .getNode(bn, nodeName);
        int states = node.getStatesSize();
        for (int i = 0; i < states; i++) {
            if (status.equals(node.getStateAt(i))) {
                return node.getMarginalAt(i);
            }
        }
        throw new UnknowkNodeStateException(bn, nodeName, status);
    }
895082
def Majority(*xs, simplify=True, conj=False):
    
    xs = [Expression.box(x).node for x in xs]
    if conj:
        terms = list()
        for _xs in itertools.combinations(xs, (len(xs) + 1) // 2):
            terms.append(exprnode.or_(*_xs))
        y = exprnode.and_(*terms)
    else:
        terms = list()
        for _xs in itertools.combinations(xs, len(xs) // 2 + 1):
            terms.append(exprnode.and_(*_xs))
        y = exprnode.or_(*terms)
    if simplify:
        y = y.simplify()
    return _expr(y)
1302772
function fractionDigits(number) {
  var splitArr = number.toString().split('.');
  return (splitArr.length > 1) ?
    splitArr[1].length :
    0;
}
318560
function simplifySigns(fraction) {
  if (!Node.Type.isOperator(fraction) || fraction.op !== '/') {
    return Node.Status.noChange(fraction);
  }
  const oldFraction = clone(fraction);
  let numerator = fraction.args[0];
  let denominator = fraction.args[1];
  // The denominator should never be negative.
  if (Negative.isNegative(denominator)) {
    denominator = Negative.negate(denominator);
    const changeType = Negative.isNegative(numerator) ?
      ChangeTypes.CANCEL_MINUSES :
      ChangeTypes.SIMPLIFY_SIGNS;
    numerator = Negative.negate(numerator);
    const newFraction = Node.Creator.operator('/', [numerator, denominator]);
    return Node.Status.nodeChanged(changeType, oldFraction, newFraction);
  }
  else {
    return Node.Status.noChange(fraction);
  }
}
1275017
function cancelLikeTerms(node) {
  if (!Node.Type.isOperator(node) || node.op !== '/') {
    return Node.Status.noChange(node);
  }
  let newNode = clone(node);
  const numerator = newNode.args[0];
  const denominator = newNode.args[1];

  // case 1: neither the numerator or denominator is a multiplication of terms
  if (!isMultiplicationOfTerms(numerator) &&
      !isMultiplicationOfTerms(denominator)) {
    const cancelStatus = cancelTerms(numerator, denominator);
    if (cancelStatus.hasChanged) {
      newNode.args[0] = cancelStatus.numerator || Node.Creator.constant(1);
      if (cancelStatus.denominator) {
        newNode.args[1] = cancelStatus.denominator;
      }
      else {
        // If we cancelled out the denominator, the node is now its numerator
        // e.g. (2x*y) / 2x => y (note y isn't a fraction)
        newNode = newNode.args[0];
      }
      return Node.Status.nodeChanged(
        ChangeTypes.CANCEL_TERMS, node, newNode);
    }
    else {
      return Node.Status.noChange(node);
    }
  }

  // case 2: numerator is a multiplication of terms and denominator is not
  // e.g. (2x^2 * 5) / 2x^2 => 5 / 1
  // e.g. (x^2*y) / x  => x^(2 - 1) * y (<-- note that the denominator goes
  // away because we always adjust the exponent in the numerator)
  else if (isMultiplicationOfTerms(numerator) &&
      !isMultiplicationOfTerms(denominator)) {
    const numeratorArgs = Node.Type.isParenthesis(numerator) ?
            numerator.content.args : numerator.args;
    for (let i = 0; i < numeratorArgs.length; i++) {
      const cancelStatus = cancelTerms(numeratorArgs[i], denominator);
      if (cancelStatus.hasChanged) {
        if (cancelStatus.numerator) {
          numeratorArgs[i] = cancelStatus.numerator;
        }
        // if the cancelling out got rid of the numerator node, we remove it from
        // the list
        else {
          numeratorArgs.splice(i, 1);
          // if the numerator is now a "multiplication" of only one term,
          // change it to just that term
          if (numeratorArgs.length === 1) {
            newNode.args[0] = numeratorArgs[0];
          }
        }
        if (cancelStatus.denominator) {
          newNode.args[1] = cancelStatus.denominator;
        }
        else {
          // If we cancelled out the denominator, the node is now its numerator
          // e.g. (2x*y) / 2x => y (note y isn't a fraction)
          newNode = newNode.args[0];
        }
        return Node.Status.nodeChanged(
          ChangeTypes.CANCEL_TERMS, node, newNode);
      }
    }
    return Node.Status.noChange(node);
  }

  // case 3: denominator is a multiplication of terms and numerator is not
  // e.g. 2x^2 / (2x^2 * 5) => 1 / 5
  // e.g. x / (x^2*y) => x^(1-2) / y
  else if (isMultiplicationOfTerms(denominator) &&
      !isMultiplicationOfTerms(numerator)) {
    const denominatorArgs = Node.Type.isParenthesis(denominator) ?
            denominator.content.args : denominator.args;
    for (let i = 0; i < denominatorArgs.length; i++) {
      const cancelStatus = cancelTerms(numerator, denominatorArgs[i]);
      if (cancelStatus.hasChanged) {
        newNode.args[0] = cancelStatus.numerator || Node.Creator.constant(1);
        if (cancelStatus.denominator) {
          denominatorArgs[i] = cancelStatus.denominator;
        }
        // if the cancelling out got rid of the denominator node, we remove it
        // from the list
        else {
          denominatorArgs.splice(i, 1);
          // if the denominator is now a "multiplication" of only one term,
          // change it to just that term
          if (denominatorArgs.length === 1) {
            newNode.args[1] = denominatorArgs[0];
          }
        }
        return Node.Status.nodeChanged(
          ChangeTypes.CANCEL_TERMS, node, newNode);
      }
    }
    return Node.Status.noChange(node);
  }

  // case 4: the numerator and denominator are both multiplications of terms
  else {
    const numeratorArgs = Node.Type.isParenthesis(numerator) ?
      numerator.content.args : numerator.args;
    const denominatorArgs = Node.Type.isParenthesis(denominator) ?
      denominator.content.args : denominator.args;
    for (let i = 0; i < numeratorArgs.length; i++) {
      for (let j = 0; j < denominatorArgs.length; j++) {
        const cancelStatus = cancelTerms(numeratorArgs[i], denominatorArgs[j]);
        if (cancelStatus.hasChanged) {
          if (cancelStatus.numerator) {
            numeratorArgs[i] = cancelStatus.numerator;
          }
          // if the cancelling out got rid of the numerator node, we remove it
          // from the list
          else {
            numeratorArgs.splice(i, 1);
            // if the numerator is now a "multiplication" of only one term,
            // change it to just that term
            if (numeratorArgs.length === 1) {
              newNode.args[0] = numeratorArgs[0];
            }
          }
          if (cancelStatus.denominator) {
            denominatorArgs[j] = cancelStatus.denominator;
          }
          // if the cancelling out got rid of the denominator node, we remove it
          // from the list
          else {
            denominatorArgs.splice(j, 1);
            // if the denominator is now a "multiplication" of only one term,
            // change it to just that term
            if (denominatorArgs.length === 1) {
              newNode.args[1] = denominatorArgs[0];
            }
          }
          return Node.Status.nodeChanged(
            ChangeTypes.CANCEL_TERMS, node, newNode);
        }
      }
    }
    return Node.Status.noChange(node);
  }
}
118430
def fmt_part(part, node_labels=None):
    
    def nodes(x):  # pylint: disable=missing-docstring
        return ','.join(labels(x, node_labels)) if x else EMPTY_SET

    numer = nodes(part.mechanism)
    denom = nodes(part.purview)

    width = max(3, len(numer), len(denom))
    divider = HORIZONTAL_BAR * width

    return (
        '{numer:^{width}}\n'
        '{divider}\n'
        '{denom:^{width}}'
    ).format(numer=numer, divider=divider, denom=denom, width=width)
616450
function checkNum( nodes ) {
         for ( var i = 0, ci; ci = nodes[i++]; ) {
             var value = ci.value;
             if ( !isNumber( value ) && value) {
                 alert( lang.numError );
                 ci.value = "";
                 ci.focus();
                 return false;
             }
         }
         return true;
     }