Skip to content

Commit

Permalink
Remove eigenvalues and eigenspaces (now in Nemo)
Browse files Browse the repository at this point in the history
  • Loading branch information
joschmitt authored and lgoettgens committed Jan 24, 2024
1 parent 5d76f55 commit 6c72843
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 115 deletions.
75 changes: 0 additions & 75 deletions src/Misc/jordan.jl
Original file line number Diff line number Diff line change
@@ -1,78 +1,3 @@
@doc raw"""
spectrum(M::MatElem{T}) where T <: FieldElem -> Dict{T, Int}
Returns the spectrum of a matrix, i.e. the set of eigenvalues of $M$ with multiplicities.
"""
function spectrum(M::MatElem{T}) where T <: FieldElem
@assert is_square(M)
K = base_ring(M)
f = charpoly(M)
fac = factor(f) #Should use roots! But needs to take into account
#multiplicities
D = Dict{elem_type(K), Int}()
for (g, v) in fac
if degree(g) > 1
continue
end
lambda = -divexact(coeff(g, 0), leading_coefficient(g))
D[lambda] = v
end
return D
end

@doc raw"""
spectrum(M::MatElem{T}, L) where T <: FieldElem -> Dict{T, Int}
Returns the spectrum of a matrix over the field $L$, i.e. the set of eigenvalues of $M$ with multiplicities.
"""
function spectrum(M::MatElem{T}, L) where T <: FieldElem
@assert is_square(M)
M1 = change_base_ring(L, M)
return spectrum(M1)
end

eigvals(M::MatElem{T}) where T <: FieldElem = spectrum(M)
eigvals(M::MatElem{T}, L) where T <: FieldElem = spectrum(M, L)

@doc raw"""
eigenspace(M::MatElem{T}, lambda::T; side::Symbol = :right)
where T <: FieldElem -> Vector{MatElem{T}}
Return a basis of the eigenspace of $M$ with respect to the eigenvalue $\lambda$.
If side is `:right`, the right eigenspace is computed, i.e. vectors $v$ such that
$Mv = \lambda v$. If side is `:left`, the left eigenspace is computed, i.e. vectors
$v$ such that $vM = \lambda v$.
"""
function eigenspace(M::MatElem{T}, lambda::T; side::Symbol = :right) where T <: FieldElem
@assert is_square(M)
N = deepcopy(M)
for i = 1:ncols(N)
N[i, i] -= lambda
end
return kernel(N, side = side)[2]
end

@doc raw"""
eigenspace(M::MatElem{T}; side::Symbol = :right)
where T <: FieldElem -> Dict{T, MatElem{T}}
Return a dictionary containing the eigenvalues of $M$ as keys and bases for the
corresponding eigenspaces as values.
If side is `:right`, the right eigenspaces are computed, if it is `:left` then the
left eigenspaces are computed.
See also `eigenspace`.
"""
function eigenspaces(M::MatElem{T}; side::Symbol = :right) where T<:Hecke.FieldElem

S = spectrum(M)
L = Dict{elem_type(base_ring(M)), typeof(M)}()
for k in keys(S)
push!(L, k => Hecke.vcat(Hecke.eigenspace(M, k, side = side)))
end
return L
end

function closure_with_pol(v::MatElem{T}, M::MatElem{T}) where T <: FieldElem
i = 1
E = rref(v)[2]
Expand Down
3 changes: 0 additions & 3 deletions src/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,6 @@ export dual_isogeny
export dual_of_frobenius
export echelon_with_transform
export ei
export eigenspace
export eigenspaces
export eisenstein_extension
export elem_in_algebra
export elem_in_nf
Expand Down Expand Up @@ -881,7 +879,6 @@ export sparse_trafo_partial_dense
export sparse_trafo_scale
export sparse_trafo_swap
export sparsity
export spectrum
export splitting_field
export sqrt
export stabilizer
Expand Down
38 changes: 1 addition & 37 deletions test/Misc/jordan_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,44 +59,8 @@
@test Set([ J[1, 1], J[2, 2], J[3, 3] ]) == Set([ K(), K(1), K(-1) ])
end

@testset "Spectrum and eigenspaces" begin
M = matrix(FlintQQ, 4, 4, [ 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 ])
l = eigvals(M)
@test length(keys(l)) == 1
@test haskey(l, one(FlintQQ))
@test l[one(FlintQQ)] == 2

@testset "Common eigenspaces" begin
K, a = cyclotomic_field(3, "a")
lK = eigvals(M, K)
@test length(keys(lK)) == 3
@test haskey(lK, one(K)) && haskey(lK, a) && haskey(lK, -a - 1)
@test lK[one(K)] == 2
@test lK[a] == 1
@test lK[-a - 1] == 1

M = matrix(K, 4, 4, [ 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 ])
lK2 = eigvals(M)
@test lK == lK2

Eig = eigenspaces(M, side = :right)
V = zero_matrix(K, 4, 0)
for (e, v) in Eig
@test haskey(lK2, e)
@test lK2[e] == ncols(v)
@test M*v == e*v
V = hcat(V, v)
end
@test rref!(V) == 4

Eig = eigenspaces(M, side = :left)
V = zero_matrix(K, 0, 4)
for (e, v) in Eig
@test haskey(lK2, e)
@test lK2[e] == nrows(v)
@test v*M == e*v
V = vcat(V, v)
end
@test rref!(V) == 4

M = [ matrix(QQ, [ 0 1 0 0 0 0;
1 0 0 0 0 0;
Expand Down

0 comments on commit 6c72843

Please sign in to comment.