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

32 views
Skip to first unread message

am...@ma.iitr.ac.in

unread,
Jun 18, 2018, 4:41:48 AM6/18/18
to sage-support
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(2*numberOfLines);
  edgesCheckList2 = listcreate(2*numberOfLines);
 
  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(2*numberOfLines);  edgesCheckList2 = listcreate(2*numberOfLines);  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.

slelievre

unread,
Jun 18, 2018, 5:18:07 AM6/18/18
to sage-support

Jeroen Demeyer

unread,
Jun 19, 2018, 3:52:19 AM6/19/18
to sage-s...@googlegroups.com
> --
> You received this message because you are subscribed to the Google
> Groups "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sage-support...@googlegroups.com
> <mailto:sage-support...@googlegroups.com>.
> To post to this group, send email to sage-s...@googlegroups.com
> <mailto:sage-s...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.

It looks strange to use gp.set() for that. I would simply use gp.eval()
Reply all
Reply to author
Forward
0 new messages