Skip to content

Commit 6153edc

Browse files
authored
breaking changes (#381)
* work around domain * remove dependency on Intervals * close #374 (#377) * V3 drop 1 0 (#379) * drop support for older versions of Julia * V3 docs (#380) * Qr (#384) * remove depwarn * add Val(:x) as means to specify the symbol
1 parent 9a6d167 commit 6153edc

21 files changed

+336
-291
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
version:
18-
- '1.0' # lowest supported version
18+
- '1.6' # lowest supported version
1919
- '1' # last released version
2020
os:
2121
- ubuntu-latest

Project.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@ name = "Polynomials"
22
uuid = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
33
license = "MIT"
44
author = "JuliaMath"
5-
version = "2.0.25"
5+
version = "3.0.0"
66

77
[deps]
8-
Intervals = "d8418881-c3e1-53bb-8760-2df7ec849ed5"
98
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
109
MutableArithmetics = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
1110
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
1211

1312
[compat]
14-
Intervals = "0.5, 1.0, 1.3"
15-
MutableArithmetics = "0.3, 1.0"
13+
MutableArithmetics = "0.3,1"
1614
RecipesBase = "0.7, 0.8, 1"
17-
julia = "1"
15+
julia = "1.6"
1816

1917
[extras]
2018
DualNumbers = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74"

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ Basic arithmetic, integration, differentiation, evaluation, and root finding ove
1313
(v1.6) pkg> add Polynomials
1414
```
1515

16+
This package supports Julia v1.6 and later.
17+
1618
## Available Types of Polynomials
1719

18-
* `Polynomial` –⁠ standard basis polynomials, `a(x) = a₀ + a₁ x + a₂ x² + … + aₙ xⁿ`, `n ∈ ℕ`
20+
* `Polynomial` –⁠ standard basis polynomials, `a(x) = a₀ + a₁ x + a₂ x² + … + aₙ xⁿ`, `n ≥ 0`
1921
* `ImmutablePolynomial` –⁠ standard basis polynomials backed by a [Tuple type](https://docs.julialang.org/en/v1/manual/functions/#Tuples-1) for faster evaluation of values
2022
* `SparsePolynomial` –⁠ standard basis polynomial backed by a [dictionary](https://docs.julialang.org/en/v1/base/collections/#Dictionaries-1) to hold sparse high-degree polynomials
2123
* `LaurentPolynomial` –⁠ [Laurent polynomials](https://docs.julialang.org/en/v1/base/collections/#Dictionaries-1), `a(x) = aₘ xᵐ + … + aₙ xⁿ` `m ≤ n`, `m,n ∈ ℤ` backed by an [offset array](https://github.com/JuliaArrays/OffsetArrays.jl); for example, if `m<0` and `n>0`, `a(x) = aₘ xᵐ + … + a₋₁ x⁻¹ + a₀ + a₁ x + … + aₙ xⁿ`
@@ -99,7 +101,7 @@ julia> q ÷ p # `div`, also `rem` and `divrem`
99101
Polynomial(0.25 - 0.5*x)
100102
```
101103

102-
Operations involving polynomials with different variables will error.
104+
Most operations involving polynomials with different variables will error.
103105

104106
```jldoctest
105107
julia> p = Polynomial([1, 2, 3], :x);
@@ -189,8 +191,9 @@ julia> integrate(Polynomial([1, 0, -1]), 2)
189191
Polynomial(2.0 + 1.0*x - 0.3333333333333333*x^3)
190192
```
191193

192-
Differentiate the polynomial `p` term by term. The degree of the
193-
resulting polynomial is one lower than the degree of `p`.
194+
Differentiate the polynomial `p` term by term. For non-zero
195+
polynomials the degree of the resulting polynomial is one lower than
196+
the degree of `p`.
194197

195198
```jldoctest
196199
julia> derivative(Polynomial([1, 3, -1]))
@@ -242,16 +245,17 @@ Visual example:
242245

243246
Polynomial objects also have other methods:
244247

245-
* 0-based indexing is used to extract the coefficients of `[a0, a1, a2, ...]`, coefficients may be changed using indexing
246-
notation.
248+
* For standard basis polynomials, 0-based indexing is used to extract
249+
the coefficients of `[a0, a1, a2, ...]`; for mutable polynomials,
250+
coefficients may be changed using indexing notation.
247251

248-
* `coeffs`: returns the entire coefficient vector
252+
* `coeffs`: returns the coefficients
249253

250254
* `degree`: returns the polynomial degree, `length` is number of stored coefficients
251255

252-
* `variable`: returns the polynomial symbol as polynomial in the underlying type
256+
* `variable`: returns the polynomial symbol as a polynomial in the underlying type
253257

254-
* `norm`: find the `p`-norm of a polynomial
258+
* `LinearAlgebra.norm`: find the `p`-norm of a polynomial
255259

256260
* `conj`: finds the conjugate of a polynomial over a complex field
257261

@@ -283,7 +287,7 @@ Polynomial objects also have other methods:
283287

284288
* [CommutativeAlgebra.jl](https://github.com/KlausC/CommutativeRings.jl) the start of a computer algebra system specialized to discrete calculations with support for polynomials.
285289

286-
* [PolynomialRoots.jl](https://github.com/giordano/PolynomialRoots.jl) for a fast complex polynomial root finder. For larger degree problems, also [FastPolynomialRoots](https://github.com/andreasnoack/FastPolynomialRoots.jl) and [AMRVW](https://github.com/jverzani/AMRVW.jl).
290+
* [PolynomialRoots.jl](https://github.com/giordano/PolynomialRoots.jl) for a fast complex polynomial root finder. For larger degree problems, also [FastPolynomialRoots](https://github.com/andreasnoack/FastPolynomialRoots.jl) and [AMRVW](https://github.com/jverzani/AMRVW.jl). For real roots only [RealPolynomialRoots](https://github.com/jverzani/RealPolynomialRoots.jl).
287291

288292

289293
* [SpecialPolynomials.jl](https://github.com/jverzani/SpecialPolynomials.jl) A package providing various polynomial types beyond the standard basis polynomials in `Polynomials.jl`. Includes interpolating polynomials, Bernstein polynomials, and classical orthogonal polynomials.

docs/src/extending.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ As always, if the default implementation does not work or there are more efficie
2222
| Type function (`(::P)(x)`) | x | |
2323
| `convert(::Polynomial, ...)` | | Not required, but the library is built off the [`Polynomial`](@ref) type, so all operations are guaranteed to work with it. Also consider writing the inverse conversion method. |
2424
| `Polynomials.evalpoly(x, p::P)` | to evaluate the polynomial at `x` (`Base.evalpoly` okay post `v"1.4.0"`) |
25-
| `domain` | x | Should return an [`AbstractInterval`](https://invenia.github.io/Intervals.jl/stable/#Intervals-1) |
25+
| `Polynomials.domain` | x | Should return a `Polynomials.Interval` instance|
2626
| `vander` | | Required for [`fit`](@ref) |
2727
| `companion` | | Required for [`roots`](@ref) |
2828
| `*(::P, ::P)` | | Multiplication of polynomials |

docs/src/index.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ To install the package, run
1010
(v1.6) pkg> add Polynomials
1111
```
1212

13-
The package can then be loaded into the current session using
13+
As of version `v3.0.0` Julia version `1.6` or higher is required.
14+
15+
The package can then be loaded into the current session through
1416

1517
```julia
1618
using Polynomials
@@ -132,7 +134,8 @@ Polynomial(2.0 + 1.0*x - 0.3333333333333333*x^3)
132134
```
133135

134136
Differentiate the polynomial `p` term by term. The degree of the
135-
resulting polynomial is one lower than the degree of `p`.
137+
resulting polynomial is one lower than the degree of `p`, unless `p`
138+
is a zero polynomial.
136139

137140
```jldoctest
138141
julia> derivative(Polynomial([1, 3, -1]))
@@ -361,9 +364,9 @@ Most of the root finding algorithms have issues when the roots have
361364
multiplicities. For example, both `ANewDsc` and `Hecke.roots` assume a
362365
square free polynomial. For non-square free polynomials:
363366

364-
* 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.
367+
* The `Polynomials.Multroot.multroot` function is available for finding the roots of a polynomial and their multiplicities. This is based on work of Zeng.
365368

366-
Here we see `IntervalRootsFindings.roots` having trouble isolating the roots due to the multiplicites:
369+
Here we see `IntervalRootFinding.roots` having trouble isolating the roots due to the multiplicites:
367370

368371
```
369372
julia> p = fromroots(Polynomial, [1,2,2,3,3])
@@ -553,7 +556,7 @@ Polynomial(24 - 50*x + 35*x^2 - 10*x^3 + x^4)
553556
julia> q = convert(FactoredPolynomial, p) # noisy form of `factor`:
554557
FactoredPolynomial((x - 4.0000000000000036) * (x - 2.9999999999999942) * (x - 1.0000000000000002) * (x - 2.0000000000000018))
555558
556-
julia> map(round, q, digits=10)
559+
julia> map(x -> round(x, digits=10), q)
557560
FactoredPolynomial((x - 4.0) * (x - 2.0) * (x - 3.0) * (x - 1.0))
558561
```
559562

@@ -818,7 +821,7 @@ savefig("rational_function.svg"); nothing # hide
818821

819822
* [AbstractAlgebra.jl](https://github.com/wbhart/AbstractAlgebra.jl), [Nemo.jl](https://github.com/wbhart/Nemo.jl) for generic polynomial rings, matrix spaces, fraction fields, residue rings, power series, [Hecke.jl](https://github.com/thofma/Hecke.jl) for algebraic number theory.
820823

821-
* [LaurentPolynomials.jl](https://github.com/jmichel7/LaurentPolynomials.jl) A package for Laurent polynom
824+
* [LaurentPolynomials.jl](https://github.com/jmichel7/LaurentPolynomials.jl) A package for Laurent polynomials.
822825

823826
* [CommutativeAlgebra.jl](https://github.com/KlausC/CommutativeRings.jl) the start of a computer algebra system specialized to discrete calculations with support for polynomials.
824827

docs/src/reference.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ coeffs
1919
degree
2020
length
2121
size
22-
domain
22+
Polynomials.domain
2323
mapdomain
2424
chop
2525
chop!
@@ -105,10 +105,9 @@ chebs = [
105105
ChebyshevT([0, 0, 0, 0, 1]),
106106
]
107107
colors = ["#4063D8", "#389826", "#CB3C33", "#9558B2"]
108-
itr = zip(chebs, colors)
109-
(cheb,col), state = iterate(itr)
110-
p = plot(cheb, c=col, lw=5, legend=false, label="")
111-
for (cheb, col) in Base.Iterators.rest(itr, state)
108+
109+
p = plot(legend=false, label="")
110+
for (cheb, col) in zip(chebs, colors)
112111
plot!(cheb, c=col, lw=5)
113112
end
114113
savefig("chebs.svg"); nothing # hide

src/Polynomials.jl

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ module Polynomials
22

33
# using GenericLinearAlgebra ## remove for now. cf: https://github.com/JuliaLinearAlgebra/GenericLinearAlgebra.jl/pull/71#issuecomment-743928205
44
using LinearAlgebra
5-
using Intervals
6-
7-
if VERSION >= v"1.4.0"
8-
import Base: evalpoly
9-
end
5+
import Base: evalpoly
106

117
include("abstract.jl")
128
include("show.jl")
@@ -16,7 +12,6 @@ include("contrib.jl")
1612
# Interface for all AbstractPolynomials
1713
include("common.jl")
1814

19-
2015
# Polynomials
2116
include("polynomials/standard-basis.jl")
2217
include("polynomials/mutable-arithmetics.jl")
@@ -32,13 +27,11 @@ include("polynomials/multroot.jl")
3227
include("polynomials/ChebyshevT.jl")
3328

3429
# Rational functions
35-
if VERSION >= v"1.2.0"
36-
include("rational-functions/common.jl")
37-
include("rational-functions/rational-function.jl")
38-
include("rational-functions/fit.jl")
39-
#include("rational-transfer-function.jl")
40-
include("rational-functions/plot-recipes.jl")
41-
end
30+
include("rational-functions/common.jl")
31+
include("rational-functions/rational-function.jl")
32+
include("rational-functions/fit.jl")
33+
#include("rational-functions/rational-transfer-function.jl")
34+
include("rational-functions/plot-recipes.jl")
4235

4336

4437
# compat; opt-in with `using Polynomials.PolyCompat`

src/abstract.jl

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Var(x::Symbol) = Var{x}()
77
Symbol(::Var{T}) where {T} = T
88

99
const SymbolLike = Union{AbstractString,Char,Symbol, Var{T} where T}
10+
Base.Symbol(::Val{T}) where {T} = Symbol(T)
11+
1012

1113
"""
1214
AbstractPolynomial{T,X}
@@ -25,8 +27,8 @@ A polynomial type holds an indeterminate `X`; coefficients of type `T`, stored i
2527
Some `T`s will not be successful
2628
2729
* scalar mult: `c::Number * p::Polynomial` should be defined
28-
* scalar mult: `c::T * p:Polynomial{T}` An ambiguity when `T <: AbstractPolynomial`
29-
* scalar mult: `p:Polynomial{T} * c::T` need not commute
30+
* scalar mult: `c::T * p::Polynomial{T}` An ambiguity when `T <: AbstractPolynomial`
31+
* scalar mult: `p::Polynomial{T} * c::T` need not commute
3032
3133
* scalar add/sub: `p::Polynomial{T} + q::Polynomial{T}` should be defined
3234
* scalar sub: `p::Polynomial{T} - p::Polynomial{T}` generally needs `zeros(T,1)` defined for `zero(Polynomial{T})`
@@ -49,7 +51,7 @@ abstract type AbstractPolynomial{T,X} end
4951

5052

5153
## -----
52-
# We want ⟒(P{α…,T}) = P{α…}; this default
54+
# We want ⟒(P{α…,T,X}) = P{α…}; this default
5355
# works for most cases
5456
(P::Type{<:AbstractPolynomial}) = constructorof(P)
5557

@@ -87,27 +89,36 @@ macro register(name)
8789
Base.promote_rule(::Type{<:$poly{T,X}}, ::Type{<:$poly{S,X}}) where {T,S,X} = $poly{promote_type(T, S),X}
8890
Base.promote_rule(::Type{<:$poly{T,X}}, ::Type{S}) where {T,S<:Number,X} =
8991
$poly{promote_type(T, S),X}
90-
$poly(coeffs::AbstractVector{T}) where {T} =
91-
$poly{T, :x}(coeffs)
92-
$poly(coeffs::AbstractVector{T}, var::SymbolLike) where {T} =
92+
93+
$poly(coeffs::AbstractVector{T}, var::SymbolLike=Var(:x)) where {T} =
9394
$poly{T, Symbol(var)}(coeffs)
94-
$poly{T}(x::AbstractVector{S}, var::SymbolLike = :x) where {T,S} =
95+
$poly{T}(x::AbstractVector{S}, var::SymbolLike=Var(:x)) where {T,S} =
9596
$poly{T,Symbol(var)}(T.(x))
96-
function $poly(coeffs::G, var::SymbolLike=:x) where {G}
97+
98+
function $poly{T}(coeffs::G, var::SymbolLike=Var(x)) where {T,G}
99+
!Base.isiterable(G) && throw(ArgumentError("coeffs is not iterable"))
100+
cs = collect(T, coeffs)
101+
$poly{T, Symbol(var)}(cs)
102+
end
103+
function $poly(coeffs::G, var::SymbolLike=Var(:x)) where {G}
97104
!Base.isiterable(G) && throw(ArgumentError("coeffs is not iterable"))
98105
cs = collect(coeffs)
99106
$poly{eltype(cs), Symbol(var)}(cs)
100107
end
108+
101109
$poly{T,X}(c::AbstractPolynomial{S,Y}) where {T,X,S,Y} = convert($poly{T,X}, c)
102110
$poly{T}(c::AbstractPolynomial{S,Y}) where {T,S,Y} = convert($poly{T}, c)
103111
$poly(c::AbstractPolynomial{S,Y}) where {S,Y} = convert($poly, c)
112+
104113
$poly{T,X}(n::S) where {T, X, S<:Number} =
105114
T(n) * one($poly{T, X})
106-
$poly{T}(n::S, var::SymbolLike = :x) where {T, S<:Number} =
115+
$poly{T}(n::S, var::SymbolLike = Var(:x)) where {T, S<:Number} =
107116
T(n) * one($poly{T, Symbol(var)})
108-
$poly(n::S, var::SymbolLike = :x) where {S <: Number} = n * one($poly{S, Symbol(var)})
109-
$poly{T}(var::SymbolLike=:x) where {T} = variable($poly{T, Symbol(var)})
110-
$poly(var::SymbolLike=:x) = variable($poly, Symbol(var))
117+
$poly(n::S, var::SymbolLike = Var(:x)) where {S <: Number} = n * one($poly{S, Symbol(var)})
118+
119+
$poly{T}(var::SymbolLike=Var(:x)) where {T} = variable($poly{T, Symbol(var)})
120+
$poly(var::SymbolLike=Var(:x)) = variable($poly, Symbol(var))
121+
111122
(p::$poly)(x) = evalpoly(x, p)
112123
end
113124
end
@@ -125,21 +136,22 @@ macro registerN(name, params...)
125136
Base.promote_rule(::Type{<:$poly{$(αs...),T,X}}, ::Type{S}) where {$(αs...),T,X,S<:Number} =
126137
$poly{$(αs...),promote_type(T,S),X}
127138

128-
function $poly{$(αs...),T}(x::AbstractVector{S}, var::SymbolLike = :x) where {$(αs...),T,S}
139+
function $poly{$(αs...),T}(x::AbstractVector{S}, var::SymbolLike = Var(:x)) where {$(αs...),T,S}
129140
$poly{$(αs...),T,Symbol(var)}(T.(x))
130141
end
131-
$poly{$(αs...)}(coeffs::AbstractVector{T}, var::SymbolLike=:x) where {$(αs...),T} =
142+
$poly{$(αs...)}(coeffs::AbstractVector{T}, var::SymbolLike=Var(:x)) where {$(αs...),T} =
132143
$poly{$(αs...),T,Symbol(var)}(coeffs)
133144
$poly{$(αs...),T,X}(c::AbstractPolynomial{S,Y}) where {$(αs...),T,X,S,Y} = convert($poly{$(αs...),T,X}, c)
134145
$poly{$(αs...),T}(c::AbstractPolynomial{S,Y}) where {$(αs...),T,S,Y} = convert($poly{$(αs...),T}, c)
135146
$poly{$(αs...),}(c::AbstractPolynomial{S,Y}) where {$(αs...),S,Y} = convert($poly{$(αs...),}, c)
136147

137148
$poly{$(αs...),T,X}(n::Number) where {$(αs...),T,X} = T(n)*one($poly{$(αs...),T,X})
138-
$poly{$(αs...),T}(n::Number, var::SymbolLike = :x) where {$(αs...),T} = T(n)*one($poly{$(αs...),T,Symbol(var)})
139-
$poly{$(αs...)}(n::S, var::SymbolLike = :x) where {$(αs...), S<:Number} =
149+
$poly{$(αs...),T}(n::Number, var::SymbolLike = Var(:x)) where {$(αs...),T} = T(n)*one($poly{$(αs...),T,Symbol(var)})
150+
$poly{$(αs...)}(n::S, var::SymbolLike = Var(:x)) where {$(αs...), S<:Number} =
140151
n*one($poly{$(αs...),S,Symbol(var)})
141-
$poly{$(αs...),T}(var::SymbolLike=:x) where {$(αs...), T} = variable($poly{$(αs...),T,Symbol(var)})
142-
$poly{$(αs...)}(var::SymbolLike=:x) where {$(αs...)} = variable($poly{$(αs...)},Symbol(var))
152+
$poly{$(αs...),T}(var::SymbolLike=Var(:x)) where {$(αs...), T} =
153+
variable($poly{$(αs...),T,Symbol(var)})
154+
$poly{$(αs...)}(var::SymbolLike=Var(:x)) where {$(αs...)} = variable($poly{$(αs...)},Symbol(var))
143155
(p::$poly)(x) = evalpoly(x, p)
144156
end
145157
end

0 commit comments

Comments
 (0)