Loading [MathJax]/extensions/tex2jax.js
Parallel numerical verification of the σ_odd problem  October 6, 2018
All Classes Namespaces Files Functions Variables Typedefs Macros
bounds.cpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 /** \file common/bounds.cpp (January 5, 2018)
3  * \brief
4  * Some upper bounds for the sigma_odd problem.
5  *
6  * GPLv3 --- Copyright (C) 2017, 2018 Olivier Pirson
7  * http://www.opimedia.be/
8  */
9 
10 // \cond
11 #include <cassert>
12 #include <cmath>
13 #include <cstdlib>
14 
15 #include <iostream>
16 // \endcond
17 
18 #include "helper/helper.hpp"
19 #include "sigmaodd/helper.hpp"
20 #include "sigmaodd/primes.hpp"
21 #include "sigmaodd/sigmaodd.hpp"
22 
23 
24 /* ***********
25  * Prototype *
26  *************/
27 
28 void
30 
31 
32 
33 /* **********
34  * Function *
35  ************/
36 
37 void
39  std::cerr << "Usage: bounds [options]" << std::endl
40  << std::endl
41  << "Options:" << std::endl
42  << " --first n first odd number to check (1 by default)" << std::endl
43  << " --last n last odd number to check (101 by default)" << std::endl
44  << " --nb n number of odd numbers to check" << std::endl;
45 
46  exit(EXIT_FAILURE);
47 }
48 
49 
50 
51 /* ******
52  * Main *
53  ********/
54 
55 int
56 main(int argc, const char* const argv[]) {
57  // Load primes table
59  std::cerr << "! Impossible to load \"" << sigmaodd::prime_filename << '"' << std::endl
60  << std::endl;
61  help_and_exit();
62  }
63 
64 
65  sigmaodd::nat_type first = 1;
66  sigmaodd::nat_type last = 1000;
67 
68 
69  // Read command line parameters
70  for (unsigned int i = 1; i < static_cast<unsigned int>(argc); ++i) {
71  const std::string param(argv[i]);
72 
73  if (param == "--first") {
74  first = std::max(1ul, helper::get_ulong(argc, argv, ++i, &help_and_exit));
75  if (sigmaodd::is_even(first)) {
76  ++first;
77  }
78  }
79  else if (param == "--last") {
80  last = helper::get_ulong(argc, argv, ++i, &help_and_exit);
81  if (sigmaodd::is_even(last)) {
82  --last;
83  }
84  }
85  else if (param == "--nb") {
86  last = first + helper::get_ulong(argc, argv, ++i, &help_and_exit)*2 - 1;
87  }
88  else {
89  help_and_exit();
90  }
91  }
92 
93 
94  // Print intern configuration
96 
97 
98  // Print parameters
99  std::cout << "First: " << first
100  << "\tLast: " << last
101  << "\tNb: " << (first <= last
102  ? (last - first)/2 + 1
103  : 0)
104  << std::endl;
105 
106 
107  // Print table legend
108  std::cout << std::endl
109  << "n\tsigma_odd\tvarsigma_odd\tUpper bound\tDeTemple\tDeTemple adapt\tSum_odd\tPow9_8\tSqrt8\tHalf_sqrt8"
110  << std::endl;
111 
112 
113  // Print data
114  for (sigmaodd::nat_type n = first; n <= last; n += 2) {
115  const sigmaodd::nat_type sum_odd_divisors = sigmaodd::sum_odd_divisors__factorize(n);
120 
121  // ??????
123  sigmaodd::nat_type n_divided;
124  unsigned int alpha;
125  sigmaodd::nat_type bound_DeTemple_adapt;
126 
127  assert(sigmaodd::is_odd(n));
128 
129  {
130  const std::pair<sigmaodd::nat_type, unsigned int>
131  result_alpha = (prime != 1
132  ? sigmaodd::divide_until_nb(n, prime)
133  : std::make_pair(n, 0u));
134 
135  if (n == 1) {
136  bound_DeTemple_adapt = 1;
137  }
138  else {
139  assert(prime > 1);
140 
141  if (prime == n) { // n is prime
142  assert(sigmaodd::is_prime(n));
143 
144  // ???????? bound_DeTemple_adapt = n + 1;
145  bound_DeTemple_adapt = 0;
146  }
147  else if (prime <= sigmaodd::floor_square_root(result_alpha.first)) {
148  assert(!sigmaodd::is_prime(n));
149  // assert(prime <= sigmaodd::floor_square_root(result_alpha.first));
150 
151  n_divided = result_alpha.first;
152  alpha = result_alpha.second;
153 
154  assert(sigmaodd::is_odd(n_divided));
155  assert(1 <= alpha);
156 
158  }
159  else { // n_divided is prime
160  assert(!sigmaodd::is_prime(n));
161  // ???assert(sigmaodd::is_square(n_divided));
162 
163  // ???bound_DeTemple_adapt = sigmaodd::sum_odd_divisors__factorize(n);
164  // ???bound_DeTemple_adapt = sigmaodd::sum_odd_divisors_upper_bound__DeTemple(n);
165  bound_DeTemple_adapt = 0;
166  }
167  }
168  }
169 
170  const sigmaodd::nat_type pow9_8
171  = static_cast<sigmaodd::nat_type>(std::floor(std::pow(n, 9.0/8)*2));
172  const sigmaodd::nat_type sqrt8
173  = static_cast<sigmaodd::nat_type>(std::floor((std::pow(n - 1, 1.0/8) + 1.0/2)
174  * static_cast<double>(n)));
175  const sigmaodd::nat_type half_sqrt8
176  = static_cast<sigmaodd::nat_type>(std::floor((std::pow(n - 1, 1.0/8) + 1.0/2)
177  * static_cast<double>(n) / 2));
178 
179  std::cout << n
180  << '\t' << sum_odd_divisors
181  << '\t' << varsum_odd_divisors
182  << '\t' << bound
183  << '\t' << bound_DeTemple
184  << '\t' << ((bound_DeTemple_adapt > 0) // ??? && (n_divided())
185  ? std::to_string(bound_DeTemple_adapt)
186  : "")
187  << '\t' << sum_odd
188  << '\t' << pow9_8
189  << '\t' << sqrt8
190  << '\t' << half_sqrt8
191  << std::endl;
192 
193  assert(varsum_odd_divisors <= sum_odd_divisors);
194 
195  assert(sum_odd_divisors <= bound);
196  assert(sum_odd_divisors <= bound_DeTemple);
197  if (bound_DeTemple_adapt > 0) {
198  // ???assert(sum_odd_divisors <= bound_DeTemple_adapt);
199  assert(varsum_odd_divisors <= bound_DeTemple_adapt);
200  }
201  assert(sum_odd_divisors <= pow9_8);
202  if (n != 1) {
203  assert(sum_odd_divisors <= sqrt8);
204  }
205  if (!sigmaodd:: is_square(n)) {
206  assert(varsum_odd_divisors <= half_sqrt8);
207  }
208 
209  assert(bound <= bound_DeTemple);
210  assert(bound_DeTemple <= sum_odd);
211  assert(bound_DeTemple_adapt <= sum_odd);
212 
213  assert(sqrt8 <= pow9_8);
214  assert(half_sqrt8 <= sqrt8);
215  }
216 
217  return EXIT_SUCCESS;
218 }
Define type and some generic functions.
constexpr nat_type sum_geometric_progression(nat_type r, unsigned int k)
Return the sum of the (k + 1) terms of the geometric progression of the common ratio r...
nat_type floor_square_root(nat_type n)
Return the square root of n rounded to below.
Definition: helper.cpp:76
uint64_t nat_type
Type for natural number used in all code, on 64 bits.
Definition: helper.hpp:33
constexpr bool is_odd(nat_type n)
Return true iff n is odd.
void help_and_exit()
Definition: bounds.cpp:38
const std::string prime_filename
Default filename for the binary file "big_data/prime28.bin".
Definition: primes.cpp:35
bool is_prime(nat_type n)
Return true iff n is a prime number.
Definition: primes.cpp:169
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.
nat_type first_divisor(nat_type n)
Return the first divisor of n > 1 (or 1 if n <= 1)
Definition: divisors.cpp:223
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
Functions to access to tables of precaculated prime numbers and offsets to iterate on possible prime ...
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
int main(int argc, const char *const argv[])
Definition: bounds.cpp:56
nat_type sum_odd_divisors_upper_bound(nat_type n)
Return an upper bound of sum odd divisors.
Definition: divisors.cpp:531
Some generic helper functions for programs.
void print_intern_config_compiler()
Print to stdcout the intern configuration of the compiler.
Definition: helper.cpp:148
Main functions to deal the sigma_odd problem.
const double alpha
Definition: harmonic.cpp:24
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
std::pair< nat_type, unsigned int > divide_until_nb(nat_type n, nat_type d)
Divide n by d until the result is not divisible by d, and return (result, number of divisions)...
Definition: divisors.cpp:207
std::string to_string(bool b)
Return the string "true" if b, else "false".
Definition: helper.cpp:177
constexpr nat_type sum_odd(nat_type n)
Return 1 + 3 + 5 + 7 + ... + (n or n-1) = k^2 with k floor((n+1)/2).
nat_type sum_odd_divisors_upper_bound__DeTemple(nat_type n)
Return an upper bound of sum odd divisors of n using the DeTemple inequalities.
Definition: divisors.cpp:602