
In Part 1 of this series I have resurrected my old HP-28S scientific calculator and written about stack computing. I have given the simple example of manipulating a stack to calculate Fibonacci Numbers by application of the operator $F$.
The purpose of this exercise is to show how actions shape forms and how the forms become symbols for actions. In this part we will apply our operator $F$ repeatedly and iterate through the Fibonacci Numbers to reach an interesting (however, well-known) conclusion…
Prelude Link to heading
Before we start I have to make a remark on the order in which stack operations are applied: The $F$-operator requires two numbers on the stack that get added to find the next update, $x_{n}$. Since addition is commutative, ie. $a+b = b+a$, the stack order of the numbers to be added is irrelevant. However, the + operation reduces the stack by one level and leaves the updated value on the stack. As we want to keep also the last value before the update we need to copy the second level over before addition. For proper stack maintanance the order of the stack matters and we have to SWAP the levels before or after OVER + to maintain the same ordering1:
1 2 SWAP OVER + .s \ first variant, keeps greater number at top
2 3 <-Top ok
2 1 OVER + SWAP .s \ second variant, keeps smaller number at top
2 3 3 2 <-Top ok
For reasons to become clear later we prefer the second variant (keeping the smaller number on top).
Here is the operator definition for F, again, and a proof of concept2 (investigating the current state of the stack with .s):
: F ( n1 n2 -- n2 n1+n2) OVER + SWAP ; \ second variant with lesser value at TOS
2 1 \ put initial values on stack
F .s
3 2 <-Top ok
F .s
5 3 <-Top ok
We understand now how the operator (read: action) F adds the previous stack, always keeping the last result at the TOS.
Are you ready for the next step?
Iteration Link to heading

Iteration applies an operator repeatedly on its result. The n-fold application on the stack is $FFF \cdots F$ (n times) or $F^n$. If we do this (and I encourage the reader to try it out with paper and pencil, with an RPN capable calculator - or a Forth stack) we find the sequence of adding up ever higher numbers. We can start or continue the iteration with any two numbers, in any order, producing a generalized Fibonacci sequence.
In Forth we can iterate F like this
: Fn ( n n n -- n n) 0 DO F .s LOOP ; \ iterate F n times
2 1 ok
10 Fn \ eg. 10 iterations
3 2 <-Top
5 3 <-Top
8 5 <-Top
13 8 <-Top
21 13 <-Top
34 21 <-Top
55 34 <-Top
89 55 <-Top
144 89 <-Top
233 144 <-Top ok
The output shows the stack after each iteration. If the .s is placed outside the loop the stack shows after eg. 50 iterations
: Fn ( n n n -- n n) 0 DO F LOOP ; \ iterate F n times ok
2 1 ok
50 Fn .s
53316291173 32951280099 <-Top ok
As the numbers are increasing during iterations, we may wish to re-normalize the stack. This can be done, at any point, by dividing the larger number (on the second stack level) by the other, and placing 1 at the top of the stack:
$$ x_{n}, x_{n-1} \to \phi_{n}, 1 ~~ where ~~ \phi_{n} = x_{n}/x_{n-1} \in \mathbb{R} $$
The re-normalized stack can now be displayed at once3.
: F ( n1 n2 -- n2, n1+n2) OVER + SWAP ; \ Fibonacci ok
: Fn ( n n n -- n n) 0 DO F LOOP ; \ iterate F n times ok
: 2S>F ( n1 n2 -- F: r1 r2) SWAP S>F S>F ; \ move S to F-stack ok
2 1 50 Fn 2DUP 2S>F F/ 1e .s \ do 50 iterations and re-normalize
53316291173 32951280099 <-Top 1.6180340E+00 1.0000000E+00 <-FTop ok
FOVER F. \ pop result 1.61803399 ok
In Forth we had to resort to Floating-Point (FP) arithmetic: We made the shift to the F-Stack (“F” stands for floating-point), performed the division and placed
1e there. The last line pops the re-normalized result to the foreground. Showing the current stack(s) with .s is only for illustration and can be dropped. – On the HP-28S calculator these acrobatics are all hidden in RPL as it does floating-point calculations out of the box.Interpretation Link to heading
Incidentally, the ratio $\phi_{n}$ of the two numbers converges to the Golden Section $\phi = 1.6180\ldots$ as we continue applying $F$ to the stack. So the re-normalization of the stack is a way to interrupt the recursion after n iterations $FFF \cdots F$ and to investigate the state. We can always continue iterating from where we left it for more precision4:
$$ GF^n \to \phi ~~ (n \to \infty) $$
Here $G$ stands for the operator of re-normalization that divides the two numbers on the stack and places 1 at the top (ie. dividing both by the lower value). In a next post to this series we will explore further the effects of $GF$.
For now the example has shown how we can use stack operations to arrive at stable eigen-values. These operations can be seen as actions in an environment (represented by the stack). After many iterations the operator and the state of the stack are in a dynamic balance, where the result corresponds to the action - in this case the operator $F$ and $\phi$ - and does not depend on the numbers acted upon!
Conclusion Link to heading
Congratulations, you have made it to the end of the second part. I hope you enjoyed it!
Admittedly the article has become more technical than I had thought. Partly because I got more acquainted with Forth and left aside my much easier experiments on the HP-28S pocket calculator. But they were more difficult to communicate on the other hand. So I had to work the Forth example with the generalized Fibonacci operator in detail (apologies and hope it was worth it).
This is all about how stack operations leave impressions in a history of states on the stack. Similar to a blockchain5 the history is “recorded” in a unified way. The stack is informed by the recursive application of the operator and constitutes the entire recorded history. If we know how to read it, it reveals the actions as form or state. Its form becomes a symbol for the action.
To make the analogy clearer, actions (like in our example) create stack modifications in which certain stable states can emerge. Eventually they result in “eigen-states”, like the forms and objects around us. Conversely, if the forms and objects we perceive are the result of actions, cognitive meta-stable states of consciousness, this little exercise can give us an idea of how they come about, appear and vanish in the space of the observer’s mind…
Writing this article was fun and gave me a chance to review some notes I had about the Forth language. It kindled some renewed interest for it. Postfix stack operations packed in WORDS inspire a sense for action as they are closer to our everyday experience of doing things. What seems like computational musings has analogues in the real world…
Also I resurrected my HP-28S that had “Memory Lost” since a long time. I purchased three new LR1 size N 1.5V batteries and - pow! - it came back to live instantly. The internet has preserved a lot of information about this magnificient calculator that make it worth using again after almost 40 years!
The stack is a LIFO (last-in first-out) buffer. ↩︎
For the sake of the argument I use
Fas a shorthand for a single Fibonacci Update, although its internalOVER + SWAPis basic and could stand by itself for transparancy. In fact, Leo Brody has described this exact phrase as a “cliché” that should not be factored:
Brodie, L. (2004). Thinking FORTH: A language and philosophy for solving problems. Fig Leaf Press, Forth Interest Group. Tip 6.16, p. 188. https://thinking-forth.sourceforge.net ↩︎Division requires Floating-Point (FP) arithmetic. The HP-28S runs FP natively so the re-normalization of the stack is simply
/ 1(divide and place 1 at TOS) in RPL. In Forth we need to move/copy the numbers from the data stack to a separate Floating-Point area (called F-stack). This is done by theS>Foperator which has to be applied twice, defining: 2S>F ( n1 n2 -- F: r1 r2) SWAP S>F S>F ; \ move 2 cells from S to F-stackdoes the trick. On the F-stack re-normalization is now possible. However, once re-normalized, we cannot return the result to the data stack without loss of the remainder. ↩︎The Golden Section $\phi$ is the positive root of the quadratic equation $x-1=1/x$ and the ratio of the numbers on the stack is an approximation. The order on the stack guarantees that $GF^n$ yields a value greater than 1. ↩︎
There is an obvious analogy to blockchain. Indeed, the operator approach presented here (in Forth-words) bears similarities to cryptocurrency transactions recorded in a string of hashes… ↩︎