OKlibrary  0.2.1.6
CountProgressions_GreenTao.cpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 18.10.2009 (Swansea)
00002 /* Copyright 2009, 2010 Oliver Kullmann
00003 This file is part of the OKlibrary. OKlibrary is free software; you can redistribute
00004 it and/or modify it under the terms of the GNU General Public License as published by
00005 the Free Software Foundation and included in this library; either version 3 of the
00006 License, or any later version. */
00007 
00022 #include <iostream>
00023 #include <string>
00024 
00025 #include <boost/lexical_cast.hpp>
00026 
00027 #include <OKlib/Combinatorics/Hypergraphs/Generators/GreenTao.hpp>
00028 
00029 namespace {
00030 
00031 #  ifndef UINT_TYPE_GT
00032 #    define UINT_TYPE_GT unsigned long
00033 #  endif
00034 
00035   typedef UINT_TYPE_GT uint_type;
00036 
00037   enum { errcode_parameter = 1, errcode_parameter_values = 2 };
00038         
00039   const std::string program = "CountProgressions_GreenTao";
00040   const std::string err = "ERROR[" + program + "]: ";
00041 
00042 }
00043 
00044 int main(const int argc, const char* const argv[]) {
00045 
00046   if (argc != 3) {
00047     std::cerr << err << "Exactly two arguments are needed,\n"
00048     "the length k of arithmetic progressions, and the maximal number N of primes.\n";
00049     return(errcode_parameter);
00050   }
00051 
00052   try {
00053 
00054     const uint_type k = boost::lexical_cast<uint_type>(argv[1]);
00055     const uint_type N = boost::lexical_cast<uint_type>(argv[2]);
00056 
00057     typedef OKlib::Combinatorics::Hypergraphs::Generators::GreenTao<uint_type> gt_generator;
00058     typedef gt_generator::set_system_type set_system_type;
00059     typedef gt_generator::hyperedge_type hyperedge_type;
00060     const gt_generator g(k,N);
00061 
00062     const set_system_type G(g.hyperedge_set());
00063     const hyperedge_type V(g.vertex_set());
00064 
00065     typedef OKlib::Combinatorics::Hypergraphs::Generators::Sizes_strata_indmon<hyperedge_type, set_system_type> strata_gen_t;
00066     typedef strata_gen_t::result_type statistics_vector_t;
00067 
00068     statistics_vector_t cumulative = strata_gen_t()(V,G);
00069     OKlib::Combinatorics::Hypergraphs::Generators::accumulate_l(cumulative);
00070 
00071     std::cout << "n nhyp\n";
00072     for (statistics_vector_t::const_iterator i = cumulative.begin();
00073         i != cumulative.end(); ++i)
00074       std::cout << i -> first << " " << i -> second << "\n";
00075 
00076   }
00077   catch (boost::bad_lexical_cast&) {
00078     std::cerr << err << "Both parameters must be non-negative integers\n"
00079       "in the range given by UINT_TYPE_GT (default = unsigned long).\n";
00080     return(errcode_parameter_values);
00081   }
00082 
00083 }
00084