Skip to content
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
2 changes: 1 addition & 1 deletion hpcgap/lib/ffe.gi
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ InstallMethod( RootOfDefiningPolynomial,

coeffs:= ShiftedCoeffs( coeffs[1], coeffs[2] );
p:= Characteristic( F );
d:= ( Length( coeffs ) - 1 ) * DegreeOverPrimeField( F );
d:= DegreeOverPrimeField( F );

if Length( coeffs ) = 2 then
return - coeffs[1] / coeffs[2];
Expand Down
7 changes: 6 additions & 1 deletion hpcgap/lib/ffeconway.gi
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ InstallOtherMethod(ZOp,
[IsPosInt, IsPosInt],
function(p,d)
local q;
if not IsPrimeInt(p) then
Error("Z: <p> must be a prime");
fi;
q := p^d;
if q <= MAXSIZE_GF_INTERNAL or d =1 then
return Z(q);
Expand All @@ -185,7 +188,9 @@ InstallMethod(ZOp,
p := SmallestRootInt(q);
d := LogInt(q,p);
Assert(1, q=p^d);
Assert(2, IsProbablyPrimeInt(p));
if not IsPrimeInt(p) then
Error("Z: <q> must be a positive prime power");
fi;
if d > 1 then
return FFECONWAY.ZNC(p,d);
fi;
Expand Down
2 changes: 1 addition & 1 deletion lib/ffe.gi
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ InstallMethod( RootOfDefiningPolynomial,

coeffs:= ShiftedCoeffs( coeffs[1], coeffs[2] );
p:= Characteristic( F );
d:= ( Length( coeffs ) - 1 ) * DegreeOverPrimeField( F );
d:= DegreeOverPrimeField( F );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any ideas why this factor was there before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I dug a bit. That line was added by @ThomasBreuer in a commit from 1998-11-16 (hash 8a81e3cac9f5878891017aa3b6e9d060a0845f0d in the private git history). Looking at the code added there, a large part of it is identical to code in FieldExtension, including the bit computing d -- there, however, F was the base field, while here it is the extension field. So I suspect this was a copy&paste accident. Since this code was never triggered before I added the patches in this PR, we never noticed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One may in fact wonder whether it wouldn't be better to extract the common code into a new helper operationRootOfPolynomial(F, poly). Then the above RootOfDefiningPolynomial method would essentially becomes F -> RootOfPolynomial(PrimeField(F), DefiningPolynomial(F), and the FieldExtension method could also be shortened. And if somebody comes up with a better implementation than "try all field elements" to do this, they'd have to edit only one spot.


if Length( coeffs ) = 2 then
return - coeffs[1] / coeffs[2];
Expand Down
7 changes: 6 additions & 1 deletion lib/ffeconway.gi
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ InstallOtherMethod(ZOp,
[IsPosInt, IsPosInt],
function(p,d)
local q;
if not IsPrimeInt(p) then
Error("Z: <p> must be a prime");
fi;
q := p^d;
if q <= MAXSIZE_GF_INTERNAL or d =1 then
return Z(q);
Expand All @@ -172,7 +175,9 @@ InstallMethod(ZOp,
p := SmallestRootInt(q);
d := LogInt(q,p);
Assert(1, q=p^d);
Assert(2, IsProbablyPrimeInt(p));
if not IsPrimeInt(p) then
Error("Z: <q> must be a positive prime power");
fi;
if d > 1 then
return FFECONWAY.ZNC(p,d);
fi;
Expand Down
22 changes: 4 additions & 18 deletions src/finfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ FF FiniteField (
succ = (FFV*)(1+ADDR_OBJ( succBag ));

/* if q is a prime find the smallest primitive root $e$, use $x - e$ */
/*N 1990/02/04 mschoene this is likely to explode if 'FFV' is 'UInt4' */
/*N 1990/02/04 mschoene there are few dumber ways to find prim. roots */
if ( d == 1 ) {
for ( e = 1, i = 1; i != p-1; ++e ) {
Expand All @@ -281,7 +280,6 @@ FF FiniteField (
}

/* construct 'indx' such that 'e = x^(indx[e]-1) % poly' for every e */
/*N 1990/02/04 mschoene this is likely to explode if 'FFV' is 'UInt4' */
indx[ 0 ] = 0;
for ( e = 1, n = 0; n < q-1; ++n ) {
indx[ e ] = n + 1;
Expand Down Expand Up @@ -698,7 +696,6 @@ Obj SumFFEFFE (
fR = FLD_FFE( opR );
qR = SIZE_FF( fR );

/*N 1997/01/04 mschoene this is likely to explode if 'FFV' is 'UInt4' */
if ( qL == qR ) {
fX = fL;
}
Expand Down Expand Up @@ -866,7 +863,6 @@ Obj DiffFFEFFE (
fR = FLD_FFE( opR );
qR = SIZE_FF( fR );

/*N 1997/01/04 mschoene this is likely to explode if 'FFV' is 'UInt4' */
if ( qL == qR ) {
fX = fL;
}
Expand Down Expand Up @@ -996,7 +992,6 @@ Obj ProdFFEFFE (
fR = FLD_FFE( opR );
qR = SIZE_FF( fR );

/*N 1997/01/04 mschoene this is likely to explode if 'FFV' is 'UInt4' */
if ( qL == qR ) {
fX = fL;
}
Expand Down Expand Up @@ -1165,7 +1160,6 @@ Obj QuoFFEFFE (
fR = FLD_FFE( opR );
qR = SIZE_FF( fR );

/*N 1997/01/04 mschoene this is likely to explode if 'FFV' is 'UInt4' */
if ( qL == qR ) {
fX = fL;
}
Expand Down Expand Up @@ -1343,11 +1337,7 @@ Obj PowFFEFFE (
{
/* get the field for the result */
if ( CHAR_FF( FLD_FFE(opL) ) != CHAR_FF( FLD_FFE(opR) ) ) {
opR = ErrorReturnObj(
"FFE operations: characteristic of conjugating element must be %d",
(Int)CHAR_FF(FLD_FFE(opL)), 0L,
"you can replace conjugating element <elt> via 'return <elt>;'" );
return POW( opL, opR );
ErrorMayQuit("<x> and <y> have different characteristic", 0, 0);
}

/* compute and return the result */
Expand Down Expand Up @@ -1406,19 +1396,17 @@ Obj FuncLOG_FFE_DEFAULT (
Int a, b, c, d, t; /* temporaries */

/* check the arguments */
if ( ! IS_FFE(opZ) || VAL_FFE(opZ) == 0 ) {
while ( ! IS_FFE(opZ) || VAL_FFE(opZ) == 0 ) {
opZ = ErrorReturnObj(
"LogFFE: <z> must be a nonzero finite field element",
0L, 0L,
"you can replace <z> via 'return <z>;'" );
return FuncLOG_FFE_DEFAULT( self, opZ, opR );
}
if ( ! IS_FFE(opR) || VAL_FFE(opR) == 0 ) {
while ( ! IS_FFE(opR) || VAL_FFE(opR) == 0 ) {
opR = ErrorReturnObj(
"LogFFE: <r> must be a nonzero finite field element",
0L, 0L,
"you can replace <r> via 'return <r>;'" );
return FuncLOG_FFE_DEFAULT( self, opZ, opR );
}

/* get the values, handle trivial cases */
Expand All @@ -1431,7 +1419,6 @@ Obj FuncLOG_FFE_DEFAULT (
fR = FLD_FFE( opR );
qR = SIZE_FF( fR );

/*N 1997/01/04 mschoene this is likely to explode if 'FFV' is 'UInt4' */
if ( qZ == qR ) {
fX = fZ;
qX = qZ;
Expand All @@ -1457,7 +1444,6 @@ Obj FuncLOG_FFE_DEFAULT (
}

/* now solve <l> * (<vR>-1) = (<vZ>-1) % (<qX>-1) */
/*N 1990/02/04 mschoene this is likely to explode if 'FFV' is 'UInt4' */
a = 1; b = 0;
c = (Int) (vR-1); d = (Int) (qX-1);
while ( d != 0 ) {
Expand Down Expand Up @@ -1637,7 +1623,7 @@ Obj FuncZ2 ( Obj self, Obj p, Obj d)
{
ip = INT_INTOBJ(p);
id = INT_INTOBJ(d);
if (ip > 1 && id > 0 && id <= 16 && ip <= 65536)
if (ip > 1 && id > 0 && id <= 16 && ip < 65536)
{
id1 = id;
q = ip;
Expand Down
Loading