Ejemplo n.º 1
0
 /// <summary>
 /// Generates a "sparse" or "dense" polynomial containing numOnes ints equal to 1,
 /// numNegOnes int equal to -1, and the rest equal to 0.
 /// </summary>
 ///
 /// <param name="N">Number of coeffeients</param>
 /// <param name="NumOnes">Number of ones</param>
 /// <param name="NumNegOnes">Number of negative ones</param>
 /// <param name="Sparse">Create a SparseTernaryPolynomial or DenseTernaryPolynomial</param>
 /// <param name="Rng">Random number generator</param>
 ///
 /// <returns>A ternary polynomial</returns>
 public static ITernaryPolynomial GenerateRandomTernary(int N, int NumOnes, int NumNegOnes, bool Sparse, IRandom Rng)
 {
     if (Sparse)
     {
         return(SparseTernaryPolynomial.GenerateRandom(N, NumOnes, NumNegOnes, Rng));
     }
     else
     {
         return(DenseTernaryPolynomial.GenerateRandom(N, NumOnes, NumNegOnes, Rng));
     }
 }
 private void CheckTernarity(DenseTernaryPolynomial poly)
 {
     if (!poly.IsTernary())
         throw new Exception("DenseTernaryPolynomial CheckTernarity test failed!");
 }
Ejemplo n.º 3
0
        private void MultTest(int[] coeffs1, int[] coeffs2)
        {
            IntegerPolynomial i1 = new IntegerPolynomial(coeffs1);
            IntegerPolynomial i2 = new IntegerPolynomial(coeffs2);
            LongPolynomial5 a = new LongPolynomial5(i1);
            DenseTernaryPolynomial b = new DenseTernaryPolynomial(i2);
            IntegerPolynomial c1 = i1.Multiply(i2, 2048);
            IntegerPolynomial c2 = a.Multiply(b).ToIntegerPolynomial();

            if (!EqualsMod(c1.Coeffs, c2.Coeffs, 2048))
                throw new Exception("LongPolynomial5 multiply test failed!");
        }