]> www.ginac.de Git - ginac.git/blobdiff - check/exam_cra.cpp
include <algorithm> for use of std::min().
[ginac.git] / check / exam_cra.cpp
index 2c6163eef65c9e410e13bc8fa776bf4d0d96d3c5..a20027d07437829f3c9b1520d6beb949c8ab4630 100644 (file)
@@ -1,14 +1,38 @@
-#include <iostream>
+/** @file exam_cra.cpp
+ *
+ *  Test of Chinese remainder algorithm. */
+
+/*
+ *  GiNaC Copyright (C) 1999-2015 Johannes Gutenberg University Mainz, Germany
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "polynomial/cra_garner.h"
+
 #include <cln/integer.h>
 #include <cln/integer_io.h>
 #include <cln/random.h>
 #include <cln/numtheory.h>
 #include <cln/integer.h>
 #include <cln/integer_io.h>
 #include <cln/random.h>
 #include <cln/numtheory.h>
-#include "polynomial/cra_garner.hpp"
+using namespace cln;
+#include <iostream>
+#include <limits>
 #include <map>
 #include <map>
-#include <vector>
 #include <stdexcept>
 #include <stdexcept>
-#include <limits>
-using namespace cln;
+#include <vector>
+#include <algorithm>
 using namespace std;
 
 /// Generate a sequences of primes p_i such that \prod_i p_i < limit
 using namespace std;
 
 /// Generate a sequences of primes p_i such that \prod_i p_i < limit
@@ -102,12 +126,14 @@ make_random_moduli(const cln::cl_I& limit)
        std::vector<cln::cl_I> moduli;
        cln::cl_I prod(1);
        cln::cl_I next = random_I(std::min(limit >> 1, cln::cl_I(128)));
        std::vector<cln::cl_I> moduli;
        cln::cl_I prod(1);
        cln::cl_I next = random_I(std::min(limit >> 1, cln::cl_I(128)));
+       unsigned count = 0;
        do {
                cln::cl_I tmp = nextprobprime(next);
                next = tmp + random_I(cln::cl_I(10)) + 1;
                prod = prod*tmp;
                moduli.push_back(tmp);
        do {
                cln::cl_I tmp = nextprobprime(next);
                next = tmp + random_I(cln::cl_I(10)) + 1;
                prod = prod*tmp;
                moduli.push_back(tmp);
-       } while (prod < limit);
+               ++count;
+       } while (prod < limit || (count < 2));
        return moduli;
 }
 
        return moduli;
 }
 
@@ -118,4 +144,3 @@ static void dump(const std::vector<cln::cl_I>& v)
                std::cerr << v[i] << " ";
        std::cerr << "]";
 }
                std::cerr << v[i] << " ";
        std::cerr << "]";
 }
-