If `node` is a product of terms where some are fractions (but none are polynomial terms), multiplies them together. e.g. 2 * 5/x -> (2*5)/x e.g. 3 * 1/5 * 5/9 = (3*1*5)/(5*9) Returns a Node.Status object.
422285
function multiplyFractions(node) {
  if (!Node.Type.isOperator(node) || node.op !== '*') {
    return Node.Status.noChange(node);
  }
  const atLeastOneFraction = node.args.some(
    arg => Node.Type.isOperator(arg, '/'));
  const hasPolynomialTerms = node.args.some(
    arg => Node.PolynomialTerm.isPolynomialTerm(arg));
  if (!atLeastOneFraction || hasPolynomialTerms) {
    return Node.Status.noChange(node);
  }

  const numeratorArgs = [];
  const denominatorArgs = [];
  node.args.forEach(operand => {
    if (Node.Type.isOperator(operand, '/')) {
      numeratorArgs.push(operand.args[0]);
      denominatorArgs.push(operand.args[1]);
    }
    else {
      numeratorArgs.push(operand);
    }
  });

  const newNumerator = Node.Creator.parenthesis(
    Node.Creator.operator('*', numeratorArgs));
  const newDenominator = denominatorArgs.length === 1
    ? denominatorArgs[0]
    : Node.Creator.parenthesis(Node.Creator.operator('*', denominatorArgs));

  const newNode = Node.Creator.operator('/', [newNumerator, newDenominator]);
  return Node.Status.nodeChanged(
    ChangeTypes.MULTIPLY_FRACTIONS, node, newNode);
}
1141942
public float multipliedBy (Fraction fraction)
  {
    int newNumerator = numerator * fraction.getNumerator();
    int newDenominator = denominator * fraction.getDenominator();
    return (newNumerator/newDenominator);
  }
509629
function addLikeTerms(node, polynomialOnly=false) {
  if (!Node.Type.isOperator(node)) {
    return Node.Status.noChange(node);
  }
  let status;

  if (!polynomialOnly) {
    status = evaluateConstantSum(node);
    if (status.hasChanged()) {
      return status;
    }
  }

  status = addLikePolynomialTerms(node);
  if (status.hasChanged()) {
    return status;
  }

  return Node.Status.noChange(node);
}
272065
def visit_BoolOp(self, node):
        
        return sum((self.visit(value) for value in node.values), [])
1222568
def Xor(*xs, simplify=True):
    
    xs = [Expression.box(x).node for x in xs]
    y = exprnode.xor(*xs)
    if simplify:
        y = y.simplify()
    return _expr(y)
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);
  }
}
723176
public static float getHypothesis(Network bn, String nodeName, String status)
            throws ShanksException {
        int node = ShanksAgentBayesianReasoningCapability.getNode(bn, nodeName);
        String[] states = bn.getOutcomeIds(node);
        for (int i = 0; i < states.length; i++) {
            if (status.equals(states[i])) {
                return (float) bn.getNodeValue(node)[i];
            }
        }
        throw new UnknowkNodeStateException(bn, nodeName, status);
    }
261986
function convertMultiplicationToExponent(node) {
  const newNode = clone(node);

  const radicandNode = getRadicandNode(node);

  if (Node.Type.isParenthesis(radicandNode)) {
    const child = radicandNode.content;
    if (isMultiplicationOfEqualNodes(child)) {
      const baseNode = child.args[0];
      const exponentNode = Node.Creator.constant(child.args.length);
      newNode.args[0] = Node.Creator.operator('^', [baseNode, exponentNode]);
      return Node.Status.nodeChanged(
        ChangeTypes.CONVERT_MULTIPLICATION_TO_EXPONENT, node, newNode);
    }
  }
  else if (Node.Type.isOperator(radicandNode, '*')) {
    const children = [];
    radicandNode.args.forEach(child => {
      if (Node.Type.isParenthesis(child)) {
        const grandChild = child.content;
        if (isMultiplicationOfEqualNodes(grandChild)) {
          const baseNode = grandChild.args[0];
          const exponentNode = Node.Creator.constant(grandChild.args.length);
          children.push(Node.Creator.operator('^', [baseNode, exponentNode]));
          return;
        }
      }
      children.push(child);
    });

    newNode.args[0] = Node.Creator.operator('*', children);
    return Node.Status.nodeChanged(
      ChangeTypes.CONVERT_MULTIPLICATION_TO_EXPONENT, node, newNode);
  }

  return Node.Status.noChange(node);
}
211726
function nthRootConstant(node) {
  let newNode = clone(node);
  const radicandNode = getRadicandNode(node);
  const rootNode = getRootNode(node);

  if (Negative.isNegative(radicandNode)) {
    return Node.Status.noChange(node);
  }
  else if (!Node.Type.isConstant(rootNode) || Negative.isNegative(rootNode)) {
    return Node.Status.noChange(node);
  }

  const radicandValue = parseFloat(radicandNode.value);
  const rootValue = parseFloat(rootNode.value);
  const nthRootValue = math.nthRoot(radicandValue, rootValue);
  // Perfect root e.g. nthRoot(4, 2) = 2
  if (nthRootValue % 1 === 0) {
    newNode = Node.Creator.constant(nthRootValue);
    return Node.Status.nodeChanged(
      ChangeTypes.NTH_ROOT_VALUE, node, newNode);
  }
  // Try to find if we can simplify by finding factors that can be
  // pulled out of the radical
  else {
    // convert the number into the product of its prime factors
    const factors = ConstantFactors.getPrimeFactors(radicandValue);
    if (factors.length > 1) {
      let substeps = [];
      const factorNodes = factors.map(Node.Creator.constant);

      newNode.args[0] = Node.Creator.operator('*', factorNodes);
      substeps.push(Node.Status.nodeChanged(
          ChangeTypes.FACTOR_INTO_PRIMES, node, newNode));

      // run nthRoot on the new node
      const nodeStatus = nthRootMultiplication(newNode);
      if (nodeStatus.hasChanged()) {
        substeps = substeps.concat(nodeStatus.substeps);
        newNode = nodeStatus.newNode;

        return Node.Status.nodeChanged(
          ChangeTypes.NTH_ROOT_VALUE, node, newNode, true, substeps);
      }
    }
  }

  return Node.Status.noChange(node);
}
934520
function distributeUnaryMinus(node) {
  if (!Node.Type.isUnaryMinus(node)) {
    return Node.Status.noChange(node);
  }
  const unaryContent = node.args[0];
  if (!Node.Type.isParenthesis(unaryContent)) {
    return Node.Status.noChange(node);
  }
  const content = unaryContent.content;
  if (!Node.Type.isOperator(content)) {
    return Node.Status.noChange(node);
  }
  const newContent = clone(content);
  node.changeGroup = 1;
  // For multiplication and division, we can push the unary minus in to
  // the first argument.
  // e.g. -(2/3) -> (-2/3)    -(4*9*x^2) --> (-4 * 9  * x^2)
  if (content.op === '*' || content.op === '/') {
    newContent.args[0] = Negative.negate(newContent.args[0]);
    newContent.args[0].changeGroup = 1;
    const newNode = Node.Creator.parenthesis(newContent);
    return Node.Status.nodeChanged(
      ChangeTypes.DISTRIBUTE_NEGATIVE_ONE, node, newNode, false);
  }
  else if (content.op === '+') {
    // Now we know `node` is of the form -(x + y + ...).
    // We want to now return (-x + -y + ....)
    // If any term is negative, we make it positive it right away
    // e.g. -(2-4) => -2 + 4
    const newArgs = newContent.args.map(arg => {
      const newArg = Negative.negate(arg);
      newArg.changeGroup = 1;
      return newArg;
    });
    newContent.args = newArgs;
    const newNode = Node.Creator.parenthesis(newContent);
    return Node.Status.nodeChanged(
      ChangeTypes.DISTRIBUTE_NEGATIVE_ONE, node, newNode, false);
  }
  else {
    return Node.Status.noChange(node);
  }
}
705566
function isMultiplicationOfTerms(node) {
  if (Node.Type.isParenthesis(node)) {
    return isMultiplicationOfTerms(node.content);
  }
  return (Node.Type.isOperator(node, '*') &&
          !Node.PolynomialTerm.isPolynomialTerm(node));
}
39090
def simplify(self):
        """"""
        node = self.node.simplify()
        if node is self.node:
            return self
        else:
            return _expr(node)
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)
1117786
function() {
    var op
      , node = this.additive();
    if (op = this.accept('...') || this.accept('..')) {
      this.operand = true;
      if (!node) this.error('illegal unary "' + op + '", missing left-hand operand');
      node = new nodes.BinOp(op.val, node, this.additive());
      this.operand = false;
    }
    return node;
  }
744601
def _old_forney(self, omega, X, k=None):
        ''''''
        # XXX Is floor division okay here? Should this be ceiling?
        if not k: k = self.k
        t = (self.n - k) // 2

        Y = []

        for l, Xl in enumerate(X):

            # Compute the sequence product and multiply its inverse in
            prod = GF2int(1) # just to init the product (1 is the neutral term for multiplication)
            Xl_inv = Xl.inverse()
            for ji in _range(t): # do not change to _range(len(X)) as can be seen in some papers, it won't give the correct result! (sometimes yes, but not always)
                if ji == l:
                    continue
                if ji < len(X):
                    Xj = X[ji]
                else: # if above the maximum degree of the polynomial, then all coefficients above are just 0 (that's logical...)
                    Xj = GF2int(0)
                prod = prod * (Xl - Xj)
                #if (ji != l):
                #    prod = prod * (GF2int(1) - X[ji]*(Xl.inverse()))

            # Compute Yl
            Yl = Xl**t * omega.evaluate(Xl_inv) * Xl_inv * prod.inverse()

            Y.append(Yl)
        return Y
678524
def NHot(n, *xs, simplify=True):
    
    if not isinstance(n, int):
        raise TypeError("expected n to be an int")
    if not 0 <= n <= len(xs):
        fstr = "expected 0 <= n <= {}, got {}"
        raise ValueError(fstr.format(len(xs), n))

    xs = [Expression.box(x).node for x in xs]
    num = len(xs)
    terms = list()
    for hot_idxs in itertools.combinations(range(num), n):
        hot_idxs = set(hot_idxs)
        _xs = [xs[i] if i in hot_idxs else exprnode.not_(xs[i])
               for i in range(num)]
        terms.append(exprnode.and_(*_xs))
    y = exprnode.or_(*terms)
    if simplify:
        y = y.simplify()
    return _expr(y)
283723
def expr(self):
        
        node = self.term()

        while self.token.nature in (Nature.PLUS, Nature.MINUS):
            token = self.token
            if token.nature == Nature.PLUS:
                self._process(Nature.PLUS)
            elif token.nature == Nature.MINUS:
                self._process(Nature.MINUS)
            else:
                self._error()

            node = BinaryOperation(left=node, op=token, right=self.term())

        return node