From ec59506c290a8872dfa5a77a37db68a007b0980b Mon Sep 17 00:00:00 2001 From: n0rbed Date: Fri, 22 Mar 2024 14:35:31 +0200 Subject: [PATCH 1/4] fix added --- src/utils.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utils.jl b/src/utils.jl index f86ed12c3..9477a9c09 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -305,6 +305,11 @@ julia> Symbolics.coeff(x^2 + y, x^2) """ function coeff(p, sym=nothing) p, sym = value(p), value(sym) + + if sym == 1 + sym = nothing + end + if issym(p) || isterm(p) sym === nothing ? 0 : Int(isequal(p, sym)) elseif ispow(p) From 20c09c940fdf7615805f19c88438075750ff6c6c Mon Sep 17 00:00:00 2001 From: n0rbed Date: Fri, 22 Mar 2024 15:17:03 +0200 Subject: [PATCH 2/4] added some tests to validate the changes --- test/coeff.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/coeff.jl b/test/coeff.jl index 44b874646..f23047a37 100644 --- a/test/coeff.jl +++ b/test/coeff.jl @@ -39,3 +39,9 @@ e = x*y^2 + 2x + y^3*x^3 @test isequal(coeff(expand(((x + 1)^4 + x)^3), x^2), 93) @test isequal(coeff(simplify((x^2 - 1) / (x - 1)), x), 1) @test isequal(coeff(expand((x^(1//2) + y^0.5)^2), x), 1) + + +# issue #1098 +@test isequal(coeff(x^2 + 1, x^0), 1) +@test isequal(coeff(e, x^0), 4) +@test isequal(coeff(a, x^0), a) From 601c4e0c26f5408e35475d421ee9ec507c289f4a Mon Sep 17 00:00:00 2001 From: n0rbed Date: Fri, 22 Mar 2024 15:25:57 +0200 Subject: [PATCH 3/4] fixed tests --- test/coeff.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/coeff.jl b/test/coeff.jl index f23047a37..1bb74854d 100644 --- a/test/coeff.jl +++ b/test/coeff.jl @@ -43,5 +43,5 @@ e = x*y^2 + 2x + y^3*x^3 # issue #1098 @test isequal(coeff(x^2 + 1, x^0), 1) -@test isequal(coeff(e, x^0), 4) -@test isequal(coeff(a, x^0), a) +@test isequal(coeff(e, x^0), 0) +@test isequal(coeff(a*x + 3, x^0), 3) From cf3b3ae4952699f9a8f29282507dcc4dfc236a3b Mon Sep 17 00:00:00 2001 From: n0rbed Date: Sun, 24 Mar 2024 00:02:27 +0200 Subject: [PATCH 4/4] fixed non-boolean comparison issue --- src/utils.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.jl b/src/utils.jl index 9477a9c09..8b427d0c7 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -306,7 +306,7 @@ julia> Symbolics.coeff(x^2 + y, x^2) function coeff(p, sym=nothing) p, sym = value(p), value(sym) - if sym == 1 + if isequal(sym, 1) sym = nothing end