Loading [MathJax]/extensions/tex2jax.js
Parallel numerical verification of the σ_odd problem  October 6, 2018
All Classes Namespaces Files Functions Variables Typedefs Macros
dot.cpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 /** \file common/sigmaodd/dot.cpp (January 2, 2018)
3  *
4  * GPLv3 --- Copyright (C) 2017, 2018 Olivier Pirson
5  * http://www.opimedia.be/
6  */
7 
8 // \cond
9 #include <iostream>
10 #include <map>
11 #include <string>
12 #include <utility>
13 // \endcond
14 
15 #include "sigmaodd.hpp"
16 
17 #include "dot.hpp"
18 
19 
20 namespace sigmaodd {
21 
22  /* *******************
23  * Private prototype *
24  *********************/
25  void
26  print_arrow_(nat_type from, nat_type to, unsigned int length, bool circular);
27 
28 
29 
30  /* ******************
31  * Private function *
32  ********************/
33  void
34  print_arrow_(nat_type from, nat_type to, unsigned int length, bool circular) {
35  const bool is_sqr = is_square(from);
36  const std::string color = (is_sqr
37  ? "orange"
38  : "red");
39  const unsigned int penwidth = (is_sqr
40  ? 3
41  : 5);
42 
43  if (from == to) {
44  std::cout << " " << from << " [style=filled"
45  << (circular
46  ? ", height=3, width=3"
47  : "")
48  << "];" << std::endl;
49  }
50  else if ((from < to) || (length > 1)) {
51  std::cout << " " << from << " [color=" << color << ", style=filled];" << std::endl;
52  }
53 
54  std::cout << std::to_string(from)
55  << " -> "
56  << std::to_string(to);
57 
58  if ((from < to) || (length > 1)) {
59  std::cout << " [color=" << color << ", penwidth=" << penwidth;
60  if (length > 1) {
61  std::cout << ", label=" << std::to_string(length);
62  }
63  std::cout << ']';
64  }
65 
66  std::cout << ';' << std::endl;
67  }
68 
69 
70 
71  /* **********
72  * Function *
73  ************/
74 
75  void
76  print_varsigmaodd_dot(nat_type first, nat_type last, bool show_node,
77  bool shortcut, bool circular) {
78  assert(is_odd(first));
79 
80  // Compute the graph
81  std::map<nat_type, std::pair<nat_type, unsigned int>> map;
82 
83  map[1] = std::make_pair(1, 1);
84 
85  for (nat_type start_n = first; start_n <= last; start_n += 2) {
86  if (shortcut) {
88  }
89  else {
90  nat_type n = start_n;
91 
92  do {
94 
95  map[n] = std::make_pair(to, 1);
96  n = to;
97  } while (n != 1);
98  }
99  }
100 
101 
102  // Print the graph
103  std::cout << "digraph \"sigma odd\" {" << std::endl
104  << (circular
105  ? " layout=\"circo\";"
106  : " rankdir=\"LR\";") << std::endl;
107  if (!show_node) {
108  std::cout << " node[shape=point];" << std::endl;
109  }
110  std::cout << std::endl;
111 
112  for (std::pair<nat_type, std::pair<nat_type, unsigned int>> from_to_length : map) {
113  print_arrow_(from_to_length.first, from_to_length.second.first,
114  from_to_length.second.second, circular);
115  }
116 
117  std::cout << '}' << std::endl;
118  }
119 
120 } // namespace sigmaodd
unsigned long nat_type
Type for natural number used in all code, on 64 bits.
Definition: sigmaodd.cl:22
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.
std::pair< nat_type, unsigned int > sum_odd_divisors_divided_until_odd_iterate_until_lower__factorize(nat_type n)
Iterates the sum_odd_divisors_divided_until_odd__factorize() function from n until have a result lowe...
Definition: sigmaodd.cpp:712
nat_type sum_odd_divisors_divided_until_odd__factorize(nat_type n, bool skip_primes_table)
Calculates the sum of all odd divisors of n by the factorization method, divides the results by 2 unt...
Definition: sigmaodd.cpp:476
bool is_square(nat_type n)
Return true iff n is a perfect square.
Definition: divisors.cpp:267
void print_arrow_(nat_type from, nat_type to, unsigned int length, bool circular)
Definition: dot.cpp:34
A lot of functions and stuffs to deal the sigma_odd problem and related stuffs.
Definition: divisors.cpp:22
To produce graph DOT file.
void print_varsigmaodd_dot(nat_type first, nat_type last, bool show_node, bool shortcut, bool circular)
Print to std::cout in a DOT format, a graph of path of the sigma odd problem.
Definition: dot.cpp:76
Main functions to deal the sigma_odd problem.
std::string to_string(bool b)
Return the string "true" if b, else "false".
Definition: helper.cpp:177