JuliaSymbolics / Symbolics.jl

Symbolic programming for the next generation of numerical software
https://docs.sciml.ai/Symbolics/stable/
Other
1.35k stars 151 forks source link

Symbolics.coeff for multivariate polynomials incorrect #1041

Closed NAThompson closed 1 week ago

NAThompson commented 7 months ago

To reproduce:

julia> @variables x y;
julia> Symbolics.coeff(3x + 2*x*y, x*y)
0

Of course the answer should be 2. . .

Julia version 1.10.0, latest released Symbolics.

yuvalwas commented 7 months ago

I'm also having this problem. For your case, semipolynomial_form seems to work:

julia> @variables x y;
julia> d = semipolynomial_form(3x + 2*x*y, [x, y], Inf)
(Dict{Any, Any}(x*y => 2, x => 3), 0)
julia> d[1][x*y]
2

However, it doesn't work when the power is also a variable, as in

@variables x y a b
poly = 3x^a + 2*x^b * y^a
NAThompson commented 7 months ago

@yuvalwas : My report was actually a simplification of a case where the power was also a variable, so thanks for looking into this. . .

zengmao commented 1 week ago

I've fixed the original issue in pull request #1240, though I haven't covered the case where the power is also a variable.

ChrisRackauckas commented 1 week ago

Fixed in https://github.com/JuliaSymbolics/Symbolics.jl/pull/1240