Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc fixes #729

Merged
merged 5 commits into from Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions diofant/domains/domain.py
Expand Up @@ -22,8 +22,8 @@ class Domain(DefaultPrinting, abc.ABC):
zero = None
one = None

has_Ring = False
has_Field = False
is_Ring = False
is_Field = False

has_assoc_Ring = False
has_assoc_Field = False
Expand Down Expand Up @@ -190,7 +190,7 @@ def unify(self, K1, symbols=()):

if ((self.is_FractionField and K1.is_PolynomialRing or
K1.is_FractionField and self.is_PolynomialRing) and
(not self_ground.has_Field or not K1_ground.has_Field) and domain.has_Field):
(not self_ground.is_Field or not K1_ground.is_Field) and domain.is_Field):
domain = domain.ring

if self.is_Composite and (not K1.is_Composite or self.is_FractionField or K1.is_PolynomialRing):
Expand Down
2 changes: 1 addition & 1 deletion diofant/domains/field.py
Expand Up @@ -9,7 +9,7 @@
class Field(Ring):
"""Represents a field domain. """

has_Field = True
is_Field = True

@property
def ring(self):
Expand Down
2 changes: 1 addition & 1 deletion diofant/domains/ring.py
Expand Up @@ -10,7 +10,7 @@
class Ring(Domain):
"""Represents a ring domain. """

has_Ring = True
is_Ring = True

@property
def ring(self):
Expand Down
2 changes: 1 addition & 1 deletion diofant/polys/__init__.py
Expand Up @@ -6,7 +6,7 @@
exquo, half_gcdex, gcdex, invert, subresultants,
resultant, discriminant, cofactors, gcd_list, gcd,
lcm_list, lcm, terms_gcd, trunc, monic, content,
primitive, compose, decompose, sturm, gff_list, gff,
primitive, compose, decompose, sturm,
sqf_norm, sqf_part, sqf_list, sqf, factor_list,
factor, intervals, refine_root, count_roots,
real_roots, nroots, ground_roots, nth_power_roots_poly,
Expand Down
6 changes: 1 addition & 5 deletions diofant/polys/compatibility.py
Expand Up @@ -48,7 +48,7 @@
dup_isolate_real_roots_sqf, dup_refine_real_root,
dup_root_upper_bound, dup_sturm)
from .sqfreetools import (dmp_sqf_list, dmp_sqf_list_include, dmp_sqf_norm,
dmp_sqf_part, dup_gff_list)
dmp_sqf_part)


__all__ = ('IPolys',)
Expand Down Expand Up @@ -540,10 +540,6 @@ def dmp_sqf_list_include(self, f):
factors = dmp_sqf_list_include(self.to_dense(f), self.ngens-1, self.domain)
return [(self.from_dense(g), k) for g, k in factors]

def dup_gff_list(self, f):
factors = dup_gff_list(self.to_dense(f), self.domain)
return [ (self.from_dense(g), k) for g, k in factors ]

def dup_root_upper_bound(self, f):
return dup_root_upper_bound(self.to_dense(f), self.domain)

Expand Down
4 changes: 2 additions & 2 deletions diofant/polys/densearith.py
Expand Up @@ -207,7 +207,7 @@ def dmp_quo_ground(f, c, u, K):
if not f:
return f

if K.has_Field:
if K.is_Field:
return [K.quo(coeff, c) for coeff in f]
else:
return [coeff // c for coeff in f]
Expand Down Expand Up @@ -1001,7 +1001,7 @@ def dmp_div(f, g, u, K):
>>> R.dmp_div(x**2 + x*y, 2*x + 2)
(1/2*x + 1/2*y - 1/2, -y + 1)
"""
if K.has_Field:
if K.is_Field:
return dmp_ff_div(f, g, u, K)
else:
return dmp_rr_div(f, g, u, K)
Expand Down
10 changes: 5 additions & 5 deletions diofant/polys/euclidtools.py
Expand Up @@ -37,7 +37,7 @@ def dup_half_gcdex(f, g, K):
>>> R.dup_half_gcdex(f, g)
(-1/5*x + 3/5, x + 1)
"""
if not K.has_Field:
if not K.is_Field:
raise DomainError("can't compute half extended GCD over %s" % K)

a, b = [K.one], []
Expand Down Expand Up @@ -640,7 +640,7 @@ def dmp_resultant(f, g, u, K, includePRS=False):
if includePRS:
return dmp_prs_resultant(f, g, u, K)

if K.has_Field:
if K.is_Field:
if K.is_RationalField and query('USE_COLLINS_RESULTANT'):
return dmp_qq_collins_resultant(f, g, u, K)
else:
Expand Down Expand Up @@ -1061,7 +1061,7 @@ def _dmp_inner_gcd(f, g, u, K):
cfg = dmp_convert(cfg, u, exact, K)

return h, cff, cfg
elif K.has_Field:
elif K.is_Field:
if K.is_RationalField:
if query('USE_HEU_GCD'):
try:
Expand Down Expand Up @@ -1209,7 +1209,7 @@ def dmp_lcm(f, g, u, K):
>>> R.dmp_lcm(f, g)
x**3 + 2*x**2*y + x*y**2
"""
if K.has_Field:
if K.is_Field:
return dmp_ff_lcm(f, g, u, K)
else:
return dmp_rr_lcm(f, g, u, K)
Expand Down Expand Up @@ -1281,7 +1281,7 @@ def dmp_cancel(f, g, u, K, include=True):
"""
K0 = None

if K.has_Field and K.has_assoc_Ring:
if K.is_Field and K.has_assoc_Ring:
K0, K = K, K.ring

cq, f = dmp_clear_denoms(f, u, K0, K, convert=True)
Expand Down
4 changes: 2 additions & 2 deletions diofant/polys/factortools.py
Expand Up @@ -1066,7 +1066,7 @@ def dmp_factor_list(f, u, K0):
else:
K0_inexact = None

if K0.has_Field:
if K0.is_Field:
K = K0.ring

denom, f = dmp_clear_denoms(f, u, K0, K)
Expand All @@ -1092,7 +1092,7 @@ def dmp_factor_list(f, u, K0):
else: # pragma: no cover
raise DomainError('factorization not supported over %s' % K0)

if K0.has_Field:
if K0.is_Field:
for i, (f, k) in enumerate(factors):
factors[i] = (dmp_convert(f, u, K, K0), k)

Expand Down
4 changes: 2 additions & 2 deletions diofant/polys/fields.py
Expand Up @@ -110,7 +110,7 @@ def ground_new(self, element):
except CoercionFailed:
domain = self.domain

if not domain.has_Field and domain.has_assoc_Field:
if not domain.is_Field and domain.has_assoc_Field:
ring = self.ring
ground_field = domain.field
element = ground_field.convert(element)
Expand Down Expand Up @@ -160,7 +160,7 @@ def _rebuild(expr):
if c.is_Integer and c != 1:
return _rebuild(expr.base**a)**int(c)

if not domain.has_Field and domain.has_assoc_Field:
if not domain.is_Field and domain.has_assoc_Field:
return domain.field.convert(expr)
else:
return domain.convert(expr)
Expand Down
6 changes: 3 additions & 3 deletions diofant/polys/groebnertools.py
Expand Up @@ -32,7 +32,7 @@ def groebner(seq, ring, method=None):

domain, orig = ring.domain, None

if not domain.has_Field or not domain.has_assoc_Field:
if not domain.is_Field or not domain.has_assoc_Field:
orig, ring = ring, ring.clone(domain=domain.field)
seq = [s.set_ring(ring) for s in seq]

Expand Down Expand Up @@ -771,14 +771,14 @@ def groebner_gcd(f, g):
raise ValueError("Values should be equal")
domain = f.ring.domain

if not domain.has_Field:
if not domain.is_Field:
fc, f = f.primitive()
gc, g = g.primitive()
gcd = domain.gcd(fc, gc)

h = (f*g)//groebner_lcm(f, g)

if not domain.has_Field:
if not domain.is_Field:
return gcd*h
else:
return h.monic()
31 changes: 11 additions & 20 deletions diofant/polys/modulargcd.py
Expand Up @@ -504,10 +504,11 @@ def _modgcd_p(f, g, p, degbound, contbound):
ha = _modgcd_p(fa, ga, p, degbound, contbound)

if ha is None:
d += 1
if d > n:
if d < n:
d += 1
continue
else:
return
continue

if ha.is_ground:
h = conth.set_ring(ring).trunc_ground(p)
Expand Down Expand Up @@ -1076,10 +1077,11 @@ def _func_field_modgcd_p(f, g, minpoly, p):
ha = _func_field_modgcd_p(fa, ga, minpolya, p)

if ha is None:
d += 1
if d > n:
if d < n:
d += 1
continue
else:
return
continue

if ha == 1:
return ha
Expand Down Expand Up @@ -1198,15 +1200,11 @@ def integer_rational_reconstruction(c, m, domain):
return

if s1 < 0:
a, b = -r1, -s1
elif s1 > 0:
a, b = r1, s1
else:
return
r1, s1 = -r1, -s1

field = domain.field

return field(a) / field(b)
return field(r1) / field(s1)


def _rational_reconstruction_int_coeffs(hm, m, ring):
Expand Down Expand Up @@ -1351,6 +1349,7 @@ def _func_field_modgcd_m(f, g, minpoly):
gamma = f.drop_to_ground(-1).LC * g.drop_to_ground(-1).LC
# polynomial in Z[t_1, ..., t_k]
delta = minpoly.LC
assert k > 0 or delta == 1

p = 1
primes = []
Expand All @@ -1363,14 +1362,6 @@ def _func_field_modgcd_m(f, g, minpoly):
if gamma.trunc_ground(p) == 0:
continue

if k == 0:
test = (delta % p == 0)
else:
test = (delta.trunc_ground(p) == 0)

if test:
continue

fp = f.trunc_ground(p)
gp = g.trunc_ground(p)
minpolyp = minpoly.trunc_ground(p)
Expand Down
2 changes: 1 addition & 1 deletion diofant/polys/monomials.py
Expand Up @@ -254,7 +254,7 @@ def term_div(a, b, domain):

monom = monomial_div(a_lm, b_lm)

if domain.has_Field:
if domain.is_Field:
if monom is not None:
return monom, domain.quo(a_lc, b_lc)
else:
Expand Down
10 changes: 1 addition & 9 deletions diofant/polys/polyclasses.py
Expand Up @@ -28,7 +28,7 @@
dup_isolate_real_roots, dup_isolate_real_roots_sqf,
dup_refine_real_root, dup_sturm)
from .sqfreetools import (dmp_sqf_list, dmp_sqf_list_include, dmp_sqf_norm,
dmp_sqf_p, dmp_sqf_part, dup_gff_list)
dmp_sqf_p, dmp_sqf_part)


class DMP(CantSympify):
Expand Down Expand Up @@ -534,14 +534,6 @@ def sturm(self):
else:
raise ValueError('univariate polynomial expected')

def gff_list(self):
"""Computes greatest factorial factorization of ``self``. """
if not self.lev:
return [(self.per(g), k) for g, k in dup_gff_list(self.rep,
self.domain)]
else:
raise ValueError('univariate polynomial expected')

def sqf_norm(self):
"""Computes square-free norm of ``self``. """
s, g, r = dmp_sqf_norm(self.rep, self.lev, self.domain)
Expand Down
2 changes: 1 addition & 1 deletion diofant/polys/polyroots.py
Expand Up @@ -877,7 +877,7 @@ def _try_heuristics(f):

coeff, f = preprocess_roots(f)

if auto and f.domain.has_Ring:
if auto and f.domain.is_Ring:
f = f.to_field()

rescale_x = None
Expand Down