1/*==============================================================================
2|
3| NAME
4|
5| ppOperationCount.cpp
6|
7| DESCRIPTION
8|
9| Collect operation counts for the primitive polynomial algorithm:
10| number of iterations for prime factoring, number of polynomials free of
11| linear factors, and whatnot.
12|
13| User manual and technical documentation are described in detail in my web page at
14| http://seanerikoconnor.freeservers.com/Mathematics/AbstractAlgebra/PrimitivePolynomials/overview.html
15|
16| LEGAL
17|
18| Primpoly Version 16.3 - A Program for Computing Primitive Polynomials.
19| Copyright (C) 1999-2024 by Sean Erik O'Connor. All Rights Reserved.
20|
21| This program is free software: you can redistribute it and/or modify
22| it under the terms of the GNU General Public License as published by
23| the Free Software Foundation, either version 3 of the License, or
24| (at your option) any later version.
25|
26| This program is distributed in the hope that it will be useful,
27| but WITHOUT ANY WARRANTY; without even the implied warranty of
28| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29| GNU General Public License for more details.
30|
31| You should have received a copy of the GNU General Public License
32| along with this program. If not, see http://www.gnu.org/licenses/.
33|
34| The author's address is seanerikoconnor!AT!gmail!DOT!com
35| with !DOT! replaced by . and the !AT! replaced by @
36|
37==============================================================================*/
38
39
40
41/*------------------------------------------------------------------------------
42| Includes |
43------------------------------------------------------------------------------*/
44
45#include <cstdlib> // abort()
46#include <iostream> // Basic stream I/O.
47#include <new> // set_new_handler()
48#include <cmath> // Basic math functions e.g. sqrt()
49#include <limits> // Numeric limits.
50#include <complex> // Complex data type and operations.
51#include <fstream> // File stream I/O.
52#include <sstream> // String stream I/O.
53#include <vector> // STL vector class.
54#include <string> // STL string class.
55#include <algorithm> // Iterators.
56#include <stdexcept> // Exceptions.
57#include <cassert> // assert()
58
59using namespace std ; // So we don't need to say std::vector everywhere.
60
61
62
63/*------------------------------------------------------------------------------
64| PP Include Files |
65------------------------------------------------------------------------------*/
66
67#include "Primpoly.hpp" // Global functions.
68#include "ppArith.hpp" // Basic arithmetic functions.
69#include "ppBigInt.hpp" // Arbitrary precision integer arithmetic.
70#include "ppOperationCount.hpp" // OperationCount collection for factoring and poly finding.
71#include "ppFactor.hpp" // Prime factorization and Euler Phi.
72#include "ppPolynomial.hpp" // Polynomial operations and mod polynomial operations.
73#include "ppParser.hpp" // Parsing of polynomials and I/O services.
74#include "ppUnitTest.hpp" // Complete unit test.
75
76
77/*=============================================================================
78 |
79 | NAME
80 |
81 | OperationCount
82 |
83 | DESCRIPTION
84 |
85 | Default constructor.
86 |
87 +============================================================================*/
88
89OperationCount::OperationCount()
90 : n( 0u )
91 , p( 0u )
92 , max_num_possible_poly( 0u )
93 , num_primitive_poly( 0u )
94 , num_poly_tested( 0u )
95 , num_gcds( 0u )
96 , num_primality_tests( 0u )
97 , num_squarings( 0u )
98 , num_trial_divides( 0u )
99 , num_free_of_linear_factors( 0u )
100 , num_where_const_coeff_is_primitive_root( 0u )
101 , num_passing_const_coeff_test( 0u )
102 , num_irreducible_to_power( 0u )
103 , num_order_m( 0u )
104 , num_order_r( 0u )
105{
106}
107
108
109
110/*=============================================================================
111 |
112 | NAME
113 |
114 | OperationCount
115 |
116 | DESCRIPTION
117 |
118 | No special destruction needed.
119 |
120 +============================================================================*/
121
122OperationCount::~OperationCount()
123{
124}
125
126
127
128/*=============================================================================
129 |
130 | NAME
131 |
132 | OperationCount
133 |
134 | DESCRIPTION
135 |
136 | Copy constructor.
137 |
138 +============================================================================*/
139
140OperationCount::OperationCount( const OperationCount & statistics )
141 :n( statistics.n )
142 ,p( statistics.p )
143 ,max_num_possible_poly( statistics.max_num_possible_poly )
144 ,num_primitive_poly( statistics.num_primitive_poly )
145 ,num_poly_tested( statistics.num_poly_tested )
146 ,num_gcds( statistics.num_gcds )
147 ,num_primality_tests( statistics.num_primality_tests )
148 ,num_squarings( statistics.num_squarings )
149 ,num_trial_divides( statistics.num_trial_divides )
150 ,num_free_of_linear_factors( statistics.num_free_of_linear_factors )
151 ,num_where_const_coeff_is_primitive_root( statistics.num_where_const_coeff_is_primitive_root )
152 ,num_passing_const_coeff_test( statistics.num_passing_const_coeff_test )
153 ,num_irreducible_to_power( statistics.num_irreducible_to_power )
154 ,num_order_m( statistics.num_order_m )
155 ,num_order_r( statistics.num_order_r )
156
157{
158}
159
160
161
162/*=============================================================================
163 |
164 | NAME
165 |
166 | OperationCount
167 |
168 | DESCRIPTION
169 |
170 | Assignment.
171 |
172 +============================================================================*/
173
174OperationCount & OperationCount::operator=( const OperationCount & statistics )
175{
176 // Check for assigning to oneself: just pass back a reference to the unchanged object.
177 if (this == &statistics)
178 return *this ;
179
180 n = statistics.n ;
181 p = statistics.p ;
182
183 max_num_possible_poly = statistics.max_num_possible_poly ;
184 num_primitive_poly = statistics.num_primitive_poly ;
185
186 num_poly_tested = statistics.num_poly_tested ;
187 num_gcds = statistics.num_gcds ;
188 num_primality_tests = statistics.num_primality_tests ;
189 num_squarings = statistics.num_squarings ;
190 num_trial_divides = statistics.num_trial_divides ;
191 num_free_of_linear_factors = statistics.num_free_of_linear_factors ;
192 num_where_const_coeff_is_primitive_root = statistics.num_where_const_coeff_is_primitive_root ;
193 num_passing_const_coeff_test = statistics.num_passing_const_coeff_test ;
194 num_irreducible_to_power = statistics.num_irreducible_to_power ;
195 num_order_m = statistics.num_order_m ;
196 num_order_r = statistics.num_order_r ;
197
198 return *this ;
199}
200
201
202
203/*=============================================================================
204 |
205 | NAME
206 |
207 | OperationCount
208 |
209 | DESCRIPTION
210 |
211 | Print out a report of the operation count to the console.
212 |
213 +============================================================================*/
214
215ostream & operator<<( ostream & out, const OperationCount & op )
216{
217 out << "+--------- OperationCount --------------------------------\n" ;
218 out << "|\n" ;
219 out << "| Integer factorization: Table lookup + Trial division + Pollard Rho\n" ;
220 out << "|\n" ;
221 out << "| Number of trial divisions : " << op.num_trial_divides << endl ;
222 out << "| Number of gcd's computed : " << op.num_gcds << endl ;
223 out << "| Number of primality tests : " << op.num_primality_tests << endl ;
224 out << "| Number of squarings: " << op.num_squarings << endl ;
225 out << "|\n" ;
226 out << "| Polynomial Testing\n" ;
227 out << "|\n" ;
228 out << "| Total num. degree " << op.n << " poly mod " << op.p << " : " << op.max_num_possible_poly << endl ;
229 out << "| Number of possible primitive poly: " << op.num_primitive_poly << endl ;
230 out << "| Polynomials tested : " << op.num_poly_tested << endl ;
231 out << "| Const. coeff. was primitive root : " << op.num_where_const_coeff_is_primitive_root << endl ;
232 out << "| Free of linear factors : " << op.num_free_of_linear_factors << endl ;
233 out << "| Irreducible to power >=1 : " << op.num_irreducible_to_power << endl ;
234 out << "| Had order r (x^r = integer) : " << op.num_order_r << endl ;
235 out << "| Passed const. coeff. test : " << op.num_passing_const_coeff_test << endl ;
236 out << "| Had order m (x^m != integer) : " << op.num_order_m << endl ;
237 out << "|\n" ;
238 out << "+-----------------------------------------------------\n" ;
239
240 return out ;
241}