本文整理汇总了Python中sympy.polys.Poly.as_basic方法的典型用法代码示例。如果您正苦于以下问题:Python Poly.as_basic方法的具体用法?Python Poly.as_basic怎么用?Python Poly.as_basic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.polys.Poly
的用法示例。
在下文中一共展示了Poly.as_basic方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ratint_ratpart
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import as_basic [as 别名]
def ratint_ratpart(f, g, x):
"""Horowitz-Ostrogradsky algorithm.
Given a field K and polynomials f and g in K[x], such that f and g
are coprime and deg(f) < deg(g), returns fractions A and B in K(x),
such that f/g = A' + B and B has square-free denominator.
"""
f = Poly(f, x)
g = Poly(g, x)
u, v, _ = g.cofactors(g.diff())
n = u.degree()
m = v.degree()
d = g.degree()
A_coeffs = [ Dummy('a' + str(n-i)) for i in xrange(0, n) ]
B_coeffs = [ Dummy('b' + str(m-i)) for i in xrange(0, m) ]
C_coeffs = A_coeffs + B_coeffs
A = Poly(A_coeffs, x, domain=ZZ[C_coeffs])
B = Poly(B_coeffs, x, domain=ZZ[C_coeffs])
H = f - A.diff()*v + A*(u.diff()*v).exquo(u) - B*u
result = solve(H.coeffs(), C_coeffs)
A = A.as_basic().subs(result)
B = B.as_basic().subs(result)
rat_part = cancel(A/u.as_basic(), x)
log_part = cancel(B/v.as_basic(), x)
return rat_part, log_part
示例2: roots
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import as_basic [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