TrigPolys

TrigPolys.jl is a package for fast manipulation of trigonometric polynomials.

A trignometric polynomial is defined on $x \in [0,2\pi)$ by

\[p(x) = a_0 + \sum_{k=1}^n a_k \cos(kx) + a_{-k} \sin(kx)\]

The polynomial $p(x)$ can be represented either by $2n+1$ coefficients $a_k$ or by evaluations at $2n+1$ distinct points in the interval $[0,2\pi)$. Each representation is useful in different situations: the coefficient representation is useful for truncating or increasing the degree of a polynomial whereas the evaluation representation is useful for adding and multiplying polynomials.

This package provides the functions evaluate and interpolate to convert efficiently between these two representations. These operations are implemented via the Fast Fourier Transform (FFT) provided by the FFTW.jl library.

For example, multiplying two trigonometric polynomials is implemented with the following code:

function Base.:*(p1::TrigPoly, p2::TrigPoly)
    n = p1.n + p2.n
    interpolate(evaluate(pad_to(p1, n)) .* evaluate(pad_to(p2, n)))
end

Construction and Convertion

TrigPolys.TrigPolyType
struct TrigPoly{T<:AbstractFloat, VT<:AbstractVector{T}}
    a0::T    # Constant coefficient
    ac::VT   # cos coefficients
    as::VT   # sin coefficients
end

Represents a trigonometric polynomial by its coefficients.

source
TrigPolys.TrigPolyMethod
TrigPoly(u::AbstractVector{T}) where {T<:AbstractFloat}

Constructs a TrigPoly given a vector of coefficients of length 2n+1. The first entry of u is a0, the next n entries are ac and the last n entries are as.

source
TrigPolys.a0Function
a0(p::TrigPoly)

Equivalent to p.a0, used for incorporation into automatic differentiation libraries.

source
TrigPolys.acFunction
ac(p::TrigPoly)

Equivalent to p.ac, used for incorporation into automatic differentiation libraries.

source
TrigPolys.asFunction
as(p::TrigPoly)

Equivalent to p.as, used for incorporation into automatic differentiation libraries.

source
TrigPolys.nFunction
n(p::TrigPoly)

Equivalent to p.n. Returns the length of cosine/sine coefficients, which is length(p.ac) == length(p.as).

source
TrigPolys.degreeFunction
degree(p::TrigPoly)

Returns the number of coefficients of p, which is 2*p.n + 1.

source

Methods

Base.:==Method
Base.:(==)(p1::TrigPoly, p2::TrigPoly)

Returns true if the coefficients of p1 and p2 are all equal.

source
Base.:+Method
Base.:+(p1::TrigPoly, p2::TrigPoly)

Adds p1 to p2. The degree of the resulting polynomial will be the maximum degree of p1 and p2: (p1 + p2).n == max(p1.n, p2.n)

source
Base.:*Method
Base.:*(p1::TrigPoly, p2::TrigPoly)

Multiplies p1 and p2. The degree of the resulting polynomial will be the sum of degrees of p1 and p2: (p1 * p2).n == p1.n + p2.n

source
Base.:/Method
Base.:/(p::TrigPoly, a::Number)

Divides p by a scalar.

source

Functions

TrigPolys.pad_toFunction
pad_to(p::TrigPoly{T,VT}, n::Integer) where {T<:AbstractFloat, VT<:AbstractVector{T}}

Increase the length of p.ac and p.as to n, padding with zeros if necessary. n cannot be smaller than p.n.

source
TrigPolys.pad_byFunction
pad_by(p::TrigPoly, n::Integer)

Increase the length of p.ac and p.as by n, padding with n zeros.

source
TrigPolys.basisFunction
basis(n, x)

Generate the basis for TrigPoly expressed as a vector, so that basis(p.n, x)'*vec(p) = p(x).

source
TrigPolys.evaluateFunction
evaluate(u::AbstractVector)

Evaluates an array representation of p::TrigPoly, returned by vec(p).

source
evaluate(p::TrigPoly)

Evaluates p on degree(p) uniformly-spaced points on the circle. See here for more details.

source
TrigPolys.evaluateTFunction
evaluateT(u::AbstractVector)

Adjoint of evaluate operator on an array representation of p::TrigPoly , returned by vec(p).

source
evaluateT(p::TrigPoly)

Adjoint of evaluate operator. Returns a vector.

source