5.55.15 Smith normal form: smith
The smith command takes one argument, a square matrix A with
elements in a field K.
smith returns matrices U, V, and
D, where U and V are invertible, D
is diagonal, and D = U*A*V.
Input:
M:=([[5,-2,3,6],[1,-3,1,3],[7,-6,-4,7],[-2,-4,-3,0]]) % 17
A := x*idn(4) -M
Output:
[[x-5 % 17,2 % 17,-3 % 17,-6 % 17],[-1 % 17,x+3 % 17,-1 % 17,-3 % 17],[-7 % 17,6 % 17,x+4 % 17,-7 % 17],[2 % 17,4 % 17,3 % 17,x]]
Input:
U, D, V := smith(A)
then:
U
Output:
[[0 % 17,-1 % 17,0 % 17,0 % 17],[0 % 17,0 % 17,6 % 17,4 % 17],[(-2*x+5) % 17,(-4*x-5) % 17,(-3*x-6) % 17,(x^2-3*x+6) % 17],[(2*x^2+5*x+6) % 17,(4*x^2+8*x+2) % 17,(3*x^2+4*x+1) % 17,(-x^3-2*x^2+2*x-6) % 17]]
Input:
V
Output:
[[1 % 17,(x+3) % 17,(-6*x^2-3*x-7) % 17,(6*x^5+2*x^4-2*x^3+x^2-8*x+6) % 17],[0 % 17,1 % 17,(-6*x-2) % 17,(6*x^4+x^3-6*x^2+5*x-6) % 17],[0 % 17,0 % 17,1 % 17,(-x^3+3*x^2+7) % 17],[0 % 17,0 % 17,0 % 17,1 % 17]]
Input:
D
Output:
[[1 % 17,0 % 17,0 % 17,0 % 17],[0 % 17,1 % 17,0 % 17,0 % 17],[0 % 17,0 % 17,1 % 17,0 % 17],[0 % 17,0 % 17,0 % 17,(-x^4-2*x^3+8*x^2-3*x+2) % 17]]
We can check this:
Input:
normal(U*A*V-D)
Output:
[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
Input:
B:=[[x^2+x-1,1,0,1],[-1,x,0,-1],[0,x^2+1,x,0],[1,0,1,x^2+x+1]] % 3
L:=smith(B)
Output:
[[0 % 3,-1 % 3,0 % 3,0 % 3],[1 % 3,0 % 3,0 % 3,(-x^2-x+1) % 3],[0 % 3,(x^2+1) % 3,(-x) % 3,(x^2+1) % 3],[-1 % 3,(-x^4-x^3+x+1) % 3,(x^3+x^2-x+1) % 3,(-x^4-x^3+x^2-x) % 3]],[[1 % 3,0 % 3,0 % 3,0 % 3],[0 % 3,1 % 3,0 % 3,0 % 3],[0 % 3,0 % 3,1 % 3,0 % 3],[0 % 3,0 % 3,0 % 3,(-x^6+x^5+x+1) % 3]],[[1 % 3,x % 3,(x^3+x^2-x) % 3,(-x^7+x^6+x^4+x^3+x^2+x-1) % 3],[0 % 3,1 % 3,(x^2+x-1) % 3,(-x^6+x^5+x^3+x^2+x+1) % 3],[0 % 3,0 % 3,1 % 3,(-x^4-x^3-x^2-x) % 3],[0 % 3,0 % 3,0 % 3,1 % 3]]