本文整理汇总了Python中sympy.polys.Poly.half_gcdex方法的典型用法代码示例。如果您正苦于以下问题:Python Poly.half_gcdex方法的具体用法?Python Poly.half_gcdex怎么用?Python Poly.half_gcdex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.polys.Poly
的用法示例。
在下文中一共展示了Poly.half_gcdex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apart_list_full_decomposition
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import half_gcdex [as 别名]
def apart_list_full_decomposition(P, Q, dummygen):
"""
Bronstein's full partial fraction decomposition algorithm.
Given a univariate rational function ``f``, performing only GCD
operations over the algebraic closure of the initial ground domain
of definition, compute full partial fraction decomposition with
fractions having linear denominators.
Note that no factorization of the initial denominator of ``f`` is
performed. The final decomposition is formed in terms of a sum of
:class:`RootSum` instances.
References
==========
1. [Bronstein93]_
"""
f, x, U = P/Q, P.gen, []
u = Function('u')(x)
a = Dummy('a')
partial = []
for d, n in Q.sqf_list_include(all=True):
b = d.as_expr()
U += [ u.diff(x, n - 1) ]
h = cancel(f*b**n) / u**n
H, subs = [h], []
for j in range(1, n):
H += [ H[-1].diff(x) / j ]
for j in range(1, n + 1):
subs += [ (U[j - 1], b.diff(x, j) / j) ]
for j in range(0, n):
P, Q = cancel(H[j]).as_numer_denom()
for i in range(0, j + 1):
P = P.subs(*subs[j - i])
Q = Q.subs(*subs[0])
P = Poly(P, x)
Q = Poly(Q, x)
G = P.gcd(d)
D = d.quo(G)
B, g = Q.half_gcdex(D)
b = (P * B.quo(g)).rem(D)
Dw = D.subs(x, dummygen.next())
numer = Lambda(a, b.as_expr().subs(x, a))
denom = Lambda(a, (x - a))
exponent = n-j
partial.append((Dw, numer, denom, exponent))
return partial
示例2: apart
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import half_gcdex [as 别名]
def apart(f, z=None, **args):
"""Computes partial fraction decomposition of a rational function.
Given a rational function 'f', performing only gcd operations
over the algebraic closure of the initial field of definition,
compute full partial fraction decomposition with fractions
having linear denominators.
For all other kinds of expressions the input is returned in an
unchanged form. Note however, that `apart` function can thread
over sums and relational operators.
Note that no factorization of the initial denominator of `f` is
needed. The final decomposition is formed in terms of a sum of
RootSum instances. By default RootSum tries to compute all its
roots to simplify itself. This behavior can be however avoided
by setting the keyword flag evaluate=False, which will make this
function return a formal decomposition.
>>> from sympy import apart
>>> from sympy.abc import x, y
>>> apart(y/(x+2)/(x+1), x)
y/(1 + x) - y/(2 + x)
>>> apart(1/(1+x**5), x, evaluate=False)
RootSum(Lambda(_a, -_a/(5*(x - _a))), x**5 + 1, x, domain='ZZ')
References
==========
.. [Bronstein93] M. Bronstein, B. Salvy, Full partial fraction
decomposition of rational functions, Proceedings ISSAC '93,
ACM Press, Kiev, Ukraine, 1993, pp. 157-160.
"""
f = cancel(f)
if z is None:
symbols = f.atoms(Symbol)
if not symbols:
return f
if len(symbols) == 1:
z = list(symbols)[0]
else:
raise ValueError("multivariate partial fractions are not supported")
P, Q = f.as_numer_denom()
if not Q.has(z):
return f
partial, r = div(P, Q, z)
f, q, U = r / Q, Q, []
u = Function('u')(z)
a = Dummy('a')
q = Poly(q, z)
for d, n in q.sqf_list(all=True, include=True):
b = d.as_basic()
U += [ u.diff(z, n-1) ]
h = cancel(f*b**n) / u**n
H, subs = [h], []
for j in range(1, n):
H += [ H[-1].diff(z) / j ]
for j in range(1, n+1):
subs += [ (U[j-1], b.diff(z, j) / j) ]
for j in range(0, n):
P, Q = cancel(H[j]).as_numer_denom()
for i in range(0, j+1):
P = P.subs(*subs[j-i])
Q = Q.subs(*subs[0])
P = Poly(P, z)
Q = Poly(Q, z)
G = P.gcd(d)
D = d.exquo(G)
B, g = Q.half_gcdex(D)
b = (P * B.exquo(g)).rem(D)
numer = b.as_basic()
denom = (z-a)**(n-j)
expr = numer.subs(z, a) / denom
partial += RootSum(Lambda(a, expr), D, **args)
#.........这里部分代码省略.........