Bill Allombert on Sun, 6 Apr 2003 19:54:25 +0200


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

Re: very simple Pari program


On Sun, Apr 06, 2003 at 01:00:00PM -0400, Allan Adler wrote:
> Here is a very simple Pari 2.1.4 program I wrote.
> 
> #include "pari.h"
> 
> main()
> {
>  printf("%d\n",qfbhclassno(28));
> }
> 
> I tried to compile it on a *86 system running RedHat Linux 7.1:
> 
> gcc classnos.c -lm -lpari -I.
> 
> Here is what happened:
> 
> In file included from pari.h:70,
>                  from classnos.c:3:
> parigen.h:22: warning: redefinition of `ulong'
> /usr/include/sys/types.h: 144: warning: `ulong' previously declared here
> /tmp/ccEqSW6i.o: In function `main':
> /tmp/ccEqSW6i.o(.text+0xf): undefined reference fo `qfbhclassno'
> collect2: ld returned 1 exit status

Here a correct program:

#include "pari.h"
main()
{
  pari_init(4000000, 50000);/*Init pari*/
  pariputsf("%Z\n",hclassno(stoi(28)));
}

%gcc qfb.c -lpari -lm
%./a.out
2

Here some more detail:
--- pari_init(4000000, 50000);
This initialize PARI. This must be called once at the start of your
program.  The number correspond to the message
parisize = 4000000, primelimit = 500000
that appear at the start of GP.

--- stoi(28): this build the PARI object equal to 28.
--- hclassno: this is the C name of the qfbhclassno function,

? ??qfbhclassno
...
   The library syntax is hclassno(x).

--- pariputsf() is the PARI equivalent of printf. it support the
   special format type %Z to print PARI objects.

You can look at the examples/matexp.c file.

I agree all this difference between GP and PARI are tedious. That
why I wrote GP2C. This is a program that automatically generate
C code from a GP script (without the call to pari_init currently).

for example if you give 
print(qfbclassno(28)) to GP2C it will output 

pariputsf("%Z\n",hclassno(stoi(28)));

GP2C is available at 
ftp://megrez.math.u-bordeaux.fr/pub/pari/GP2C/gp2c-0.0.2pl5.tar.gz

Cheers,
Bill.