First define the time verb using the external conjunction. time returns the time in seconds to evaluate the sentence given as its right input.
time =: 6 !: 2Next, using the definition of fibonacci given in Section 2.3.2, determine the speed, in calls per sec to fibonacci, of fibonacci n for values of n not more than about 25. Note that you need to use the fib_work_iter function from Section 2.3.2 to compute these speeds. For example, on a RISC workstation you might measure this speed as:
(fib_work_iter 20) % 10 time 'fibonacci 20' 2650.24This measurement gives a speed of about 2650 calls per sec as determined by the average of 10 evaluations of fibonacci 20.
The next step of the experiment involves dividing fib_work_iter 100 by 2650 to obtain the estimate of the time in seconds to evaluate fibonacci 100. This division requires exact integer division which is expressed in J as:
0 2650 #: 1146295688027634168201x 432564410576465723x 2251xIgnoring the remainder of 2251 we have a result of 432564410576465723 seconds (the suffix "x" indicates an exact integer). Students performing this lab are always surprised to learn that this time is 13,716,527,478 years, 350 days, 4 hours, 55 minutes and 23 seconds. This result is easily expressed in J as:
0 365 24 60 60 #: 432564410576465723x 13716527478x 350x 4x 55x 23x