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

`MethodError: binomial(::Num, ::Int64) is ambiguous.`

Open nsajko opened this issue 2 years ago • 1 comments

julia> using Symbolics

julia> @variables x
1-element Vector{Num}:
 x

julia> invoke(binomial, Tuple{Number, Integer}, x, 3)  # this is what I would expect from `binomial(x, 3)`
(1//6)*x*(x - 1)*(x - 2)

julia> binomial(x, 3)  # instead there's a `MethodError`
ERROR: MethodError: binomial(::Num, ::Int64) is ambiguous.

Candidates:
  binomial(arg1::Num, arg2::Real)
    @ Symbolics ~/.julia/packages/Symbolics/BQlmn/src/register.jl:55
  binomial(x::Number, k::Integer)
    @ Base intfuncs.jl:1145

Possible fix, define
  binomial(::Num, ::Integer)

Stacktrace:
 [1] top-level scope
   @ REPL[4]:1

(@v1.11) pkg> st Symbolics
Status `~/.julia/environments/v1.11/Project.toml`
  [0c5d862f] Symbolics v5.5.1

As first noted by stevengj on Discourse.

nsajko avatar Aug 16 '23 20:08 nsajko

The behavior of binomial(x, 3) changed recently, I guess because of #985:

julia> using Symbolics

julia> @variables x
1-element Vector{Num}:
 x

julia> invoke(binomial, Tuple{Number, Integer}, x, 3)
(1//6)*(-2 + x)*(-1 + x)*x

julia> binomial(x, 3)
binomial(x, 3)

(@v1.11) pkg> st Symbolics
Status `~/.julia/environments/v1.11/Project.toml`
  [0c5d862f] Symbolics v5.10.0

So the error is gone, but I don't see how the result is useful. @YingboMa how to get the result as expected (a polynomial, as in the invoke) from the result of a call like binomial(x, 3)?

nsajko avatar Nov 20 '23 00:11 nsajko