Ask Your Question
0

Is This A limitation of my Processing Power

asked 2025-03-07 17:03:45 +0100

Kazzie gravatar image

updated 2025-03-07 18:14:50 +0100

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

edit retag flag offensive close merge delete

Comments

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

John Palmieri gravatar imageJohn Palmieri ( 2025-03-07 18:14:29 +0100 )edit

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

John Palmieri gravatar imageJohn Palmieri ( 2025-03-07 18:19:10 +0100 )edit

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 ( 2025-03-07 18:53:52 +0100 )edit

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 ( 2025-03-07 19:29:29 +0100 )edit

You may try simply

gee = sage_eval(bar)
Max Alekseyev gravatar imageMax Alekseyev ( 2025-03-07 20:29:07 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2025-03-07 19:45:49 +0100

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,

edit flag offensive delete link more

Comments

Thank-you all, it took about 45 minutes

Kazzie gravatar imageKazzie ( 2025-03-08 08:21:18 +0100 )edit

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 ( 2025-03-08 10:14:55 +0100 )edit

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 ( 2025-03-08 11:15:28 +0100 )edit

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 ( 2025-03-08 11:21:40 +0100 )edit

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: 2025-03-07 17:03:45 +0100

Seen: 46 times

Last updated: Mar 07