Showing posts with label Classic RPN. Show all posts
Showing posts with label Classic RPN. Show all posts

Sunday, November 8, 2026

Classic RPN Stack Operations

 Classic RPN Stack Operations


Starting Stack:



T:  d

Z:  c

Y:  b

X:  a


OVER:   Copies b to the Z and X stacks, while leaving a in the Y stack.   c is pushed to the T stack.


T:  d  -> c
Z:  c  -> b
Y:  b -> a
X:  a -> b


RPN Keystrokes:

x<>y
ENTER
R↓
x<>y
R↑



ROT:  Rotate Up.   The contents of the T stack is untouched.



T:  d  -> d
Z:  c  -> b
Y:  b -> a
X:  a -> c


RPN Keystrokes:

R↓
R↓
x<>y
R↓



UNROT:  Rotate Down.   The contents of the T stack is untouched.

T:  d  -> d
Z:  c  -> a
Y:  b -> c
X:  a -> b


RPN Keystrokes:

R↑
X<>Y
R↑
R↑


DROP:  Drops the contents of the X stack.   It is named DROPX on the R47.  d is copied onto the Z stack.  



T:  d  -> d
Z:  c  -> d
Y:  b -> c
X:  a -> b

(thank you, Craig!)


RPN Keystrokes:

CL x
+



NIP:  Drops the contents of the Y stack.   It is named DROPY on the R47.  d is copied onto the Z stack.  

T:  d  -> d
Z:  c  -> d
Y:  b -> c
X:  a -> a


RPN Keystrokes:

x<>y
CL x
+



DROP2:  Deletes a and b from the X and Y stacks, respectively, and replaces them with c and d.  



T:  d  -> 0
Z:  c  -> 0
Y:  b -> d
X:  a -> c


RPN Keystrokes:

R↓
CL x
ENTER
R↓
R↓



DUP2:  Duplicates a and b on to the Z and T stacks, respectively.

(Ball, John A.  Algorithms for RPN Calculators.  John Wiley & Sons, Inc. New York, NY.  1978)



T:  d  -> b
Z:  c  -> a
Y:  b -> b
X:  a -> a


RPN Keystrokes:

ENTER
ENTER
CL x
-
R↓
x<>y
R↓


Eddie


All original content copyright, © 2011-2026. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.



Saturday, February 14, 2026

RPN: Absolute Value Equations with the HP 11C and DM41X

RPN: Absolute Value Equations with the HP 11C and DM41X



Introduction: Solving |z * w + y| = x


Today’s blog focuses on solving the absolute value equation:


|z * w + y| = x


for the variable w, and the values of z, y, and x are given and are on the Classic RPN stack.


For example, in the problem |5 * w + 7| = 2, the stack would be set up as:


t: (anything, it doesn’t matter)

z: 5

y: 7

x: 2


(This is why I set the variable as w instead of the usual x.)


One approach is to use memory registers and other uses only stack operations. Today’s algorithm focuses on the latter.


Caution: In the above equation, x will always be non-negative. The equation will never be valid if x is negative.



The Algebra


Solve for w:

|z * w + y| = x


This leads us to solve the two equations:


(I)

z * w + y = -x

z * w = -x – y

w = -x/z – y/z


Let w- = -x/z – y/z = (-x/z) + (-y/z)


(II)

z * w + y = x

z * w = x – y

w = x/z - y/z


Let w+ = x/z – y/z = (x/z) + (-y/z)


Then:


w- = -x/z – y/z

w- = (-x/z) + (-y/z)

w- = (-x/z) + (-y/z) + (-x/z) + (x/z)

w- = 2 * (-x/z) + (x/z) + (-y/z)

w- = 2 * (-x/z) + w+


RPN Code: HP 11C (adoptable for other RPN calculators)


LBL A

001

42, 21, 11

Program start

R↓

002

33


R↓

003

33


X<>Y

004

34


R↓

005

33


1/x

006

15


×

007

20


LST x

008

43, 36


X<>Y

009

34


R↓

010

33


×

011

20


LST x

012

43, 36


R↑

013

43, 33


X<>Y

014

34


R↓

015

33


X<>Y

016

34


CHS

017

16


X<>Y

018

34


+

019

40


ENTER

020

36


ENTER

021

36


LST x

022

43, 36


-

023

30


LST x

024

43, 36


-

025

30


RTN

026

43, 32

Program end


RPN Code: DM41X (HP 41C series, no module is required)


LBL “ASBEQ”

RDN

RDN

X<>Y

RDN


1/x

×

LAST X

X<>Y

RDN

×

LAST X

R↑

X<>Y


RDN


X<>Y

CHS

X<>Y


+

ENTER

ENTER

LAST X

-

LAST X

-


RTN



Notes:

* RDN is shown as R↓

* To enter R↑, press XEQ, ALPHA, R, SHIFT, ENTER, ALPHA



Subroutines Used


We used several techniques to manipulate the stack. They are presented below:


Rotate stack from X, Y, Z, T to Z, X, Y, T

R↓

R↓

X<>Y

R↓


Source:

Ball, John A. Algorithms for RPN Calculators John Wiley & Sons: New York. 1978. ISBN 0-471-03070-8. pg. 78



Multiply Y and Z by 1/X. Stack: X, Y, Z, T → X, Y/X, Z/X, T


1/x

×

LAST X

X<>Y

R↓

×

LAST X

R↑

X<>Y


Change X, Y to Y+ X, Y – X


+

ENTER

ENTER

LAST X

-

LAST X

-


The resulting stack is:


z

z

y + x

y – x


Doing LAST X, -, twice is effectively subtracting whatever is in L register twice.



Examples


|4 * w – 6| = 5


Stack:

z: 4

y: -6

x: 5


Results:

y: 2.75

x: 0.25


|2 * w + 5| = 3


Stack:

z: 2

y: 5

x: 3


Results:

y: -1

x: -4




Eddie


All original content copyright, © 2011-2026. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

HP 15C: The I Squared Rule and HHC 2026

HP 15C: The I Squared Rule and HHC 2026 HHC 2026 Videos Before we start, the videos for HHC 2026 are up! Please take a look, ev...