From c25644d503d990af0ae1623e125763028ff2d214 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 19 Apr 2022 15:38:04 +0200 Subject: [PATCH] Add script for regenerating src/finfield_conway.h --- etc/gen_conway.g | 111 ++++++++++++++++++++++++++++++++++++++++++ src/finfield_conway.h | 103 ++++++++++++++++++++------------------- 2 files changed, 164 insertions(+), 50 deletions(-) create mode 100644 etc/gen_conway.g diff --git a/etc/gen_conway.g b/etc/gen_conway.g new file mode 100644 index 0000000000..0f61792941 --- /dev/null +++ b/etc/gen_conway.g @@ -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); diff --git a/src/finfield_conway.h b/src/finfield_conway.h index eb7d176345..459c679c91 100644 --- a/src/finfield_conway.h +++ b/src/finfield_conway.h @@ -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 @@ -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,