#ifndef SPQLIOS_NEGACYCLIC_POLYNOMIAL_H #define SPQLIOS_NEGACYCLIC_POLYNOMIAL_H #include #include "test_commons.h" template class polynomial; typedef polynomial<__int128_t> znx_i128; typedef polynomial znx_i64; typedef polynomial rnx_f64; template class polynomial { public: std::vector coeffs; /** @brief create a polynomial out of existing coeffs */ polynomial(uint64_t N, const T* c); /** @brief zero polynomial of dimension N */ explicit polynomial(uint64_t N); /** @brief empty polynomial (dim 0) */ polynomial(); /** @brief ring dimension */ uint64_t nn() const; /** @brief special setter (accept any indexes, and does the negacyclic translation) */ void set_coeff(int64_t i, T v); /** @brief special getter (accept any indexes, and does the negacyclic translation) */ T get_coeff(int64_t i) const; /** @brief returns the coefficient layout */ T* data(); /** @brief returns the coefficient layout (const version) */ const T* data() const; /** @brief saves to the layout */ void save_as(T* dest) const; /** @brief zero */ static polynomial zero(uint64_t n); /** @brief random polynomial with coefficients in [-2^log2bounds, 2^log2bounds]*/ static polynomial random_log2bound(uint64_t n, uint64_t log2bound); /** @brief random polynomial with coefficients in [-2^log2bounds, 2^log2bounds]*/ static polynomial random(uint64_t n); /** @brief random polynomial with coefficient in [lb;ub] */ static polynomial random_bound(uint64_t n, const T lb, const T ub); }; /** @brief equality operator (used during tests) */ template bool operator==(const polynomial& a, const polynomial& b); /** @brief addition operator (used during tests) */ template polynomial operator+(const polynomial& a, const polynomial& b); /** @brief subtraction operator (used during tests) */ template polynomial operator-(const polynomial& a, const polynomial& b); /** @brief negation operator (used during tests) */ template polynomial operator-(const polynomial& a); template polynomial naive_product(const polynomial& a, const polynomial& b); /** @brief distance between two real polynomials (used during tests) */ double infty_dist(const rnx_f64& a, const rnx_f64& b); #endif // SPQLIOS_NEGACYCLIC_POLYNOMIAL_H