本文整理汇总了Python中sympy.polys.densearith.dup_mul函数的典型用法代码示例。如果您正苦于以下问题:Python dup_mul函数的具体用法?Python dup_mul怎么用?Python dup_mul使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dup_mul函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dup_transform
def dup_transform(f, p, q, K):
"""
Evaluate functional transformation ``q**n * f(p/q)`` in ``K[x]``.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_transform(x**2 - 2*x + 1, x**2 + 1, x - 1)
x**4 - 2*x**3 + 5*x**2 - 4*x + 4
"""
if not f:
return []
n = len(f) - 1
h, Q = [f[0]], [[K.one]]
for i in range(0, n):
Q.append(dup_mul(Q[-1], q, K))
for c, q in zip(f[1:], Q[1:]):
h = dup_mul(h, p, K)
q = dup_mul_ground(q, c, K)
h = dup_add(h, q, K)
return h
示例2: dup_transform
def dup_transform(f, p, q, K):
"""
Evaluate functional transformation ``q**n * f(p/q)`` in ``K[x]``.
Examples
========
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.densetools import dup_transform
>>> f = ZZ.map([1, -2, 1])
>>> p = ZZ.map([1, 0, 1])
>>> q = ZZ.map([1, -1])
>>> dup_transform(f, p, q, ZZ)
[1, -2, 5, -4, 4]
"""
if not f:
return []
n = dup_degree(f)
h, Q = [f[0]], [[K.one]]
for i in xrange(0, n):
Q.append(dup_mul(Q[-1], q, K))
for c, q in zip(f[1:], Q[1:]):
h = dup_mul(h, p, K)
q = dup_mul_ground(q, c, K)
h = dup_add(h, q, K)
return h
示例3: test_dup_gcdex
def test_dup_gcdex():
f = dup_normal([1,-2,-6,12,15], QQ)
g = dup_normal([1,1,-4,-4], QQ)
s = [QQ(-1,5),QQ(3,5)]
t = [QQ(1,5),QQ(-6,5),QQ(2)]
h = [QQ(1),QQ(1)]
assert dup_half_gcdex(f, g, QQ) == (s, h)
assert dup_gcdex(f, g, QQ) == (s, t, h)
f = dup_normal([1,4,0,-1,1], QQ)
g = dup_normal([1,0,-1,1], QQ)
s, t, h = dup_gcdex(f, g, QQ)
S, T, H = dup_gcdex(g, f, QQ)
assert dup_add(dup_mul(s, f, QQ),
dup_mul(t, g, QQ), QQ) == h
assert dup_add(dup_mul(S, g, QQ),
dup_mul(T, f, QQ), QQ) == H
f = dup_normal([2,0], QQ)
g = dup_normal([1,0,-16], QQ)
s = [QQ(1,32),QQ(0)]
t = [QQ(-1,16)]
h = [QQ(1)]
assert dup_half_gcdex(f, g, QQ) == (s, h)
assert dup_gcdex(f, g, QQ) == (s, t, h)
示例4: test_dmp_mul
def test_dmp_mul():
assert dmp_mul([ZZ(5)], [ZZ(7)], 0, ZZ) == dup_mul([ZZ(5)], [ZZ(7)], ZZ)
assert dmp_mul([QQ(5, 7)], [QQ(3, 7)], 0, QQ) == dup_mul([QQ(5, 7)], [QQ(3, 7)], QQ)
assert dmp_mul([[[]]], [[[]]], 2, ZZ) == [[[]]]
assert dmp_mul([[[ZZ(1)]]], [[[]]], 2, ZZ) == [[[]]]
assert dmp_mul([[[]]], [[[ZZ(1)]]], 2, ZZ) == [[[]]]
assert dmp_mul([[[ZZ(2)]]], [[[ZZ(1)]]], 2, ZZ) == [[[ZZ(2)]]]
assert dmp_mul([[[ZZ(1)]]], [[[ZZ(2)]]], 2, ZZ) == [[[ZZ(2)]]]
assert dmp_mul([[[]]], [[[]]], 2, QQ) == [[[]]]
assert dmp_mul([[[QQ(1, 2)]]], [[[]]], 2, QQ) == [[[]]]
assert dmp_mul([[[]]], [[[QQ(1, 2)]]], 2, QQ) == [[[]]]
assert dmp_mul([[[QQ(2, 7)]]], [[[QQ(1, 3)]]], 2, QQ) == [[[QQ(2, 21)]]]
assert dmp_mul([[[QQ(1, 7)]]], [[[QQ(2, 3)]]], 2, QQ) == [[[QQ(2, 21)]]]
示例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_gff_list
def dup_gff_list(f, K):
"""
Compute greatest factorial factorization of ``f`` in ``K[x]``.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_gff_list(x**5 + 2*x**4 - x**3 - 2*x**2)
[(x, 1), (x + 2, 4)]
"""
if not f:
raise ValueError("greatest factorial factorization doesn't exist for a zero polynomial")
f = dup_monic(f, K)
if not dup_degree(f):
return []
else:
g = dup_gcd(f, dup_shift(f, K.one, K), K)
H = dup_gff_list(g, K)
for i, (h, k) in enumerate(H):
g = dup_mul(g, dup_shift(h, -K(k), K), K)
H[i] = (h, k + 1)
f = dup_quo(f, g, K)
if not dup_degree(f):
return H
else:
return [(f, 1)] + H
示例7: dup_rr_lcm
def dup_rr_lcm(f, g, K):
"""
Computes polynomial LCM over a ring in ``K[x]``.
**Examples**
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.euclidtools import dup_rr_lcm
>>> f = ZZ.map([1, 0, -1])
>>> g = ZZ.map([1, -3, 2])
>>> dup_rr_lcm(f, g, ZZ)
[1, -2, -1, 2]
"""
fc, f = dup_primitive(f, K)
gc, g = dup_primitive(g, K)
c = K.lcm(fc, gc)
h = dup_exquo(dup_mul(f, g, K),
dup_gcd(f, g, K), K)
return dup_mul_ground(h, c, K)
示例8: 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
示例9: dup_revert
def dup_revert(f, n, K):
"""
Compute ``f**(-1)`` mod ``x**n`` using Newton iteration.
This function computes first ``2**n`` terms of a polynomial that
is a result of inversion of a polynomial modulo ``x**n``. This is
useful to efficiently compute series expansion of ``1/f``.
Examples
========
>>> from sympy.polys.domains import QQ
>>> from sympy.polys.densetools import dup_revert
>>> f = [-QQ(1,720), QQ(0), QQ(1,24), QQ(0), -QQ(1,2), QQ(0), QQ(1)]
>>> dup_revert(f, 8, QQ)
[61/720, 0/1, 5/24, 0/1, 1/2, 0/1, 1/1]
"""
g = [K.revert(dup_TC(f, K))]
h = [K.one, K.zero, K.zero]
N = int(_ceil(_log(n, 2)))
for i in xrange(1, N + 1):
a = dup_mul_ground(g, K(2), K)
b = dup_mul(f, dup_sqr(g, K), K)
g = dup_rem(dup_sub(a, b, K), h, K)
h = dup_lshift(h, dup_degree(h), K)
return g
示例10: dup_revert
def dup_revert(f, n, K):
"""
Compute ``f**(-1)`` mod ``x**n`` using Newton iteration.
This function computes first ``2**n`` terms of a polynomial that
is a result of inversion of a polynomial modulo ``x**n``. This is
useful to efficiently compute series expansion of ``1/f``.
Examples
========
>>> from sympy.polys import ring, QQ
>>> R, x = ring("x", QQ)
>>> f = -QQ(1,720)*x**6 + QQ(1,24)*x**4 - QQ(1,2)*x**2 + 1
>>> R.dup_revert(f, 8)
61/720*x**6 + 5/24*x**4 + 1/2*x**2 + 1
"""
g = [K.revert(dup_TC(f, K))]
h = [K.one, K.zero, K.zero]
N = int(_ceil(_log(n, 2)))
for i in range(1, N + 1):
a = dup_mul_ground(g, K(2), K)
b = dup_mul(f, dup_sqr(g, K), K)
g = dup_rem(dup_sub(a, b, K), h, K)
h = dup_lshift(h, dup_degree(h), K)
return g
示例11: dup_zz_hensel_step
def dup_zz_hensel_step(m, f, g, h, s, t, K):
"""
One step in Hensel lifting in `Z[x]`.
Given positive integer `m` and `Z[x]` polynomials `f`, `g`, `h`, `s`
and `t` such that::
f == g*h (mod m)
s*g + t*h == 1 (mod m)
lc(f) is not a zero divisor (mod m)
lc(h) == 1
deg(f) == deg(g) + deg(h)
deg(s) < deg(h)
deg(t) < deg(g)
returns polynomials `G`, `H`, `S` and `T`, such that::
f == G*H (mod m**2)
S*G + T**H == 1 (mod m**2)
References
==========
1. [Gathen99]_
"""
M = m**2
e = dup_sub_mul(f, g, h, K)
e = dup_trunc(e, M, K)
q, r = dup_div(dup_mul(s, e, K), h, K)
q = dup_trunc(q, M, K)
r = dup_trunc(r, M, K)
u = dup_add(dup_mul(t, e, K), dup_mul(q, g, K), K)
G = dup_trunc(dup_add(g, u, K), M, K)
H = dup_trunc(dup_add(h, r, K), M, K)
u = dup_add(dup_mul(s, G, K), dup_mul(t, H, K), K)
b = dup_trunc(dup_sub(u, [K.one], K), M, K)
c, d = dup_div(dup_mul(s, b, K), H, K)
c = dup_trunc(c, M, K)
d = dup_trunc(d, M, K)
u = dup_add(dup_mul(t, b, K), dup_mul(c, G, K), K)
S = dup_trunc(dup_sub(s, d, K), M, K)
T = dup_trunc(dup_sub(t, u, K), M, K)
return G, H, S, T
示例12: dup_laguerre
def dup_laguerre(n, alpha, K):
"""Low-level implementation of Laguerre polynomials. """
seq = [[K.zero], [K.one]]
for i in range(1, n + 1):
a = dup_mul(seq[-1], [-K.one/i, alpha/i + K(2*i - 1)/i], K)
b = dup_mul_ground(seq[-2], alpha/i + K(i - 1)/i, K)
seq.append(dup_sub(a, b, K))
return seq[-1]
示例13: dup_laguerre
def dup_laguerre(n, K):
"""Low-level implementation of Laguerre polynomials. """
seq = [[K.one], [-K.one, K.one]]
for i in xrange(2, n+1):
a = dup_mul(seq[-1], [-K(1, i), K(2*i-1, i)], K)
b = dup_mul_ground(seq[-2], K(i-1, i), K)
seq.append(dup_sub(a, b, K))
return seq[n]
示例14: test_dmp_mul
def test_dmp_mul():
assert dmp_mul([ZZ(5)], [ZZ(7)], 0, ZZ) == \
dup_mul([ZZ(5)], [ZZ(7)], ZZ)
assert dmp_mul([QQ(5,7)], [QQ(3,7)], 0, QQ) == \
dup_mul([QQ(5,7)], [QQ(3,7)], QQ)
assert dmp_mul([[[]]], [[[]]], 2, ZZ) == [[[]]]
assert dmp_mul([[[ZZ(1)]]], [[[]]], 2, ZZ) == [[[]]]
assert dmp_mul([[[]]], [[[ZZ(1)]]], 2, ZZ) == [[[]]]
assert dmp_mul([[[ZZ(2)]]], [[[ZZ(1)]]], 2, ZZ) == [[[ZZ(2)]]]
assert dmp_mul([[[ZZ(1)]]], [[[ZZ(2)]]], 2, ZZ) == [[[ZZ(2)]]]
assert dmp_mul([[[]]], [[[]]], 2, QQ) == [[[]]]
assert dmp_mul([[[QQ(1,2)]]], [[[]]], 2, QQ) == [[[]]]
assert dmp_mul([[[]]], [[[QQ(1,2)]]], 2, QQ) == [[[]]]
assert dmp_mul([[[QQ(2,7)]]], [[[QQ(1,3)]]], 2, QQ) == [[[QQ(2,21)]]]
assert dmp_mul([[[QQ(1,7)]]], [[[QQ(2,3)]]], 2, QQ) == [[[QQ(2,21)]]]
K = FF(6)
assert dmp_mul([[K(2)],[K(1)]], [[K(3)],[K(4)]], 1, K) == [[K(5)],[K(4)]]
示例15: test_dmp_content
def test_dmp_content():
assert dmp_content([[-2]], 1, ZZ) == [2]
f, g, F = [ZZ(3),ZZ(2),ZZ(1)], [ZZ(1)], []
for i in xrange(0, 5):
g = dup_mul(g, f, ZZ)
F.insert(0, g)
assert dmp_content(F, 1, ZZ) == f
assert dmp_one_p(dmp_content(f_4, 2, ZZ), 1, ZZ)
assert dmp_one_p(dmp_content(f_5, 2, ZZ), 1, ZZ)
assert dmp_one_p(dmp_content(f_6, 3, ZZ), 2, ZZ)