Question about a certain featue of the stack

Post here to share useful tips and tricks, to ask questions about using your DM42 or to report software-related problems
Post Reply
mcc
Posts: 277
Joined: Fri Jun 23, 2017 5:10 am

Question about a certain featue of the stack

Post by mcc »

Hi,

suppose this is the stack
T: 0
Z: 1
Y: 1
X: 1

I hit 6 (!) times '+' and get "3' as a result. "From above" '0's are filling the stack, when the "1"s are consumed.

but if the stack has this layout
T: 1
Z: 1
Y: 1
X: 1

again I hit 6 (!) times '+' and get "7' as a result. "From above" '1's are filling the stack, when the "1"s are consumed.

The act of filling '0's as replacement for "missing" items which get consumed at the bottom of the stack is what I would exspect since it is that what
CLST also does.

But what is the reason behind filling "1" (or whatever is in "T" at the start of the procedure) if the stack get consumed?

Thanks for any help and information in advance!
Cheers
Meino
DM 42 - SN: 00373, Firmware release v.:3.22. / DMCP 3.24. as compiled by SwissMicros
HPMike
Posts: 439
Joined: Fri Jul 21, 2017 11:01 pm
Location: DFW, Texas

Re: Question about a certain featue of the stack

Post by HPMike »

The T register is being replicated, which has always been the practice with HP RPN calculators. So it acts like a perpetual constant that gets repeated as the stack drops. See what happens when you put zero in the T register, and repeatedly press X (multiplication).
DM15L, S/N 00548. DM42, SN: 00159. DM41X, SN: 00973. DM32, SN 00054.
mcc
Posts: 277
Joined: Fri Jun 23, 2017 5:10 am

Re: Question about a certain featue of the stack

Post by mcc »

Hi Mike,

thanks for your answer.
It repeats with other words what I already had figured out.

But is the technical/mathematical reason for that NOT to feed the initial value ("0" after CLST) into the stack which it is consumed?

Cheers
Meino
DM 42 - SN: 00373, Firmware release v.:3.22. / DMCP 3.24. as compiled by SwissMicros
keithdalby
Posts: 564
Joined: Mon Apr 24, 2017 8:38 pm

Re: Question about a certain featue of the stack

Post by keithdalby »

I don't understand the question
mcc
Posts: 277
Joined: Fri Jun 23, 2017 5:10 am

Re: Question about a certain featue of the stack

Post by mcc »

Hi Keith,

I want to know the mathematical and or technical reason behind HP's decision to repeat T's value over and over again despite the
fact, that the initial value put onto the stack after CLST is different.

Cheers
Meino
DM 42 - SN: 00373, Firmware release v.:3.22. / DMCP 3.24. as compiled by SwissMicros
keithdalby
Posts: 564
Joined: Mon Apr 24, 2017 8:38 pm

Re: Question about a certain featue of the stack

Post by keithdalby »

So, if I am right in my understanding, you are asking why CLST clears the T register of the stack as well as the other registers? It clears the whole stack, that makes sense to me. I cannot think of a reason why CLST should clear the stack except for the T register.

As for why the T register copies down as values are popped off, it has some advantages for programming equations (such as polynomials), but I also find it useful if I'm to perform a series of calculations that all involve the same constant so I don't have to re-enter it or STO and RCL it.
dlachieze
Posts: 614
Joined: Thu May 04, 2017 12:20 pm
Location: France

Re: Question about a certain featue of the stack

Post by dlachieze »

Replicating T value on stack drop enables constant arithmetic, as explain for example in the HP-67 manual :
Example: A bacteriologist tests a certain strain whose population typically increases by 15% each day. If he starts a sample culture of 1000, what will be the bacteria population at the end of each day for six consecutive days?

Method: Put the growth factor (1.15) in the Y-, Z-, and T-registers and put the original population (1000) in the X-register. Thereafter, you get the new population whenever you press ×.
The replicating of T is also very useful to evaluate polynomials using the Horner method. For example to evaluate 8*x^4 + 5*x^3 + 2*x^2 - 7*x - 6 for the value in X you just have to do: ENTER, ENTER, ENTER, 8, *, 5, +, *, 2, +, *, 7, -, *, 6, -

This is very easy to program and uses only a very small amount of program steps. Remember that the RPN logic was defined when the calculator memory was scarce and expensive.

What would be the benefit of having 0 in T instead of replicating the previous value?
DM42: 00425 - DM41X: β00066 - WP43: 00042
User avatar
Walter
Posts: 3070
Joined: Tue May 02, 2017 11:13 am
Location: On a mission close to DRS, Germany

Re: Question about a certain featue of the stack

Post by Walter »

Look, Meino, the facts are:
  1. In the beginning and after CLST, the stack is all clear (i.e. loaded with zeros).
  2. When you enter a number, e.g. 47.11, this is in stack level X.
  3. When you press ENTER, the content of X is copied into stack level Y.
  4. Now enter a second number, e.g. 11.47; this goes into X again.
  5. When you press a dyadic function, e.g. +, y is added to x and the result (58.58) is loaded into X; then the previous content of Z (=0) is copied to Y; then the previous content of T (=0) is copied to Z; since there is no higher stack level, the previous content of T stays there unchanged.
Now let's modify this a little bit:
  1. In the beginning and after CLST, the stack is all clear.
  2. When you enter a number, e.g. 1.11, this is in stack level X.
  3. When you press ENTER, the content of X is copied into stack level Y.
  4. Now enter a second number, e.g. 111; this goes into X again.
  5. When you press a dyadic function, e.g. 'multiply', y is multiplied by x and the result (=123.21) is loaded into X; then the previous content of Z (=0) is copied to Y; then the previous content of T (=0) is copied to Z; since there is no higher stack level, the previous content of T stays there unchanged.
  6. Press 'multiply' again and you'll get zero.
Now let's modify this a second little bit:
  1. In the beginning and after CLST, the stack is all clear.
  2. When you enter a number, e.g. 1.11, this is in stack level X.
  3. When you press ENTER, the content of X is copied into stack level Y. Press it twice more and also Z and T will contain 1.11.
  4. Now enter a second number, e.g. 111; this goes into X again.
  5. When you press a dyadic function, e.g. 'multiply', y is multiplied by x and the result (=123.21) is loaded into X; then the previous content of Z (=1.11) is copied to Y; then the previous content of T (=1.11) is copied to Z; since there is no higher stack level, the previous content of T stays there unchanged.
  6. Press 'multiply' again and you'll get 136.7631.
  7. Press 'multiply' again and you'll get 151.807041.
  8. Press 'multiply' again and you'll get 168.50581551.
  9. etc.
HTH finally.
WP43 SN00000, 34S, and 31S for obvious reasons; HP-35, 45, ..., 35S, 15CE, DM16L S/N# 00093, DM42β SN:00041
Post Reply