 |
|
List Archives > 
Maple User Group List Archive > 
Archive by date > 
This Month By Date > 
This Month By Topic
[MUG] I/O in Maple 8
| [MUG] I/O in Maple 8 |
|
Author: Brad Weir
Posted: Sat, 9 Nov 2002 19:01:51 -0500 (
|
>> From: Brad Weir "bw300"
I'm using Maple 8 (Solaris) to read a list of primes from a file,
and then do some statistics on these primes. I was wondering what's the
most efficient way to do this? I have two options for the formatting of
the primes file: (1) each prime on a new line, (2) each prime seperated by
a space, with all of the primes on one line. I want to be able to then
pass a range to a procedure say, abc(10^5..10^7), and it will do the
statistics on all the primes in that range. Obviously, if I have a 90MB
file of primes, and I do successive readlines to get down to the first
prime greater than 10^5, then I'll be waiting for a long time. This
doesn't seem like a very efficient solution to me.
I was thinking about keeping all the primes on one line, then
using filepos to jump ahead in the file, and using readbytes and more
filepos to move back in forth in the file until I find the prime to start
with. This process seems far to complicated for something I'm sure a lot
of people have had to deal with.
Does anyone know of a simple and efficient way to do this?
Brad Weir
|
| [MUG] Re: I/O in Maple 8 |
|
Author: Maple User Group
Posted: Fri, 15 Nov 2002 10:52:50 -0500
|
>> From: Maple User Group "maple_gr"
On Sat, 9 Nov 2002, Brad Weir wrote:
| I'm using Maple 8 (Solaris) to read a list of primes from a file,
| and then do some statistics on these primes. I was wondering what's the
| most efficient way to do this?
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Mon, 11 Nov 2002 17:02:15 -0800 (PST)
From: Robert Israel "israel"
To: "maple-list"
Subject: I/O in Maple 8
If your ranges will all be based on powers of 10, I'd suggest generating
separate files for the primes in each range 10^j .. 10^(j+1). Or if
you want to allow arbitrary ranges, perhaps you could write a simple
filter in perl or awk, or C if you want speed, to extract the primes
you want.
Robert Israel "israel"
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia
Vancouver, BC, Canada V6T 1Z2
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Thu, 14 Nov 2002 07:01:05 -0500 (EST)
From: Carl Devore "devore"
To: "maple-list"
Subject: I/O in Maple 8
I find it hard to believe that any file-based method could be more
efficient than just using the Maple commands ithprime, nextprime,
prevprime, and numtheory[pi].
| I have two options for the formatting of the primes file: (1) each
| prime on a new line,
Is it possible to pad them with leading spaces so that each line is the
same length? You could use Maple to make the file.
| (2) each prime seperated by a space, with all of the primes on one line.
Is it possible to do this but have them all use the same number of spaces?
Perhaps you can achieve this by adding a large power of 10?
| I want to be able to then pass a range to a procedure say,
| abc(10^5..10^7), and it will do the statistics on all the primes in
| that range. Obviously, if I have a 90MB file of primes, and I do
| successive readlines to get down to the first prime greater than 10^5,
| then I'll be waiting for a long time.
This took 94 milliseconds on my computer, reading and parsing 9592
numbers. Maple file I/O and string parsing is fast.
filepos(primes,0);
n:= 0:
st:= time():
while n<10^5 do n:= fscanf(primes,"%d")[] od:
time()-st;
0.094
| I was thinking about keeping all the primes on one line, then using
| filepos to jump ahead in the file,
If each item in the file takes up the same amount of space, then jumping
to the exact position that you want is easy with filepos. Suppose you
want the first prime after 10^5:
N:= numtheory[pi](10^5);
9592
Thus we want the 9593rd number in the file. Assume that they each take 10
characters:
filepos(primes, 10*N);
p:= fscanf(primes, "%d")[];
100003
| and using readbytes and more filepos to move back in forth in the file
| until I find the prime to start with. This process seems far to
| complicated for something I'm sure a lot of people have had to deal
| with.
You will find many ideas for storage and searching in _The Art of Computer
Programming_ by Donald Knuth.
|
Previous by date: [MUG] Help with dsolve (Maple 6 vs Maple 7), Jim Shoemaker
Next by date: [MUG] Re: Can Maple krack this kernel?, Maple User Group
Previous thread: [MUG] maximize, Dragomir Deltchev
Next thread: [MUG] Can Maple krack this kernel?, NS Jones, Mathematics
|
|
|