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.Mon, 12 Jul 2021 09:48:54 +0200GP compiler problemhttps://ask.sagemath.org/question/57965/gp-compiler-problem/When I do individual calculations the algorithm seems to be fine
but when I do multiple iterations it crashes, any help is super appreciated.
from sage.all_cmdline import * # import sage library
non_square = [2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
for k in non_square:
K = gp.bnfinit(x^2 - k)
XY = []
Y = []
for i in range(1, 100):
x = gp.bnrclassno(K, i)
XY.append([x, euler_phi(i)])
print(XY)
# scatter_plot(XY, markersize=100, facecolor='green', ymax=100).save('new1.png')
list_plot(XY).save('new' + str(k) + '.png')
del(K)prathamlalwaniMon, 12 Jul 2021 09:48:54 +0200https://ask.sagemath.org/question/57965/How to load local PARI/GP script in Sage notebook?https://ask.sagemath.org/question/43681/how-to-load-local-parigp-script-in-sage-notebook/I have a PARI/GP script which I want to load and run locally on my laptop inside a Sage notebook. I tried to open a new notebook in the same directory where my script is located, and run this:
%default_mode gp
But, it throws the following error:
> UsageError: Line magic function '%default_mode` not found.
Please note that I'm using Sage 8.3. How can I run a PARI/GP script locally?ninhoSat, 15 Sep 2018 23:50:41 +0200https://ask.sagemath.org/question/43681/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/The use of %gp to switch to Pari/gp commandshttps://ask.sagemath.org/question/41336/the-use-of-gp-to-switch-to-parigp-commands/I am using Sagemath 8.0 on my computer and also have subscribed to Cocalc (the former Sagemathcloud). I currently do quite a bit of programming in Pari/gp and noted that using %gp in the Cocalc-cloud allows me to switch to entering a sequence of Pari/gp commands, however this doesn't seem to work for the PC-version I use. Of course I can circumvent this by transforming each Pari/gp command into a string with pari(' .... '), however that can only be done line by line and produces ugly code.
Is it correct that %gp doesn't work on the PC version and if so, is there another way to write multiple lines of Pari/gp code other than producing line by line strings and/or use the terminal?
Thanks.RuudHThu, 01 Mar 2018 17:20:08 +0100https://ask.sagemath.org/question/41336/Using Sage plotting capability on data from PARI/GP (1)https://ask.sagemath.org/question/41048/using-sage-plotting-capability-on-data-from-parigp-1/ This is a short follow-up question from [this one](https://ask.sagemath.org/question/41029/using-sage-plotting-capability-on-data-from-parigp/).
I would like to produce an implicit plot (a contour plot where the real or imaginary values of a function are zero):
var('x,y,s')
g=real(zeta(s))
implicit_plot(lambda x,y:g(x+y*I),(x,-3,3),(y,-3,3))
This works fine, however I want to use GP/Pari to evaluate the zeta function and therefore wrote:
var('x,y')
g=gp("H(s)=zeta(s)")
implicit_plot(lambda x,y:real_part(g(x+y*I)),(x,-3,3),(y,-3,3))
but then keep getting an error message:
**PARI/GP ERROR:
*** at top-level: sage[45020]=sage[16][1]
*** ^---
*** incorrect type in _[_] OCcompo1 [not a vector] (t_REAL).**
For 'normal' plots like this one:
var('x')
g=gp("H(s)=real(zeta(s))")
plot(lambda x:(g(x)),(x,3,6))
the interface with GP works fine, so I probably do something wrong using multiple variables or complex numbers? It doesn't seem to be zeta-function specific (like the pole at s=1), since it also fails for e.g. the cos-function.
Grateful for any advice on how to make this work.
Thanks!RuudHFri, 09 Feb 2018 16:20:43 +0100https://ask.sagemath.org/question/41048/