Polynomial¶
This file contains the Polynomial class, created to quick and easy access to polynomials.
- class fft.polynomial.Polynomial(_list: list)¶
This class represents polynomials as a list of coefficients.
- Example
import fft.Polynomial as Poly # f(x) = 1 + 2x + xx f = Poly([1, 2, 1]) # The f is callable and will evaluate the polynomial at the input value. f(3) -> 16.
- degreeint
The largest power the variable is raised to in the polynomial.
- add(polynomial_1list, polynomial_2list)list
Adds two polynomials and returns the result.
- adjust(polynomial_1list, polynomial_2list)list
Adds a buffer so that the two lists representing the polynomials are the same size.
- are_equal(polynomial_1list, polynomial_2list)bool
Compares the two input polynomials to check if they are the same.
- static add(polynomial_1: list, polynomial_2: list) list ¶
Adds together two input polynomials and returns the result.
- Example
# (1 + 2x) + (3 + 2x + 5xx) = 4 + 4x + 5xx Poly.add([1, 2], [3, 2, 5]) -> [4, 4, 5]
- Returns
The sum of the two polynomials.
- static adjust(polynomial_1: list, polynomial_2: list) tuple ¶
Insures that polynomials are the same size by adding zeros as buffer.
This function is useful for the add method.
- Returns
The two polynomials adjusted to have the same size.
- static are_equal(polynomial_1: list, polynomial_2: list) bool ¶
Checks if two polynomials are equal.
- Returns
Returns true if the polynomials are equal and false otherwise.
- evens()¶
This returns a polynomial whose coefficients correspond to the even powers of x of the polynomial it is run on.
- horners_rule(x: complex) complex ¶
Evaluates this polynomial using Horner’s Rule.
Horner’s Rule allows polynomials to be evaluated in linear time, whereas evaluating term by term would have a polynomial time complexity.
- Parameters
x – Input to the polynomial.
- Returns
The polynomial evaluated at the input.
- odds()¶
This returns a polynomial whose coefficients correspond to the run powers of x of the polynomial it is run on.
- strip_zeros() list ¶
Removes any terms with coefficient zero from the end of the polynomial.
- Returns
The polynomial as a list without trailing zeros.
- static strip_zeros_l(polynomials: list) list ¶
Strips zeros from a list of polynomials.
- Parameters
polynomials – A list of polynomials.
- Returns
The same polynomials with trailing terms with trailing zeros removed.