AbstractAlgebra.jl
AbstractAlgebra.jl copied to clipboard
Identity operator, LinearAlgebra.UniformScaling
This AbstractAlgebra behavior is unexpected, it would be great if this was supported:
julia> using LinearAlgebra, AbstractAlgebra
julia> [1 0; 0 1] == I
true
julia> ZZ[1 0; 0 1] == I
false
julia> QQ[1 0; 0 1] == I
false
julia> I == QQ[1 0; 0 1]
false
Likewise:
julia> QQ[2 3; 0 1] * I
ERROR: MethodError: no method matching *(::AbstractAlgebra.Generic.MatSpaceElem{Rational{BigInt}}, ::UniformScaling{Bool})
Closest candidates are:
*(::Any, ::Any, ::Any, ::Any...)
@ Base operators.jl:578
*(::MatrixElem{T}, ::Vector{T}) where T<:Union{NCRingElem, RingElement}
@ AbstractAlgebra ~/.julia/packages/AbstractAlgebra/ElVzc/src/Matrix.jl:924
*(::MatrixElem{T}, ::Union{AbstractFloat, Integer, Rational}) where T<:Union{NCRingElem, RingElement}
@ AbstractAlgebra ~/.julia/packages/AbstractAlgebra/ElVzc/src/Matrix.jl:754
...
Stacktrace:
[1] top-level scope
@ REPL[9]:1
It's, of course, possible to do the same thing less efficiently by constructing an explicit identity matrix:
julia> ZZ[1 0; 0 1] == identity_matrix(ZZ, 2)
true
julia> ZZ[1 0; 0 1] == identity_matrix(QQ, 2)
true
So I guess there's two potential issues here:
- there's no standard way to check whether an AbstractAlgebra matrix is an identity matrix without constructing the identity matrix. This could be solved in multiple ways, for example fixing the behavior of
==with anUniformScalingargument, or introducing a new functionis_identity - it's unexpected that AbstractAlgebra doesn't interoperate with
LinearAlgebra.UniformScalingandLinearAlgebra.I, for example the methods for*and==are missing