Mike Rosing on Tue, 24 Feb 2015 16:27:17 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Using libpari


Thanks Karim!

Since I had something working by hand, I tried it with gp2c. I ended up with this:

while(a6coef < 0x3ffff)
  {
    mask = 1;
    a2 = gen_0;
    a6 = gen_0;
    for(i=0; i<64; i++)
    {
      if(mask & a2coef)
	a2 = gadd(gpowgs(y,i), a2);
      if(mask & a6coef)
	a6 = gadd(gpowgs(y,i), a6);
      mask <<= 1;
    }

I then alternate incrementing a2coef and a6coef.
This is very similar to your concat suggestion (and probably not as efficient).

I really appreciate your answer - I have a lot of functions to look at!
Mike

On Tue, 24 Feb 2015, Karim Belabas wrote:


* Mike Rosing [2015-02-23 19:39]:
Hello,

I am trying to use libpari as a stand alone C program rather than creating
useful functions for gp.  I can do things easily with gp (well, not so easy
the first time!) but when I try to do similar things in C I get a lot of
errors.

What I would like to do is create GF(2^n) elements in "increasing" order:
1
t
t + 1 t^2
t^2 + 1
t^2 + t
t^2 + t + 1
etc..

This is not easy ! The "simple" way is to call ffgen + FF_primroot then
compute its powers via 2^n-2 multiplications.

I start my program, and things are fine:

#include <pari/pari.h>

int main()
{
  GEN y, E, f, z, a1, a2;

  pari_init(2*1024*1024, 5*1024*512);
  z = ffinit(gen_2, 10, -1);
  y = ffgen(z, -1);

This creates a polynomial z in F_2[x], and create y as (x mod z(x))

  pari_printf("%Ps %ld\n", type0(y), lg(y));

----------------------

I can give a2 a constant value like gen_1, but I have no idea how to give it
a value of y, let alone different t_FFELT values.

For specific values:

a2 = y;  // x mod z
a2 = gadd(y, gen_1); // x+1

More complicated:

A = mkpoln(5, gen_1,gen_0,gen_1,gen_0,gen_0); // x^2+x^4
a2 = gsubst(A, gvar(A), y);  // A(x), assuming A is a t_POL with coefs in Z, say

To go through all finite fields elements in the order you requested, you
need some backtracking algorithm emulating forvec(). It's a nice
exercise, but I'd advise against it if you're beginning with libpari :-)

Another (not too wasteful) posibility is to use something like

 // assume 2^n is representable as an ulong
 ulong i, N = upowuu(2,n);
 GEN vy = concat( gpow(y,gen_0), vecpow(y,n-1) ); // vy[i] = y^(i-1)
 for(i=0; i < N; i++)
 {
   GEN h = RgV_sum( shallowextract(vy, utoi(i)) );
   ...
 }

(Easier in characteristic 2, but digits() allows to generalize ...)

Cheers,

   K.B.
--
Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite de Bordeaux         Fax: (+33) (0)5 40 00 69 50
351, cours de la Liberation    http://www.math.u-bordeaux.fr/~kbelabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux.fr/  [PARI/GP]
`