Ask Your Question

Pedja's profile - activity

2021-07-29 10:10:09 +0100 received badge  Famous Question (source)
2020-06-07 07:31:47 +0100 received badge  Popular Question (source)
2020-06-07 07:31:47 +0100 received badge  Notable Question (source)
2020-01-25 12:05:22 +0100 asked a question Show function inside embedded Sage cell is not working!

I am trying to embed the code, given below, in my webpage (Project Primus) , but show function doesn't work (see Sage cell below Theorem 5). When I use print function instead of show function everything is ok, but problem is that I can't render LaTex formula using a print function. Also, inside Sage Math Cell code works correctly (see here). How to fix this problem?

gp.eval("test(n,k)={s=2*polchebyshev(k,1,8/2);N=k*2^n+1;ctr=1;while(ctr<=n-2,s=Mod(s^2-2,N);ctr+=1);return(s)}")
def Check(n,k):
    if k%2==0:
        return(LatexExpr("\\text{Coefficient must be an odd number!}"))
    elif k<=0:
        return(LatexExpr("\\text{Coefficient must be greater than zero!}"))
    elif n<3:
        return(LatexExpr("\\text{Exponent must be greater than two!}"))
    elif k>=2**n:
        return(LatexExpr("\\text{Coefficient must be less than 2^exponent!}"))
    elif not(((k%30==1 or k%30==7) and n%4==0) or ((k%30==11 or k%30==23) and n%4==1) or ((k%30==13 or k%30==19) and n%4==2) or ((k%30==17 or k%30==29) and n%4==3)):
        return(LatexExpr("\\text{That combination of the coefficient and exponent is not supported by this test!}"))
    else:
          if gp.function_call("test",[n,k]).sage()==0:
               return(LatexExpr(str(k)+"\\cdot 2^"+str({n})+"\\text{+1 is prime!}"))
          else:
               return(LatexExpr(str(k)+"\\cdot 2^"+str({n})+"\\text{+1 is composite!}"))
@interact
def _(k=input_box(1,'Coefficient:',width=20),n=input_box(4,'Exponent:',width=20),action=selector(['Check'],buttons=True,label='')):
    action = eval(action) 
    show(action(n,k))
2020-01-18 06:38:31 +0100 commented question Missing 1 required positional argument

@JohnPalmieri I have found a problem. The last line should read: print(action(n)) .

2020-01-18 05:59:21 +0100 commented question Missing 1 required positional argument

@JohnPalmieri You are right, but that's not issue. Please see edit.

2020-01-18 05:57:38 +0100 received badge  Editor (source)
2020-01-17 15:11:46 +0100 received badge  Organizer (source)
2020-01-17 15:07:01 +0100 asked a question Missing 1 required positional argument

What's wrong with my code? It doesn't work inside Sage Math Cell.

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())

I am getting the following message: TypeError: Check() missing 1 required positional argument: 'n'

EDIT

You can run this code here.

2020-01-17 01:24:46 +0100 received badge  Teacher (source)
2020-01-17 01:24:46 +0100 received badge  Self-Learner (source)
2020-01-17 01:24:43 +0100 received badge  Student (source)
2020-01-13 08:42:34 +0100 answered a question Mixing GP and @interact in one cell

The following code works:

gp.eval("square(x)=x^2")
@interact
def _(x=2):
    print(gp.function_call("square",[x]).sage())
2020-01-12 01:10:00 +0100 asked a question 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.