Groups.jl/src/matrix_groups/eltary_matrices.jl

29 lines
847 B
Julia
Raw Normal View History

2022-10-14 01:14:38 +02:00
struct ElementaryMatrix{N,T} <: Groups.GSymbol
i::Int
j::Int
val::T
2022-10-14 01:14:38 +02:00
ElementaryMatrix{N}(i, j, val=1) where {N} =
(@assert i j; new{N,typeof(val)}(i, j, val))
end
function Base.show(io::IO, e::ElementaryMatrix)
print(io, 'E', Groups.subscriptify(e.i), Groups.subscriptify(e.j))
!isone(e.val) && print(io, "^$(e.val)")
end
2022-10-14 01:14:38 +02:00
Base.:(==)(e::ElementaryMatrix{N}, f::ElementaryMatrix{N}) where {N} =
e.i == f.i && e.j == f.j && e.val == f.val
Base.hash(e::ElementaryMatrix, h::UInt) =
hash(typeof(e), hash((e.i, e.j, e.val), h))
2022-10-14 01:14:38 +02:00
Base.inv(e::ElementaryMatrix{N}) where {N} =
ElementaryMatrix{N}(e.i, e.j, -e.val)
2022-10-14 01:14:38 +02:00
function matrix_repr(e::ElementaryMatrix{N,T}) where {N,T}
m = StaticArrays.MMatrix{N,N,T}(LinearAlgebra.I)
m[e.i, e.j] = e.val
2022-10-14 01:14:38 +02:00
x = StaticArrays.SMatrix{N,N}(m)
return x
end