# HP Forums

Full Version: Communicating stack state transitions, a notation.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

I will try using the following notation to communicate RPN program's effect on the stack and LASTX register:

[d,c,b,a][e]->oper. desc.->[d',c',b',a'][e']

The first array with four elements represents the stack where d and d' refers to content of the T stack register and a and a' to content in the X stack register. The e and e' in the single element
array refers to the LASTX register's content. Ofcourse actual letters or words used may be choosen to so fit the input/output for particular program.

So for example to describe sqrt:

[d,c,b,v][e]->sqrt->[d,c,b,sqrt(v)][v]

[d,c,b,a][e]->+->[d,d,c,b+a][a]

Ofcourse there are other (better?) ways using tables or some kind of bar diagram but think this may work and have the advantage of being easy and fast to type in text only documents.

Anyone of your long time rpn hackers having an opinion on this topic?

Hi, Arne:

Obviously it would be far easier on the eyes and more useful if you would use X, Y, Z, T and L instead of a, b, c, d and e, like this:

```
[X, Y, Z, T | L] -> Sqrt -> [Sqrt(X), Y, Z, T | X ]
```
or a variation thereof.

Best regards from V.

Edited: 9 Oct 2007, 6:17 p.m. after one or more responses were posted

Small details, but think your way of | replacement for my 'two array' notation looks better, will use.

As for the actual letters, think may become confusing if variable bound to orginal position in register; there may be a chain of operation... And if x contains speed of light; use c.

Now, for me LEFT maps to TOP (i.e. T) and I always think of LASTX as 'below' X register... Interesting that you turned it around! Perhaps most people find yours more natural, perhaps its because I am lefthanded :-).

Hmmm, actual that is perhaps more readable... must think about it... to bad there aint enough people interested in this detail to have a poll!

Thanks!

Edited: 9 Oct 2007, 6:17 p.m.

God dag Arne,

I like Valentin's notation better because the x-level -- which will change most frequently -- appears leftmost, i.e. first for people reading from left to right.

Just my 20 milli-Euro

Hi Arne,

I agree with Valentin and Walter.

It's the notation I have been using since my first steps in RPN.

Best regards

I have arrived at the same conclusion myself... Good thing I asked :-)

I would advocate following the stack notation practices used with the programming language Forth. The lowest items on the stack appear to the right, only the applicable levels appear, and two dashes separate the 'before' and 'after' snapshots.

For example:

`( y x -- y+x )`
would be a compact representation for the '+' key.

If you want to explicitly show the entire stack (and Last X register) this could become

`( t z y x | a -- t t z y+x | x ) `

Usually the stack comments would try to convey a little more meaning, such as:

`( Lat1 Lon1 Lat2 Lon2 -- Bearing )`

to document that calculates the initial great circle bearing
to fly from point 1 to point 2.

Interesting, I remember in my young days there was a lot of talk about the FORTH language... The notation is good and very similar to Valentin's proposal I have addopted (good I did not go ahead with my orginal syntax). I do agree names should reflect nature of value. I use X, Y, Z, T, L for the 'bystanders'...