# PARI/GP error in wrapping custom-defined PARI functions in Sage using the command gp.set()

I have a library in PARI/GP and since Sage also supports the GP calculator I have been trying to shift my library using gp.set() and gp.get() commands. So far all functions are working but I got a PARI/GP error while implementing this function in Sage using gp.set(). Here is the code of that function:

compareSides(printedgesonscreen=0) = { local( edge, edgesCheckList1:list, edgesCheckList2:list, cancelCriterion);

edgesCheckList1 = listcreate(2numberOfLines); edgesCheckList2 = listcreate(2numberOfLines);

for (j = 1, numberOfSpheres, if( deleteFlag[j] == 0,

 if( printedgesonscreen == 1,
print("Cell ",j," lies on the hemisphere with center at ",
divideInNumberField(K,Lambda[j],Mu[j]) );
" and has the following edges:");
);

for( s = 1, length( pointsOfLine[j]),

edge = setintersect(Set(pointsOfLine[j][s]),
Set(pointsOfSphere[j]:list));

if(length(edge) == 2,

if(printedgesonscreen == 1, print(edge); );

if( setsearch(Set(edgesCheckList1),edge),

if(setsearch(Set(edgesCheckList2),edge),

if (printedgesonscreen == 1,
print("***Error in function compareSides: triple edge in cell diagram");
);
,
listput(edgesCheckList2,edge);
);
, /* else not yet entered in edgesCheckList1 */
listput(edgesCheckList1,edge);
);

);
if(length(edge) > 2,
print("***Error in function compareSides: edge with three corners");
);
);


);
);

if(Set(edgesCheckList1) == Set(edgesCheckList2),

    print("All ", length(edgesCheckList1), " = ",
length(edgesCheckList2)," edges appear twice.");
if( length(edgesCheckList1) > 3,
cancelCriterion = 1
,
cancelCriterion = 0
);
, /* else some edges do not appear twice. */
print("Some edges do not appear twice:");
print(setminus(Set(edgesCheckList1),Set(edgesCheckList2)));


); listkill(edgesCheckList1); listkill(edgesCheckList2); /* Return */ cancelCriterion };

I have run this function in the GP calculator of Sage using the gp.console() command and it works fine but I don't understand why it is not working using gp.set(). Here is the implementation I did:

gp.set('compareSides(printedgesonscreen=0)','{ local( edge, edgesCheckList1:list, edgesCheckList2:list, cancelCriterion); edgesCheckList1 = listcreate(2numberOfLines); edgesCheckList2 = listcreate(2numberOfLines); for (j = 1, numberOfSpheres, if( deleteFlag[j] == 0, if( printedgesonscreen == 1, print("Cell ",j," lies on the hemisphere with center at ", divideInNumberField(K,Lambda[j],Mu[j]) ); print(" with radius square ", radiusSquare[j], " and has the following edges:"); ); for( s = 1, length( pointsOfLine[j]), edge = setintersect(Set(pointsOfLine[j][s]), Set(pointsOfSphere[j]:list)); if(length(edge) == 2, if(printedgesonscreen == 1, print(edge); ); if( setsearch(Set(edgesCheckList1),edge), if(setsearch(Set(edgesCheckList2),edge), if (printedgesonscreen == 1, print("Error in function compareSides: triple edge in cell diagram"); ); , listput(edgesCheckList2,edge); ); , / else not yet entered in edgesCheckList1 / listput(edgesCheckList1,edge); ); ); if(length(edge) > 2, print("Error in function compareSides: edge with three corners"); ); ); ); ); if(Set(edgesCheckList1) == Set(edgesCheckList2), print("All ", length(edgesCheckList1), " = ", length(edgesCheckList2)," edges appear twice."); if( length(edgesCheckList1) > 3, cancelCriterion = 1; , cancelCriterion = 0; ); , /* else some edges do not appear twice. / print("Some edges do not appear twice:"); print(setminus(Set(edgesCheckList1),Set(edgesCheckList2))); ); listkill(edgesCheckList1); listkill(edgesCheckList2); / Return */ cancelCriterion}')

When I run this in Sage it shows a PARI/GP error and outputs the whole code. I have been trying to find the bug since the last 3 days. Please help me regarding this. Thank you.

edit retag close merge delete

( 2018-06-18 04:09:59 -0600 )edit

To display inline code, like z = x*y, use backticks.

To display blocks of code or error messages, skip a line above and below, and do one of the following (all give the same result):

• indent all code lines with 4 spaces
• select all code lines and click the "code" button (the icon with '101 010')
• select all code lines and hit ctrl-K

For instance, typing

If we define f by

def f(x, y):
return (x, y)

then f(2, 3) returns (2, 3) but f(2) gives:

TypeError: f() takes exactly 2 arguments (1 given)


produces:

If we define f by

def f(x, y):
return (x, y)


then f(2, 3) returns (2, 3) but f(2) gives:

TypeError: f() takes exactly 2 arguments (1 given)


( 2018-06-18 04:10:03 -0600 )edit

( 2018-06-18 04:17:27 -0600 )edit

Sort by » oldest newest most voted

Instead of saying "it shows a PARI/GP error", show the actual error that you see. That makes it easier for people to answer your question, increasing the changes of getting a reply. See also https://www.chiark.greenend.org.uk/~s...

more