public class PolynomialRing.Polynomial extends java.lang.Object implements RingElement
PolynomialRing.| Modifier and Type | Field and Description |
|---|---|
protected RingElement[] |
coefficients
Coefficients of this polynomial, i.e.
|
protected int |
degree
The degree of this polynomial.
|
| Constructor and Description |
|---|
Polynomial(int i)
Creates the polynomial \(X^i\).
|
Polynomial(int i,
RingElement a)
Creates the polynomial \(a \cdot X^i\).
|
Polynomial(java.util.List<RingElement> coefficients)
Creates a polynomial with the given coefficients.
|
Polynomial(RingElement... coefficients)
Creates a polynomial with the given coefficients.
|
| Modifier and Type | Method and Description |
|---|---|
PolynomialRing.Polynomial |
add(Element e)
Creates a new polynomial by adding the given polynomial to this.
|
java.math.BigInteger |
asInteger()
Interprets this element as an integer.
|
protected void |
computeDegree()
Sets the degree instance variable according to the coefficients.
|
boolean |
divides(RingElement e)
Checks whether this polynomial can be divided without remainder by the given polynomial.
|
PolynomialRing.Polynomial[] |
divideWithRemainder(RingElement e)
Performs polynomial division with remainder.
|
protected void |
ensureArrayNonNull()
Makes sure that the coefficients array does not contain null values at indices
i <= degree. |
boolean |
equals(java.lang.Object o) |
RingElement |
evaluate(Element x)
Return the value of the polynomial evaluated at
x. |
RingElement[] |
getCoefficients() |
RingElementVector |
getCoefficientVector() |
int |
getDegree() |
java.math.BigInteger |
getRank()
Implements the euclidean function of a euclidean domain.
|
Representation |
getRepresentation()
The representation of this object.
|
PolynomialRing |
getStructure()
Returns the
Structure that this Element belongs to. |
int |
hashCode() |
Zp.ZpElement |
innerProduct(PolynomialRing.Polynomial e)
Computes the inner product of the coefficient vectors.
|
PolynomialRing.Polynomial |
inv()
Inverts the constant polynomial by inverting the zero degree coefficient in its corresponding ring.
|
PolynomialRing.Polynomial |
mul(java.math.BigInteger k)
Multiplies each coefficient with the given integer.
|
PolynomialRing.Polynomial |
mul(Element e)
Multiplies the given polynomial with this using standard polynomial multiplication.
|
PolynomialRing.Polynomial |
neg()
Negates the polynomial by negating each coefficient.
|
PolynomialRing.Polynomial |
normalize()
Normalizes this polynomial by multiplying it with the inverse of the leading coefficient.
|
PolynomialRing.Polynomial |
scalarMul(Element elem)
Multiplies each coefficient of this polynomial with the given base ring element.
|
PolynomialRing.Polynomial |
sub(Element e)
Creates a new polynomial by subtracting the given polynomial from this.
|
java.lang.String |
toString() |
ByteAccumulator |
updateAccumulator(ByteAccumulator accumulator)
Updates the ByteAccumulator with the unique byte representation of this object.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitdiv, isOne, isUnit, isZero, mul, pow, pow, square, toAdditiveGroupElement, toUnitGroupElementgetUniqueByteRepresentationprotected RingElement[] coefficients
All entries with index i > degree may be null.
This array always contains at least one element.
protected int degree
public Polynomial(RingElement... coefficients)
For example, new Polynomial(1,2,3) returns \(1 + 2 \cdot X + 3 \cdot X^2\).
coefficients - coefficients for the new polynomial, in order from smallest to largest exponentpublic Polynomial(java.util.List<RingElement> coefficients)
For example, new Polynomial([1,2,3]) returns \(1 + 2 \cdot X + 3 \cdot X^2\).
coefficients - coefficients for the new polynomial, in order from smallest to largest exponentspublic Polynomial(int i,
RingElement a)
public Polynomial(int i)
public RingElement[] getCoefficients()
public RingElementVector getCoefficientVector()
protected void computeDegree()
This is done once when creating the polynomial.
protected void ensureArrayNonNull()
i <= degree.java.lang.IllegalArgumentException - if any coefficient of the polynomial is nullpublic Representation getRepresentation()
RepresentableReprUtilgetRepresentation in interface RepresentableRepresentationpublic PolynomialRing getStructure()
ElementStructure that this Element belongs to.getStructure in interface ElementgetStructure in interface RingElementpublic RingElement evaluate(Element x)
x.
Result is computes using the Horner scheme.
x - position to evaluatexpublic PolynomialRing.Polynomial add(Element e)
Addition is done by adding the coefficients together. Degree of the resulting polynomial is the maximum degree of the two involved polynomials.
add in interface RingElemente - the addendpublic PolynomialRing.Polynomial neg()
neg in interface RingElementpublic Zp.ZpElement innerProduct(PolynomialRing.Polynomial e)
public PolynomialRing.Polynomial sub(Element e)
Subtraction is done by subtracting the coefficients of the given polynomial from this. Degree of the resulting polynomial is the maximum degree of the two involved polynomials.
sub in interface RingElemente - the polynomial to subtractpublic PolynomialRing.Polynomial mul(Element e)
mul in interface RingElemente - the factorpublic PolynomialRing.Polynomial mul(java.math.BigInteger k)
mul in interface RingElementk - the factorpublic PolynomialRing.Polynomial inv() throws java.lang.UnsupportedOperationException
Does not work for polynomial of higher degree.
inv in interface RingElementjava.lang.UnsupportedOperationException - if the degree of the polynomial to invert is greater than zeropublic PolynomialRing.Polynomial scalarMul(Element elem)
public PolynomialRing.Polynomial normalize() throws java.lang.UnsupportedOperationException
Results in a polynomial with coefficient one for the highest (leading) coefficient.
java.lang.UnsupportedOperationException - if the highest coefficient is not a unit, i.e. cannot be factored outpublic boolean divides(RingElement e) throws java.lang.UnsupportedOperationException
divides in interface RingElemente - the divisorjava.lang.UnsupportedOperationException - if the divisors leading coefficient cannot be invertedpublic PolynomialRing.Polynomial[] divideWithRemainder(RingElement e) throws java.lang.UnsupportedOperationException
divideWithRemainder in interface RingElemente - the divisorPolynomial array containing the quotient and remainder, in that orderjava.lang.UnsupportedOperationException - if the divisors leading coefficient cannot be invertedpublic java.math.BigInteger asInteger()
throws java.lang.UnsupportedOperationException
RingElementResult will be between 0 and the ring's characteristic.
Formally, this method shall return the inverse of Ring.getElement(BigInteger), i.e.
x.getStructure().getElement(x.asInteger()).equals(x) (if asInteger() doesn't throw an exception).
asInteger in interface RingElementjava.lang.UnsupportedOperationException - if no such element exists or cannot be efficiently computedpublic java.math.BigInteger getRank()
throws java.lang.UnsupportedOperationException
RingElementThe euclidean function is a function from \(R \setminus \{0\}\) to \(\mathbb{N}_0\) such that
a.getRank() >= 0 for any a in the ring
a.mul(b).getRank() >= a.getRank() for any a, b != 0
divideWithRemainder is less than the divisor's rank
The rank of the zero element is undefined (no guarantee as to what this method returns in that case).
getRank in interface RingElementjava.lang.UnsupportedOperationException - if the ring is not a euclidean domainpublic int getDegree()
public boolean equals(java.lang.Object o)
public int hashCode()
public java.lang.String toString()
toString in class java.lang.Objectpublic ByteAccumulator updateAccumulator(ByteAccumulator accumulator)
UniqueByteRepresentableThe input to the accumulators update function is an injective (with respect to a given domain) byte encoding of this object.
For many use-cases, the AnnotatedUbrUtil can be used to quickly implement this method.
updateAccumulator in interface UniqueByteRepresentable