Loading [MathJax]/extensions/tex2jax.js
Parallel numerical verification of the σ_odd problem  October 6, 2018
All Classes Namespaces Files Functions Variables Typedefs Macros
sequential.hpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 /** \file sequential/sequential/sequential.hpp (January 17, 2018)
3  * \brief
4  * Implementation of the sequential algorithms presented in the report.
5  * (Some functions are not use in this part.
6  * There are present here to be used by several parallel implementation.)
7  *
8  * GPLv3 --- Copyright (C) 2017, 2018 Olivier Pirson
9  * http://www.opimedia.be/
10  */
11 
12 #ifndef PROGS_SRC_SEQUENTIAL_SEQUENTIAL_SEQUENTIAL_HPP_
13 #define PROGS_SRC_SEQUENTIAL_SEQUENTIAL_SEQUENTIAL_HPP_
14 
15 // \cond
16 #include <set>
17 #include <vector>
18 // \endcond
19 
20 #include "../../common/sigmaodd/helper.hpp"
21 #include "../../common/sigmaodd/primes.hpp"
22 
23 
24 namespace sequential {
25 
28 
29 
30 
31  /* ************
32  * Prototypes *
33  **************/
34 
35  /** \brief
36  * Check in the order all odd gentle numbers between first_n and last_n,
37  * and if print_bad
38  * then print all bad numbers between first_n and last_n (included).
39  * The consequence of the result is that:
40  * if (all numbers < first_n respect the conjecture)
41  * and (all perfect squares < last_n respect the conjecture)
42  * and (all bad numbers < last_n respect the conjecture)
43  * then all numbers < last_n respect the conjecture.
44  *
45  * sigmaodd::primes.cpp must be compiled without the macro PRIME16.
46  *
47  * @param first_n 3 <= odd <= last_n
48  * @param last_n <= MAX_POSSIBLE_N
49  * @param print_bad
50  *
51  * @return the set of all bad numbers between first_n and last_n (included)
52  */
53  std::set<nat_type>
55  bool print_bad = true);
56 
57 
58  /** \brief
59  * Check in the order all odd gentle numbers between first_n and last_n,
60  * and if print_bad
61  * then print all bad numbers between first_n and last_n (included).
62  * The consequence of the result is that:
63  * if (all numbers < first_n respect the conjecture)
64  * and (all perfect squares < last_n respect the conjecture)
65  * and (all bad numbers < last_n respect the conjecture)
66  * then all numbers < last_n respect the conjecture.
67  *
68  * sigmaodd::primes.cpp must be compiled without the macro PRIME16.
69  *
70  * @param first_n 3 <= odd <= last_n
71  * @param last_n <= MAX_POSSIBLE_N
72  * @param bad_table must be contains all bad numbers between bad_first_n and bad_last_n (included)
73  * @param bad_first_n
74  * @param bad_last_n
75  * @param print_bad
76  *
77  * @return the set of all bad numbers between first_n and last_n (included)
78  */
79  std::set<nat_type>
81  const std::set<nat_type> &bad_table,
82  nat_type bad_first_n, nat_type bad_last_n,
83  bool print_bad = true);
84 
85 
86  /** \brief
87  * Check in the order all odd numbers between first_n and last_n.
88  * The consequence of the result is that:
89  * if all numbers < first_n respect the conjecture
90  * and first_iterate_varsigma_odd_until_lower()
91  * do not exits with impossible to check or cycle found,
92  * then all numbers <= last_n respect the conjecture.
93  *
94  * If print_bad
95  * then print all bad numbers between first_n and last_n (included).
96  *
97  * If print_all
98  * then print all odd numbers between first_n and last_n (included).
99  *
100  * If print_category
101  * then moreover print the category of the number.
102  *
103  * If print_lower
104  * then moreover print the lower number reached.
105  *
106  * If print_length
107  * then moreover print the length of the partial path.
108  *
109  * If print_path
110  * then moreover print the partial path.
111  *
112  * sigmaodd::primes.cpp must be compiled without the macro PRIME16.
113  *
114  * @param first_n 3 <= odd <= last_n
115  * @param last_n <= MAX_POSSIBLE_N
116  * @param print_bad
117  * @param print_all
118  * @param print_category
119  * @param print_length
120  * @param print_lower
121  * @param print_path
122  */
123  void
125  bool print_bad = true,
126  bool print_all = false,
127  bool print_category = true,
128  bool print_lower = true,
129  bool print_length = true,
130  bool print_path = true);
131 
132 
133  /** \brief
134  * Return sequential_check_varsigma_odd(),
135  * but only for n perfect square.
136  *
137  * sigmaodd::primes.cpp must be compiled without the macro PRIME16.
138  *
139  * @param n 3 <= odd <= MAX_POSSIBLE_N
140  * @param print
141  * @param print_length
142  * @param print_lower
143  * @param print_path
144  */
145  void
147  bool print = true,
148  bool print_lower = true,
149  bool print_length = true,
150  bool print_path = true);
151 
152 
153  /** \brief
154  * Check completely (until 1) in the order all odd numbers between first_n and last_n.
155  * The consequence of the result is that:
156  * all odd numbers *checked* between first_n and last_n (included) respect the conjecture.
157  *
158  * If check_useless
159  * then check also odd numbers that verify is_first_mersenne_prime_unitary_divide(n)
160  * else check only others.
161  *
162  * If print_bad
163  * then print all bad numbers between first_n and last_n (included).
164  *
165  * If print_all
166  * then print all odd numbers between first_n and last_n (included).
167  *
168  * If print_category
169  * then moreover print the category of the number.
170  *
171  * If print_lower
172  * then moreover print the lower number reached.
173  *
174  * If print_length
175  * then moreover print the length of the partial path.
176  *
177  * If print_path
178  * then moreover print the partial path.
179  *
180  * sigmaodd::primes.cpp must be compiled without the macro PRIME16.
181  *
182  * @param first_n 3 <= odd <= last_n
183  * @param last_n <= MAX_POSSIBLE_N
184  * @param check_useless
185  * @param print_bad
186  * @param print_all
187  * @param print_category
188  * @param print_length
189  * @param print_lower
190  * @param print_path
191  */
192  void
194  bool check_useless = false,
195  bool print_bad = true,
196  bool print_all = false,
197  bool print_category = true,
198  bool print_lower = true,
199  bool print_length = true,
200  bool print_path = true);
201 
202 
203  /** \brief
204  * Return sequential_check_varsigma_odd_complete(),
205  * but only for n perfect square.
206  *
207  * sigmaodd::primes.cpp must be compiled without the macro PRIME16.
208  *
209  * @param n 3 <= odd <= MAX_POSSIBLE_N
210  * @param print
211  * @param print_length
212  * @param print_lower
213  * @param print_path
214  */
215  void
217  bool print = true,
218  bool print_lower = true,
219  bool print_length = true,
220  bool print_path = true);
221 
222 
223  /** \brief
224  * Return true iff varsigma_odd(n) < n.
225  *
226  * sigmaodd::primes.cpp must be compiled without the macro PRIME16.
227  *
228  * @param n 3 <= odd <= MAX_POSSIBLE_N
229  * @param bad_table must be contains all bad numbers between first_n (included) and n (excluded)
230  * @param bad_first_n
231  */
232  bool
234  const std::set<nat_type> &bad_table,
235  nat_type bad_first_n);
236 
237 
238  /** \brief
239  * Return true iff varsigma_odd(n) < n.
240  *
241  * sigmaodd::primes.cpp must be compiled without the macro PRIME16.
242  *
243  * @param n 3 <= odd <= MAX_POSSIBLE_N
244  * @param bad_table must be contains all bad numbers between bad_first_n and bad_last_n (included)
245  * @param bad_first_n
246  * @param bad_last_n
247  */
248  bool
250  const std::set<nat_type> &bad_table,
251  nat_type bad_first_n, nat_type bad_last_n);
252 
253 
254  /** \brief
255  * Iterate sequential_varsigma_odd(start_n) until to reach 1.
256  * Return this complete path.
257  *
258  * If one iteration gives a result > MAX_POSSIBLE_N
259  * then exits with an error message "! Impossible to check [...]".
260  *
261  * If one cycle is reached
262  * then exits with an error message "! Found not trivial cycle [...]".
263  *
264  * sigmaodd::primes.cpp must be compiled without the macro PRIME16.
265  *
266  * @param start_n 3 <= odd <= MAX_POSSIBLE_N
267  */
268  std::vector<nat_type>
270 
271 
272  /** \brief
273  * Return sequential_iterate_varsigma_odd_until_1(),
274  * but only for n perfect square.
275  *
276  * sigmaodd::primes.cpp must be compiled without the macro PRIME16.
277  *
278  * @param start_n 3 <= odd <= MAX_POSSIBLE_N
279  */
280  std::vector<nat_type>
282 
283 
284  /** \brief
285  * Iterate sequential_varsigma_odd(start_n) until to be have a result < start_n.
286  * Return this partial path.
287  *
288  * If one iteration gives a result > MAX_POSSIBLE_N
289  * then exits with an error message "! Impossible to check [...]".
290  *
291  * If one cycle is reached
292  * then exits with an error message "! Found not trivial cycle [...]".
293  *
294  * sigmaodd::primes.cpp must be compiled without the macro PRIME16.
295  *
296  * @param start_n 3 <= odd <= MAX_POSSIBLE_N
297  */
298  std::vector<nat_type>
300 
301 
302  /** \brief
303  * Return sequential_iterate_varsigma_odd_until_lower(),
304  * but only for n perfect square.
305  *
306  * sigmaodd::primes.cpp must be compiled without the macro PRIME16.
307  *
308  * @param start_n 3 <= odd <= MAX_POSSIBLE_N
309  */
310  std::vector<nat_type>
312 
313 
314  /** \brief
315  * Return the minimum of the first size values of ns.
316  *
317  * @param ns must be contains at least size elements
318  * @param size >= 1
319  */
320  constexpr
321  nat_type
322  sequential_min_array(const nat_type ns[], size_t size);
323 
324 
325  /** \brief
326  * Print number from ns, in increasing order
327  * and return a list of these number in the same order.
328  */
329  std::vector<nat_type>
330  sequential_print_in_order(const std::set<nat_type> &ns);
331 
332 
333  /** \brief
334  * Return varsigma_odd(n),
335  * i.e. the sum of all odd divisors of n,
336  * divided by 2 until to be odd.
337  *
338  * sigmaodd::primes.cpp must be compiled without the macro PRIME16.
339  *
340  * @param n 3 <= odd <= MAX_POSSIBLE_N
341  */
342  nat_type
344 
345 
346  /** \brief
347  * Return sequential_varsigma_odd(),
348  * but only for n perfect square.
349  *
350  * sigmaodd::primes.cpp must be compiled without the macro PRIME16.
351  *
352  * @param n 3 <= (odd and perfect square) <= MAX_POSSIBLE_N
353  */
354  nat_type
356 
357 
358  /** \brief
359  * Return the set of n from ns
360  * such that varsigma_odd(n) > n.
361  *
362  * sigmaodd::primes.cpp must be compiled without the macro PRIME16.
363  *
364  * @param ns list of (3 <= odd <= MAX_POSSIBLE_N)
365  * @param bad_table must be contains all bad numbers between bad_first_n and bad_last_n (included)
366  * @param bad_first_n
367  * @param bad_last_n
368  */
369  std::set<nat_type>
370  sequential_varsigma_odd_greater_set(const std::vector<nat_type> &ns,
371  const std::set<nat_type> &bad_table,
372  nat_type bad_first_n, nat_type bad_last_n);
373 
374 
375  /** \brief
376  * Return an upper bound of varsigma_odd(n).
377  *
378  * If n == 1 then return 1.
379  * If n is identified as a gentle number then return n - 1.
380  * Else return floor((n * ceil(2 * (n - 1)^{1/8} + 1)) / 2).
381  *
382  * @param n odd
383  * @param bad_table must be contains all bad numbers between bad_first_n (included) and n (excluded)
384  * @param bad_first_n
385  */
386  constexpr
387  nat_type
389  const std::set<nat_type> &bad_table,
390  nat_type bad_first_n);
391 
392 
393  /** \brief
394  * Return an upper bound of sigma_odd(n).
395  *
396  * If n == 1 then return 1.
397  * If n is identified as a gentle number then return n - 1.
398  * Else return floor((n * ceil(2 * (n - 1)^{1/8} + 1)) / 2).
399  *
400  * @param n odd
401  * @param bad_table must be contains all bad numbers between bad_first_n and bad_last_n (included)
402  * @param bad_first_n
403  * @param bad_last_n
404  */
405  constexpr
406  nat_type
408  const std::set<nat_type> &bad_table,
409  nat_type bad_first_n, nat_type bad_last_n);
410 
411 
412  /** \brief
413  * Return an upper bound of varsigma_odd(n).
414  *
415  * If n == 1 then return 1.
416  * If n is identified as a gentle number then return n - 1.
417  * Else return floor((n * ceil(2 * (n - 1)^{1/8} + 1)) / 2).
418  *
419  * @param n odd
420  * @param bad_table must be contains all bad numbers between bad_first_n (included) and n (excluded)
421  * @param bad_first_n
422  * @param sqrt_n must be equal floor_square_root(n)
423  */
424  constexpr
425  nat_type
427  const std::set<nat_type> &bad_table,
428  nat_type bad_first_n,
429  nat_type sqrt_n);
430 
431 
432  /** \brief
433  * Return an upper bound of sigma_odd(n).
434  *
435  * If n == 1 then return 1.
436  * If n is identified as a gentle number then return n - 1.
437  * Else return floor((n * ceil(2 * (n - 1)^{1/8} + 1)) / 2).
438  *
439  * @param n odd
440  * @param bad_table must be contains all bad numbers between bad_first_n and bad_last_n (included)
441  * @param bad_first_n
442  * @param bad_last_n
443  * @param sqrt_n must be equal floor_square_root(n)
444  */
445  constexpr
446  nat_type
448  const std::set<nat_type> &bad_table,
449  nat_type bad_first_n, nat_type bad_last_n,
450  nat_type sqrt_n);
451 
452 } // namespace sequential
453 
454 #include "sequential__inline.hpp"
455 
456 #endif // PROGS_SRC_SEQUENTIAL_SEQUENTIAL_SEQUENTIAL_HPP_
std::vector< nat_type > sequential_print_in_order(const std::set< nat_type > &ns)
Print number from ns, in increasing order and return a list of these number in the same order...
Definition: sequential.cpp:480
std::set< nat_type > sequential_check_gentle_varsigma_odd(nat_type first_n, nat_type last_n, bool print_bad)
Check in the order all odd gentle numbers between first_n and last_n, and if print_bad then print all...
Definition: sequential.cpp:29
void sequential_check_varsigma_odd_perfect_square(nat_type n, bool print, bool print_lower, bool print_length, bool print_path)
Return sequential_check_varsigma_odd(), but only for n perfect square.
Definition: sequential.cpp:124
uint64_t nat_type
Type for natural number used in all code, on 64 bits.
Definition: helper.hpp:33
sigmaodd::nat_type nat_type
Definition: sequential.hpp:26
sigmaodd::prime_type prime_type
Definition: sequential.hpp:27
std::vector< nat_type > sequential_iterate_varsigma_odd_perfect_square_until_1(nat_type start_n)
Return sequential_iterate_varsigma_odd_until_1(), but only for n perfect square.
Definition: sequential.cpp:345
std::vector< nat_type > sequential_iterate_varsigma_odd_until_lower(nat_type start_n)
Iterate sequential_varsigma_odd(start_n) until to be have a result < start_n. Return this partial pat...
Definition: sequential.cpp:392
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
bool sequential_is_varsigma_odd_lower(nat_type n, const std::set< nat_type > &bad_table, nat_type bad_first_n)
Return true iff varsigma_odd(n) < n.
Definition: sequential.cpp:202
uint32_t prime_type
Type for prime number, particularly for the table of primes.
Definition: primes.hpp:49
std::set< nat_type > sequential_varsigma_odd_greater_set(const std::vector< nat_type > &ns, const std::set< nat_type > &bad_table, nat_type bad_first_n, nat_type bad_last_n)
Return the set of n from ns such that varsigma_odd(n) > n.
Definition: sequential.cpp:588
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 sequential_min_array(const nat_type ns[], size_t size)
Return the minimum of the first size values of ns.
nat_type sequential_varsigma_odd_perfect_square(nat_type n)
Return sequential_varsigma_odd(), but only for n perfect square.
Definition: sequential.cpp:536
void sequential_check_varsigma_odd_perfect_square_complete(nat_type n, bool print, bool print_lower, bool print_length, bool print_path)
Return sequential_check_varsigma_odd_complete(), but only for n perfect square.
Definition: sequential.cpp:179
constexpr nat_type sequential_sigma_odd_upper_bound_with_sqrt(nat_type n, const std::set< nat_type > &bad_table, nat_type bad_first_n, nat_type sqrt_n)
Return an upper bound of varsigma_odd(n).
std::vector< nat_type > sequential_iterate_varsigma_odd_until_1(nat_type start_n)
Iterate sequential_varsigma_odd(start_n) until to reach 1. Return this complete path.
Definition: sequential.cpp:304
void print_path(const std::vector< nat_type > &path, std::ostream &out)
Send to the stream a string representation of the path. All numbers are separated by the correspondin...
Definition: sigmaodd.cpp:251
std::vector< nat_type > sequential_iterate_varsigma_odd_perfect_square_until_lower(nat_type start_n)
Return sequential_iterate_varsigma_odd_until_lower(), but only for n perfect square.
Definition: sequential.cpp:433
nat_type sequential_varsigma_odd(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: sequential.cpp:494
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