1
from sympy import *
x = sym.symbols('x')
result = solve([Eq(Mod(x, 23), 0), Eq(Mod(x, 41), 28), Eq(Mod(x, 829), 806), Eq(Mod(x, 13), 3), Eq(Mod(x, 17), 14), Eq(Mod(x, 29), 6), Eq(Mod(x, 677), 623), Eq(Mod(x, 37), 14), Eq(Mod(x, 19), 3)], x)

raises the error:

not a valid Sympy Expression

azro
  • 53,056
  • 7
  • 34
  • 70

1 Answers1

1

I get NotImplementedError when trying your example in sympy 1.7.1.

This kind of system of equations is not implemented in solve. I'm not sure what high-level solver function in sympy could handle this.

There is a low-level function crt for exactly this kind of system though: https://docs.sympy.org/latest/modules/ntheory.html#sympy.ntheory.modular.crt

You pass in a list of moduli and a list of remainders:

>>> from sympy.ntheory.modular import crt
>>> crt([23, 41, 829, 13, 17, 29, 677, 37, 19], [0, 28, 806, 3, 14, 6, 623, 14, 3])
(600689120448303, 2384517360007913)

I think that means that the solutions are of the form

    x = 600689120448303 + 2384517360007913 * n

for any integer n.

Oscar Benjamin
  • 12,649
  • 1
  • 12
  • 14