Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::NTT< MOD, ROOT > Class Template Reference

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 charsimd_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 charsimd_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_ttransformed (const Array< uint64_t > &input, const bool invert=false)
 Transform an input array and return the result.
 
static Array< uint64_tmultiply (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_tnegacyclic_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_tptransformed (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_tpmultiply (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_tpoly_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 > &dividend, const Array< uint64_t > &divisor)
 Polynomial division with remainder modulo MOD.
 
static Array< uint64_tpoly_log (const Array< uint64_t > &coeffs, const size_t n)
 Formal polynomial logarithm modulo x^n.
 
static Array< uint64_tpoly_exp (const Array< uint64_t > &coeffs, const size_t n)
 Formal polynomial exponential modulo x^n.
 
static Array< uint64_tpoly_sqrt (const Array< uint64_t > &coeffs, const size_t n)
 Formal polynomial square root modulo x^n.
 
static Array< uint64_tpoly_power (const Array< uint64_t > &coeffs, const uint64_t k, const size_t n)
 Formal polynomial power modulo x^n.
 
static Array< uint64_tmultipoint_eval (const Array< uint64_t > &coeffs, const Array< uint64_t > &points)
 Evaluate a polynomial on multiple points modulo MOD.
 
static Array< uint64_tinterpolate (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_tbigint_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_tpbigint_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 Member Functions

static constexpr bool is_power_of_two (const size_t n) noexcept
 
static constexpr uint64_t add_mod (const uint64_t lhs, const uint64_t rhs) noexcept
 
static constexpr uint64_t sub_mod (const uint64_t lhs, const uint64_t rhs) noexcept
 
static constexpr bool simd_mod_supported () noexcept
 
static constexpr uint64_t pow_mod_constexpr (uint64_t base, uint64_t exp) noexcept
 
static constexpr uint64_t max_transform_size_impl () noexcept
 
static constexpr bool supports_power_of_two_size (const size_t n) noexcept
 
static constexpr bool supports_root_order (const uint64_t order) noexcept
 
static constexpr bool supports_bluestein_size (const size_t n) noexcept
 
static void validate_root_order (const uint64_t order, const char *const ctx)
 
static constexpr uint64_t primitive_root_of_order (const uint64_t order)
 
static void validate_supported_size (const size_t n, const char *const ctx)
 
static size_t next_power_of_two (size_t n, const char *const ctx)
 
static Array< uint64_tpadded_copy (const Array< uint64_t > &input, const size_t n)
 
static Array< uint64_tprefix_copy (const Array< uint64_t > &input, const size_t length)
 
static constexpr const charsimd_preference_name (const SimdPreference preference) noexcept
 
static SimdPreference simd_preference () noexcept
 
static NTTSimdBackend detected_simd_backend () noexcept
 
static void trim_trailing_zeros (Array< uint64_t > &poly)
 
static Array< uint64_tnormalize_poly (const Array< uint64_t > &input)
 
static Array< uint64_tzero_series (const size_t n)
 
static Array< uint64_tseries_prefix (const Array< uint64_t > &input, const size_t n)
 
static Array< uint64_ttruncate_poly (const Array< uint64_t > &input, const size_t n)
 
static Array< uint64_treverse_poly (const Array< uint64_t > &input)
 
static Array< uint64_tpoly_add_series (const Array< uint64_t > &lhs, const Array< uint64_t > &rhs, const size_t n)
 
static Array< uint64_tpoly_sub_series (const Array< uint64_t > &lhs, const Array< uint64_t > &rhs, const size_t n)
 
static Array< uint64_tpoly_add_normalized (const Array< uint64_t > &lhs, const Array< uint64_t > &rhs)
 
static Array< uint64_tpoly_sub_normalized (const Array< uint64_t > &lhs, const Array< uint64_t > &rhs)
 
static Array< uint64_tpoly_scalar_mul_series (const Array< uint64_t > &input, const uint64_t scalar, const size_t n)
 
static Array< uint64_tpoly_mul_trunc (const Array< uint64_t > &lhs, const Array< uint64_t > &rhs, const size_t n)
 
static Array< uint64_tpoly_derivative (const Array< uint64_t > &coeffs)
 
static Array< uint64_tpoly_integral (const Array< uint64_t > &coeffs)
 
static uint64_t tonelli_shanks (const uint64_t value, const char *const ctx)
 
static Array< Array< uint64_t > > make_product_tree_storage (const size_t count)
 
static void build_product_tree (Array< Array< uint64_t > > &tree, const Array< uint64_t > &points, const size_t node, const size_t left, const size_t right)
 
static void validate_distinct_points (const Array< uint64_t > &points, const char *const ctx)
 
static Array< uint64_tpoly_mod (const Array< uint64_t > &dividend, const Array< uint64_t > &divisor)
 
static void multipoint_eval_recursive (const Array< Array< uint64_t > > &tree, const Array< uint64_t > &poly, Array< uint64_t > &output, const size_t node, const size_t left, const size_t right)
 
static Array< uint64_tinterpolate_recursive (const Array< Array< uint64_t > > &tree, const Array< uint64_t > &scaled_values, const size_t node, const size_t left, const size_t right)
 

Static Private Attributes

static constexpr MontgomeryCtx mctx_ = montgomery_ctx_for_mod<MOD>()
 

Detailed Description

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
class Aleph::NTT< MOD, ROOT >

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:

  • power-of-two transforms
  • Bluestein-based transforms for supported non-power-of-two sizes
  • AVX2/NEON runtime dispatch on the power-of-two butterfly path
  • reusable plans
  • batch transforms
  • explicit ThreadPool parallelism
  • fast polynomial multiplication modulo MOD
  • exact big-integer multiplication over base-B digits
  • negacyclic convolution modulo x^N + 1

    Template Parameters
    MODPrime modulus with a sufficiently large power-of-two factor in MOD - 1.
    ROOTPrimitive root modulo MOD.

Definition at line 114 of file ntt.H.

Member Enumeration Documentation

◆ NTTSimdBackend

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
enum class Aleph::NTT::NTTSimdBackend
strong

SIMD backends available to the NTT butterfly core.

Enumerator
scalar 

Portable scalar implementation.

avx2 

x86-64 AVX2 grouped butterfly path.

neon 

AArch64 NEON grouped butterfly path.

Definition at line 122 of file ntt.H.

◆ Representation

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
enum class Aleph::NTT::Representation
strongprivate
Enumerator
standard 
montgomery 

Definition at line 138 of file ntt.H.

◆ SimdPreference

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
enum class Aleph::NTT::SimdPreference
strongprivate
Enumerator
automatic 
scalar_only 
avx2_only 
neon_only 

Definition at line 130 of file ntt.H.

Member Function Documentation

◆ add_mod()

◆ avx2_dispatch_available()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static bool Aleph::NTT< MOD, ROOT >::avx2_dispatch_available ( )
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().

◆ bigint_multiply()

template<uint64_t MOD, uint64_t ROOT>
template<uint64_t Base>
Array< uint64_t > Aleph::NTT< MOD, ROOT >::bigint_multiply ( const Array< uint64_t > &  a,
const Array< uint64_t > &  b 
)
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:

  • if 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 used
  • otherwise it falls back to NTTExact, then propagates carries
Template Parameters
BaseDigit base, must be at least 2.
Parameters
aFirst integer digits.
bSecond integer digits.
Returns
Exact product digits in base Base.
Exceptions
std::invalid_argumentif 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().

◆ build_product_tree()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static void Aleph::NTT< MOD, ROOT >::build_product_tree ( Array< Array< uint64_t > > &  tree,
const Array< uint64_t > &  points,
const size_t  node,
const size_t  left,
const size_t  right 
)
inlinestaticprivate

◆ detected_simd_backend()

◆ interpolate()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::interpolate ( const Array< uint64_t > &  points,
const Array< uint64_t > &  values 
)
inlinestatic

Interpolate a polynomial from point-value samples modulo MOD.

Parameters
pointsSample points.
valuesSample values.
Returns
Unique polynomial of degree < points.size() passing through all pairs.
Exceptions
std::invalid_argumentif 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().

◆ interpolate_recursive()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::interpolate_recursive ( const Array< Array< uint64_t > > &  tree,
const Array< uint64_t > &  scaled_values,
const size_t  node,
const size_t  left,
const size_t  right 
)
inlinestaticprivate

◆ is_power_of_two()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static constexpr bool Aleph::NTT< MOD, ROOT >::is_power_of_two ( const size_t  n)
inlinestaticconstexprprivatenoexcept

◆ make_product_tree_storage()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< Array< uint64_t > > Aleph::NTT< MOD, ROOT >::make_product_tree_storage ( const size_t  count)
inlinestaticprivate

◆ max_transform_size()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static constexpr uint64_t Aleph::NTT< MOD, ROOT >::max_transform_size ( )
inlinestaticconstexprnoexcept

Maximum supported power-of-two transform size.

Returns
Largest 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().

◆ max_transform_size_impl()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static constexpr uint64_t Aleph::NTT< MOD, ROOT >::max_transform_size_impl ( )
inlinestaticconstexprprivatenoexcept

◆ multiply()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::multiply ( const Array< uint64_t > &  a,
const Array< uint64_t > &  b 
)
inlinestatic

◆ multiply_inplace()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static void Aleph::NTT< MOD, ROOT >::multiply_inplace ( Array< uint64_t > &  a,
const Array< uint64_t > &  b 
)
inlinestatic

Replace a by the product a * b.

Parameters
aLeft polynomial, overwritten with the product.
bRight polynomial.

Definition at line 1756 of file ntt.H.

References Aleph::NTT< MOD, ROOT >::multiply().

◆ multipoint_eval()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::multipoint_eval ( const Array< uint64_t > &  coeffs,
const Array< uint64_t > &  points 
)
inlinestatic

◆ multipoint_eval_recursive()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static void Aleph::NTT< MOD, ROOT >::multipoint_eval_recursive ( const Array< Array< uint64_t > > &  tree,
const Array< uint64_t > &  poly,
Array< uint64_t > &  output,
const size_t  node,
const size_t  left,
const size_t  right 
)
inlinestaticprivate

◆ negacyclic_multiply()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::negacyclic_multiply ( const Array< uint64_t > &  a,
const Array< uint64_t > &  b 
)
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.

Parameters
aFirst polynomial coefficients, size N.
bSecond polynomial coefficients, size N.
Returns
Negacyclic product of size N.
Exceptions
std::invalid_argumentif 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().

◆ neon_dispatch_available()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static bool Aleph::NTT< MOD, ROOT >::neon_dispatch_available ( )
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().

◆ next_power_of_two()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static size_t Aleph::NTT< MOD, ROOT >::next_power_of_two ( size_t  n,
const char *const  ctx 
)
inlinestaticprivate

◆ normalize_poly()

◆ padded_copy()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::padded_copy ( const Array< uint64_t > &  input,
const size_t  n 
)
inlinestaticprivate

◆ pbigint_multiply()

template<uint64_t MOD, uint64_t ROOT>
template<uint64_t Base>
Array< uint64_t > Aleph::NTT< MOD, ROOT >::pbigint_multiply ( ThreadPool pool,
const Array< uint64_t > &  a,
const Array< uint64_t > &  b,
const size_t  chunk_size = 0 
)
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.

Template Parameters
BaseDigit base, must be at least 2.
Parameters
poolThread pool used for the convolution backend.
aFirst integer digits.
bSecond integer digits.
chunk_sizeParallel chunk size forwarded to the backend.
Returns
Exact product digits in base Base.
Exceptions
std::invalid_argumentif 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().

◆ pmultiply()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::pmultiply ( ThreadPool pool,
const Array< uint64_t > &  a,
const Array< uint64_t > &  b,
const size_t  chunk_size = 0 
)
inlinestatic

Parallel polynomial multiplication modulo MOD.

Parameters
poolThread pool used for transform stages and pointwise products.
aFirst polynomial.
bSecond polynomial.
chunk_sizeIterations per scheduled chunk (0 selects an automatic value).
Returns
Discrete convolution of 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().

◆ poly_add_normalized()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::poly_add_normalized ( const Array< uint64_t > &  lhs,
const Array< uint64_t > &  rhs 
)
inlinestaticprivate

◆ poly_add_series()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::poly_add_series ( const Array< uint64_t > &  lhs,
const Array< uint64_t > &  rhs,
const size_t  n 
)
inlinestaticprivate

◆ poly_derivative()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::poly_derivative ( const Array< uint64_t > &  coeffs)
inlinestaticprivate

◆ poly_divmod()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static std::pair< Array< uint64_t >, Array< uint64_t > > Aleph::NTT< MOD, ROOT >::poly_divmod ( const Array< uint64_t > &  dividend,
const Array< uint64_t > &  divisor 
)
inlinestatic

Polynomial division with remainder modulo MOD.

Parameters
dividendDividend coefficients in ascending degree order.
divisorDivisor coefficients in ascending degree order.
Returns
{quotient, remainder} with remainder.degree < divisor.degree.
Exceptions
std::invalid_argumentif 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().

◆ poly_eval()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static uint64_t Aleph::NTT< MOD, ROOT >::poly_eval ( const Array< uint64_t > &  coeffs,
const uint64_t  x 
)
inlinestatic

Evaluate a polynomial at a single point modulo MOD.

Parameters
coeffsPolynomial coefficients in ascending degree order.
xEvaluation point.
Returns
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().

◆ poly_exp()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::poly_exp ( const Array< uint64_t > &  coeffs,
const size_t  n 
)
inlinestatic

Formal polynomial exponential modulo x^n.

Parameters
coeffsInput polynomial with zero constant term.
nNumber of coefficients to compute.
Returns
exp(coeffs) mod x^n.
Exceptions
std::invalid_argumentif 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().

◆ poly_integral()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::poly_integral ( const Array< uint64_t > &  coeffs)
inlinestaticprivate

◆ poly_inverse()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::poly_inverse ( const Array< uint64_t > &  coeffs,
const size_t  n 
)
inlinestatic

Formal polynomial inverse modulo x^n.

Parameters
coeffsInput polynomial.
nNumber of coefficients to compute.
Returns
g such that coeffs * g ≡ 1 (mod x^n, MOD).
Exceptions
std::invalid_argumentif 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().

◆ poly_log()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::poly_log ( const Array< uint64_t > &  coeffs,
const size_t  n 
)
inlinestatic

Formal polynomial logarithm modulo x^n.

Parameters
coeffsInput polynomial with constant term 1.
nNumber of coefficients to compute.
Returns
ln(coeffs) mod x^n.
Exceptions
std::invalid_argumentif 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().

◆ poly_mod()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::poly_mod ( const Array< uint64_t > &  dividend,
const Array< uint64_t > &  divisor 
)
inlinestaticprivate

◆ poly_mul_trunc()

◆ poly_power()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::poly_power ( const Array< uint64_t > &  coeffs,
const uint64_t  k,
const size_t  n 
)
inlinestatic

Formal polynomial power modulo x^n.

Parameters
coeffsBase polynomial.
kNon-negative exponent.
nNumber of coefficients to compute.
Returns
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().

◆ poly_scalar_mul_series()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::poly_scalar_mul_series ( const Array< uint64_t > &  input,
const uint64_t  scalar,
const size_t  n 
)
inlinestaticprivate

◆ poly_sqrt()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::poly_sqrt ( const Array< uint64_t > &  coeffs,
const size_t  n 
)
inlinestatic

◆ poly_sub_normalized()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::poly_sub_normalized ( const Array< uint64_t > &  lhs,
const Array< uint64_t > &  rhs 
)
inlinestaticprivate

◆ poly_sub_series()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::poly_sub_series ( const Array< uint64_t > &  lhs,
const Array< uint64_t > &  rhs,
const size_t  n 
)
inlinestaticprivate

◆ pow_mod_constexpr()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static constexpr uint64_t Aleph::NTT< MOD, ROOT >::pow_mod_constexpr ( uint64_t  base,
uint64_t  exp 
)
inlinestaticconstexprprivatenoexcept

◆ prefix_copy()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::prefix_copy ( const Array< uint64_t > &  input,
const size_t  length 
)
inlinestaticprivate

◆ primitive_root_of_order()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static constexpr uint64_t Aleph::NTT< MOD, ROOT >::primitive_root_of_order ( const uint64_t  order)
inlinestaticconstexprprivate

◆ primitive_root_of_unity()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static constexpr uint64_t Aleph::NTT< MOD, ROOT >::primitive_root_of_unity ( const size_t  n)
inlinestaticconstexpr

Return an n-th primitive root of unity modulo MOD.

Parameters
nTransform length. It must be a supported power of two.
Returns
Primitive n-th root of unity in standard representation.
Exceptions
std::invalid_argumentif 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().

◆ ptransform()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static void Aleph::NTT< MOD, ROOT >::ptransform ( ThreadPool pool,
Array< uint64_t > &  a,
const bool  invert,
const size_t  chunk_size = 0 
)
inlinestatic

Parallel in-place transform using a ThreadPool.

Parameters
poolThread pool used for stage-level parallelism.
aInput/output array.
invertIf true, computes the inverse NTT.
chunk_sizeIterations 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().

◆ ptransform_batch()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static void Aleph::NTT< MOD, ROOT >::ptransform_batch ( ThreadPool pool,
Array< Array< uint64_t > > &  batch,
const bool  invert,
const size_t  chunk_size = 0 
)
inlinestatic

Parallel batch transform for equal-sized inputs.

Parameters
poolThread pool used for execution.
batchBatch of arrays. All items must have the same supported size.
invertIf true, computes inverse transforms.
chunk_sizeIterations 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().

◆ ptransformed()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::ptransformed ( ThreadPool pool,
const Array< uint64_t > &  input,
const bool  invert = false,
const size_t  chunk_size = 0 
)
inlinestatic

Parallel transform returning a new array.

Parameters
poolThread pool used for stage-level parallelism.
inputInput array.
invertIf true, computes the inverse NTT.
chunk_sizeIterations per scheduled chunk (0 selects an automatic value).
Returns
Transformed copy of input.

Definition at line 1886 of file ntt.H.

References Aleph::divide_and_conquer_partition_dp(), output, and Aleph::NTT< MOD, ROOT >::ptransform().

◆ reverse_poly()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::reverse_poly ( const Array< uint64_t > &  input)
inlinestaticprivate

◆ series_prefix()

◆ simd_backend()

◆ simd_backend_name() [1/2]

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static const char * Aleph::NTT< MOD, ROOT >::simd_backend_name ( )
inlinestaticnoexcept

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().

◆ simd_backend_name() [2/2]

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static constexpr const char * Aleph::NTT< MOD, ROOT >::simd_backend_name ( const NTTSimdBackend  backend)
inlinestaticconstexprnoexcept

◆ simd_mod_supported()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static constexpr bool Aleph::NTT< MOD, ROOT >::simd_mod_supported ( )
inlinestaticconstexprprivatenoexcept

◆ simd_preference()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static SimdPreference Aleph::NTT< MOD, ROOT >::simd_preference ( )
inlinestaticprivatenoexcept

◆ simd_preference_name()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static constexpr const char * Aleph::NTT< MOD, ROOT >::simd_preference_name ( const SimdPreference  preference)
inlinestaticconstexprprivatenoexcept

◆ sub_mod()

◆ supports_bluestein_size()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static constexpr bool Aleph::NTT< MOD, ROOT >::supports_bluestein_size ( const size_t  n)
inlinestaticconstexprprivatenoexcept

◆ supports_power_of_two_size()

◆ supports_root_order()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static constexpr bool Aleph::NTT< MOD, ROOT >::supports_root_order ( const uint64_t  order)
inlinestaticconstexprprivatenoexcept

◆ supports_size()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static constexpr bool Aleph::NTT< MOD, ROOT >::supports_size ( const size_t  n)
inlinestaticconstexprnoexcept

Check whether a transform size is supported.

Parameters
nCandidate transform size.
Returns
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().

◆ tonelli_shanks()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static uint64_t Aleph::NTT< MOD, ROOT >::tonelli_shanks ( const uint64_t  value,
const char *const  ctx 
)
inlinestaticprivate

◆ transform()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static void Aleph::NTT< MOD, ROOT >::transform ( Array< uint64_t > &  a,
const bool  invert 
)
inlinestatic

In-place forward or inverse transform.

Parameters
aInput/output array.
invertIf 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().

◆ transform_batch()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static void Aleph::NTT< MOD, ROOT >::transform_batch ( Array< Array< uint64_t > > &  batch,
const bool  invert 
)
inlinestatic

Sequential batch transform for equal-sized inputs.

Parameters
batchBatch of arrays. All items must have the same supported size.
invertIf 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().

◆ transformed()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< uint64_t > Aleph::NTT< MOD, ROOT >::transformed ( const Array< uint64_t > &  input,
const bool  invert = false 
)
inlinestatic

Transform an input array and return the result.

Parameters
inputInput array.
invertIf true, computes the inverse NTT.
Returns
Transformed copy of input.

Definition at line 1712 of file ntt.H.

References Aleph::divide_and_conquer_partition_dp(), output, and Aleph::NTT< MOD, ROOT >::transform().

◆ transformed_batch()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static Array< Array< uint64_t > > Aleph::NTT< MOD, ROOT >::transformed_batch ( const Array< Array< uint64_t > > &  batch,
const bool  invert = false 
)
inlinestatic

Return a transformed copy of an entire batch.

Parameters
batchBatch of arrays. All items must have the same supported size.
invertIf true, computes inverse transforms.
Returns
Transformed batch.

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().

◆ trim_trailing_zeros()

◆ truncate_poly()

◆ validate_distinct_points()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static void Aleph::NTT< MOD, ROOT >::validate_distinct_points ( const Array< uint64_t > &  points,
const char *const  ctx 
)
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().

◆ validate_root_order()

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
static void Aleph::NTT< MOD, ROOT >::validate_root_order ( const uint64_t  order,
const char *const  ctx 
)
inlinestaticprivate

◆ validate_supported_size()

◆ zero_series()

Member Data Documentation

◆ mctx_

◆ mod

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
constexpr uint64_t Aleph::NTT< MOD, ROOT >::mod = MOD
staticconstexpr

Definition at line 330 of file ntt.H.

◆ root

template<uint64_t MOD = 998244353ULL, uint64_t ROOT = 3ULL>
constexpr uint64_t Aleph::NTT< MOD, ROOT >::root = ROOT
staticconstexpr

Definition at line 331 of file ntt.H.

Referenced by Aleph::NTT< MOD, ROOT >::tonelli_shanks().


The documentation for this class was generated from the following file: