In maple, how do I calculate the digits of Pi with only using a few seconds of computation time?
I'm thinking
evalf(Pi)
But how do I know how much time the computer takes to give out the digits?
In maple, how do I calculate the digits of Pi with only using a few seconds of computation time?
I'm thinking
evalf(Pi)
But how do I know how much time the computer takes to give out the digits?
On
You can't "calculate the digits of $\pi$" in only a few seconds.
The number $\pi$ is irrational. The sequence of digits never terminates, and never repeats.
A better question to ask is "How can I calculate the first $n$ digits of $\pi$ in a few seconds on such-and-such computer with such-and-such software?"
On
$\pi$ never ends, it is an irrational number. However, you can have Maple print out as many digits of $\pi$ (within reason) as you would like. Moreover, you have the right idea how to do it:
evalf(Pi,30);
for example would evaluate $\pi$ to 30 digits of accuracy. However, if you ask for thousands of digits, eventually there always could be an error somewhere in the digits. Better in those cases to write an algorithm to compute the digits of $\pi$ yourself.
On
In Maple the following command is supposed to compute the first n decimal digits of Pi, as a floating-point approximation accurate to within 0.6 ulps.
evalf[n](Pi)
Using the above syntax there is no need to change (or reset, afterwards) the value of the environment variable Digits at the current level of your code.
The name
`evalf/constant/bigPi`
is preassigned the first 10000 decimal digits, and is available to each new kernel session. The first such computation may involve an initial read for that name from library archive file, the time for which will depend on how many archive files are found in the libname path and how many names they have stored. Also, for each distinct n <= 10000 the computation of evalf[n](Pi) will entail rounding the preassigned value to n digits, which is cheap but not entirely free of cost.
You can measure computation time using the time or the CodeTools:-Usage commands. Note that for a high number of digits the apparent real time duration can be affected by how long it takes to print those digits to the user interface. You can suppress printout of the computed result (which is nevertheless programmatically available afterwards) by terminating the statement with a full colon.
Executing the command,
showstat(`evalf/constant/Pi`);
should reveal the first level of its own interpreted code that gets run when evalf estimates Pi.
Note that evalf remembers previously computed results, keying upon both earlier input as well as the effective value of Digits, but this data is subject to garbage collection at times. If you want to prevent spurious (fast) timings then you can clear those stored results with the command,
forget(evalf);
It could be tricky to write Maple code which efficiently computes as many digits as possible within a strict time limit. There is a timelimit command, but I see no obvious way to use it effectively here.
Using the "Digits" command and setting it equal to a high number should work. (I assume you know pi is irrational, and so you only want to know up to a certain number of digits.)
As for finding out how long the command would take, I would suggest the "time()" command. Read up on it in Maple Help by typing in
After you type a command and execute it, the time() command can tell you how long it took.