예제 #1
0
/**
 * put matrix vectors to list
 */
template <class ZT, class F> void GaussSieve<ZT, F>::add_mat_list(ZZ_mat<ZT> &B)
{
  Z_NR<ZT> t, current_norm;
  dot_product(best_sqr_norm, B[0], B[0]);
  ListPoint<ZT> *p;

  for (int i = 0; i < nr; ++i)
  {
    p = new_listpoint<ZT>(nc);
    matrix_row_to_list_point(B[i], p);

    // cout << "# [info] init: additing point ";
    // cout << p->v << endl;

    if (alg == 3)
      current_norm = update_p_3reduce(p);
    else if (alg == 2)
      current_norm = update_p_2reduce(p);
    else if (alg == 4)
      current_norm = update_p_4reduce(p);
    else
    {
      cout << " Error, only support 2-, 3- and 4-sieve" << endl;
      exit(1);
    }

    if ((current_norm < best_sqr_norm) && (current_norm > 0))
      // if ((current_norm < best_sqr_norm) )
      best_sqr_norm = current_norm;
  }
}
예제 #2
0
/**
 * 4-sieve
 */
template <class ZT, class F> bool GaussSieve<ZT, F>::run_4sieve()
{

  ListPoint<ZT> *current_point;
  NumVect<Z_NR<ZT>> vec(nc);
  Z_NR<ZT> current_norm;

  /* main iteration */
  while ((best_sqr_norm > target_sqr_norm) && (collisions < mult * max_list_size + 200))
  {
    iterations++;
    max_list_size = max(max_list_size, long(List.size()));

    if (Queue.empty())
    {
      vec           = Sampler->sample();
      current_point = num_vec_to_list_point(vec, nc);
      samples++;
    }
    else
    {
      current_point = Queue.front();
      Queue.pop();
    }

    current_norm = update_p_4reduce(current_point);

#if 0
    if (!check_4reduce_order_list<ZT>(List)) {
      cout << "!!! Failed " << endl;
      //print_list(List);
      exit(1);
    }
    else {
      cout << "[check 4-red] OK " << endl;
      //print_list(List);
    }
#endif

    if (current_norm == 0)
      collisions++;
    if (current_norm > 0 && current_norm < best_sqr_norm)
    {
      best_sqr_norm = current_norm;
    }

#if 1
    print_curr_info();
#endif

    /* tuples of (iters, max_list_size) */
    iters_norm.push_back(best_sqr_norm);
    iters_ls.push_back(max_list_size);
  }

  /* finished main procedure, output some information */
  print_final_info();

#ifdef DEBUG_CHECK_4RED
  if (check_4reduce_order_list<ZT>(List))
    cout << "# [info] check 4-reduced OK" << endl;
  else
    cout << "# Error: check 4-reduced not OK" << endl;
#endif
  // print_list(List);

  if (best_sqr_norm > target_sqr_norm)
    return false;
  return true;
}