anj1/AlgebraicNumbers.jl

Cannot use `I` (`UniformScaling` from LinearAlgebra) with AlgebraicNumbers

Closed this issue · 1 comments

denshd commented

Consider the following MWE:

using LinearAlgebra
using AlgebraicNumbers


A = AlgebraicNumber.([
    1 2
    3 4
])

λ = AlgebraicNumber(2)

B = A - λ*I # error here

Error arises:

ERROR: LoadError: MethodError: promote_rule(::Type{Bool}, ::Type{AlgebraicNumber{BigInt, BigFloat}}) is ambiguous.

Candidates:
  promote_rule(x::Type{T}, y::Type{AlgebraicNumber{S, F}}) where {T<:Integer, S, F}
    @ AlgebraicNumbers ~/.julia/packages/AlgebraicNumbers/H0atE/src/promote.jl:14
  promote_rule(::Type{Bool}, ::Type{T}) where T<:Number
    @ Base bool.jl:4

Possible fix, define
  promote_rule(::Type{Bool}, ::Type{AlgebraicNumber{S, F}}) where {S, F}

Stacktrace:
 [1] promote_type(#unused#::Type{AlgebraicNumber{BigInt, BigFloat}}, #unused#::Type{Bool})
   @ Base ./promotion.jl:307
 [2] _promote
   @ ./promotion.jl:357 [inlined]
 [3] promote
   @ ./promotion.jl:381 [inlined]
 [4] *(x::AlgebraicNumber{BigInt, BigFloat}, y::Bool)
   @ Base ./promotion.jl:411
 [5] *(x::AlgebraicNumber{BigInt, BigFloat}, J::UniformScaling{Bool})
   @ LinearAlgebra ~/julia-1.9.3/share/julia/stdlib/v1.9/LinearAlgebra/src/uniformscaling.jl:263
 [6] top-level scope
   @ ~/MSU/Code/Quadrics/bug.jl:12
 [7] include(fname::String)
   @ Base.MainInclude ./client.jl:478
 [8] top-level scope
   @ REPL[14]:1

I expected that I will work just like with, e.g., NiceNumbers:

using LinearAlgebra
using NiceNumbers

A = NiceNumber.([
    1 2
    3 4
])

λ = NiceNumber(2)

B = A - λ*I

(the answer is

2×2 Matrix{NiceNumber}:
 -1  2
  3  2

what I've expected)

anj1 commented

Added commit ba3e6fa that fixes this.