本文整理汇总了Python中sympy.polys.densearith.dmp_neg函数的典型用法代码示例。如果您正苦于以下问题:Python dmp_neg函数的具体用法?Python dmp_neg怎么用?Python dmp_neg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dmp_neg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dmp_cancel
def dmp_cancel(f, g, u, K, multout=True):
"""
Cancel common factors in a rational function ``f/g``.
**Examples**
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.euclidtools import dmp_cancel
>>> f = ZZ.map([[2], [0], [-2]])
>>> g = ZZ.map([[1], [-2], [1]])
>>> dmp_cancel(f, g, 1, ZZ)
([[2], [2]], [[1], [-1]])
"""
if dmp_zero_p(f, u) or dmp_zero_p(g, u):
if multout:
return f, g
else:
return K.one, K.one, f, g
K0 = None
if K.has_Field and K.has_assoc_Ring:
K0, K = K, K.get_ring()
cq, f = dmp_clear_denoms(f, u, K0, K, convert=True)
cp, g = dmp_clear_denoms(g, u, K0, K, convert=True)
else:
cp, cq = K.one, K.one
_, p, q = dmp_inner_gcd(f, g, u, K)
if K0 is not None:
p = dmp_convert(p, u, K, K0)
q = dmp_convert(q, u, K, K0)
K = K0
p_neg = K.is_negative(dmp_ground_LC(p, u, K))
q_neg = K.is_negative(dmp_ground_LC(q, u, K))
if p_neg and q_neg:
p, q = dmp_neg(p, u, K), dmp_neg(q, u, K)
elif p_neg:
cp, p = -cp, dmp_neg(p, u, K)
elif q_neg:
cp, q = -cp, dmp_neg(q, u, K)
if not multout:
return cp, cq, p, q
p = dmp_mul_ground(p, cp, u, K)
q = dmp_mul_ground(q, cq, u, K)
return p, q
示例2: dmp_cancel
def dmp_cancel(f, g, u, K, include=True):
"""
Cancel common factors in a rational function `f/g`.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_cancel(2*x**2 - 2, x**2 - 2*x + 1)
(2*x + 2, x - 1)
"""
K0 = None
if K.has_Field and K.has_assoc_Ring:
K0, K = K, K.get_ring()
cq, f = dmp_clear_denoms(f, u, K0, K, convert=True)
cp, g = dmp_clear_denoms(g, u, K0, K, convert=True)
else:
cp, cq = K.one, K.one
_, p, q = dmp_inner_gcd(f, g, u, K)
if K0 is not None:
_, cp, cq = K.cofactors(cp, cq)
p = dmp_convert(p, u, K, K0)
q = dmp_convert(q, u, K, K0)
K = K0
p_neg = K.is_negative(dmp_ground_LC(p, u, K))
q_neg = K.is_negative(dmp_ground_LC(q, u, K))
if p_neg and q_neg:
p, q = dmp_neg(p, u, K), dmp_neg(q, u, K)
elif p_neg:
cp, p = -cp, dmp_neg(p, u, K)
elif q_neg:
cp, q = -cp, dmp_neg(q, u, K)
if not include:
return cp, cq, p, q
p = dmp_mul_ground(p, cp, u, K)
q = dmp_mul_ground(q, cq, u, K)
return p, q
示例3: dmp_sqf_part
def dmp_sqf_part(f, u, K):
"""
Returns square-free part of a polynomial in ``K[X]``.
Examples
========
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.sqfreetools import dmp_sqf_part
>>> f = ZZ.map([[1], [2, 0], [1, 0, 0], []])
>>> dmp_sqf_part(f, 1, ZZ)
[[1], [1, 0], []]
"""
if not u:
return dup_sqf_part(f, K)
if not K.has_CharacteristicZero:
return dmp_gf_sqf_part(f, u, K)
if dmp_zero_p(f, u):
return f
if K.is_negative(dmp_ground_LC(f, u, K)):
f = dmp_neg(f, u, K)
gcd = dmp_gcd(f, dmp_diff(f, 1, u, K), u, K)
sqf = dmp_quo(f, gcd, u, K)
if K.has_Field or not K.is_Exact:
return dmp_ground_monic(sqf, u, K)
else:
return dmp_ground_primitive(sqf, u, K)[1]
示例4: dmp_content
def dmp_content(f, u, K):
"""
Returns GCD of multivariate coefficients.
**Examples**
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.euclidtools import dmp_content
>>> f = ZZ.map([[2, 6], [4, 12]])
>>> dmp_content(f, 1, ZZ)
[2, 6]
"""
cont, v = dmp_LC(f, K), u-1
if dmp_zero_p(f, u):
return cont
for c in f[1:]:
cont = dmp_gcd(cont, c, v, K)
if dmp_one_p(cont, v, K):
break
if K.is_negative(dmp_ground_LC(cont, v, K)):
return dmp_neg(cont, v, K)
else:
return cont
示例5: dmp_sqf_part
def dmp_sqf_part(f, u, K):
"""
Returns square-free part of a polynomial in ``K[X]``.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_sqf_part(x**3 + 2*x**2*y + x*y**2)
x**2 + x*y
"""
if not u:
return dup_sqf_part(f, K)
if K.is_FiniteField:
return dmp_gf_sqf_part(f, u, K)
if dmp_zero_p(f, u):
return f
if K.is_negative(dmp_ground_LC(f, u, K)):
f = dmp_neg(f, u, K)
gcd = dmp_gcd(f, dmp_diff(f, 1, u, K), u, K)
sqf = dmp_quo(f, gcd, u, K)
if K.has_Field:
return dmp_ground_monic(sqf, u, K)
else:
return dmp_ground_primitive(sqf, u, K)[1]
示例6: dmp_content
def dmp_content(f, u, K):
"""
Returns GCD of multivariate coefficients.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x,y, = ring("x,y", ZZ)
>>> R.dmp_content(2*x*y + 6*x + 4*y + 12)
2*y + 6
"""
cont, v = dmp_LC(f, K), u - 1
if dmp_zero_p(f, u):
return cont
for c in f[1:]:
cont = dmp_gcd(cont, c, v, K)
if dmp_one_p(cont, v, K):
break
if K.is_negative(dmp_ground_LC(cont, v, K)):
return dmp_neg(cont, v, K)
else:
return cont
示例7: dmp_sqf_list
def dmp_sqf_list(f, u, K, all=False):
"""
Return square-free decomposition of a polynomial in ``K[X]``.
Examples
========
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.sqfreetools import dmp_sqf_list
>>> f = ZZ.map([[1], [2, 0], [1, 0, 0], [], [], []])
>>> dmp_sqf_list(f, 1, ZZ)
(1, [([[1], [1, 0]], 2), ([[1], []], 3)])
>>> dmp_sqf_list(f, 1, ZZ, all=True)
(1, [([[1]], 1), ([[1], [1, 0]], 2), ([[1], []], 3)])
"""
if not u:
return dup_sqf_list(f, K, all=all)
if not K.has_CharacteristicZero:
return dmp_gf_sqf_list(f, u, K, all=all)
if K.has_Field or not K.is_Exact:
coeff = dmp_ground_LC(f, u, K)
f = dmp_ground_monic(f, u, K)
else:
coeff, f = dmp_ground_primitive(f, u, K)
if K.is_negative(dmp_ground_LC(f, u, K)):
f = dmp_neg(f, u, K)
coeff = -coeff
if dmp_degree(f, u) <= 0:
return coeff, []
result, i = [], 1
h = dmp_diff(f, 1, u, K)
g, p, q = dmp_inner_gcd(f, h, u, K)
while True:
d = dmp_diff(p, 1, u, K)
h = dmp_sub(q, d, u, K)
if dmp_zero_p(h, u):
result.append((p, i))
break
g, p, q = dmp_inner_gcd(p, h, u, K)
if all or dmp_degree(g, u) > 0:
result.append((g, i))
i += 1
return coeff, result
示例8: dmp_sqf_list
def dmp_sqf_list(f, u, K, all=False):
"""
Return square-free decomposition of a polynomial in ``K[X]``.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = x**5 + 2*x**4*y + x**3*y**2
>>> R.dmp_sqf_list(f)
(1, [(x + y, 2), (x, 3)])
>>> R.dmp_sqf_list(f, all=True)
(1, [(1, 1), (x + y, 2), (x, 3)])
"""
if not u:
return dup_sqf_list(f, K, all=all)
if K.is_FiniteField:
return dmp_gf_sqf_list(f, u, K, all=all)
if K.has_Field:
coeff = dmp_ground_LC(f, u, K)
f = dmp_ground_monic(f, u, K)
else:
coeff, f = dmp_ground_primitive(f, u, K)
if K.is_negative(dmp_ground_LC(f, u, K)):
f = dmp_neg(f, u, K)
coeff = -coeff
if dmp_degree(f, u) <= 0:
return coeff, []
result, i = [], 1
h = dmp_diff(f, 1, u, K)
g, p, q = dmp_inner_gcd(f, h, u, K)
while True:
d = dmp_diff(p, 1, u, K)
h = dmp_sub(q, d, u, K)
if dmp_zero_p(h, u):
result.append((p, i))
break
g, p, q = dmp_inner_gcd(p, h, u, K)
if all or dmp_degree(g, u) > 0:
result.append((g, i))
i += 1
return coeff, result
示例9: test_dmp_neg
def test_dmp_neg():
assert dmp_neg([ZZ(-1)], 0, ZZ) == [ZZ(1)]
assert dmp_neg([QQ(-1,2)], 0, QQ) == [QQ(1,2)]
assert dmp_neg([[[]]], 2, ZZ) == [[[]]]
assert dmp_neg([[[ZZ(1)]]], 2, ZZ) == [[[ZZ(-1)]]]
assert dmp_neg([[[ZZ(-7)]]], 2, ZZ) == [[[ZZ(7)]]]
assert dmp_neg([[[]]], 2, QQ) == [[[]]]
assert dmp_neg([[[QQ(1,9)]]], 2, QQ) == [[[QQ(-1,9)]]]
assert dmp_neg([[[QQ(-7,9)]]], 2, QQ) == [[[QQ(7,9)]]]
示例10: _parse
def _parse(cls, rep, dom, lev=None):
if type(rep) is tuple:
num, den = rep
if lev is not None:
if type(num) is dict:
num = dmp_from_dict(num, lev, dom)
if type(den) is dict:
den = dmp_from_dict(den, lev, dom)
else:
num, num_lev = dmp_validate(num)
den, den_lev = dmp_validate(den)
if num_lev == den_lev:
lev = num_lev
else:
raise ValueError('inconsistent number of levels')
if dmp_zero_p(den, lev):
raise ZeroDivisionError('fraction denominator')
if dmp_zero_p(num, lev):
den = dmp_one(lev, dom)
else:
if dmp_negative_p(den, lev, dom):
num = dmp_neg(num, lev, dom)
den = dmp_neg(den, lev, dom)
else:
num = rep
if lev is not None:
if type(num) is dict:
num = dmp_from_dict(num, lev, dom)
elif type(num) is not list:
num = dmp_ground(dom.convert(num), lev)
else:
num, lev = dmp_validate(num)
den = dmp_one(lev, dom)
return num, den, lev
示例11: _dmp_rr_trivial_gcd
def _dmp_rr_trivial_gcd(f, g, u, K):
"""Handle trivial cases in GCD algorithm over a ring. """
zero_f = dmp_zero_p(f, u)
zero_g = dmp_zero_p(g, u)
if zero_f and zero_g:
return tuple(dmp_zeros(3, u, K))
elif zero_f:
if K.is_nonnegative(dmp_ground_LC(g, u, K)):
return g, dmp_zero(u), dmp_one(u, K)
else:
return dmp_neg(g, u, K), dmp_zero(u), dmp_ground(-K.one, u)
elif zero_g:
if K.is_nonnegative(dmp_ground_LC(f, u, K)):
return f, dmp_one(u, K), dmp_zero(u)
else:
return dmp_neg(f, u, K), dmp_ground(-K.one, u), dmp_zero(u)
elif query('USE_SIMPLIFY_GCD'):
return _dmp_simplify_gcd(f, g, u, K)
else:
return None
示例12: test_dmp_sqf
def test_dmp_sqf():
assert dmp_sqf_part([[]], 1, ZZ) == [[]]
assert dmp_sqf_p([[]], 1, ZZ) == True
assert dmp_sqf_part([[7]], 1, ZZ) == [[1]]
assert dmp_sqf_p([[7]], 1, ZZ) == True
assert dmp_sqf_p(f_0, 2, ZZ) == True
assert dmp_sqf_p(dmp_sqr(f_0, 2, ZZ), 2, ZZ) == False
assert dmp_sqf_p(f_1, 2, ZZ) == True
assert dmp_sqf_p(dmp_sqr(f_1, 2, ZZ), 2, ZZ) == False
assert dmp_sqf_p(f_2, 2, ZZ) == True
assert dmp_sqf_p(dmp_sqr(f_2, 2, ZZ), 2, ZZ) == False
assert dmp_sqf_p(f_3, 2, ZZ) == True
assert dmp_sqf_p(dmp_sqr(f_3, 2, ZZ), 2, ZZ) == False
assert dmp_sqf_p(f_5, 2, ZZ) == False
assert dmp_sqf_p(dmp_sqr(f_5, 2, ZZ), 2, ZZ) == False
assert dmp_sqf_p(f_4, 2, ZZ) == True
assert dmp_sqf_part(f_4, 2, ZZ) == dmp_neg(f_4, 2, ZZ)
assert dmp_sqf_p(f_6, 3, ZZ) == True
assert dmp_sqf_part(f_6, 3, ZZ) == f_6
assert dmp_sqf_part(f_5, 2, ZZ) == [[[1]], [[1], [-1, 0]]]
assert dup_sqf_list([], ZZ) == (ZZ(0), [])
assert dup_sqf_list_include([], ZZ) == [([], 1)]
assert dmp_sqf_list([[ZZ(3)]], 1, ZZ) == (ZZ(3), [])
assert dmp_sqf_list_include([[ZZ(3)]], 1, ZZ) == [([[ZZ(3)]], 1)]
f = [-1,1,0,0,1,-1]
assert dmp_sqf_list(f, 0, ZZ) == \
(-1, [([1,1,1,1], 1), ([1,-1], 2)])
assert dmp_sqf_list_include(f, 0, ZZ) == \
[([-1,-1,-1,-1], 1), ([1,-1], 2)]
f = [[-1],[1],[],[],[1],[-1]]
assert dmp_sqf_list(f, 1, ZZ) == \
(-1, [([[1],[1],[1],[1]], 1), ([[1],[-1]], 2)])
assert dmp_sqf_list_include(f, 1, ZZ) == \
[([[-1],[-1],[-1],[-1]], 1), ([[1],[-1]], 2)]
K = FF(2)
f = [[-1], [2], [-1]]
assert dmp_sqf_list_include(f, 1, ZZ) == \
[([[-1]], 1), ([[1], [-1]], 2)]
raises(DomainError, "dmp_sqf_list([[K(1), K(0), K(1)]], 1, K)")
示例13: _dmp_zz_gcd_interpolate
def _dmp_zz_gcd_interpolate(h, x, v, K):
"""Interpolate polynomial GCD from integer GCD. """
f = []
while not dmp_zero_p(h, v):
g = dmp_ground_trunc(h, x, v, K)
f.insert(0, g)
h = dmp_sub(h, g, v, K)
h = dmp_exquo_ground(h, x, v, K)
if K.is_negative(dmp_ground_LC(f, v+1, K)):
return dmp_neg(f, v+1, K)
else:
return f
示例14: dmp_fateman_poly_F_3
def dmp_fateman_poly_F_3(n, K):
"""Fateman's GCD benchmark: sparse inputs (deg f ~ vars f) """
u = dup_from_raw_dict({n+1: K.one}, K)
for i in xrange(0, n-1):
u = dmp_add_term([u], dmp_one(i, K), n+1, i+1, K)
v = dmp_add_term(u, dmp_ground(K(2), n-2), 0, n, K)
f = dmp_sqr(dmp_add_term([dmp_neg(v, n-1, K)], dmp_one(n-1, K), n+1, n, K), n, K)
g = dmp_sqr(dmp_add_term([v], dmp_one(n-1, K), n+1, n, K), n, K)
v = dmp_add_term(u, dmp_one(n-2, K), 0, n-1, K)
h = dmp_sqr(dmp_add_term([v], dmp_one(n-1, K), n+1, n, K), n, K)
return dmp_mul(f, h, n, K), dmp_mul(g, h, n, K), h
示例15: dmp_rr_prs_gcd
def dmp_rr_prs_gcd(f, g, u, K):
"""
Computes polynomial GCD using subresultants over a ring.
Returns ``(h, cff, cfg)`` such that ``a = gcd(f, g)``, ``cff = quo(f, h)``,
and ``cfg = quo(g, h)``.
Examples
========
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.euclidtools import dmp_rr_prs_gcd
>>> f = ZZ.map([[1], [2, 0], [1, 0, 0]])
>>> g = ZZ.map([[1], [1, 0], []])
>>> dmp_rr_prs_gcd(f, g, 1, ZZ)
([[1], [1, 0]], [[1], [1, 0]], [[1], []])
"""
if not u:
return dup_rr_prs_gcd(f, g, K)
result = _dmp_rr_trivial_gcd(f, g, u, K)
if result is not None:
return result
fc, F = dmp_primitive(f, u, K)
gc, G = dmp_primitive(g, u, K)
h = dmp_subresultants(F, G, u, K)[-1]
c, _, _ = dmp_rr_prs_gcd(fc, gc, u-1, K)
if K.is_negative(dmp_ground_LC(h, u, K)):
h = dmp_neg(h, u, K)
_, h = dmp_primitive(h, u, K)
h = dmp_mul_term(h, c, 0, u, K)
cff = dmp_quo(f, h, u, K)
cfg = dmp_quo(g, h, u, K)
return h, cff, cfg