Find real roots for the specified polynomial.

@param poly Polynomial which has less than or equal to the number of coefficients specified in this class's
constructor.
183071
public void process( Polynomial poly ) {
		sturm.initialize(poly);

		if( searchRadius <= 0 )
			numRoots = sturm.countRealRoots(Double.NEGATIVE_INFINITY,Double.POSITIVE_INFINITY);
		else
			numRoots = sturm.countRealRoots(-searchRadius,searchRadius);

		if( numRoots == 0 )
			return;

		if( searchRadius <= 0 )
			handleAllRoots();
		else {
			boundEachRoot(-searchRadius,searchRadius,0,numRoots);
		}

		// improve the accuracy
		for( int i = 0; i < numRoots; i++ ) {
			roots[i] = PolynomialOps.refineRoot(poly, roots[i], maxRefineIterations);
		}
	}
29153
def gf_poly_mul(p, q):
    ''''''
    # Pre-allocate the result array
    r = bytearray(len(p) + len(q) - 1)
    # Precompute the logarithm of p
    lp = [gf_log[p[i]] for i in xrange(len(p))]
    # Compute the polynomial multiplication (just like the outer product of two vectors, we multiply each coefficients of p with all coefficients of q)
    for j in xrange(len(q)):
        qj = q[j] # optimization: load the coefficient once
        if qj != 0: # log(0) is undefined, we need to check that
            lq = gf_log[qj] # Optimization: precache the logarithm of the current coefficient of q
            for i in xrange(len(p)):
                if p[i] != 0: # log(0) is undefined, need to check that...
                    r[i + j] ^= gf_exp[lp[i] + lq] # equivalent to: r[i + j] = gf_add(r[i+j], gf_mul(p[i], q[j]))
    return r
362568
def polynomial_reduce_mod( poly, polymod, p ):
  """"""

  # This module has been tested only by extensive use
  # in calculating modular square roots.

  # Just to make this easy, require a monic polynomial:
  assert polymod[-1] == 1

  assert len( polymod ) > 1

  while len( poly ) >= len( polymod ):
    if poly[-1] != 0:
      for i in range( 2, len( polymod ) + 1 ):
        poly[-i] = ( poly[-i] - poly[-1] * polymod[-i] ) % p
    poly = poly[0:-1]

  return poly
56649
function reduceMultiplicationByZero(node) {
  if (node.op !== '*') {
    return Node.Status.noChange(node);
  }
  const zeroIndex = node.args.findIndex(arg => {
    if (Node.Type.isConstant(arg) && arg.value === '0') {
      return true;
    }
    if (Node.PolynomialTerm.isPolynomialTerm(arg)) {
      const polyTerm = new Node.PolynomialTerm(arg);
      return polyTerm.getCoeffValue() === 0;
    }
    return false;
  });
  if (zeroIndex >= 0) {
    // reduce to just the 0 node
    const newNode = Node.Creator.constant(0);
    return Node.Status.nodeChanged(
      ChangeTypes.MULTIPLY_BY_ZERO, node, newNode);
  }
  else {
    return Node.Status.noChange(node);
  }
}
962576
function(symbol, factors) {
                if(symbol.isConstant() || symbol.group === S) return symbol;
                var poly = new Polynomial(symbol),
                    cnst = poly.coeffs[0],
                    cfactors = core.Math2.ifactor(cnst),
                    roots = __.proots(symbol);
                for(var i=0; i<roots.length; i++) {
                    var r = roots[i],
                        p = 1;
                    if(!isNaN(r)) { //if it's a number
                        for(var x in cfactors) {
                            //check it's raised to a power
                            var n = core.Utils.round(Math.log(x)/Math.log(Math.abs(r)), 8);
                            if(isInt(n)) {
                                r = x; //x must be the root since n gave us a whole
                                p = n; break;
                            }
                        }
                        var root = new Frac(r),
                            terms = [new Frac(root.num).negate()];
                        terms[p] = new Frac(root.den);
                            //convert to Frac. The den is coeff of LT and the num is coeff of constant
                        var div = Polynomial.fromArray(terms, poly.variable).fill(),
                            t = poly.divide(div);
                        if(t[1].equalsNumber(0)) { //if it's zero we have a root and divide it out
                            poly = t[0];
                            factors.add(div.toSymbol());
                        }
                    }
                }
                if(!poly.equalsNumber(1)) {
                    poly = __.Factor.search(poly, factors);
                }
                return poly.toSymbol();
            }
837795
def gf_poly_div(dividend, divisor):
    ''''''
    # CAUTION: this function expects polynomials to follow the opposite convention at decoding: the terms must go from the biggest to lowest degree (while most other functions here expect a list from lowest to biggest degree). eg: 1 + 2x + 5x^2 = [5, 2, 1], NOT [1, 2, 5]

    msg_out = bytearray(dividend) # Copy the dividend list and pad with 0 where the ecc bytes will be computed
    #normalizer = divisor[0] # precomputing for performance
    for i in xrange(len(dividend) - (len(divisor)-1)):
        #msg_out[i] /= normalizer # for general polynomial division (when polynomials are non-monic), the usual way of using synthetic division is to divide the divisor g(x) with its leading coefficient (call it a). In this implementation, this means:we need to compute: coef = msg_out[i] / gen[0]. For more infos, see http://en.wikipedia.org/wiki/Synthetic_division
        coef = msg_out[i] # precaching
        if coef != 0: # log(0) is undefined, so we need to avoid that case explicitly (and it's also a good optimization). In fact if you remove it, it should still work because gf_mul() will take care of the condition. But it's still a good practice to put the condition here.
            for j in xrange(1, len(divisor)): # in synthetic division, we always skip the first coefficient of the divisior, because it's only used to normalize the dividend coefficient
                if divisor[j] != 0: # log(0) is undefined
                    msg_out[i + j] ^= gf_mul(divisor[j], coef) # equivalent to the more mathematically correct (but xoring directly is faster): msg_out[i + j] += -divisor[j] * coef

    # The resulting msg_out contains both the quotient and the remainder, the remainder being the size of the divisor (the remainder has necessarily the same degree as the divisor -- not length but degree == length-1 -- since it's what we couldn't divide from the dividend), so we compute the index where this separation is, and return the quotient and remainder.
    separator = -(len(divisor)-1)
    return msg_out[:separator], msg_out[separator:]
972000
public void mainFindBestValEntropy(Node root) {
		if (root != null) {
			DoubleVector parentClassCL = new DoubleVector();
			DoubleVector classCountL = root.classCountsLeft; //class count left
			DoubleVector classCountR = root.classCountsRight; //class count left
			double numInst = root.classCountsLeft.sumOfValues() + root.classCountsRight.sumOfValues();
			double classCountLSum = root.classCountsLeft.sumOfValues();
			double classCountRSum = root.classCountsRight.sumOfValues();
			double classCountLEntropy = entropy(classCountL);
			double classCountREntropy = entropy(classCountR);
			this.minEntropyTemp = ( classCountLSum / numInst) * classCountLEntropy 
					+ (classCountRSum / numInst)* classCountREntropy;
			for (int f = 0; f < root.classCountsLeft.numValues(); f++) {
				parentClassCL.setValue(f, root.classCountsLeft.getValue(f));
				}
			findBestValEntropy(root ,classCountL , classCountR, true, this.minEntropyTemp, parentClassCL);
			}
		}
1273946
function(poly) {
            var l = Math.max(this.coeffs.length, poly.coeffs.length);
            for(var i=0; i<l; i++) {
                var a = (this.coeffs[i] || new Frac(0)),
                    b = (poly.coeffs[i] || new Frac(0));
                this.coeffs[i] = a.add(b);
            }
            return this;
        }
1233353
def polynomial(img, mask, inplace=False, replace_all=False,
               max_dev=1e-5, max_iter=20, order=2):
    '''
    
    '''
    if inplace:
        out = img
    else:
        out = img.copy()
    lastm = 0
    for _ in range(max_iter):
        out2 = polyfit2dGrid(out, mask, order=order, copy=not inplace,
                             replace_all=replace_all)
        if replace_all:
            out = out2
            break
        res = (np.abs(out2 - out)).mean()
        print('residuum: ', res)
        if res < max_dev:
            out = out2
            break
        out = out2
        mask = _highGrad(out)

        m = mask.sum()
        if m == lastm or m == img.size:
            break
        lastm = m
    out = np.clip(out, 0, 1, out=out)  # if inplace else None)
    return out
245125
@Override
  public void evaluate(DoubleSolution solution) {

    int numberOfVariables = solution.getNumberOfVariables();
    int numberOfObjectives = solution.getNumberOfObjectives();

    double[] x = new double[numberOfVariables];
    double[] f = new double[numberOfObjectives];

    for (int i = 0; i < numberOfVariables; i++) {
      x[i] = solution.getVariableValue(i);
    }

    double[] g = new double[numberOfObjectives];
    double[] thet = new double[numberOfObjectives - 1];
    int lb, ub;
    // evaluate g, thet
    for (int i = 0; i < numberOfObjectives - 1; i++) {
      g[i] = 0;
      lb = numberOfObjectives + i * const2;
      ub = numberOfObjectives + (i + 1) * const2 - 1;
      for (int j = lb - 1; j < ub; j++) {
        g[i] += Math.pow(x[j] / 2 - 0.25, 2);
      }
      thet[i] = Math.PI / 2 * (x[i] / 2 + 0.25);
    }
    lb = numberOfObjectives + (numberOfObjectives - 1) * const2;
    ub = numberOfVariables;
    for (int j = lb - 1; j < ub; j++) {
      g[numberOfObjectives - 1] += Math.pow(x[j] / 2 - 0.25, 2);
    }
    // evaluate fm,fm-1,...,2,f1
    f[numberOfObjectives - 1] = Math.sin(thet[0]) * (1 + g[numberOfObjectives - 1]);
    double subf1 = 1;
    // fi=cos(thet1)cos(thet2)...cos(thet[m-i])*sin(thet(m-i+1))*(1+g[i]),fi=subf1*subf2*subf3
    for (int i = numberOfObjectives - 2; i > 0; i--) {
      subf1 *= Math.cos(thet[numberOfObjectives - i - 2]);
      f[i] = subf1 * Math.sin(thet[numberOfObjectives - i - 1]) * (1 + g[i]);
    }
    f[0] = subf1 * Math.cos(thet[numberOfObjectives - 2]) * (1 + g[0]);

    for (int i = 0; i < numberOfObjectives; i++) {
      solution.setObjective(i, f[i]);
    }
  }
596484
def roots(self):
      """"""
      return [x for x in self._nodes.values() if x.id not in self._c2p]
202948
def __get_trace_facvar(self, polynomial):
        
        facvar = [0] * (self.n_vars + 1)
        F = {}
        for i in range(self.matrix_var_dim):
            for j in range(self.matrix_var_dim):
                for key, value in \
                        polynomial[i, j].as_coefficients_dict().items():
                    skey = apply_substitutions(key, self.substitutions,
                                               self.pure_substitution_rules)
                    try:
                        Fk = F[skey]
                    except KeyError:
                        Fk = zeros(self.matrix_var_dim, self.matrix_var_dim)
                    Fk[i, j] += value
                    F[skey] = Fk
        # This is the tracing part
        for key, Fk in F.items():
            if key == S.One:
                k = 1
            else:
                k = self.monomial_index[key]
            for i in range(self.matrix_var_dim):
                for j in range(self.matrix_var_dim):
                    sym_matrix = zeros(self.matrix_var_dim,
                                       self.matrix_var_dim)
                    sym_matrix[i, j] = 1
                    facvar[k+i*self.matrix_var_dim+j] = (sym_matrix*Fk).trace()
        facvar = [float(f) for f in facvar]
        return facvar
1194285
public static Polynomial wrap( double ...coefficients ) {
		Polynomial p = new Polynomial(coefficients.length);
		p.setTo(coefficients,coefficients.length);

		return p;
	}
1256288
def _get_facvar(self, polynomial):
        
        facvar = [0] * (self.n_vars + 1)
        # Preprocess the polynomial for uniform handling later
        if is_number_type(polynomial):
            facvar[0] = polynomial
            return facvar
        polynomial = polynomial.expand()
        if polynomial.is_Mul:
            elements = [polynomial]
        else:
            elements = polynomial.as_coeff_mul()[1][0].as_coeff_add()[1]
        for element in elements:
            results = self._get_index_of_monomial(element)
            for (k, coeff) in results:
                facvar[k] += coeff
        return facvar
183293
public static double[][] getReal(ComplexNumber[][] cn) {
        double[][] n = new double[cn.length][cn[0].length];
        for (int i = 0; i < n.length; i++) {
            for (int j = 0; j < n[0].length; j++) {
                n[i][j] = cn[i][j].real;
            }
        }
        return n;
    }
281822
public void evaluate(DoubleSolution solution) {
    int numberOfVariables = getNumberOfVariables();
    int numberOfObjectives = getNumberOfObjectives();
    double[] f = new double[numberOfObjectives];
    double[] x = new double[numberOfVariables] ;

    for (int i = 0; i < numberOfVariables; i++) {
      x[i] = solution.getVariableValue(i) ;
    }

    int k = getNumberOfVariables() - getNumberOfObjectives() + 1;

    double g = 0.0;
    for (int i = numberOfVariables - k; i < numberOfVariables; i++) {
      g += (x[i] - 0.5) * (x[i] - 0.5);
    }

    for (int i = 0; i < numberOfObjectives; i++) {
      f[i] = 1.0 + g;
    }

    for (int i = 0; i < numberOfObjectives; i++) {
      for (int j = 0; j < numberOfObjectives - (i + 1); j++) {
        f[i] *= Math.cos(x[j] * 0.5 * Math.PI);
      }
      if (i != 0) {
        int aux = numberOfObjectives - (i + 1);
        f[i] *= Math.sin(x[aux] * 0.5 * Math.PI);
      }
    }

    for (int i = 0; i < numberOfObjectives; i++) {
      solution.setObjective(i, f[i]);
    }
  }
1085243
def roots(cls, degree, domain, kind):
        """"""
        basis_coefs = cls._basis_monomial_coefs(degree)
        basis_poly = cls.functions_factory(basis_coefs, domain, kind)
        return basis_poly.roots()