Ask Your Question

Revision history [back]

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]) );
         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 };

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.