本文整理汇总了Python中sympy.polys.densebasic.dup_strip函数的典型用法代码示例。如果您正苦于以下问题:Python dup_strip函数的具体用法?Python dup_strip怎么用?Python dup_strip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dup_strip函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dup_strip
def test_dup_strip():
assert dup_strip([]) == []
assert dup_strip([0]) == []
assert dup_strip([0,0,0]) == []
assert dup_strip([1]) == [1]
assert dup_strip([0,1]) == [1]
assert dup_strip([0,0,0,1]) == [1]
assert dup_strip([1,2,0]) == [1,2,0]
assert dup_strip([0,1,2,0]) == [1,2,0]
assert dup_strip([0,0,0,1,2,0]) == [1,2,0]
示例2: dup_trunc
def dup_trunc(f, p, K):
"""
Reduce a ``K[x]`` polynomial modulo a constant ``p`` in ``K``.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_trunc(2*x**3 + 3*x**2 + 5*x + 7, ZZ(3))
-x**3 - x + 1
"""
if K.is_ZZ:
g = []
for c in f:
c = c % p
if c > p // 2:
g.append(c - p)
else:
g.append(c)
else:
g = [ c % p for c in f ]
return dup_strip(g)
示例3: dup_compose
def dup_compose(f, g, K):
"""
Evaluate functional composition ``f(g)`` in ``K[x]``.
Examples
========
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.densetools import dup_compose
>>> f = ZZ.map([1, 1, 0])
>>> g = ZZ.map([1, -1])
>>> dup_compose(f, g, ZZ)
[1, -1, 0]
"""
if len(g) <= 1:
return dup_strip([dup_eval(f, dup_LC(g, K), K)])
if not f:
return []
h = [f[0]]
for c in f[1:]:
h = dup_mul(h, g, K)
h = dup_add_term(h, c, 0, K)
return h
示例4: dup_trunc
def dup_trunc(f, p, K):
"""
Reduce ``K[x]`` polynomial modulo a constant ``p`` in ``K``.
Examples
========
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.densetools import dup_trunc
>>> f = ZZ.map([2, 3, 5, 7])
>>> dup_trunc(f, ZZ(3), ZZ)
[-1, 0, -1, 1]
"""
if K.is_ZZ:
g = []
for c in f:
c = c % p
if c > p // 2:
g.append(c - p)
else:
g.append(c)
else:
g = [ c % p for c in f ]
return dup_strip(g)
示例5: dup_compose
def dup_compose(f, g, K):
"""
Evaluate functional composition ``f(g)`` in ``K[x]``.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_compose(x**2 + x, x - 1)
x**2 - x
"""
if len(g) <= 1:
return dup_strip([dup_eval(f, dup_LC(g, K), K)])
if not f:
return []
h = [f[0]]
for c in f[1:]:
h = dup_mul(h, g, K)
h = dup_add_term(h, c, 0, K)
return h
示例6: dup_add
def dup_add(f, g, K):
"""
Add dense polynomials in ``K[x]``.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_add(x**2 - 1, x - 2)
x**2 + x - 3
"""
if not f:
return g
if not g:
return f
df = dup_degree(f)
dg = dup_degree(g)
if df == dg:
return dup_strip([ a + b for a, b in zip(f, g) ])
else:
k = abs(df - dg)
if df > dg:
h, f = f[:k], f[k:]
else:
h, g = g[:k], g[k:]
return h + [ a + b for a, b in zip(f, g) ]
示例7: dup_sqf_list_include
def dup_sqf_list_include(f, 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 dup_sqf_list_include
>>> f = ZZ.map([2, 16, 50, 76, 56, 16])
>>> dup_sqf_list_include(f, ZZ)
[([2], 1), ([1, 1], 2), ([1, 2], 3)]
>>> dup_sqf_list_include(f, ZZ, all=True)
[([2], 1), ([1, 1], 2), ([1, 2], 3)]
"""
coeff, factors = dup_sqf_list(f, K, all=all)
if factors and factors[0][1] == 1:
g = dup_mul_ground(factors[0][0], coeff, K)
return [(g, 1)] + factors[1:]
else:
g = dup_strip([coeff])
return [(g, 1)] + factors
示例8: dup_sub_term
def dup_sub_term(f, c, i, K):
"""
Subtract ``c*x**i`` from ``f`` in ``K[x]``.
**Examples**
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.densearith import dup_sub_term
>>> f = ZZ.map([2, 0, 1, 0, -1])
>>> dup_sub_term(f, ZZ(2), 4, ZZ)
[1, 0, -1]
"""
if not c:
return f
n = len(f)
m = n-i-1
if i == n-1:
return dup_strip([f[0]-c] + f[1:])
else:
if i >= n:
return [-c] + [K.zero]*(i-n) + f
else:
return f[:m] + [f[m]-c] + f[m+1:]
示例9: dup_sub
def dup_sub(f, g, K):
"""
Subtract dense polynomials in ``K[x]``.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_sub(x**2 - 1, x - 2)
x**2 - x + 1
"""
if not f:
return dup_neg(g, K)
if not g:
return f
df = dup_degree(f)
dg = dup_degree(g)
if df == dg:
return dup_strip([ a - b for a, b in zip(f, g) ])
else:
k = abs(df - dg)
if df > dg:
h, f = f[:k], f[k:]
else:
h, g = dup_neg(g[:k], K), g[k:]
return h + [ a - b for a, b in zip(f, g) ]
示例10: dup_sub
def dup_sub(f, g, K):
"""
Subtract dense polynomials in ``K[x]``.
**Examples**
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.densearith import dup_sub
>>> f = ZZ.map([1, 0, -1])
>>> g = ZZ.map([1, -2])
>>> dup_sub(f, g, ZZ)
[1, -1, 1]
"""
if not f:
return dup_neg(g, K)
if not g:
return f
df = dup_degree(f)
dg = dup_degree(g)
if df == dg:
return dup_strip([ a - b for a, b in zip(f, g) ])
else:
k = abs(df - dg)
if df > dg:
h, f = f[:k], f[k:]
else:
h, g = dup_neg(g[:k], K), g[k:]
return h + [ a - b for a, b in zip(f, g) ]
示例11: dup_mul
def dup_mul(f, g, K):
"""
Multiply dense polynomials in ``K[x]``.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_mul(x - 2, x + 2)
x**2 - 4
"""
if f == g:
return dup_sqr(f, K)
if not (f and g):
return []
df = dup_degree(f)
dg = dup_degree(g)
h = []
for i in xrange(0, df + dg + 1):
coeff = K.zero
for j in xrange(max(0, i - dg), min(df, i) + 1):
coeff += f[j]*g[i - j]
h.append(coeff)
return dup_strip(h)
示例12: dup_sub_term
def dup_sub_term(f, c, i, K):
"""
Subtract ``c*x**i`` from ``f`` in ``K[x]``.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_sub_term(2*x**4 + x**2 - 1, ZZ(2), 4)
x**2 - 1
"""
if not c:
return f
n = len(f)
m = n - i - 1
if i == n - 1:
return dup_strip([f[0] - c] + f[1:])
else:
if i >= n:
return [-c] + [K.zero]*(i - n) + f
else:
return f[:m] + [f[m] - c] + f[m + 1:]
示例13: dup_add_term
def dup_add_term(f, c, i, K):
"""
Add ``c*x**i`` to ``f`` in ``K[x]``.
Examples
========
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.densearith import dup_add_term
>>> f = ZZ.map([1, 0, -1])
>>> dup_add_term(f, ZZ(2), 4, ZZ)
[2, 0, 1, 0, -1]
"""
if not c:
return f
n = len(f)
m = n-i-1
if i == n-1:
return dup_strip([f[0]+c] + f[1:])
else:
if i >= n:
return [c] + [K.zero]*(i-n) + f
else:
return f[:m] + [f[m]+c] + f[m+1:]
示例14: dup_sqf_list_include
def dup_sqf_list_include(f, K, all=False):
"""
Return square-free decomposition of a polynomial in ``K[x]``.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> f = 2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16
>>> R.dup_sqf_list_include(f)
[(2, 1), (x + 1, 2), (x + 2, 3)]
>>> R.dup_sqf_list_include(f, all=True)
[(2, 1), (x + 1, 2), (x + 2, 3)]
"""
coeff, factors = dup_sqf_list(f, K, all=all)
if factors and factors[0][1] == 1:
g = dup_mul_ground(factors[0][0], coeff, K)
return [(g, 1)] + factors[1:]
else:
g = dup_strip([coeff])
return [(g, 1)] + factors
示例15: dup_factor_list
def dup_factor_list(f, K0, **args):
"""Factor polynomials into irreducibles in `K[x]`. """
if not K0.has_CharacteristicZero: # pragma: no cover
raise DomainError('only characteristic zero allowed')
if K0.is_Algebraic:
coeff, factors = dup_ext_factor(f, K0)
else:
if not K0.is_Exact:
K0_inexact, K0 = K0, K0.get_exact()
f = dup_convert(f, K0_inexact, K0)
else:
K0_inexact = None
if K0.has_Field:
K = K0.get_ring()
denom, f = dup_ground_to_ring(f, K0, K)
f = dup_convert(f, K0, K)
else:
K = K0
if K.is_ZZ:
coeff, factors = dup_zz_factor(f, K, **args)
elif K.is_Poly:
f, u = dmp_inject(f, 0, K)
coeff, factors = dmp_factor_list(f, u, K.dom, **args)
for i, (f, k) in enumerate(factors):
factors[i] = (dmp_eject(f, u, K), k)
coeff = K.convert(coeff, K.dom)
else: # pragma: no cover
raise DomainError('factorization not supported over %s' % K0)
if K0.has_Field:
for i, (f, k) in enumerate(factors):
factors[i] = (dup_convert(f, K, K0), k)
coeff = K0.convert(coeff, K)
denom = K0.convert(denom, K)
coeff = K0.quo(coeff, denom)
if K0_inexact is not None:
for i, (f, k) in enumerate(factors):
factors[i] = (dup_convert(f, K0, K0_inexact), k)
coeff = K0_inexact.convert(coeff, K0)
if not args.get('include', False):
return coeff, factors
else:
if not factors:
return [(dup_strip([coeff]), 1)]
else:
g = dup_mul_ground(factors[0][0], coeff, K)
return [(g, factors[0][1])] + factors[1:]