1/*==============================================================================
2|
3| NAME
4|
5| Primpoly.hpp
6|
7| DESCRIPTION
8|
9| Global header file for primitive polynomial routines.
10| Constants, message strings, data types and algorithm control parameters.
11|
12| User manual and technical documentation are described in detail in my web page at
13| http://seanerikoconnor.freeservers.com/Mathematics/AbstractAlgebra/PrimitivePolynomials/overview.html
14|
15| LEGAL
16|
17| Primpoly Version 16.3 - A Program for Computing Primitive Polynomials.
18| Copyright (C) 1999-2024 by Sean Erik O'Connor. All Rights Reserved.
19|
20| This program is free software: you can redistribute it and/or modify
21| it under the terms of the GNU General Public License as published by
22| the Free Software Foundation, either version 3 of the License, or
23| (at your option) any later version.
24|
25| This program is distributed in the hope that it will be useful,
26| but WITHOUT ANY WARRANTY; without even the implied warranty of
27| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28| GNU General Public License for more details.
29|
30| You should have received a copy of the GNU General Public License
31| along with this program. If not, see http://www.gnu.org/licenses/.
32|
33| The author's address is seanerikoconnor!AT!gmail!DOT!com
34| with !DOT! replaced by . and the !AT! replaced by @
35|
36==============================================================================*/
37
38// Wrap this header file to prevent duplication if it is included
39// accidentally more than once.
40#ifndef PP_H
41#define PP_H
42
43
44/*=============================================================================
45 |
46 | NAME
47 |
48 | Debug macros.
49 |
50 +============================================================================*/
51
52// Let's do this always, so we can gather bug information from users.
53#define SELF_CHECK
54
55// These debugging flags are normally be defined in the makefile or build file,
56// but you could alternately define them here.
57#define DEBUG_ALL
58#undef DEBUG_ALL
59
60#ifdef DEBUG_ALL
61 // Highest level primitivity testing:
62 #define DEBUG_PP_PRIMITIVITY
63
64 // Polynomial calculations debugging:
65 #define DEBUG_PP_POLYNOMIAL
66
67 // Debug the LALR(1) parser for polynomials and factor tables:
68 #define DEBUG_PP_PARSER
69
70 // Testing primality:
71 #define DEBUG_PP_PRIMALITY_TESTING
72
73 // Factoring into primes:
74 #define DEBUG_PP_FACTOR
75
76 // Arbitrary precision arithmetic debugging:
77 #define DEBUG_PP_BIGINT
78
79 // Modulo p arithmetic debugging:
80 #define DEBUG_PP_ARITH
81#endif // DEBUG_ALL
82
83// Forces one or more unit tests to fail and generate test error messages.
84// Default is to leave undefined.
85//
86// #define DEBUG_PP_FORCE_UNIT_TEST_FAIL
87//
88// Turn on to check memory exceptions. Default is to leave it off.
89// This may crash some on machines with buggy C++ compilers and OS's.
90//
91// #define DEBUG_PP_FORCE_MEMORY_OVERLOAD
92
93
94/*=============================================================================
95 |
96 | NAME
97 |
98 | Basic integer types.
99 |
100 | DESCRIPTION
101 |
102 | Define the basic integer types we will use for all modulus p calculations,
103 | multiple precision arithmetic, polynomial operations and factoring.
104 | Higher precision will decrease your computation time according to profiling.
105 |
106 +============================================================================*/
107
108// Microsoft Windows 7 64-bit + Visual C++ compiler or Cygwin.
109#if defined( _MSC_VER ) || defined( __CYGWIN__ )
110 // 64-bit integer types.
111 typedef unsigned long long ppuint ;
112 typedef signed long long ppsint ;
113
114 // 32-bit integer types.
115 typedef unsigned int ppuint32 ;
116 typedef unsigned int ppsint32 ;
117// Mac OS X or Ubuntu Linux.
118#else
119 // 64-bit integer types.
120 typedef unsigned long int ppuint ;
121 typedef signed long int ppsint ;
122
123 // 32-bit integer types.
124 typedef unsigned int ppuint32 ;
125 typedef unsigned int ppsint32 ;
126#endif
127
128// Check if we have at least 64-bit arithmetic.
129static_assert( 8 * sizeof( ppuint ) >= 64 || 8 * sizeof( ppsint ) >= 64,
130 "Error: basic integer types ppuint and ppsint must be at least 64-bits. Sorry, you'll have to run on a computer with a 64-bit CPU." ) ;
131
132// Check if we have 32-bit arithmetic.
133static_assert( 8 * sizeof( ppuint32 ) == 32 || 8 * sizeof( ppsint32 ) == 32,
134 "Error: basic integer types ppuint32 and ppsint32 must be at least 32-bits. Redefine the types in Primpoly.hpp" ) ;
135
136
137/*=============================================================================
138 |
139 | NAME
140 |
141 | ReturnStatus
142 |
143 | DESCRIPTION
144 |
145 | Enumerated type integer status fed back to the Unix shell from main().
146 |
147 +============================================================================*/
148
149enum class ReturnStatus
150{
151 Success = 0,
152 AskForHelp = 1,
153 PNotPrime = 2,
154 RangeError = 3,
155 InternalError = 4,
156 Reserved = 5
157} ;
158
159
160/*=============================================================================
161 |
162 | NAME
163 |
164 | PrimpolyError
165 |
166 | DESCRIPTION
167 |
168 | Top level error class used in main() and UnitTest.
169 |
170 +============================================================================*/
171
172class PrimpolyError : public runtime_error
173{
174 public:
175 // Throw with error message, file name and line number.
176 PrimpolyError( const string & description, const string & file, const int & line )
177 : runtime_error( description + " in file " + file + " at line " + to_string(line) )
178 {
179 } ;
180
181 // Throw with an error message.
182 PrimpolyError( const string & description )
183 : runtime_error( description )
184 {
185 } ;
186
187 // Default throw with no error message.
188 PrimpolyError()
189 : runtime_error( "Polynomial error: " )
190 {
191 } ;
192
193} ; // end class PrimpolyError
194
195
196/*=============================================================================
197 |
198 | NAME
199 |
200 | Message strings.
201 |
202 | DESCRIPTION
203 |
204 | Messages to console which are used by main() only.
205 |
206 +============================================================================*/
207
208static const string writeToAuthorMessage
209(
210 "Dear User,\n"
211 " Sorry you got an error message. Please email the author at\n"
212 " seanerikoconnor!AT!gmail!DOT!com\n"
213 " with !DOT! replaced by . and the !AT! replaced by @\n"
214 #ifdef SELF_CHECK
215 " Please send me all console output from this program.\n"
216 " Attach the unitTest.log file which should be located in the current directory.\n"
217 " However, if the self-check failed, there won't be a log file.\n"
218 #else
219 " It looks like you have the unit test self check compiled off."
220 " Please set #define SELF_CHECK in the Primpoly.hpp header file, recompile and rerun."
221 #endif
222 "Thanks for your help,\n"
223 "Sean E. O'Connor\n"
224 "\n"
225) ;
226
227static const string confirmWarning
228(
229 "Confirming polynomial is primitive with a brute force check.\n"
230 "WARNING: You may wait an impossibly long time!\n"
231 "To abort, hit control-C in your console window to stop this program.\n"
232) ;
233
234#endif // End of wrapper for header.