Loading [MathJax]/extensions/tex2jax.js
Parallel numerical verification of the σ_odd problem  October 6, 2018
All Classes Namespaces Files Functions Variables Typedefs Macros
sequential__inline.hpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 /** \file sequential/sequential/sequential__inline.hpp (January 8, 2018)
3  *
4  * GPLv3 --- Copyright (C) 2017, 2018 Olivier Pirson
5  * http://www.opimedia.be/
6  */
7 
8 #ifndef PROGS_SRC_SEQUENTIAL_SEQUENTIAL_SEQUENTIAL__INLINE_HPP_
9 #define PROGS_SRC_SEQUENTIAL_SEQUENTIAL_SEQUENTIAL__INLINE_HPP_
10 
11 // \cond
12 #include <cassert>
13 
14 #include <algorithm>
15 #include <set>
16 // \endcond
17 
18 #include "../../common/sigmaodd/helper.hpp"
19 
20 
21 namespace sequential {
22 
23  /* ********************
24  * constexpr function *
25  **********************/
26 
27  constexpr
28  nat_type
29  sequential_min_array(const nat_type ns[], size_t size) {
30  assert(size != 0);
31 
32  nat_type min = ns[0];
33 
34  for (unsigned int i = 1; i < size; ++i) {
35  min = std::min(min, ns[i]);
36  }
37 
38  return min;
39  }
40 
41 
42  constexpr
43  nat_type
45  const std::set<nat_type> &bad_table,
46  nat_type bad_first_n) {
47  assert(sigmaodd::is_odd(n));
48 
49  return (n == 1
50  ? 1
51  : ((bad_first_n <= n) && !sigmaodd::is_square(n)
52  && (bad_table.find(n) == bad_table.cend())
53  ? n - 1
54  : ((n*((sigmaodd::ceil_eighth_root(n - 1) << 1) + 1)) >> 1)));
55  }
56 
57 
58  constexpr
59  nat_type
61  const std::set<nat_type> &bad_table,
62  nat_type bad_first_n, nat_type bad_last_n) {
63  assert(sigmaodd::is_odd(n));
64 
65  return (n == 1
66  ? 1
67  : ((bad_first_n <= n) && (n <= bad_last_n) && !sigmaodd::is_square(n)
68  && (bad_table.find(n) == bad_table.cend())
69  ? n - 1
70  : ((n*((sigmaodd::ceil_eighth_root(n - 1) << 1) + 1)) >> 1)));
71  }
72 
73 
74  constexpr
75  nat_type
77  const std::set<nat_type> &bad_table,
78  nat_type bad_first_n,
79  nat_type sqrt_n) {
80  assert(sigmaodd::is_odd(n));
81  // assert(sqrt_n == sigmaodd::floor_square_root(n));
82 
83  return (n == 1
84  ? 1
85  : ((bad_first_n <= n) && (sigmaodd::square(sqrt_n) != n)
86  && (bad_table.find(n) == bad_table.cend())
87  ? n - 1
88  : ((n*((sigmaodd::ceil_eighth_root(n - 1) << 1) + 1)) >> 1)));
89  }
90 
91 
92  constexpr
93  nat_type
95  const std::set<nat_type> &bad_table,
96  nat_type bad_first_n, nat_type bad_last_n,
97  nat_type sqrt_n) {
98  assert(sigmaodd::is_odd(n));
99  // assert(sqrt_n == sigmaodd::floor_square_root(n));
100 
101  return (n == 1
102  ? 1
103  : ((bad_first_n <= n) && (n <= bad_last_n) && (sigmaodd::square(sqrt_n) != n)
104  && (bad_table.find(n) == bad_table.cend())
105  ? n - 1
106  : ((n*((sigmaodd::ceil_eighth_root(n - 1) << 1) + 1)) >> 1)));
107  }
108 
109 } // namespace sequential
110 
111 #endif // PROGS_SRC_SEQUENTIAL_SEQUENTIAL_SEQUENTIAL__INLINE_HPP_
unsigned long nat_type
Type for natural number used in all code, on 64 bits.
Definition: sigmaodd.cl:22
sigmaodd::nat_type nat_type
Definition: sequential.hpp:26
constexpr bool is_odd(nat_type n)
Return true iff n is odd.
nat_type ceil_eighth_root(nat_type n)
Return the eighth root of n rounded to above.
bool is_square(nat_type n)
Return true iff n is a perfect square.
Definition: divisors.cpp:267
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.
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).
constexpr double square(double x)
Return x*x.