Skip to content

Commit 4c99692

Browse files
authored
Merge pull request #179 from mileslucas/refactor
Abstracting Polynomials
2 parents 49cbdd8 + aaaa0b0 commit 4c99692

29 files changed

+3048
-1363
lines changed

.github/workflows/compat.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: CompatHelper
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *"
6+
7+
jobs:
8+
CompatHelper:
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
julia-version: [1.3.0]
13+
julia-arch: [x86]
14+
os: [ubuntu-latest]
15+
steps:
16+
- uses: julia-actions/setup-julia@latest
17+
with:
18+
version: ${{ matrix.julia-version }}
19+
- name: Pkg.add("CompatHelper")
20+
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
21+
- name: CompatHelper.main()
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
run: julia -e 'using CompatHelper; CompatHelper.main()'

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ matrix:
1919
notifications:
2020
email: false
2121

22-
coveralls: true
22+
codecov: true
2323

2424
jobs:
2525
include:

Project.toml

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

77
[deps]
8+
Intervals = "d8418881-c3e1-53bb-8760-2df7ec849ed5"
89
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
910
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
1011

1112
[compat]
12-
julia = "1.0"
13+
Intervals = "0.5.0"
1314
RecipesBase = "0.7, 0.8"
15+
julia = "1"
16+
1417

1518
[extras]
1619
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

README.md

Lines changed: 80 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,180 +1,167 @@
1-
# Polynomials
1+
# Polynomials.jl
22

33
Basic arithmetic, integration, differentiation, evaluation, and root finding over dense univariate polynomials.
44

5-
[![Polynomials](http://pkg.julialang.org/badges/Polynomials_0.6.svg)](http://pkg.julialang.org/?pkg=Polynomials)
6-
7-
Master branch:
5+
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaMath.github.io/Polynomials.jl/stable)
6+
[![](https://img.shields.io/badge/docs-latest-blue.svg)](https://JuliaMath.github.io/Polynomials.jl/dev)
87
[![Build Status](https://travis-ci.org/JuliaMath/Polynomials.jl.svg?branch=master)](https://travis-ci.org/JuliaMath/Polynomials.jl)
9-
[![Coverage Status](https://coveralls.io/repos/github/JuliaMath/Polynomials.jl/badge.svg)](https://coveralls.io/github/JuliaMath/Polynomials.jl)
8+
[![codecov](https://codecov.io/gh/JuliaMath/Polynomials.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaMath/Polynomials.jl)
109

11-
Documentation:
12-
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaMath.github.io/Polynomials.jl/stable)
13-
[![](https://img.shields.io/badge/docs-latest-blue.svg)](https://JuliaMath.github.io/Polynomials.jl/latest)
1410

15-
#### Poly(a::Vector) where {T<:Number}
11+
## Installation
12+
13+
```julia
14+
(v1.2) pkg> add Polynomials
15+
16+
julia> using Polynomials
17+
```
18+
19+
## Usage
20+
21+
#### Available Polynomials
22+
23+
* `Polynomial` - Standard polynomials
24+
* `ChebyshevT` - Chebyshev polynomials of the first kind
25+
26+
#### Construction and Evaluation
1627

1728
Construct a polynomial from its coefficients, lowest order first.
1829

1930
```julia
20-
julia> Poly([1,0,3,4])
21-
Poly(1 + 3x^2 + 4x^3)
31+
julia> Polynomial([1,0,3,4])
32+
Polynomial(1 + 3x^2 + 4x^3)
2233
```
2334

2435
An optional variable parameter can be added.
2536

2637
```julia
27-
julia> Poly([1,2,3], :s)
28-
Poly(1 + 2s + 3s^2)
38+
julia> Polynomial([1,2,3], :s)
39+
Polynomial(1 + 2s + 3s^2)
2940
```
3041

31-
#### poly(r::AbstractVector)
42+
Construct a polynomial from its roots.
3243

33-
Construct a polynomial from its roots. This is in contrast to the
34-
`Poly` constructor, which constructs a polynomial from its
35-
coefficients.
44+
```julia
45+
julia> fromroots([1,2,3]) # (x-1)*(x-2)*(x-3)
46+
Polynomial(-6 + 11x - 6x^2 + x^3)
47+
```
48+
49+
Evaluate the polynomial `p` at `x`.
3650

3751
```julia
38-
// Represents (x-1)*(x-2)*(x-3)
39-
julia> poly([1,2,3])
40-
Poly(-6 + 11x - 6x^2 + x^3)
52+
julia> p = Polynomial([1, 0, -1])
53+
julia> p(0.1)
54+
0.99
4155
```
4256

43-
#### +, -, *, /, div, ==
57+
#### Arithmetic
4458

4559
The usual arithmetic operators are overloaded to work on polynomials, and combinations of polynomials and scalars.
60+
4661
```julia
47-
julia> p = Poly([1,2])
48-
Poly(1 + 2x)
62+
julia> p = Polynomial([1,2])
63+
Polynomial(1 + 2x)
4964

50-
julia> q = Poly([1, 0, -1])
51-
Poly(1 - x^2)
65+
julia> q = Polynomial([1, 0, -1])
66+
Polynomial(1 - x^2)
5267

5368
julia> 2p
54-
Poly(2 + 4x)
69+
Polynomial(2 + 4x)
5570

5671
julia> 2+p
57-
Poly(3 + 2x)
72+
Polynomial(3 + 2x)
5873

5974
julia> p - q
6075
Poly(2x + x^2)
6176

6277
julia> p * q
63-
Poly(1 + 2x - x^2 - 2x^3)
78+
Polynomial(1 + 2x - x^2 - 2x^3)
6479

6580
julia> q / 2
66-
Poly(0.5 - 0.5x^2)
81+
Polynomial(0.5 - 0.5x^2)
6782

68-
julia> q ÷ p # `div`, also `rem` and `divrem`
69-
Poly(0.25 - 0.5x)
83+
julia> q ÷ p # `div`, also `rem` and `divrem`
84+
Polynomial(0.25 - 0.5x)
7085
```
7186

7287
Note that operations involving polynomials with different variables will error.
7388

7489
```julia
75-
julia> p = Poly([1, 2, 3], :x)
76-
julia> q = Poly([1, 2, 3], :s)
90+
julia> p = Polynomial([1, 2, 3], :x)
91+
julia> q = Polynomial([1, 2, 3], :s)
7792
julia> p + q
7893
ERROR: Polynomials must have same variable.
7994
```
8095

81-
To get the degree of the polynomial use the `degree` method
82-
83-
```
84-
julia> degree(p)
85-
2
86-
87-
julia> degree(p^2)
88-
4
89-
90-
julia> degree(p-p)
91-
-1
92-
```
93-
94-
#### polyval(p::Poly, x::Number)
95-
96-
Evaluate the polynomial `p` at `x`.
97-
98-
```julia
99-
julia> p = Poly([1, 0, -1])
100-
julia> polyval(p, 0.1)
101-
0.99
102-
```
103-
104-
A call method is also available:
105-
106-
```julia
107-
julia> p(0.1)
108-
0.99
109-
```
110-
111-
112-
#### polyint(p::Poly, k::Number=0)
96+
#### Integrals and Derivatives
11397

11498
Integrate the polynomial `p` term by term, optionally adding constant
11599
term `k`. The order of the resulting polynomial is one higher than the
116100
order of `p`.
117101

118102
```julia
119-
julia> polyint(Poly([1, 0, -1]))
120-
Poly(x - 0.3333333333333333x^3)
103+
julia> integrate(Polynomial([1, 0, -1]))
104+
Polynomial(x - 0.3333333333333333x^3)
121105

122-
julia> polyint(Poly([1, 0, -1]), 2)
123-
Poly(2.0 + x - 0.3333333333333333x^3)
106+
julia> integrate(Polynomial([1, 0, -1]), 2)
107+
Polynomial(2.0 + x - 0.3333333333333333x^3)
124108
```
125109

126-
#### polyder(p::Poly)
127-
128110
Differentiate the polynomial `p` term by term. The order of the
129111
resulting polynomial is one lower than the order of `p`.
130112

131113
```julia
132-
julia> polyder(Poly([1, 3, -1]))
133-
Poly(3 - 2x)
114+
julia> derivative(Polynomial([1, 3, -1]))
115+
Polynomial(3 - 2x)
134116
```
135117

136-
#### roots(p::Poly)
118+
#### Root-finding
119+
137120

138121
Return the roots (zeros) of `p`, with multiplicity. The number of
139122
roots returned is equal to the order of `p`. By design, this is not type-stable,
140123
the returned roots may be real or complex.
141124

142125
```julia
143-
julia> roots(Poly([1, 0, -1]))
126+
julia> roots(Polynomial([1, 0, -1]))
144127
2-element Array{Float64,1}:
145128
-1.0
146129
1.0
147130

148-
julia> roots(Poly([1, 0, 1]))
131+
julia> roots(Polynomial([1, 0, 1]))
149132
2-element Array{Complex{Float64},1}:
150133
0.0+1.0im
151134
0.0-1.0im
152135

153-
julia> roots(Poly([0, 0, 1]))
136+
julia> roots(Polynomial([0, 0, 1]))
154137
2-element Array{Float64,1}:
155138
0.0
156139
0.0
157140
```
158141

159-
#### polyfit(x, y, n=length(x)-1)
142+
#### Fitting arbitrary data
160143

161-
* `polyfit`: fits a polynomial (of order `n`) to `x` and `y` using a least-squares approximation.
144+
Fit a polynomial (of order `deg`) to `x` and `y` using a least-squares approximation.
162145

163146
```julia
164-
julia> xs = 1:4; ys = exp.(xs); polyfit(xs, ys)
165-
Poly(-7.717211620141281 + 17.9146616149694x - 9.77757245502143x^2 + 2.298404288652356x^3)
147+
julia> xs = 0:4; ys = @. exp(-xs) + sin(xs);
148+
149+
julia> fit(xs, ys)
150+
Polynomial(1.0000000000000016 + 0.059334723072240664*x + 0.39589720602859824*x^2 - 0.2845598112184312*x^3 + 0.03867830809692903*x^4)
151+
152+
julia> fit(ChebyshevT, xs, ys, deg=2)
153+
ChebyshevT([0.541280671210034, -0.8990834124779993, -0.4237852336242923])
166154
```
167155

168156
Visual example:
169157

170-
![newplot 42](https://user-images.githubusercontent.com/3156114/41799777-9ba00582-7627-11e8-94ef-15297ec8790e.png)
158+
![fit example](https://user-images.githubusercontent.com/14099459/70382587-9e055500-1902-11ea-8952-3f03ae08b7dc.png)
171159

172160
#### Other methods
173161

174162
Polynomial objects also have other methods:
175163

176-
* 0-based indexing is used to extract the coefficients of $a_0 + a_1
177-
x + a_2 x^2 + ...$, coefficients may be changed using indexing
164+
* 0-based indexing is used to extract the coefficients of `[a0, a1, a2, ...]`, coefficients may be changed using indexing
178165
notation.
179166

180167
* `coeffs`: returns the entire coefficient vector
@@ -187,18 +174,16 @@ Polynomial objects also have other methods:
187174

188175
* `conj`: finds the conjugate of a polynomial over a complex fiel
189176

190-
* `truncate`: set to 0 all small terms in a polynomial; `chop` chops off
191-
any small leading values that may arise due to floating point
192-
operations.
177+
* `truncate`: set to 0 all small terms in a polynomial;
178+
* `chop` chops off any small leading values that may arise due to floating point operations.
193179

194180
* `gcd`: greatest common divisor of two polynomials.
195181

196182
* `Pade`: Return the
197-
[Pade approximant](https://en.wikipedia.org/wiki/Pad%C3%A9_approximant)
198-
of order `m/n` for a polynomial as a `Pade` object.
183+
[Pade approximant](https://en.wikipedia.org/wiki/Pad%C3%A9_approximant) of order `m/n` for a polynomial as a `Pade` object.
199184

200185

201-
## See also
186+
## Related Packages
202187

203188
* [MultiPoly.jl](https://github.com/daviddelaat/MultiPoly.jl) for sparse multivariate polynomials
204189

@@ -207,3 +192,8 @@ Polynomial objects also have other methods:
207192
* [Nemo.jl](https://github.com/wbhart/Nemo.jl) for generic polynomial rings, matrix spaces, fraction fields, residue rings, power series
208193

209194
* [PolynomialRoots.jl](https://github.com/giordano/PolynomialRoots.jl) for a fast complex polynomial root finder
195+
196+
197+
## Contributing
198+
199+
If you are interested in contributing, feel free to open an issue or pull request to get started.

docs/Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
4+
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
35

46
[compat]
5-
Documenter = "0.23.3"
7+
Documenter = "0.24"

docs/make.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
using Documenter, Polynomials
1+
using Documenter
2+
using Polynomials
23

3-
DocMeta.setdocmeta!(Polynomials, :DocTestSetup, :(using Polynomials); recursive=true)
4+
DocMeta.setdocmeta!(Polynomials, :DocTestSetup, :(using Polynomials); recursive = true)
45

5-
makedocs(modules = [Polynomials],
6+
makedocs(
7+
modules = [Polynomials],
68
format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true"),
79
sitename = "Polynomials.jl",
810
authors = "Jameson Nash, Keno Fischer, and other contributors",
911
pages = [
10-
"Manual" => "index.md",
12+
"Home" => "index.md",
13+
"Reference/API" => "reference.md",
14+
"Polynomial Types" => [
15+
"Polynomial" => "polynomials/polynomial.md",
16+
"Chebyshev" => "polynomials/chebyshev.md",
17+
],
18+
"Extending" => "extending.md",
1119
],
1220
)
1321

0 commit comments

Comments
 (0)