Ask Your Question

From Pari to SAGE

asked 2018-12-13 15:46:48 +0200

polistirolo gravatar image



forprime(q=1,10^7,z=select(m->f(m,q)==0,v);if(length(z)>0,v=setminus(v,z);print(‌​q," ",length(z)," ",length(v))))

This is a program for PARI. For numbers of the form (2^k-1)*10^d+2^(k-1)-1 where d is the number of decimal digits of 2^(k-1)-1 in the range k=[100000..101000], it displays numbers with no factor below 10^7. Can somebody translate this PARI program in a SAGE program?

edit retag flag offensive close merge delete


Please format the code by selecting it and using the code (101010) button. Wrap inline code in backticks and LaTeX in dollar signs.

rburing gravatar imagerburing ( 2018-12-13 17:45:35 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-12-13 18:05:23 +0200

rburing gravatar image

updated 2018-12-13 18:26:37 +0200

Here is a more or less direct translation:

def f(n,p):
    d = ceil(log(2)/log(10)*(n-1))
    s = GF(p)(2)^(n-1)
    t = GF(p)(10)^d
    u = ((2*s-1)*t + s - 1).lift()
    return u

v = set(srange(100000,101000+1))

for q in primes(10^7):
    z = [m for m in v if f(m,q) == 0]
    if len(z) > 0:
        v -= set(z)
        print q, len(z), len(v)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-12-13 15:46:48 +0200

Seen: 357 times

Last updated: Dec 13 '18