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

inv not working on Quaternion{Num}

Open knuesel opened this issue 3 years ago • 3 comments

The inv function doesn't work for quaternions of Symbolics.Num type:

julia> using Quaternions, Symbolics

julia> q = quat(Num.([0,0,0,1])...)
Quaternion{Num}(0, 0, 0, 1)

julia> inv(q)
ERROR: MethodError: /(::Quaternion{Num}, ::Num) is ambiguous. Candidates:
  /(a::Number, b::Num) in Symbolics at /home/j/.julia/packages/SymbolicUtils/qulQp/src/methods.jl:71
  /(q::Quaternion, x::Real) in Quaternions at /home/j/.julia/packages/Quaternions/kqEsP/src/Quaternion.jl:123
Possible fix, define
  /(::Quaternion, ::Num)
Stacktrace:
 [1] inv(q::Quaternion{Num})
   @ Quaternions ~/.julia/packages/Quaternions/kqEsP/src/Quaternion.jl:143
 [2] top-level scope
   @ REPL[3]:1

knuesel avatar Dec 21 '22 16:12 knuesel

I think the method inv(q::Quaternion) should be defined in Symbolics.jl because:

  • Base.inv(z::Complex{Num}) is defined on Symbolics.jl
  • Quaternions.jl should be a lightweight package that does not have a dependency on Symbolics.jl.

hyrodium avatar Dec 28 '22 12:12 hyrodium

On Julia v1.9 this could be done by setting up a weakdep of Symbolics on Quaternions or the other way around. I'm not certain which makes more sense.

sethaxen avatar Jan 25 '23 19:01 sethaxen

It seems the issue is not just implementations of /(::Quaternion{Num}, ::Num), inv(::Quaternion{Num}) etc.

For example, we need a quaternionic version of Symbolics.ComplexTerm, so the problem is not that simple and that should not be finished in this package.

hyrodium avatar Nov 25 '23 10:11 hyrodium