当前位置: 首页>>代码示例>>Python>>正文


Python Poly.terms_gcd方法代码示例

本文整理汇总了Python中sympy.polys.Poly.terms_gcd方法的典型用法代码示例。如果您正苦于以下问题:Python Poly.terms_gcd方法的具体用法?Python Poly.terms_gcd怎么用?Python Poly.terms_gcd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sympy.polys.Poly的用法示例。


在下文中一共展示了Poly.terms_gcd方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: roots

# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import terms_gcd [as 别名]

#.........这里部分代码省略.........
            if f.degree() == 1:
                return map(cancel, roots_linear(f))
            else:
                return roots_binomial(f)

        result = []

        for i in [S(-1), S(1)]:
            if f.eval(i).expand().is_zero:
                f = f.exquo(Poly(x-1, x))
                result.append(i)
                break

        n = f.degree()

        if n == 1:
            result += map(cancel, roots_linear(f))
        elif n == 2:
            result += map(cancel, roots_quadratic(f))
        elif n == 3 and flags.get('cubics', True):
            result += roots_cubic(f)
        elif n == 4 and flags.get('quartics', True):
            result += roots_quartic(f)

        return result

    if f.is_monomial == 1:
        if f.is_ground:
            if multiple:
                return []
            else:
                return {}
        else:
            result = { S(0) : f.degree() }
    else:
        (k,), f = f.terms_gcd()

        if not k:
            zeros = {}
        else:
            zeros = { S(0) : k }

        result = {}

        if f.length() == 2:
            if f.degree() == 1:
                result[cancel(roots_linear(f)[0])] = 1
            else:
                for r in roots_binomial(f):
                    _update_dict(result, r, 1)
        elif f.degree() == 2:
            for r in roots_quadratic(f):
                _update_dict(result, cancel(r), 1)
        else:
            _, factors = Poly(f.as_basic()).factor_list()

            if len(factors) == 1 and factors[0][1] == 1:
                result = _try_decompose(f)
            else:
                for factor, k in factors:
                    for r in _try_heuristics(Poly(factor, x, field=True)):
                        _update_dict(result, r, k)

        result.update(zeros)

    filter = flags.get('filter', None)

    if filter not in [None, 'C']:
        handlers = {
            'Z' : lambda r: r.is_Integer,
            'Q' : lambda r: r.is_Rational,
            'R' : lambda r: r.is_real,
            'I' : lambda r: r.is_imaginary,
        }

        try:
            query = handlers[filter]
        except KeyError:
            raise ValueError("Invalid filter: %s" % filter)

        for zero in dict(result).iterkeys():
            if not query(zero):
                del result[zero]

    predicate = flags.get('predicate', None)

    if predicate is not None:
        for zero in dict(result).iterkeys():
            if not predicate(zero):
                del result[zero]

    if not multiple:
        return result
    else:
        zeros = []

        for zero, k in result.iteritems():
            zeros.extend([zero]*k)

        return zeros
开发者ID:Aang,项目名称:sympy,代码行数:104,代码来源:polyroots.py


注:本文中的sympy.polys.Poly.terms_gcd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。