4-level stack manipulation on 12c
03-02-2015, 03:18 AM
Post: #1
 Don Shepherd Senior Member Posts: 542 Joined: Dec 2013
4-level stack manipulation on 12c
If my 4-level stack on my 12c contains:

t - don't care
z - don't care
y - 17
x - 5

and I want it to contain:

t - 17
z - 5
y - 17
x - 5

is there an elegant way to achieve that using only ENTER, roll down, and x<->y?
03-02-2015, 03:40 AM (This post was last modified: 03-02-2015 03:40 AM by Mark Hardman.)
Post: #2
 Mark Hardman Senior Member Posts: 471 Joined: Dec 2013
RE: 4-level stack manipulation on 12c
(03-02-2015 03:18 AM)Don Shepherd Wrote:  If my 4-level stack on my 12c contains:

t - don't care
z - don't care
y - 17
x - 5

and I want it to contain:

t - 17
z - 5
y - 17
x - 5

is there an elegant way to achieve that using only ENTER, roll down, and x<->y?

If you also allow Rup it can be done in six steps:

Code:
 Enter, Enter, Rup, Enter, Rdn, x<>y t   0    0   17    5    5   17   17 z   0   17    5    5    5    5    5 y  17    5    5    5   17    5   17 x   5    5    5   17   17   17    5

The Rup can be replaced with three Rdn for a total of eight steps:

Code:
 Enter, Enter, Rdn, Rdn, Rdn, Enter, Rdn, x<>y t   0    0   17    5    5    5    5   17   17 z   0   17    5   17    5    5    5    5    5 y  17    5    5    5   17    5   17    5   17 x   5    5    5    5    5   17   17   17    5

I'm sure someone can do better.

Ceci n'est pas une signature.
03-02-2015, 03:40 AM
Post: #3
 Dale Reed Junior Member Posts: 34 Joined: Dec 2013
RE: 4-level stack manipulation on 12c
I'm sure someone will find an 'elegant' way in fewer steps, but:

---
---
17
5 Enter ^

---
17
5
5 Enter ^

17
5
5
5 R v

5
17
5
5 R v

5
5
17
5 R v

5
5
5
17 Enter ^

5
5
17
17 R v

17
5
5
17 x <> y

17
5
17

Total 8 operations.
Yep, somebody will definitely find a shorter one. But at least this is straightforward. ;-)

Dale
03-02-2015, 03:50 AM
Post: #4
 Dale Reed Junior Member Posts: 34 Joined: Dec 2013
RE: 4-level stack manipulation on 12c
Mark,

I guess us old HP-25 users think similarly... and simultaneously! It may chew up 8 steps, but at least it's easy to remember. Repeat after me:

"Enter - Enter - Down Down Down - Enter - Down - Exchange"
03-02-2015, 03:57 AM (This post was last modified: 03-02-2015 04:02 AM by PANAMATIK.)
Post: #5
 PANAMATIK Senior Member Posts: 870 Joined: Oct 2014
RE: 4-level stack manipulation on 12c
(03-02-2015 03:18 AM)Don Shepherd Wrote:  If my 4-level stack on my 12c contains:

t - don't care
z - don't care
y - 17
x - 5

and I want it to contain:

t - 17
z - 5
y - 17
x - 5

is there an elegant way to achieve that using only ENTER, roll down, and x<->y?

Code:
 t z x x y x z z x y y  z y z z x y x x x x x  y x y x z x y x y x y  x x x y x z x y y y x
Perhaps not the fastest approach, but it was asked to be elegant!
Bernhard
03-02-2015, 03:59 AM (This post was last modified: 03-02-2015 04:05 AM by Mark Hardman.)
Post: #6
 Mark Hardman Senior Member Posts: 471 Joined: Dec 2013
RE: 4-level stack manipulation on 12c
(03-02-2015 03:50 AM)Dale Reed Wrote:  Mark,

I guess us old HP-25 users think similarly... and simultaneously! It may chew up 8 steps, but at least it's easy to remember. Repeat after me:

"Enter - Enter - Down Down Down - Enter - Down - Exchange"

I would say that great minds think alike.

;-)

Ceci n'est pas une signature.
03-02-2015, 08:14 AM
Post: #7
 Paul Dale Senior Member Posts: 1,405 Joined: Dec 2013
RE: 4-level stack manipulation on 12c
In fewer keystrokes but not sticking to the operations available:

Assuming that: 17 ENTER 5 has already occurred.

Then:
Code:
        1 7 ENTER 5

Pauli
03-02-2015, 08:19 AM
Post: #8
 Csaba Tizedes Member Posts: 287 Joined: May 2014
RE: 4-level stack manipulation on 12c
(03-02-2015 03:18 AM)Don Shepherd Wrote:  If my 4-level stack on my 12c contains:

t - don't care
z - don't care
y - 17
x - 5

and I want it to contain:

t - 17
z - 5
y - 17
x - 5

is there an elegant way to achieve that using only ENTER, roll down, and x<->y?

Sigma+
RCL 2
RCL 4
RCL 2

But it does not count (...too many preconditions).
03-02-2015, 10:48 AM
Post: #9
 PANAMATIK Senior Member Posts: 870 Joined: Oct 2014
RE: 4-level stack manipulation on 12c
(03-02-2015 08:19 AM)Csaba Tizedes Wrote:  But it does not count (...too many preconditions).

If preconditions are allowed:

RCL 0 (R0 contains 17)
RCL 1 (R1 contains 5)

Shortest key sequence with preconditions allowed:

R/S
03-02-2015, 11:40 AM
Post: #10
 RayAtHP Junior Member Posts: 13 Joined: Apr 2014
RE: 4-level stack manipulation on 12c
(03-02-2015 10:48 AM)PANAMATIK Wrote:
(03-02-2015 08:19 AM)Csaba Tizedes Wrote:  But it does not count (...too many preconditions).

If preconditions are allowed:

RCL 0 (R0 contains 17)
RCL 1 (R1 contains 5)

Shortest key sequence with preconditions allowed:

R/S

Stretching the preconditions a bith further and assuming 17 and 5 are on the stack:

2dup

... hp71b in forth mode.

Best regards -Ray
03-02-2015, 12:28 PM
Post: #11
 Werner Senior Member Posts: 335 Joined: Dec 2013
RE: 4-level stack manipulation on 12c
6 steps:

Code:
ENTER ENTER - RDN X<>Y LASTX

Cheers, Werner
03-02-2015, 12:31 PM
Post: #12
 Sylvain Cote Senior Member Posts: 903 Joined: Dec 2013
RE: 4-level stack manipulation on 12c
(03-02-2015 03:18 AM)Don Shepherd Wrote:  is there an elegant way to achieve that using only ENTER, roll down, and x<->y?

The attached file contains all the possible stack manipulation.
From the french book "Programmer HP-41"

Attached File(s) Thumbnail(s)

03-02-2015, 12:45 PM
Post: #13
 Csaba Tizedes Member Posts: 287 Joined: May 2014
RE: 4-level stack manipulation on 12c
(03-02-2015 12:28 PM)Werner Wrote:  6 steps:

Code:
ENTER ENTER - RDN X<>Y LASTX

Cheers, Werner

Yes, this is REALLY elegant! Grat!
03-02-2015, 01:49 PM
Post: #14
 Don Shepherd Senior Member Posts: 542 Joined: Dec 2013
RE: 4-level stack manipulation on 12c
(03-02-2015 12:28 PM)Werner Wrote:  6 steps:

Code:
ENTER ENTER - RDN X<>Y LASTX

Cheers, Werner

Well, I have to agree with Csaba. Elegant!

Thanks to all. Lots of great minds out there.

Don
03-02-2015, 03:30 PM (This post was last modified: 03-02-2015 03:33 PM by Gene.)
Post: #15
 Gene Moderator Posts: 842 Joined: Dec 2013
RE: 4-level stack manipulation on 12c
Tony Hutchins gave this 7-step solution without using LASTX.

ENTER
ENTER
CLx
-
Roll Down
X<>Y
Roll Down

But more importantly, the PDF where this and a large number of such ideas is found here:

Stack Rearrangements

You can find this solution by searching for ABAB, which represents XYXY as the contents of the four level RPN stack.
03-02-2015, 03:53 PM (This post was last modified: 03-02-2015 05:41 PM by Don Shepherd.)
Post: #16
 Don Shepherd Senior Member Posts: 542 Joined: Dec 2013
RE: 4-level stack manipulation on 12c
Thanks Gene. A fascinating book.

I just realized I have the book upon which Tony's book is based, "Algorithms for RPN Calculators," in my bookcase!

But I wouldn't have known about Werner's 6-step solution from that book, I suppose.

Don
03-03-2015, 10:54 PM (This post was last modified: 03-03-2015 10:57 PM by Marcus von Cube.)
Post: #17
 Marcus von Cube Senior Member Posts: 754 Joined: Dec 2013
RE: 4-level stack manipulation on 12c
(03-02-2015 03:30 PM)Gene Wrote:  Stack Rearrangements

That's why we have included the shuffle command ⇄ in the 34S. It allows to shuffle the lower four stack levels in an arbitrary fashion with a single command. The main purpose of this command is readability in a program but it works interactively as well. To accomplish the requested task the command would be:

Code:
⇄ XYXY

Self explanatory, isn't it?

A solution that works for all calculators which can directly recall the stack:

Code:
RCL Y RCL Y

Marcus von Cube
Wehrheim, Germany
http://www.mvcsys.de
http://wp34s.sf.net
http://mvcsys.de/doc/basic-compare.html
03-03-2015, 11:25 PM
Post: #18
 PedroLeiva Member Posts: 99 Joined: Jun 2014
RE: 4-level stack manipulation on 12c
When I saw the discussion of management of operational scale I remembered a paper from Tony Hutching where the author presents a series of tables to relocate data (see attached). Perhaps it would be useful to analyze this issue

I take this opportunity to ask for a brief management explanation of Tony job and if it is useful today for programming the HP 35s calculator. Thank you very much for your attention, Pedro

Attached File(s)
03-04-2015, 06:52 AM
Post: #19
 Massimo Gnerucci Senior Member Posts: 1,585 Joined: Dec 2013
RE: 4-level stack manipulation on 12c
(03-03-2015 11:25 PM)PedroLeiva Wrote:  When I saw the discussion of management of operational scale I remembered a paper from Tony Hutching where the author presents a series of tables to relocate data (see attached). Perhaps it would be useful to analyze this issue

I take this opportunity to ask for a brief management explanation of Tony job and if it is useful today for programming the HP 35s calculator. Thank you very much for your attention, Pedro

Same as Gene's.
:)

Greetings,
Massimo

-+×÷ ↔ left is right and right is wrong
03-04-2015, 09:50 AM
Post: #20
 PedroLeiva Member Posts: 99 Joined: Jun 2014
RE: 4-level stack manipulation on 12c
(03-04-2015 06:52 AM)Massimo Gnerucci Wrote:
(03-03-2015 11:25 PM)PedroLeiva Wrote:  When I saw the discussion of management of operational scale I remembered a paper from Tony Hutching where the author presents a series of tables to relocate data (see attached). Perhaps it would be useful to analyze this issue

I take this opportunity to ask for a brief management explanation of Tony job and if it is useful today for programming the HP 35s calculator. Thank you very much for your attention, Pedro

Same as Gene's.

My apologies. I read over what Gene had written, and did not open the file. Sorry. But I still wonder if Tony tables are useful today, and what is the reason of saving so much programming steps. Pedro
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)