Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #593 #595

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading