Gordon Royle on Mon, 15 Sep 2025 09:35:32 +0200


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

Using Pari from within a C program


Dear Pari Users

I wonder if someone could point me in the right direction with the following task.

I am aware that there is documentation concerning the use of Pari as a library and how to incorporate it into a C program, but in this situation (described below), I don't have full control over the C program and I don't understand where to put things like the Pari initialisation code. 

Anyway, here is the setup.

I am writing a single function in C that has a fixed prototype that is to be called hundreds of millions of times as a "plugin" in a larger program.

The function uses the arguments to create a symmetric integer matrix, decides if it has any eigenvalues strictly less than zero, and returns 1 if so and 0 otherwise. 

The function is used to control the pruning of a huge combinatorial search tree - if the matrix does have an eigenvalue strictly less than zero, then that branch of the search can be pruned.

I need the calculation to be done in exact arithmetic - no floating-point number or approximations.

It seems to me that the GP function "qfsign" for computing the signature of a quadratic form is what I need to use

So logically it all seems ok

Int pruner(<arguments> {
  // create matrix a
  // call qfsign(a) 
 // return 0/1 
}

This little function will be compiled into existing code via a compilation flag; in the first instance I'd like to assume that I can't change the existing code.

I'd really appreciate just a simple working example of how to do this using Pari.

Thanks in advance

Gordon