Skip to content

Commit

Permalink
kernel: add LookupPrimePower helper
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Dec 21, 2018
1 parent d9a48a9 commit 8a5877e
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions src/finfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,20 @@ static Obj TYPE_FFE0;
// used for successor bags
static Obj TYPE_KERNEL_OBJECT;


/****************************************************************************
**
*F FiniteField(<p>,<d>) . . . make the small finite field with <q> elements
*F LookupPrimePower(<q>) . . . . . . . . search for a prime power in tables
**
** 'FiniteField' returns the small finite field with <p>^<d> elements.
** Searches the tables of prime powers from ffdata.c for q, returns the
** index of q in SizeFF if it is present and 0 if not (the 0 position of
** SizeFF is unused).
*/
FF FiniteField (
UInt p,
UInt d )
static FF LookupPrimePower(UInt q)
{
FF ff; /* finite field, result */
Obj tmp; /* temporary bag */
Obj succBag; /* successor table bag */
FFV * succ; /* successor table */
FFV * indx; /* index table */
UInt q; /* size of finite field */
UInt poly; /* Conway polynomial of extension */
UInt i, l, f, n, e; /* loop variables */

/* calculate size of field */
q = 1;
for (i = 1; i <= d; i++)
q *= p;
UInt l, n;
FF ff;
UInt e;

/* search through the finite field table */
l = 1;
Expand All @@ -85,10 +76,39 @@ FF FiniteField (
}
if (ff < 1 || ff > NUM_SHORT_FINITE_FIELDS)
return 0;
if (CharFF[ff] != p)
return 0;
if (SizeFF[ff] != q)
return 0;
return ff;
}


/****************************************************************************
**
*F FiniteField(<p>,<d>) . . . make the small finite field with <q> elements
**
** 'FiniteField' returns the small finite field with <p>^<d> elements.
*/
FF FiniteField (
UInt p,
UInt d )
{
FF ff; /* finite field, result */
Obj tmp; /* temporary bag */
Obj succBag; /* successor table bag */
FFV * succ; /* successor table */
FFV * indx; /* index table */
UInt q; /* size of finite field */
UInt poly; /* Conway polynomial of extension */
UInt i, l, f, n, e; /* loop variables */

/* calculate size of field */
q = 1;
for (i = 1; i <= d; i++)
q *= p;

ff = LookupPrimePower(q);
if (CharFF[ff] != p)
return 0;
#ifdef HPCGAP
/* Important correctness concern here:
*
Expand Down

0 comments on commit 8a5877e

Please sign in to comment.