Loading [MathJax]/extensions/tex2jax.js
Parallel numerical verification of the σ_odd problem  October 6, 2018
All Classes Namespaces Files Functions Variables Typedefs Macros
divisors__inline.hpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 /** \file common/sigmaodd/divisors__inline.hpp (January 7, 2018)
3  *
4  * GPLv3 --- Copyright (C) 2017, 2018 Olivier Pirson
5  * http://www.opimedia.be/
6  */
7 
8 #ifndef PROGS_SRC_COMMON_SIGMAODD_DIVISORS__INLINE_HPP_
9 #define PROGS_SRC_COMMON_SIGMAODD_DIVISORS__INLINE_HPP_
10 
11 // \cond
12 #include <cassert>
13 #include <cstring> // for ffsl, https://linux.die.net/man/3/ffs
14 
15 #include <utility>
16 // \endcond
17 
18 
19 namespace sigmaodd {
20 
21  /* ********
22  * Struct *
23  **********/
24  constexpr
25  bool
26  FactorExp::operator==(const FactorExp &other) const {
27  return (factor == other.factor) && (exp == other.exp);
28  }
29 
30 
31  constexpr
32  nat_type
33  FactorExp::value() const {
34  return pow_nat(factor, exp);
35  }
36 
37 
38 
39  /* *********************
40  * constexpr functions *
41  ***********************/
42 
43  constexpr
44  nat_type
46  while (b != 0) {
47  const nat_type m = a % b;
48 
49  a = b;
50  b = m;
51  }
52 
53  return a;
54 
55  /*
56  "We might call Euclid's method the granddaddy of all algorithms,
57  because it is the oldest nontrivial algorithm that has survived to the present day."
58  (Donald E. Knuth.
59  The Art of Computer Programming, Volume 2: Seminumerical Algorithms. 3rd 1997)
60  */
61  }
62 
63 
64  constexpr
65  nat_type
67  return (gcd(a, b) == 1);
68  }
69 
70 
71  constexpr
72  bool
74  assert(d != 0);
75 
76  return n % d == 0;
77  }
78 
79 
80  constexpr
81  bool
83  return (is_unitary_divide(3, n)
84  || is_unitary_divide(7, n)
85  || is_unitary_divide(31, n)
86  || is_unitary_divide(127, n));
87  }
88 
89 
90  constexpr
91  bool
94  }
95 
96 
97  constexpr
98  bool
101  || is_unitary_divide(8191, n)
102  || is_unitary_divide(131071, n)
103  || is_unitary_divide(524287, n));
104  }
105 
106 
107  constexpr
108  bool
111  || is_unitary_divide(2147483647u, n)
112  || is_unitary_divide(2305843009213693951u, n));
113  }
114 
115 
116  constexpr
117  bool
119  assert(d != 0);
120 
121  return is_divide(d, n) && !is_divide(d, n/d);
122  }
123 
124 
125 
126  /* ******************
127  * inline functions *
128  ********************/
129 
130  inline
131  nat_type
133  assert(n != 0);
134 
135  // https://linux.die.net/man/3/ffs
136  return n >> (static_cast<unsigned int>(ffsl(static_cast<long int>(n))) - 1);
137  }
138 
139 
140  inline
141  std::pair<nat_type, unsigned int>
143  assert(n != 0);
144 
145  // https://linux.die.net/man/3/ffs
146  const unsigned int alpha = static_cast<unsigned int>(ffsl(static_cast<long int>(n))) - 1;
147 
148  return std::make_pair(n >> alpha, alpha);
149  }
150 
151 } // namespace sigmaodd
152 
153 #endif // PROGS_SRC_COMMON_SIGMAODD_DIVISORS__INLINE_HPP_
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
constexpr bool is_unitary_divide(nat_type d, nat_type n)
Return true iff (d divide n) and (d NOT divide n/d).
std::pair< nat_type, unsigned int > divide_until_odd_nb(nat_type n)
Divide n by 2 until the result is odd, and return (result, number of divisions).
nat_type divide_until_odd(nat_type n)
Return n divided by 2 until the result is odd.
unsigned int exp
Definition: divisors.hpp:35
bool is_square(nat_type n)
Return true iff n is a perfect square.
Definition: divisors.cpp:267
A lot of functions and stuffs to deal the sigma_odd problem and related stuffs.
Definition: divisors.cpp:22
constexpr bool is_mersenne_prime_unitary_divide(nat_type n)
Return true iff at least one of 3, 7, 31, 127, 8191, 131071, 524287, 2147483647 or 230584300921369395...
constexpr bool is_divide(nat_type d, nat_type n)
Return true iff d divide n, i.e. if n is divisible by d.
constexpr nat_type pow_nat(nat_type n, unsigned int k)
Return x^k, x power k.
constexpr bool operator==(const FactorExp &other) const
constexpr nat_type gcd(nat_type a, nat_type b)
Return the Greatest Common Divisor of a and b.
constexpr bool is_first_mersenne_prime_unitary_divide_or_square(nat_type n)
Return true iff is_first_mersenne_prime_unitary_divide(n) or is_square(n).
constexpr bool is_little_mersenne_prime_unitary_divide(nat_type n)
Return true iff at least one of 3, 7, 31, 127, 8191, 131071 or 524287 is an unitary divisor of n...
constexpr bool is_first_mersenne_prime_unitary_divide(nat_type n)
Return true iff at least one of 3, 7, 31 or 127 is an unitary divisor of n.
const double alpha
Definition: harmonic.cpp:24
constexpr nat_type value() const
constexpr nat_type is_coprime(nat_type a, nat_type b)
Return true iff a and b are coprime (relatively prime).