Skip to content

Commit

Permalink
fix issue #593 (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani authored Feb 11, 2025
1 parent 9cd95fb commit 41da4d0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Polynomials"
uuid = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
license = "MIT"
author = "JuliaMath"
version = "4.0.15"
version = "4.0.16"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
26 changes: 17 additions & 9 deletions src/rational-functions/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -427,22 +427,23 @@ end

## ---- zeros, poles, ...
"""
poles(pq::AbstractRationalFunction;
method=:numerical, multroot_method=:direct, kwargs...)
poles(pq::AbstractRationalFunction{T};
method=:numerical, multroot_method=nothing, kwargs...) where {T}
For a rational function `p/q`, first reduces to normal form, then finds the roots and multiplicities of the resulting denominator.
* `method` is used to pass to `lowest_terms`
* `multroot_method` is passed to the method argument of `multroot`, which can be `:direct` (the faster default) or `:iterative` (the slower, and possibly more robust alternate)
* `multroot_method` is passed to the method argument of `multroot`, which can be `:direct` (the faster default) or `:iterative` (the slower, and possibly more robust alternate). The default is `:direct` save for `Big` values in which case `:iterative` is used.
"""
function poles(pq::AbstractRationalFunction;
function poles(pq::AbstractRationalFunction{T};
method=:numerical, # for lowest_terms
multroot_method=:direct, # or :iterative
kwargs...)
multroot_method=nothing, # :direct or:iterative
kwargs...) where {T}
pq′ = lowest_terms(pq; method=method, kwargs...)
den = denominator(pq′)
mr = Multroot.multroot(den; method=multroot_method)
mmethod = something(multroot_method, default_multroot_method(T))
mr = Multroot.multroot(den; method=mmethod)
(zs=mr.values, multiplicities = mr.multiplicities)
end

Expand All @@ -452,12 +453,19 @@ end
Return the `zeros` of the rational function (after cancelling commong factors, the `zeros` are the roots of the numerator.
"""
function roots(pq::AbstractRationalFunction; method=:numerical, kwargs...)
function roots(pq::AbstractRationalFunction{T};
method=:numerical,
multroot_method=nothing, # :direct or:iterative
kwargs...) where {T}
pq′ = lowest_terms(pq; method=method, kwargs...)
den = numerator(pq′)
mr = Multroot.multroot(den)
mmethod = something(multroot_method, default_multroot_method(T))
mr = Multroot.multroot(den; method=mmethod)
(zs=mr.values, multiplicities = mr.multiplicities)
end
default_multroot_method(::Type{T}) where {T<:Union{BigFloat, Complex{BigFloat}, BigInt, Complex{BigInt}}} = :iterative
default_multroot_method(::Any) = :direct


"""
residues(pq::AbstractRationalFunction; method=:numerical, kwargs...)
Expand Down
9 changes: 7 additions & 2 deletions test/StandardBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1038,9 +1038,14 @@ end
q = Polynomial(dencoeffs)
r = p//q

@test_throws ArgumentError poles(r)
out = poles(r; multroot_method=:iterative)
out = roots(r)
@test out.multiplicities == [3]
our = poles(r)
@test out.multiplicities == [3]

multroot_method = :direct # fails if direct
@test_throws ArgumentError poles(r; multroot_method)
@test_throws ArgumentError roots(r; multroot_method)
end

@testset "critical points" begin
Expand Down

2 comments on commit 41da4d0

@jverzani
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/124850

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v4.0.16 -m "<description of version>" 41da4d034ee90c40aca6148957e52cf3f9aa3d79
git push origin v4.0.16

Please sign in to comment.