Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use I (UniformScaling from LinearAlgebra) with AlgebraicNumbers #28

Closed
denshd opened this issue Dec 8, 2023 · 1 comment
Closed

Comments

@denshd
Copy link

denshd commented Dec 8, 2023

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
Copy link
Owner

anj1 commented Dec 8, 2023

Added commit ba3e6fa that fixes this.

@denshd denshd closed this as completed Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants