| Bill Allombert on Mon, 17 Nov 2025 17:47:22 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: correct way to expose pari internal functions? |
On Mon, Nov 17, 2025 at 05:03:15PM +0100, hermann@stamm-wilbrandt.de wrote:
> I stumbled through pari source code looking for "qfsolve()" and found this
> nearby in "src/basemath/qfsolve.c":
>
> /* p a prime number, G 3x3 symmetric. Finds X!=0 such that X^t G X = 0 mod
> p.
> * Allow returning a shorter X: to be completed with 0s. */
> static GEN
> qfsolvemodp(GEN G, GEN p)
>
> I wanted to play with, but since it is static it cannot be just used with GP
> "install()" command.
>
> I saw that "qfsolve()" implementation is oneliner calling static
> "qfsolve_i()".
>
> I copied that and renamed:
>
> GEN
> qfsolvemodp_(GEN G, GEN p)
> { pari_sp av = avma; return gerepilecopy(av, qfsolvemodp(G, p)); }
>
> Then I added this to "src/headers/paridecl.h":
>
> GEN qfsolvemodp_(GEN G, GEN p);
>
> After "make all" and starting gp new function works:
>
> hermann@j4105:~/pari-2.17.2$ ./gp -q
> ? install("qfsolvemodp_","GG")
> ? qfsolvemodp_(matdiagonal([1,1,1]),13)
> [5, 1, 0]~
> ? abs(qfsolve(matdiagonal([1,1,1,-13]))[1..3])
> [3, 2, 0]~
> ?
>
>
> Is this the correct way to expose internal functions for playing with?
Correct ? Yes.
But if you just want to try it, just remove the 'static' and recompile.
then do
install("qfsolvemodp","mGG")
to let GP do the gerepilecopy (recently renamed to gc_GEN) itself.
Cheers,
Bill.