Ejemplo n.º 1
0
    def test_embedding(self):
        """Checks that canonical embedding is correct.

        Checks that the embedding matches the evaluations of the roots of unity at
        indices that are 1 (mod) 4.

        Raises:
            ValueError: An error if test fails.
        """
        coeffs = [10, 34, 71, 31, 1, 2, 3, 4]
        poly = Polynomial(self.num_slots, coeffs)
        fft_length = self.num_slots * 4
        embedding = self.fft.embedding(coeffs)
        evals = []
        power = 1
        for i in range(1, fft_length, 4):
            angle = 2 * pi * power / fft_length
            root_of_unity = complex(cos(angle), sin(angle))
            evals.append(poly.evaluate(root_of_unity))
            power = (power * 5) % fft_length

        check_complex_vector_approx_eq(embedding, evals, 0.00001)
Ejemplo n.º 2
0
 def test_evaluate(self):
     poly = Polynomial(self.degree, [0, 1, 2, 3, 4])
     result = poly.evaluate(3)
     self.assertEqual(result, 426)