11#ifndef WEILYCODER_POLY_ELEMENTARY_FUNC_MULTIPLY_HPP
22#define WEILYCODER_POLY_ELEMENTARY_FUNC_MULTIPLY_HPP
33
4+ /* *
5+ * @file multiply.hpp
6+ * @brief Polynomial Multiplication Functions
7+ */
8+
49#include " ../../number_theory/mod_utility.hpp"
510#include " ../ntt_convolve.hpp"
611#include < vector>
712
813namespace weilycoder {
14+ /* *
15+ * @brief Multiply two polynomials using a provided multiplication function.
16+ * @tparam T Coefficient type.
17+ * @tparam MultiplyFunc Type of the multiplication function.
18+ * @param a Coefficients of the first polynomial.
19+ * @param b Coefficients of the second polynomial.
20+ * @param multiply Function to multiply two polynomials.
21+ * @return Coefficients of the resulting polynomial after multiplication.
22+ */
923template <typename T, typename MultiplyFunc>
1024std::vector<T> poly_mul (const std::vector<T> &a, const std::vector<T> &b,
1125 MultiplyFunc multiply) {
1226 return multiply (a, b);
1327}
1428
29+ /* *
30+ * @brief Multiply two polynomials using a provided multiplication function,
31+ * limiting the result to degree n-1.
32+ * @tparam T Coefficient type.
33+ * @tparam MultiplyFunc Type of the multiplication function.
34+ * @param a Coefficients of the first polynomial.
35+ * @param b Coefficients of the second polynomial.
36+ * @param n Maximum degree of the resulting polynomial (result size will be n).
37+ * @param multiply Function to multiply two polynomials.
38+ * @return Coefficients of the resulting polynomial after multiplication,
39+ * limited to degree n-1.
40+ */
1541template <typename T, typename MultiplyFunc>
1642std::vector<T> poly_mul (const std::vector<T> &a, const std::vector<T> &b, size_t n,
1743 MultiplyFunc multiply) {
@@ -21,6 +47,16 @@ std::vector<T> poly_mul(const std::vector<T> &a, const std::vector<T> &b, size_t
2147 return res;
2248}
2349
50+ /* *
51+ * @brief Multiply two polynomials using NTT under a given modulus,
52+ * limiting the result to degree n-1.
53+ * @tparam mod Modulus for NTT.
54+ * @param a Coefficients of the first polynomial.
55+ * @param b Coefficients of the second polynomial.
56+ * @param n Maximum degree of the resulting polynomial (result size will be n).
57+ * @return Coefficients of the resulting polynomial after multiplication,
58+ * limited to degree n-1.
59+ */
2460template <uint64_t mod>
2561std::vector<uint64_t > ntt_poly_mul (const std::vector<uint64_t > &a,
2662 const std::vector<uint64_t > &b, size_t n) {
0 commit comments