Skip to content

Commit

Permalink
Merge pull request #1224 from mxhbl/master
Browse files Browse the repository at this point in the history
fix coeff on divisions
  • Loading branch information
ChrisRackauckas authored Aug 22, 2024
2 parents 149a63e + 62859ce commit 783b1e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,12 @@ function coeff(p, sym=nothing)
@views prod(Iterators.flatten((coeffs[findall(!iszero, coeffs)], args[findall(iszero, coeffs)])))
end
elseif isdiv(p)
throw(DomainError(p, "coeff on expressions with division is not yet implemented."))
numerator, denominator = arguments(p)
if !occursin(sym, denominator)
coeff(numerator, sym) / denominator
else
throw(DomainError(p, "coeff on fractions is not yet implemented."))
end
else
p isa Number && return sym === nothing ? p : 0
p isa Symbolic && return coeff(p, sym)
Expand Down
4 changes: 4 additions & 0 deletions test/coeff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ e = x*y^2 + 2x + y^3*x^3
@test isequal(coeff(x^2 + 1, x^0), 1)
@test isequal(coeff(e, x^0), 0)
@test isequal(coeff(a*x + 3, x^0), 3)

@test isequal(coeff(x / 5, x), 1//5)
@test isequal(coeff(x / y, x), 1/y)
@test isequal(coeff(x * 5y / (1 + y + z) , x), 5y / (1 + y + z))

0 comments on commit 783b1e4

Please sign in to comment.