Question on reading a file (and suggestion)

4 views
Skip to first unread message

Rolandb

unread,
Aug 7, 2008, 12:20:47 AM8/7/08
to sage-support
ABC@home is a project to find abc-triples: positive integers a,b,c
such that a+b=c, a < b < c, a,b,c have no common divisors and c >
rad(abc), the so-called radical of abc. See http://abcathome.com/ for
further details.

Now the project has found around 6 million abc-triples. The
abc_triples.bin file contains all triples found by the abc project so
far in binary form in the following format: c_1b_1c_2b_2c_3b_3 .. such
that each c_i b_i form an abc triple: (c_i-b_i,b_i,c_i). The sequence
is ordered in such a way that the c_i form an increasing sequence and
for equal c_i the b_i form an increasing sequence. The size of each
c_i and b_i is a 64bit unsigned integer.

The database can be found on http://www.abcathome.com/stuff/. Each day
new abc-triples are added. The size of the file is around 60Mb.

Question: How can I acces this file in SAGE? (I'm not familiar with
reading 64bit unsigned integers, so please some lines of code please)
Tnx in advance!

Suggestion: The ABC conjecture says that there are only finitely many
a,b,c such that log(c)/log(rad(abc)) > h for any real h > 1. The ABC
conjecture is currently one of the greatest open problems in
mathematics. Therefor an idea to have the abc-triples permanently
available in SAGE?

Roland


Robert Bradshaw

unread,
Aug 7, 2008, 12:59:44 AM8/7/08
to sage-s...@googlegroups.com
On Aug 6, 2008, at 9:20 PM, Rolandb wrote:

> ABC@home is a project to find abc-triples: positive integers a,b,c
> such that a+b=c, a < b < c, a,b,c have no common divisors and c >
> rad(abc), the so-called radical of abc. See http://abcathome.com/ for
> further details.
>
> Now the project has found around 6 million abc-triples.

Cool.

> The
> abc_triples.bin file contains all triples found by the abc project so
> far in binary form in the following format: c_1b_1c_2b_2c_3b_3 .. such
> that each c_i b_i form an abc triple: (c_i-b_i,b_i,c_i). The sequence
> is ordered in such a way that the c_i form an increasing sequence and
> for equal c_i the b_i form an increasing sequence. The size of each
> c_i and b_i is a 64bit unsigned integer.
>
> The database can be found on http://www.abcathome.com/stuff/. Each day
> new abc-triples are added. The size of the file is around 60Mb.
>
> Question: How can I acces this file in SAGE? (I'm not familiar with
> reading 64bit unsigned integers, so please some lines of code please)
> Tnx in advance!

Numpy makes things really easy here:

sage: import numpy
sage: data = numpy.memmap("/path/to/abc_triples.bin", dtype=[('a',
'uint64'), ('b', 'uint64'), ('c', 'uint64')])
sage: data[0]
(2L, 6L, 8L)

> Suggestion: The ABC conjecture says that there are only finitely many
> a,b,c such that log(c)/log(rad(abc)) > h for any real h > 1. The ABC
> conjecture is currently one of the greatest open problems in
> mathematics. Therefor an idea to have the abc-triples permanently
> available in SAGE?

One would probably want to put them in a database as an spkg, or
write an interface to grab them of the web.

- Robert

William Stein

unread,
Aug 7, 2008, 1:00:34 AM8/7/08
to sage-s...@googlegroups.com, Willem Jan Palenstijn, Bart de Smit, Hendrik W. Lenstra

Hi,

I've cc'd Hendrik Lenstra (who was my Ph.D. adviser) and Bart de Smit,
since they
are very invovled in abcathome. Regarding your request, I wrote a
small program
in the Sage notebook that uses Cython, and which parses the complete 57MB
binary ABC triples file in 1 second. It's given below. I also saved the
result to a compressed sobj:

http://sage.math.washington.edu/home/was/tmp/abc_triples.sobj

You can do

v = load('http://sage.math.washington.edu/home/was/tmp/abc_triples.sobj')

and Sage will download and load the file, giving the list of c1,b1,c2,b2, etc.

Untitled
system:sage

Click edit and paste this into a sage notebook. Assumes you're
on a 64-bit computer. Be sure to edit the open command to open
your decompressed copy of the abc data file.

{{{id=0|
r = open('/home/was/tmp/abc_triples.bin','rb').read()
///
}}}

{{{id=1|
%cython
def to_ints(r):
# This *assumes* a 64-bit Linux OS...
v = []
cdef char* c = r
cdef long* w = <long*> c
cdef Py_ssize_t i
assert sizeof(long) == 8
return [w[i] for i in range(len(r)//8)]
///
}}}

{{{id=2|
time v = to_ints(r)
///

CPU time: 1.63 s, Wall time: 1.63 s
}}}

{{{id=16|
c1,b1=v[-2],v[-1]
///
}}}

{{{id=3|
(c1 - b1, b1, c1)
///

(1, 999999999999999999, 1000000000000000000)
}}}

{{{id=5|
abc = (c1-b1)*b1*c1
///
}}}

{{{id=6|
prod(prime_divisors(abc))
///

370370370370370370
}}}

{{{id=7|
factor(abc)
///

2^18 * 3^4 * 5^18 * 7 * 11 * 13 * 19 * 37 * 52579 * 333667
}}}

{{{id=12|
time save(v,'/home/was/tmp/abc_triples.sobj')
///
}}}

{{{id=17|

///
}}}

John Cremona

unread,
Aug 7, 2008, 5:00:28 AM8/7/08
to sage-s...@googlegroups.com
After unzipping the file,

sage: f=open('abc_triples.bin','rb')

opens the file for reading in binary format. But I don't know how to
parse the strange results of f.readline(). Someone else might be
able to help.

John

2008/8/7 Rolandb <rol...@planet.nl>:

Rolandb

unread,
Aug 11, 2008, 3:29:27 PM8/11/08
to sage-support
Dear William,

I tried hard but your suggestion doesn't work (at my computer).

v = load('http://sage.math.washington.edu/home/was/tmp/
abc_triples.sobj')

Attempting to load remote file: http://sage.math.washington.edu/home/was/tmp/abc_triples.sobj
Loading: [..................................................]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/notebook/sage_notebook/worksheets/admin/21/code/9.py",
line 6, in <module>
exec compile(ur'v = load(\u0027http://sage.math.washington.edu/
home/was/tmp/abc_triples.sobj\u0027)' + '\n', '', 'single')
File "/usr/local/sage/local/lib/python2.5/site-packages/sympy/
plotting/", line 1, in <module>

File "sage_object.pyx", line 458, in sage.structure.sage_object.load
(sage/structure/sage_object.c:4444)
File "sage_object.pyx", line 577, in
sage.structure.sage_object.loads (sage/structure/sage_object.c:5489)
RuntimeError:
invalid data stream
invalid load key, 'x'.
Unable to load pickled data.

Maybe something to do with the fact you are assuming I'm on a 64-bit
computer?

Roland


On 7 aug, 07:00, "William Stein" <wst...@gmail.com> wrote:
> On Wed, Aug 6, 2008 at 9:20 PM, Rolandb <rola...@planet.nl> wrote:
>
> > ABC@home is a project to find abc-triples: positive integers a,b,c
> > such that a+b=c, a < b < c, a,b,c have no common divisors and c >
> > rad(abc), the so-called radical of abc. Seehttp://abcathome.com/for
> > further details.
>
> > Now the project has found around 6 million abc-triples. The
> > abc_triples.bin file contains all triples found by the abc project so
> > far in binary form in the following format: c_1b_1c_2b_2c_3b_3 .. such
> > that each c_i b_i form an abc triple: (c_i-b_i,b_i,c_i). The sequence
> > is ordered in such a way that the c_i form an increasing sequence and
> > for equal c_i the b_i form an increasing sequence. The size of each
> > c_i and b_i is a 64bit unsigned integer.
>
> > The database can be found onhttp://www.abcathome.com/stuff/. Each day

William Stein

unread,
Aug 11, 2008, 3:46:37 PM8/11/08
to sage-s...@googlegroups.com
On Mon, Aug 11, 2008 at 12:29 PM, Rolandb <rol...@planet.nl> wrote:
>
> Dear William,
>
> I tried hard but your suggestion doesn't work (at my computer).

Do what Robert Bradshaw suggested you do in this same thread.
His solution is better.

William

--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

Rolandb

unread,
Aug 12, 2008, 12:10:43 AM8/12/08
to sage-support
Dear William,

Sorry to bother you again, but also Robert's suggestion doesn't work
either (at my computer):

import numpy
data = numpy.memmap("http://sage.math.washington.edu/home/was/tmp/
abc_triples.bin", dtype=[('a',
'uint64'), ('b', 'uint64'), ('c', 'uint64')])

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/notebook/sage_notebook/worksheets/admin/21/code/24.py",
line 8, in <module>
'uint64'), ('b', 'uint64'), ('c', 'uint64')])
File "/usr/local/sage/local/lib/python2.5/site-packages/numpy/core/
memmap.py", line 28, in __new__
fid = file(name, (mode == 'c' and 'r' or mode)+'b')
IOError: [Errno 2] No such file or directory: 'http://
sage.math.washington.edu/home/was/tmp/abc_triples.bin'

Roland

On 11 aug, 21:46, "William Stein" <wst...@gmail.com> wrote:

Robert Bradshaw

unread,
Aug 12, 2008, 2:47:16 AM8/12/08
to sage-s...@googlegroups.com
On Aug 11, 2008, at 9:10 PM, Rolandb wrote:

>
> Dear William,
>
> Sorry to bother you again, but also Robert's suggestion doesn't work
> either (at my computer):
>
> import numpy
> data = numpy.memmap("http://sage.math.washington.edu/home/was/tmp/
> abc_triples.bin", dtype=[('a','uint64'), ('b', 'uint64'), ('c',
> 'uint64')])

You have to download the file locally to use memmap.

Reply all
Reply to author
Forward
0 new messages