[sage-support] Missing 1 required positional argument
The following code doesn't work inside Sage Math Cell. I am getting message: TypeError: Check() missing 1 required positional argument: 'n' . I guess I use a selector incorrectly. How can I fix it? gp.eval("xmat(r,n) = [2*x, -1; 1, 0]*Mod(1,x^r-1)*Mod(1,n);") gp.eval("smallestr(n)={if(n==1 || n%2==0, return(0));forprime(r = 3, oo,my(u=n%r);if (u==0 && r < n, return(0));if (u!=0 && u!=1 && u!=r-1, return(r)));}") gp.eval("myisprime(n)={my(r = smallestr(n));if (r == 0, return(n == 2));my(xp = xmat(r,n)^n*[x,1]~);xp[2] == Mod(x*Mod(1,n),x^r-1)^n;}") def Check(n): if gp.function_call("myisprime",[n]).sage()==true: return ("Prime!") else: return ("Composite!") @interact def _(n=2017,action=selector(['Check'],buttons=True,label='')): action = eval(action) print (action()) -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/71036036-d5a6-420d-b47d-f465e89f02fa%40googlegroups.com.
Re: [sage-support] Mixing GP and @interact inside Sage Cell
Thank you, it works! On Sun, Jan 12, 2020 at 7:54 PM Dima Pasechnik wrote: > e.g. something like > > sage: gp.eval("square(x)=x^2") > '(x)->x^2' > sage: gp.function_call("square",[20]).sage() > 400 > > So one can have > > def foo(x): > return gp.function_call("square",[x]).sage() > > to create a Sage function that will square a number using GP > > On Sun, Jan 12, 2020 at 2:26 PM Dima Pasechnik wrote: > > > > this way Python does not know anything about GP functions. > > You need to pass the input/output from/to Python. > > > > On Sun, 12 Jan 2020, 14:06 Pedja, wrote: > >> > >> Why the following code doesn't work inside Sage Cell? > >> > >> gp(""" > >> square(x)=x^2; > >> """) > >> > >> @interact > >> def _(x=2): > >> print(square(x)) > >> > >> -- > >> 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+unsubscr...@googlegroups.com. > >> To view this discussion on the web visit > https://groups.google.com/d/msgid/sage-support/25a5f980-f93d-4721-94d4-e5f1677b285d%40googlegroups.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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sage-support/CAAWYfq0rwwUEQFxmexC9vn8PaLczFSBFGSekYQFQMKi5bTPFFw%40mail.gmail.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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/CAJBHNMBw4-CPs5sTG59bF_055yRnHgNa1BTy-Ha5dGADPO98DQ%40mail.gmail.com.
[sage-support] Mixing GP and @interact inside Sage Cell
Why the following code doesn't work inside Sage Cell? gp(""" square(x)=x^2; """) @interactdef _(x=2): print(square(x)) -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/25a5f980-f93d-4721-94d4-e5f1677b285d%40googlegroups.com.