本文整理汇总了Python中sympy.polys.Poly.to_field方法的典型用法代码示例。如果您正苦于以下问题:Python Poly.to_field方法的具体用法?Python Poly.to_field怎么用?Python Poly.to_field使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.polys.Poly
的用法示例。
在下文中一共展示了Poly.to_field方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: roots
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import to_field [as 别名]
def roots(f, *gens, **flags):
"""Computes symbolic roots of a univariate polynomial.
Given a univariate polynomial f with symbolic coefficients (or
a list of the polynomial's coefficients), returns a dictionary
with its roots and their multiplicities.
Only roots expressible via radicals will be returned. To get
a complete set of roots use RootOf class or numerical methods
instead. By default cubic and quartic formulas are used in
the algorithm. To disable them because of unreadable output
set `cubics=False` or `quartics=False` respectively.
To get roots from a specific domain set the `filter` flag with
one of the following specifiers: Z, Q, R, I, C. By default all
roots are returned (this is equivalent to setting `filter='C'`).
By default a dictionary is returned giving a compact result in
case of multiple roots. However to get a tuple containing all
those roots set the `multiple` flag to True.
Examples
========
>>> from sympy import Poly, roots
>>> from sympy.abc import x, y
>>> roots(x**2 - 1, x)
{1: 1, -1: 1}
>>> p = Poly(x**2-1, x)
>>> roots(p)
{1: 1, -1: 1}
>>> p = Poly(x**2-y, x, y)
>>> roots(Poly(p, x))
{y**(1/2): 1, -y**(1/2): 1}
>>> roots(x**2 - y, x)
{y**(1/2): 1, -y**(1/2): 1}
>>> roots([1, 0, -1])
{1: 1, -1: 1}
"""
multiple = flags.get('multiple', False)
if isinstance(f, list):
if gens:
raise ValueError('redundant generators given')
x = Dummy('x')
poly, i = {}, len(f)-1
for coeff in f:
poly[i], i = sympify(coeff), i-1
f = Poly(poly, x, field=True)
else:
try:
f = Poly(f, *gens, **flags)
except GeneratorsNeeded:
if multiple:
return []
else:
return {}
if f.is_multivariate:
raise PolynomialError('multivariate polynomials are not supported')
f, x = f.to_field(), f.gen
def _update_dict(result, root, k):
if root in result:
result[root] += k
else:
result[root] = k
def _try_decompose(f):
"""Find roots using functional decomposition. """
factors = f.decompose()
result, g = {}, factors[0]
for h, i in g.sqf_list()[1]:
for r in _try_heuristics(h):
_update_dict(result, r, i)
for factor in factors[1:]:
last, result = result.copy(), {}
for last_r, i in last.iteritems():
g = factor - Poly(last_r, x)
for h, j in g.sqf_list()[1]:
for r in _try_heuristics(h):
_update_dict(result, r, i*j)
return result
#.........这里部分代码省略.........