1

Is there a simple way to calculate (especially powers/exponetiation) with matrices whose elements are integers from finite field, or at least arbitrary integer precision matrices with support of % operator?

For example let's say we have a matrix

A = 1 1
    1 0

and want to compute something like (A**100) % 1000, how to achieve this?

I have tried numpy, but problem is that it uses fixed precision data types so it overflows quickly... Then I tried sympy since it supports arbitrary integer precision, but it does not seem to have support for finite fields operations (except for inverse)...

  • If you diagonalise the matrix, then you can exponentiate the diagonal values directly, and python's builtin `pow` function accepts a modulo optional parameter specifically for this use-case. That is, in python, `pow(x, p, m)` computes `(x ** p) % m` efficiently. – Stef Sep 16 '22 at 15:16
  • Nevermind, my previous comment only works if the eigenvalues are integers, which is rarely the case. (In the case of [[1 1] [1 0]], the eigen values are phi and 1-phi, where phi = golden ratio = (1+sqrt(5))/2) – Stef Sep 16 '22 at 16:06

1 Answers1

0

It might be an overkill, but Sage has everything you want (and much more). It is a python based software, but is very large (~1.2GB download). You can use sage --preparse script.sage to create a python file.

There is even SO-like QA site https://ask.sagemath.org/questions/ which is specialized to sage.

Example of your code might be:

m = Matrix(GF(5), [[1, 1], [1, 0]])
power = m^100

I have used GF(5) as GF(1000) is not a finite field. Also there are some differences, for instance the exponentiation can be done either by x**y or equivalently x^y.

kyticka
  • 604
  • 8
  • 19