Esempio n. 1
0
static void			do_redir(t_token **token, t_process **current,
							t_process **process)
{
	char			state;

	state = check_state(*token);
	if (state == 3 || state == 4)
		*process = process_lst_add(*process, (*token)->next->next->str);
	else if (state == 5)
		*process = process_lst_add(*process,
				(*token)->next->next->next->next->str);
	else if (state == 6 || state == 7)
		*process = process_lst_add(*process, "cat");
	*current = get_last_process(*process);
	*current = update_fd(*token, current);
	if (state == 2 || state == 6 || state == 5 || state == 3)
		*token = (*token)->next->next;
	else if (state == 4)
		*token = (*token)->next->next->next;
	if (state == 2 || state == 6 || state == 5 || state == 4)
		*current = update_fd(*token, current);
	if (state == 5)
		*token = (*token)->next;
	*token = ((*token)->next) ? (*token)->next->next : (*token)->next;
}
Esempio n. 2
0
int
pm1_rootsG (mpz_t f, listz_t G, unsigned long dF, pm1_roots_state_t *state, 
            listz_t t, mpmod_t modulus)
{
  unsigned long i;
  unsigned long muls = 0, gcds = 0;
  unsigned int st;
  progression_params_t *params = &(state->params); /* for less typing */
  
  outputf (OUTPUT_TRACE,
	   "pm1_rootsG: dF = %d, state: size_fd = %d, nr = %d, S = %d\n",
	   dF, params->size_fd, params->nr, params->S);
  
  st = cputime ();
  
  for (i = 0; i < dF;)
    {
      /* Did we use every progression since the last update? */
      if (params->next == params->nr)
        {
          /* Yes, time to update again */
	  outputf (OUTPUT_TRACE, "pm1_rootsG: Updating table at rsieve = %d\n",
		   params->rsieve);
          update_fd (state->fd, params->nr, params->S, modulus, &muls);
          params->next = 0;
        }
      
      /* Is this a root we should skip? (Take only if gcd == 1) */
      if (gcd (params->rsieve, params->dsieve) == 1)
        {
	  outputf (OUTPUT_TRACE,
		   "pm1_rootsG: Taking root G[%d] at rsieve = %d\n",
		   i, params->rsieve);
          mpres_get_z (G[i++], state->fd[params->next * (params->S + 1)], 
		       modulus);
        }
      else
	outputf (OUTPUT_TRACE, "pm1_rootsG: Skipping root at rsieve = %d\n",
		 params->rsieve);
      
      params->next ++;
      params->rsieve ++;
    }
  
  if (state->invtrick)
    {
      if (list_invert (t, G, dF, t[dF], modulus)) 
        {
	  outputf (OUTPUT_VERBOSE,
		   "Found factor while inverting G[0]*..*G[d]\n");
          mpz_set (f, t[dF]);
          return ECM_FACTOR_FOUND_STEP2;
        }

      muls += 3 * (dF - 1);
      gcds ++;
      
      for (i = 0; i < dF; i++) 
        {
          mpz_add (G[i], G[i], t[i]);
          mpz_mod (G[i], G[i], modulus->orig_modulus);
        }
    }
  
  outputf (OUTPUT_VERBOSE, "Computing roots of G took %ldms",
	   elltime (st, cputime ()));
  outputf (OUTPUT_DEVVERBOSE, ", %lu muls and %lu extgcds", muls, gcds);
  outputf (OUTPUT_VERBOSE, "\n");
  
  return ECM_NO_FACTOR_FOUND;
}
Esempio n. 3
0
int
pm1_rootsF (mpz_t f, listz_t F, root_params_t *root_params, 
            unsigned long dF, mpres_t *x, listz_t t, mpmod_t modulus)
{
  unsigned long i;
  unsigned long muls = 0, gcds = 0;
  long st, st1;
  pm1_roots_state_t state;
  progression_params_t *params = &state.params; /* for less typing */
  listz_t coeffs;
  mpz_t ts;

  if (dF == 0)
    return 0;

  st = cputime ();

  /* Relative cost of point add during init and computing roots assumed =1 */
  init_roots_params (&state.params, root_params->S, root_params->d1, 
		     root_params->d2, 1.0);

  /* The invtrick is profitable for x^S, S even and > 6. Does not work for 
     Dickson polynomials (root_params->S < 0)! */
  if (root_params->S > 6 && (root_params->S & 1) == 0)
    {
      state.invtrick = 1;
      params->S /= 2;
      params->size_fd = params->nr * (params->S + 1);
    }
  else
    state.invtrick = 0;

  outputf (OUTPUT_DEVVERBOSE, 
	   "pm1_rootsF: state: nr = %d, dsieve = %d, size_fd = %d, S = %d, "
	   "dickson_a = %d, invtrick = %d\n", params->nr, params->dsieve, 
	   params->size_fd, params->S, params->dickson_a, state.invtrick);

  /* Init finite differences tables */
  mpz_init (ts); /* ts = 0 */
  coeffs = init_progression_coeffs (ts, params->dsieve, root_params->d2, 
				    1, 6, params->S, params->dickson_a);
  mpz_clear (ts);

  if (coeffs == NULL)
    return ECM_ERROR;

  /* Allocate memory for fd[] and compute x^coeff[]*/
  state.fd = (mpres_t *) malloc (params->size_fd * sizeof (mpres_t));
  if (state.fd == NULL)
    {
      clear_list (coeffs, params->size_fd);
      return ECM_ERROR;
    }

  for (i = 0; i < params->size_fd; i++) 
    {
      outputf (OUTPUT_TRACE, "pm1_rootsF: coeffs[%d] = %Zd\n", i, coeffs[i]);
      mpres_init (state.fd[i], modulus);
      /* The highest coefficient of all progressions is identical */
      if (i > params->S + 1 && i % (params->S + 1) == params->S)
	{
	  ASSERT (mpz_cmp (coeffs[i], coeffs[params->S]) == 0);
	  mpres_set (state.fd[i], state.fd[params->S], modulus);
	}
      else
        mpres_pow (state.fd[i], *x, coeffs[i], modulus);
    }

  clear_list (coeffs, params->size_fd);
  coeffs = NULL;
  
  st1 = cputime ();
  outputf (OUTPUT_VERBOSE,
	   "Initializing table of differences for F took %ldms\n",
	   elltime (st, st1));
  st = st1;

  /* Now for the actual calculation of the roots. */
  for (i = 0; i < dF;)
    {
      /* Is this a rsieve value where we computed x^Dickson(j * d2) ? */
      if (gcd (params->rsieve, params->dsieve) == 1)
        {
          /* Did we use every progression since the last update? */
          if (params->next == params->nr)
            {
              /* Yes, time to update again */
              update_fd (state.fd, params->nr, params->S, modulus, 
			 &muls);
              params->next = 0;
            }
          
          /* Is this a j value where we want x^Dickson(j * d2) as a root? */
          if (gcd (params->rsieve, root_params->d1) == 1)
            mpres_get_z (F[i++], state.fd[params->next * (params->S + 1)], 
                         modulus);
          params->next ++;
        }
      params->rsieve += 6;
    }

  for (i = 0; i < params->size_fd; i++)
    mpres_clear (state.fd[i], modulus);
  free (state.fd);
  state.fd = NULL;

  if (state.invtrick)
    {
      if (list_invert (t, F, dF, t[dF], modulus)) 
        {
          /* Should never happen */
	  outputf (OUTPUT_ERROR, 
		   "Found factor unexpectedly while inverting F[0]*..*F[dF]\n");
          mpz_set (f, t[dF]);
          return ECM_FACTOR_FOUND_STEP2;
        }
      
      muls += 3 * (dF - 1);
      gcds ++;
      
      for (i = 0; i < dF; i++) 
        {
          mpz_add (F[i], F[i], t[i]);
          mpz_mod (F[i], F[i], modulus->orig_modulus);
        }
    }
  
  outputf (OUTPUT_VERBOSE, "Computing roots of F took %ldms",
	   elltime (st, cputime ()));
  outputf (OUTPUT_DEVVERBOSE, ", %lu muls and %lu extgcds", muls, gcds);
  outputf (OUTPUT_VERBOSE, "\n");
  
  return ECM_NO_FACTOR_FOUND;
}