### worked example: Fibonacci-and-factorial

description:
simple recursive Fibonacci and factorial
NB: we use !=> instead of #=>
ie, memoizing rules instead of plain stored-rules.
otherwise this code gets very slow, very fast.

code:
fib |0> => |0>
fib |1> => |1>
fib |*> !=> arithmetic( fib minus[1] |_self>, |+>, fib minus[2] |_self>)
fib-ratio |*> !=> arithmetic( fib |_self> , |/>, fib minus[1] |_self> )

fact |0> => |1>
fact |*> !=> arithmetic(|_self>, |*>, fact minus[1] |_self>)

examples:
table[number, fib, fib-ratio, fact] range(|1>, |30>)
+--------+--------+--------------------+-----------------------------------+
| number | fib    | fib-ratio          | fact                              |
+--------+--------+--------------------+-----------------------------------+
| 1      | 1      |                    | 1                                 |
| 2      | 1      | 1.0                | 2                                 |
| 3      | 2      | 2.0                | 6                                 |
| 4      | 3      | 1.5                | 24                                |
| 5      | 5      | 1.6666666666666667 | 120                               |
| 6      | 8      | 1.6                | 720                               |
| 7      | 13     | 1.625              | 5040                              |
| 8      | 21     | 1.6153846153846154 | 40320                             |
| 9      | 34     | 1.619047619047619  | 362880                            |
| 10     | 55     | 1.6176470588235294 | 3628800                           |
| 11     | 89     | 1.6181818181818182 | 39916800                          |
| 12     | 144    | 1.6179775280898876 | 479001600                         |
| 13     | 233    | 1.6180555555555556 | 6227020800                        |
| 14     | 377    | 1.6180257510729614 | 87178291200                       |
| 15     | 610    | 1.6180371352785146 | 1307674368000                     |
| 16     | 987    | 1.618032786885246  | 20922789888000                    |
| 17     | 1597   | 1.618034447821682  | 355687428096000                   |
| 18     | 2584   | 1.6180338134001253 | 6402373705728000                  |
| 19     | 4181   | 1.618034055727554  | 121645100408832000                |
| 20     | 6765   | 1.6180339631667064 | 2432902008176640000               |
| 21     | 10946  | 1.6180339985218033 | 51090942171709440000              |
| 22     | 17711  | 1.618033985017358  | 1124000727777607680000            |
| 23     | 28657  | 1.6180339901755971 | 25852016738884976640000           |
| 24     | 46368  | 1.618033988205325  | 620448401733239439360000          |
| 25     | 75025  | 1.618033988957902  | 15511210043330985984000000        |
| 26     | 121393 | 1.6180339886704431 | 403291461126605635584000000       |
| 27     | 196418 | 1.6180339887802426 | 10888869450418352160768000000     |
| 28     | 317811 | 1.618033988738303  | 304888344611713860501504000000    |
| 29     | 514229 | 1.6180339887543225 | 8841761993739701954543616000000   |
| 30     | 832040 | 1.6180339887482036 | 265252859812191058636308480000000 |
+--------+--------+--------------------+-----------------------------------+

Home