Loading [MathJax]/extensions/tex2jax.js
Parallel numerical verification of the σ_odd problem  October 6, 2018
All Classes Namespaces Files Functions Variables Typedefs Macros
print_path.cpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 /** \file sequential/print_path.cpp (January 16, 2018)
3  * \brief
4  * Check odd gentle numbers for the varsigma_odd problem
5  * and print bad numbers.
6  *
7  * GPLv3 --- Copyright (C) 2017, 2018 Olivier Pirson
8  * http://www.opimedia.be/
9  */
10 
11 // \cond
12 #include <cstdlib>
13 
14 #include <chrono>
15 #include <iostream>
16 // \endcond
17 
18 #include "../common/helper/helper.hpp"
20 
21 
22 
23 /* ***********
24  * Prototype *
25  *************/
26 
27 void
29 
30 
31 
32 /* **********
33  * Function *
34  ************/
35 
36 void
38  std::cerr << "Usage: print_path [options]" << std::endl
39  << std::endl
40  << "Options:" << std::endl
41  << " --complete check complete path until 1 (by default check only partial path until < n)" << std::endl
42  << " --first n first odd number to check (3 by default)" << std::endl
43  << " --last n last odd number to check (1000001 by default)" << std::endl
44  << " --nb n number of odd numbers to check" << std::endl
45  << " --useless check all odd numbers (by default avoid exactly divisible by 3, 7, 31 or 127)" << std::endl;
46 
47  exit(EXIT_FAILURE);
48 }
49 
50 
51 
52 /* ******
53  * Main *
54  ********/
55 
56 int
57 main(int argc, const char* const argv[]) {
58  // Load primes table
60  std::cerr << "! Impossible to load \"" << sigmaodd::prime_filename << '"' << std::endl
61  << std::endl;
62  help_and_exit();
63  }
64 
65 
66  sigmaodd::nat_type first = 3;
67  sigmaodd::nat_type last = 1000001;
68  bool complete = false;
69  bool useless = false;
70 
71 
72  // Read command line parameters
73  for (unsigned int i = 1; i < static_cast<unsigned int>(argc); ++i) {
74  const std::string param(argv[i]);
75 
76  if (param == "--complete") {
77  complete = true;
78  }
79  else if (param == "--first") {
80  first = std::max(3ul, helper::get_ulong(argc, argv, ++i, &help_and_exit));
81  if (sigmaodd::is_even(first)) {
82  ++first;
83  }
84  }
85  else if (param == "--last") {
86  last = helper::get_ulong(argc, argv, ++i, &help_and_exit);
87  if (sigmaodd::is_even(last)) {
88  --last;
89  }
90  }
91  else if (param == "--nb") {
92  last = first + helper::get_ulong(argc, argv, ++i, &help_and_exit)*2 - 1;
93  }
94  else if (param == "--useless") {
95  useless = true;
96  }
97  else {
98  help_and_exit();
99  }
100  }
101 
102 
103  // Print intern configuration
105 
106  // Print parameters
107  std::cout << "sequential/print_path"
108  << "\tFirst: " << first
109  << "\tLast: " << last
110  << "\tNb: " << (first <= last
111  ? (last - first)/2 + 1
112  : 0)
113  << "\tComplete?: " << helper::to_string(complete)
114  << "\tUseless?: " << helper::to_string(useless)
115  << std::endl;
116 
117  // Print table legend
118  std::cout << std::endl
119  << "n\tLower\tPartial length\tPartial path";
120  if (complete) {
121  std::cout << "\tLength\tPath";
122  }
123  std::cout << std::endl;
124  std::cout.flush();
125 
126 
127  // Main calculation
128  const std::chrono::steady_clock::time_point clock_start = std::chrono::steady_clock::now();
129 
130  for (sigmaodd::nat_type n = first; n <= last; n += 2) {
131  if (complete) {
132  sequential::sequential_check_varsigma_odd_complete(n, n, useless, false, true);
133  }
134  else {
136  }
137  }
138 
139  // End
140  std::chrono::duration<double> duration = std::chrono::steady_clock::now() - clock_start;
141 
142  std::cout << "Total duration: " << helper::duration_to_string(duration)
143  << std::endl;
144 
145  return EXIT_SUCCESS;
146 }
uint64_t nat_type
Type for natural number used in all code, on 64 bits.
Definition: helper.hpp:33
const std::string prime_filename
Default filename for the binary file "big_data/prime28.bin".
Definition: primes.cpp:35
void sequential_check_varsigma_odd_complete(nat_type first_n, nat_type last_n, bool check_useless, bool print_bad, bool print_all, bool print_category, bool print_lower, bool print_length, bool print_path)
Check completely (until 1) in the order all odd numbers between first_n and last_n. The consequence of the result is that: all odd numbers checked between first_n and last_n (included) respect the conjecture.
Definition: sequential.cpp:148
constexpr bool is_even(nat_type n)
Return true iff n is even.
std::string duration_to_string(std::chrono::duration< double > duration_second)
Return a string with the duration expressed in milliseconds, seconds, minutes and hours...
Definition: helper.cpp:61
bool read_primes_table()
Read the binary file prime_filename to fill the table with all primes < 2^28. This table must be read...
Definition: primes.cpp:241
Implementation of the sequential algorithms presented in the report. (Some functions are not use in t...
void print_intern_config_compiler()
Print to stdcout the intern configuration of the compiler.
Definition: helper.cpp:148
unsigned long get_ulong(int argc, const char *const argv[], unsigned int i, void(*help_and_exit_function)())
Return argv[i] converted in integer.
Definition: helper.cpp:124
void sequential_check_varsigma_odd(nat_type first_n, nat_type last_n, bool print_bad, bool print_all, bool print_category, bool print_lower, bool print_length, bool print_path)
Check in the order all odd numbers between first_n and last_n. The consequence of the result is that:...
Definition: sequential.cpp:95
std::string to_string(bool b)
Return the string "true" if b, else "false".
Definition: helper.cpp:177