Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script for regenerating src/finfield_conway.h #4868

Merged
merged 1 commit into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions etc/gen_conway.g
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#############################################################################
##
## This file is part of GAP, a system for computational discrete algebra.
## This files's authors include Jan De Beule, Max Horn.
##
## Copyright of GAP belongs to its developers, whose names are too numerous
## to list here. Please refer to the COPYRIGHT file for details.
##
## SPDX-License-Identifier: GPL-2.0-or-later
##
## This file contains code to regenerate the PolsFF table in
## src/finfield_conway.h.
##

ConwayPolForCCodeNice := function(p,h,align)
local list,substring,co,sub,i,lc,lpp,empty,a;
empty := Concatenation(List([1..40],x->" "));
list := ConwayPol(p,h);
substring := [String(p^h, align)];
Add(substring,", ");
for i in [1..Length(list)-1] do
co := Int(list[i]);
if co = 0 then
lpp := Length(String(p^(i-1)));
if p = 2 then
sub := empty{[1..1+lpp]};
else
sub := empty{[1..3+lpp]};
fi;
else
if i = 1 then
sub := Concatenation(String(co, 2)," ");
elif p = 2 then
sub := Concatenation("+",String(p^(i-1)));
else
sub := Concatenation("+",String(co),"*",String(p^(i-1)));
fi;
fi;
Add(substring,sub);
od;
# Remove trailing all-whitespace entries
repeat
a := Remove(substring);
NormalizeWhitespace(a);
until Length(a) > 0;
Add(substring, a);
Add(substring,",\n");
return Concatenation(substring);
end;

MAX := 2^16;
align := 4 + LogInt(MAX, 10);

polynomials_as_strings_of_numbers := [];
p := 2;
while p^2 <= MAX do
Print("\rProcessing p = ", p, "\c");
max_h := LogInt(MAX, p);
for h in [2..max_h] do
Add(polynomials_as_strings_of_numbers,ConwayPolForCCodeNice(p,h,align));
od;
p := NextPrimeInt(p);
od;
Print("\n");

CleanupNewlines := function(str)
if str[1] = '\n' then Remove(str, 1); fi;
return str;
end;

stream := OutputTextFile("src/finfield_conway.h", false);
SetPrintFormattingStatus(stream, false);
PrintTo(stream, CleanupNewlines("""
/****************************************************************************
**
** This file is part of GAP, a system for computational discrete algebra.
**
** Copyright of GAP belongs to its developers, whose names are too numerous
** to list here. Please refer to the COPYRIGHT file for details.
**
** SPDX-License-Identifier: GPL-2.0-or-later
**
** The polynomial for q = p^r will be of the form x^r + \sum{a_i x^i} and is
** represented as \sum{a_i q^i}.
*/

#ifndef GAP_FINFIELD_CONWAY_H
#define GAP_FINFIELD_CONWAY_H

/****************************************************************************
**
*V PolsFF . . . . . . . . . . list of Conway polynomials for finite fields
**
** 'PolsFF' is a list of Conway polynomials for finite fields. The even
** entries are the proper prime powers, odd entries are the corresponding
** conway polynomials.
*/
extern const unsigned long PolsFF[]; // FIXME: should be static, but cvec uses it
const unsigned long PolsFF[] = {
"""));
for p in polynomials_as_strings_of_numbers do
PrintTo(stream, p);
od;
PrintTo(stream, CleanupNewlines("""
};


#endif // GAP_FINFIELD_CONWAY_H
"""));

CloseStream(stream);
103 changes: 53 additions & 50 deletions src/finfield_conway.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
** to list here. Please refer to the COPYRIGHT file for details.
**
** SPDX-License-Identifier: GPL-2.0-or-later
**
** The polynomial for q = p^r will be of the form x^r + \sum{a_i x^i} and is
** represented as \sum{a_i q^i}.
*/

#ifndef GAP_FINFIELD_CONWAY_H
Expand All @@ -21,71 +24,71 @@
*/
extern const unsigned long PolsFF[]; // FIXME: should be static, but cvec uses it
const unsigned long PolsFF[] = {
4, 1+2,
8, 1+2,
16, 1+2,
32, 1 +4,
64, 1+2 +8+16,
128, 1+2,
256, 1 +4+8+16,
512, 1 +16,
1024, 1+2+4+8 +32+64,
2048, 1 +4,
4096, 1+2 +8 +32+64+128,
8192, 1+2 +8+16,
16384, 1 +8 +32 +128,
32768, 1 +4 +16+32,
65536, 1 +4+8 +32,
4, 1 +2,
8, 1 +2,
16, 1 +2,
32, 1 +4,
64, 1 +2 +8+16,
128, 1 +2,
256, 1 +4+8+16,
512, 1 +16,
1024, 1 +2+4+8 +32+64,
2048, 1 +4,
4096, 1 +2 +8 +32+64+128,
8192, 1 +2 +8+16,
16384, 1 +8 +32 +128,
32768, 1 +4 +16+32,
65536, 1 +4+8 +32,
9, 2 +2*3,
27, 1 +2*3,
81, 2 +2*27,
81, 2 +2*27,
243, 1 +2*3,
729, 2 +2*3 +1*9 +2*81,
2187, 1 +2*9,
6561, 2 +2*3 +2*9 +1*81 +2*243,
19683, 1 +1*3 +2*9 +2*27,
59049, 2 +1*3 +2*81 +2*243 +2*729,
729, 2 +2*3+1*9 +2*81,
2187, 1 +2*9,
6561, 2 +2*3+2*9 +1*81+2*243,
19683, 1 +1*3+2*9+2*27,
59049, 2 +1*3 +2*81+2*243+2*729,
25, 2 +4*5,
125, 3 +3*5,
625, 2 +4*5 +4*25,
625, 2 +4*5+4*25,
3125, 3 +4*5,
15625, 2 +1*25 +4*125 +1*625,
15625, 2 +1*25+4*125+1*625,
49, 3 +6*7,
343, 4 +6*49,
2401, 3 +4*7 +5*49,
343, 4 +6*49,
2401, 3 +4*7+5*49,
16807, 4 +1*7,
121, 2 + 7*11,
1331, 9 + 2*11,
14641, 2 +10*11 +8*121,
121, 2 +7*11,
1331, 9 +2*11,
14641, 2 +10*11+8*121,
169, 2 +12*13,
2197, 11 + 2*13,
28561, 2 +12*13 +3*169,
2197, 11 +2*13,
28561, 2 +12*13+3*169,
289, 3 +16*17,
4913, 14 + 1*17,
4913, 14 +1*17,
361, 2 +18*19,
6859, 17 + 4*19,
6859, 17 +4*19,
529, 5 +21*23,
12167, 18 + 2*23,
12167, 18 +2*23,
841, 2 +24*29,
24389, 27 + 2*29,
24389, 27 +2*29,
961, 3 +29*31,
29791, 28 + 1*31,
29791, 28 +1*31,
1369, 2 +33*37,
50653, 35 + 6*37,
1681, 6 + 38* 41,
1849, 3 + 42* 43,
2209, 5 + 45* 47,
2809, 2 + 49* 53,
3481, 2 + 58* 59,
3721, 2 + 60* 61,
4489, 2 + 63* 67,
5041, 7 + 69* 71,
5329, 5 + 70* 73,
6241, 3 + 78* 79,
6889, 2 + 82* 83,
7921, 3 + 82* 89,
9409, 5 + 96* 97,
10201, 2 + 97*101,
50653, 35 +6*37,
1681, 6 +38*41,
1849, 3 +42*43,
2209, 5 +45*47,
2809, 2 +49*53,
3481, 2 +58*59,
3721, 2 +60*61,
4489, 2 +63*67,
5041, 7 +69*71,
5329, 5 +70*73,
6241, 3 +78*79,
6889, 2 +82*83,
7921, 3 +82*89,
9409, 5 +96*97,
10201, 2 +97*101,
10609, 5 +102*103,
11449, 2 +103*107,
11881, 6 +108*109,
Expand Down