Re: Incorporating Pari into a C program

Bill Allombert <[email protected]>
Newsgroups gmane.comp.mathematics.pari.user
Message-ID <aChfXKUcFkEKZDOF@seventeen>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.