Page 1 of 1

HowTo create this program?

PostPosted: Mon Mar 29, 2021 2:44 pm
by floppy_stuttgart
Hello,
what key sequence or module should I use for creating..

LBL 'RAC'
RDN <- this
CHS
ST/ Z <- this
ST+ X <- this
/
STO Z <- this
STO T <- this
X^2
+
SQRT
ST- Z <- this
+
END

I just wanted to show an HP41 program to a family member (since its works again after 30y). I just cannot find again the doc how to input this in PRGM mode.

Re: HowTo create this program?

PostPosted: Mon Mar 29, 2021 4:32 pm
by dlachieze
Hello,
Congratulations for having again a working 41C ! It's a great machine with a lot of people still developing programs and modules for it.
The instructions you're looking for are part of the 41C instruction set, no need for an additional module.
Here are the key sequences:
  • RDN: the key above XEQ with R and a down arrow (RDN: RollDowN)
  • ST/ Z: STO / . Z (/ is the division symbol, when you press . the display will show ST/ ST, which means STO divide Stack, then you press Z to specify the stack register Z and the display will be ST/ Z)
  • ST+ X: STO + . X
  • STO Z: STO . Z
  • STO T: STO . T
  • ST- Z: STO - . Z

Re: HowTo create this program?

PostPosted: Mon Mar 29, 2021 8:22 pm
by floppy_stuttgart
Thanks: works.

Code: Select all
LBL 'RAC'
RDN
CHS
ST/ Z
ST+ X
/
STO Z
STO T
X^2
+
SQRT
ST- Z
+
END


This is solving a.X² +b.X+c = 0

By just doing..
c
ENTER
b
ENTER
a
ENTER
XEQ "RAC"

.. both solutionx X1 and X2 are in the X and Y of the stack.
(ERROR if no solution in real).

I am happy. My program anno 1983 works again.

Re: HowTo create this program?

PostPosted: Sun Apr 04, 2021 10:00 am
by mike-stgt
I attempted to reduce it in size but got squeezed out one single byte only.

Re: HowTo create this program?

PostPosted: Sun Apr 04, 2021 5:45 pm
by floppy_stuttgart
mike-stgt wrote:I attempted to reduce it in size but got squeezed out one single byte only.

And: what is the result of that squeezed out byte?
If I remember RDN was not necessary in the program if no "ENTER" is made after the entry "a". But for the beauty and symetrie of the entry sequence, clicking on "enter" after introducing "a" would make the symetrie of clicking "enter" after c and b and a.
So, the only squeeze possibility was to avoid that RDN.
If you have the print document (or scan to it in a link) when it was published in (198x?) I would be happy to receive it.

Re: HowTo create this program?

PostPosted: Sun Apr 04, 2021 11:50 pm
by mike-stgt
floppy_stuttgart wrote:And: what is the result of that squeezed out byte?
I may use the saved byte elsewhere for something much more meaningful :mrgreen:
[...] But for the beauty and symetrie of the entry sequence, clicking on "enter" after introducing "a" would make the symetrie of clicking "enter" after c and b and a.
I've got that, therefore my routine starts with the stack set as yours.
So, the only squeeze possibility was to avoid that RDN.
As just said I start with the same stack setup. Following one of my unhappy attempts, saving one byte only was not worth the effort. Result is almost the same as with your routine, mine shows the lower root in X -- I prefer that, as it complies with the common reading direction in Europe.
Code: Select all
 01▶LBL "QG3"
ST/ T  +  /  STO T  X^2
-  CHS  SQRT  ENTER^  R^
ST- Z  +  CHS  END 

        12,00000 ENTER^
        -7,00000 ENTER^
         1,00000 ENTER^
                    RUN
         3,00000    ***
                   X<>Y
         4,00000    ***

Well, others solve sudokus or do crosswords, my preferred brainteaser is "squeezing" HP-41 routines.

Re: HowTo create this program?

PostPosted: Thu Apr 08, 2021 8:23 am
by floppy_stuttgart
I see. Lets adopt an other story telling ("alternative fact" -:) and now we could become "lean": lets chase waste of clicking too much the HP41CV.
By feeding the stack with
c
ENTER
b
ENTER
a

then executing a program
XEQ 'RAC'

where
LBL 'RAC'
CHS
ST/ Z
ST+ X
/
STO Z
STO T
X^2
+
SQRT
ST- Z
+
END

then we solve the equation a.X² +b.X+c = 0 and both solutions X1 and X2 are in the stack in X and Y
(only solutions in real; no solution in complex given; it would else give ERROR).
So now, is that RAC program lean/clean/short or has anybody an idea how to make it smaller?
a) smaller in number of lines
b) or smaller in number of bytes

Whatever, can somebody remember me to know how is the size of this "RAC"?

Re: HowTo create this program?

PostPosted: Fri Apr 09, 2021 12:01 am
by mike-stgt
Altering the input protocol/procedure is a game changer. For the original stack setup I was able to shorten the routine by another byte:
Code: Select all
 01▶LBL "QG5"
ST/ T  +  /  CHS  ENTER^
ENTER^  X^2  R^  -  SQRT
+  X<>Y  LASTX  -  END

The size of routines is shown in CAT 1, at least on a 41CX.

Re: HowTo create this program?

PostPosted: Sun Apr 11, 2021 10:45 am
by mike-stgt
floppy_stuttgart wrote:So now, is that RAC program lean/clean/short or has anybody an idea how to make it smaller?
a) smaller in number of lines
b) or smaller in number of bytes

Yes, no problem. Starting from the new stack setup, plugging an Advantage and a printer offers a Einstein–Rosen bridge to a routine with a) fewer lines and b) less bytes.
Code: Select all
 01▶LBL "QGL"
2  STO 22  R^  STO 00 
R^  STO 01  R^  STO 02
SF 00  XROM "RTS"  END
I guess, this is only an intermediate stage towards the optimum.