本文整理汇总了Python中sympy.polys.polyroots.preprocess_roots函数的典型用法代码示例。如果您正苦于以下问题:Python preprocess_roots函数的具体用法?Python preprocess_roots怎么用?Python preprocess_roots使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了preprocess_roots函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __new__
def __new__(cls, f, x, index=None, radicals=False, expand=True):
""" Construct an indexed complex root of a polynomial.
See ``rootof`` for the parameters.
The default value of ``radicals`` is ``False`` to satisfy
``eval(srepr(expr) == expr``.
"""
x = sympify(x)
if index is None and x.is_Integer:
x, index = None, x
else:
index = sympify(index)
if index is not None and index.is_Integer:
index = int(index)
else:
raise ValueError("expected an integer root index, got %s" % index)
poly = PurePoly(f, x, greedy=False, expand=expand)
if not poly.is_univariate:
raise PolynomialError("only univariate polynomials are allowed")
if not poly.gen.is_Symbol:
# PurePoly(sin(x) + 1) == PurePoly(x + 1) but the roots of
# x for each are not the same: issue 8617
raise PolynomialError("generator must be a Symbol")
degree = poly.degree()
if degree <= 0:
raise PolynomialError("can't construct CRootOf object for %s" % f)
if index < -degree or index >= degree:
raise IndexError("root index out of [%d, %d] range, got %d" %
(-degree, degree - 1, index))
elif index < 0:
index += degree
dom = poly.get_domain()
if not dom.is_Exact:
poly = poly.to_exact()
roots = cls._roots_trivial(poly, radicals)
if roots is not None:
return roots[index]
coeff, poly = preprocess_roots(poly)
dom = poly.get_domain()
if not dom.is_ZZ:
raise NotImplementedError("CRootOf is not supported over %s" % dom)
root = cls._indexed_root(poly, index)
return coeff * cls._postprocess_root(root, radicals)
开发者ID:asmeurer,项目名称:sympy,代码行数:59,代码来源:rootoftools.py
示例2: test_roots_preprocessing
def test_roots_preprocessing():
f = a*y*x**2 + y - b
coeff, poly = preprocess_roots(Poly(f, x))
assert coeff == 1
assert poly == Poly(a*y*x**2 + y - b, x)
f = c**3*x**3 + c**2*x**2 + c*x + a
coeff, poly = preprocess_roots(Poly(f, x))
assert coeff == 1/c
assert poly == Poly(x**3 + x**2 + x + a, x)
f = c**3*x**3 + c**2*x**2 + a
coeff, poly = preprocess_roots(Poly(f, x))
assert coeff == 1/c
assert poly == Poly(x**3 + x**2 + a, x)
f = c**3*x**3 + c*x + a
coeff, poly = preprocess_roots(Poly(f, x))
assert coeff == 1/c
assert poly == Poly(x**3 + x + a, x)
f = c**3*x**3 + a
coeff, poly = preprocess_roots(Poly(f, x))
assert coeff == 1/c
assert poly == Poly(x**3 + a, x)
E, F, J, L = symbols("E,F,J,L")
f = -21601054687500000000*E**8*J**8/L**16 + \
508232812500000000*F*x*E**7*J**7/L**14 - \
4269543750000000*E**6*F**2*J**6*x**2/L**12 + \
16194716250000*E**5*F**3*J**5*x**3/L**10 - \
27633173750*E**4*F**4*J**4*x**4/L**8 + \
14840215*E**3*F**5*J**3*x**5/L**6 + \
54794*E**2*F**6*J**2*x**6/(5*L**4) - \
1153*E*J*F**7*x**7/(80*L**2) + \
633*F**8*x**8/160000
coeff, poly = preprocess_roots(Poly(f, x))
assert coeff == 20*E*J/(F*L**2)
assert poly == 633*x**8 - 115300*x**7 + 4383520*x**6 + 296804300*x**5 - 27633173750*x**4 + \
809735812500*x**3 - 10673859375000*x**2 + 63529101562500*x - 135006591796875
f = Poly(-y**2 + x**2*exp(x), y, domain=ZZ[x, exp(x)])
g = Poly(-y**2 + exp(x), y, domain=ZZ[exp(x)])
assert preprocess_roots(f) == (x, g)
开发者ID:NalinG,项目名称:sympy,代码行数:58,代码来源:test_polyroots.py
示例3: _preprocess_roots
def _preprocess_roots(cls, poly):
"""Take heroic measures to make ``poly`` compatible with ``RootOf``. """
dom = poly.get_domain()
if not dom.is_Exact:
poly = poly.to_exact()
coeff, poly = preprocess_roots(poly)
dom = poly.get_domain()
if not dom.is_ZZ:
raise NotImplementedError("RootOf is not supported over %s" % dom)
return coeff, poly
开发者ID:AALEKH,项目名称:sympy,代码行数:14,代码来源:rootoftools.py
示例4: __new__
def __new__(cls, f, x, index=None, radicals=True, expand=True):
"""Construct a new ``RootOf`` object for ``k``-th root of ``f``. """
x = sympify(x)
if index is None and x.is_Integer:
x, index = None, x
else:
index = sympify(index)
if index.is_Integer:
index = int(index)
else:
raise ValueError("expected an integer root index, got %d" % index)
poly = PurePoly(f, x, greedy=False, expand=expand)
if not poly.is_univariate:
raise PolynomialError("only univariate polynomials are allowed")
degree = poly.degree()
if degree <= 0:
raise PolynomialError("can't construct RootOf object for %s" % f)
if index < -degree or index >= degree:
raise IndexError("root index out of [%d, %d] range, got %d" %
(-degree, degree - 1, index))
elif index < 0:
index += degree
dom = poly.get_domain()
if not dom.is_Exact:
poly = poly.to_exact()
roots = cls._roots_trivial(poly, radicals)
if roots is not None:
return roots[index]
coeff, poly = preprocess_roots(poly)
dom = poly.get_domain()
if not dom.is_ZZ:
raise NotImplementedError("RootOf is not supported over %s" % dom)
root = cls._indexed_root(poly, index)
return coeff*cls._postprocess_root(root, radicals)
开发者ID:AALEKH,项目名称:sympy,代码行数:48,代码来源:rootoftools.py
示例5: _transform
def _transform(cls, expr, x):
"""Transform an expression to a polynomial. """
poly = PurePoly(expr, x, greedy=False)
return preprocess_roots(poly)
开发者ID:A-turing-machine,项目名称:sympy,代码行数:4,代码来源:rootoftools.py
示例6: __new__
def __new__(cls, f, x=None, indices=None, radicals=True, expand=True):
"""Construct a new ``RootOf`` object for ``k``-th root of ``f``. """
if indices is None and (not isinstance(x, Basic) or x.is_Integer):
x, indices = None, x
poly = Poly(f, x, greedy=False, expand=expand)
if not poly.is_univariate:
raise PolynomialError("only univariate polynomials are allowed")
degree = poly.degree()
if degree <= 0:
raise PolynomialError("can't construct RootOf object for %s" % f)
if indices is not None and indices is not True:
if hasattr(indices, "__iter__"):
indices, iterable = list(indices), True
else:
indices, iterable = [indices], False
indices = map(int, indices)
for i, index in enumerate(indices):
if index < -degree or index >= degree:
raise IndexError("root index out of [%d, %d] range, got %d" % (-degree, degree - 1, index))
elif index < 0:
indices[i] += degree
else:
iterable = True
if indices is True:
indices = range(degree)
dom = poly.get_domain()
if not dom.is_Exact:
poly = poly.to_exact()
roots = roots_trivial(poly, radicals)
if roots is not None:
if indices is not None:
result = [roots[index] for index in indices]
else:
result = [root for root in roots if root.is_real]
else:
coeff, poly = preprocess_roots(poly)
dom = poly.get_domain()
if not dom.is_ZZ:
raise NotImplementedError("RootOf is not supported over %s" % dom)
result = []
for data in _rootof_data(poly, indices):
poly, index, pointer, conjugate = data
roots = roots_trivial(poly, radicals)
if roots is not None:
result.append(coeff * roots[index])
else:
result.append(coeff * cls._new(poly, index, pointer, conjugate))
if not iterable:
return result[0]
else:
return result
开发者ID:jegerjensen,项目名称:sympy,代码行数:69,代码来源:rootoftools.py
示例7: test_roots_preprocessing
def test_roots_preprocessing():
f = a * y * x ** 2 + y - b
coeff, poly = preprocess_roots(Poly(f, x))
assert coeff == 1
assert poly == Poly(a * y * x ** 2 + y - b, x)
f = c ** 3 * x ** 3 + c ** 2 * x ** 2 + c * x + a
coeff, poly = preprocess_roots(Poly(f, x))
assert coeff == 1 / c
assert poly == Poly(x ** 3 + x ** 2 + x + a, x)
f = c ** 3 * x ** 3 + c ** 2 * x ** 2 + a
coeff, poly = preprocess_roots(Poly(f, x))
assert coeff == 1 / c
assert poly == Poly(x ** 3 + x ** 2 + a, x)
f = c ** 3 * x ** 3 + c * x + a
coeff, poly = preprocess_roots(Poly(f, x))
assert coeff == 1 / c
assert poly == Poly(x ** 3 + x + a, x)
f = c ** 3 * x ** 3 + a
coeff, poly = preprocess_roots(Poly(f, x))
assert coeff == 1 / c
assert poly == Poly(x ** 3 + a, x)
E, F, J, L = symbols("E,F,J,L")
f = (
-21601054687500000000 * E ** 8 * J ** 8 / L ** 16
+ 508232812500000000 * F * x * E ** 7 * J ** 7 / L ** 14
- 4269543750000000 * E ** 6 * F ** 2 * J ** 6 * x ** 2 / L ** 12
+ 16194716250000 * E ** 5 * F ** 3 * J ** 5 * x ** 3 / L ** 10
- 27633173750 * E ** 4 * F ** 4 * J ** 4 * x ** 4 / L ** 8
+ 14840215 * E ** 3 * F ** 5 * J ** 3 * x ** 5 / L ** 6
+ 54794 * E ** 2 * F ** 6 * J ** 2 * x ** 6 / (5 * L ** 4)
- 1153 * E * J * F ** 7 * x ** 7 / (80 * L ** 2)
+ 633 * F ** 8 * x ** 8 / 160000
)
coeff, poly = preprocess_roots(Poly(f, x))
assert coeff == 20 * E * J / (F * L ** 2)
assert (
poly
== 633 * x ** 8
- 115300 * x ** 7
+ 4383520 * x ** 6
+ 296804300 * x ** 5
- 27633173750 * x ** 4
+ 809735812500 * x ** 3
- 10673859375000 * x ** 2
+ 63529101562500 * x
- 135006591796875
)
开发者ID:alxspopov,项目名称:sympy,代码行数:65,代码来源:test_polyroots.py
注:本文中的sympy.polys.polyroots.preprocess_roots函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论