|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Number Theoretic Transform over Z / MOD Z.
More...
#include <ntt.H>
Classes | |
| class | Plan |
| Precomputed plans for NTT transforms. More... | |
Public Types | |
| enum class | NTTSimdBackend { scalar , avx2 , neon } |
| SIMD backends available to the NTT butterfly core. More... | |
Static Public Member Functions | |
| static constexpr const char * | simd_backend_name (const NTTSimdBackend backend) noexcept |
| static bool | avx2_dispatch_available () noexcept |
| Returns whether AVX2 dispatch is available at runtime. | |
| static bool | neon_dispatch_available () noexcept |
| Returns whether AArch64 NEON dispatch is available at runtime. | |
| static NTTSimdBackend | simd_backend () noexcept |
Returns the SIMD backend selected under ALEPH_NTT_SIMD. | |
| static const char * | simd_backend_name () noexcept |
| Returns the active SIMD backend name. | |
| static constexpr uint64_t | max_transform_size () noexcept |
| Maximum supported power-of-two transform size. | |
| static constexpr bool | supports_size (const size_t n) noexcept |
| Check whether a transform size is supported. | |
| static constexpr uint64_t | primitive_root_of_unity (const size_t n) |
Return an n-th primitive root of unity modulo MOD. | |
| static void | transform (Array< uint64_t > &a, const bool invert) |
| In-place forward or inverse transform. | |
| static Array< uint64_t > | transformed (const Array< uint64_t > &input, const bool invert=false) |
| Transform an input array and return the result. | |
| static Array< uint64_t > | multiply (const Array< uint64_t > &a, const Array< uint64_t > &b) |
Multiply two polynomials modulo MOD. | |
| static void | multiply_inplace (Array< uint64_t > &a, const Array< uint64_t > &b) |
Replace a by the product a * b. | |
| static Array< uint64_t > | negacyclic_multiply (const Array< uint64_t > &a, const Array< uint64_t > &b) |
Negacyclic convolution modulo x^N + 1. | |
| static void | transform_batch (Array< Array< uint64_t > > &batch, const bool invert) |
| Sequential batch transform for equal-sized inputs. | |
| static Array< Array< uint64_t > > | transformed_batch (const Array< Array< uint64_t > > &batch, const bool invert=false) |
| Return a transformed copy of an entire batch. | |
| static void | ptransform (ThreadPool &pool, Array< uint64_t > &a, const bool invert, const size_t chunk_size=0) |
| Parallel in-place transform using a ThreadPool. | |
| static Array< uint64_t > | ptransformed (ThreadPool &pool, const Array< uint64_t > &input, const bool invert=false, const size_t chunk_size=0) |
| Parallel transform returning a new array. | |
| static Array< uint64_t > | pmultiply (ThreadPool &pool, const Array< uint64_t > &a, const Array< uint64_t > &b, const size_t chunk_size=0) |
Parallel polynomial multiplication modulo MOD. | |
| static void | ptransform_batch (ThreadPool &pool, Array< Array< uint64_t > > &batch, const bool invert, const size_t chunk_size=0) |
| Parallel batch transform for equal-sized inputs. | |
| static uint64_t | poly_eval (const Array< uint64_t > &coeffs, const uint64_t x) |
Evaluate a polynomial at a single point modulo MOD. | |
| static Array< uint64_t > | poly_inverse (const Array< uint64_t > &coeffs, const size_t n) |
Formal polynomial inverse modulo x^n. | |
| static std::pair< Array< uint64_t >, Array< uint64_t > > | poly_divmod (const Array< uint64_t > ÷nd, const Array< uint64_t > &divisor) |
Polynomial division with remainder modulo MOD. | |
| static Array< uint64_t > | poly_log (const Array< uint64_t > &coeffs, const size_t n) |
Formal polynomial logarithm modulo x^n. | |
| static Array< uint64_t > | poly_exp (const Array< uint64_t > &coeffs, const size_t n) |
Formal polynomial exponential modulo x^n. | |
| static Array< uint64_t > | poly_sqrt (const Array< uint64_t > &coeffs, const size_t n) |
Formal polynomial square root modulo x^n. | |
| static Array< uint64_t > | poly_power (const Array< uint64_t > &coeffs, const uint64_t k, const size_t n) |
Formal polynomial power modulo x^n. | |
| static Array< uint64_t > | multipoint_eval (const Array< uint64_t > &coeffs, const Array< uint64_t > &points) |
Evaluate a polynomial on multiple points modulo MOD. | |
| static Array< uint64_t > | interpolate (const Array< uint64_t > &points, const Array< uint64_t > &values) |
Interpolate a polynomial from point-value samples modulo MOD. | |
| template<uint64_t Base = (1ULL << 15)> | |
| static Array< uint64_t > | bigint_multiply (const Array< uint64_t > &a, const Array< uint64_t > &b) |
Multiply two non-negative integers represented as base-Base digits. | |
| template<uint64_t Base = (1ULL << 15)> | |
| static Array< uint64_t > | pbigint_multiply (ThreadPool &pool, const Array< uint64_t > &a, const Array< uint64_t > &b, const size_t chunk_size=0) |
Parallel big-integer multiplication in base Base. | |
Static Public Attributes | |
| static constexpr uint64_t | mod = MOD |
| static constexpr uint64_t | root = ROOT |
Private Types | |
| enum class | SimdPreference { automatic , scalar_only , avx2_only , neon_only } |
| enum class | Representation { standard , montgomery } |
Static Private Attributes | |
| static constexpr MontgomeryCtx | mctx_ = montgomery_ctx_for_mod<MOD>() |
Number Theoretic Transform over Z / MOD Z.
The implementation mirrors the iterative Cooley-Tukey structure used in Aleph's FFT support, but replaces floating-point arithmetic with exact modular operations. Internally, multiplications are carried out in the Montgomery domain for a fixed odd modulus.
Current capabilities:
ThreadPool parallelismMOD negacyclic convolution modulo x^N + 1
| MOD | Prime modulus with a sufficiently large power-of-two factor in MOD - 1. |
| ROOT | Primitive root modulo MOD. |
|
strong |
|
strongprivate |
|
strongprivate |
|
inlinestaticconstexprprivatenoexcept |
Definition at line 153 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), MOD, and Aleph::sum().
Referenced by Aleph::NTT< MOD, ROOT >::Plan::apply_scalar_butterfly_range(), Aleph::NTT< MOD, ROOT >::poly_add_series(), Aleph::NTT< MOD, ROOT >::poly_eval(), and Aleph::NTT< MOD, ROOT >::poly_exp().
|
inlinestaticnoexcept |
Returns whether AVX2 dispatch is available at runtime.
Definition at line 397 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp().
Referenced by Aleph::NTT< MOD, ROOT >::detected_simd_backend().
|
static |
Multiply two non-negative integers represented as base-Base digits.
Digits are stored in little-endian order: a[0] is the least significant digit. The result is normalized by trimming high zero digits, except that zero is returned as a single digit {0}.
The implementation selects an exact convolution path automatically:
min(a.size(), b.size()) * (Base - 1)^2 < MOD and the transform size is supported by this NTT<MOD, ROOT>, a single-prime exact multiplication is usedNTTExact, then propagates carries| Base | Digit base, must be at least 2. |
| a | First integer digits. |
| b | Second integer digits. |
Base. | std::invalid_argument | if some input digit is outside [0, Base) or if no exact backend can support the requested convolution. |
Definition at line 2740 of file ntt.H.
References ah_invalid_argument_if, Aleph::and, Aleph::Array< T >::create(), Aleph::divide_and_conquer_partition_dp(), MOD, Aleph::NTTExact::multiply(), output, Aleph::Array< T >::reserve(), and Aleph::Array< T >::size().
|
inlinestaticprivate |
Definition at line 1550 of file ntt.H.
References Aleph::NTT< MOD, ROOT >::build_product_tree(), Aleph::divide_and_conquer_partition_dp(), MOD, Aleph::NTT< MOD, ROOT >::multiply(), and Aleph::NTT< MOD, ROOT >::sub_mod().
Referenced by Aleph::NTT< MOD, ROOT >::build_product_tree(), Aleph::NTT< MOD, ROOT >::interpolate(), and Aleph::NTT< MOD, ROOT >::multipoint_eval().
|
inlinestaticprivatenoexcept |
Definition at line 385 of file ntt.H.
References Aleph::NTT< MOD, ROOT >::avx2, Aleph::NTT< MOD, ROOT >::avx2_dispatch_available(), Aleph::NTT< MOD, ROOT >::neon, Aleph::NTT< MOD, ROOT >::neon_dispatch_available(), and Aleph::NTT< MOD, ROOT >::scalar.
Referenced by Aleph::NTT< MOD, ROOT >::simd_backend().
|
inlinestatic |
Interpolate a polynomial from point-value samples modulo MOD.
| points | Sample points. |
| values | Sample values. |
< points.size() passing through all pairs. | std::invalid_argument | if the points collide modulo MOD or the arrays have different sizes. |
Definition at line 2272 of file ntt.H.
References ah_invalid_argument_if, Aleph::NTT< MOD, ROOT >::build_product_tree(), Aleph::Array< T >::create(), Aleph::divide_and_conquer_partition_dp(), Aleph::NTT< MOD, ROOT >::interpolate_recursive(), Aleph::Array< T >::is_empty(), Aleph::NTT< MOD, ROOT >::make_product_tree_storage(), MOD, Aleph::mod_inv(), Aleph::mod_mul(), Aleph::NTT< MOD, ROOT >::multipoint_eval(), Aleph::NTT< MOD, ROOT >::normalize_poly(), Aleph::NTT< MOD, ROOT >::poly_derivative(), Aleph::Array< T >::size(), and Aleph::NTT< MOD, ROOT >::validate_distinct_points().
|
inlinestaticprivate |
Definition at line 1629 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::NTT< MOD, ROOT >::interpolate_recursive(), MOD, Aleph::NTT< MOD, ROOT >::multiply(), and Aleph::NTT< MOD, ROOT >::poly_add_normalized().
Referenced by Aleph::NTT< MOD, ROOT >::interpolate(), and Aleph::NTT< MOD, ROOT >::interpolate_recursive().
|
inlinestaticconstexprprivatenoexcept |
Definition at line 147 of file ntt.H.
References Aleph::and.
Referenced by Aleph::NTT< MOD, ROOT >::negacyclic_multiply(), Aleph::NTT< MOD, ROOT >::supports_bluestein_size(), and Aleph::NTT< MOD, ROOT >::supports_power_of_two_size().
|
inlinestaticprivate |
Definition at line 1539 of file ntt.H.
References Aleph::Array< T >::append(), Aleph::count(), and Aleph::Array< T >::reserve().
Referenced by Aleph::NTT< MOD, ROOT >::interpolate(), and Aleph::NTT< MOD, ROOT >::multipoint_eval().
|
inlinestaticconstexprnoexcept |
Maximum supported power-of-two transform size.
2^k such that 2^k divides MOD - 1. Definition at line 1656 of file ntt.H.
References Aleph::NTT< MOD, ROOT >::max_transform_size_impl().
Referenced by Aleph::NTT< MOD, ROOT >::negacyclic_multiply(), and Aleph::NTT< MOD, ROOT >::validate_supported_size().
|
inlinestaticconstexprprivatenoexcept |
Definition at line 196 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), MOD, and Aleph::size().
Referenced by Aleph::NTT< MOD, ROOT >::max_transform_size(), and Aleph::NTT< MOD, ROOT >::supports_power_of_two_size().
|
inlinestatic |
Multiply two polynomials modulo MOD.
| a | First polynomial. |
| b | Second polynomial. |
a and b modulo MOD. | std::invalid_argument | if the required transform size is not supported by the modulus. |
Definition at line 1729 of file ntt.H.
References ah_invalid_argument_if, Aleph::divide_and_conquer_partition_dp(), Aleph::Array< T >::is_empty(), Aleph::NTT< MOD, ROOT >::Plan::multiply(), Aleph::NTT< MOD, ROOT >::next_power_of_two(), Aleph::Array< T >::size(), Aleph::NTT< MOD, ROOT >::supports_size(), and Aleph::NTT< MOD, ROOT >::validate_supported_size().
Referenced by Aleph::NTT< MOD, ROOT >::build_product_tree(), demo_ntt(), Aleph::NTT< MOD, ROOT >::interpolate_recursive(), Aleph::NTT< MOD, ROOT >::multiply_inplace(), Aleph::NTT< MOD, ROOT >::poly_divmod(), Aleph::NTT< MOD, ROOT >::poly_mul_trunc(), and TEST_F().
|
inlinestatic |
Replace a by the product a * b.
| a | Left polynomial, overwritten with the product. |
| b | Right polynomial. |
Definition at line 1756 of file ntt.H.
References Aleph::NTT< MOD, ROOT >::multiply().
|
inlinestatic |
Evaluate a polynomial on multiple points modulo MOD.
| coeffs | Polynomial coefficients. |
| points | Evaluation points. |
coeffs(points[i]) mod MOD. Definition at line 2240 of file ntt.H.
References Aleph::NTT< MOD, ROOT >::build_product_tree(), Aleph::Array< T >::create(), Aleph::divide_and_conquer_partition_dp(), Aleph::Array< T >::is_empty(), Aleph::NTT< MOD, ROOT >::make_product_tree_storage(), MOD, Aleph::NTT< MOD, ROOT >::multipoint_eval_recursive(), Aleph::NTT< MOD, ROOT >::normalize_poly(), output, and Aleph::Array< T >::size().
Referenced by Aleph::NTT< MOD, ROOT >::interpolate().
|
inlinestaticprivate |
Definition at line 1599 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::Array< T >::is_empty(), MOD, Aleph::NTT< MOD, ROOT >::multipoint_eval_recursive(), output, Aleph::NTT< MOD, ROOT >::poly_mod(), Aleph::Array< T >::size(), and Aleph::size().
Referenced by Aleph::NTT< MOD, ROOT >::multipoint_eval(), and Aleph::NTT< MOD, ROOT >::multipoint_eval_recursive().
|
inlinestatic |
Negacyclic convolution modulo x^N + 1.
This computes polynomial multiplication in the quotient ring Z / MOD Z [x] / (x^N + 1) using the classic twist/untwist reduction to an N-point NTT. A primitive 2N-th root of unity must therefore exist under the current modulus.
| a | First polynomial coefficients, size N. |
| b | Second polynomial coefficients, size N. |
N. | std::invalid_argument | if the inputs have different sizes, if N is not a positive power of two, or if 2N is unsupported by the modulus. |
Definition at line 1777 of file ntt.H.
References ah_invalid_argument_if, Aleph::Array< T >::create(), Aleph::divide_and_conquer_partition_dp(), Aleph::Array< T >::is_empty(), Aleph::NTT< MOD, ROOT >::is_power_of_two(), Aleph::NTT< MOD, ROOT >::max_transform_size(), MOD, Aleph::mod_inv(), Aleph::mod_mul(), Aleph::NTT< MOD, ROOT >::primitive_root_of_unity(), and Aleph::Array< T >::size().
Referenced by TEST_F().
|
inlinestaticnoexcept |
Returns whether AArch64 NEON dispatch is available at runtime.
Definition at line 413 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp().
Referenced by Aleph::NTT< MOD, ROOT >::detected_simd_backend().
|
inlinestaticprivate |
Definition at line 282 of file ntt.H.
References ah_overflow_error_if.
Referenced by Aleph::NTT< MOD, ROOT >::Plan::initialize_bluestein_plan(), Aleph::NTT< MOD, ROOT >::multiply(), and Aleph::NTT< MOD, ROOT >::pmultiply().
|
inlinestaticprivate |
Definition at line 1319 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), MOD, output, Aleph::Array< T >::reserve(), and Aleph::NTT< MOD, ROOT >::trim_trailing_zeros().
Referenced by Aleph::NTT< MOD, ROOT >::interpolate(), Aleph::NTT< MOD, ROOT >::multipoint_eval(), and Aleph::NTT< MOD, ROOT >::poly_divmod().
|
inlinestaticprivate |
Definition at line 301 of file ntt.H.
References Aleph::Array< T >::create(), Aleph::divide_and_conquer_partition_dp(), MOD, and output.
Referenced by Aleph::NTT< MOD, ROOT >::Plan::multiply_impl().
|
static |
Parallel big-integer multiplication in base Base.
The expensive convolution runs in parallel using the best exact backend selected by bigint_multiply; carry propagation itself remains a linear pass.
| Base | Digit base, must be at least 2. |
| pool | Thread pool used for the convolution backend. |
| a | First integer digits. |
| b | Second integer digits. |
| chunk_size | Parallel chunk size forwarded to the backend. |
Base. | std::invalid_argument | if some input digit is outside [0, Base) or if no exact backend can support the requested convolution. |
Definition at line 2843 of file ntt.H.
References ah_invalid_argument_if, Aleph::and, Aleph::Array< T >::create(), Aleph::divide_and_conquer_partition_dp(), MOD, output, Aleph::NTTExact::pmultiply(), Aleph::Array< T >::reserve(), and Aleph::Array< T >::size().
|
inlinestatic |
Parallel polynomial multiplication modulo MOD.
| pool | Thread pool used for transform stages and pointwise products. |
| a | First polynomial. |
| b | Second polynomial. |
| chunk_size | Iterations per scheduled chunk (0 selects an automatic value). |
a and b modulo MOD. Definition at line 1907 of file ntt.H.
References ah_invalid_argument_if, Aleph::divide_and_conquer_partition_dp(), Aleph::Array< T >::is_empty(), Aleph::NTT< MOD, ROOT >::next_power_of_two(), Aleph::NTT< MOD, ROOT >::Plan::pmultiply(), Aleph::Array< T >::size(), Aleph::NTT< MOD, ROOT >::supports_size(), and Aleph::NTT< MOD, ROOT >::validate_supported_size().
|
inlinestaticprivate |
Definition at line 1401 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), output, Aleph::NTT< MOD, ROOT >::poly_add_series(), and Aleph::NTT< MOD, ROOT >::trim_trailing_zeros().
Referenced by Aleph::NTT< MOD, ROOT >::interpolate_recursive().
|
inlinestaticprivate |
Definition at line 1371 of file ntt.H.
References Aleph::NTT< MOD, ROOT >::add_mod(), Aleph::divide_and_conquer_partition_dp(), MOD, output, Aleph::Array< T >::size(), and Aleph::NTT< MOD, ROOT >::zero_series().
Referenced by Aleph::NTT< MOD, ROOT >::poly_add_normalized(), and Aleph::NTT< MOD, ROOT >::poly_sqrt().
|
inlinestaticprivate |
Definition at line 1449 of file ntt.H.
References Aleph::Array< T >::create(), Aleph::divide_and_conquer_partition_dp(), MOD, Aleph::mod_mul(), output, and Aleph::Array< T >::size().
Referenced by Aleph::NTT< MOD, ROOT >::interpolate(), and Aleph::NTT< MOD, ROOT >::poly_log().
|
inlinestatic |
Polynomial division with remainder modulo MOD.
| dividend | Dividend coefficients in ascending degree order. |
| divisor | Divisor coefficients in ascending degree order. |
{quotient, remainder} with remainder.degree < divisor.degree. | std::invalid_argument | if divisor is the zero polynomial. |
Definition at line 2020 of file ntt.H.
References ah_invalid_argument_if, Aleph::divide_and_conquer_partition_dp(), Aleph::Array< T >::is_empty(), Aleph::NTT< MOD, ROOT >::multiply(), Aleph::NTT< MOD, ROOT >::normalize_poly(), Aleph::NTT< MOD, ROOT >::poly_inverse(), Aleph::NTT< MOD, ROOT >::poly_mul_trunc(), Aleph::NTT< MOD, ROOT >::poly_sub_normalized(), remainder(), Aleph::NTT< MOD, ROOT >::reverse_poly(), Aleph::Array< T >::size(), Aleph::NTT< MOD, ROOT >::trim_trailing_zeros(), and Aleph::NTT< MOD, ROOT >::truncate_poly().
Referenced by Aleph::NTT< MOD, ROOT >::poly_mod().
|
inlinestatic |
Evaluate a polynomial at a single point modulo MOD.
| coeffs | Polynomial coefficients in ascending degree order. |
| x | Evaluation point. |
sum coeffs[i] * x^i mod MOD. Definition at line 1958 of file ntt.H.
References Aleph::NTT< MOD, ROOT >::add_mod(), Aleph::divide_and_conquer_partition_dp(), MOD, Aleph::mod_mul(), and Aleph::Array< T >::size().
|
inlinestatic |
Formal polynomial exponential modulo x^n.
| coeffs | Input polynomial with zero constant term. |
| n | Number of coefficients to compute. |
exp(coeffs) mod x^n. | std::invalid_argument | if coeffs[0] != 0 (mod MOD). |
Definition at line 2084 of file ntt.H.
References Aleph::NTT< MOD, ROOT >::add_mod(), ah_invalid_argument_if, Aleph::Array< T >::create(), Aleph::divide_and_conquer_partition_dp(), Aleph::Array< T >::is_empty(), m, MOD, Aleph::NTT< MOD, ROOT >::poly_log(), Aleph::NTT< MOD, ROOT >::poly_mul_trunc(), Aleph::NTT< MOD, ROOT >::poly_sub_series(), and Aleph::NTT< MOD, ROOT >::series_prefix().
Referenced by Aleph::NTT< MOD, ROOT >::poly_power().
|
inlinestaticprivate |
Definition at line 1463 of file ntt.H.
References Aleph::Array< T >::create(), Aleph::divide_and_conquer_partition_dp(), MOD, Aleph::mod_inv(), Aleph::mod_mul(), output, and Aleph::Array< T >::size().
Referenced by Aleph::NTT< MOD, ROOT >::poly_log().
|
inlinestatic |
Formal polynomial inverse modulo x^n.
| coeffs | Input polynomial. |
| n | Number of coefficients to compute. |
g such that coeffs * g ≡ 1 (mod x^n, MOD). | std::invalid_argument | if the constant term is not invertible. |
Definition at line 1979 of file ntt.H.
References ah_invalid_argument_if, Aleph::Array< T >::create(), Aleph::divide_and_conquer_partition_dp(), Aleph::Array< T >::is_empty(), m, MOD, Aleph::mod_inv(), Aleph::NTT< MOD, ROOT >::poly_mul_trunc(), Aleph::NTT< MOD, ROOT >::series_prefix(), Aleph::NTT< MOD, ROOT >::sub_mod(), Aleph::NTT< MOD, ROOT >::truncate_poly(), and Aleph::NTT< MOD, ROOT >::zero_series().
Referenced by Aleph::NTT< MOD, ROOT >::poly_divmod(), Aleph::NTT< MOD, ROOT >::poly_log(), and Aleph::NTT< MOD, ROOT >::poly_sqrt().
|
inlinestatic |
Formal polynomial logarithm modulo x^n.
| coeffs | Input polynomial with constant term 1. |
| n | Number of coefficients to compute. |
ln(coeffs) mod x^n. | std::invalid_argument | if coeffs[0] != 1 (mod MOD). |
Definition at line 2056 of file ntt.H.
References ah_invalid_argument_if, Aleph::divide_and_conquer_partition_dp(), Aleph::Array< T >::is_empty(), MOD, Aleph::NTT< MOD, ROOT >::poly_derivative(), Aleph::NTT< MOD, ROOT >::poly_integral(), Aleph::NTT< MOD, ROOT >::poly_inverse(), Aleph::NTT< MOD, ROOT >::poly_mul_trunc(), Aleph::NTT< MOD, ROOT >::series_prefix(), Aleph::NTT< MOD, ROOT >::truncate_poly(), and Aleph::NTT< MOD, ROOT >::zero_series().
Referenced by Aleph::NTT< MOD, ROOT >::poly_exp(), and Aleph::NTT< MOD, ROOT >::poly_power().
|
inlinestaticprivate |
Definition at line 1583 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), and Aleph::NTT< MOD, ROOT >::poly_divmod().
Referenced by Aleph::NTT< MOD, ROOT >::multipoint_eval_recursive().
|
inlinestaticprivate |
Definition at line 1433 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::Array< T >::is_empty(), Aleph::NTT< MOD, ROOT >::multiply(), Aleph::NTT< MOD, ROOT >::series_prefix(), Aleph::NTT< MOD, ROOT >::truncate_poly(), and Aleph::NTT< MOD, ROOT >::zero_series().
Referenced by Aleph::NTT< MOD, ROOT >::poly_divmod(), Aleph::NTT< MOD, ROOT >::poly_exp(), Aleph::NTT< MOD, ROOT >::poly_inverse(), Aleph::NTT< MOD, ROOT >::poly_log(), and Aleph::NTT< MOD, ROOT >::poly_sqrt().
|
inlinestatic |
Formal polynomial power modulo x^n.
| coeffs | Base polynomial. |
| k | Non-negative exponent. |
| n | Number of coefficients to compute. |
coeffs^k mod x^n. Definition at line 2181 of file ntt.H.
References Aleph::and, Aleph::divide_and_conquer_partition_dp(), k, MOD, Aleph::mod_exp(), Aleph::mod_inv(), Aleph::mod_mul(), output, Aleph::NTT< MOD, ROOT >::poly_exp(), Aleph::NTT< MOD, ROOT >::poly_log(), Aleph::NTT< MOD, ROOT >::poly_scalar_mul_series(), Aleph::Array< T >::reserve(), Aleph::NTT< MOD, ROOT >::truncate_poly(), and Aleph::NTT< MOD, ROOT >::zero_series().
|
inlinestaticprivate |
Definition at line 1421 of file ntt.H.
References Aleph::and, Aleph::divide_and_conquer_partition_dp(), MOD, Aleph::mod_mul(), output, Aleph::NTT< MOD, ROOT >::scalar, and Aleph::NTT< MOD, ROOT >::zero_series().
Referenced by Aleph::NTT< MOD, ROOT >::poly_power(), and Aleph::NTT< MOD, ROOT >::poly_sqrt().
|
inlinestatic |
Formal polynomial square root modulo x^n.
| coeffs | Input polynomial. |
| n | Number of coefficients to compute. |
g such that g^2 ≡ coeffs (mod x^n, MOD). | std::invalid_argument | if no square root exists under the stated preconditions. |
Definition at line 2121 of file ntt.H.
References ah_invalid_argument_if, Aleph::and, Aleph::Array< T >::append(), Aleph::Array< T >::create(), Aleph::divide_and_conquer_partition_dp(), m, MOD, Aleph::mod_inv(), output, Aleph::NTT< MOD, ROOT >::poly_add_series(), Aleph::NTT< MOD, ROOT >::poly_inverse(), Aleph::NTT< MOD, ROOT >::poly_mul_trunc(), Aleph::NTT< MOD, ROOT >::poly_scalar_mul_series(), Aleph::NTT< MOD, ROOT >::poly_sqrt(), Aleph::Array< T >::reserve(), Aleph::NTT< MOD, ROOT >::series_prefix(), Aleph::NTT< MOD, ROOT >::tonelli_shanks(), Aleph::NTT< MOD, ROOT >::truncate_poly(), and Aleph::NTT< MOD, ROOT >::zero_series().
Referenced by Aleph::NTT< MOD, ROOT >::poly_sqrt().
|
inlinestaticprivate |
Definition at line 1411 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), output, Aleph::NTT< MOD, ROOT >::poly_sub_series(), and Aleph::NTT< MOD, ROOT >::trim_trailing_zeros().
Referenced by Aleph::NTT< MOD, ROOT >::poly_divmod().
|
inlinestaticprivate |
Definition at line 1386 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), MOD, output, Aleph::Array< T >::size(), Aleph::NTT< MOD, ROOT >::sub_mod(), and Aleph::NTT< MOD, ROOT >::zero_series().
Referenced by Aleph::NTT< MOD, ROOT >::poly_exp(), and Aleph::NTT< MOD, ROOT >::poly_sub_normalized().
|
inlinestaticconstexprprivatenoexcept |
Definition at line 174 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), exp(), and MOD.
Referenced by Aleph::NTT< MOD, ROOT >::primitive_root_of_order().
|
inlinestaticprivate |
Definition at line 315 of file ntt.H.
References ah_invalid_argument_if, Aleph::divide_and_conquer_partition_dp(), output, Aleph::Array< T >::reserve(), and Aleph::Array< T >::size().
Referenced by Aleph::NTT< MOD, ROOT >::Plan::multiply_impl().
|
inlinestaticconstexprprivate |
Definition at line 261 of file ntt.H.
References MOD, Aleph::NTT< MOD, ROOT >::pow_mod_constexpr(), and ROOT.
Referenced by Aleph::NTT< MOD, ROOT >::Plan::initialize_bluestein_plan(), and Aleph::NTT< MOD, ROOT >::primitive_root_of_unity().
|
inlinestaticconstexpr |
Return an n-th primitive root of unity modulo MOD.
| n | Transform length. It must be a supported power of two. |
n-th root of unity in standard representation. | std::invalid_argument | if n is not supported. |
Definition at line 1682 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::NTT< MOD, ROOT >::primitive_root_of_order(), and Aleph::NTT< MOD, ROOT >::validate_supported_size().
Referenced by Aleph::NTT< MOD, ROOT >::Plan::initialize_twiddles(), and Aleph::NTT< MOD, ROOT >::negacyclic_multiply().
|
inlinestatic |
Parallel in-place transform using a ThreadPool.
| pool | Thread pool used for stage-level parallelism. |
| a | Input/output array. |
| invert | If true, computes the inverse NTT. |
| chunk_size | Iterations per scheduled chunk (0 selects an automatic value). |
Definition at line 1868 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::NTT< MOD, ROOT >::Plan::ptransform(), and Aleph::Array< T >::size().
Referenced by Aleph::NTT< MOD, ROOT >::ptransformed().
|
inlinestatic |
Parallel batch transform for equal-sized inputs.
| pool | Thread pool used for execution. |
| batch | Batch of arrays. All items must have the same supported size. |
| invert | If true, computes inverse transforms. |
| chunk_size | Iterations per scheduled chunk (0 selects an automatic value). |
Definition at line 1940 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::NTT< MOD, ROOT >::Plan::ptransform_batch(), and Aleph::size().
|
inlinestatic |
Parallel transform returning a new array.
| pool | Thread pool used for stage-level parallelism. |
| input | Input array. |
| invert | If true, computes the inverse NTT. |
| chunk_size | Iterations per scheduled chunk (0 selects an automatic value). |
input. Definition at line 1886 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), output, and Aleph::NTT< MOD, ROOT >::ptransform().
|
inlinestaticprivate |
Definition at line 1361 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), MOD, output, and Aleph::Array< T >::reserve().
Referenced by Aleph::NTT< MOD, ROOT >::poly_divmod().
|
inlinestaticprivate |
Definition at line 1339 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), MOD, output, and Aleph::NTT< MOD, ROOT >::zero_series().
Referenced by Aleph::NTT< MOD, ROOT >::poly_exp(), Aleph::NTT< MOD, ROOT >::poly_inverse(), Aleph::NTT< MOD, ROOT >::poly_log(), Aleph::NTT< MOD, ROOT >::poly_mul_trunc(), and Aleph::NTT< MOD, ROOT >::poly_sqrt().
|
inlinestaticnoexcept |
Returns the SIMD backend selected under ALEPH_NTT_SIMD.
Definition at line 432 of file ntt.H.
References Aleph::NTT< MOD, ROOT >::automatic, Aleph::NTT< MOD, ROOT >::avx2, Aleph::NTT< MOD, ROOT >::avx2_only, Aleph::NTT< MOD, ROOT >::detected_simd_backend(), Aleph::divide_and_conquer_partition_dp(), Aleph::NTT< MOD, ROOT >::neon, Aleph::NTT< MOD, ROOT >::neon_only, Aleph::NTT< MOD, ROOT >::scalar, Aleph::NTT< MOD, ROOT >::scalar_only, and Aleph::NTT< MOD, ROOT >::simd_preference().
Referenced by Aleph::NTT< MOD, ROOT >::Plan::should_use_avx2(), Aleph::NTT< MOD, ROOT >::Plan::should_use_neon(), and Aleph::NTT< MOD, ROOT >::simd_backend_name().
Returns the active SIMD backend name.
Definition at line 455 of file ntt.H.
References Aleph::NTT< MOD, ROOT >::simd_backend(), and Aleph::NTT< MOD, ROOT >::simd_backend_name().
Referenced by Aleph::NTT< MOD, ROOT >::simd_backend_name().
|
inlinestaticconstexprnoexcept |
Definition at line 334 of file ntt.H.
References Aleph::NTT< MOD, ROOT >::avx2, Aleph::divide_and_conquer_partition_dp(), Aleph::NTT< MOD, ROOT >::neon, and Aleph::NTT< MOD, ROOT >::scalar.
|
inlinestaticconstexprprivatenoexcept |
Definition at line 168 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp().
Referenced by Aleph::NTT< MOD, ROOT >::Plan::should_use_avx2(), and Aleph::NTT< MOD, ROOT >::Plan::should_use_neon().
|
inlinestaticprivatenoexcept |
Definition at line 367 of file ntt.H.
References Aleph::and, Aleph::NTT< MOD, ROOT >::automatic, Aleph::NTT< MOD, ROOT >::avx2_only, Aleph::mode(), Aleph::NTT< MOD, ROOT >::neon_only, and Aleph::NTT< MOD, ROOT >::scalar_only.
Referenced by Aleph::NTT< MOD, ROOT >::simd_backend().
|
inlinestaticconstexprprivatenoexcept |
Definition at line 350 of file ntt.H.
References Aleph::NTT< MOD, ROOT >::automatic, Aleph::NTT< MOD, ROOT >::avx2_only, Aleph::divide_and_conquer_partition_dp(), Aleph::NTT< MOD, ROOT >::neon_only, and Aleph::NTT< MOD, ROOT >::scalar_only.
|
inlinestaticconstexprprivatenoexcept |
Definition at line 161 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), and MOD.
Referenced by Aleph::NTT< MOD, ROOT >::Plan::apply_scalar_butterfly_range(), Aleph::NTT< MOD, ROOT >::build_product_tree(), Aleph::NTT< MOD, ROOT >::poly_inverse(), and Aleph::NTT< MOD, ROOT >::poly_sub_series().
|
inlinestaticconstexprprivatenoexcept |
Definition at line 222 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::NTT< MOD, ROOT >::is_power_of_two(), MOD, Aleph::NTT< MOD, ROOT >::supports_power_of_two_size(), and Aleph::NTT< MOD, ROOT >::supports_root_order().
Referenced by Aleph::NTT< MOD, ROOT >::supports_size().
|
inlinestaticconstexprprivatenoexcept |
Definition at line 209 of file ntt.H.
References Aleph::and, Aleph::divide_and_conquer_partition_dp(), Aleph::NTT< MOD, ROOT >::is_power_of_two(), and Aleph::NTT< MOD, ROOT >::max_transform_size_impl().
Referenced by Aleph::NTT< MOD, ROOT >::Plan::Plan(), Aleph::NTT< MOD, ROOT >::Plan::initialize_bluestein_plan(), Aleph::NTT< MOD, ROOT >::supports_bluestein_size(), and Aleph::NTT< MOD, ROOT >::supports_size().
|
inlinestaticconstexprprivatenoexcept |
Definition at line 216 of file ntt.H.
References Aleph::and, and MOD.
Referenced by Aleph::NTT< MOD, ROOT >::supports_bluestein_size(), and Aleph::NTT< MOD, ROOT >::validate_root_order().
|
inlinestaticconstexprnoexcept |
Check whether a transform size is supported.
| n | Candidate transform size. |
true iff n is a positive power of two within the modulus limit. Definition at line 1668 of file ntt.H.
References Aleph::and, Aleph::divide_and_conquer_partition_dp(), Aleph::NTT< MOD, ROOT >::supports_bluestein_size(), and Aleph::NTT< MOD, ROOT >::supports_power_of_two_size().
Referenced by Aleph::NTT< MOD, ROOT >::multiply(), Aleph::NTT< MOD, ROOT >::pmultiply(), and Aleph::NTT< MOD, ROOT >::validate_supported_size().
|
inlinestaticprivate |
Definition at line 1476 of file ntt.H.
References ah_invalid_argument_if, ah_runtime_error_if, Aleph::and, Aleph::divide_and_conquer_partition_dp(), m, MOD, Aleph::mod_exp(), Aleph::mod_mul(), r, and Aleph::NTT< MOD, ROOT >::root.
Referenced by Aleph::NTT< MOD, ROOT >::poly_sqrt().
|
inlinestatic |
In-place forward or inverse transform.
| a | Input/output array. |
| invert | If true, computes the inverse NTT. |
Definition at line 1699 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::Array< T >::size(), and Aleph::NTT< MOD, ROOT >::Plan::transform().
Referenced by Aleph::NTT< MOD, ROOT >::transformed().
|
inlinestatic |
Sequential batch transform for equal-sized inputs.
| batch | Batch of arrays. All items must have the same supported size. |
| invert | If true, computes inverse transforms. |
Definition at line 1833 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::size(), and Aleph::NTT< MOD, ROOT >::Plan::transform_batch().
|
inlinestatic |
Transform an input array and return the result.
| input | Input array. |
| invert | If true, computes the inverse NTT. |
input. Definition at line 1712 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), output, and Aleph::NTT< MOD, ROOT >::transform().
|
inlinestatic |
Return a transformed copy of an entire batch.
| batch | Batch of arrays. All items must have the same supported size. |
| invert | If true, computes inverse transforms. |
Definition at line 1850 of file ntt.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::size(), and Aleph::NTT< MOD, ROOT >::Plan::transformed_batch().
|
inlinestaticprivate |
Definition at line 1312 of file ntt.H.
References Aleph::and, Aleph::divide_and_conquer_partition_dp(), Aleph::Array< T >::get_last(), Aleph::Array< T >::is_empty(), MOD, and Aleph::Array< T >::remove_last().
Referenced by Aleph::NTT< MOD, ROOT >::normalize_poly(), Aleph::NTT< MOD, ROOT >::poly_add_normalized(), Aleph::NTT< MOD, ROOT >::poly_divmod(), and Aleph::NTT< MOD, ROOT >::poly_sub_normalized().
|
inlinestaticprivate |
Definition at line 1350 of file ntt.H.
References Aleph::and, Aleph::divide_and_conquer_partition_dp(), MOD, output, and Aleph::Array< T >::reserve().
Referenced by Aleph::NTT< MOD, ROOT >::poly_divmod(), Aleph::NTT< MOD, ROOT >::poly_inverse(), Aleph::NTT< MOD, ROOT >::poly_log(), Aleph::NTT< MOD, ROOT >::poly_mul_trunc(), Aleph::NTT< MOD, ROOT >::poly_power(), and Aleph::NTT< MOD, ROOT >::poly_sqrt().
|
inlinestaticprivate |
Definition at line 1572 of file ntt.H.
References ah_invalid_argument_if, MOD, and Aleph::Array< T >::size().
Referenced by Aleph::NTT< MOD, ROOT >::interpolate().
|
inlinestaticprivate |
Definition at line 250 of file ntt.H.
References ah_invalid_argument_if, Aleph::divide_and_conquer_partition_dp(), MOD, and Aleph::NTT< MOD, ROOT >::supports_root_order().
Referenced by Aleph::NTT< MOD, ROOT >::Plan::initialize_bluestein_plan().
|
inlinestaticprivate |
Definition at line 267 of file ntt.H.
References ah_invalid_argument_if, Aleph::divide_and_conquer_partition_dp(), Aleph::NTT< MOD, ROOT >::max_transform_size(), MOD, and Aleph::NTT< MOD, ROOT >::supports_size().
Referenced by Aleph::NTT< MOD, ROOT >::Plan::Plan(), Aleph::NTT< MOD, ROOT >::multiply(), Aleph::NTT< MOD, ROOT >::pmultiply(), and Aleph::NTT< MOD, ROOT >::primitive_root_of_unity().
Definition at line 1330 of file ntt.H.
References Aleph::Array< T >::create(), and output.
Referenced by Aleph::NTT< MOD, ROOT >::poly_add_series(), Aleph::NTT< MOD, ROOT >::poly_inverse(), Aleph::NTT< MOD, ROOT >::poly_log(), Aleph::NTT< MOD, ROOT >::poly_mul_trunc(), Aleph::NTT< MOD, ROOT >::poly_power(), Aleph::NTT< MOD, ROOT >::poly_scalar_mul_series(), Aleph::NTT< MOD, ROOT >::poly_sqrt(), Aleph::NTT< MOD, ROOT >::poly_sub_series(), and Aleph::NTT< MOD, ROOT >::series_prefix().
|
staticconstexprprivate |
Definition at line 144 of file ntt.H.
Referenced by Aleph::NTT< MOD, ROOT >::Plan::apply_scalar_butterfly_range(), Aleph::NTT< MOD, ROOT >::Plan::initialize_power_of_two_plan(), Aleph::NTT< MOD, ROOT >::Plan::initialize_twiddles(), Aleph::NTT< MOD, ROOT >::Plan::lift_input(), Aleph::NTT< MOD, ROOT >::Plan::lower_output(), Aleph::NTT< MOD, ROOT >::Plan::multiply_impl(), and Aleph::NTT< MOD, ROOT >::Plan::scale_inverse().
Definition at line 331 of file ntt.H.
Referenced by Aleph::NTT< MOD, ROOT >::tonelli_shanks().