Skip to content

Commit 4204b2d

Browse files
committed
Try to add work-around for sympy/sympy#26645
1 parent dd3dc6e commit 4204b2d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

symengine/lib/symengine_wrapper.in.pyx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ try:
3131
except ImportError:
3232
have_numpy = False
3333

34+
try:
35+
import flint as _flint
36+
have_flint_py = True
37+
except ImportError:
38+
_flint = None
39+
have_flint_py = False
40+
3441

3542
class SympifyError(Exception):
3643
pass
@@ -499,6 +506,17 @@ def sympy2symengine(a, raise_error=False):
499506
elif isinstance(a, sympy.ConditionSet):
500507
return conditionset(*(a.args))
501508

509+
if have_flint_py:
510+
if isinstance(a, _flint.types.nmod.nmod):
511+
# Work around for sympy/sympy#26645
512+
class _modular_integer(sympy.polys.domains.modularinteger.ModularInteger):
513+
mod = int(a.modulus())
514+
dom = sympy.polys.domains.ZZ
515+
sym = True
516+
517+
b = _modular_integer(int(a))
518+
return PyNumber(b, sympy_module)
519+
502520
if raise_error:
503521
raise SympifyError(("sympy2symengine: Cannot convert '%r' (of type %s)"
504522
" to a symengine type.") % (a, type(a)))

symengine/tests/test_sympy_conv.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ def test_pynumber():
778778
assert isinstance(b, PyNumber)
779779
assert b == a # Check equality via SymEngine
780780
assert a == b # Check equality via SymPy
781+
assert (b-a).simplify() == 0
781782
assert str(a) == str(b)
782783

783784
a = 1 - a

0 commit comments

Comments
 (0)