/* C program using pari.h -- many examples by Steven Miller, Princeton University Last modified April 2001 */ #include "pari.h" int main() { long x; GEN y, z, a, v, b, F, E; /* Section 1: by Josko Plazonic initialization procedures GEN stands for generic pari type this section shows how to create GEN variables and goes thru the initialization process */ /*@Ccom take a stack of $10^6$ bytes, no prime table */ pari_init(1000000, 2); y = cgeti(32); /* need to initialize the variables b4 using this makes them big integers */ z = cgeti(32); a = cgeti(32); b = cgeti(32); gaffsg(800, y); /* assigns 800 to y */ printf("parametar: "); outbrute(y); /* prints u */ z = phi(y); /* makes z = phi(y), phi a pari function */ printf("\nresult: "); outbrute(z); printf("\n"); for (x=2; x <= 10; ++x) /* note x is a regular C variable */ { gaffsg(x, y); /* assigns x to y */ printf("phi["); outbrute(y); printf("] = "); z = phi(y); /* uses phi, a function from pari */ outbrute(z); printf("\n"); } printf("Made it thru Stage 1 Successfully\n"); /*!!!!!!!!!!!*/ /* */ /* Stage 2 */ /* */ /*!!!!!!!!!!!*/ v = cgetg(3, t_COMPLEX); /* v will be a complex number */ v[1] = lgetr(MEDDEFAULTPREC); /* initializing components */ v[2] = lgetr(MEDDEFAULTPREC); gaffsg(11,b); a = phi(b); /* makes a the pari number phi(11) */ (GEN) v[1] = a; /* assigns a to v[1] */ /* the program works without the (GEN) in front of v[1], but a warning message is generated. the (GEN) should be added to help C correctly cast objects */ printf("v[1] = "); outbrute((GEN) v[1]); printf("\n"); printf("Made it thru Stage 2 Successfully\n"); /*!!!!!!!!!!!*/ /* */ /* Stage 3 */ /* */ /*!!!!!!!!!!!*/ F = cgetg(6, t_VEC); /* makes F a vector */ F[1] = lgeti(MEDDEFAULTPREC); /* initializes components */ F[2] = lgeti(MEDDEFAULTPREC); F[3] = lgeti(MEDDEFAULTPREC); F[4] = lgeti(MEDDEFAULTPREC); F[5] = lgeti(MEDDEFAULTPREC); for (x = 1; x <= 5; ++x) /* assigns values to F's components note we can use the C long variable x to refer to entries of F */ { gaffsg(x*x,(GEN) F[x]); printf("F[%ld] = ",x); outbrute((GEN) F[x]); printf("\n"); } printf("Made it thru Stage 3 Successfully\n"); gaffsg(0,(GEN) F[1]); /* reassigns values of F */ gaffsg(0,(GEN) F[2]); gaffsg(0,(GEN) F[3]); gaffsg(0,(GEN) F[4]); gaffsg(1,(GEN) F[5]); printf("New Values of F[i]\n"); for (x = 1; x <= 5; ++x) /* prints new F values */ { printf("F[%ld] = ",x); outbrute((GEN) F[x]); printf("\n"); } printf("Starting Elliptic Curve Test Stage\n"); /* in pari, elliptic curves are of the form: y^2 + a1 xy + a3 y = x^3 + a2 x^2 + a4 x + a6 represent as a vector [a1,a2,a3,a4,a6] to use elliptic curve functions, need a related vector with 13 components, the first five as above. First we will manually input the data, then we will show how to use the pari built in initialization procedure, where it calculates the other 8 components from a1, ..., a6. */ E = cgetg(14, t_VEC); /* makes E a vector */ for (x = 1; x <= 13; x++) /* itializes components */ { E[x] = lgeti(MEDDEFAULTPREC); } gaffsg(0,(GEN) E[1]); gaffsg(0,(GEN) E[2]); gaffsg(0,(GEN) E[3]); gaffsg(0,(GEN) E[4]); gaffsg(1,(GEN) E[5]); gaffsg(0,(GEN) E[6]); gaffsg(0,(GEN) E[7]); gaffsg(4,(GEN) E[8]); gaffsg(0,(GEN) E[9]); gaffsg(0,(GEN) E[10]); gaffsg(-846,(GEN) E[11]); gaffsg(-432,(GEN) E[12]); gaffsg(0,(GEN) E[13]); for (x = 1; x <= 13; ++x) /* prints new E values */ { printf("E[%ld] = ",x); outbrute((GEN) E[x]); printf("\n"); } gaffsg(97,y); a = apell(E,y); printf("a(97) for this curve is "); /*correct ans: 14 */ outbrute(a); printf("\n"); printf("First Section of Elliptic Curve Test Stage Successful\n"); /*second stage of elliptic curve test will try to use the initialization procedures instead of defining everything piecemeal. Below F is a vector with 5 components, and E is a vector with 13. MEDDEFAULTPREC is the precision of storage. The below works fine if all 13 entries are integral */ E = initell(F,MEDDEFAULTPREC); /*this initializes E to be a 13 component vector, and we can now use the pari elliptic curve functions on E */ printf("Printing Check for Second Stage\n"); for (x = 1; x <= 13; ++x) /* prints new E values */ { printf("E[%ld] = ",x); outbrute((GEN) E[x]); printf("\n"); } printf("Second Stage EC Test Successful\n"); /* third stage of EC test: will try to do initialization without having everything integral. one can check these values by running PARI in a dos window */ gaffsg(0,(GEN) F[1]); /* reassigns values of F */ gaffsg(0,(GEN) F[2]); gaffsg(0,(GEN) F[3]); gaffsg(2,(GEN) F[4]); gaffsg(3,(GEN) F[5]); E = initell(F,MEDDEFAULTPREC); /* again, initializing E */ printf("Printing Check for Third Stage\n"); for (x = 1; x <= 13; ++x) /* prints new E values */ { printf("E[%ld] = ",x); outbrute((GEN) E[x]); printf("\n"); } gaffsg(13,y); a = apell(E,y); /* correct answer -4 */ printf("a(13) for this curve is "); outbrute(a); printf("\n"); gaffsg(7919,y); a = apell(E,y); /* correct answer -144 */ printf("a(7919) for this curve is "); outbrute(a); printf("\n"); printf("Third Stage EC Test Successful\n"); printf("\nPress Return to Continue\n\n"); scanf("%c", &x); exit(0); }