public class SparseTernaryPolynomial extends java.lang.Object implements TernaryPolynomial
TernaryPolynomial
with a "low" number of nonzero coefficients.Constructor and Description |
---|
SparseTernaryPolynomial(int[] coeffs)
Constructs a new
SparseTernaryPolynomial with a given set of coefficients. |
SparseTernaryPolynomial(IntegerPolynomial intPoly)
Constructs a
DenseTernaryPolynomial from a IntegerPolynomial . |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
equals(java.lang.Object obj) |
static SparseTernaryPolynomial |
fromBinary(java.io.InputStream is,
int N,
int numOnes,
int numNegOnes)
Decodes a byte array encoded with
toBinary() to a ploynomial. |
static SparseTernaryPolynomial |
generateRandom(int N,
int numOnes,
int numNegOnes,
java.security.SecureRandom random)
Generates a random polynomial with
numOnes coefficients equal to 1,
numNegOnes coefficients equal to -1, and the rest equal to 0. |
int[] |
getNegOnes() |
int[] |
getOnes() |
int |
hashCode() |
BigIntPolynomial |
mult(BigIntPolynomial poly2)
Multiplies the polynomial by a
BigIntPolynomial , taking the indices mod N. |
IntegerPolynomial |
mult(IntegerPolynomial poly2)
Multiplies the polynomial by an
IntegerPolynomial , taking the indices mod N |
IntegerPolynomial |
mult(IntegerPolynomial poly2,
int modulus)
Multiplies the polynomial by an
IntegerPolynomial ,
taking the coefficient values mod modulus and the indices mod N . |
int |
size()
Returns the maximum number of coefficients the polynomial can have
|
byte[] |
toBinary()
Encodes the polynomial to a byte array writing
BITS_PER_INDEX bits for each coefficient. |
IntegerPolynomial |
toIntegerPolynomial()
Returns a polynomial that is equal to this polynomial (in the sense that
Polynomial.mult(IntegerPolynomial, int)
returns equal IntegerPolynomial s). |
public SparseTernaryPolynomial(IntegerPolynomial intPoly)
DenseTernaryPolynomial
from a IntegerPolynomial
. The two polynomials are
independent of each other.intPoly
- the original polynomialpublic SparseTernaryPolynomial(int[] coeffs)
SparseTernaryPolynomial
with a given set of coefficients.coeffs
- the coefficientspublic static SparseTernaryPolynomial fromBinary(java.io.InputStream is, int N, int numOnes, int numNegOnes) throws java.io.IOException
toBinary()
to a ploynomial.is
- an input stream containing an encoded polynomialN
- number of coefficients including zerosnumOnes
- number of coefficients equal to 1numNegOnes
- number of coefficients equal to -1java.io.IOException
public static SparseTernaryPolynomial generateRandom(int N, int numOnes, int numNegOnes, java.security.SecureRandom random)
numOnes
coefficients equal to 1,
numNegOnes
coefficients equal to -1, and the rest equal to 0.N
- number of coefficientsnumOnes
- number of 1'snumNegOnes
- number of -1'spublic IntegerPolynomial mult(IntegerPolynomial poly2)
TernaryPolynomial
IntegerPolynomial
, taking the indices mod Nmult
in interface Polynomial
mult
in interface TernaryPolynomial
poly2
- a polynomialpublic IntegerPolynomial mult(IntegerPolynomial poly2, int modulus)
Polynomial
IntegerPolynomial
,
taking the coefficient values mod modulus
and the indices mod N
.mult
in interface Polynomial
poly2
- a polynomialmodulus
- a modulus to applypublic BigIntPolynomial mult(BigIntPolynomial poly2)
Polynomial
BigIntPolynomial
, taking the indices mod N. Does not
change this polynomial but returns the result as a new polynomial.mult
in interface Polynomial
poly2
- the polynomial to multiply bypublic int[] getOnes()
getOnes
in interface TernaryPolynomial
public int[] getNegOnes()
getNegOnes
in interface TernaryPolynomial
public byte[] toBinary()
BITS_PER_INDEX
bits for each coefficient.public IntegerPolynomial toIntegerPolynomial()
Polynomial
Polynomial.mult(IntegerPolynomial, int)
returns equal IntegerPolynomial
s). The new polynomial is guaranteed to be independent of the original.toIntegerPolynomial
in interface Polynomial
IntegerPolynomial
.public int size()
TernaryPolynomial
size
in interface TernaryPolynomial
public void clear()
clear
in interface TernaryPolynomial
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object