Returns the degree of a noncommutative polynomial.

    :param polynomial: Polynomial of noncommutive variables.
    :type polynomial: :class:`sympy.core.expr.Expr`.

    :returns: int -- the degree of the polynomial.
178979
def ncdegree(polynomial):
    
    degree = 0
    if is_number_type(polynomial):
        return degree
    polynomial = polynomial.expand()
    for monomial in polynomial.as_coefficients_dict():
        subdegree = 0
        for variable in monomial.as_coeff_mul()[1]:
            if isinstance(variable, Pow):
                subdegree += variable.exp
            elif not isinstance(variable, Number) and variable != I:
                subdegree += 1
        if subdegree > degree:
            degree = subdegree
    return degree
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
1106800
def derivatives(self, **kwargs):
        
        # Call parent method
        super(CurveEvaluator2, self).derivatives(**kwargs)

        param = kwargs.get('parameter')
        deriv_order = kwargs.get('deriv_order', 0)
        degree = kwargs.get('degree')
        knotvector = kwargs.get('knotvector')
        ctrlpts = kwargs.get('ctrlpts')
        dimension = kwargs.get('dimension')

        # Algorithm A3.4
        du = min(degree, deriv_order)

        CK = [[0.0 for _ in range(dimension)] for _ in range(deriv_order + 1)]

        span = self._span_func(degree, knotvector, len(ctrlpts), param)
        bfuns = helpers.basis_function_all(degree, tuple(knotvector), span, param)

        # "derivatives_ctrlpts" is a static method that could be called like below
        PK = CurveEvaluator2.derivatives_ctrlpts(r1=(span - degree), r2=span,
                                                 degree=degree,
                                                 knotvector=knotvector,
                                                 ctrlpts=ctrlpts,
                                                 dimension=dimension,
                                                 deriv_order=du)

        for k in range(0, du + 1):
            for j in range(0, degree - k + 1):
                CK[k][:] = [elem + (bfuns[j][degree - k] * drv_ctl_p) for elem, drv_ctl_p in
                            zip(CK[k], PK[k][j])]

        # Return the derivatives
        return CK
1352471
def degree_operations(obj, param, **kwargs):
    
    def validate_reduction(degree):
        if degree < 2:
            raise GeomdlException("Input spline geometry must have degree > 1")

    # Start curve degree manipulation operations
    if isinstance(obj, abstract.Curve):
        if param[0] is not None and param[0] != 0:
            # Find multiplicity of the internal knots
            int_knots = set(obj.knotvector[obj.degree + 1:-(obj.degree + 1)])
            mult_arr = []
            for ik in int_knots:
                s = helpers.find_multiplicity(ik, obj.knotvector)
                mult_arr.append(s)

            # Decompose the input by knot insertion
            crv_list = decompose_curve(obj, **kwargs)

            # If parameter is positive, apply degree elevation. Otherwise, apply degree reduction
            if param[0] > 0:
                # Loop through to apply degree elevation
                for crv in crv_list:
                    cpts = crv.ctrlptsw if crv.rational else crv.ctrlpts
                    new_cpts = helpers.degree_elevation(crv.degree, cpts, num=param[0])
                    crv.degree += param[0]
                    crv.set_ctrlpts(new_cpts)
                    crv.knotvector = [crv.knotvector[0] for _ in range(param[0])] + list(crv.knotvector) + [crv.knotvector[-1] for _ in range(param[0])]

                # Compute new degree
                nd = obj.degree + param[0]

                # Number of knot removals
                num = obj.degree + 1
            else:
                # Validate degree reduction operation
                validate_reduction(obj.degree)

                # Loop through to apply degree reduction
                for crv in crv_list:
                    cpts = crv.ctrlptsw if crv.rational else crv.ctrlpts
                    new_cpts = helpers.degree_reduction(crv.degree, cpts)
                    crv.degree -= 1 
                    crv.set_ctrlpts(new_cpts)
                    crv.knotvector = list(crv.knotvector[1:-1])
                
                # Compute new degree
                nd = obj.degree - 1

                # Number of knot removals
                num = obj.degree - 1
            
            # Link curves together (reverse of decomposition)
            kv, cpts, ws, knots = ops.link_curves(*crv_list, validate=False)
            
            # Organize control points (if necessary)
            ctrlpts = compatibility.combine_ctrlpts_weights(cpts, ws) if obj.rational else cpts

            # Apply knot removal
            for k, s in zip(knots, mult_arr):
                span = helpers.find_span_linear(nd, kv, len(ctrlpts), k)
                ctrlpts = helpers.knot_removal(nd, kv, ctrlpts, k, num=num-s)
                kv = helpers.knot_removal_kv(kv, span, num-s)
            
            # Update input curve
            obj.degree = nd
            obj.set_ctrlpts(ctrlpts)
            obj.knotvector = kv

    # Start surface degree manipulation operations
    if isinstance(obj, abstract.Surface):
        # u-direction
        if param[0] is not None and param[0] != 0:

            # If parameter is positive, apply degree elevation. Else, apply degree reduction
            if param[0] > 0:
                pass
            else:
                # Apply degree reduction operation
                validate_reduction(obj.degree_u)

        # v-direction
        if param[1] is not None and param[1] != 0:

            # If parameter is positive, apply degree elevation. Otherwise, apply degree reduction
            if param[1] > 0:
                pass
            else:
                # Validate degree reduction operation
                validate_reduction(obj.degree_v)

    # Start surface degree manipulation operations
    if isinstance(obj, abstract.Volume):
        raise GeomdlException("Degree manipulation operations are not available for spline volumes")

    # Return updated spline geometry
    return obj
229925
public static <A extends Number & Comparable<?>> NumberExpression<Double> degrees(Expression<A> num) {
        return Expressions.numberOperation(Double.class, Ops.MathOps.DEG, num);
    }
301101
def derivatives(self, **kwargs):
        
        deriv_order = kwargs.get('deriv_order')
        param = kwargs.get('parameter')
        degree = kwargs.get('degree')
        knotvector = kwargs.get('knotvector')
        ctrlpts_size = kwargs.get('ctrlpts_size')
        dimension = kwargs.get('dimension')

        SKL = [[[0.0 for _ in range(dimension)] for _ in range(deriv_order + 1)] for _ in range(deriv_order + 1)]

        d = (min(degree[0], deriv_order), min(degree[1], deriv_order))

        span = [0 for _ in range(len(degree))]
        basis = [[] for _ in range(len(degree))]
        for idx in range(len(degree)):
            span[idx] = self._span_func(degree[idx], knotvector[idx], ctrlpts_size[idx], param[idx])
            basis[idx] = helpers.basis_function_all(degree[idx], knotvector[idx], span[idx], param[idx])

        PKL = self.derivatives_ctrlpts(r1=span[0] - degree[0], r2=span[0],
                                       s1=span[1] - degree[1], s2=span[1],
                                       **kwargs)

        # Evaluating the derivative at parameters (u,v) using its control points
        for k in range(0, d[0] + 1):
            dd = min(deriv_order - k, d[1])

            for l in range(0, dd + 1):
                SKL[k][l] = [0.0 for _ in range(dimension)]

                for i in range(0, degree[1] - l + 1):
                    temp = [0.0 for _ in range(dimension)]

                    for j in range(0, degree[0] - k + 1):
                        temp[:] = [elem + (basis[0][j][degree[0] - k] * drv_ctl_p) for elem, drv_ctl_p in
                                   zip(temp, PKL[k][l][j][i])]

                    SKL[k][l][:] = [elem + (basis[1][i][degree[1] - l] * drv_ctl_p) for elem, drv_ctl_p in
                                    zip(SKL[k][l], temp)]

        return SKL
693066
def deriv(self, n=1):
        
        if n==1:
            if self.order > 0:
                return PowerSeries(self.c[1:]*range(1,len(self.c)))
            else:
                return PowerSeries([0. * self.c[0]])
        elif n>1:
            return self.deriv().deriv(n-1)
        elif n==0:
            return self
749405
def paga_degrees(adata) -> List[int]:
    
    import networkx as nx
    g = nx.Graph(adata.uns['paga']['connectivities'])
    degrees = [d for _, d in g.degree(weight='weight')]
    return degrees
305165
def get_support(variables, polynomial):
    
    support = []
    if is_number_type(polynomial):
        support.append([0] * len(variables))
        return support
    for monomial in polynomial.expand().as_coefficients_dict():
        tmp_support = [0] * len(variables)
        mon, _ = __separate_scalar_factor(monomial)
        symbolic_support = flatten(split_commutative_parts(mon))
        for s in symbolic_support:
            if isinstance(s, Pow):
                base = s.base
                if is_adjoint(base):
                    base = base.adjoint()
                tmp_support[variables.index(base)] = s.exp
            elif is_adjoint(s):
                tmp_support[variables.index(s.adjoint())] = 1
            elif isinstance(s, (Operator, Symbol)):
                tmp_support[variables.index(s)] = 1
        support.append(tmp_support)
    return support
1202804
def commutator_order(cls, ops, kwargs):
    
    from qnet.algebra.core.operator_algebra import Commutator
    assert len(ops) == 2
    if cls.order_key(ops[1]) < cls.order_key(ops[0]):
        return -1 * Commutator.create(ops[1], ops[0])
    else:
        return ops, kwargs
969377
def _calc_degreeminutes(decimal_degree):
        '''
        
        '''
        sign = compare(decimal_degree, 0) # Store whether the coordinate is negative or positive
        decimal_degree = abs(decimal_degree)
        degree = decimal_degree//1 # Truncate degree to be an integer
        decimal_minute = (decimal_degree - degree)*60. # Calculate the decimal minutes
        minute = decimal_minute//1 # Truncate minute to be an integer
        second = (decimal_minute - minute)*60. # Calculate the decimal seconds
        # Finally, re-impose the appropriate sign
        degree = degree*sign
        minute = minute*sign
        second = second*sign
        return (degree, minute, decimal_minute, second)
1184742
def get_all_monomials(variables, extramonomials, substitutions, degree,
                      removesubstitutions=True):
    
    monomials = get_monomials(variables, degree)
    if extramonomials is not None:
        monomials.extend(extramonomials)
    if removesubstitutions and substitutions is not None:
        monomials = [monomial for monomial in monomials if monomial not
                     in substitutions]
        monomials = [remove_scalar_factor(apply_substitutions(monomial,
                                                              substitutions))
                     for monomial in monomials]
    monomials = unique(monomials)
    return monomials
982668
function(w, degree, t, depth) {
		var left = [], right = [],
			left_count, right_count,
			left_t = [], right_t = [];

		switch (_getCrossingCount(w, degree)) {
			case 0 : {
				return 0;
			}
			case 1 : {
				if (depth >= maxRecursion) {
					t[0] = (w[0].x + w[degree].x) / 2.0;
					return 1;
				}
				if (_isFlatEnough(w, degree)) {
					t[0] = _computeXIntercept(w, degree);
					return 1;
				}
				break;
			}
		}
		_bezier(w, degree, 0.5, left, right);
		left_count  = _findRoots(left,  degree, left_t, depth+1);
		right_count = _findRoots(right, degree, right_t, depth+1);
		for (var i = 0; i < left_count; i++) t[i] = left_t[i];
		for (var i = 0; i < right_count; i++) t[i+left_count] = right_t[i];
		return (left_count+right_count);
	}
551252
def binomial_coefficient(k)
	    (0...k).inject(1) {|m,i| (m * (degree - i)) / (i + 1) }
	end
210837
function(toPolynomial) {
            //get the first nozero coefficient and returns its power
            var fnz = function(a) {
                    for(var i=0; i<a.length; i++)
                        if(!a[i].equals(0)) return i;
                },
                ca = [];
            for(var i=0; i<this.coeffs.length; i++) {
                var c = this.coeffs[i];
                if(!c.equals(0) && ca.indexOf(c) === -1) ca.push(c);
            }
            var p = [core.Math2.QGCD.apply(undefined, ca), fnz(this.coeffs)].toDecimal(); 

            if(toPolynomial) {
                var parr = [];
                parr[p[1]-1] = p[0];
                p = Polynomial.fromArray(parr, this.variable).fill();
            }

            return p;
        }
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
296410
def degrees(x):
    
    if isinstance(x, UncertainFunction):
        mcpts = np.degrees(x._mcpts)
        return UncertainFunction(mcpts)
    else:
        return np.degrees(x)