Post Reply 
HP-42s Entering 4 complex numbers on the stack
05-28-2023, 09:42 AM (This post was last modified: 05-28-2023 09:45 AM by Vincent Weber.)
Post: #1
HP-42s Entering 4 complex numbers on the stack
A common reproach made to the 42S is that its complex numbers implantation, while being one the best, does not allow to enter 4 complex numbers on the stack in the row, since 2 stack levels are needed to create a complex number (as opposed to the 15c which has a parallel imaginary stack, or to the 35S that allows one-line entry).

To solve this, various solutions have been suggested, generally consumming registers or variables.

I have thought of a simple solution with no variables consumption: just enter the 4 complex numbers in a 1x4 complex matrix. If CSTK is such a matrix, then the following little program populates the stack with the 4 numbers, et voilà. What do you think?

00 { 30-Byte Prgm }
01▸LBL "CPX"
02 INDEX "CSTK"
03 RCLEL
04 I+
05 RCLEL
06 I+
07 RCLEL
08 I+
09 RCLEL
10 RTN
11 END
Find all posts by this user
Quote this message in a reply
05-28-2023, 11:53 AM
Post: #2
RE: HP-42s Entering 4 complex numbers on the stack
That’s brilliant! Works great!
Another option for users of the DM42 (or Free42/Plus42) is to turn on the Big Stack (NSTK) mode. Then you can enter as many complex numbers onto the stack as you want.
Visit this user's website Find all posts by this user
Quote this message in a reply
05-28-2023, 12:00 PM
Post: #3
RE: HP-42s Entering 4 complex numbers on the stack
Thanks! But unlimited stack is not an option for die-hard RPN users Smile
Find all posts by this user
Quote this message in a reply
05-28-2023, 01:23 PM
Post: #4
RE: HP-42s Entering 4 complex numbers on the stack
(05-28-2023 09:42 AM)Vincent Weber Wrote:  A common reproach made to the 42S is that its complex numbers implantation, while being one the best, does not allow to enter 4 complex numbers on the stack in the row, since 2 stack levels are needed to create a complex number (as opposed to the 15c which has a parallel imaginary stack, or to the 35S that allows one-line entry).

Yes, and this little annoyance is made worst by the fact that COMPLEX saves the X content into LaxtX, which is not only useless since X is not lost but also prevents to use LastX as an auxiliary register to input these 4 complex values.

BTW, I'm one of the few who see the HP-32S/32SII way to enter a complex value on the stack (imag part first, then real part) much more natural on a RPN machine, than the algebraic order of the 42S.

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
05-28-2023, 01:38 PM
Post: #5
RE: HP-42s Entering 4 complex numbers on the stack
Good point about LASTX. What do you think of my way?

Regarding the 32S/32SII, I like the simplicity or the complex numbers handling, but I think it is half-baked:
-A stack reduced to 2 elements;
-No way to operate this stack like the normal one: no complex X<>, lastX,etc...;
-Missing math functions, e.g. reverse trigs.

All in all, quite difficult to write a program that operates seemlessly on both real and complex numbers!
Find all posts by this user
Quote this message in a reply
05-28-2023, 04:21 PM (This post was last modified: 05-28-2023 04:23 PM by jonmoore.)
Post: #6
RE: HP-42s Entering 4 complex numbers on the stack
(05-28-2023 01:38 PM)Vincent Weber Wrote:  Good point about LASTX. What do you think of my way?

Regarding the 32S/32SII, I like the simplicity or the complex numbers handling, but I think it is half-baked:
-A stack reduced to 2 elements;
-No way to operate this stack like the normal one: no complex X<>, lastX,etc...;
-Missing math functions, e.g. reverse trigs.

All in all, quite difficult to write a program that operates seemlessly on both real and complex numbers!

^ This.

The 32 series is great for the mathematics a student encounters pre-university, be that GCSE A-Levels or English Baccalaureate (on this side of the pond), which is the superior option IMO (our Continental European friends have known this all along). But it's lacking for studies beyond this standard. In fact, depending on chosen options available to talented pre-university math students, they'll also require more sophisticated complex math capabilities than a 32 can provide.

I'm aware few on the MoHPC forum are interested in student-level mathematics, but the 32 series was originally specified for high-school math. I sit on a PTA, so probably care more about this stuff than the average parent, but there are plenty of students that frequent other parts of the MoHPC forums, and it's pertinent knowledge for them should they be interested in picking up a HP 32 on an auction site or if the DM32 is a tempting proposition.

Much that the vast majority of kids can't believe that some prefer hardware to mobile phone/tablet apps for their calculating needs, others adore the 尺?七尺ㄖ ⼕卄讠⼕ of dedicated hardware.
Find all posts by this user
Quote this message in a reply
05-28-2023, 04:28 PM
Post: #7
RE: HP-42s Entering 4 complex numbers on the stack
(05-28-2023 01:38 PM)Vincent Weber Wrote:  Regarding the 32S/32SII, I like the simplicity or the complex numbers handling, but I think it is half-baked:
-A stack reduced to 2 elements;
-No way to operate this stack like the normal one: no complex X<>, lastX,etc...;
-Missing math functions, e.g. reverse trigs.

I agree, the 32SII has serious limitations for complex number handling.
I'm particularly missing CMPLXx^2 and CMPLXSQR. It can be computed with the help of CMPLXy^x but it's quite tedious and uses all the stack.
Note however, that CMPLXx<>y can be done with Rv Rv
(I long ago asked for a way to do CPMLXENTER as a challenge).


Back to the 42S:
Quote:What do you think of my way?
It's a fine idea but it uses a variable CSTK. Can you design a solution with the matrix on the stack?
I don't remember if a solution without a extra variable/register was ever found.

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
05-28-2023, 04:52 PM
Post: #8
RE: HP-42s Entering 4 complex numbers on the stack
(05-28-2023 04:28 PM)J-F Garnier Wrote:  Note however, that CMPLXx<>y can be done with Rv Rv
(I long ago asked for a way to do CPMLXENTER as a challenge).

Is 0 ENTER 1 CMPLX× the shortest solution for CMPLXENTER?

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
05-28-2023, 04:57 PM
Post: #9
RE: HP-42s Entering 4 complex numbers on the stack
(05-28-2023 04:28 PM)J-F Garnier Wrote:  [Back to the 42S:
Quote:What do you think of my way?
It's a fine idea but it uses a variable CSTK. Can you design a solution with the matrix on the stack?
I don't remember if a solution without a extra variable/register was ever found.

J-F

I'm trying to put the matrix creation and edition in the program. But I struggle, EDIT is programmable, but the program doesn't wait for the edition to be completed to continue... Any way to make it wait?
Find all posts by this user
Quote this message in a reply
05-28-2023, 05:14 PM
Post: #10
RE: HP-42s Entering 4 complex numbers on the stack
Here we go. I was being silly, just R/S will do. I have cheated a bit, using LSTO (only available in Free42/DM42/Plus42, not the original 42S) not to consume a global variable. We still need a variable for the matrix, no way to put it on the stack and at the same time to fill the stack! Just edit the matrix, exit the editor, press R/S, and done. Compared to my previous solution, you start with zeros rather than previously entered values. Maybe a drawback in some cases? Oh well...

00 { 47-Byte Prgm }
01▸LBL "CPX"
02 1
03 ENTER
04 4
05 NEWMAT
06 ENTER
07 COMPLEX
08 EDIT
09 STOP
10 LSTO "CSTK"
11 INDEX "CSTK"
12 RCLEL
13 I+
14 RCLEL
15 I+
16 RCLEL
17 I+
18 RCLEL
19 RTN
20 END
Find all posts by this user
Quote this message in a reply
05-28-2023, 06:25 PM
Post: #11
RE: HP-42s Entering 4 complex numbers on the stack
(05-28-2023 04:52 PM)Joe Horn Wrote:  
(05-28-2023 04:28 PM)J-F Garnier Wrote:  Note however, that CMPLXx<>y can be done with Rv Rv
(I long ago asked for a way to do CPMLXENTER as a challenge).

Is 0 ENTER 1 CMPLX× the shortest solution for CMPLXENTER?

My solution was close: 0 ENTER CMPLX+ , a bit shorter and marginally faster.

It enables to emulate the missing CMPLXx^2 by 0 ENTER CMPLX+ CMPLX*

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
05-28-2023, 10:22 PM
Post: #12
RE: HP-42s Entering 4 complex numbers on the stack
(05-28-2023 06:25 PM)J-F Garnier Wrote:  
(05-28-2023 04:52 PM)Joe Horn Wrote:  Is 0 ENTER 1 CMPLX× the shortest solution for CMPLXENTER?

My solution was close: 0 ENTER CMPLX+ , a bit shorter and marginally faster.

It enables to emulate the missing CMPLXx^2 by 0 ENTER CMPLX+ CMPLX*

J-F

Sweet! Smile

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
05-30-2023, 06:42 AM (This post was last modified: 05-30-2023 06:44 AM by Werner.)
Post: #13
RE: HP-42s Entering 4 complex numbers on the stack
(05-28-2023 05:14 PM)Vincent Weber Wrote:  We still need a variable for the matrix, no way to put it on the stack and at the same time to fill the stack!

If you don't care about LASTX:

00 { 38-Byte Prgm }
01▸LBL "CPX"
02 1
03 4
04 NEWMAT
05 ENTER
06 COMPLEX
07 EDIT
08 STOP
09 EXITALL
10 EDIT @ reposition at (1,1)
11 ENTER
12 ↓
13 ENTER
14 ↓
15 ENTER
16 ↓
17 STO ST L
18 EXITALL
19 X<> ST L
20 END

The first EXITALL may be omitted if you keep the same usage instructions.
Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
06-10-2023, 10:12 AM
Post: #14
RE: HP-42s Entering 4 complex numbers on the stack
Hi,

I came up with a totally different approach. It gives up on real HP-42S compatibility and makes use of awesome Free42/Plus42 extensions:
-FUNC that allows user-defined functions with preserves the original stack;
-RCOMPLEX and PCOMPLEX with allow to enter a complex number in a different mode than the current rect/polar mode.
-Just launch, mess up with the stack without any fear, generate your complex number as usual (on 2 stack levels) and press either RECT or POLAR. Do it As much as you want (until you have 4 complex numbers on the stack) then press EXIT. Done.

I have always found the 35S One-line entry way cute, but limited: it will use one stack level... Only if you know exactly in advance the 2 parts of the complex number and key them in! But in most cases you need to build these parts with intermediate computations. Here you can use the stack as a scratch pad before entering a new complex number, the stack will remain intact. Cute, isn't it? Even more so than on the 15C! Smile

If you want to to use a real HP 42S you can use variables to save and restore the stack registers, and conversions to enter in a different rect/polar mode.

00 { 59-Byte Prgm }
01▸LBL "RC"
02 CLMENU
03 "RECT"
04 KEY 1 XEQ 02
05 "POL"
06 KEY 6 XEQ 03
07 KEY 9 XEQ 99
08 MENU
09▸LBL 04
10 XEQ 01
11 GTO 04
12 RTN
13▸LBL 02
14 RCOMPLX
15 RTN
16▸LBL 03
17 PCOMPLX
18 RTN
19▸LBL 01
20 FUNC 01
21 STOP
22 RTN
23▸LBL 99
24 CLMENU
25 EXITALL
26 RTN
27 END
Find all posts by this user
Quote this message in a reply
06-10-2023, 07:29 PM (This post was last modified: 06-10-2023 07:39 PM by C.Ret.)
Post: #15
RE: HP-42s Entering 4 complex numbers on the stack
Hi,

I'm a little surprised to read that there is no way on the 42S to put four complex numbers in the stack. While this is possible on an HP-15C. This is a bit tricky, since you must use the sequence [<-] [Re↔Im] [<-] to modify the two parts of the X-register to INPUT the last complex of a complete stack.

But the typing:
41 ENTER 402 f I 31 ENTER 302 f I 21 ENTER f I 202 enter the first three complex numbers in the stack
ENTER make a copy of the last entry
<- 102 f Re↔Im <- 11 enter last complex with no stack move
and finally:
R↓ f (i) R↓ f (i) R↓ f (i) R↓ f (i) lists the real and imaginary contents of the full stack

Code:
T: 41 + 402 i
Z: 31 + 302 i
Y: 21 + 202 i
X: 11 + 102 i

Really, there's no other way than to use a 27-lines program to fill the stack with complex entries?

Amazed I am!
Find all posts by this user
Quote this message in a reply
06-10-2023, 07:40 PM (This post was last modified: 06-10-2023 07:41 PM by Vincent Weber.)
Post: #16
RE: HP-42s Entering 4 complex numbers on the stack
The HP-15C is the only calculator in the world with a parallel imaginary stack, hence its edge in this matter.

Nonetheless I did these programs just for fun, in practice I find the 42S approach much more convenient even with this little drawback, you can see the complex number at one glance, be it in rectangular or in polar form!

And you seldom are in the situation where you know the exact 4 numbers to enter before hand. Usually you need to compute the complex numbers first. If the 2 parts have to be computed separately, then you need to switch to real mode on the 15C, hence breaking the nice "complex work exactly like real" paradigm. Oh well.

The 15C and the 42S are two excellent, legendary RPN machines. The 42S is much more capable in almost every way, save for little details like this one. The 15C is cuter, its design is unique, it has more prestige. I guess the 15C owner could see the 42S as a worthy successor, while keeping nostalgia for the 15C design...
Find all posts by this user
Quote this message in a reply
06-10-2023, 10:29 PM
Post: #17
RE: HP-42s Entering 4 complex numbers on the stack
.
Hi, C.Ret,

(06-10-2023 07:29 PM)C.Ret Wrote:  I'm a little surprised to read that there is no way on the 42S to put four complex numbers in the stack [...] Really, there's no other way than to use a 27-lines program to fill the stack with complex entries?

Of course there is ! Matter of fact you need no program to do it, that's just Mr. Weber doing his thing ...

From the keyboard, do this to enter 1+2i, 3+4i, 5+6i and 7+8i into the RPN stack:
    1, ENTER, 2, COMPLEX, STO A {... or any other variable}
    3, ENTER, 4, COMPLEX,
    5, ENTER, 6, COMPLEX,
    7, ENTER, 8, COMPLEX, RCL A, Rdown

... and there you are, simple and effortless.

Regards.
V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
06-10-2023, 10:36 PM (This post was last modified: 06-10-2023 10:40 PM by Vincent Weber.)
Post: #18
RE: HP-42s Entering 4 complex numbers on the stack
(06-10-2023 10:29 PM)Valentin Albillo Wrote:  .
Hi, C.Ret,

(06-10-2023 07:29 PM)C.Ret Wrote:  I'm a little surprised to read that there is no way on the 42S to put four complex numbers in the stack [...] Really, there's no other way than to use a 27-lines program to fill the stack with complex entries?

Of course there is ! Matter of fact you need no program to do it, that's just Mr. Weber doing his thing ...

From the keyboard, do this to enter 1+2i, 3+4i, 5+6i and 7+8i into the RPN stack:
    1, ENTER, 2, COMPLEX, STO A {... or any other variable}
    3, ENTER, 4, COMPLEX,
    5, ENTER, 6, COMPLEX,
    7, ENTER, 8, COMPLEX, RCL A, Rdown

... and there you are, simple and effortless.

Regards.
V.
Hi Valentin,

I thought we were on a first name basis, did I do anything wrong to deserve to be back to "Mr. Weber"? Smile

As for me "doing my thing", may I remind you that the challenge I set to myself (admittedly quite futile), was precisely NOT to use an intermediate variable, but to do it directly, which my program does.

I thought you yourself were regretting that entering 4 numbers on the stack was not as straightforward as on the 15C...

Also, my program, as I stated, allows you to mess up with the stack as much as you want between 2 entries, so that the complex numbers can be computed rather than just entered. I thought this was kind of convenient.

Best regards,

Vincent
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: