Adds a list of nodes that are polynomial terms. Returns a Node.Status object.
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);
}
383908
def compute_rpo(self):
        
        nb = len(self.nodes) + 1
        for node in self.post_order():
            node.num = nb - node.po
        self.rpo = sorted(self.nodes, key=lambda n: n.num)
831061
def add_precedence_relations(self):
        
        assert len(self.tokens) > 1, \
            "There are no tokens to add precedence relations to."
        self.add_edge(self.root, self.tokens[0],
                      layers={self.ns, self.ns+':precedence'},
                      edge_type=EdgeTypes.precedence_relation)
        for i, token_node_id in enumerate(self.tokens[1:]):
            # edge from token_n to token_n+1
            self.add_edge(self.tokens[i], token_node_id,
                          layers={self.ns, self.ns+':precedence'},
                          edge_type=EdgeTypes.precedence_relation)
276858
def n_term(self, node):
        """"""
        if len(node) == 1:
            self.preorder(node[0])
            node.value = node[0].value
            self.prune()
        else:
            self.preorder(node[0])
            self.preorder(node[2])
            if node[1].attr == '*':
                node.value = node[0].value * node[2].value
            elif node[1].attr == '/':
                node.value = node[0].value / node[2].value
            else:
                assert False, "Expecting operator to be '*' or '/'"
            self.prune()
        assert False, "Expecting atom to have length 1 or 3"
404874
function getTermsForCollectingAddition(node) {
  let terms = {};

  for(let i = 0; i < node.args.length; i++) {
    const child = node.args[i];

    if (Node.PolynomialTerm.isPolynomialTerm(child)) {
      const termName = getTermName(child, '+');
      terms = Util.appendToArrayInObject(terms, termName, child);
    }
    else if (Node.Type.isIntegerFraction(child)) {
      terms = Util.appendToArrayInObject(terms, CONSTANT_FRACTION, child);
    }
    else if (Node.Type.isConstant(child)) {
      terms = Util.appendToArrayInObject(terms, CONSTANT, child);
    }
    else if (Node.Type.isOperator(node) ||
             Node.Type.isFunction(node) ||
             Node.Type.isParenthesis(node) ||
             Node.Type.isUnaryMinus(node)) {
      terms = Util.appendToArrayInObject(terms, OTHER, child);
    }
    else {
      // Note that we shouldn't get any symbol nodes in the switch statement
      // since they would have been handled by isPolynomialTerm
      throw Error('Unsupported node type: ' + child.type);
    }
  }
  // If there's exactly one constant and one fraction, we collect them
  // to add them together.
  // e.g. 2 + 1/3 + 5 would collect the constants (2+5) + 1/3
  // but 2 + 1/3 + x would collect (2 + 1/3) + x so we can add them together
  if (terms[CONSTANT] && terms[CONSTANT].length === 1 &&
     terms[CONSTANT_FRACTION] && terms[CONSTANT_FRACTION].length === 1) {
    const fraction = terms[CONSTANT_FRACTION][0];
    terms = Util.appendToArrayInObject(terms, CONSTANT, fraction);
    delete terms[CONSTANT_FRACTION];
  }

  return terms;
}
1270384
def add_vertex(self, vertex, **attr):
        
        self.vertices[vertex] = []
        if attr:
            self.nodes[vertex] = attr
        self.pred[vertex] = []
        self.succ[vertex] = []
453213
def iflat_nodes(self, status=None, op="==", nids=None):
        
        nids = as_set(nids)

        if status is None:
            if not (nids and self.node_id not in nids):
                yield self

            for work in self:
                if nids and work.node_id not in nids: continue
                yield work
                for task in work:
                    if nids and task.node_id not in nids: continue
                    yield task
        else:
            # Get the operator from the string.
            op = operator_from_str(op)

            # Accept Task.S_FLAG or string.
            status = Status.as_status(status)

            if not (nids and self.node_id not in nids):
                if op(self.status, status): yield self

            for wi, work in enumerate(self):
                if nids and work.node_id not in nids: continue
                if op(work.status, status): yield work

                for ti, task in enumerate(work):
                    if nids and task.node_id not in nids: continue
                    if op(task.status, status): yield task
549315
def _helper(result,
            graph,
            number_edges_remaining: int,
            node_blacklist: Set[BaseEntity],
            invert_degrees: Optional[bool] = None,
            ):
    
    original_node_count = graph.number_of_nodes()

    log.debug('adding remaining %d edges', number_edges_remaining)
    for _ in range(number_edges_remaining):

        source, possible_step_nodes, c = None, set(), 0
        while not source or not possible_step_nodes:
            source = get_random_node(result, node_blacklist, invert_degrees=invert_degrees)

            c += 1
            if c >= original_node_count:
                log.warning('infinite loop happening')
                log.warning('source: %s', source)
                log.warning('no grow: %s', node_blacklist)
                return  # Happens when after exhausting the connected components. Try increasing the number seed edges

            if source is None:
                continue  # maybe do something else?

            # Only keep targets in the original graph that aren't in the result graph
            possible_step_nodes = set(graph[source]) - set(result[source])

            if not possible_step_nodes:
                node_blacklist.add(
                    source)  # there aren't any possible nodes to step to, so try growing from somewhere else

        step_node = random.choice(list(possible_step_nodes))

        # it's not really a big deal which, but it might be possible to weight this by the utility of edges later
        key, attr_dict = random.choice(list(graph[source][step_node].items()))

        result.add_edge(source, step_node, key=key, **attr_dict)
894611
def composition
      root_terms.reduce(SignedMultiset.new) do |s, t|
        s.increment(t.atom.dim, t.exponent) if t.atom
        s
      end
    end
796625
def get_all_nodes(self, simrun_addr, stmt_idx):
        
        nodes=[]
        for n in self.graph.nodes():
            if n.simrun_addr == simrun_addr and n.stmt_idx == stmt_idx:
                nodes.add(n)
        return nodes
203750
def __push_facvar_sparse(self, polynomial, block_index, row_offset, i, j):
        
        width = self.block_struct[block_index - 1]
        # Preprocess the polynomial for uniform handling later
        # DO NOT EXPAND THE POLYNOMIAL HERE!!!!!!!!!!!!!!!!!!!
        # The simplify_polynomial bypasses the problem.
        # Simplifying here will trigger a bug in SymPy related to
        # the powers of daggered variables.
        # polynomial = polynomial.expand()
        if is_number_type(polynomial) or polynomial.is_Mul:
            elements = [polynomial]
        else:
            elements = polynomial.as_coeff_mul()[1][0].as_coeff_add()[1]
        # Identify its constituent monomials
        for element in elements:
            results = self._get_index_of_monomial(element)
            # k identifies the mapped value of a word (monomial) w
            for (k, coeff) in results:
                if k > -1 and coeff != 0:
                    self.F[row_offset + i * width + j, k] += coeff
566589
@Override
	public boolean addAll(Collection<? extends BooleanTerm> terms) {
		boolean modified = false;
		// a null booleanTerms means that the expression is
		// already true, so no need to modify it
		if (terms == null) {
			modified = booleanTerms != null;
			booleanTerms = null;
		} else if (booleanTerms != null) {
			for (BooleanTerm term : terms) {
				modified |= add(term);
			}
		}
		return modified;
	}
126368
function canMultiplyLikeTermPolynomialNodes(node) {
  if (!Node.Type.isOperator(node) || node.op !== '*') {
    return false;
  }
  const args = node.args;
  if (!args.every(n => Node.PolynomialTerm.isPolynomialTerm(n))) {
    return false;
  }
  if (args.length === 1) {
    return false;
  }

  const polynomialTermList = node.args.map(n => new Node.PolynomialTerm(n));
  if (!polynomialTermList.every(polyTerm => !polyTerm.hasCoeff())) {
    return false;
  }

  const firstTerm = polynomialTermList[0];
  const restTerms = polynomialTermList.slice(1);
  // they're considered like terms if they have the same symbol name
  return restTerms.every(term => firstTerm.getSymbolName() === term.getSymbolName());
}
362157
def add_vertex(self, vertex, **attr):
        
        self.vertices[vertex] = []
        if attr:
            self.nodes[vertex] = attr
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)
193327
def points(self):
        ''''''
        # add all points in a section except the first one, which is a duplicate
        _pts = [v for s in self.root_node.ipreorder()
                for v in s.points[1:, COLS.XYZR]]
        # except for the very first point, which is not a duplicate
        _pts.insert(0, self.root_node.points[0][COLS.XYZR])
        return np.array(_pts)
264026
function collectExponents(node) {
  const polynomialTermList = node.args.map(n => new Node.PolynomialTerm(n));

  // If we're multiplying polynomial nodes together, they all share the same
  // symbol. Get that from the first node.
  const symbolNode = polynomialTermList[0].getSymbolNode();

  // The new exponent will be a sum of exponents (an operation, wrapped in
  // parens) e.g. x^(3+4+5)
  const exponentNodeList = polynomialTermList.map(p => p.getExponentNode(true));
  const newExponent = Node.Creator.parenthesis(
    Node.Creator.operator('+', exponentNodeList));
  const newNode = Node.Creator.polynomialTerm(symbolNode, newExponent, null);
  return Node.Status.nodeChanged(
    ChangeTypes.COLLECT_EXPONENTS, node, newNode);
}