Dispatching A Sequence of Computations

An application may issue a sequence of compute method invocations.  The example we choose is computing the nth composition of a function. Consider Fibonacci number once again: Let f( 0 ) = f( 1 ) = 1; f( n ) = f( n - 1 ) + f( n - 2 ), for n > 1.

Define fm(n) = f(n), when m = 1; f( fm-1(n) ), otherwise.

For example, 

fm( 1 ) = 1, for any natural number m.
fm( 2 ) = 2, for any natural number m.
fm( 3 ) = 3, for any natural number m.

However, things finally get interesting for n > 3.

f1( 4 ) = 5
f2( 4 ) = 8
f3( 4 ) = 34
f4( 4 ) = 9,227,465

I was afraid to try to compute f5( 4 ). It surely would overflow the int variables that I define for it, and I may not have time for variables that are long or BigInteger (without resorting to the closed form formula for f( n ) ).

Without further ado, here is the code (it uses fastfibonacci classes for F and Atom):

Application.java
F.java
Atom.java
AddInteger.java - from the janet.services.tasks package.

The output is given below, when for m = 4 and n = 4.



F( 1, 4 ) = 5
F( 2, 4 ) = 8
F( 3, 4 ) = 34
F( 4, 4 ) = 9227465