Ejemplo n.º 1
0
void
_nmod_poly_divrem_basecase_3(mp_ptr Q, mp_ptr R, mp_ptr W,
                             mp_srcptr A, slong lenA, mp_srcptr B, slong lenB,
                             nmod_t mod)
{
    const mp_limb_t invL = n_invmod(B[lenB - 1], mod.n);
    slong iR, i;
    mp_ptr B3 = W, R3 = W + 3*(lenB - 1), ptrQ = Q - lenB + 1;

    for (i = 0; i < lenB - 1; i++)
    {
        B3[3 * i] = B[i];
        B3[3 * i + 1] = 0;
        B3[3 * i + 2] = 0;
    }
    for (i = 0; i < lenA; i++)
    {
        R3[3 * i] = A[i];
        R3[3 * i + 1] = 0;
        R3[3 * i + 2] = 0;
    }

    for (iR = lenA - 1; iR >= lenB - 1; )
    {
        mp_limb_t r =
            n_lll_mod_preinv(R3[3 * iR + 2], R3[3 * iR + 1],
                             R3[3 * iR], mod.n, mod.ninv);

        while ((iR + 1 >= lenB) && (r == WORD(0)))
        {
            ptrQ[iR--] = WORD(0);
            if (iR + 1 >= lenB)
                r = n_lll_mod_preinv(R3[3 * iR + 2], R3[3 * iR + 1],
                                     R3[3 * iR], mod.n, mod.ninv);
        }

        if (iR + 1 >= lenB)
        {
            ptrQ[iR] = n_mulmod2_preinv(r, invL, mod.n, mod.ninv);

            if (lenB > 1)
            {
                const mp_limb_t c = n_negmod(ptrQ[iR], mod.n);
                mpn_addmul_1(R3 + 3 * (iR - lenB + 1), B3, 3 * lenB - 3, c);
            }
            iR--;
        }
    }

    for (iR = 0; iR < lenB - 1; iR++)
        R[iR] = n_lll_mod_preinv(R3[3 * iR + 2], R3[3 * iR + 1],
                                 R3[3 * iR], mod.n, mod.ninv);
}
Ejemplo n.º 2
0
void _nmod_poly_rem_basecase_3(mp_ptr R, mp_ptr W,
                               mp_srcptr A, long lenA, mp_srcptr B, long lenB,
                               nmod_t mod)
{
    if (lenB > 1)
    {
        const mp_limb_t invL = n_invmod(B[lenB - 1], mod.n);
        long iR, i;
        mp_ptr B3 = W, R3 = W + 3*(lenB - 1);

        for (i = 0; i < lenB - 1; i++)
        {
            B3[3 * i] = B[i];
            B3[3 * i + 1] = 0;
            B3[3 * i + 2] = 0;
        }
        for (i = 0; i < lenA; i++)
        {
            R3[3 * i] = A[i];
            R3[3 * i + 1] = 0;
            R3[3 * i + 2] = 0;
        }

        for (iR = lenA - 1; iR >= lenB - 1; iR--)
        {
            const mp_limb_t r = n_lll_mod_preinv(R3[3*iR + 2], R3[3*iR + 1],
                                                 R3[3*iR], mod.n, mod.ninv);

            if (r != 0)
            {
                const mp_limb_t q = n_mulmod2_preinv(r, invL, mod.n, mod.ninv);
                const mp_limb_t c = n_negmod(q, mod.n);
                mpn_addmul_1(R3 + 3 * (iR - lenB + 1), B3, 3 * lenB - 3, c);
            }
        }

        for (iR = 0; iR < lenB - 1; iR++)
            R[iR] = n_lll_mod_preinv(R3[3 * iR + 2], R3[3 * iR + 1],
                                     R3[3 * iR], mod.n, mod.ninv);
    }
}
Ejemplo n.º 3
0
void sample(void * arg, ulong count)
{
   mp_limb_t n, d, dinv, r = 0, norm;
   double dpre;
   info_t * info = (info_t *) arg;
   mp_bitcnt_t bits = info->bits;
   ulong type = info->type;
   ulong i;
   flint_rand_t state;
   flint_randinit(state);
      
   mp_ptr arr  = (mp_ptr) malloc(1024*sizeof(mp_limb_t));
   mp_ptr arr2 = (mp_ptr) malloc(1024*sizeof(mp_limb_t));
      
   for (i = 0; i < count; i++)
   {
      int j;
      d = n_randbits(state, bits);
      if (d == 0UL) d++;

      dinv = n_preinvert_limb(d);
      
      for (j = 0; j < 1024; j++)
      {
         arr[j] = n_randbits(state, FLINT_BITS);
         arr2[j] = n_randint(state, n);
      }

	  switch (type)
	  {
	  case 1:

         prof_start();
         for (mp_size_t j = 0; j < 10000UL; j++)
         {
            r += n_lll_mod_preinv(arr2[j&1023], arr[j&1023], arr[(j+1)&1023], d, dinv);  
         }
	     prof_stop();

	  break;
	  }

   }
  
   if (r == 9879875897UL) abort();

   flint_randclear(state);
   free(arr);
   free(arr2);
}
Ejemplo n.º 4
0
int main(void)
{
   int i, result;
   flint_rand_t state;
   
   printf("lll_mod_preinv....");
   fflush(stdout);

   flint_randinit(state);

   for (i = 0; i < 1000000; i++)
   {
      mp_limb_t d, dinv, nh, nm, nl, r1, r2, m;

      d = n_randtest_not_zero(state);
      m = n_randtest(state);
      nh = n_randint(state, d);
      nm = n_randtest(state);
      nl = n_randtest(state);
      
      dinv = n_preinvert_limb(d);

      r2 = n_lll_mod_preinv(nh, nm, nl, d, dinv);
      nm = n_ll_mod_preinv(nh, nm, d, dinv);
	  r1 = n_ll_mod_preinv(nm, nl, d, dinv);

      result = (r1 == r2);
      if (!result)
      {
         printf("FAIL:\n");
         printf("nh = %lu, nm = %ld, nl = %lu, d = %lu, dinv = %lu\n", nh, nm, nl, d, dinv); 
         printf("r1 = %lu, r2 = %lu\n", r1, r2);
         abort();
      }
   }

   flint_randclear(state);

   printf("PASS\n");
   return 0;
}
Ejemplo n.º 5
0
void
_nmod_poly_div_basecase_3(mp_ptr Q, mp_ptr W,
                             mp_srcptr A, long A_len, mp_srcptr B, long B_len,
                             nmod_t mod)
{
    long coeff, i, len;
    mp_limb_t lead_inv = n_invmod(B[B_len - 1], mod.n);
    mp_limb_t r_coeff;
    mp_ptr B3, R3;
    mp_srcptr Btop;
    
    B3 = W;
    for (i = 0; i < B_len - 1; i++)
    {
        B3[3 * i] = B[i];
        B3[3 * i + 1] = 0;
        B3[3 * i + 2] = 0;
    }
    Btop = B3 + 3*(B_len - 1);

    R3 = W + 3*(B_len - 1);
    for (i = 0; i < A_len - B_len + 1; i++)
    {
        R3[3 * i] = A[B_len + i - 1];
        R3[3 * i + 1] = 0;
        R3[3 * i + 2] = 0;
    }

    coeff = A_len - B_len;
    
    while (coeff >= 0)
    {
        r_coeff =
            n_lll_mod_preinv(R3[3 * coeff + 2], R3[3 * coeff + 1],
                             R3[3 * coeff], mod.n, mod.ninv);

        while (coeff >= 0 && r_coeff == 0L)
        {
            Q[coeff--] = 0L;
            if (coeff >= 0)
                r_coeff =
                    n_lll_mod_preinv(R3[3 * coeff + 2], R3[3 * coeff + 1],
                                     R3[3 * coeff], mod.n, mod.ninv);
        }

        if (coeff >= 0)
        {
            mp_limb_t c, * R_sub;

            Q[coeff] =
                n_mulmod2_preinv(r_coeff, lead_inv, mod.n, mod.ninv);

            c = n_negmod(Q[coeff], mod.n);

            len = FLINT_MIN(B_len - 1, coeff);
            R_sub = R3 + 3 * (coeff - len);
            if (len > 0)
                mpn_addmul_1(R_sub, Btop - 3*len, 3 * len, c);

            coeff--;
        }
    }
}