AbstractAlgebra.jl icon indicating copy to clipboard operation
AbstractAlgebra.jl copied to clipboard

Identity operator, LinearAlgebra.UniformScaling

Open nsajko opened this issue 3 years ago • 0 comments

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:

  1. 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 an UniformScaling argument, or introducing a new function is_identity
  2. it's unexpected that AbstractAlgebra doesn't interoperate with LinearAlgebra.UniformScaling and LinearAlgebra.I, for example the methods for * and == are missing

nsajko avatar Sep 04 '22 21:09 nsajko