ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 11 Jan 2020 12:03:01 -0600Mixing GP and @interact in one cellhttps://ask.sagemath.org/question/49508/mixing-gp-and-interact-in-one-cell/ What's wrong with my code? It doesn't work inside Sage Cell.
gp("""
square(x)=x^2;
""")
@interact
def _(x=2):
print(square(x))
When I press evaluate button code runs forever with no output at all. I can't figure out what is the problem.PedjaSat, 11 Jan 2020 12:03:01 -0600https://ask.sagemath.org/question/49508/PARI/GP error in wrapping custom-defined PARI functions in Sage using the command gp.set()https://ask.sagemath.org/question/42638/parigp-error-in-wrapping-custom-defined-pari-functions-in-sage-using-the-command-gpset/ 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.MathematicianMon, 18 Jun 2018 02:20:09 -0500https://ask.sagemath.org/question/42638/Using multiple lines of pari/gp code in a Sage notebookhttps://ask.sagemath.org/question/41758/using-multiple-lines-of-parigp-code-in-a-sage-notebook/I am struggling to get multiple lines of pari/gp code working in a Jupyter Sage notebook.
When I enter:
%%gp
for(x=1,10,print(x))
it all works fine, however when I for instance write:
%%gp
for(x=1,10,{
print(x);
})
the system just 'hangs' and doesn't return any output. The same issue occurs in the Cocalc Sage cloud environment. I also tried 'pari/gp in your browser' and there it works fine.
Am I doing something wrong or isn't the multi-line pari/gp option supported in Sage?RuudHSun, 25 Mar 2018 15:58:41 -0500https://ask.sagemath.org/question/41758/Unable to start parihttps://ask.sagemath.org/question/34578/unable-to-start-pari/Hi,
I tried this calculation with pari/GP for instance:
%gp
factorial(56847)
And I was surprised when it returned:
>Traceback (most recent call last):
>File "<stdin>", line 1, in <module>
>File "_sage_input_4.py", line 10, in <module>
exec compile(u"print _support_.syseval(gp, u'factorial(56847)', __SAGE_TMP_DIR__)" + '\n', '', 'single')
>File "", line 1, in <module>
>File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sagenb/misc/support.py", line 438, in syseval
return system.eval(cmd, sage_globals, locals = sage_globals)
>File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/interfaces/expect.py", line 1293, in eval
for L in code.split('\n') if L != ''])
>File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/interfaces/gp.py", line 440, in _eval_line
wait_for_prompt=wait_for_prompt)
>File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/interfaces/expect.py", line 904, in _eval_line
self._start()
>File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/interfaces/gp.py", line 240, in _start
Expect._start(self, alt_message, block_during_init)
>File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/interfaces/expect.py", line 501, in _start
raise RuntimeError("unable to start %s" % self.name())
>RuntimeError: unable to start pari
I'll soon get the update 7.3(time for updating the binaries from the depository), but how can I fix that ?
Just to clarify: when I start pari in a terminal it works perfectly.
ThxRomuald_314Thu, 25 Aug 2016 02:08:52 -0500https://ask.sagemath.org/question/34578/RuntimeError when starting pari/library not foundhttps://ask.sagemath.org/question/33725/runtimeerror-when-starting-parilibrary-not-found/ Hello,
I am using a binary distribution of sage 7.1 for debian jessie and "installed" it to /opt.
Now, when I want to use pari, I get a runtime error:
```
sage: %gp
```
```
--> Switching to PARI/GP interpreter <--
```
```
pari: sqrt(4)
```
```
RuntimeError: unable to start pari
```
The full backtrace can be found here: paste.kde.org/pvqeoh3ve
however, the following works:
```
LD_LIBRARY_PATH=/opt/sage-7.1/local/lib sage
```
It seems that sage is unable to find that library when starting pari.
Setting SAGE_ROOT does not help. Did I miss some configuration file to set the library path for sage?
fxrhThu, 09 Jun 2016 07:58:27 -0500https://ask.sagemath.org/question/33725/Can't use gp interfacehttps://ask.sagemath.org/question/26701/cant-use-gp-interface/ I'm running Sage 6.6 on Windows as a virtual machine in VirtualBox. I can't use the gp interface:
sage: gp("3+3")
Traceback (click to the left of this block for traceback)
...
OSError: [Errno 2] No such file or directory: '/tmp/tmp5koDDd'
Does anybody have an idea? Thank you!
Ok, seems to work again after restarting...OderynSat, 02 May 2015 08:38:17 -0500https://ask.sagemath.org/question/26701/