mpqsPolynom.H

Go to the documentation of this file.
00001 #ifndef mpqsPolynom_header
00002 #define mpqsPolynom_header
00003 
00014 #include <iosfwd>
00015 #include <gmp.h>
00016 #include "utils.H"
00017 #include "mpz_wrapper.H"
00018 using namespace my_mpz_wrapper;
00019 #include "modulo.H"
00020 
00021 using std::ostream;
00022 using std::istream;
00023 
00024 using std::cout;
00025 using std::cerr;
00026 
00027 
00037 extern bool collecting_phase_finished;
00038 
00039 extern const int SingleLargePrime_Threshold;
00040 extern double Factor_Threshold;
00041 
00042 class CmpqsPolynom
00043 {
00044   /* Implementation of polynomial calculations for MPQS.
00045      Notation of variables is similar to the one given in
00046      "The Multiple Polynomial Quadratic Sieve",
00047      Robert D. Silverman,
00048      Mathematics Of Computation, Vol. 48, January 1987, p. 329-339
00049   */  
00050 private:
00051   mpz_t A,B,C,D,h0,h1,h2;
00052   mpz_t kN, kN_div2, D2_inv_mod_kN;
00053   mpz_t A2;
00054   mpz_t A_div_D_mod_kN, B_div_2D_mod_kN;
00055 public:
00056   inline CmpqsPolynom() // constructor
00057     {
00058       mpz_init(A); mpz_init(B); mpz_init(C); mpz_init(D);
00059       mpz_init(h0); mpz_init(h1); mpz_init(h2);
00060       mpz_init(kN); mpz_init(kN_div2); mpz_init(D2_inv_mod_kN);
00061       mpz_init(A2);
00062       mpz_init(A_div_D_mod_kN); mpz_init(B_div_2D_mod_kN);
00063     }
00064   inline ~CmpqsPolynom() // destructor
00065     {
00066       mpz_clear(A); mpz_clear(B); mpz_clear(C); mpz_clear(D);
00067       mpz_clear(h0); mpz_clear(h1); mpz_clear(h2);
00068       mpz_clear(kN); mpz_clear(kN_div2); mpz_clear(D2_inv_mod_kN);
00069       mpz_clear(A2);
00070       mpz_clear(A_div_D_mod_kN); mpz_clear(B_div_2D_mod_kN);
00071     }
00072   void compute_first_polynomial(const mpz_t fuer_kN, const int M);
00073   void compute_next_polynomial(const int step=0);
00074   void get_values(const signed int SievePos, mpz_t radix, mpz_t Q) const;
00075   double get_logval(const signed int SievePos) const;
00076   void SanityCheck(const signed int SievePos=0);
00077   void save(ostream &ostr); // for Recovery etc.
00078   void load(istream &in); // for Recovery etc.
00079   void load_if_available(istream &in); // for Recovery etc.
00080   inline bool operator < (const mpz_t K) const 
00081     {
00082       return mpz_cmp(D, K)<0;
00083     }
00084 
00085   // some helper functions to provide read-only access to internal parameters
00086   inline unsigned int get_A2_mod(const unsigned int m) const
00087    {
00088      // A2 := A*2 = 2*D^2
00089      unsigned int h = numtheory::squaremod(mpz_remainder_ui(D,m),m)<<1;
00090      if (h>=m) h-=m;
00091      return h;
00092    }
00093   inline const mpz_t& get_A2() const { return A2; }
00094   inline const mpz_t& get_B() const { return B; }
00095   inline const mpz_t& get_D() const { return D; }
00096 };
00097 
00098 #endif

Generated on Wed Nov 7 23:29:25 2007 for Qsieve by  doxygen 1.5.4