Adept Scientific - English
The world's best software for research, science and engineering.
flag arrow
clearclear
 

 Adept Store | register Join My Adept | Flags  
Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055  
UKusdedksvnofi
Home
Products
Training
Consultancy
 Buy Online
Downloads
Education
Support
My Adept
International |  About Us |  Contact Us |  Press Room |  Jobs


The Next Steps

• Ask us a question
• Maple Product Tour
• Buy Maple Now
• View Maple Pricing
• Find out about Online Training
• Download a Brochure
• Request a Brochure
• Download a Demo
• Request a Demo
• Meet Our Team
• Read our RSS Feeds

Learn More

Maple Home
Maple 11 Professional
Maple 11 Academic
Maple 11 Student Use
Recorded Online Seminars
FREE Training Resources


MapleNet
Maple T.A.
MapleConnect
BlockImporter for Simulink
BlockBuilder for Simulink
Maple Toolboxes
Maple Rave Reviews
Maple Study Guides
Books about Maple
System Requirements

View Maple 10 in Action
Product Comparison Chart

Latest Information

New Features: Professional
New Features: Academic
The Maple Reporter
The Maple Reporter Online
Numerical Algorithms Group
(NAG)


Service & Support

Maple 10 Training Videos
MaplePrimes, blogs, forums
Elite Maintenance Program
Application Centre
Powertools
Maple User Group (MUG)
Join the Maple User Group
(MUG)

Search the Knowledge Base
Technical Support request

List Archives >  Maple User Group List Archive >  Archive by date >  This Month By Date >  This Month By Topic

[MUG] I/O in Maple 8

Search email archive for  

[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



Ready to buy?

Maple - single user licence
Add to shopping basket
$ 1,895.00
Upgrade to Maple 12 from v11
Add to shopping basket
$ 995.00
Upgrade to Maple 12 from v10 & below
Add to shopping basket
$ 1,395.00

Featured Downloads

Maple White Paper: Technical Knowledge - An Asset You Can Afford to Lose?
Maple in Electronics Application Pack
Maple in Robotics & Aerospace Application Pack
Maple in Finance Application Pack

Product Reviews

"Without the Maple software, we would have to spend weeks generating the equations of motion for every experiment. Then the chances that we did it right would basically be near zero. There would always be a mistake somewhere. It is very difficult to set up a dynamic motion model by hand."
- Jean-Claude PiedBeouf, Ph.D Manager of Robotics, Canadian Space Agency

"Its very good - highly accurate and easy to use. The speed of Maple allows me to change equations and quickly reintegrate them into the application, so more possibilities can be explored to achieve the precise effect desired."
Shawn Neely, Senior R & D Director for PDI/Dreamworks
adept

Top of the Page

Our Privacy and Terms and Conditions Statement
All Trademarks Recognised. Copyright © 2007, Adept Scientific plc.
Site designed and maintained by Adeptise

Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055