term ::= factor+
7427
Token parseTerm() throws ParseException {
		int ch = this.read();
		Token tok = null;
		if (ch == T_OR || ch == T_RPAREN || ch == T_EOF) {
			tok = Token.createEmpty();
		} else {
			tok = this.parseFactor();
			Token concat = null;
			while ((ch = this.read()) != T_OR && ch != T_RPAREN && ch != T_EOF) {
				if (concat == null) {
					concat = Token.createConcat();
					concat.addChild(tok);
					tok = concat;
				}
				concat.addChild(this.parseFactor());
				// tok = Token.createConcat(tok, this.parseFactor());
			}
		}
		if (ch == T_RPAREN) {
			parenCount--;
		}
		return tok;
	}
422610
function(symbol, factors) {  
                if(symbol.group === FN) { 
                    if(symbol.fname === 'sqrt') {
                        var factors2 = new Factors(),
                            arg = __.Factor.common(symbol.args[0].clone(), factors2);
                        arg = __.Factor.coeffFactor(arg, factors2);
                        symbol = _.symfunction('sqrt', [arg]);
                        factors2.each(function(x) {
                            symbol = _.multiply(symbol, _.parse(core.Utils.format('sqrt({0})', x)));
                        });
                    }
                    else
                        factors.add(symbol);
                }
                else { 
                    //symbol = __.Factor.common(symbol, factors);
                    symbol = __.Factor.mSqfrFactor(symbol, factors);
                    
                    var vars = variables(symbol),
                        symbols = symbol.collectSymbols().map(function(x) {
                            return Symbol.unwrapSQRT(x);
                        }),
                        sorted = {},
                        maxes = {},
                        l = vars.length, n = symbols.length;
                    //take all the variables in the symbol and organize by variable name
                    //e.g. a^2+a^2+b*a -> {a: {a^3, a^2, b*a}, b: {b*a}}
                    
                    for(var i=0; i<l; i++) {
                        var v = vars[i];
                        sorted[v] = new Symbol(0);
                        for(var j=0; j<n; j++) {
                            var s = symbols[j];
                            if(s.contains(v)) {
                                var p = s.value === v ? s.power.toDecimal() : s.symbols[v].power.toDecimal();
                                if(!maxes[v] || p < maxes[v]) maxes[v] = p;
                                sorted[v] = _.add(sorted[v], s.clone());
                            }
                        }
                    }
                    
                    for(var x in sorted) {
                        var r = _.parse(x+'^'+maxes[x]); 
                        var div = _.divide(sorted[x], r);
                        var new_factor = _.expand(div); 
                        
                        if(new_factor.equals(1))
                            break; //why divide by one. Just move 
                        var divided = __.div(symbol.clone(), new_factor); 
                        if(divided[0].equals(0)) { 
                            //cant factor anymore
                            break;
                        }
                        
                        var neg_numeric_factor = isInt(new_factor) && new_factor.lessThan(0);
                        
                        if(divided[1].equals(0) && !neg_numeric_factor) { //we found at least one factor
                            //factors.add(new_factor);
                            var d = __.div(symbol.clone(), divided[0].clone());
                            var r = d[0];
                            symbol = d[1];
                            //we don't want to just flip the sign. If the remainder is -1 then we accomplished nothing
                            //and we just return the symbol;
                            //If r equals zero then there's nothing left to do so we're done
                            if(r.equals(-1))
                                return symbol;

                            var factor = divided[0]; 
                            if(symbol.equals(factor)) {
                                var rem = __.Factor.reduce(factor, factors);
                                
                                if(!symbol.equals(rem)) 
                                    return __.Factor.mfactor(rem, factors);
                            }
                            else {
                                factors.add(factor); 
                                //if the remainder of the symbol is zero then we're done. TODO: Rethink this logic a bit.
                                if(symbol.equals(0))
                                    return r;
                            }
                            
                            if(r.isConstant('all')) { 
                                factors.add(r);
                                return r;
                            }
                            
                            return __.Factor.mfactor(r, factors);
                        }
                    }
                    
                }
                
                //difference of squares factorization
                symbol = __.Factor.sqdiff(symbol, factors);
                //factors by fishing for zeroes
                symbol = __.Factor.zeroes(symbol, factors);
                
                return symbol;
            }
894523
def get_factors(n):
    

    def factor(n, i, combi, res):
        """[summary]
        helper function

        Arguments:
            n {[int]} -- [number]
            i {[int]} -- [to tested divisor]
            combi {[list]} -- [catch divisors]
            res {[list]} -- [all factors of the number n]
        
        Returns:
            [list] -- [res]
        """

        while i * i <= n:
            if n % i == 0:
                res += combi + [i, int(n/i)],
                factor(n/i, i, combi+[i], res)
            i += 1
        return res
    return factor(n, 2, [], [])
601217
void pass_2(int fi, 
	      float in[],  int in0, int istride,
	      float out[], int out0, int ostride,
	      int sign, int product) {
    int k, k1;

    int factor = 2;
    int m = n / factor;
    int q = n / product;
    int product_1 = product / factor;

    int di = istride * m;
    int dj = ostride * product_1;
    int i = in0, j = out0;
    float x_real, x_imag;
    for (k = 0; k < q; k++) {
      float twids[] = twiddle[fi][k];
      float w_real =       twids[0];
      float w_imag = -sign*twids[1];

      for (k1 = 0; k1 < product_1; k1++) {
	float z0_real = in[i];
	float z0_imag = in[i+1];
	float z1_real = in[i+di];
	float z1_imag = in[i+di+1];
	i += istride;

	/* compute x = W(2) z */

	/* apply twiddle factors */
	  
	/* out0 = 1 * (z0 + z1) */
	out[j]   = z0_real + z1_real;
	out[j+1] = z0_imag + z1_imag;
	  
	/* out1 = w * (z0 - z1) */
	x_real = z0_real - z1_real;
	x_imag = z0_imag - z1_imag;
	out[j+dj]   = w_real * x_real - w_imag * x_imag;
	out[j+dj+1] = w_real * x_imag + w_imag * x_real;
	  
	j += ostride;
      }
      j += (factor-1)*dj;
    }}
1195988
def OneHot0(*xs, simplify=True, conj=True):
    
    xs = [Expression.box(x).node for x in xs]
    terms = list()
    if conj:
        for x0, x1 in itertools.combinations(xs, 2):
            terms.append(exprnode.or_(exprnode.not_(x0),
                                      exprnode.not_(x1)))
        y = exprnode.and_(*terms)
    else:
        for _xs in itertools.combinations(xs, len(xs) - 1):
            terms.append(exprnode.and_(*[exprnode.not_(x) for x in _xs]))
        y = exprnode.or_(*terms)
    if simplify:
        y = y.simplify()
    return _expr(y)
1257946
def OneHot(*xs, simplify=True, conj=True):
    
    xs = [Expression.box(x).node for x in xs]
    terms = list()
    if conj:
        for x0, x1 in itertools.combinations(xs, 2):
            terms.append(exprnode.or_(exprnode.not_(x0),
                                      exprnode.not_(x1)))
        terms.append(exprnode.or_(*xs))
        y = exprnode.and_(*terms)
    else:
        for i, xi in enumerate(xs):
            zeros = [exprnode.not_(x) for x in xs[:i] + xs[i+1:]]
            terms.append(exprnode.and_(xi, *zeros))
        y = exprnode.or_(*terms)
    if simplify:
        y = y.simplify()
    return _expr(y)
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();
            }
642441
def add(other)
      case other
      when LinExpr
        @terms.merge!(other.terms) { |_, c1, c2| c1 + c2 }
      when Variable
        if @terms.key? other
          @terms[other] += 1.0
        else
          @terms[other] = 1.0
        end
      else
        fail TypeError
      end

      self
    end
1228218
def *(x)
      x = Unit.cast(x)
      if scalar?
        return x
      elsif x.scalar?
        return self.dup
      end
      check_operable2(x)
      dims = dimension_binop(x){|a,b| a+b}
      factor = self.factor * x.factor
      Unit.new(factor,dims)
    end
452228
def _compute_magnitude_squared_term(self, P, M, Q, W, mag):
        
        return P * (mag - M) + Q * (mag - M) ** 2 + W
509618
private int precisionSum(List<UnitFactor> factors) {
    return factors.stream().map(f -> totalPrecision(f.rational())).reduce(0, Math::addExact);
  }
840471
public static Factor add(List<Factor> factors) {
    Preconditions.checkNotNull(factors);
    Preconditions.checkArgument(!factors.isEmpty());
    return factors.get(0).add(factors.subList(1, factors.size()));
  }
827602
def _get_magnitude_term(self, C, mag):
        
        if mag >= self.CONSTS["Mh"]:
            return C["e1"] + C["b3"] * (mag - self.CONSTS["Mh"])
        else:
            return C["e1"] + (C["b1"] * (mag - self.CONSTS["Mh"])) +\
                (C["b2"] * (mag - self.CONSTS["Mh"]) ** 2.)
1371040
public static void fe_add(int[] h,int[] f,int[] g)
{
  int f0 = f[0];
  int f1 = f[1];
  int f2 = f[2];
  int f3 = f[3];
  int f4 = f[4];
  int f5 = f[5];
  int f6 = f[6];
  int f7 = f[7];
  int f8 = f[8];
  int f9 = f[9];
  int g0 = g[0];
  int g1 = g[1];
  int g2 = g[2];
  int g3 = g[3];
  int g4 = g[4];
  int g5 = g[5];
  int g6 = g[6];
  int g7 = g[7];
  int g8 = g[8];
  int g9 = g[9];
  int h0 = f0 + g0;
  int h1 = f1 + g1;
  int h2 = f2 + g2;
  int h3 = f3 + g3;
  int h4 = f4 + g4;
  int h5 = f5 + g5;
  int h6 = f6 + g6;
  int h7 = f7 + g7;
  int h8 = f8 + g8;
  int h9 = f9 + g9;
  h[0] = (int)h0;
  h[1] = (int)h1;
  h[2] = (int)h2;
  h[3] = (int)h3;
  h[4] = (int)h4;
  h[5] = (int)h5;
  h[6] = (int)h6;
  h[7] = (int)h7;
  h[8] = (int)h8;
  h[9] = (int)h9;
}
966701
def +(other)
      rgb =
        case other
        when RGB
          compound_by(other.rgb) { |a, b| [a+b, 255].min }
        when Array
          raise ArgumentError, "Invalid size of Array given" unless other.size==3
          compound_by(other) { |a, b| (a + b) % 256 }
        when Integer
          compound_by([other] * 3) { |a, b| (a + b) % 256 }
        else
          raise ArgumentError, "Invalid argument given"
        end
      self.class.new *rgb
    end
1150679
def _factor(lexer):
    """"""
    tok = _expect_token(lexer, FACTOR_TOKS)
    # '~' F
    toktype = type(tok)
    if toktype is OP_not:
        return ('not', _factor(lexer))
    # '(' EXPR ')'
    elif toktype is LPAREN:
        expr = _expr(lexer)
        _expect_token(lexer, {RPAREN})
        return expr
    # OPN '(' ... ')'
    elif any(toktype is t for t in OPN_TOKS):
        op = tok.ASTOP
        _expect_token(lexer, {LPAREN})
        tok = next(lexer)
        # OPN '(' ')'
        if isinstance(tok, RPAREN):
            xs = tuple()
        # OPN '(' XS ')'
        else:
            lexer.unpop_token(tok)
            xs = _args(lexer)
            _expect_token(lexer, {RPAREN})
        return (op, ) + xs
    # ITE '(' EXPR ',' EXPR ',' EXPR ')'
    elif toktype is KW_ite:
        _expect_token(lexer, {LPAREN})
        s = _expr(lexer)
        _expect_token(lexer, {COMMA})
        d1 = _expr(lexer)
        _expect_token(lexer, {COMMA})
        d0 = _expr(lexer)
        _expect_token(lexer, {RPAREN})
        return ('ite', s, d1, d0)
    # Implies '(' EXPR ',' EXPR ')'
    elif toktype is KW_implies:
        _expect_token(lexer, {LPAREN})
        p = _expr(lexer)
        _expect_token(lexer, {COMMA})
        q = _expr(lexer)
        _expect_token(lexer, {RPAREN})
        return ('implies', p, q)
    # Not '(' EXPR ')'
    elif toktype is KW_not:
        _expect_token(lexer, {LPAREN})
        x = _expr(lexer)
        _expect_token(lexer, {RPAREN})
        return ('not', x)
    # VARIABLE
    elif toktype is NameToken:
        lexer.unpop_token(tok)
        return _variable(lexer)
    # '0' | '1'
    else:
        if tok.value not in {0, 1}:
            raise Error("unexpected token: " + str(tok))
        return ('const', tok.value)
106478
def term_with_coeff(term, coeff):
    
    if not isinstance(coeff, Number):
        raise ValueError("coeff must be a Number")
    new_pauli = term.copy()
    # We cast to a complex number to ensure that internally the coefficients remain compatible.
    new_pauli.coefficient = complex(coeff)
    return new_pauli