|
algebramix_doc 0.3
|
#include <crt_int.hpp>
Definition at line 195 of file crt_int.hpp.
Definition at line 209 of file crt_int.hpp.
References mmx::C, mmx::is_prime(), M, mmx::N(), and mmx::value().
{
// construct prime moduli of s bits exactly,
// starting with those which have a maximal number of
// primitive 2^k-th roots of unity
typedef modulus<C,V> M;
const nat b= V::template maximum_size_helper<C>::value;
ASSERT (s <= b, "bitsize overflow");
ASSERT (b <= 8 * sizeof (nat), "bitsize overflow");
if (s < 2 && n > 0) return false;
const C m= 1 + MMX_SAFE_LEFT_SHIFT_INT (C, 1, (s-1));
const C l= MMX_SAFE_LEFT_SHIFT_INT (C, 1, s);
for (nat i= N(v); i < n; i++) {
C j= i == 0 ? m : (bit_reverse (* v[i-1], s) + 2), k;
for (; j <= l - 1 && j >= m; j += 2)
if (is_prime (k= bit_reverse (j, s))) break;
if (j > l - 1 || j < m) return false;
v << M(k); }
return true; }