Example of Nemo.jl (Matrices · Nemo.jl)
Code:
using Nemo
matrix(T, A) = MatrixSpace(T, size(A)...)(A)
pl(x...) = println(x...)
macro s(expr)
:(println($(string(expr)), " ="); show(stdout, "text/plain", $expr); println("\n"))
end
F, a = FiniteField(7, 2, "a")
P, x = F["x"]
X = matrix(F, (0:6)' .* a .+ (0:6))
A = F[a+1 a+2; a+3 3a+4]
v = F[5a+2; 3a+6]
@show F P; pl()
@show [F(3)^k for k in 1:6]; pl()
@show [a^k for k in 1:48]; pl()
@s X
@s rref(X)[2]
@show det(X) tr(X) rank(X) charpoly(P, X) minpoly(P, X); pl()
@s A
@s A'
@s A'A
@show det(A) tr(A) rank(A) charpoly(P, A) lu(A) inv(A); pl()
@show v A*v; pl()
Output:
F = Finite field of degree 2 over F_7
P = Univariate Polynomial Ring in x over Finite field of degree 2 over F_7
[F(3) ^ k for k = 1:6] = fq_nmod[3, 2, 6, 4, 5, 1]
[a ^ k for k = 1:48] = fq_nmod[a, a + 4, 5*a + 4, 2*a + 6, a + 1, 2*a + 4, 6*a + 1, 3, 3*a, 3*a + 5, a + 5, 6*a + 4, 3*a + 3, 6*a + 5, 4*a + 3, 2, 2*a, 2*a + 1, 3*a + 1, 4*a + 5, 2*a + 2, 4*a + 1, 5*a + 2, 6, 6*a, 6*a + 3, 2*a + 3, 5*a + 1, 6*a + 6, 5*a + 3, a + 6, 4, 4*a, 4*a + 2, 6*a + 2, a + 3, 4*a + 4, a + 2, 3*a + 4, 5, 5*a, 5*a + 6, 4*a + 6, 3*a + 2, 5*a + 5, 3*a + 6, 2*a + 5, 1]
X =
[0 a 2*a 3*a 4*a 5*a 6*a]
[1 a + 1 2*a + 1 3*a + 1 4*a + 1 5*a + 1 6*a + 1]
[2 a + 2 2*a + 2 3*a + 2 4*a + 2 5*a + 2 6*a + 2]
[3 a + 3 2*a + 3 3*a + 3 4*a + 3 5*a + 3 6*a + 3]
[4 a + 4 2*a + 4 3*a + 4 4*a + 4 5*a + 4 6*a + 4]
[5 a + 5 2*a + 5 3*a + 5 4*a + 5 5*a + 5 6*a + 5]
[6 a + 6 2*a + 6 3*a + 6 4*a + 6 5*a + 6 6*a + 6]
(rref(X))[2] =
[1 0 6 5 4 3 2]
[0 1 2 3 4 5 6]
[0 0 0 0 0 0 0]
[0 0 0 0 0 0 0]
[0 0 0 0 0 0 0]
[0 0 0 0 0 0 0]
[0 0 0 0 0 0 0]
det(X) = 0
tr(X) = 0
rank(X) = 2
charpoly(P, X) = x^7
minpoly(P, X) = x^2
A =
[a + 1 a + 2]
[a + 3 3*a + 4]
A' =
[a + 1 a + 3]
[a + 2 3*a + 4]
A' * A =
[3*a + 4 6*a + 2]
[6*a + 2 3*a + 4]
det(A) = 4*a + 6
tr(A) = 4*a + 5
rank(A) = 2
charpoly(P, A) = x^2 + (3*a + 2)*x + 4*a + 6
lu(A) = (2, (), [1 0; a+6 1], [a+1 a+2; 0 a+2])
inv(A) = [3*a+2 3*a+1; 2*a 3*a+5]
v = [5*a+2; 3*a+6]
A * v = [6*a+4; 5*a+2]