0

Does Sympy support modular groups?

I'm looking for something akin to pari/gp's Mod function.

Philippe
  • 1,715
  • 4
  • 25
  • 49

1 Answers1

0

Somewhat confusingly, the ring of integers modulo n is implemented as GF(n) (the notation suggesting finite fields, which these in general are not). So, 5 mod 12 would be represented by

>>> from sympy import GF
>>> x = GF(12)(5)
>>> print(x)
5 mod 12
>>> print(x*4)
8 mod 12
>>> print(-x)
7 mod 12
>>> print(x+10)
3 mod 12
>>> print(x**2)
1 mod 12
Philippe
  • 1,715
  • 4
  • 25
  • 49