Class: Polynomial

Polynomial

Represents a Polynomial. Polynomials should be created using a factory method.

Constructor

new Polynomial(coefficients, field)

Init the polynomial, this method should not be used, use PolynomialFactory instead.
Parameters:
Name Type Description
coefficients array An array containing the polynomial coefficients, left is bigger.
field object The field used in this polynomial.
Source:
Example
// Example 1: Summing x + x

// Create first polynomial using the factory.
let p1 = pFactory.createClass([1, 0]);
// Create another polynomial.
let p2 = pFactory.createClass([1, 0]);
// Sum both polynomials
let sum = p1.add(p2);
// Get the coefficients from the sum.
let coefficients = sum.getCoefficients();
// Check everything went ok
assert.deepEqual(coefficients, [2, 0]);

Methods

add(poly)

Sum a polynomial of the monomial are required.
Parameters:
Name Type Description
poly object Other polynomial to add.
Source:

buildMonomial(degree, coefficient, field)

Build a monomial. A monomial is, roughly speaking, a polynomial which has only one term.
Parameters:
Name Type Description
degree number The degree of the monomial term.
coefficient number The coefficient of the monomial term.
field object The monomial's' field.
Source:

divide(poly)

Polynomial division. Note: The algorithm is explained here.
Parameters:
Name Type Description
poly object Other polynomial to substract.
Source:

evaluate(x)

Evaluate the a polynomial at a point x using Horner's method.
Parameters:
Name Type Description
x number The point where the polynomial is going to be evaluated.
Source:

getCoefficient(degree)

Return the coefficient with the given degree of the polynomial.
Parameters:
Name Type Description
degree number The degree of the desired coefficient.
Source:

getCoefficients()

Return the coefficients array of the polynomial.
Source:

getDegree()

Return the degree of the polynomial.
Source:

isZero()

Check if a polynomial is zero. Notice that a polynomial is zero when all the coefficients are zero.
Source:

multiply(other)

Multiply two polynomials or a polynomial and a scalar.
Parameters:
Name Type Description
other object The other polynomial to multiply.
Source:

multiplyByMonomial(degree, coefficient)

Multiply a polynomial by a monomial. This method builds the monomial "on the fly" so only the degree and the coefficients the field is assumed to be the same. of the monomial are required.
Parameters:
Name Type Description
degree number The degree of the monomial term.
coefficient number The coefficient of the monomial term.
Source:

multiplyPolynomial(polynomial)

Multiply two polynomials. This method runs a O(n^2) algorithm, maybe fast Fourier transform (FFT) can be used instead.
Parameters:
Name Type Description
polynomial object The polynomial to multiply.
Source:

multiplyScalar(scalar)

Multiply a polynomial and a scalar.
Parameters:
Name Type Description
scalar number The scalar to multiply.
Source:

sub(poly)

Polynomial substraction.
Parameters:
Name Type Description
poly object Other polynomial to substract.
Source: