Skip to content

Commit

Permalink
polys: correct conversion of Diofant expressions to field elements
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Mar 9, 2018
1 parent ea73b11 commit d5af645
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
4 changes: 4 additions & 0 deletions diofant/domains/tests/test_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ def test_Domain__contains__():

assert (Rational(3, 2)*x/(y + 1) - z in QQ.poly_ring(x, y, z)) is False

# issue sympy/sympy#14433
assert (1/x in QQ.frac_field(1/x)) is True
assert (x in QQ.frac_field(1/x)) is True


def test_Domain_ring():
assert ZZ.has_assoc_Ring is True
Expand Down
24 changes: 12 additions & 12 deletions diofant/polys/fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Sparse rational function fields. """

from functools import reduce
from operator import add, ge, gt, le, lt, mul
import functools
import operator

from ..core import Expr, Symbol, sympify
from ..core.sympify import CantSympify
Expand Down Expand Up @@ -147,14 +147,14 @@ def _rebuild_expr(self, expr, mapping):
domain = self.domain

def _rebuild(expr):
generator = mapping.get(expr)

if generator is not None:
return generator
if expr in mapping:
return mapping[expr]
elif 1/expr in mapping:
return 1/mapping[1/expr]
elif expr.is_Add:
return reduce(add, list(map(_rebuild, expr.args)))
return functools.reduce(operator.add, map(_rebuild, expr.args))
elif expr.is_Mul:
return reduce(mul, list(map(_rebuild, expr.args)))
return functools.reduce(operator.mul, map(_rebuild, expr.args))
elif expr.is_Pow:
c, a = expr.exp.as_coeff_Mul(rational=True)
if c.is_Integer and c != 1:
Expand Down Expand Up @@ -328,16 +328,16 @@ def _cmp(self, other, op):
return NotImplemented

def __lt__(self, other):
return self._cmp(other, lt)
return self._cmp(other, operator.lt)

def __le__(self, other):
return self._cmp(other, le)
return self._cmp(other, operator.le)

def __gt__(self, other):
return self._cmp(other, gt)
return self._cmp(other, operator.gt)

def __ge__(self, other):
return self._cmp(other, ge)
return self._cmp(other, operator.ge)

def __pos__(self):
return self.raw_new(self.numer, self.denom)
Expand Down

0 comments on commit d5af645

Please sign in to comment.