Skip to content

Commit

Permalink
get working on v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani committed Apr 13, 2021
1 parent ac232f0 commit 4258a2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/rational-functions/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ function integrate(pq::P) where {P <: AbstractRationalFunction}
end

## ----
# :numerical only works for v1.2 or later
# drop once new LTS Julia is released
const default_gcd_method = VERSION >= v"1.2" ? :numerical : :euclidean

"""
divrem(pq::AbstractRationalFunction; method=:numerical, kargs...)
Expand All @@ -368,7 +372,7 @@ Return `d,r` with `p/q = d + r/q` where `degree(numerator(r)) < degree(denominat
* `method`: passed to `gcd`
* `kwargs...`: passed to `gcd`
"""
function Base.divrem(pq::PQ; method=:numerical, kwargs...) where {PQ <: AbstractRationalFunction}
function Base.divrem(pq::PQ; method=default_gcd_method, kwargs...) where {PQ <: AbstractRationalFunction}
p,q = pqs(pq)
degree(p) < degree(q) && return (zero(p), pq)

Expand Down Expand Up @@ -405,7 +409,7 @@ Find GCD of `(p,q)`, `u`, and return `(p÷u)//(q÷u)`. Commonly referred to as l
By default, `AbstractRationalFunction` types do not cancel common factors. This method will numerically cancel common factors, returning the normal form, canonicalized here by `q[end]=1`. The result and original may be considered equivalent as rational expressions, but different when seen as functions of the indeterminate.
"""
function lowest_terms(pq::PQ; method=:numerical, kwargs...) where {T,X,
function lowest_terms(pq::PQ; method=default_gcd_method, kwargs...) where {T,X,
P<:StandardBasisPolynomial{T,X},
PQ<:AbstractRationalFunction{T,X,P}}
v,w = _divgcd(Val(method), pq; kwargs...)
Expand All @@ -419,7 +423,7 @@ end
For a rational function `p/q`, first reduces to normal form, then finds the roots and multiplicities of the resulting denominator.
"""
function poles(pq::AbstractRationalFunction; method=:numerical, kwargs...)
function poles(pq::AbstractRationalFunction; method=default_gcd_method, kwargs...)
pq′ = lowest_terms(pq; method=method, kwargs...)
den = denominator(pq′)
mr = Multroot.multroot(den)
Expand All @@ -432,7 +436,7 @@ 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; method=default_gcd_method, kwargs...)
pq′ = lowest_terms(pq; method=method, kwargs...)
den = numerator(pq′)
mr = Multroot.multroot(den)
Expand Down Expand Up @@ -494,7 +498,7 @@ true
There are several areas where numerical issues can arise. The `divrem`, the identification of multiple roots (`multroot`), the evaluation of the derivatives, ...
"""
function residues(pq::AbstractRationalFunction; method=:numerical, kwargs...)
function residues(pq::AbstractRationalFunction; method=default_gcd_method, kwargs...)


d,r′ = divrem(pq)
Expand Down Expand Up @@ -537,7 +541,7 @@ Should be if `p/q` is in normal form and `d,r=partial_fraction(p//q)` that
`d + sum(r) - p//q ≈ 0`
"""
function partial_fraction(pq::AbstractRationalFunction; method=:numerical, kwargs...)
function partial_fraction(pq::AbstractRationalFunction; method=default_gcd_method, kwargs...)
d,r = residues(pq; method=method, kwargs...)
s = variable(pq)
d, partial_fraction(Val(:residue), r, s)
Expand Down
1 change: 1 addition & 0 deletions src/rational-functions/fit.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module RationalFunctionFit
using ..Polynomials
import ..Polynomials: RationalFunction, indeterminate, constructorof
import ..Polynomials: evalpoly
using LinearAlgebra

"""
Expand Down

0 comments on commit 4258a2d

Please sign in to comment.