|
Aleph-w 7.10.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 Member Functions | |
| static constexpr coeff_type | exact_modulus_product_impl () noexcept |
| static constexpr uint64_t | sub_mod (const uint64_t lhs, const uint64_t rhs, const uint64_t mod) noexcept |
| static constexpr coeff_type | add_capped (const coeff_type lhs, const coeff_type rhs, const coeff_type cap) noexcept |
| static constexpr coeff_type | mul_capped (const coeff_type lhs, const coeff_type rhs, const coeff_type cap) noexcept |
| static constexpr size_t | next_power_of_two (const size_t n) noexcept |
| template<typename PrimeNTT > | |
| static constexpr bool | prime_supports_product_size (const size_t required) noexcept |
| static std::string | coeff_to_string (coeff_type value) |
| static CoefficientStats | analyze_coefficients (const Array< uint64_t > &input) |
| static coeff_type | conservative_bound (const Array< uint64_t > &a, const Array< uint64_t > &b) |
| static void | validate_inputs (const Array< uint64_t > &a, const Array< uint64_t > &b, const char *const ctx) |
| static coeff_type | reconstruct_coefficient (const uint64_t r0, const uint64_t r1, const uint64_t r2) |
| static Array< coeff_type > | reconstruct_product (const Array< uint64_t > &c0, const Array< uint64_t > &c1, const Array< uint64_t > &c2, ThreadPool *const pool, const size_t chunk_size) |
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.
| using Aleph::NTTExact::coeff_type = __uint128_t |
|
private |
|
private |
|
private |
|
inlinestaticconstexprprivatenoexcept |
|
inlinestaticprivate |
Definition at line 2569 of file ntt.H.
References Aleph::NTTExact::CoefficientStats::max_value, Aleph::NTTExact::CoefficientStats::non_zero, Aleph::Array< T >::size(), Aleph::NTTExact::CoefficientStats::sum, and value.
|
inlinestaticprivate |
|
inlinestaticprivate |
Definition at line 2589 of file ntt.H.
References Aleph::Array< T >::is_empty(), Aleph::NTTExact::CoefficientStats::max_value, Aleph::NTTExact::CoefficientStats::non_zero, and Aleph::NTTExact::CoefficientStats::sum.
|
inlinestaticconstexprnoexcept |
|
inlinestaticconstexprprivatenoexcept |
|
inlinestaticconstexprprivatenoexcept |
|
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 2746 of file ntt.H.
References 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().
|
inlinestaticconstexprprivatenoexcept |
|
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 2777 of file ntt.H.
References 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().
|
inlinestaticconstexprnoexcept |
|
inlinestaticconstexprprivatenoexcept |
Definition at line 2538 of file ntt.H.
References Aleph::and.
|
inlinestaticprivate |
Definition at line 2651 of file ntt.H.
References Aleph::mod_inv(), and Aleph::mod_mul().
|
inlinestaticprivate |
Definition at line 2678 of file ntt.H.
References ah_runtime_error_unless, Aleph::and, Aleph::Array< T >::create(), Aleph::ThreadPool::num_threads(), output, Aleph::parallel_for_index(), and Aleph::Array< T >::size().
|
inlinestaticconstexprprivatenoexcept |
|
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 2729 of file ntt.H.
References Aleph::and.
Referenced by TEST_F().
|
inlinestaticprivate |
Definition at line 2628 of file ntt.H.
References ah_invalid_argument_if, and Aleph::Array< T >::size().
|
staticconstexprprivate |