From 3b0524587166ddfcfed3fd5031e2ea133aecf4f8 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Mon, 5 Mar 2018 13:59:53 +0300 Subject: [PATCH] polys: remove FracField, make FractionField domain Partial fix for sympy/sympy#14220 --- diofant/domains/__init__.py | 2 - diofant/domains/domain.py | 2 +- diofant/domains/fractionfield.py | 132 ----------------------- diofant/domains/polynomialring.py | 4 +- diofant/domains/tests/test_domains.py | 20 ++-- diofant/polys/__init__.py | 2 +- diofant/polys/fields.py | 124 ++++++++++++++++----- diofant/polys/modulargcd.py | 4 +- diofant/polys/numberfields.py | 3 +- diofant/polys/rings.py | 3 +- diofant/polys/tests/test_fields.py | 21 ++-- diofant/polys/tests/test_polytools.py | 4 +- diofant/polys/tests/test_rings.py | 4 +- diofant/printing/repr.py | 4 +- diofant/printing/str.py | 2 +- diofant/printing/tests/test_repr.py | 20 ++-- diofant/printing/tests/test_str.py | 2 +- diofant/utilities/tests/test_pickling.py | 10 +- docs/modules/domains.rst | 2 +- 19 files changed, 150 insertions(+), 215 deletions(-) delete mode 100644 diofant/domains/fractionfield.py diff --git a/diofant/domains/__init__.py b/diofant/domains/__init__.py index 420b685ed43..ebc14b58bb4 100644 --- a/diofant/domains/__init__.py +++ b/diofant/domains/__init__.py @@ -14,7 +14,6 @@ from . import gmpyrationalfield # noqa: F401 from . import algebraicfield # noqa: F401 from . import polynomialring # noqa: F401 -from . import fractionfield # noqa: F401 from . import expressiondomain # noqa: F401 from .domain import Domain # noqa: F401 @@ -31,7 +30,6 @@ from .gmpyrationalfield import GMPYRationalField from .algebraicfield import AlgebraicField # noqa: F401 from .polynomialring import PolynomialRing # noqa: F401 -from .fractionfield import FractionField # noqa: F401 from .expressiondomain import ExpressionDomain from .groundtypes import PythonRational # noqa: F401 diff --git a/diofant/domains/domain.py b/diofant/domains/domain.py index 7619add4c2d..abd6e896419 100644 --- a/diofant/domains/domain.py +++ b/diofant/domains/domain.py @@ -277,7 +277,7 @@ def poly_ring(self, *symbols, **kwargs): def frac_field(self, *symbols, **kwargs): """Returns a fraction field, i.e. `K(X)`. """ - from .fractionfield import FractionField + from ..polys.fields import FractionField return FractionField(self, symbols, kwargs.get("order", lex)) def is_one(self, a): diff --git a/diofant/domains/fractionfield.py b/diofant/domains/fractionfield.py deleted file mode 100644 index 16e66c7ec01..00000000000 --- a/diofant/domains/fractionfield.py +++ /dev/null @@ -1,132 +0,0 @@ -"""Implementation of :class:`FractionField` class. """ - -from ..polys.polyerrors import CoercionFailed, GeneratorsError -from .compositedomain import CompositeDomain -from .field import Field - - -__all__ = ('FractionField',) - - -class FractionField(Field, CompositeDomain): - """A class for representing multivariate rational function fields. """ - - is_FractionField = is_Frac = True - - has_assoc_Ring = True - has_assoc_Field = True - - def __init__(self, domain_or_field, symbols=None, order=None): - from ..polys.fields import FracField - - if isinstance(domain_or_field, FracField) and symbols is None and order is None: - field = domain_or_field - else: - field = FracField(symbols, domain_or_field, order) - - self.field = field - self.dtype = field.dtype - - self.gens = field.gens - self.ngens = field.ngens - self.symbols = field.symbols - self.domain = field.domain - - self.rep = str(self.domain) + '(' + ','.join(map(str, self.symbols)) + ')' - - def new(self, element): - return self.field.field_new(element) - - @property - def zero(self): - return self.field.zero - - @property - def one(self): - return self.field.one - - @property - def order(self): - return self.field.order - - def __hash__(self): - return hash((self.__class__.__name__, self.dtype, self.domain, self.symbols)) - - def __eq__(self, other): - """Returns `True` if two domains are equivalent. """ - return isinstance(other, FractionField) and \ - self.dtype == other.dtype and self.field == other.field - - def to_diofant(self, a): - """Convert `a` to a Diofant object. """ - return a.as_expr() - - def from_diofant(self, a): - """Convert Diofant's expression to `dtype`. """ - return self.field.from_expr(a) - - def from_ZZ_python(self, a, K0): - """Convert a Python `int` object to `dtype`. """ - return self(self.domain.convert(a, K0)) - - def from_QQ_python(self, a, K0): - """Convert a Python `Fraction` object to `dtype`. """ - return self(self.domain.convert(a, K0)) - - def from_ZZ_gmpy(self, a, K0): - """Convert a GMPY `mpz` object to `dtype`. """ - return self(self.domain.convert(a, K0)) - - def from_QQ_gmpy(self, a, K0): - """Convert a GMPY `mpq` object to `dtype`. """ - return self(self.domain.convert(a, K0)) - - def from_RealField(self, a, K0): - """Convert a mpmath `mpf` object to `dtype`. """ - return self(self.domain.convert(a, K0)) - - def from_PolynomialRing(self, a, K0): - """Convert a polynomial to ``dtype``. """ - try: - return self.new(a) - except (CoercionFailed, GeneratorsError): - return - - def from_FractionField(self, a, K0): - """Convert a rational function to ``dtype``. """ - try: - return a.set_field(self.field) - except (CoercionFailed, GeneratorsError): - return - - def get_ring(self): - """Returns a field associated with `self`. """ - return self.field.to_ring().to_domain() - - def is_positive(self, a): - """Returns True if `LC(a)` is positive. """ - return self.domain.is_positive(a.numer.LC) - - def is_negative(self, a): - """Returns True if `LC(a)` is negative. """ - return self.domain.is_negative(a.numer.LC) - - def is_nonpositive(self, a): - """Returns True if `LC(a)` is non-positive. """ - return self.domain.is_nonpositive(a.numer.LC) - - def is_nonnegative(self, a): - """Returns True if `LC(a)` is non-negative. """ - return self.domain.is_nonnegative(a.numer.LC) - - def numer(self, a): - """Returns numerator of ``a``. """ - return a.numer - - def denom(self, a): - """Returns denominator of ``a``. """ - return a.denom - - def factorial(self, a): - """Returns factorial of `a`. """ - return self.dtype(self.domain.factorial(a)) diff --git a/diofant/domains/polynomialring.py b/diofant/domains/polynomialring.py index 2444421558d..4075d88dfd2 100644 --- a/diofant/domains/polynomialring.py +++ b/diofant/domains/polynomialring.py @@ -102,11 +102,11 @@ def from_FractionField(self, a, K0): denom = K0.denom(a) if denom.is_ground: - return self.from_PolynomialRing(K0.numer(a)/denom, K0.field.ring.to_domain()) + return self.from_PolynomialRing(K0.numer(a)/denom, K0.ring.to_domain()) def get_field(self): """Returns a field associated with `self`. """ - return self.ring.to_field().to_domain() + return self.ring.to_field() def is_positive(self, a): """Returns True if `LC(a)` is positive. """ diff --git a/diofant/domains/tests/test_domains.py b/diofant/domains/tests/test_domains.py index 02e6eb3c7e0..4c50cd3808a 100644 --- a/diofant/domains/tests/test_domains.py +++ b/diofant/domains/tests/test_domains.py @@ -685,9 +685,9 @@ def test_PolynomialRing_from_FractionField(): g = (x**2 + y**2)/4 h = x**2 + y**2 - assert R.to_domain().from_FractionField(f, F.to_domain()) is None - assert R.to_domain().from_FractionField(g, F.to_domain()) == X**2/4 + Y**2/4 - assert R.to_domain().from_FractionField(h, F.to_domain()) == X**2 + Y**2 + assert R.to_domain().from_FractionField(f, F) is None + assert R.to_domain().from_FractionField(g, F) == X**2/4 + Y**2/4 + assert R.to_domain().from_FractionField(h, F) == X**2 + Y**2 F, x, y = field("x,y", QQ) R, X, Y = ring("x,y", QQ) @@ -696,9 +696,9 @@ def test_PolynomialRing_from_FractionField(): g = (x**2 + y**2)/4 h = x**2 + y**2 - assert R.to_domain().from_FractionField(f, F.to_domain()) is None - assert R.to_domain().from_FractionField(g, F.to_domain()) == X**2/4 + Y**2/4 - assert R.to_domain().from_FractionField(h, F.to_domain()) == X**2 + Y**2 + assert R.to_domain().from_FractionField(f, F) is None + assert R.to_domain().from_FractionField(g, F) == X**2/4 + Y**2/4 + assert R.to_domain().from_FractionField(h, F) == X**2 + Y**2 def test_FractionField_from_PolynomialRing(): @@ -708,17 +708,17 @@ def test_FractionField_from_PolynomialRing(): f = 3*x**2 + 5*y**2 g = x**2/3 + y**2/5 - assert F.to_domain().from_PolynomialRing(f, R.to_domain()) == 3*X**2 + 5*Y**2 - assert F.to_domain().from_PolynomialRing(g, R.to_domain()) == (5*X**2 + 3*Y**2)/15 + assert F.from_PolynomialRing(f, R.to_domain()) == 3*X**2 + 5*Y**2 + assert F.from_PolynomialRing(g, R.to_domain()) == (5*X**2 + 3*Y**2)/15 RALG, u, v = ring("u,v", ALG) pytest.raises(CoercionFailed, - lambda: F.to_domain().convert(3*u**2 + 5*sqrt(2)*v**2)) + lambda: F.convert(3*u**2 + 5*sqrt(2)*v**2)) def test_FractionField_convert(): F, X, Y = field("x,y", QQ) - F.to_domain().convert(QQ_python()(1, 3)) == F.one/3 + F.convert(QQ_python()(1, 3)) == F.one/3 def test_FF_of_type(): diff --git a/diofant/polys/__init__.py b/diofant/polys/__init__.py index a88f60f2fc2..041da744959 100644 --- a/diofant/polys/__init__.py +++ b/diofant/polys/__init__.py @@ -42,4 +42,4 @@ from .partfrac import apart, apart_list, assemble_partfrac_list # noqa: F401 from .polyoptions import Options # noqa: F401 from .rings import ring, sring, vring # noqa: F401,F403 -from .fields import field, sfield, vfield # noqa: F401 +from .fields import FractionField, field, vfield # noqa: F401 diff --git a/diofant/polys/fields.py b/diofant/polys/fields.py index 6eb90b6d845..b7dbf20acb5 100644 --- a/diofant/polys/fields.py +++ b/diofant/polys/fields.py @@ -5,44 +5,45 @@ from ..core import Expr, Symbol, sympify from ..core.sympify import CantSympify +from ..domains.compositedomain import CompositeDomain from ..domains.domainelement import DomainElement -from ..domains.fractionfield import FractionField +from ..domains.field import Field from ..domains.polynomialring import PolynomialRing from ..printing.defaults import DefaultPrinting from ..utilities.magic import pollute from .orderings import lex -from .polyerrors import CoercionFailed +from .polyerrors import CoercionFailed, GeneratorsError from .rings import PolyElement -__all__ = ('field', 'sfield', 'vfield') +__all__ = ('field', 'vfield') def field(symbols, domain, order=lex): """Construct new rational function field returning (field, x1, ..., xn). """ - _field = FracField(symbols, domain, order) + _field = FractionField(domain, symbols, order) return (_field,) + _field.gens def vfield(symbols, domain, order=lex): """Construct new rational function field and inject generators into global namespace. """ - _field = FracField(symbols, domain, order) - pollute([ sym.name for sym in _field.symbols ], _field.gens) + _field = FractionField(domain, symbols, order) + pollute([sym.name for sym in _field.symbols], _field.gens) return _field -def sfield(exprs, *symbols, **options): - """Construct a field deriving generators and domain from options and input expressions. """ - raise NotImplementedError # pragma: no cover - - _field_cache = {} -class FracField(DefaultPrinting): +class FractionField(Field, CompositeDomain): """Multivariate distributed rational function field. """ - def __new__(cls, symbols, domain, order=lex): + is_FractionField = is_Frac = True + + has_assoc_Ring = True + has_assoc_Field = True + + def __new__(cls, domain, symbols, order=lex): from .rings import PolyRing ring = PolyRing(symbols, domain, order) symbols = ring.symbols @@ -68,6 +69,8 @@ def __new__(cls, symbols, domain, order=lex): obj.gens = obj._gens() + obj.rep = str(domain) + '(' + ','.join(map(str, symbols)) + ')' + for symbol, generator in zip(obj.symbols, obj.gens): if isinstance(symbol, Symbol): name = symbol.name @@ -180,13 +183,84 @@ def from_expr(self, expr): else: return self.field_new(frac) - def to_domain(self): - return FractionField(self) - def to_ring(self): from .rings import PolyRing return PolyRing(self.symbols, self.domain, self.order) + def to_diofant(self, a): + """Convert `a` to a Diofant object. """ + return a.as_expr() + + def from_diofant(self, a): + """Convert Diofant's expression to `dtype`. """ + return self.from_expr(a) + + def from_ZZ_python(self, a, K0): + """Convert a Python `int` object to `dtype`. """ + return self(self.domain.convert(a, K0)) + + def from_QQ_python(self, a, K0): + """Convert a Python `Fraction` object to `dtype`. """ + return self(self.domain.convert(a, K0)) + + def from_ZZ_gmpy(self, a, K0): + """Convert a GMPY `mpz` object to `dtype`. """ + return self(self.domain.convert(a, K0)) + + def from_QQ_gmpy(self, a, K0): + """Convert a GMPY `mpq` object to `dtype`. """ + return self(self.domain.convert(a, K0)) + + def from_RealField(self, a, K0): + """Convert a mpmath `mpf` object to `dtype`. """ + return self(self.domain.convert(a, K0)) + + def from_PolynomialRing(self, a, K0): + """Convert a polynomial to ``dtype``. """ + try: + return self.field_new(a) + except (CoercionFailed, GeneratorsError): + return + + def from_FractionField(self, a, K0): + """Convert a rational function to ``dtype``. """ + try: + return a.set_field(self) + except (CoercionFailed, GeneratorsError): + return + + def get_ring(self): + """Returns a field associated with `self`. """ + return self.to_ring().to_domain() + + def is_positive(self, a): + """Returns True if `LC(a)` is positive. """ + return self.domain.is_positive(a.numer.LC) + + def is_negative(self, a): + """Returns True if `LC(a)` is negative. """ + return self.domain.is_negative(a.numer.LC) + + def is_nonpositive(self, a): + """Returns True if `LC(a)` is non-positive. """ + return self.domain.is_nonpositive(a.numer.LC) + + def is_nonnegative(self, a): + """Returns True if `LC(a)` is non-negative. """ + return self.domain.is_nonnegative(a.numer.LC) + + def numer(self, a): + """Returns numerator of ``a``. """ + return a.numer + + def denom(self, a): + """Returns denominator of ``a``. """ + return a.denom + + def factorial(self, a): + """Returns factorial of `a`. """ + return self.dtype(self.domain.factorial(a)) + class FracElement(DomainElement, DefaultPrinting, CantSympify): """Element of multivariate distributed rational function field. """ @@ -213,7 +287,7 @@ def to_poly(self): @property def parent(self): - return self.field.to_domain() + return self.field _hash = None @@ -310,9 +384,9 @@ def __add__(self, other): return self.new(self.numer + self.denom*other, self.denom) else: if isinstance(other, FracElement): - if isinstance(field.domain, FractionField) and field.domain.field == other.field: + if isinstance(field, FractionField) and field.domain == other.field: pass - elif isinstance(other.field.domain, FractionField) and other.field.domain.field == field: + elif isinstance(other.field.domain, FractionField) and other.field.domain == field: return other.__radd__(self) else: # pragma: no cover return NotImplemented @@ -356,9 +430,9 @@ def __sub__(self, other): return self.new(self.numer - self.denom*other, self.denom) else: if isinstance(other, FracElement): - if isinstance(field.domain, FractionField) and field.domain.field == other.field: + if isinstance(field.domain, FractionField) and field.domain == other.field: pass - elif isinstance(other.field.domain, FractionField) and other.field.domain.field == field: + elif isinstance(other.field.domain, FractionField) and other.field.domain == field: return other.__rsub__(self) else: # pragma: no cover return NotImplemented @@ -404,9 +478,9 @@ def __mul__(self, other): return self.new(self.numer*other, self.denom) else: if isinstance(other, FracElement): - if isinstance(field.domain, FractionField) and field.domain.field == other.field: + if isinstance(field.domain, FractionField) and field.domain == other.field: pass - elif isinstance(other.field.domain, FractionField) and other.field.domain.field == field: + elif isinstance(other.field.domain, FractionField) and other.field.domain == field: return other.__rmul__(self) else: # pragma: no cover return NotImplemented @@ -443,9 +517,9 @@ def __truediv__(self, other): return self.new(self.numer, self.denom*other) else: if isinstance(other, FracElement): - if isinstance(field.domain, FractionField) and field.domain.field == other.field: + if isinstance(field.domain, FractionField) and field.domain == other.field: pass - elif isinstance(other.field.domain, FractionField) and other.field.domain.field == field: + elif isinstance(other.field.domain, FractionField) and other.field.domain == field: return other.__rtruediv__(self) else: # pragma: no cover return NotImplemented diff --git a/diofant/polys/modulargcd.py b/diofant/polys/modulargcd.py index ad64622770e..5d7e72cd850 100644 --- a/diofant/polys/modulargcd.py +++ b/diofant/polys/modulargcd.py @@ -1647,7 +1647,7 @@ def _func_field_modgcd_p(f, g, minpoly, p): continue if k == 1: - dom = qring.domain.field + dom = qring.domain den = dom.ring.one for coeff in h.itercoeffs(): @@ -1655,7 +1655,7 @@ def _func_field_modgcd_p(f, g, minpoly, p): p, dom.domain)) else: - dom = qring.domain.domain.field + dom = qring.domain.domain den = dom.ring.one for coeff in h.itercoeffs(): diff --git a/diofant/polys/numberfields.py b/diofant/polys/numberfields.py index 43db5063cb0..7c3e00aaa73 100644 --- a/diofant/polys/numberfields.py +++ b/diofant/polys/numberfields.py @@ -560,7 +560,6 @@ def minimal_polynomial(ex, x=None, **args): """ from .polytools import degree - from ..domains import FractionField from ..core import preorder_traversal compose = args.get('compose', True) @@ -580,7 +579,7 @@ def minimal_polynomial(ex, x=None, **args): x, cls = Dummy('x'), PurePoly if not dom: - dom = FractionField(QQ, list(ex.free_symbols)) if ex.free_symbols else QQ + dom = QQ.frac_field(*ex.free_symbols) if ex.free_symbols else QQ if hasattr(dom, 'symbols') and x in dom.symbols: raise GeneratorsError("the variable %s is an element of the ground domain %s" % (x, dom)) diff --git a/diofant/polys/rings.py b/diofant/polys/rings.py index 09b93697a18..610071462a6 100644 --- a/diofant/polys/rings.py +++ b/diofant/polys/rings.py @@ -369,8 +369,7 @@ def to_domain(self): return PolynomialRing(self) def to_field(self): - from .fields import FracField - return FracField(self.symbols, self.domain, self.order) + return self.domain.frac_field(*self.symbols, order=self.order) @property def is_univariate(self): diff --git a/diofant/polys/tests/test_fields.py b/diofant/polys/tests/test_fields.py index 9527598af46..69bc16a8bf4 100644 --- a/diofant/polys/tests/test_fields.py +++ b/diofant/polys/tests/test_fields.py @@ -5,18 +5,17 @@ from diofant import I, Rational, sqrt from diofant.core import symbols from diofant.domains import QQ, ZZ -from diofant.polys.fields import FracElement, FracField, field -from diofant.polys.orderings import lex +from diofant.polys.fields import FracElement, field from diofant.polys.rings import ring __all__ = () -def test_FracField___init__(): - F1 = FracField("x,y", ZZ, lex) - F2 = FracField("x,y", ZZ, lex) - F3 = FracField("x,y,z", ZZ, lex) +def test_FractionField___init__(): + F1, *_ = field("x y", ZZ) + F2, *_ = field("x y", ZZ) + F3, *_ = field("x y z", ZZ) assert F1.x == F1.gens[0] assert F1.y == F1.gens[1] @@ -25,16 +24,16 @@ def test_FracField___init__(): assert F1.x != F3.x assert F1.y != F3.y - F4 = FracField("gens", ZZ) + F4, *_ = field("gens", ZZ) assert type(F4.gens) is tuple -def test_FracField___hash__(): +def test_FractionField___hash__(): F, x, y, z = field("x,y,z", QQ) assert hash(F) -def test_FracField___eq__(): +def test_FractionField___eq__(): assert field("x,y,z", QQ)[0] == field("x,y,z", QQ)[0] assert field("x,y,z", QQ)[0] is field("x,y,z", QQ)[0] @@ -51,8 +50,8 @@ def test_FracField___eq__(): assert field("x,y", QQ)[0] is not field("x,y,z", QQ)[0] -def test_FracField_methods(): - F = FracField("x", ZZ) +def test_FractionField_methods(): + F, *_ = field("x", ZZ) assert F.domain_new(2) == ZZ(2) diff --git a/diofant/polys/tests/test_polytools.py b/diofant/polys/tests/test_polytools.py index 9ace78e0813..a7b06efdbfc 100644 --- a/diofant/polys/tests/test_polytools.py +++ b/diofant/polys/tests/test_polytools.py @@ -440,10 +440,10 @@ def test_Poly__unify(): F, A, B = field("a,b", ZZ) assert Poly(a*x, x, domain='ZZ[a]')._unify(Poly(a*b*x, x, domain='ZZ(a,b)'))[2:] == \ - (DMP([A, F(0)], F.to_domain()), DMP([A*B, F(0)], F.to_domain())) + (DMP([A, F(0)], F), DMP([A*B, F(0)], F)) assert Poly(a*x, x, domain='ZZ(a)')._unify(Poly(a*b*x, x, domain='ZZ(a,b)'))[2:] == \ - (DMP([A, F(0)], F.to_domain()), DMP([A*B, F(0)], F.to_domain())) + (DMP([A, F(0)], F), DMP([A*B, F(0)], F)) pytest.raises(CoercionFailed, lambda: Poly(Poly(x**2 + x**2*z, y, field=True), domain='ZZ(x)')) diff --git a/diofant/polys/tests/test_rings.py b/diofant/polys/tests/test_rings.py index 3b9c06e2120..ab96182941c 100644 --- a/diofant/polys/tests/test_rings.py +++ b/diofant/polys/tests/test_rings.py @@ -8,7 +8,7 @@ from diofant import oo, pi, sqrt from diofant.core import Symbol, symbols from diofant.domains import EX, FF, QQ, RR, ZZ -from diofant.polys.fields import FracField, field +from diofant.polys.fields import field from diofant.polys.orderings import grlex, lex from diofant.polys.polyerrors import (CoercionFailed, ExactQuotientFailed, GeneratorsError, GeneratorsNeeded, @@ -190,7 +190,7 @@ def test_sring(): R = PolyRing("x,y,z", Rt, lex) assert sring(x + t*y/2 + t**2*z/3, x, y, z) == (R, R.x + Rt.t*R.y/2 + Rt.t**2*R.z/3) - Rt = FracField("t", ZZ, lex) + Rt, *_ = field("t", ZZ) R = PolyRing("x,y,z", Rt, lex) assert sring(x + 2*y/t + t**2*z/3, x, y, z) == (R, R.x + 2*R.y/Rt.t + Rt.t**2*R.z/3) diff --git a/diofant/printing/repr.py b/diofant/printing/repr.py index 0941a26925e..5c3bf4aae49 100644 --- a/diofant/printing/repr.py +++ b/diofant/printing/repr.py @@ -162,9 +162,9 @@ def _print_GMPYIntegerRing(self, expr): def _print_PolynomialRing(self, expr): return "%s(%s)" % (expr.__class__.__name__, repr(expr.ring)) - def _print_FracField(self, field): + def _print_FractionField(self, field): return "%s(%s, %s, %s)" % (field.__class__.__name__, - self._print(field.symbols), self._print(field.domain), self._print(field.order)) + self._print(field.domain), self._print(field.symbols), self._print(field.order)) def _print_PolyElement(self, poly): terms = list(poly.terms()) diff --git a/diofant/printing/str.py b/diofant/printing/str.py index f8a2634bd33..f9dad3e53f1 100644 --- a/diofant/printing/str.py +++ b/diofant/printing/str.py @@ -360,7 +360,7 @@ def _print_PolyRing(self, ring): return "Polynomial ring in %s over %s with %s order" % \ (", ".join(map(self._print, ring.symbols)), ring.domain, ring.order) - def _print_FracField(self, field): + def _print_FractionField(self, field): return "Rational function field in %s over %s with %s order" % \ (", ".join(map(self._print, field.symbols)), field.domain, field.order) diff --git a/diofant/printing/tests/test_repr.py b/diofant/printing/tests/test_repr.py index 47db7193162..750e5221e31 100644 --- a/diofant/printing/tests/test_repr.py +++ b/diofant/printing/tests/test_repr.py @@ -18,7 +18,6 @@ # environment is the scope of "from diofant import *" for most cases. ENV = {} imports = ["from diofant import *", - "from diofant.polys.fields import FracField", "from diofant.polys.orderings import GradedLexOrder, LexOrder", "from diofant.polys.rings import PolyRing"] exec("\n".join(imports), ENV) @@ -196,15 +195,14 @@ def test_PolyRing(): "%s, LexOrder())), LexOrder())" % repr(ZZ)) -def test_FracField(): - sT(field("x", ZZ, lex)[0], "FracField((Symbol('x'),), " - "%s, LexOrder())" % repr(ZZ)) - sT(field("x,y", QQ, grlex)[0], "FracField((Symbol('x'), Symbol('y')), " - "%s, GradedLexOrder())" % repr(QQ)) +def test_FractionField(): + sT(field("x", ZZ, lex)[0], "FractionField(%s, (Symbol('x'),), " + "LexOrder())" % repr(ZZ)) + sT(field("x,y", QQ, grlex)[0], "FractionField(%s, (Symbol('x'), Symbol('y')), " + "GradedLexOrder())" % repr(QQ)) sT(field("x,y,z", ZZ["t"], lex)[0], - "FracField((Symbol('x'), Symbol('y'), Symbol('z')), " - "PolynomialRing(PolyRing((Symbol('t'),), %s, " - "LexOrder())), LexOrder())" % repr(ZZ)) + "FractionField(PolynomialRing(PolyRing((Symbol('t'),), %s, LexOrder())), " + "(Symbol('x'), Symbol('y'), Symbol('z')), LexOrder())" % repr(ZZ)) def test_PolyElement(): @@ -220,8 +218,8 @@ def test_PolyElement(): def test_FracElement(): F, x, y = field("x,y", ZZ) g = F.domain.dtype - assert repr((3*x**2*y + 1)/(x - y**2)) == ("FracElement(FracField((Symbol('x'), " - "Symbol('y')), %s, LexOrder()), [((2, 1), %s), " + assert repr((3*x**2*y + 1)/(x - y**2)) == ("FracElement(FractionField(%s, (Symbol('x'), " + "Symbol('y')), LexOrder()), [((2, 1), %s), " "((0, 0), %s)], [((1, 0), %s), " "((0, 2), %s)])" % (repr(ZZ), repr(g(3)), diff --git a/diofant/printing/tests/test_str.py b/diofant/printing/tests/test_str.py index ba69db27ef8..28d27325d7c 100644 --- a/diofant/printing/tests/test_str.py +++ b/diofant/printing/tests/test_str.py @@ -361,7 +361,7 @@ def test_PolyRing(): assert str(ring("x,y,z", ZZ["t"], lex)[0]) == "Polynomial ring in x, y, z over ZZ[t] with lex order" -def test_FracField(): +def test_FractionField(): assert str(field("x", ZZ, lex)[0]) == "Rational function field in x over ZZ with lex order" assert str(field("x,y", QQ, grlex)[0]) == "Rational function field in x, y over QQ with grlex order" assert str(field("x,y,z", ZZ["t"], lex)[0]) == "Rational function field in x, y, z over ZZ[t] with lex order" diff --git a/diofant/utilities/tests/test_pickling.py b/diofant/utilities/tests/test_pickling.py index 5f177a434b5..49e4021c20c 100644 --- a/diofant/utilities/tests/test_pickling.py +++ b/diofant/utilities/tests/test_pickling.py @@ -4,7 +4,7 @@ import pytest -from diofant import QQ, ZZ, lex +from diofant import QQ, ZZ from diofant.abc import x, y, z from diofant.concrete.products import Product from diofant.concrete.summations import Sum @@ -51,7 +51,7 @@ from diofant.matrices import Matrix, SparseMatrix from diofant.ntheory.generate import Sieve from diofant.plotting.plot import Plot -from diofant.polys.fields import FracField +from diofant.polys.fields import FractionField from diofant.polys.monomials import Monomial from diofant.polys.numberfields import AlgebraicNumber from diofant.polys.orderings import (GradedLexOrder, InverseOrder, LexOrder, @@ -287,7 +287,7 @@ def test_pickling_polys_polytools(): check(c) # TODO: fix pickling of Options class (see GroebnerBasis._options) - # for c in (GroebnerBasis, GroebnerBasis([x**2 - 1], x, order=lex)): + # for c in (GroebnerBasis, GroebnerBasis([x**2 - 1], x)): # check(c) @@ -303,7 +303,7 @@ def test_pickling_polys_rings(): # NOTE: can't use protocols < 2 because we have to execute __new__ to # make sure caching of rings works properly. - ring = PolyRing("x,y,z", ZZ, lex) + ring = PolyRing("x,y,z", ZZ) for c in (PolyRing, ring): check(c, exclude=[0, 1]) @@ -317,7 +317,7 @@ def test_pickling_polys_fields(): # NOTE: can't use protocols < 2 because we have to execute __new__ to # make sure caching of fields works properly. - field = FracField("x,y,z", ZZ, lex) + field = FractionField("x,y,z", ZZ) for c in (FracField, field): check(c, exclude=[0, 1]) diff --git a/docs/modules/domains.rst b/docs/modules/domains.rst index 9be81f84cb4..231df3c6b32 100644 --- a/docs/modules/domains.rst +++ b/docs/modules/domains.rst @@ -53,7 +53,7 @@ Concrete Domains .. autoclass:: diofant.domains.AlgebraicField :members: -.. autoclass:: FractionField +.. autoclass:: diofant.polys.fields.FractionField :members: .. autoclass:: RealField