Ask Your Question
0

Is This A limitation of my Processing Power

asked 0 years ago

Kazzie gravatar image

updated 0 years ago

I'm trying to load a large number into Sage for factoring. I believe with the help of the people on this forum I've managed to create the string and read the number back into a string:

Create the String

foo=str(frac(pi).n(digits=13048009))
f=open(r"/mnt/c/Users/karen/Desktop/factcipher.txt", "w", encoding="utf8")
f.write("%s\n"%foo[2:])

Read Number Back into a String

Sage: f=open(r"/mnt/c/Users/karen/Desktop/factcipher.txt", "r", encoding="utf8")
Sage: bar=f.readline()
Sage: f.close()

I'm now trying to convert it to an integer:

Sage: gee=eval("Integer(%s)"%bar)

but it just hangs. Is this a limitation of my laptop. I know for a fact other people have managed to read the number into Sage and factor it, though I don't know their exact process

Preview: (hide)

Comments

Does it work if your file instead contains a smaller integer, say 5 digits?

John Palmieri gravatar imageJohn Palmieri ( 0 years ago )

You should add f.close() after writing to the file; otherwise, the write operation may not complete.

John Palmieri gravatar imageJohn Palmieri ( 0 years ago )

ISTR that I gave you this example, and that my read test ran in about 45 seconds on a fast AMD Ryzen 9 with gobs of memory (but no noticeable RAM consumption nor CPU abuse : this example used one CPU at a time). On a slow machine (and especially on Windows, where Sage runs in a virtual machine), you should give it a few minutes before throwing the towel.

I can't test this on

When I'll be able to access my machine, I'll check that and correct the present comment if necessary.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 0 years ago )

Check inSagecell : readind an integer of 200 000 digits takes about half a second, but reading an integer of 2 000 000 digits fail. I might bump a Sagecell limit.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 0 years ago )

You may try simply

gee = sage_eval(bar)
Max Alekseyev gravatar imageMax Alekseyev ( 0 years ago )

1 Answer

Sort by » oldest newest most voted
0

answered 0 years ago

Emmanuel Charpentier gravatar image

On my main machine :

sage: from tempfile import TemporaryFile
....: from time import time as stime
....: Ndig=13048009
....: foo=str(frac(pi).n(digits=Ndig))
....: f=TemporaryFile(mode="w+", encoding="utf8")
....: f.write("%s\n"%foo[2:])
....: f.seek(0)
....: bar=f.readline()
....: f.close()
....: t1=stime()
....: gee=eval("Integer(%s)"%bar)
....: t2=stime()
....: print("Reading an integer ", ceil(gee.log(10)), "digits long took ",round(
....: t2-t1, 2)," seconds")
13048010
0
Reading an integer  13048009 digits long took  33.85  seconds

Even if my machine is indeed speedy (Ryzen 9 4+Ghz), this shows that reading your integer should be a matter of a few minutes at most.

Checking your code might be a good idea...

HTH,

Preview: (hide)
link

Comments

Thank-you all, it took about 45 minutes

Kazzie gravatar imageKazzie ( 0 years ago )

Thank-you all, it took about 45 minutes

This is suspicious : a difference of two orders of magnitude between you computer and my (cheap, chinese) desktop seems too large to be true.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 0 years ago )

In Sagecell, the largest integer I was able to read was :

Reading an integer  1468496 digits long took  27.48  seconds

I suspect that this is limit comes from a timeout, to this size may be stochastic... In any case, Sagecell is still one to two orders of magnitude faster than your setup, which is highly suspicious.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 0 years ago )

FWIW, on my system, reading this integer 1468496 long took 1.03 seconds (about one order of magnitude faster than Sagecell).

Checking your setup is still in order.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 0 years ago )

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: 0 years ago

Seen: 54 times

Last updated: Mar 07