Ask Your Question
0

From Pari to SAGE

asked 2018-12-13 08:46:48 -0600

polistirolo gravatar image

f(n,p)={d=ceil(log(2)/log(10)(n-1));s=lift(Mod(2,p)^(n-1));t=lift(Mod(10,p)^d);‌​u=lift(Mod((2s-1)*t+s-1,p));u}

v=[100000..101000]

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

Comments

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 10:45:35 -0600 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2018-12-13 11:05:23 -0600

rburing gravatar image

updated 2018-12-13 11:26:37 -0600

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

Stats

Asked: 2018-12-13 08:46:48 -0600

Seen: 36 times

Last updated: Dec 13 '18