# Extending Polynomials

The AbstractPolynomial type was made to be extended via a rich interface.

Polynomials.AbstractPolynomialType
AbstractPolynomial{T}

An abstract container for various polynomials.

Properties

• coeffs - The coefficients of the polynomial
• var - The indeterminate of the polynomial
source

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.

To implement a new polynomial type, P, the following methods should be implemented.

Note

Promotion rules will always coerce towards the Polynomial type, so not all methods have to be implemented if you provide a conversion function.

As always, if the default implementation does not work or there are more efficient ways of implementing, feel free to overwrite functions from common.jl for your type.

FunctionRequiredNotes
Constructorx
Type function ((::P)(x))x
convert(::Polynomial, ...)Not required, but the library is built off the Polynomial type, so all operations are guaranteed to work with it. Also consider writing the inverse conversion method.
domainxShould return an AbstractInterval
vanderRequired for fit
companionRequired for roots
fromrootsBy default, will form polynomials using prod(variable(::P) - r) for reach root r
+(::P, ::P)Addition of polynomials
-(::P, ::P)Subtraction of polynomials
*(::P, ::P)Multiplication of polynomials
divremRequired for gcd
variableConvenience to find monomial x in new basis

Check out both the Polynomial and ChebyshevT for examples of this interface being extended.