本文整理汇总了Python中sympy.polys.densebasic.dmp_zero函数的典型用法代码示例。如果您正苦于以下问题:Python dmp_zero函数的具体用法?Python dmp_zero怎么用?Python dmp_zero使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dmp_zero函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: dmp_zz_collins_resultant
def dmp_zz_collins_resultant(f, g, u, K):
"""
Collins's modular resultant algorithm in `Z[X]`.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = x + y + 2
>>> g = 2*x*y + x + 3
>>> R.dmp_zz_collins_resultant(f, g)
-2*y**2 - 5*y + 1
"""
n = dmp_degree(f, u)
m = dmp_degree(g, u)
if n < 0 or m < 0:
return dmp_zero(u - 1)
A = dmp_max_norm(f, u, K)
B = dmp_max_norm(g, u, K)
a = dmp_ground_LC(f, u, K)
b = dmp_ground_LC(g, u, K)
v = u - 1
B = K(2)*K.factorial(K(n + m))*A**m*B**n
r, p, P = dmp_zero(v), K.one, K.one
while P <= B:
p = K(nextprime(p))
while not (a % p) or not (b % p):
p = K(nextprime(p))
F = dmp_ground_trunc(f, p, u, K)
G = dmp_ground_trunc(g, p, u, K)
try:
R = dmp_zz_modular_resultant(F, G, p, u, K)
except HomomorphismFailed:
continue
if K.is_one(P):
r = R
else:
r = dmp_apply_pairs(r, R, _collins_crt, (P, p, K), v, K)
P *= p
return r
开发者ID:AdrianPotter,项目名称:sympy,代码行数:57,代码来源:euclidtools.py
示例2: dmp_zz_collins_resultant
def dmp_zz_collins_resultant(f, g, u, K):
"""
Collins's modular resultant algorithm in `Z[X]`.
Examples
========
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.euclidtools import dmp_zz_collins_resultant
>>> f = ZZ.map([[1], [1, 2]])
>>> g = ZZ.map([[2, 1], [3]])
>>> dmp_zz_collins_resultant(f, g, 1, ZZ)
[-2, -5, 1]
"""
n = dmp_degree(f, u)
m = dmp_degree(g, u)
if n < 0 or m < 0:
return dmp_zero(u-1)
A = dmp_max_norm(f, u, K)
B = dmp_max_norm(g, u, K)
a = dmp_ground_LC(f, u, K)
b = dmp_ground_LC(g, u, K)
v = u - 1
B = K(2)*K.factorial(n+m)*A**m*B**n
r, p, P = dmp_zero(v), K.one, K.one
while P <= B:
p = K(nextprime(p))
while not (a % p) or not (b % p):
p = K(nextprime(p))
F = dmp_ground_trunc(f, p, u, K)
G = dmp_ground_trunc(g, p, u, K)
try:
R = dmp_zz_modular_resultant(F, G, p, u, K)
except HomomorphismFailed:
continue
if K.is_one(P):
r = R
else:
r = dmp_apply_pairs(r, R, _collins_crt, (P, p, K), v, K)
P *= p
return r
开发者ID:dyao-vu,项目名称:meta-core,代码行数:57,代码来源:euclidtools.py
示例3: _dmp_ff_trivial_gcd
def _dmp_ff_trivial_gcd(f, g, u, K):
"""Handle trivial cases in GCD algorithm over a field. """
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:
return (dmp_ground_monic(g, u, K), dmp_zero(u), dmp_ground(dmp_ground_LC(g, u, K), u))
elif zero_g:
return (dmp_ground_monic(f, u, K), dmp_ground(dmp_ground_LC(f, u, K), u), dmp_zero(u))
elif query("USE_SIMPLIFY_GCD"):
return _dmp_simplify_gcd(f, g, u, K)
else:
return None
开发者ID:mattpap,项目名称:sympy,代码行数:15,代码来源:euclidtools.py
示例4: dmp_eval_tail
def dmp_eval_tail(f, A, u, K):
"""
Evaluate a polynomial at ``x_j = a_j, ...`` in ``K[X]``.
Examples
========
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.densetools import dmp_eval_tail
>>> f = ZZ.map([[2, 3], [1, 2]])
>>> dmp_eval_tail(f, (2, 2), 1, ZZ)
18
>>> dmp_eval_tail(f, (2,), 1, ZZ)
[7, 4]
"""
if not A:
return f
if dmp_zero_p(f, u):
return dmp_zero(u - len(A))
e = _rec_eval_tail(f, 0, A, u, K)
if u == len(A) - 1:
return e
else:
return dmp_strip(e, u - len(A))
开发者ID:jenshnielsen,项目名称:sympy,代码行数:30,代码来源:densetools.py
示例5: dmp_fateman_poly_F_1
def dmp_fateman_poly_F_1(n, K):
"""Fateman's GCD benchmark: trivial GCD """
u = [K(1), K(0)]
for i in xrange(0, n):
u = [dmp_one(i, K), u]
v = [K(1), K(0), K(0)]
for i in xrange(0, n):
v = [dmp_one(i, K), dmp_zero(i), v]
m = n - 1
U = dmp_add_term(u, dmp_ground(K(1), m), 0, n, K)
V = dmp_add_term(u, dmp_ground(K(2), m), 0, n, K)
f = [[-K(3), K(0)], [], [K(1), K(0), -K(1)]]
W = dmp_add_term(v, dmp_ground(K(1), m), 0, n, K)
Y = dmp_raise(f, m, 1, K)
F = dmp_mul(U, V, n, K)
G = dmp_mul(W, Y, n, K)
H = dmp_one(n, K)
return F, G, H
开发者ID:Acebulf,项目名称:sympy,代码行数:28,代码来源:specialpolys.py
示例6: dmp_discriminant
def dmp_discriminant(f, u, K):
"""
Computes discriminant of a polynomial in ``K[X]``.
**Examples**
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.euclidtools import dmp_discriminant
>>> f = ZZ.map([[[[1]], [[]]], [[[1], []]], [[[1, 0]]]])
>>> dmp_discriminant(f, 3, ZZ)
[[[-4, 0]], [[1], [], []]]
"""
if not u:
return dup_discriminant(f, K)
d, v = dmp_degree(f, u), u-1
if d <= 0:
return dmp_zero(v)
else:
s = (-1)**((d*(d-1)) // 2)
c = dmp_LC(f, K)
r = dmp_resultant(f, dmp_diff(f, 1, u, K), u, K)
c = dmp_mul_ground(c, K(s), v, K)
return dmp_exquo(r, c, v, K)
开发者ID:addisonc,项目名称:sympy,代码行数:30,代码来源:euclidtools.py
示例7: dmp_mul_term
def dmp_mul_term(f, c, i, u, K):
"""
Multiply ``f`` by ``c(x_2..x_u)*x_0**i`` in ``K[X]``.
**Examples**
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.densearith import dmp_mul_term
>>> f = ZZ.map([[1, 0], [1], []])
>>> c = ZZ.map([3, 0])
>>> dmp_mul_term(f, c, 2, 1, ZZ)
[[3, 0, 0], [3, 0], [], [], []]
"""
if not u:
return dup_mul_term(f, c, i, K)
v = u-1
if dmp_zero_p(f, u):
return f
if dmp_zero_p(c, v):
return dmp_zero(u)
else:
return [ dmp_mul(cf, c, v, K) for cf in f ] + dmp_zeros(i, v, K)
开发者ID:101man,项目名称:sympy,代码行数:27,代码来源:densearith.py
示例8: dmp_mul
def dmp_mul(f, g, u, K):
"""Multiply dense polynomials in `K[X]`. """
if not u:
return dup_mul(f, g, K)
if f == g:
return dmp_sqr(f, u, K)
df = dmp_degree(f, u)
if df < 0:
return f
dg = dmp_degree(g, u)
if dg < 0:
return g
h, v = [], u-1
for i in xrange(0, df+dg+1):
coeff = dmp_zero(v)
for j in xrange(max(0, i-dg), min(df, i)+1):
coeff = dmp_add(coeff, dmp_mul(f[j], g[i-j], v, K), v, K)
h.append(coeff)
return h
开发者ID:Aang,项目名称:sympy,代码行数:29,代码来源:densearith.py
示例9: dmp_sqr
def dmp_sqr(f, u, K):
"""Square dense polynomials in `K[X]`. """
if not u:
return dup_sqr(f, K)
df = dmp_degree(f, u)
if df < 0:
return f
h, v = [], u-1
for i in xrange(0, 2*df+1):
c = dmp_zero(v)
jmin = max(0, i-df)
jmax = min(i, df)
n = jmax - jmin + 1
jmax = jmin + n // 2 - 1
for j in xrange(jmin, jmax+1):
c = dmp_add(c, dmp_mul(f[j], f[i-j], v, K), v, K)
c = dmp_mul_ground(c, 2, v, K)
if n & 1:
elem = dmp_sqr(f[jmax+1], v, K)
c = dmp_add(c, elem, v, K)
h.append(c)
return h
开发者ID:Aang,项目名称:sympy,代码行数:34,代码来源:densearith.py
示例10: dmp_eval_tail
def dmp_eval_tail(f, A, u, K):
"""
Evaluate a polynomial at ``x_j = a_j, ...`` in ``K[X]``.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = 2*x*y + 3*x + y + 2
>>> R.dmp_eval_tail(f, [2])
7*x + 4
>>> R.dmp_eval_tail(f, [2, 2])
18
"""
if not A:
return f
if dmp_zero_p(f, u):
return dmp_zero(u - len(A))
e = _rec_eval_tail(f, 0, A, u, K)
if u == len(A) - 1:
return e
else:
return dmp_strip(e, u - len(A))
开发者ID:asmeurer,项目名称:sympy,代码行数:30,代码来源:densetools.py
示例11: dmp_mul_term
def dmp_mul_term(f, c, i, u, K):
"""
Multiply ``f`` by ``c(x_2..x_u)*x_0**i`` in ``K[X]``.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_mul_term(x**2*y + x, 3*y, 2)
3*x**4*y**2 + 3*x**3*y
"""
if not u:
return dup_mul_term(f, c, i, K)
v = u - 1
if dmp_zero_p(f, u):
return f
if dmp_zero_p(c, v):
return dmp_zero(u)
else:
return [ dmp_mul(cf, c, v, K) for cf in f ] + dmp_zeros(i, v, K)
开发者ID:QuaBoo,项目名称:sympy,代码行数:25,代码来源:densearith.py
示例12: dmp_discriminant
def dmp_discriminant(f, u, K):
"""
Computes discriminant of a polynomial in `K[X]`.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x,y,z,t = ring("x,y,z,t", ZZ)
>>> R.dmp_discriminant(x**2*y + x*z + t)
-4*y*t + z**2
"""
if not u:
return dup_discriminant(f, K)
d, v = dmp_degree(f, u), u - 1
if d <= 0:
return dmp_zero(v)
else:
s = (-1)**((d*(d - 1)) // 2)
c = dmp_LC(f, K)
r = dmp_resultant(f, dmp_diff(f, 1, u, K), u, K)
c = dmp_mul_ground(c, K(s), v, K)
return dmp_quo(r, c, v, K)
开发者ID:AdrianPotter,项目名称:sympy,代码行数:29,代码来源:euclidtools.py
示例13: dup_real_imag
def dup_real_imag(f, K):
"""
Return bivariate polynomials ``f1`` and ``f2``, such that ``f = f1 + f2*I``.
Examples
========
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.densetools import dup_real_imag
>>> dup_real_imag([ZZ(1), ZZ(1), ZZ(1), ZZ(1)], ZZ)
([[1], [1], [-3, 0, 1], [-1, 0, 1]], [[3, 0], [2, 0], [-1, 0, 1, 0]])
"""
if not K.is_ZZ and not K.is_QQ:
raise DomainError(
"computing real and imaginary parts is not supported over %s" % K)
f1 = dmp_zero(1)
f2 = dmp_zero(1)
if not f:
return f1, f2
g = [[[K.one, K.zero]], [[K.one], []]]
h = dmp_ground(f[0], 2)
for c in f[1:]:
h = dmp_mul(h, g, 2, K)
h = dmp_add_term(h, dmp_ground(c, 1), 0, 2, K)
H = dup_to_raw_dict(h)
for k, h in H.iteritems():
m = k % 4
if not m:
f1 = dmp_add(f1, h, 1, K)
elif m == 1:
f2 = dmp_add(f2, h, 1, K)
elif m == 2:
f1 = dmp_sub(f1, h, 1, K)
else:
f2 = dmp_sub(f2, h, 1, K)
return f1, f2
开发者ID:jenshnielsen,项目名称:sympy,代码行数:46,代码来源:densetools.py
示例14: dup_real_imag
def dup_real_imag(f, K):
"""
Return bivariate polynomials ``f1`` and ``f2``, such that ``f = f1 + f2*I``.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dup_real_imag(x**3 + x**2 + x + 1)
(x**3 + x**2 - 3*x*y**2 + x - y**2 + 1, 3*x**2*y + 2*x*y - y**3 + y)
"""
if not K.is_ZZ and not K.is_QQ:
raise DomainError("computing real and imaginary parts is not supported over %s" % K)
f1 = dmp_zero(1)
f2 = dmp_zero(1)
if not f:
return f1, f2
g = [[[K.one, K.zero]], [[K.one], []]]
h = dmp_ground(f[0], 2)
for c in f[1:]:
h = dmp_mul(h, g, 2, K)
h = dmp_add_term(h, dmp_ground(c, 1), 0, 2, K)
H = dup_to_raw_dict(h)
for k, h in H.items():
m = k % 4
if not m:
f1 = dmp_add(f1, h, 1, K)
elif m == 1:
f2 = dmp_add(f2, h, 1, K)
elif m == 2:
f1 = dmp_sub(f1, h, 1, K)
else:
f2 = dmp_sub(f2, h, 1, K)
return f1, f2
开发者ID:asmeurer,项目名称:sympy,代码行数:45,代码来源:densetools.py
示例15: dmp_pdiv
def dmp_pdiv(f, g, u, K):
"""
Polynomial pseudo-division in ``K[X]``.
Examples
========
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.densearith import dmp_pdiv
>>> f = ZZ.map([[1], [1, 0], []])
>>> g = ZZ.map([[2], [2]])
>>> dmp_pdiv(f, g, 1, ZZ)
([[2], [2, -2]], [[-4, 4]])
"""
if not u:
return dup_pdiv(f, g, K)
df = dmp_degree(f, u)
dg = dmp_degree(g, u)
if dg < 0:
raise ZeroDivisionError("polynomial division")
q, r = dmp_zero(u), f
if df < dg:
return q, r
N = df - dg + 1
lc_g = dmp_LC(g, K)
while True:
dr = dmp_degree(r, u)
if dr < dg:
break
lc_r = dmp_LC(r, K)
j, N = dr-dg, N-1
Q = dmp_mul_term(q, lc_g, 0, u, K)
q = dmp_add_term(Q, lc_r, j, u, K)
R = dmp_mul_term(r, lc_g, 0, u, K)
G = dmp_mul_term(g, lc_r, j, u, K)
r = dmp_sub(R, G, u, K)
c = dmp_pow(lc_g, N, u-1, K)
q = dmp_mul_term(q, c, 0, u, K)
r = dmp_mul_term(r, c, 0, u, K)
return q, r
开发者ID:SwaathiRamesh,项目名称:sympy,代码行数:56,代码来源:densearith.py
示例16: dmp_pdiv
def dmp_pdiv(f, g, u, K):
"""
Polynomial pseudo-division in ``K[X]``.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_pdiv(x**2 + x*y, 2*x + 2)
(2*x + 2*y - 2, -4*y + 4)
"""
if not u:
return dup_pdiv(f, g, K)
df = dmp_degree(f, u)
dg = dmp_degree(g, u)
if dg < 0:
raise ZeroDivisionError("polynomial division")
q, r, dr = dmp_zero(u), f, df
if df < dg:
return q, r
N = df - dg + 1
lc_g = dmp_LC(g, K)
while True:
lc_r = dmp_LC(r, K)
j, N = dr - dg, N - 1
Q = dmp_mul_term(q, lc_g, 0, u, K)
q = dmp_add_term(Q, lc_r, j, u, K)
R = dmp_mul_term(r, lc_g, 0, u, K)
G = dmp_mul_term(g, lc_r, j, u, K)
r = dmp_sub(R, G, u, K)
_dr, dr = dr, dmp_degree(r, u)
if dr < dg:
break
elif not (dr < _dr):
raise PolynomialDivisionFailed(f, g, K)
c = dmp_pow(lc_g, N, u - 1, K)
q = dmp_mul_term(q, c, 0, u, K)
r = dmp_mul_term(r, c, 0, u, K)
return q, r
开发者ID:QuaBoo,项目名称:sympy,代码行数:55,代码来源:densearith.py
示例17: dmp_ff_div
def dmp_ff_div(f, g, u, K):
"""
Polynomial division with remainder over a field.
Examples
========
>>> from sympy.polys.domains import QQ
>>> from sympy.polys.densearith import dmp_ff_div
>>> f = QQ.map([[1], [1, 0], []])
>>> g = QQ.map([[2], [2]])
>>> dmp_ff_div(f, g, 1, QQ)
([[1/2], [1/2, -1/2]], [[-1/1, 1/1]])
"""
if not u:
return dup_ff_div(f, g, K)
df = dmp_degree(f, u)
dg = dmp_degree(g, u)
if dg < 0:
raise ZeroDivisionError("polynomial division")
q, r = dmp_zero(u), f
if df < dg:
return q, r
lc_g, v = dmp_LC(g, K), u-1
while True:
dr = dmp_degree(r, u)
if dr < dg:
break
lc_r = dmp_LC(r, K)
c, R = dmp_ff_div(lc_r, lc_g, v, K)
if not dmp_zero_p(R, v):
break
j = dr - dg
q = dmp_add_term(q, c, j, u, K)
h = dmp_mul_term(g, c, j, u, K)
r = dmp_sub(r, h, u, K)
return q, r
开发者ID:SwaathiRamesh,项目名称:sympy,代码行数:54,代码来源:densearith.py
示例18: dmp_rr_div
def dmp_rr_div(f, g, u, K):
"""
Multivariate division with remainder over a ring.
**Examples**
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.densearith import dmp_rr_div
>>> f = ZZ.map([[1], [1, 0], []])
>>> g = ZZ.map([[2], [2]])
>>> dmp_rr_div(f, g, 1, ZZ)
([[]], [[1], [1, 0], []])
"""
if not u:
return dup_rr_div(f, g, K)
df = dmp_degree(f, u)
dg = dmp_degree(g, u)
if dg < 0:
raise ZeroDivisionError("polynomial division")
q, r = dmp_zero(u), f
if df < dg:
return q, r
lc_g, v = dmp_LC(g, K), u-1
while True:
dr = dmp_degree(r, u)
if dr < dg:
break
lc_r = dmp_LC(r, K)
c, R = dmp_rr_div(lc_r, lc_g, v, K)
if not dmp_zero_p(R, v):
break
j = dr - dg
q = dmp_add_term(q, c, j, u, K)
h = dmp_mul_term(g, c, j, u, K)
r = dmp_sub(r, h, u, K)
return q, r
开发者ID:101man,项目名称:sympy,代码行数:53,代码来源:densearith.py
示例19: _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
开发者ID:addisonc,项目名称:sympy,代码行数:21,代码来源:euclidtools.py
示例20: dmp_mul_term
def dmp_mul_term(f, c, i, u, K):
"""Multiply `f` by `c(x_2..x_u)*x_0**i` in `K[X]`. """
if not u:
return dup_mul_term(f, c, i, K)
v = u-1
if dmp_zero_p(f, u):
return f
if dmp_zero_p(c, v):
return dmp_zero(u)
else:
return [ dmp_mul(cf, c, v, K) for cf in f ] + dmp_zeros(i, v, K)
开发者ID:Aang,项目名称:sympy,代码行数:13,代码来源:densearith.py
注:本文中的sympy.polys.densebasic.dmp_zero函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论