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 #727

Merged
merged 12 commits into from
Dec 5, 2018
14 changes: 3 additions & 11 deletions diofant/domains/algebraicfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ..polys.densearith import (dmp_neg, dmp_pow, dmp_rem, dup_add, dup_mul,
dup_sub)
from ..polys.densebasic import dmp_LC, dmp_strip, dmp_to_dict, dmp_to_tuple
from ..polys.densetools import dmp_compose, dmp_eval
from ..polys.densetools import dmp_compose, dmp_eval_in
from ..polys.euclidtools import dup_invert
from ..polys.polyerrors import CoercionFailed, DomainError, NotAlgebraic
from ..printing.defaults import DefaultPrinting
Expand Down Expand Up @@ -250,14 +250,6 @@ def to_dict(self):
"""Convert ``self`` to a dict representation with native coefficients. """
return dmp_to_dict(self.rep, 0, self.domain)

def to_diofant_list(self):
"""Convert ``self`` to a list representation with Diofant coefficients. """
return [self.domain.to_expr(c) for c in self.rep]

@classmethod
def from_list(cls, rep):
return cls(dmp_strip(list(map(cls._parent.domain.convert, rep)), 0))

def LC(self):
"""Returns the leading coefficient of ``self``. """
return dmp_LC(self.rep, self.domain)
Expand Down Expand Up @@ -403,8 +395,8 @@ def _cmp(self, other, op):
inf=self.parent.ext_root[1].interval.a,
sup=self.parent.ext_root[1].interval.b):
self.parent.ext_root[1].refine()
v = dmp_eval(rep, diff.parent.ext_root[1].interval.center,
0, diff.domain)
v = dmp_eval_in(rep, diff.parent.ext_root[1].interval.center,
0, 0, diff.domain)
return bool(op(v, 0))

def __lt__(self, other):
Expand Down
8 changes: 0 additions & 8 deletions diofant/domains/field.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Implementation of :class:`Field` class. """

from ..polys.polyerrors import NotReversible
from .ring import Ring


Expand Down Expand Up @@ -81,10 +80,3 @@ def lcm(self, a, b):
q = ring.gcd(a.denominator, b.denominator)

return self.convert(p, ring)/q

def revert(self, a):
"""Returns ``a**(-1)`` if possible. """
if a:
return 1/a
else:
raise NotReversible('zero is not reversible')
10 changes: 1 addition & 9 deletions diofant/domains/ring.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Implementation of :class:`Ring` class. """

from ..polys.polyerrors import (ExactQuotientFailed, NotInvertible,
NotReversible)
from ..polys.polyerrors import ExactQuotientFailed, NotInvertible
from .domain import Domain


Expand Down Expand Up @@ -46,13 +45,6 @@ def invert(self, a, b):
else:
raise NotInvertible("zero divisor")

def revert(self, a):
"""Returns ``a**(-1)`` if possible. """
if a == self.one:
return a
else:
raise NotReversible('only unity is reversible in a ring')

def half_gcdex(self, a, b):
"""Half extended GCD of ``a`` and ``b``. """
s, t, h = self.gcdex(a, b)
Expand Down
2 changes: 1 addition & 1 deletion diofant/integrals/rationaltools.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _include_sign(c, sqf):
h = R_map[i]
h_lc = Poly(h.LC(), t, field=True)

c, h_lc_sqf = h_lc.sqf_list(all=True)
c, h_lc_sqf = h_lc.sqf_list()
_include_sign(c, h_lc_sqf)

for a, j in h_lc_sqf:
Expand Down
2 changes: 1 addition & 1 deletion diofant/integrals/risch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ def residue_reduce(a, d, DE, z=None, invert=True):
continue
h_lc = Poly(h.as_poly(DE.t).LC(), DE.t, field=True)

h_lc_sqf = h_lc.sqf_list_include(all=True)
h_lc_sqf = h_lc.sqf_list_include()

for a, j in h_lc_sqf:
h = Poly(h, DE.t, field=True).exquo(Poly(gcd(a, s**j, *kkinv),
Expand Down
31 changes: 12 additions & 19 deletions diofant/polys/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
dmp_sub_term, dup_add, dup_add_term, dup_lshift,
dup_mul, dup_mul_term, dup_pexquo, dup_rshift,
dup_sqr, dup_sub, dup_sub_term)
from .densebasic import dmp_degree, dmp_LC, dmp_strip, dmp_to_dict
from .densebasic import dmp_degree_in, dmp_LC, dmp_strip, dmp_to_dict
from .densetools import (dmp_clear_denoms, dmp_compose, dmp_diff,
dmp_diff_eval_in, dmp_diff_in, dmp_eval, dmp_eval_in,
dmp_diff_eval_in, dmp_diff_in, dmp_eval_in,
dmp_eval_tail, dmp_ground_content, dmp_ground_extract,
dmp_ground_monic, dmp_ground_primitive,
dmp_ground_trunc, dmp_integrate, dmp_integrate_in,
dmp_lift, dmp_trunc, dup_decompose, dup_diff,
dup_integrate, dup_mirror, dup_real_imag, dup_revert,
dup_scale, dup_shift, dup_sign_variations,
dup_transform, dup_trunc)
dup_integrate, dup_mirror, dup_real_imag, dup_scale,
dup_shift, dup_sign_variations, dup_transform,
dup_trunc)
from .euclidtools import (dmp_cancel, dmp_content, dmp_discriminant,
dmp_ff_lcm, dmp_ff_prs_gcd, dmp_gcd, dmp_inner_gcd,
dmp_inner_subresultants, dmp_lcm, dmp_primitive,
Expand Down Expand Up @@ -202,8 +202,8 @@ def dmp_LC(self, f):
else:
return LC

def dmp_degree(self, f):
return dmp_degree(self.to_dense(f), self.ngens-1)
def dmp_degree_in(self, f, j):
return dmp_degree_in(self.to_dense(f), j, self.ngens-1)

def dup_integrate(self, f, m):
return self.from_dense(dup_integrate(self.to_dense(f), m, self.domain))
Expand All @@ -223,10 +223,6 @@ def dmp_diff_in(self, f, m, j):
def dmp_integrate_in(self, f, m, j):
return self.from_dense(dmp_integrate_in(self.to_dense(f), m, j, self.ngens-1, self.domain))

def dmp_eval(self, f, a):
result = dmp_eval(self.to_dense(f), a, self.ngens-1, self.domain)
return self.drop(0).from_dense(result)

def dmp_eval_in(self, f, a, j):
result = dmp_eval_in(self.to_dense(f), a, j, self.ngens-1, self.domain)
return self.drop(j).from_dense(result)
Expand Down Expand Up @@ -299,9 +295,6 @@ def dmp_clear_denoms(self, f, convert=False):
ring = self
return c, ring.from_dense(F)

def dup_revert(self, f, n):
return self.from_dense(dup_revert(self.to_dense(f), n, self.domain))

def dup_half_gcdex(self, f, g):
s, h = dup_half_gcdex(self.to_dense(f), self.to_dense(g), self.domain)
return self.from_dense(s), self.from_dense(h)
Expand Down Expand Up @@ -539,13 +532,13 @@ def dmp_sqf_norm(self, f):
def dmp_sqf_part(self, f):
return self.from_dense(dmp_sqf_part(self.to_dense(f), self.ngens-1, self.domain))

def dmp_sqf_list(self, f, all=False):
coeff, factors = dmp_sqf_list(self.to_dense(f), self.ngens-1, self.domain, all=all)
def dmp_sqf_list(self, f):
coeff, factors = dmp_sqf_list(self.to_dense(f), self.ngens-1, self.domain)
return coeff, [(self.from_dense(g), k) for g, k in factors]

def dmp_sqf_list_include(self, f, all=False):
factors = dmp_sqf_list_include(self.to_dense(f), self.ngens-1, self.domain, all=all)
return [ (self.from_dense(g), k) for g, k in factors ]
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)
Expand Down
4 changes: 2 additions & 2 deletions diofant/polys/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def _construct_algebraic(coeffs, opt):

for i, (coeff, a, b) in enumerate(result):
if coeff is not None:
coeff = a*domain.dtype.from_list(H[exts.index(coeff)]) + b
coeff = a*domain.dtype(H[exts.index(coeff)]) + b
else:
coeff = domain.dtype.from_list([b])
coeff = domain.dtype([b])

result[i] = coeff

Expand Down
52 changes: 26 additions & 26 deletions diofant/polys/densearith.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Arithmetics for dense recursive polynomials in ``K[x]`` or ``K[X]``. """

from .densebasic import (dmp_degree, dmp_LC, dmp_one, dmp_one_p, dmp_slice,
from .densebasic import (dmp_degree_in, dmp_LC, dmp_one, dmp_one_p, dmp_slice,
dmp_strip, dmp_zero, dmp_zero_p, dmp_zeros)
from .polyerrors import ExactQuotientFailed, PolynomialDivisionFailed

Expand Down Expand Up @@ -330,8 +330,8 @@ def dup_add(f, g, K):
if not g:
return f

df = dmp_degree(f, 0)
dg = dmp_degree(g, 0)
df = dmp_degree_in(f, 0, 0)
dg = dmp_degree_in(g, 0, 0)

if df == dg:
return dmp_strip([a + b for a, b in zip(f, g)], 0)
Expand Down Expand Up @@ -361,12 +361,12 @@ def dmp_add(f, g, u, K):
if not u:
return dup_add(f, g, K)

df = dmp_degree(f, u)
df = dmp_degree_in(f, 0, u)

if df < 0:
return g

dg = dmp_degree(g, u)
dg = dmp_degree_in(g, 0, u)

if dg < 0:
return f
Expand Down Expand Up @@ -403,8 +403,8 @@ def dup_sub(f, g, K):
if not g:
return f

df = dmp_degree(f, 0)
dg = dmp_degree(g, 0)
df = dmp_degree_in(f, 0, 0)
dg = dmp_degree_in(g, 0, 0)

if df == dg:
return dmp_strip([a - b for a, b in zip(f, g)], 0)
Expand Down Expand Up @@ -434,12 +434,12 @@ def dmp_sub(f, g, u, K):
if not u:
return dup_sub(f, g, K)

df = dmp_degree(f, u)
df = dmp_degree_in(f, 0, u)

if df < 0:
return dmp_neg(g, u, K)

dg = dmp_degree(g, u)
dg = dmp_degree_in(g, 0, u)

if dg < 0:
return f
Expand Down Expand Up @@ -508,8 +508,8 @@ def dup_mul(f, g, K):
if not (f and g):
return []

df = dmp_degree(f, 0)
dg = dmp_degree(g, 0)
df = dmp_degree_in(f, 0, 0)
dg = dmp_degree_in(g, 0, 0)

n = max(df, dg) + 1

Expand Down Expand Up @@ -563,12 +563,12 @@ def dmp_mul(f, g, u, K):
if f == g:
return dmp_sqr(f, u, K)

df = dmp_degree(f, u)
df = dmp_degree_in(f, 0, u)

if df < 0:
return f

dg = dmp_degree(g, u)
dg = dmp_degree_in(g, 0, u)

if dg < 0:
return g
Expand Down Expand Up @@ -639,7 +639,7 @@ def dmp_sqr(f, u, K):
if not u:
return dup_sqr(f, K)

df = dmp_degree(f, u)
df = dmp_degree_in(f, 0, u)

if df < 0:
return f
Expand Down Expand Up @@ -742,8 +742,8 @@ def dmp_pdiv(f, g, u, K):
>>> R.dmp_pdiv(x**2 + x*y, 2*x + 2)
(2*x + 2*y - 2, -4*y + 4)
"""
df = dmp_degree(f, u)
dg = dmp_degree(g, u)
df = dmp_degree_in(f, 0, u)
dg = dmp_degree_in(g, 0, u)

if dg < 0:
raise ZeroDivisionError("polynomial division")
Expand All @@ -767,7 +767,7 @@ def dmp_pdiv(f, g, 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)
_dr, dr = dr, dmp_degree_in(r, 0, u)

if dr < dg:
break
Expand Down Expand Up @@ -796,8 +796,8 @@ def dmp_prem(f, g, u, K):
>>> R.dmp_prem(x**2 + x*y, 2*x + 2)
-4*y + 4
"""
df = dmp_degree(f, u)
dg = dmp_degree(g, u)
df = dmp_degree_in(f, 0, u)
dg = dmp_degree_in(g, 0, u)

if dg < 0:
raise ZeroDivisionError("polynomial division")
Expand All @@ -818,7 +818,7 @@ def dmp_prem(f, g, 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)
_dr, dr = dr, dmp_degree_in(r, 0, u)

if dr < dg:
break
Expand Down Expand Up @@ -895,8 +895,8 @@ def dmp_rr_div(f, g, u, K):
>>> R.dmp_rr_div(x**2 + x*y, 2*x + 2)
(0, x**2 + x*y)
"""
df = dmp_degree(f, u)
dg = dmp_degree(g, u)
df = dmp_degree_in(f, 0, u)
dg = dmp_degree_in(g, 0, u)

if dg < 0:
raise ZeroDivisionError("polynomial division")
Expand Down Expand Up @@ -926,7 +926,7 @@ def dmp_rr_div(f, g, u, K):
h = dmp_mul_term(g, c, j, u, K)
r = dmp_sub(r, h, u, K)

_dr, dr = dr, dmp_degree(r, u)
_dr, dr = dr, dmp_degree_in(r, 0, u)

if dr < dg:
break
Expand All @@ -947,8 +947,8 @@ def dmp_ff_div(f, g, u, K):
>>> R.dmp_ff_div(x**2 + x*y, 2*x + 2)
(1/2*x + 1/2*y - 1/2, -y + 1)
"""
df = dmp_degree(f, u)
dg = dmp_degree(g, u)
df = dmp_degree_in(f, 0, u)
dg = dmp_degree_in(g, 0, u)

if dg < 0:
raise ZeroDivisionError("polynomial division")
Expand Down Expand Up @@ -976,7 +976,7 @@ def dmp_ff_div(f, g, u, K):
h = dmp_mul_term(g, c, j, u, K)
r = dmp_sub(r, h, u, K)

_dr, dr = dr, dmp_degree(r, u)
_dr, dr = dr, dmp_degree_in(r, 0, u)

if dr < dg:
break
Expand Down
Loading