We present C++ software for a program which generates a primitive polynomial of degree n modulo p. You can also test a given polynomial for primitivity and find all primitive polynomials.
A sample run from the command line:
$ Primpoly 2 200
Primpoly Version 10.4 - A Program for Computing Primitive Polynomials. Copyright (C) 1999-2009 by Sean Erik O'Connor. All Rights Reserved. Primpoly comes with ABSOLUTELY NO WARRANTY; for details see the GNU General Public License. This is free software, and you are welcome to redistribute it under certain conditions; see the GNU General Public License for details.
Primitive polynomial modulo 2 of degree 200
Self-check passes...
x ^ 200 + x ^ 5 + x ^ 3 + x ^ 2 + 1, 2
Total time: 8 seconds on my MacBook Pro.
Running time vs degree for modulo 2
MacBookPro 2.4GHz Intel Core 2 Duo 2GB 667MHz DDR2 SDRAM.
I'm currently optimizing the code for speed. You can also try the C version below which is faster for small n and p.
Source code and executables are distributed under the terms of the GNU General Public License for Primpoly Version 10.4
| Click on the
|
|
|
|
Main program. |
|
|
Header file containing parameters and constants. |
|
|
Modulo p integer arithmetic. |
|
|
Modulo p integer arithmetic class. |
|
|
Factoring into primes and primality testing. |
|
|
Factoring into primes and primality testing class. |
|
|
OperationCount collection. |
|
|
OperationCount class. |
|
|
Polynomial I/O. I took the liberty of using my own LALR(1) parser generator on a simple polynomial grammar to automatically generate the parser. Here is the grammar and its LALR(1) parse tables. The C++ LR parser isn't hard to implement using STL vectors and the automatically generated parse tables above. |
|
|
Polynomial I/O. |
|
|
Polynomial arithmetic. |
|
|
Polynomial arithmetic class. |
|
|
Multiple precision integer arithmetic for non-negative numbers. |
|
|
Multiple precision integer arithmetic class. |
|
|
Unit test function for all the classes and their member functions. Runs always and prints to a log file. |
|
|
Unit test function. |
|
|
Makefile for Macs, Unix systems and Windows systems running Cygwin. |
|
|
Known good test results for automated unit test in makefile |
This version is faster but has limits on the size of p and n since it uses native integer arithmetic. See the user manual for more details. For p=2 we can go as high as n=62.
Source code and executables are distributed under the terms of the GNU General Public License for Primpoly Version 10.4
| Click on the
|
|
|
|
This is the main program. |
|
|
This is the header file containing parameters and constants. |
|
|
High level helper functions. |
|
|
Modulo p integer arithmetic, primitive root testing. |
|
|
Factoring into primes and primality testing. |
|
|
Polynomial I/O. |
|
|
Polynomial arithmetic. |
|
|
Polynomial order testing. |
|
|
Makefile for Macs, Unix systems and Windows systems running Cygwin. |
On Mac OS X, I use the Xcode IDE; ona Windows platforms, I use the GNU Cygwin toolset for command line compiling and debugging; and on Unix systems, including Mac OS X, I use the built-in gcc compiler and gdb debugger. For online C++ language tutorials, books and references, see links to C++ documentation.
Copyright © 1986-2009 by Sean Erik O'Connor. All Rights Reserved. last updated 01 Jul 09.