Modular Arithmetic
Doing arithmetic mod m is critical in number theory.
> 25*73 mod 99;
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;
Inverting mod n is simple. Of course it isn't always defined.
> 53^(-1) mod 99; 66^(-1) mod 99;
Error, the modular inverse does not exist
> msolve({3*x-4*y=1,7*x+y=2},19);
> msolve(x^2 = 5 , 17);
> msolve(x^2= 1, 8);
Now let's do some linear algebra mod m;.
> m := 19;
> N := RandomMatrix(2,2,generator=0..m-1);
I'll define my own function to invert a matrix and to multiply to matrices.
> ModInv := (M , m)-> map( modp, M^(-1), m);
> Ninv := ModInv(N,m);
> N^2 mod m;
Error, invalid argument for modp or mods
> ModMul := (M,N, m) -> map(modp, M.N, m);
> ModMul(N,N,m);
> ModMul(N,Ninv,m);
> Determinant(N, method = modular[m]); 16*15 mod m;
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);
> Nullspace(N1) mod 19;
> N2 := linalg[submatrix](N1, 1..1,1..2);
> Nullspace(N2) mod 19;
>