Complex calculations using complex stack and implicit entry

Post Reply
User avatar
RJvM
Posts: 276
Joined: Wed Jun 02, 2021 9:21 am
Location: Gelderland, Netherlands

Complex calculations using complex stack and implicit entry

Post by RJvM »

I have developed a set of routines for complex calculations using a complex stack and implicit data entry. This was purely meant for entertainment, as there are various well known (ROM) alternatives. However, I have made an effort to make it as user friendly as possible, I think it certainly is more convenient than the equivalent operations on the DM42 (which I have used to verify my calculations). I have been working on this as a pet project since I received my machine about a month ago.

Basis operations go like this:

a ENTER b "INPX" (push on complex stack, assigned to shift ENTER); c ENTER d, followed by any function defined for the complex calculations, e.g.
2 ENTER 3 INPX 4 ENTER 5 INPX C+ (complex addition) => 6 + 8J is displayed

(user flag 1 set means "I" is used instead of "J"; user flag 3 means real numbers are displayed without imaginary part of 0)

The stack is implemented as a series of memory registers:
T: R18 + R19
Z: R16 + R17
Y: R14 + R15
X: R12 + R13
L: R10 + R11

Just like in the normal stack, there is no need to use INPX just before a unary or binary function. Even better (IMHO) there is no need to enter an imaginary part of zero if you just want to enter a real number (just make sure to make the next keystroke a function or INPX).

By starting "CPLX" the calculator is put in user mode and RADians, some initialisations are made.

The following (sub)routines are available:

CRND (key 11) rounds Re and Im
CABS (key -11) absolute value
CRCP (key 12) reciprocal value
CPWR (key -12) Y to the power of X
CSQRT (key 13) square root
CSQ (key -13) square
CLN (key 15) natural logarithm
CEXP (key -15) exp
CSIN (key 23) complex sine
CASIN (key -23) complex inverse sine
CCOS (key 24) complex cosine
CACOS (key -24) complex inverse sine
CTAN (key 25) complex tangent
CATAN (key-25) complex inverse tangent
CRE (key -33) real part
CIM (key -34) imaginary part
C- (key 51) subtract
C+ (key 61) add
C* (key 71) multiply
C/ (key 81) divide
CPI (key -82) enter pi as complex number (zero imaginary part)

INPX (key -41) Enter complex number (y => R12: Real, x => R13: Imaginary)
CSTO (key 33) Copy X to Storage register (R22 + R23)
CRCL (key 34) Push Storage register onto stack
CXY (key 21) X <> Y
CCLR (key -21) Clear (L, X, Y, Z, T, U (scratch), S (storage), RL (real last x), RS (real stack))
ROT- (key 22) Roll down complex stack
VSTK (key -22) View complex stack (L, X, Y, Z, T when flag 0 is nog set, L, X. Y, Z, T, U, S, RL, RS when flag 0 is set)
CCHS (key -42) CHS
CCLX (key -44) CLX (disables stack lift temporarily, as in regular calculations; as indicated by flag 2)
LX (key -83) Last X
VUX (key -84) View X (as the alpha register is used, this is sometimes needed to refresh the display)

STRS (key 14) set real stack (Y to y and X to x) and enter normal (not user) mode to continue regular calculations
GTRS (key -14) get real stack (x, y => x + iy in X)

I will post the source and raw file here, as well as a compact representation I made using Excel, color coded.

Should there be interest in more information on this implementation, I will put in some more time to document the algorithms I implemented.
The program makes use of a local program HYP containing the regular hyperbolic trig functions, used to implement complex trig; this is a separate raw file.
Attachments
hyp.raw
(221 Bytes) Downloaded 171 times
cplx.pdf
(65.77 KiB) Downloaded 196 times
cplx.raw
(1.73 KiB) Downloaded 179 times
Robbert Jan, MSEE, RPN user since 1976 and a collector for many years I now own all the important ones: HP-35, 45, 55, 65, 97, 19, 21, 25, 34, 10-16, 41, 42, 71, 48, 50, Prime, DM41, DM42, WP43, C47, R47; Project 47 team member https://47calc.com
User avatar
RJvM
Posts: 276
Joined: Wed Jun 02, 2021 9:21 am
Location: Gelderland, Netherlands

Re: Complex calculations using complex stack and implicit entry

Post by RJvM »

Some additional information
Attachments
cplx-registers and flags.pdf
(38.46 KiB) Downloaded 194 times
hyp.pdf
(28.9 KiB) Downloaded 196 times
Robbert Jan, MSEE, RPN user since 1976 and a collector for many years I now own all the important ones: HP-35, 45, 55, 65, 97, 19, 21, 25, 34, 10-16, 41, 42, 71, 48, 50, Prime, DM41, DM42, WP43, C47, R47; Project 47 team member https://47calc.com
User avatar
RJvM
Posts: 276
Joined: Wed Jun 02, 2021 9:21 am
Location: Gelderland, Netherlands

Re: Complex calculations using complex stack and implicit entry

Post by RJvM »

Of course, the example should be:

2 ENTER 3 INPX 4 ENTER 5 C+ (complex addition) => 6 + 8J is displayed
Robbert Jan, MSEE, RPN user since 1976 and a collector for many years I now own all the important ones: HP-35, 45, 55, 65, 97, 19, 21, 25, 34, 10-16, 41, 42, 71, 48, 50, Prime, DM41, DM42, WP43, C47, R47; Project 47 team member https://47calc.com
User avatar
RJvM
Posts: 276
Joined: Wed Jun 02, 2021 9:21 am
Location: Gelderland, Netherlands

Re: Complex calculations using complex stack and implicit entry

Post by RJvM »

Set SIZE to 28
Robbert Jan, MSEE, RPN user since 1976 and a collector for many years I now own all the important ones: HP-35, 45, 55, 65, 97, 19, 21, 25, 34, 10-16, 41, 42, 71, 48, 50, Prime, DM41, DM42, WP43, C47, R47; Project 47 team member https://47calc.com
User avatar
RJvM
Posts: 276
Joined: Wed Jun 02, 2021 9:21 am
Location: Gelderland, Netherlands

Re: Complex calculations using complex stack and implicit entry

Post by RJvM »

Correction:
STRS puts real part of X into y and imaginary part into x; abs of complex last X into regular last x... It also restored the previous values of the regular stack's x and y to z resp. t...
Robbert Jan, MSEE, RPN user since 1976 and a collector for many years I now own all the important ones: HP-35, 45, 55, 65, 97, 19, 21, 25, 34, 10-16, 41, 42, 71, 48, 50, Prime, DM41, DM42, WP43, C47, R47; Project 47 team member https://47calc.com
User avatar
RJvM
Posts: 276
Joined: Wed Jun 02, 2021 9:21 am
Location: Gelderland, Netherlands

Re: Complex calculations using complex stack and implicit entry

Post by RJvM »

Some addition functions can be accessed best via the custom menu, as shown in this bitmap:

CPLX - start CPLX
R<>I - exchange real and imaginary part of complex number
CCNJ - conjugate
CDOT - dot product
CCRS - cross product
CABS - absolute value (modulus)
CARG - argument (angle - radians)
CRCT - convert (X: angle, Y:modulus) to rectangular form in X
Attachments
Custom menu (cplx).bmp
Custom menu (cplx).bmp (12.31 KiB) Viewed 4235 times
Robbert Jan, MSEE, RPN user since 1976 and a collector for many years I now own all the important ones: HP-35, 45, 55, 65, 97, 19, 21, 25, 34, 10-16, 41, 42, 71, 48, 50, Prime, DM41, DM42, WP43, C47, R47; Project 47 team member https://47calc.com
Post Reply