Skip to content

Commit 7a3bb78

Browse files
committed
Applying pull-request by d-torrance:
--- Macaulay2 uses givaro as a dependency. However, it builds its own patched givaro, adding an additional version of the function GFqDom [1]. It would great if this function existed natively so that Macaulay2 could be built using a pre-existing givaro on the user's system. ---
1 parent 7042516 commit 7a3bb78

File tree

5 files changed

+146
-6
lines changed

5 files changed

+146
-6
lines changed

examples/Polynomial/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ LDADD = -L${top_srcdir}/src -L${top_srcdir}/src/.libs -lgivaro $(GMP_LIBS) $(LDF
3030
AM_LDFLAGS=-static
3131

3232

33-
EXTRA_PROGRAMS=isirred isprimitive trunc_arith pol_arith pol_eval pol_factor interpolate PolynomialCRT highorder bivariate
33+
EXTRA_PROGRAMS=isirred isprimitive trunc_arith pol_arith pol_eval pol_factor interpolate PolynomialCRT highorder bivariate isgenerator
3434

3535
CLEANFILES=$(EXTRA_PROGRAMS)
3636

3737
interpolate_SOURCES = interpolate.C
3838
isirred_SOURCES = isirred.C
39+
isgenerator_SOURCES = isgenerator.C
3940
isprimitive_SOURCES = isprimitive.C
4041
pol_arith_SOURCES = pol_arith.C
4142
trunc_arith_SOURCES = trunc_arith.C

examples/Polynomial/isgenerator.C

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright(c)'1994-2009 by The Givaro group
2+
// This file is part of Givaro.
3+
// Givaro is governed by the CeCILL-B license under French law
4+
// and abiding by the rules of distribution of free software.
5+
// see the COPYRIGHT file for more details.
6+
/*! @file examples/Polynomial/isprimitive.C
7+
* @ingroup examples
8+
* @ingroup polynomials
9+
* @example examples/Polynomial/isprimitive.C
10+
* @brief NO DOC
11+
*/
12+
13+
#include <iostream>
14+
#include <stdlib.h>
15+
#include <givaro/gfq.h>
16+
#include <givaro/givpoly1factor.h>
17+
#include <givaro/givtimer.h>
18+
19+
// using namespace std;
20+
21+
using namespace Givaro;
22+
23+
24+
int main(int argc, char** argv)
25+
{
26+
typedef GFqDom<int64_t>::Residu_t UT;
27+
UT MOD;
28+
if (argc > 1)
29+
MOD = (UT)atoi(argv[1]);
30+
else
31+
std::cin >> MOD;
32+
uint64_t expo = 1;
33+
if (argc > 2) expo = (uint64_t)atoi(argv[2]);
34+
35+
GFqDom<int64_t> F(MOD, expo);
36+
37+
Poly1FactorDom<GFqDom<int64_t>, Dense> FD(F,Indeter("X"));
38+
Poly1FactorDom<GFqDom<int64_t>, Dense>::Element P, G;
39+
FD.read( std::cin, P );
40+
FD.read( std::cin, G );
41+
42+
Timer tim; tim.clear(); tim.start();
43+
bool f = FD.is_prim_root(G, P );
44+
tim.stop();
45+
46+
FD.write(F.write( FD.write( std::cout, G ) << " is " << (f?"":"not ") << " a generator in " ) << " defined with ", P) << std::endl;
47+
48+
// std::cout << f << std::endl;
49+
std::cerr << tim << std::endl;
50+
51+
return 0;
52+
}
53+

src/kernel/field/gfq.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// and abiding by the rules of distribution of free software.
66
// see the COPYRIGHT file for more details.
77
// file: gfq.h
8-
// Time-stamp: <28 Oct 15 20:48:41 Jean-Guillaume.Dumas@imag.fr>
8+
// Time-stamp: <17 Jul 16 16:12:52 Jean-Guillaume.Dumas@imag.fr>
99
// date: 1999
1010
// version:
1111
// author: Jean-Guillaume.Dumas
@@ -98,6 +98,14 @@ template<class TT> class GFqDom {
9898
template<typename Vector>
9999
GFqDom(const UTT P, const UTT e, const Vector& modPoly);
100100

101+
// Construction with prescribed irreducible polynomial
102+
// and with prescribed generator polynomial
103+
// coefficients of the vector should be integers-like
104+
// there will be a call to this->init to build the
105+
// representation of both polynomials
106+
template<typename Vector>
107+
GFqDom( const UTT P, const UTT e, const Vector& modPoly, const Vector& genPoly);
108+
101109
GFqDom( const GFqDom<TT>& F)
102110
: zero(F.zero),
103111
one(F.one),

src/kernel/field/gfq.inl

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,77 @@ namespace Givaro {
11151115
_plus1[size_t(mOne)] = 0;
11161116
}
11171117

1118+
// Construction with prescribed irreducible polynomial
1119+
// and with prescribed generator polynomial
1120+
// coefficients of the vector should be integers-like
1121+
// there will be a call to this->init to build the
1122+
// representation of both polynomials
1123+
template<typename TT>
1124+
template<typename Vector>
1125+
inline GFqDom<TT>::GFqDom(const UTT P, const UTT e,
1126+
const Vector& modPoly, const Vector& genPoly):
1127+
zero(0)
1128+
, one ((TT) power(P,e) - 1 )
1129+
, mOne( (P==2)? (one) : ( one >> 1) ) // 1 == -1 in GF(2^k)
1130+
, _characteristic(P)
1131+
, _exponent(e)
1132+
, _q( (UTT) one + 1 )
1133+
, _qm1 ( (UTT)one )
1134+
, _log2pol( (UT)_q )
1135+
, _pol2log( (UT)_q )
1136+
, _plus1( (UT)_q )
1137+
, _dcharacteristic( (double)P )
1138+
{
1139+
1140+
// 1 is represented by q-1, zero by 0
1141+
_log2pol[0] = (UTT)zero;
1142+
1143+
GFqDom<TT> Zp(P,1);
1144+
typedef Poly1FactorDom< GFqDom<TT>, Dense > PolDom;
1145+
PolDom Pdom( Zp );
1146+
typename PolDom::Element Ft, F(e+1), G(genPoly.size()), H;
1147+
1148+
for( size_t i = 0; i < F.size(); ++i )
1149+
Zp.init( F[i], modPoly[i]);
1150+
1151+
for( size_t i = 0; i < G.size(); ++i )
1152+
Zp.init( G[i], genPoly[i]);
1153+
1154+
Pdom.assign(H,G);
1155+
1156+
typedef Poly1PadicDom< GFqDom<TT>, Dense > PadicDom;
1157+
PadicDom PAD(Pdom);
1158+
1159+
PAD.eval(_log2pol[1],H);
1160+
PAD.eval(_irred, F);
1161+
1162+
for (UTT i = 2; i < _qm1; ++i) {
1163+
Pdom.mulin(H, G);
1164+
Pdom.modin(H, F);
1165+
PAD.eval(_log2pol[i], H);
1166+
}
1167+
_log2pol[_qm1] = 1;
1168+
1169+
_log2pol[0] = 0;
1170+
1171+
for (UTT i = 0; i < _q; ++i)
1172+
_pol2log[ _log2pol[i] ] = i;
1173+
1174+
_plus1[0] = 0;
1175+
1176+
UTT a,b,r;
1177+
for (UTT i = 1; i < _q; ++i) {
1178+
a = _log2pol[i];
1179+
r = a % P;
1180+
if (r == (P - 1))
1181+
b = a - r;
1182+
else
1183+
b = a + 1;
1184+
_plus1[i] = (TT)_pol2log[b] - (TT)_qm1;
1185+
}
1186+
1187+
_plus1[size_t(mOne)] = 0;
1188+
}
11181189

11191190
template<typename TT> inline void GFqDom<TT>::Init() {}
11201191

tests/test-ffarith.C

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,19 @@ int main(int argc, char ** argv)
371371

372372
// Zech log finite field with 256 elements
373373
// and prescribed 1 + x +x^3 +x^4 +x^8 irreducible polynomial
374-
std::vector< GFqDom<int64_t>::Residu_t > Irred(9);
375-
Irred[0] = 1; Irred[1] = 1; Irred[2] = 0; Irred[3] = 1;
376-
Irred[4] = 1; Irred[5] = 0; Irred[6] = 0; Irred[7] = 0;
377-
Irred[8] = 1;
374+
// std::vector< GFqDom<int64_t>::Residu_t > Irred(9);
375+
// Irred[0] = 1; Irred[1] = 1; Irred[2] = 0; Irred[3] = 1;
376+
// Irred[4] = 1; Irred[5] = 0; Irred[6] = 0; Irred[7] = 0;
377+
// Irred[8] = 1;
378+
std::vector< int64_t > Irred {1,1,0,1,1,0,0,0,1};
378379
TEST_SPECIFIC(GFqDom<int64_t>, GF256, 2, 8, Irred);
379380

381+
// Zech log finite field with 343 elements
382+
// and prescribed 3 +x^3 irreducible polynomial
383+
// and prescribed 5 +3x +4x^2 generator polynomial
384+
std::vector< int64_t > Irred3 {3,0,0,1}, Gene3 {5,3,4};
385+
TEST_SPECIFIC(GFqDom<int64_t>, GF343, 7, 3, Irred3, Gene3);
386+
380387
TEST_SPECIFIC(GFqDom<int32_t>, GF625, 5, 4);
381388
TEST_SPECIFIC(GFqExt<int32_t>, GF81, 3, 4);
382389

0 commit comments

Comments
 (0)