How to speed up a cyclotomic polynomial inversion in NTL?

时间:2016-07-11 22:14:39

标签: inverse polynomials ntl

I'm computing polynomial modular inverses in a ring built over the nth-cyclotomic polynomial, with n power of 2. These inverses are computed for polynomials with the coefficient of x^0 equal to (x+1) and others sampled from some random distribution but always equal 0 or x, for some integer x.

I'm able to use NTL's InvMod to compute the inverse of several polynomials, however for big instances of the described ones it took just forever to return. I did compiled NTL 9.10.0 with GMP 6.1.1. Is there any optimization I can use on NTL to solve this operations faster?

This is a minimum code:

#include <NTL/ZZ_p.h>
#include <NTL/ZZ_pEX.h>
#include <ctime>

NTL_CLIENT

int main(){

    int degree = 4095;
    int nphi = 8192;
    int nq = 127;

    // Sets q as the mersenne prime 2^nq - 1
    ZZ q = NTL::power2_ZZ(nq) - 1;
    ZZ_p::init(q);

    // Sets phi as the n-th cyclotomic polynomial
    ZZ_pX ring;
    NTL::SetCoeff(ring,0,1);
    NTL::SetCoeff(ring,nphi/2,1);
    ZZ_pE::init(ring);

    ZZ_pEX ntl_phi;
    NTL::SetCoeff(ntl_phi,0,conv<ZZ_p>(1));
    NTL::SetCoeff(ntl_phi,nphi/2,conv<ZZ_p>(1));

    // Initializes f
    std::srand(std::time(0)); // use current time as seed for random generator

    ZZ_pEX f;
    NTL::SetCoeff(f,0,conv<ZZ_p>(1025));
    for(int i = 1; i <= degree; i++){
        int random_variable = std::rand();
        NTL::SetCoeff(f,i,conv<ZZ_p>(1024*(random_variable%2 == 1)));
    }

    // Computes the inverse of f
    ZZ_pEX fInv = NTL::InvMod(f, ntl_phi);

    return 0;
}

0 个答案:

没有答案