Modular Arithmetic

Doing arithmetic mod m is critical in number theory.

> 25*73 mod 99;

43

To make Maple think before it computes use the "neutral operator" &

> 66^1235346462356 mod 99;

Error, integer too large in context

> 66 &^1235346462356 mod 99;

0

Inverting mod n is simple. Of course it isn't always defined.

> 53^(-1) mod 99; 66^(-1) mod 99;

71

Error, the modular inverse does not exist

> msolve({3*x-4*y=1,7*x+y=2},19);

{y = 11, x = 15}

> msolve(x^2 = 5 , 17);

> msolve(x^2= 1, 8);

{x = 1}, {x = 3}, {x = 5}, {x = 7}

Now let's do some linear algebra mod m;.

> m := 19;

m := 19

> N := RandomMatrix(2,2,generator=0..m-1);

N := _rtable[22793028]

I'll define my own function to invert a matrix and to multiply to matrices.

> ModInv := (M , m)-> map( modp, M^(-1), m);

ModInv := proc (M, m) options operator, arrow; map(...

> Ninv := ModInv(N,m);

Ninv := _rtable[22802992]

> N^2 mod m;

Error, invalid argument for modp or mods

> ModMul := (M,N, m) -> map(modp, M.N, m);

ModMul := proc (M, N, m) options operator, arrow; m...

> ModMul(N,N,m);

_rtable[22871720]

> ModMul(N,Ninv,m);

_rtable[22993412]

> Determinant(N, method = modular[m]); 16*15 mod m;

3

12

Unfortunately, the Nullspace command, which is used over finite fields, seems to require matrices rather than Matrices.

> Nullspace(N) mod 19;

Error, (in mod/Nullspace) 1st argument must be a matrix over a finite field

> N1 := convert(N, matrix);type(N1,matrix);

N1 := matrix([[15, 15], [0, 4]])

true

> Nullspace(N1) mod 19;

{}

> N2 := linalg[submatrix](N1, 1..1,1..2);

N2 := matrix([[15, 15]])

> Nullspace(N2) mod 19;

{vector([18, 1])}

>