57 digits.push_back(
static_cast<char>(
'0' +
static_cast<unsigned>(value % 10)));
70 for (
size_t i = value.size(); i > 0; --i)
74 static_cast<void>(
digits.remove_last());
90 for (
size_t i =
used; i > 0; --i)
91 value.push_back(
static_cast<char>(
'0' +
digits[i - 1]));
99 if (
lhs.size() !=
rhs.size())
102 for (
size_t i = 0; i <
lhs.size(); ++i)
113 cout << name <<
"(x) = ";
114 for (
size_t i = 0; i < poly.
size(); ++i)
128 for (
size_t i = 0; i <
batch.size(); ++i)
130 cout <<
" item[" << i <<
"] = [";
131 for (
size_t j = 0; j <
batch[i].size(); ++j)
141 using DefaultNTT =
NTT<>;
143 cout <<
"\n=== Number Theoretic Transform (NTT) ===\n\n";
144 cout <<
"Active SIMD backend: " << DefaultNTT::simd_backend_name() <<
'\n';
145 cout <<
" AVX2 available: "
146 << (DefaultNTT::avx2_dispatch_available() ?
"yes" :
"no") <<
'\n';
147 cout <<
" NEON available: "
148 << (DefaultNTT::neon_dispatch_available() ?
"yes" :
"no") <<
"\n\n";
150 cout <<
"[1] Static polynomial multiplication\n";
160 cout <<
"[2] Exact CRT multiplication beyond a single modulus\n";
164 DefaultNTT::mod + 77ULL,
170 DefaultNTT::mod + 11ULL
173 cout <<
"Exact coefficients with CRT:\n [";
179 cout <<
"[3] Reusable arbitrary-size plan (Bluestein)\n";
181 DefaultNTT::Plan
plan(7);
184 plan.transform(spectrum,
false);
185 cout <<
"Forward transform:\n [";
186 for (
size_t i = 0; i < spectrum.
size(); ++i)
187 cout << spectrum[i] << (i + 1 == spectrum.
size() ?
"" :
", ");
189 plan.transform(spectrum,
true);
190 cout <<
"Inverse transform recovers:\n [";
191 for (
size_t i = 0; i < spectrum.
size(); ++i)
192 cout << spectrum[i] << (i + 1 == spectrum.
size() ?
"" :
", ");
195 cout <<
"[4] Batch transforms\n";
206 cout <<
"[5] Parallel multiplication with ThreadPool\n";
210 DefaultNTT::pmultiply(pool, a, b);
215 cout <<
"Parallel exact CRT product first coefficient: "
218 cout <<
"\n[6] Polynomial algebra modulo 998244353\n";
224 cout <<
"log(1 + 4x + 7x^2 + 2x^3) mod x^6:\n [";
225 for (
size_t i = 0; i <
log_series.size(); ++i)
228 cout <<
"exp(log(series)) recovers:\n [";
229 for (
size_t i = 0; i <
exp_series.size(); ++i)
232 cout <<
"series^3 mod x^6:\n [";
242 cout <<
"Interpolation from sampled values:\n [";
248 cout <<
"\n[7] Big integer multiplication in base 10\n";
250 const string decimal_a =
"12345678901234567890";
251 const string decimal_b =
"98765432109876543210";
260 cout <<
"Parallel product matches sequential: "
263 cout <<
"\n[8] Negacyclic multiplication modulo (x^4 + 1)\n";
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
void reserve(size_t cap)
Reserves cap cells into the array.
static Array< coeff_type > pmultiply(ThreadPool &pool, const Array< uint64_t > &a, const Array< uint64_t > &b, const size_t chunk_size=0)
Exact parallel polynomial multiplication.
static Array< coeff_type > multiply(const Array< uint64_t > &a, const Array< uint64_t > &b)
Exact sequential polynomial multiplication.
Number Theoretic Transform over Z / MOD Z.
A reusable thread pool for efficient parallel task execution.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
void reverse(Itor beg, Itor end)
Reverse elements in a range.
size_t size(Node *root) noexcept
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
T product(const Container &container, const T &init=T{1})
Compute product of all elements.
void print_rule()
Prints a horizontal rule for example output separation.
Industrial-grade Number Theoretic Transform core for modular polynomial multiplication.
A modern, efficient thread pool for parallel task execution.