arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/spqlios/lib/test/testlib/negacyclic_polynomial.h
spqlios/lib/test/testlib/negacyclic_polynomial.hRaw
 1#ifndef SPQLIOS_NEGACYCLIC_POLYNOMIAL_H
 2#define SPQLIOS_NEGACYCLIC_POLYNOMIAL_H
 3
 4#include <cstdint>
 5
 6#include "test_commons.h"
 7
 8template <typename T>
 9class polynomial;
10typedef polynomial<__int128_t> znx_i128;
11typedef polynomial<int64_t> znx_i64;
12typedef polynomial<double> rnx_f64;
13
14template <typename T>
15class polynomial {
16 public:
17  std::vector<T> coeffs;
18  /** @brief create a polynomial out of existing coeffs */
19  polynomial(uint64_t N, const T* c);
20  /** @brief zero polynomial of dimension N */
21  explicit polynomial(uint64_t N);
22  /** @brief empty polynomial (dim 0) */
23  polynomial();
24
25  /** @brief ring dimension */
26  uint64_t nn() const;
27  /** @brief special setter (accept any indexes, and does the negacyclic translation) */
28  void set_coeff(int64_t i, T v);
29  /** @brief special getter (accept any indexes, and does the negacyclic translation) */
30  T get_coeff(int64_t i) const;
31  /** @brief returns the coefficient layout */
32  T* data();
33  /** @brief returns the coefficient layout (const version) */
34  const T* data() const;
35  /** @brief saves to the layout */
36  void save_as(T* dest) const;
37  /** @brief zero */
38  static polynomial<T> zero(uint64_t n);
39  /** @brief random polynomial with coefficients in [-2^log2bounds, 2^log2bounds]*/
40  static polynomial<T> random_log2bound(uint64_t n, uint64_t log2bound);
41  /** @brief random polynomial with coefficients in [-2^log2bounds, 2^log2bounds]*/
42  static polynomial<T> random(uint64_t n);
43  /** @brief random polynomial with coefficient in [lb;ub] */
44  static polynomial<T> random_bound(uint64_t n, const T lb, const T ub);
45};
46
47/** @brief equality operator (used during tests) */
48template <typename T>
49bool operator==(const polynomial<T>& a, const polynomial<T>& b);
50
51/** @brief addition operator (used during tests) */
52template <typename T>
53polynomial<T> operator+(const polynomial<T>& a, const polynomial<T>& b);
54
55/** @brief subtraction operator (used during tests) */
56template <typename T>
57polynomial<T> operator-(const polynomial<T>& a, const polynomial<T>& b);
58
59/** @brief negation operator (used during tests) */
60template <typename T>
61polynomial<T> operator-(const polynomial<T>& a);
62
63template <typename T>
64polynomial<T> naive_product(const polynomial<T>& a, const polynomial<T>& b);
65
66/** @brief distance between two real polynomials (used during tests) */
67double infty_dist(const rnx_f64& a, const rnx_f64& b);
68
69#endif  // SPQLIOS_NEGACYCLIC_POLYNOMIAL_H