Bill Allombert on Sat, 17 May 2025 12:05:20 +0200


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

Re: Incorporating Pari into a C program


On Sat, May 17, 2025 at 11:20:37AM +0200, Loïc Grenié wrote:
> #include <pari/pari.h>
> 
>     at the beginning. In your decision(int a*, int n) you'll have to do a
> variant of
> 
>     ***Since I do not know how the elements of the matrix are encoded, you
> said
>   "small rational numbers" but provide a pointer a an array of integers,
> I'll make
>   the (wrong) assumption that a is actually int ***a, where a[i-1][j-1][0]
> is the
>   numerator of the (i,j)-entry and a[i-1][j-1][1] is the denominator.
> You'll have to
>   translate that into the linear versione (maybe
> a[2*n*n*(i-1)+2*n*(j-1)+k], where
>   k is 0 or 1 above).***
> 
>     GEN M, col;
>     long i, j;
> 
>     pari_init(2*1024*1024,500*1000);
>     paristack_setsize(2*1024*1024,1024uL*1024uL*1024uL);
>    M = cgetg(n+1, t_MAT);
>    for (j = 1; j < n; j++) {
>         GEN col = cgetg(n+1, t_COL);
>         for (i = 1; i < n; i++)
>             gel(col, i) = gdiv(ltoi(a[i-1][j-1][0]),ltoi(a[i-1][j-1][1]));

ltoi is actually called stoi. But you can just use sstoQ
  gel(col, i) = sstoQ(a[i-1][j-1][0], a[i-1][j-1][1]);

Cheers,
Bill.