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


Python ZZ.from_sympy方法代码示例

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


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

示例1: _construct_composite

# 需要导入模块: from sympy.polys.domains import ZZ [as 别名]
# 或者: from sympy.polys.domains.ZZ import from_sympy [as 别名]
def _construct_composite(coeffs, opt):
    """Handle composite domains, e.g.: ZZ[X], QQ[X], ZZ(X), QQ(X). """
    numers, denoms = [], []

    for coeff in coeffs:
        numer, denom = coeff.as_numer_denom()

        numers.append(numer)
        denoms.append(denom)

    polys, gens = parallel_dict_from_basic(numers + denoms)  # XXX: sorting

    if any(gen.is_number for gen in gens):
        return None  # generators are number-like so lets better use EX

    n = len(gens)
    k = len(polys) // 2

    numers = polys[:k]
    denoms = polys[k:]

    if opt.field:
        fractions = True
    else:
        fractions, zeros = False, (0,) * n

        for denom in denoms:
            if len(denom) > 1 or zeros not in denom:
                fractions = True
                break

    result = []

    if not fractions:
        coeffs = set([])

        for numer, denom in zip(numers, denoms):
            denom = denom[zeros]

            for monom, coeff in numer.iteritems():
                coeff /= denom
                coeffs.add(coeff)
                numer[monom] = coeff

        rationals, reals = False, False

        for coeff in coeffs:
            if coeff.is_Rational:
                if not coeff.is_Integer:
                    rationals = True
            elif coeff.is_Real:
                reals = True
                break

        if reals:
            ground = RR
        elif rationals:
            ground = QQ
        else:
            ground = ZZ

        domain = ground.poly_ring(*gens)

        for numer in numers:
            for monom, coeff in numer.iteritems():
                numer[monom] = ground.from_sympy(coeff)

            result.append(domain(numer))
    else:
        domain = ZZ.frac_field(*gens)

        for numer, denom in zip(numers, denoms):
            for monom, coeff in numer.iteritems():
                numer[monom] = ZZ.from_sympy(coeff)

            for monom, coeff in denom.iteritems():
                denom[monom] = ZZ.from_sympy(coeff)

            result.append(domain((numer, denom)))

    return domain, result
开发者ID:,项目名称:,代码行数:83,代码来源:


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