Skip to content

Commit 31814ca

Browse files
authored
minor doc adjustments (#357)
1 parent 34bd564 commit 31814ca

File tree

8 files changed

+51
-58
lines changed

8 files changed

+51
-58
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "Polynomials"
22
uuid = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
33
license = "MIT"
44
author = "JuliaMath"
5-
version = "2.0.14"
5+
version = "2.0.15"
66

77
[deps]
88
Intervals = "d8418881-c3e1-53bb-8760-2df7ec849ed5"

docs/make.jl

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
using Documenter
22
using Polynomials
33

4+
5+
ENV["PLOTS_TEST"] = "true"
6+
ENV["GKSwstype"] = "100"
7+
8+
49
DocMeta.setdocmeta!(Polynomials, :DocTestSetup, :(using Polynomials); recursive = true)
510

611
makedocs(

docs/src/extending.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ As always, if the default implementation does not work or there are more efficie
3030
| `one`| | Convenience to find constant in new basis |
3131
| `variable`| | Convenience to find monomial `x` in new basis|
3232

33-
Check out both the [`Polynomial`](@ref) and [`ChebyshevT`](@ref) for examples of this interface being extended.
33+
Check out both the [`Polynomial`](@ref) and [`ChebyshevT`](@ref) for examples of this interface being extended.
3434

3535
## Example
3636

37-
The following shows a minimal example where the polynomial aliases the vector defining the coefficients.
37+
The following shows a minimal example where the polynomial aliases the vector defining the coefficients.
3838
The constructor ensures that there are no trailing zeros. The `@register` call ensures a common interface. This example subtypes `StandardBasisPolynomial`, not `AbstractPolynomial`, and consequently inherits the methods above that otherwise would have been required. For other bases, more methods may be necessary to define (again, refer to [`ChebyshevT`](@ref) for an example).
3939

4040
```jldoctest AliasPolynomial
@@ -75,7 +75,7 @@ julia> p(3)
7575
142
7676
```
7777

78-
For the `Polynomial` type, the default on operations is to copy the array. For this type, it might seem reasonable -- to avoid allocations -- to update the coefficients in place for scalar addition and scalar multiplication.
78+
For the `Polynomial` type, the default on operations is to copy the array. For this type, it might seem reasonable -- to avoid allocations -- to update the coefficients in place for scalar addition and scalar multiplication.
7979

8080
Scalar addition, `p+c`, defaults to `p + c*one(p)`, or polynomial addition, which is not inplace without addition work. As such, we create a new method and an infix operator
8181

@@ -134,7 +134,7 @@ julia> p ./= 2
134134
AliasPolynomial(3 + 2*x + 3*x^2 + 4*x^3)
135135
```
136136

137-
Trying to divide again would throw an error, as the result would not fit with the integer type of `p`.
137+
Trying to divide again would throw an error, as the result would not fit with the integer type of `p`.
138138

139139
Now `p` is treated as the vector `p.coeffs`, as regards broadcasting, so some things may be surprising, for example this expression returns a vector, not a polynomial:
140140

@@ -147,4 +147,4 @@ julia> p .+ 2
147147
6
148148
```
149149

150-
The [`Polynomials.PnPolynomial`](@ref) type implements much of this.
150+
The unexported `Polynomials.PnPolynomial` type implements much of this.

docs/src/index.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Polynomials.jl
22

33
Polynomials.jl is a Julia package that provides basic arithmetic, integration,
4-
differentiation, evaluation, and root finding over dense univariate polynomials.
4+
differentiation, evaluation, and root finding for univariate polynomials.
55

66
To install the package, run
77

@@ -57,6 +57,8 @@ julia> p(1)
5757
5858
```
5959

60+
The `Polynomial` constructor stores all coefficients using the standard basis with a vector. Other types (e.g. `ImmutablePolynomial`, `SparsePolynomial`, or `FactoredPolynomial`) use different back-end containers which may have advantage for some uses.
61+
6062
### Arithmetic
6163

6264
The usual arithmetic operators are overloaded to work on polynomials, and combinations of polynomials and scalars.
@@ -101,7 +103,7 @@ ERROR: ArgumentError: Polynomials have different indeterminates
101103
[...]
102104
```
103105

104-
Except for operations involving constant polynomials.
106+
Except for operations involving constant polynomials.
105107

106108
```jldoctest
107109
julia> p = Polynomial([1, 2, 3], :x)
@@ -358,7 +360,7 @@ Most of the root finding algorithms have issues when the roots have
358360
multiplicities. For example, both `ANewDsc` and `Hecke.roots` assume a
359361
square free polynomial. For non-square free polynomials:
360362

361-
* The `Polynomials.Multroot.multroot` function is available (version v"1.2" or greater) for finding the roots of a polynomial and their multiplicities. This is based on work of Zeng.
363+
* The `Polynomials.Multroot.multroot` function is available (version `v"1.2"` or greater) for finding the roots of a polynomial and their multiplicities. This is based on work of Zeng.
362364

363365
Here we see `IntervalRootsFindings.roots` having trouble isolating the roots due to the multiplicites:
364366

src/common.jl

+2-3
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,9 @@ _wlstsq(vand, y, W::AbstractMatrix) = qr(vand' * W * vand) \ (vand' * W * y)
170170
171171
Returns the roots, or zeros, of the given polynomial.
172172
173-
This is calculated via the eigenvalues of the companion matrix. The `kwargs` are passed to the `LinearAlgeebra.eigvals` call.
174-
175-
!!! Note
173+
For non-factored, standard basis polynomials the roots are calculated via the eigenvalues of the companion matrix. The `kwargs` are passed to the `LinearAlgeebra.eigvals` call.
176174
175+
!!! note
177176
The default `roots` implementation is for polynomials in the
178177
standard basis. The companion matrix approach is reasonably fast
179178
and accurate for modest-size polynomials. However, other packages

src/polynomials/ChebyshevT.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ julia> Polynomials.evalpoly(5.0, p, false) # bypasses the domain check done in p
3535
3636
The latter shows how to evaluate a `ChebyshevT` polynomial outside of its domain, which is `[-1,1]`. (For newer versions of `Julia`, `evalpoly` is an exported function from Base with methods extended in this package, so the module qualification is unnecessary.
3737
38-
!!! Note:
38+
!!! note
3939
The Chebyshev polynomials are also implemented in `ApproxFun`, `ClassicalOrthogonalPolynomials.jl`, `FastTransforms.jl`, and `SpecialPolynomials.jl`.
4040
4141
"""

src/rational-functions/common.jl

+17-29
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Default methods for basic arithmetic operations are provided.
1212
1313
Numeric methods to cancel common factors, compute the poles, and return the residues are provided.
1414
15-
!!! Note:
15+
!!! note
1616
Requires `VERSION >= v"1.2.0"`
1717
"""
1818
abstract type AbstractRationalFunction{T,X,P} end
@@ -131,8 +131,8 @@ end
131131

132132
Base.://(p::AbstractPolynomial,q::Number) = p // (q*one(p))
133133
Base.://(p::Number, q::AbstractPolynomial) = (p*one(q)) // q
134-
135-
134+
135+
136136
function Base.copy(pq::PQ) where {PQ <: AbstractRationalFunction}
137137
p,q = pqs(pq)
138138
rational_function(PQ, p, q)
@@ -165,7 +165,7 @@ _eltype(pq::Type{<:AbstractRationalFunction{T}}) where {T} = Polynomial{T}
165165
_eltype(pq::Type{<:AbstractRationalFunction}) = Polynomial
166166

167167
"""
168-
pqs(pq)
168+
pqs(pq)
169169
170170
Return `(p,q)`, where `pq=p/q`, as polynomials.
171171
"""
@@ -178,7 +178,7 @@ function Base.isinf(pq::AbstractRationalFunction)
178178
p,q=pqs(pq)
179179
iszero(q) && !iszero(p)
180180
end
181-
function Base.isnan(pq::AbstractRationalFunction)
181+
function Base.isnan(pq::AbstractRationalFunction)
182182
p,q= pqs(pq)
183183
iszero(p) && iszero(q)
184184
end
@@ -191,7 +191,7 @@ function Base.isone(pq::AbstractRationalFunction)
191191
isconstant(p) && isconstant(q) && p == q
192192
end
193193

194-
194+
195195

196196
## -----
197197

@@ -236,7 +236,7 @@ function variable(::Type{PQ}) where {PQ <: AbstractRationalFunction}
236236
rational_function(PQ, x, one(x))
237237
end
238238

239-
239+
240240
# use degree as largest degree of p,q after reduction
241241
function degree(pq::AbstractRationalFunction)
242242
pq′ = lowest_terms(pq)
@@ -355,7 +355,7 @@ function Base.:/(p::R, q::Number) where {R <: AbstractRationalFunction}
355355
rational_function(R, p0, (p1*q))
356356
end
357357
Base.:/(p::AbstractPolynomial, q::PQ) where {PQ <: AbstractRationalFunction} = rational_function(PQ, p,one(p)) / q
358-
function Base.:/(p::PQ, q::AbstractPolynomial) where {PQ <: AbstractRationalFunction}
358+
function Base.:/(p::PQ, q::AbstractPolynomial) where {PQ <: AbstractRationalFunction}
359359
p0,p1 = pqs(p)
360360
rational_function(PQ,p0, p1*q)
361361
end
@@ -418,17 +418,17 @@ function Base.divrem(pq::PQ; method=:numerical, kwargs...) where {PQ <: Abstract
418418

419419
d,r = divrem(p,q)
420420
(d, rational_function(PQ, r, q))
421-
421+
422422
end
423423

424424

425425

426426

427427
"""
428428
lowest_terms(pq::AbstractRationalFunction, method=:numerical)
429-
429+
430430
Find GCD of `(p,q)`, `u`, and return `(p÷u)//(q÷u)`. Commonly referred to as lowest terms.
431-
431+
432432
* `method`: passed to `gcd(p,q)`
433433
* `kwargs`: passed to `gcd(p,q)`
434434
@@ -475,11 +475,11 @@ end
475475
476476
If `p/q =d + r/q`, returns `d` and the residues of a rational fraction `r/q`.
477477
478-
First expresses `p/q =d + r/q` with `r` of lower degree than `q` through `divrem`.
478+
First expresses `p/q =d + r/q` with `r` of lower degree than `q` through `divrem`.
479479
Then finds the poles of `r/q`.
480-
For a pole, `λj` of multiplicity `k` there are `k` residues,
480+
For a pole, `λj` of multiplicity `k` there are `k` residues,
481481
`rⱼ[k]/(z-λⱼ)^k`, `rⱼ[k-1]/(z-λⱼ)^(k-1)`, `rⱼ[k-2]/(z-λⱼ)^(k-2)`, …, `rⱼ[1]/(z-λⱼ)`.
482-
The residues are found using this formula:
482+
The residues are found using this formula:
483483
`1/j! * dʲ/dsʲ (F(s)(s - λⱼ)^k` evaluated at `λⱼ` ([5-28](https://stanford.edu/~boyd/ee102/rational.pdf)).
484484
485485
@@ -521,19 +521,19 @@ julia> p′, q′ = lowest_terms(d);
521521
julia> q′ ≈ (s-1) * (s+1)^2 # works, as q is monic
522522
true
523523
524-
julia> p′ ≈ (-s^2 + s + 1)
524+
julia> p′ ≈ (-s^2 + s + 1)
525525
true
526526
```
527527
528528
529529
530-
!!! Note:
530+
!!! note
531531
There are several areas where numerical issues can arise. The `divrem`, the identification of multiple roots (`multroot`), the evaluation of the derivatives, ...
532532
533533
"""
534534
function residues(pq::AbstractRationalFunction; method=:numerical, kwargs...)
535535

536-
536+
537537
d,r′ = divrem(pq)
538538
r = lowest_terms(r′; method=method, kwargs...)
539539
b,a = pqs(r)
@@ -590,15 +590,3 @@ function partial_fraction(::Val{:residue}, r, s::PQ) where {PQ}
590590
terms
591591

592592
end
593-
594-
595-
596-
597-
598-
599-
600-
601-
602-
603-
604-

src/rational-functions/fit.jl

+15-16
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ Fit a rational function of the form `pq = (a₀ + a₁x¹ + … + aₘxᵐ) / (1
1111
1212
1313
14-
!!! Note:
15-
14+
!!! note
1615
This uses a simple implementation of the Gauss-Newton method
17-
to solve the non-linear least squares problem:
18-
`minᵦ Σ(yᵢ - pq(xᵢ,β)²`, where `β=(a₀,a₁,…,aₘ,b₁,…,bₙ)`.
16+
to solve the non-linear least squares problem:
17+
`minᵦ Σ(yᵢ - pq(xᵢ,β)²`, where `β=(a₀,a₁,…,aₘ,b₁,…,bₙ)`.
1918
2019
A more rapidly convergent method is used in the `LsqFit.jl`
2120
package, and if performance is important, re-expressing the
22-
problem for use with that package is suggested.
21+
problem for use with that package is suggested.
2322
2423
Further, if an accurate rational function fit of adaptive degrees
2524
is of interest, the `BaryRational.jl` package provides an
@@ -69,7 +68,7 @@ julia> u(variable(pq)) # to see which polynomial is used
6968
"""
7069
function Polynomials.fit(::Type{PQ}, xs::AbstractVector{S}, ys::AbstractVector{T}, m, n; var=:x) where {T,S, PQ<:RationalFunction}
7170

72-
71+
7372
β₁,β₂ = gauss_newton(collect(xs), convert(Vector{float(T)}, ys), m, n)
7473
P = eltype(PQ)
7574
T′ = Polynomials._eltype(P) == nothing ? eltype(β₁) : eltype(P)
@@ -132,10 +131,10 @@ function pade_fit(p::Polynomial{T}, m::Integer, n::Integer; var=:x) where {T}
132131
d = degree(p)
133132
@assert (0 <= m) && (1 <= n) && (m + n <= d)
134133

135-
# could be much more perfomant
134+
# could be much more perfomant
136135
c = convert(LaurentPolynomial, p) # for better indexing
137136
cs = [c[m+j-i] for j 1:n, i 0:n]
138-
137+
139138
qs′ = cs[:, 2:end] \ cs[:,1]
140139
qs = vcat(1, -qs′)
141140

@@ -198,15 +197,15 @@ function J!(Jᵣ, xs::Vector{T}, β, n) where {T}
198197
end
199198
nothing
200199
end
201-
202-
200+
201+
203202
function gauss_newton(xs, ys::Vector{T}, n, m, tol=sqrt(eps(T))) where {T}
204203

205204
β = initial_guess(xs, ys, n, m)
206205
model = make_model(n)
207206

208207
Jᵣ = zeros(T, length(xs), 1 + n + m)
209-
208+
210209
Δ = norm(ys, Inf) * tol
211210

212211
ϵₘ = norm(ys - model(xs, β), Inf)
@@ -216,7 +215,7 @@ function gauss_newton(xs, ys::Vector{T}, n, m, tol=sqrt(eps(T))) where {T}
216215

217216
while no_steps < 25
218217
no_steps += 1
219-
218+
220219
r = ys - model(xs, β)
221220
ϵ = norm(r, Inf)
222221
ϵ < Δ && return (β[1:n+1], β[n+2:end])
@@ -227,12 +226,12 @@ function gauss_newton(xs, ys::Vector{T}, n, m, tol=sqrt(eps(T))) where {T}
227226
J!(Jᵣ, xs, β, n)
228227
Δᵦ = pinv(Jᵣ' * Jᵣ) * (Jᵣ' * r)
229228
β .-= Δᵦ
230-
229+
231230
end
232231

233232
@warn "no convergence; returning best fit of many steps"
234233
return (βₘ[1:n+1], βₘ[n+2:end])
235234
end
236-
237-
238-
end
235+
236+
237+
end

0 commit comments

Comments
 (0)