Loading [MathJax]/extensions/tex2jax.js
Parallel numerical verification of the σ_odd problem  October 6, 2018
All Classes Namespaces Files Functions Variables Typedefs Macros
interactive.cpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 /** \file sequential/interactive.cpp (January 6, 2018)
3  * \brief
4  * Read number from stdin
5  * and print factorization, number of divisors, sum of divisors
6  * and complete path of the varsigma_odd problem.
7  *
8  * GPLv3 --- Copyright (C) 2017, 2018 Olivier Pirson
9  * http://www.opimedia.be/
10  */
11 
12 // \cond
13 #include <cstdlib>
14 
15 #include <algorithm>
16 #include <iostream>
17 #include <set>
18 // \endcond
19 
20 #include "../common/helper/helper.hpp"
22 
23 
24 
25 /* ***********
26  * Prototype *
27  *************/
28 
29 void
31 
32 
33 
34 /* **********
35  * Function *
36  ************/
37 
38 void
40  std::cerr << "Usage: interactive [options]" << std::endl
41  << std::endl
42  << " --no-prompt do not print the prompt" << std::endl
43  << " --no-separator do not print the separator" << std::endl;
44 
45  exit(EXIT_FAILURE);
46 }
47 
48 
49 
50 /* ******
51  * Main *
52  ********/
53 
54 int
55 main(int argc, const char* const argv[]) {
56  // Load primes table
58  std::cerr << "! Impossible to load \"" << sigmaodd::prime_filename << '"' << std::endl
59  << std::endl;
60  help_and_exit();
61  }
62 
63 
64  bool prompt = true;
65  bool separator = true;
66 
67 
68  // Read command line parameters
69  for (unsigned int i = 1; i < static_cast<unsigned int>(argc); ++i) {
70  const std::string param(argv[i]);
71 
72  if (param == "--no-prompt") {
73  prompt = false;
74  }
75  else if (param == "--no-separator") {
76  separator = false;
77  }
78  else {
79  help_and_exit();
80  }
81  }
82 
83 
84  // Print intern configuration
86 
87 
88  std::cout << "0 or CTRL-D for exit" << std::endl;
89  std::cout.flush();
90 
91 
92  // Interactive loop
93  while (true) {
94  // Input
95  std::string s;
96 
97  if (prompt) {
98  std::cout << ">>> n = ";
99  }
100  std::cin >> s;
101 
102  if (std::cin.eof()) {
103  break;
104  }
105 
107 
108  if (!std::all_of(s.cbegin(), s.cend(),
109  [] (int c) { return (('0' <= c) && (c <= '9')); })) { // invalid character
110  continue;
111  }
112 
113  try {
114  n = std::stoull(s);
115  }
116  catch (...) {
117  continue;
118  }
119 
120  if ((std::to_string(n) != s) || (n > sigmaodd::MAX_POSSIBLE_N)) {
121  std::cout << "Too big!" << std::endl;
122 
123  continue;
124  }
125 
126  if (n == 0) {
127  break;
128  }
129 
130 
131  // Factorize and compute
133  const std::vector<sigmaodd::FactorExp> prime_exps = sigmaodd::factorize(n);
134  const sigmaodd::nat_type nu = sigmaodd::factorization_to_nu(prime_exps);
135  const sigmaodd::nat_type nu_odd = sigmaodd::factorization_to_nu_odd(prime_exps);
136  const sigmaodd::nat_type sigma = sigmaodd::factorization_to_sigma(prime_exps);
137  const sigmaodd::nat_type sigma_odd = sigmaodd::factorization_to_sigma_odd(prime_exps);
139 
140  const std::set<sigmaodd::nat_type> empty_bad_table;
142  = sequential::sequential_sigma_odd_upper_bound(n_odd, empty_bad_table, 0);
143 
144  // Output
145  std::cout << "n = " << n;
146  if ((prime_exps.size() > 1)
147  || ((prime_exps.size() == 1) && (prime_exps[0].exp > 1))) {
148  // Factorization(s)
149  if (sigmaodd::is_even(n) && ((prime_exps.size() > 2)
150  || ((prime_exps.size() == 2) && (prime_exps[1].exp > 1)))) {
151  std::cout << " = " << prime_exps[0] << ' ' << n_odd;
152  }
153 
154  std::cout << " =";
155  for (sigmaodd::FactorExp prime_exp : prime_exps) {
156  std::cout << ' ' << prime_exp;
157  }
158  }
159 
160  std::cout << '\t';
161  if (sigmaodd::is_even(n)) {
162  std::cout << "even";
163  }
164  else if (n == 1) {
165  std::cout << "fixed point";
166  }
167  else if (sigmaodd::is_square(n)) {
168  std::cout << "square";
169  }
170  else if (varsigma_odd > n) {
171  std::cout << "bad";
172  }
173  else {
174  std::cout << "gentle";
175  }
176 
177 
178  // Number of divisors
179  std::cout << "\tnu_odd(n) = " << nu_odd;
180  if (sigmaodd::is_even(n)) {
181  std::cout << " < nu(n) = " << nu;
182  }
183 
184 
185  // Sum(s) of divisors
186  std::cout << "\tvarsigma_odd(n) = " << varsigma_odd
187  << ' ' << (varsigma_odd == sigma_odd
188  ? '='
189  : '<')<< " sigma_odd(n) = " << sigma_odd;
190  if (sigmaodd::is_even(n)) {
191  std::cout << " < sigma(n) = " << sigma;
192  }
193 
194  std::cout << "\t sigma_odd(n) upper bound = " << sigma_odd_upper_bound
195  << std::endl;
196 
197  assert(sigma == sigmaodd::sum_divisors__factorize(n));
198  assert(sigma_odd == sigmaodd::sum_odd_divisors__factorize(n));
199 
200  // Paths
201  if (n_odd != 1) {
202  sequential::sequential_check_varsigma_odd_complete(n_odd, n_odd, true, true, true);
203  }
204 
205  if (separator) {
206  std::cout << std::string(50, '-') << std::endl;
207  }
208  std::cout.flush();
209  }
210 
211  std::cout << std::endl;
212 
213  return EXIT_SUCCESS;
214 }
uint64_t nat_type
Type for natural number used in all code, on 64 bits.
Definition: helper.hpp:33
Structure to represent a factor with its exponent.
Definition: divisors.hpp:33
nat_type factorization_to_nu_odd(std::vector< FactorExp > prime_exps)
Return the number of odd divisors of the number corresponding to the factorization.
Definition: primes.cpp:129
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
nat_type divide_until_odd(nat_type n)
Return n divided by 2 until the result is odd.
constexpr bool is_even(nat_type n)
Return true iff n is even.
bool is_square(nat_type n)
Return true iff n is a perfect square.
Definition: divisors.cpp:267
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
constexpr nat_type sequential_sigma_odd_upper_bound(nat_type n, const std::set< nat_type > &bad_table, nat_type bad_first_n)
Return an upper bound of varsigma_odd(n).
constexpr nat_type MAX_POSSIBLE_N
Lower bound of the bigger number such that it is possible to compute the result of the sigma function...
Definition: helper.hpp:54
void help_and_exit()
Definition: interactive.cpp:39
nat_type sum_odd_divisors__factorize(nat_type n)
Calculates the sum of odd divisors of n by the factorization method and returns it.
Definition: divisors.cpp:444
std::vector< FactorExp > factorize(nat_type n)
Return a list of prime factors with their exponents.
Definition: primes.cpp:58
nat_type sum_divisors__factorize(nat_type n)
Calculates the sum of all divisors of n by the factorization method and returns it.
Definition: divisors.cpp:357
Implementation of the sequential algorithms presented in the report. (Some functions are not use in t...
nat_type factorization_to_sigma_odd(std::vector< FactorExp > prime_exps)
Return the sum of odd divisors of the number corresponding to the factorization.
Definition: primes.cpp:155
nat_type factorization_to_sigma(std::vector< FactorExp > prime_exps)
Return the sum of all divisors of the number corresponding to the factorization.
Definition: primes.cpp:143
void print_intern_config_compiler()
Print to stdcout the intern configuration of the compiler.
Definition: helper.cpp:148
int main(int argc, const char *const argv[])
Definition: interactive.cpp:55
nat_type sigma_odd_upper_bound(nat_type n)
Return an upper bound of sigma_odd(n).
Definition: sigmaodd.cl:474
nat_type factorization_to_nu(std::vector< FactorExp > prime_exps)
Return the number of all divisors of the number corresponding to the factorization.
Definition: primes.cpp:117
std::string to_string(bool b)
Return the string "true" if b, else "false".
Definition: helper.cpp:177
nat_type varsigma_odd(__global const prime_type *primes, nat_type n)
Return varsigma_odd(n), i.e. the sum of all odd divisors of n, divided by 2 until to be odd...
Definition: sigmaodd.cl:497