Ask Your Question
1

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

asked 2018-06-18 09:20:09 +0100

Mathematician gravatar image

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.

edit retag flag offensive close merge delete

Comments

Welcome to Ask Sage! Thank you for your question!

slelievre gravatar imageslelievre ( 2018-06-18 11:09:59 +0100 )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)

Please edit your question to do that.

slelievre gravatar imageslelievre ( 2018-06-18 11:10:03 +0100 )edit

Note: also asked on sage-support.

slelievre gravatar imageslelievre ( 2018-06-18 11:17:27 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-06-19 09:57:16 +0100

Jeroen Demeyer gravatar image

updated 2018-06-19 09:57:41 +0100

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...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-06-18 09:20:09 +0100

Seen: 374 times

Last updated: Jun 19 '18