|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Exact polynomial multiplication via three-prime NTT + CRT. More...
#include <ntt.H>
Classes | |
| struct | CoefficientStats |
Public Types | |
| using | coeff_type = __uint128_t |
Static Public Member Functions | |
| static constexpr size_t | prime_count () noexcept |
| Number of CRT primes in the exact multiplier. | |
| static constexpr coeff_type | exact_modulus_product () noexcept |
| Product of the three CRT moduli. | |
| static constexpr bool | supports_product_size (const size_t required) noexcept |
| Check whether a target product length is supported. | |
| static Array< coeff_type > | multiply (const Array< uint64_t > &a, const Array< uint64_t > &b) |
| Exact sequential polynomial multiplication. | |
| 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. | |
Private Types | |
| using | Prime0NTT = NTT< 998244353ULL, 3ULL > |
| using | Prime1NTT = NTT< 469762049ULL, 3ULL > |
| using | Prime2NTT = NTT< 1004535809ULL, 3ULL > |
Static Private Attributes | |
| static constexpr NTTPrime | primes_ [] |
Exact polynomial multiplication via three-prime NTT + CRT.
This helper reconstructs coefficients in __uint128_t using three standard NTT-friendly primes:
998244353 = 119 * 2^23 + 1469762049 = 7 * 2^26 + 11004535809 = 479 * 2^21 + 1The result is exact as long as every coefficient of the true convolution lies in [0, P), where P is the product of the three moduli. Before executing the transforms, the implementation applies conservative sufficient bounds and rejects inputs that cannot be proven to fit inside that CRT range.
|
private |
|
private |
|
private |
|
inlinestaticconstexprprivatenoexcept |
|
inlinestaticprivate |
Definition at line 2496 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::NTTExact::CoefficientStats::max_value, Aleph::NTTExact::CoefficientStats::non_zero, and Aleph::NTTExact::CoefficientStats::sum.
|
inlinestaticprivate |
Definition at line 2478 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp().
|
inlinestaticprivate |
Definition at line 2516 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), and Aleph::Array< T >::is_empty().
|
inlinestaticconstexprnoexcept |
|
inlinestaticconstexprprivatenoexcept |
|
inlinestaticconstexprprivatenoexcept |
Definition at line 2437 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp().
|
inlinestatic |
Exact sequential polynomial multiplication.
| a | First polynomial with non-negative uint64_t coefficients. |
| b | Second polynomial with non-negative uint64_t coefficients. |
__uint128_t. | std::invalid_argument | if the transform size is unsupported or if the inputs cannot be proven to fit in the CRT reconstruction range. |
Definition at line 2673 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), and Aleph::Array< T >::is_empty().
Referenced by Aleph::NTT< MOD, ROOT >::bigint_multiply(), main(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
inlinestatic |
Exact parallel polynomial multiplication.
Parallelism is applied across the independent prime transforms and then across CRT reconstruction when the supplied pool has more than one worker.
| pool | Thread pool used for execution. |
| a | First polynomial with non-negative uint64_t coefficients. |
| b | Second polynomial with non-negative uint64_t coefficients. |
| chunk_size | Reconstruction chunk size (0 selects automatic chunking). |
__uint128_t. | std::invalid_argument | if the transform size is unsupported or if the inputs cannot be proven to fit in the CRT reconstruction range. |
Definition at line 2704 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::ThreadPool::enqueue(), Aleph::Array< T >::is_empty(), and Aleph::ThreadPool::num_threads().
Referenced by main(), Aleph::NTT< MOD, ROOT >::pbigint_multiply(), and TEST_F().
|
inlinestaticconstexprprivatenoexcept |
Definition at line 2465 of file ntt.H.
References Aleph::and, and Aleph::divide_and_conquer_partition_dp().
|
inlinestaticprivate |
Definition at line 2578 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::mod_inv(), and Aleph::mod_mul().
|
inlinestaticprivate |
Definition at line 2605 of file ntt.H.
References ah_runtime_error_unless, Aleph::and, Aleph::Array< T >::create(), Aleph::divide_and_conquer_partition_dp(), Aleph::ThreadPool::num_threads(), output, and Aleph::parallel_for_index().
|
inlinestaticconstexprnoexcept |
Check whether a target product length is supported.
The length refers to the final convolution length a.size() + b.size() - 1. Each internal prime transform may still use Bluestein or a larger power-of-two staging length.
Definition at line 2656 of file ntt.H.
References Aleph::and, and Aleph::divide_and_conquer_partition_dp().
Referenced by TEST_F().
|
inlinestaticprivate |
Definition at line 2555 of file ntt.H.
References ah_invalid_argument_if, Aleph::divide_and_conquer_partition_dp(), and Aleph::Array< T >::size().