Loading [MathJax]/extensions/tex2jax.js
Parallel numerical verification of the σ_odd problem  October 6, 2018
All Classes Namespaces Files Functions Variables Typedefs Macros
check_multiplicativity.cpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 /** \file sequential/check_multiplicativity.cpp (October 6, 2018)
3  * \brief
4  * varsigma_odd is multiplicative,
5  * this program check if there exists some (a, b) *not* coprimes such that there is equality.
6  *
7  * GPLv3 --- Copyright (C) 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"
19 #include "../common/sigmaodd/divisors.hpp"
21 
22 
23 
24 /* ***********
25  * Constants *
26  *************/
27 
30 
31 
32 
33 /* ***********
34  * Prototype *
35  *************/
36 
37 void
39 
40 
41 
42 /* **********
43  * Function *
44  ************/
45 
46 void
48  std::cerr << "Usage: check_multiplicativity [options]" << std::endl
49  << std::endl
50  << "Options:" << std::endl
51  << " --first n first odd number to check (" << first_default << " by default)" << std::endl
52  << " --last n last odd number to check (" << last_default << " by default)" << std::endl;
53 
54  exit(EXIT_FAILURE);
55 }
56 
57 
58 
59 /* ******
60  * Main *
61  ********/
62 
63 int
64 main(int argc, const char* const argv[]) {
65  // Load primes table
67  std::cerr << "! Impossible to load \"" << sigmaodd::prime_filename << '"' << std::endl
68  << std::endl;
69  help_and_exit();
70  }
71 
72 
75 
76  // Read command line parameters
77  for (unsigned int i = 1; i < static_cast<unsigned int>(argc); ++i) {
78  const std::string param(argv[i]);
79 
80  if (param == "--first") {
81  first = std::max(9ul, helper::get_ulong(argc, argv, ++i, &help_and_exit));
82  if (sigmaodd::is_even(first)) {
83  ++first;
84  }
85  }
86  else if (param == "--last") {
87  last = helper::get_ulong(argc, argv, ++i, &help_and_exit);
88  if (sigmaodd::is_even(last)) {
89  --last;
90  }
91  }
92  else {
93  help_and_exit();
94  }
95  }
96 
97 
98  // Print intern configuration
100 
101  // Print parameters
102  std::cout << "sequential/check_multiplicativity"
103  << "\tFirst: " << first
104  << "\tLast: " << last << std::endl;
105  std::cout.flush();
106 
107 
108  // Main calculation
109  const std::chrono::steady_clock::time_point clock_start = std::chrono::steady_clock::now();
110 
111  // Check if there exists some (a, b) *not* coprimes such that there is equality
112  for (sigmaodd::nat_type a = first; a <= last; a += 2) {
113  if (a % 1001 == 0) {
114  std::cout << a << std::endl;
115  std::cout.flush();
116  }
117 
119 
120  for (sigmaodd::nat_type b = a; b <= last; b += 2) {
121  const sigmaodd::nat_type d = sigmaodd::gcd(a, b);
122 
123  if (d != 1) { // a and b *not* coprimes
125  const sigmaodd::nat_type varsigma_odd_ab = sequential::sequential_varsigma_odd(a*b);
126 
127  if (varsigma_odd_ab == varsigma_odd_a*varsigma_odd_b) {
128  std::cout << "Exception found! a b: " << a*b << '=' << a << '*' << b << '\t'
129  << d << '\t'
130  << "varsigma_odd: " << varsigma_odd_ab
131  << '=' << varsigma_odd_a << '*' << varsigma_odd_b << std::endl;
132  }
133  }
134  }
135  }
136 
137  // End
138  std::chrono::duration<double> duration = std::chrono::steady_clock::now() - clock_start;
139 
140  std::cout << "Total duration: " << helper::duration_to_string(duration)
141  << std::endl;
142 
143  return EXIT_SUCCESS;
144 }
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
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
const sigmaodd::nat_type first_default
int main(int argc, const char *const argv[])
constexpr nat_type gcd(nat_type a, nat_type b)
Return the Greatest Common Divisor of a and b.
void help_and_exit()
Implementation of the sequential algorithms presented in the report. (Some functions are not use in t...
const sigmaodd::nat_type last_default
void print_intern_config_compiler()
Print to stdcout the intern configuration of the compiler.
Definition: helper.cpp:148
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
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