Ask Your Question
1

Compiling .spyx-files

asked 2011-01-08 08:11:29 +0200

Mustafa gravatar image

updated 2011-04-28 17:21:05 +0200

Kelvin Li gravatar image

This is an implementation of the pollard-rho factorization-algorithm in sage (filename: exp.sage)

def pollard_rho(n):
    x = 2
    y = x
    t = 1

    while t == 1:
        x = mod(x,n)^2+1
        y = mod(mod(y,n)^2+1,n)^2+1
        t = gcd(x-y,n)

    if t<n:
       return(t)
    else:
       return 0

I load it with "load exp.sage" and it works.

But trying to compile

import sage.all

def pollard_rho(n):
    x = 2
    y = x
    t = 1

    while t == 1:
        x = sage.all.mod(x,n)**2+1
        y = sage.all.mod(sage.all.mod(y,n)**2+1,n)**2+1
        t = sage.all.gcd(x-y,n)

    if t<n:
       return(t)
    else:
       return 0

named as "exp.spyx" brings several errors, one of them (f.e.):

 13     while t == 1:
 14       x = sage.all.mod(x,n)**2+1
 ---> 15       y = sage.all.mod(sage.mod(y,n)**2+1,n)**2+1
 16       t = sage.all.gcd(x-y,n)
 17     

 AttributeError: 'module' object has no attribute 'mod'

What is wrong here? Probably many things - im totally new to Sage, coming from Pari-gp and work in console-mode - no experiences with C or Python. Thank you.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2011-01-08 10:43:52 +0200

Mike Hansen gravatar image

I think the version you tried to compile is different than the one posted above. In the error message, you can see the line sage.all.mod(sage.mod(y,n)**2+1,n)**2+1 which includes sage.mod which doesn't appear anywhere in the version you posted.

When I try to compile the exp.spyx file posted above, then everything works fine for me. Try that and let me know how it goes.

edit flag offensive delete link more

Comments

Yes, sorry, thank you Mike and DSM - it seems as if I intended to annoy people here with this. I did correct that in my posting, but didn't realize that this could be the mistake ... To be sure: On my machine theres absolutely no speed-up of the compiled version (its even a bit slower), whys that?

Mustafa gravatar imageMustafa ( 2011-01-08 11:07:17 +0200 )edit
1

answered 2011-01-08 10:44:13 +0200

DSM gravatar image

updated 2011-01-08 10:44:47 +0200

It seems to work for me:

sage: load "exp.spyx"
Compiling exp.spyx...
sage: time pollard_rho(next_prime(10**6)*previous_prime(10**7))
CPU times: user 0.23 s, sys: 0.01 s, total: 0.23 s
Wall time: 0.24 s
1000003

I'm a little puzzled, though, because the error message you show doesn't seem to correspond to the line in your source, namely that in the code you put up it says "sage.all.mod(sage.all.mod(y,n)**2+1,n)**2+1" but the error message points to a line of code reading "y = sage.all.mod(sage.mod(y,n)**2+1,n)**2+1", without an ".all." between sage and mod, so it seems to be looking in the module "sage" for the function mod.

For what it's worth, that's exactly the error message I get if I remove the ".all".

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

Stats

Asked: 2011-01-08 08:11:29 +0200

Seen: 943 times

Last updated: Jan 08 '11