You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/src/extending.md
+7-3
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,15 @@
1
1
# Extending Polynomials
2
2
3
-
The [`AbstractPolynomial`](@ref) type was made to be extended via a rich interface.
3
+
The [`AbstractPolynomial`](@ref) type was made to be extended via a rich interface.
4
4
5
5
```@docs
6
6
AbstractPolynomial
7
7
```
8
8
9
-
To implement a new polynomial type, `P`, the following methods should be implemented.
9
+
A polynomial's coefficients are relative to some *basis*. The `Polynomial` type relates coefficients `[a0, a1, ..., an]`, say, to the polynomial `a0 + a1*x + a2*x^ + ... + an*x^n`, through the standard basis `1, x, x^2, ..., x^n`. New polynomial types typically represent the polynomial through a different basis. For example, `CheyshevT` uses a basis `T_0=1, T_1=x, T_2=2x^2-1, ..., T_n = 2xT_{n-1} - T_{n-2}`. For this type the coefficients `[a0,a1,...,an]` are associated with the polynomial `a0*T0 + a1*T_1 + ... + an*T_n`.
10
+
11
+
To implement a new polynomial type, `P`, the following methods should
12
+
be implemented.
10
13
11
14
!!! note
12
15
Promotion rules will always coerce towards the [`Polynomial`](@ref) type, so not all methods have to be implemented if you provide a conversion function.
@@ -26,5 +29,6 @@ As always, if the default implementation does not work or there are more efficie
26
29
|`-(::P, ::P)`|| Subtraction of polynomials |
27
30
|`*(::P, ::P)`|| Multiplication of polynomials |
28
31
|`divrem`|| Required for [`gcd`](@ref)|
32
+
|`variable`|| Convenience to find monomial `x` in new basis|
29
33
30
-
Check out both the [`Polynomial`](@ref) and [`ChebyshevT`](@ref) for examples of this interface being extended!
34
+
Check out both the [`Polynomial`](@ref) and [`ChebyshevT`](@ref) for examples of this interface being extended.
A polynomial, e.g. `a_0 + a_1 x + a_2 x^2 + ... + a_n x^n`, can be seen as a collection of coefficients, `[a_0, a_1, ..., a_n]`, relative to some polynomial basis. The most familiar basis being the standard one: `1`, `x`, `x^2`, ... Alternative bases are possible. The `ChebyshevT` polynomials are implemented, as an example. Instead of `Polynomial` or `Polynomial{T}`, `ChebyshevT` or `ChebyshevT{T}` constructors are used:
If its basis is implicit, then a polynomial may be seen as just a vector of coefficients. Vectors or 1-based, but, for convenience, polynomial types are 0-based, for purposes of indexing (e.g. `getindex`, `setindex!`, `eachindex`). Iteration over a polynomial steps through the basis vectors, e.g. `a_0`, `a_1*x`, ...
200
+
201
+
```jldoctest
202
+
julia> as = [1,2,3,4,5]; p = Polynomial(as);
203
+
204
+
julia> as[3], p[2], collect(p)[3]
205
+
(3, 3, Polynomial(3*x^2))
206
+
```
166
207
167
208
## Related Packages
168
209
169
210
*[MultiPoly.jl](https://github.com/daviddelaat/MultiPoly.jl) for sparse multivariate polynomials
170
211
171
212
*[MultivariatePolynomials.jl](https://github.com/blegat/MultivariatePolynomials.jl) for multivariate polynomials and moments of commutative or non-commutative variables
172
213
173
-
*[Nemo.jl](https://github.com/wbhart/Nemo.jl) for generic polynomial rings, matrix spaces, fraction fields, residue rings, power series
214
+
*[AbstractAlgeebra.jl](https://github.com/wbhart/AbstractAlgebra.jl) for generic polynomial rings, matrix spaces, fraction fields, residue rings, power series.
174
215
175
216
*[PolynomialRoots.jl](https://github.com/giordano/PolynomialRoots.jl) for a fast complex polynomial root finder
Copy file name to clipboardexpand all lines: docs/src/polynomials/chebyshev.md
+12-2
Original file line number
Diff line number
Diff line change
@@ -6,24 +6,34 @@ DocTestSetup = quote
6
6
end
7
7
```
8
8
9
+
10
+
The [Chebyshev polynomials](https://en.wikipedia.org/wiki/Chebyshev_polynomials) are two sequences of polynomials, `T_n` and `U_n`. The Chebyshev polynomials of the first kind, `T_n`, can be defined by the recurrence relation `T_0(x)=1`, `T_1(x)=x`, and `T_{n+1}(x) = 2xT_n{x}-T_{n-1}(x)`. The Chebyshev polynomioals of the second kind, `U_n(x)`, can be defined by `U_0(x)=1`, `U_1(x)=2x`, and `U_{n+1}(x) = 2xU_n(x) - U_{n-1}(x)`. Both `T_n` and `U_n` have degree `n`, and any polynomial of degree `n` may be uniquely written as a linear combination of the polynomials `T_0`, `T_1`, ..., `T_n` (similarly with `U`).
11
+
12
+
9
13
## First Kind
10
14
11
15
```@docs
12
16
ChebyshevT
13
17
ChebyshevT()
14
18
```
15
19
20
+
The `ChebyshevT` type holds coefficients representing the polynomial `a_0 T_0 + a_1 T_1 + ... + a_n T_n`.
21
+
22
+
For example, the basis polynomial `T_4` can be represented with `ChebyshevT([0,0,0,0,1])`.
23
+
24
+
16
25
### Conversion
17
26
18
27
[`ChebyshevT`](@ref) can be converted to [`Polynomial`](@ref) and vice-versa.
0 commit comments