本文整理汇总了Python中sympy.polys.densearith.dup_neg函数的典型用法代码示例。如果您正苦于以下问题:Python dup_neg函数的具体用法?Python dup_neg怎么用?Python dup_neg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dup_neg函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: dup_sqf_part
def dup_sqf_part(f, K):
"""
Returns square-free part of a polynomial in ``K[x]``.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_sqf_part(x**3 - 3*x - 2)
x**2 - x - 2
"""
if K.is_FiniteField:
return dup_gf_sqf_part(f, K)
if not f:
return f
if K.is_negative(dup_LC(f, K)):
f = dup_neg(f, K)
gcd = dup_gcd(f, dup_diff(f, 1, K), K)
sqf = dup_quo(f, gcd, K)
if K.has_Field:
return dup_monic(sqf, K)
else:
return dup_primitive(sqf, K)[1]
开发者ID:alhirzel,项目名称:sympy,代码行数:30,代码来源:sqfreetools.py
示例2: dup_sqf_part
def dup_sqf_part(f, K):
"""
Returns square-free part of a polynomial in ``K[x]``.
Examples
========
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.sqfreetools import dup_sqf_part
>>> dup_sqf_part([ZZ(1), ZZ(0), -ZZ(3), -ZZ(2)], ZZ)
[1, -1, -2]
"""
if not K.has_CharacteristicZero:
return dup_gf_sqf_part(f, K)
if not f:
return f
if K.is_negative(dup_LC(f, K)):
f = dup_neg(f, K)
gcd = dup_gcd(f, dup_diff(f, 1, K), K)
sqf = dup_quo(f, gcd, K)
if K.has_Field or not K.is_Exact:
return dup_monic(sqf, K)
else:
return dup_primitive(sqf, K)[1]
开发者ID:FireJade,项目名称:sympy,代码行数:30,代码来源:sqfreetools.py
示例3: dup_zz_factor_sqf
def dup_zz_factor_sqf(f, K):
"""Factor square-free (non-primitive) polyomials in `Z[x]`. """
cont, g = dup_primitive(f, K)
n = dup_degree(g)
if dup_LC(g, K) < 0:
cont, g = -cont, dup_neg(g, K)
if n <= 0:
return cont, []
elif n == 1:
return cont, [(g, 1)]
if query('USE_IRREDUCIBLE_IN_FACTOR'):
if dup_zz_irreducible_p(g, K):
return cont, [(g, 1)]
factors = None
if query('USE_CYCLOTOMIC_FACTOR'):
factors = dup_zz_cyclotomic_factor(g, K)
if factors is None:
factors = dup_zz_zassenhaus(g, K)
return cont, _sort_factors(factors, multiple=False)
开发者ID:TeddyBoomer,项目名称:wxgeometrie,代码行数:27,代码来源:factortools.py
示例4: _dup_rr_trivial_gcd
def _dup_rr_trivial_gcd(f, g, K):
"""Handle trivial cases in GCD algorithm over a ring. """
if not (f or g):
return [], [], []
elif not f:
if K.is_nonnegative(dup_LC(g, K)):
return g, [], [K.one]
else:
return dup_neg(g, K), [], [-K.one]
elif not g:
if K.is_nonnegative(dup_LC(f, K)):
return f, [K.one], []
else:
return dup_neg(f, K), [-K.one], []
return None
开发者ID:addisonc,项目名称:sympy,代码行数:16,代码来源:euclidtools.py
示例5: test_dup_neg
def test_dup_neg():
assert dup_neg([], ZZ) == []
assert dup_neg([ZZ(1)], ZZ) == [ZZ(-1)]
assert dup_neg([ZZ(-7)], ZZ) == [ZZ(7)]
assert dup_neg([ZZ(-1),ZZ(2),ZZ(3)], ZZ) == [ZZ(1),ZZ(-2),ZZ(-3)]
assert dup_neg([], QQ) == []
assert dup_neg([QQ(1,2)], QQ) == [QQ(-1,2)]
assert dup_neg([QQ(-7,9)], QQ) == [QQ(7,9)]
assert dup_neg([QQ(-1,7),QQ(2,7),QQ(3,7)], QQ) == [QQ(1,7),QQ(-2,7),QQ(-3,7)]
开发者ID:BDGLunde,项目名称:sympy,代码行数:10,代码来源:test_densearith.py
示例6: dup_sqf_list
def dup_sqf_list(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
>>> f = ZZ.map([2, 16, 50, 76, 56, 16])
>>> dup_sqf_list(f, ZZ)
(2, [([1, 1], 2), ([1, 2], 3)])
>>> dup_sqf_list(f, ZZ, all=True)
(2, [([1], 1), ([1, 1], 2), ([1, 2], 3)])
"""
if not K.has_CharacteristicZero:
return dup_gf_sqf_list(f, K, all=all)
if K.has_Field or not K.is_Exact:
coeff = dup_LC(f, K)
f = dup_monic(f, K)
else:
coeff, f = dup_primitive(f, K)
if K.is_negative(dup_LC(f, K)):
f = dup_neg(f, K)
coeff = -coeff
if dup_degree(f) <= 0:
return coeff, []
result, i = [], 1
h = dup_diff(f, 1, K)
g, p, q = dup_inner_gcd(f, h, K)
while True:
d = dup_diff(p, 1, K)
h = dup_sub(q, d, K)
if not h:
result.append((p, i))
break
g, p, q = dup_inner_gcd(p, h, K)
if all or dup_degree(g) > 0:
result.append((g, i))
i += 1
return coeff, result
开发者ID:FireJade,项目名称:sympy,代码行数:56,代码来源:sqfreetools.py
示例7: dup_sqf_list
def dup_sqf_list(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(f)
(2, [(x + 1, 2), (x + 2, 3)])
>>> R.dup_sqf_list(f, all=True)
(2, [(1, 1), (x + 1, 2), (x + 2, 3)])
"""
if K.is_FiniteField:
return dup_gf_sqf_list(f, K, all=all)
if K.has_Field:
coeff = dup_LC(f, K)
f = dup_monic(f, K)
else:
coeff, f = dup_primitive(f, K)
if K.is_negative(dup_LC(f, K)):
f = dup_neg(f, K)
coeff = -coeff
if dup_degree(f) <= 0:
return coeff, []
result, i = [], 1
h = dup_diff(f, 1, K)
g, p, q = dup_inner_gcd(f, h, K)
while True:
d = dup_diff(p, 1, K)
h = dup_sub(q, d, K)
if not h:
result.append((p, i))
break
g, p, q = dup_inner_gcd(p, h, K)
if all or dup_degree(g) > 0:
result.append((g, i))
i += 1
return coeff, result
开发者ID:alhirzel,项目名称:sympy,代码行数:55,代码来源:sqfreetools.py
示例8: dmp_zz_wang_test_points
def dmp_zz_wang_test_points(f, T, ct, A, u, K):
"""Wang/EEZ: Test evaluation points for suitability. """
if not dmp_eval_tail(dmp_LC(f, K), A, u-1, K):
raise EvaluationFailed('no luck')
g = dmp_eval_tail(f, A, u, K)
if not dup_sqf_p(g, K):
raise EvaluationFailed('no luck')
c, h = dup_primitive(g, K)
if K.is_negative(dup_LC(h, K)):
c, h = -c, dup_neg(h, K)
v = u-1
E = [ dmp_eval_tail(t, A, v, K) for t, _ in T ]
D = dmp_zz_wang_non_divisors(E, c, ct, K)
if D is not None:
return c, h, E
else:
raise EvaluationFailed('no luck')
开发者ID:TeddyBoomer,项目名称:wxgeometrie,代码行数:24,代码来源:factortools.py
示例9: dup_zz_factor_sqf
def dup_zz_factor_sqf(f, K, **args):
"""Factor square-free (non-primitive) polyomials in `Z[x]`. """
cont, g = dup_primitive(f, K)
n = dup_degree(g)
if dup_LC(g, K) < 0:
cont, g = -cont, dup_neg(g, K)
if n <= 0:
return cont, []
if n == 1 or dup_zz_irreducible_p(g, K):
return cont, [(g, 1)]
factors = []
if args.get('cyclotomic', True):
factors = dup_zz_cyclotomic_factor(g, K)
if factors is None:
factors = dup_zz_zassenhaus(g, K)
return cont, _sort_factors(factors, multiple=False)
开发者ID:Aang,项目名称:sympy,代码行数:24,代码来源:factortools.py
示例10: dup_zz_factor
def dup_zz_factor(f, K):
"""
Factor (non square-free) polynomials in `Z[x]`.
Given a univariate polynomial `f` in `Z[x]` computes its complete
factorization `f_1, ..., f_n` into irreducibles over integers::
f = content(f) f_1**k_1 ... f_n**k_n
The factorization is computed by reducing the input polynomial
into a primitive square-free polynomial and factoring it using
Zassenhaus algorithm. Trial division is used to recover the
multiplicities of factors.
The result is returned as a tuple consisting of::
(content(f), [(f_1, k_1), ..., (f_n, k_n))
Consider polynomial `f = 2*x**4 - 2`::
>>> from sympy.polys.factortools import dup_zz_factor
>>> from sympy.polys.domains import ZZ
>>> dup_zz_factor([2, 0, 0, 0, -2], ZZ)
(2, [([1, -1], 1), ([1, 1], 1), ([1, 0, 1], 1)])
In result we got the following factorization::
f = 2 (x - 1) (x + 1) (x**2 + 1)
Note that this is a complete factorization over integers,
however over Gaussian integers we can factor the last term.
By default, polynomials `x**n - 1` and `x**n + 1` are factored
using cyclotomic decomposition to speedup computations. To
disable this behaviour set cyclotomic=False.
**References**
1. [Gathen99]_
"""
cont, g = dup_primitive(f, K)
n = dup_degree(g)
if dup_LC(g, K) < 0:
cont, g = -cont, dup_neg(g, K)
if n <= 0:
return cont, []
elif n == 1:
return cont, [(g, 1)]
if query('USE_IRREDUCIBLE_IN_FACTOR'):
if dup_zz_irreducible_p(g, K):
return cont, [(g, 1)]
g = dup_sqf_part(g, K)
H, factors = None, []
if query('USE_CYCLOTOMIC_FACTOR'):
H = dup_zz_cyclotomic_factor(g, K)
if H is None:
H = dup_zz_zassenhaus(g, K)
for h in H:
k = 0
while True:
q, r = dup_div(f, h, K)
if not r:
f, k = q, k+1
else:
break
factors.append((h, k))
return cont, _sort_factors(factors)
开发者ID:TeddyBoomer,项目名称:wxgeometrie,代码行数:81,代码来源:factortools.py
示例11: dup_zz_cyclotomic_p
def dup_zz_cyclotomic_p(f, K, irreducible=False):
"""
Efficiently test if ``f`` is a cyclotomic polnomial.
**Examples**
>>> from sympy.polys.factortools import dup_zz_cyclotomic_p
>>> from sympy.polys.domains import ZZ
>>> f = [1, 0, 1, 0, 0, 0,-1, 0, 1, 0,-1, 0, 0, 0, 1, 0, 1]
>>> dup_zz_cyclotomic_p(f, ZZ)
False
>>> g = [1, 0, 1, 0, 0, 0,-1, 0,-1, 0,-1, 0, 0, 0, 1, 0, 1]
>>> dup_zz_cyclotomic_p(g, ZZ)
True
"""
if K.is_QQ:
try:
K0, K = K, K.get_ring()
f = dup_convert(f, K0, K)
except CoercionFailed:
return False
elif not K.is_ZZ:
return False
lc = dup_LC(f, K)
tc = dup_TC(f, K)
if lc != 1 or (tc != -1 and tc != 1):
return False
if not irreducible:
coeff, factors = dup_factor_list(f, K)
if coeff != K.one or factors != [(f, 1)]:
return False
n = dup_degree(f)
g, h = [], []
for i in xrange(n, -1, -2):
g.insert(0, f[i])
for i in xrange(n-1, -1, -2):
h.insert(0, f[i])
g = dup_sqr(dup_strip(g), K)
h = dup_sqr(dup_strip(h), K)
F = dup_sub(g, dup_lshift(h, 1, K), K)
if K.is_negative(dup_LC(F, K)):
F = dup_neg(F, K)
if F == f:
return True
g = dup_mirror(f, K)
if K.is_negative(dup_LC(g, K)):
g = dup_neg(g, K)
if F == g and dup_zz_cyclotomic_p(g, K):
return True
G = dup_sqf_part(F, K)
if dup_sqr(G, K) == F and dup_zz_cyclotomic_p(G, K):
return True
return False
开发者ID:TeddyBoomer,项目名称:wxgeometrie,代码行数:73,代码来源:factortools.py
示例12: neg
def neg(f):
return f.per(dup_neg(f.rep, f.dom))
开发者ID:fxkr,项目名称:sympy,代码行数:2,代码来源:polyclasses.py
示例13: dup_zz_factor
def dup_zz_factor(f, K):
"""
Factor (non square-free) polynomials in `Z[x]`.
Given a univariate polynomial `f` in `Z[x]` computes its complete
factorization `f_1, ..., f_n` into irreducibles over integers::
f = content(f) f_1**k_1 ... f_n**k_n
The factorization is computed by reducing the input polynomial
into a primitive square-free polynomial and factoring it using
Zassenhaus algorithm. Trial division is used to recover the
multiplicities of factors.
The result is returned as a tuple consisting of::
(content(f), [(f_1, k_1), ..., (f_n, k_n))
Consider polynomial `f = 2*x**4 - 2`::
>>> from sympy.polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_zz_factor(2*x**4 - 2)
(2, [(x - 1, 1), (x + 1, 1), (x**2 + 1, 1)])
In result we got the following factorization::
f = 2 (x - 1) (x + 1) (x**2 + 1)
Note that this is a complete factorization over integers,
however over Gaussian integers we can factor the last term.
By default, polynomials `x**n - 1` and `x**n + 1` are factored
using cyclotomic decomposition to speedup computations. To
disable this behaviour set cyclotomic=False.
References
==========
1. [Gathen99]_
"""
cont, g = dup_primitive(f, K)
n = dup_degree(g)
if dup_LC(g, K) < 0:
cont, g = -cont, dup_neg(g, K)
if n <= 0:
return cont, []
elif n == 1:
return cont, [(g, 1)]
if query('USE_IRREDUCIBLE_IN_FACTOR'):
if dup_zz_irreducible_p(g, K):
return cont, [(g, 1)]
g = dup_sqf_part(g, K)
H = None
if query('USE_CYCLOTOMIC_FACTOR'):
H = dup_zz_cyclotomic_factor(g, K)
if H is None:
H = dup_zz_zassenhaus(g, K)
factors = dup_trial_division(f, H, K)
return cont, factors
开发者ID:abhi98khandelwal,项目名称:sympy,代码行数:70,代码来源:factortools.py
注:本文中的sympy.polys.densearith.dup_neg函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论