ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 23 Jul 2023 07:55:50 +0200How to write Pari GP script in Sagehttps://ask.sagemath.org/question/70742/how-to-write-pari-gp-script-in-sage/I'm new to Sage and Pari-GP. There does not seem to be any application which can act as a Pari interface nicely. In Sage the only solution is to use %%gp to write a pari-gp script. Is there a way to write a whole script without having to use %%gp at the start of every cell? Alternatively, if you have any suggestions for a GUI for Pari scripts, please let me know.adityaghosh2001Sun, 23 Jul 2023 07:55:50 +0200https://ask.sagemath.org/question/70742/Issue on numerical_integral with a Pari/GP functionhttps://ask.sagemath.org/question/56235/issue-on-numerical_integral-with-a-parigp-function/Hello there,
I tried to evaluate the integral of a Pari/GP function but failed so far. Here is an example code on (SageMath version 8.9, Release Date: 2019-09-29 and windows 10):
sage: lchi4 = DirichletGroup(4).list()[1].lfunction(); lchi4
PARI L-function associated to Dirichlet character modulo 4 of conductor 4 mapping 3 |--> -1
sage: numerical_integral(lambda t: lchi4(t).real(), 2,3)
---------------------------------------------------------------------------
SystemError Traceback (most recent call last)
/opt/sagemath-8.9/local/lib/python2.7/site-packages/sage/all_cmdline.pyc in <module>()
----> 1 numerical_integral(lambda t: lchi4(t).real(), Integer(2),Integer(3))
/opt/sagemath-8.9/local/lib/python2.7/site-packages/sage/calculus/integration.pyx in
sage.calculus.integration.numerical_integral (build/cythonized/sage/calculus/integration.c:4061)()
353 _b = b
354 W = <gsl_integration_workspace*> gsl_integration_workspace_alloc(n)
--> 355 sig_on()
356 gsl_integration_qag(&F,_a,_b,eps_abs,eps_rel,n,rule,W,&result,&abs_err)
357 sig_off()
SystemError: calling remove_from_pari_stack() inside sig_on()
However, for the Riemann zeta function, numerical_integral works fine as below:
sage: numerical_integral(lambda t: zeta(t), 2,3)
(1.3675256886839795, 1.518258506343328e-14)
It looks like it would work for lchi4 if it can be coerced into a symbolic expression like zeta(x) as shown below:
sage: type(lchi4(3))
<type 'sage.rings.complex_number.ComplexNumber'>
sage: type(zeta(3))
<type 'sage.symbolic.expression.Expression'>
Can you please let me know how to evaluate the integral numerically for a Pari/GP function as lchi4?
Thank you in advance.jbThu, 18 Mar 2021 22:37:39 +0100https://ask.sagemath.org/question/56235/Mixing 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 19:03:01 +0100https://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 09:20:09 +0200https://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 22:58:41 +0200https://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 09:08:52 +0200https://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 14:58:27 +0200https://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 15:38:17 +0200https://ask.sagemath.org/question/26701/