java.lang.Object
com.google.zxing.common.reedsolomon.GenericGFPoly
Represents a polynomial whose coefficients are elements of a GF. Instances of this class are immutable.
Much credit is due to William Rucklidge since portions of this code are an indirect port of his C++ Reed-Solomon implementation.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int[]Coefficients, highest power first, with no leading zeroesprivate final GenericGFThe Galois field the coefficients are arithmetic in.Constructor Summary
ConstructorsConstructorDescriptionGenericGFPoly(GenericGF field, int[] coefficients) Builds a polynomial over a given field, in the standard form.Method Summary
Public MethodsModifier and TypeMethodDescription(package private) GenericGFPolyaddOrSubtract(GenericGFPoly other) Add or subtract another polynomial.(package private) GenericGFPoly[]divide(GenericGFPoly other) Divides by another polynomial, yielding quotient and remainder.(package private) intevaluateAt(int a) Evaluate this polynomial at a value.(package private) intgetCoefficient(int degree) Get the coefficient.(package private) int[]Get the coefficients.(package private) intGet the degree.(package private) booleanisZero()Whether zero.(package private) GenericGFPolymultiply(int scalar) Multiplies every coefficient by a field element.(package private) GenericGFPolymultiply(GenericGFPoly other) Multiplies by another polynomial over the same field.(package private) GenericGFPolymultiplyByMonomial(int degree, int coefficient) Multiply by a monomial term.toString()
Field Details
field
The Galois field the coefficients are arithmetic in.coefficients
private final int[] coefficientsCoefficients, highest power first, with no leading zeroes
Constructor Details
GenericGFPoly
GenericGFPoly(GenericGF field, int[] coefficients) Builds a polynomial over a given field, in the standard form.- Parameters:
field- theGenericGFinstance representing the field to use to perform computationscoefficients- coefficients as ints representing elements of GF(size), arranged from most significant (highest-power term) coefficient to least significant- Throws:
IllegalArgumentException- if argument is null or empty, or if leading coefficient is 0 and this is not a constant polynomial (that is, it is not the monomial "0")
Method Details
getCoefficients
int[] getCoefficients()Get the coefficients.- Returns:
- the coefficients, highest power of x first, so element 0 multiplies x^0
getDegree
int getDegree()Get the degree.- Returns:
- degree of this polynomial
isZero
boolean isZero()Whether zero.- Returns:
- true iff this polynomial is the monomial "0"
getCoefficient
int getCoefficient(int degree) Get the coefficient.- Parameters:
degree- the power of x whose coefficient is wanted- Returns:
- coefficient of x^degree term in this polynomial
evaluateAt
int evaluateAt(int a) Evaluate this polynomial at a value.- Parameters:
a- the field element at which to evaluate- Returns:
- evaluation of this polynomial at a given point
addOrSubtract
Add or subtract another polynomial.- Parameters:
other- the polynomial to add, which must be over the same field- Returns:
- the field sum if the field is characteristic two, the difference otherwise
multiply
Multiplies by another polynomial over the same field.- Parameters:
other- the polynomial to multiply by, which must be over the same field- Returns:
- a new polynomial holding the product
multiply
Multiplies every coefficient by a field element.- Parameters:
scalar- the field element to multiply every coefficient by- Returns:
- a new polynomial holding the scaled coefficients
multiplyByMonomial
Multiply by a monomial term.- Parameters:
degree- the power of x to multiply by, which must not be negativecoefficient- the field element scaling each existing coefficient- Returns:
- a new polynomial shifted up by degree and scaled by coefficient
divide
Divides by another polynomial, yielding quotient and remainder.- Parameters:
other- the polynomial to divide by, which must be non-zero and over the same field- Returns:
- a two-element array holding the quotient and the remainder
toString