# Complex Arithmetic in SysRPL - Hewlett Packard

This is a discussion on Complex Arithmetic in SysRPL - Hewlett Packard ; I have reviewed the brief text and the less brief tables in Kalinowski and Dominik with some interest, and I have to tell you that I can't seem to find out the syntax for the most basic of operations--binary arithmetical ...

# Thread: Complex Arithmetic in SysRPL

1. ## Complex Arithmetic in SysRPL

I have reviewed the brief text and the less brief tables in Kalinowski
and Dominik with some interest, and I have to tell you that I can't
seem to find out the syntax for the most basic of operations--binary
arithmetical manipulations of complex numbers.

There seems to be no such thing as C%+, C%-, C%*, or C%. But we seem
to have C%SQRT, C%LN, C%COS, etc, which I have demonstrated to myself
work as you would expect.

For example, this little snippet (within a properly delimited program,
of course) will compile:

C% 2 7 C% 6 8 %+

but it seems only the real parts are added, and 8 is what is returned.

Does SysRPL expect one to decompose every complex number to Re and Im
parts and add (or subtract) each separately and then use %>C% to
recreate a complex number? That is feasible (though cumbersome). Even
more cumbersome is multiplication and division.

I just find it peculiar that there exist functions to raise complex
numbers to real or complex powers, compute trigonometrics, and take
square roots or reciprocals, but no clearly documented easy way to
carry out basic arithmetic.

What am I missing here? And if you can point me to the page reference
in Kalinowski and Dominik, I would be a little sheepish but very
grateful.

I would like to eventually work with long complex numbers--a
potentially challenging undertaking since the repertoire of math
commands for them is much smaller than that for regular complex
numbers--but if I can't figure out how to program basic arithmetic and
am sort of stuck!

TIA for any direction and your boundless patience.

Les

2. ## Re: Complex Arithmetic in SysRPL

"lcw1964" schrieb im Newsbeitrag
>I have reviewed the brief text and the less brief tables in Kalinowski
> and Dominik with some interest, and I have to tell you that I can't
> seem to find out the syntax for the most basic of operations--binary
> arithmetical manipulations of complex numbers.
>
> There seems to be no such thing as C%+, C%-, C%*, or C%.
>

Of course there are functions for complex arithmetic.
C%C*C
C%C/C
C%C+C
C%C-C

and even
C%C*R
C%C/R
C%C+R
C%C-R

Internally they decompose the complex numbers
and recompose them after the operation.
However that doesn't matter for the user...

HTH

Raymond

3. ## Re: Complex Arithmetic in SysRPL

On Jun 16, 7:09 pm, "Raymond Del Tondo" wrote:
>
> Of course there are functions for complex arithmetic.
> C%C*C
> C%C/C
> C%C+C
> C%C-C
>
> and even
> C%C*R
> C%C/R
> C%C+R
> C%C-R
>

Raymond, I tried the first four, and can't seem to get the program to
compile. ER in the MASD claims the label doesn't exist. I didn't
bother trying the last four. Moreover, a full text search of the
Kalinowski and Dominik PDF makes no mention of any of those commands.

Could they be part of a later enhancement to SysRPL? Do I possible
have an out of date extable? I am testing my code on the EMU50
emulator that comes with Debug4x, though I am not working in Debug4x,
but rather right in the emulator.

I have found that I can always resort to x+, x-, x*, x/, etc., but the
point of Sys
RPL is to always to use the faster native commands if possible.

If I have my heart set on doing full math internally with long complex
numbers (real and imaginary parts are extended reals, I may have to
write my own routines from scratch anyway! Here's to reviewing high
school math....

Many thanks,

Les

4. ## Re: Complex Arithmetic in SysRPL

On Jun 16, 7:24 pm, lcw1964 wrote:

> Could they be part of a later enhancement to SysRPL? Do I possible
> have an out of date extable?

I have found and attached Thomas Rast's extable2, which is a bit more
recent (it comes with emacs211a at hpcalc.org), but I still can't seem
to use the commands you mention!

I guess I will resort to x+, x*, x-, etc for now until I find out what
is going on.

Les

5. ## Re: Complex Arithmetic in SysRPL

Hi Les,

"lcw1964" schrieb im Newsbeitrag
> On Jun 16, 7:09 pm, "Raymond Del Tondo" wrote:
>>
>> Of course there are functions for complex arithmetic.
>> C%C*C , C%C/C , C%C+C , C%C-C
>> and even
>> C%C*R , C%C/R , C%C+R , C%C-R

>
> Could they be part of a later enhancement to SysRPL? Do I possible
> have an out of date extable? I am testing my code on the EMU50
> emulator that comes with Debug4x, though I am not working in Debug4x,
> but rather right in the emulator.
>

Actually these functions were there even in the HP-28 C/S ROM,
but unfortunately not in the supported entries list;-)

> I have found that I can always resort to x+, x-, x*, x/, etc., but the
> point of Sys
> RPL is to always to use the faster native commands if possible.
>

So here's a possible way to go:
If the basic arith. functions for complex numbers aren't directly
supported in the machines after the HP-48,
you could still analyze the object type dispatcher
of the supported arith. functions, like +,-,*,/ .
For two complex numbers, the dispatchee will be the wanted function;-)

The functions with one single '%' are for 12-digit rounding.

However, at least in the HP-48 there are also routines using full precision:
C%%C*R , C%%C*C , C%%C/C, etc...

Regards

Raymond

6. ## Re: Complex Arithmetic in SysRPL

On Jun 16, 8:51 pm, "Raymond Del Tondo" wrote:
>
> However, at least in the HP-48 there are also routines using full precision:
> C%%C*R , C%%C*C , C%%C/C, etc...

I am working with 49G+. I downloaded the FIRST edition of Kalinowski
and, sure enough, all of those C%%C functions are listed. And the book
seems better laid out too!

I have found a massive and much more recent document at hpcalc.org
called the HP49 Entry Reference, edition 2.11. Sure enough, all of the
full precision complex commands you mention are in there, with their

7. ## Re: Complex Arithmetic in SysRPL

On Jun 16, 10:04 pm, lcw1964 wrote:
>
> I have found a massive and much more recent document at hpcalc.org
> called the HP49 Entry Reference, edition 2.11. Sure enough, all of the
> full precision complex commands you mention are in there, with their

Actually, I was mistaken! The list I was looking at was the first
edition Kalinowski, for the HP48.

I can't find any basic complex arithmetic commands in the the HP49
Entry Reference. Indeed, the list of complex functions on the HP49
seems shorter, and that in the Entry Reference doesn't seem much
different from the 2nd edition of Kalinowski and Dominik.

Why on earth such important functionality in the SysRPL language would
be removed from the HP49/49+/50 version escapes me. Does anyone out
there know why?

In the meantime, I will use regular complex numbers and UserRPL
+,-,*, /, etc until I get a more sophisticated handle on SysRPL.

Les

8. ## Re: Complex Arithmetic in SysRPL

PS. The functions that interest me are listed in parentheses in the
Kalinowski, edition 1, which means that even on the HP48 they were
considered "unsupported entries". Maybe they didn't survive the move
to the HP49?

9. ## Re: Complex Arithmetic in SysRPL

Hello,

well, if they are not supported this either means that they are not in
the 49G but if they are there it also means that their address will
change with every ROM-Version. You should not rely on unsupported
pointers for this obvious reason.

Anyhow, as Raymond pointed out take a look how it is done through the
USER-RPL function.

Here is some code from x+ for example:

::
CK2&Dispatch
2REAL
%+
#FFFF_
BINT18
::
C%>%
3UNROLL
%+SWAP
%>C%
;
BINT33
::
SWAP
::
C%>%
3UNROLL
%+SWAP
%>C%
;
;

* This is the code that internally adds two complex numbers,
BINT34
::
::
C%>%
ROT
C%>%
;
ROT
%+
3UNROLL
%+SWAP
%>C%
;

( more code from x+ )
;

So the complex numbers are internally decomposed to to Re and Im
parts.

> That is feasible (though cumbersome). Even
> more cumbersome is multiplication and division.

Just look for the code in the basic arithmetic function in the ROM and
there you go.

Greetings
Andreas
www.software49g.gmxhome.de

10. ## Re: Complex Arithmetic in SysRPL

On Sat, 16 Jun 2007 19:08:43 -0500:

> I have found and attached Thomas Rast's extable2, which is a bit more
> recent (it comes with emacs211a at hpcalc.org), but I still can't seem
> to use the commands you mention!

It's possible that the ROM area handling these commands in 49 series
might be identical (except for relocation of the entire area)
to the same area in 48 series,
locations of which are all listed in Mika Heiskanen's Ent_Srt.doc
(perhaps also in Entries.all); if so, then these might turn out to be
"unsupported but stable." I leave it to someone else to research further.

A snippet from Ent_Srt.doc (original HP*48* only);
the names of "unsupported" functions,
while "supported" functions are listed without addresses:

7.4 Real & Complex Functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%+ 51C16 C%C+C 51BD0 C%C+R 51BF8 C%R+C
%%+ 51C3E C%%C+C 51C9D C%%C+R 51CB1 C%%R+C
%- 51CFC C%C-C 51CE8 C%C-R 51CD4 C%R-C
%%- 51D10 C%%C-C 51D38 C%%C-R 51D24 C%%R-C
%* 51D88 C%C*C 51D4C C%C*R 51D60 C%R*C
%%* 51DE2 C%%C*C 51DAB C%%C*R 51DBF C%%R*C
%/ 51EC8 C%C/C 51E64 C%C/R 51E19 C%R/C
%%/ 51F13 C%%C/C 51F7C C%%C/R 51F3B C%%R/C
%^ C%C^C C%C^R C%R^C
%%^

Corresponding snippet from Entries.all (original HP*48* only):

51C3E :: NS:C%%C+C
51C3E @ Internal + (2:C%%1:C%%)
51C6B :: NS:SWAP2C%>%
51C6B @ (2:C%2 1:C%1 -> 4:%re1 3:%im1 2:%re2 1:%re1)
51C84 :: NS:SWAP2C%%>%%
51C84 @ (2:C%%2 1:C%%1 -> 4:%%re1 3:%%im1 2:%%re2 1:%%re1)
51C9D :: NS:C%%C+R
51CB1 :: NS:C%%R+C
51CD4 :: NS:C%R-C
51CE8 :: NS:C%C-R
51CFC :: NS:C%C-C
51D10 :: NS:C%%C-C
51D24 :: NS:C%%R-C
51D38 :: NS:C%%C-R
51D4C :: NS:C%C-R
51D60 :: NS:C%R*C
51D88 :: NS:C%C*C
51DAB :: NS:C%%C*R
51DBF :: NS:C%%R*C
51DE2 :: NS:C%%C*C

Complete documents:
http://www.hpcalc.org/search.php?query=ent_srt
http://www.hpcalc.org/search.php?query=entries.all

-[ ]-

11. ## Re: Complex Arithmetic in SysRPL

On Mon, 18 Jun 2007 16:19:40 -0500:

> A snippet from Ent_Srt.doc (original HP*48* only);
> note that numeric addresses *precede*
> the names of "unsupported" functions,
> while "supported" functions are listed without addresses:
>
> 7.4 Real & Complex Functions
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> %+ 51C16 C%C+C 51BD0 C%C+R 51BF8 C%R+C
> %%+ 51C3E C%%C+C 51C9D C%%C+R 51CB1 C%%R+C
> %- 51CFC C%C-C 51CE8 C%C-R 51CD4 C%R-C
> %%- 51D10 C%%C-C 51D38 C%%C-R 51D24 C%%R-C
> %* 51D88 C%C*C 51D4C C%C*R 51D60 C%R*C
> %%* 51DE2 C%%C*C 51DAB C%%C*R 51DBF C%%R*C
> %/ 51EC8 C%C/C 51E64 C%C/R 51E19 C%R/C
> %%/ 51F13 C%%C/C 51F7C C%%C/R 51F3B C%%R/C
> %^ C%C^C C%C^R C%R^C
> %%^

In my calc, those which have "series 48" addresses 51xxx
seem to correspond to "series 49" addresses that are lower by
the constant #41B1Eh, indicating an apparent match between
this particular region in the different series. For example,
C%%C-R is at #51D38h - #41B1Eh = #1021Ah in my calc,
where is found :: %%CHS PTR 1017F ;

Correspondingly, PTR 1017F (#1017Fh) plus #41B1Eh = #51C9Dh
which is C%%C+R in 48, where we have :: SWAP PTR 10193 ; in 49,
and :: SWAP PTR 51CB1 ; in 48 (#51CB1h-#10193h=#41B1Eh again), etc.

Although the "series 48" addresses were evidently stable,
it's entirely possible that this region isn't always
at the same base address in different "series 49" ROM versions;
would anyone else like to check that out and see?

As far as use of single-precision input, however,
one can always use something else; for example,
' x+ EvalNoCK accomplishes any of C%C+C or C%C+R or C%R+C
you can even use EvalNoCK: x+ to do the same.

Although entry point "EvalNoCK:" (saving 2.5 bytes per use)
is actually "unsupported" in both series,
it seems to be stable in each series anyway
(#25F29h in series 49, #18F6Ah in series 48)

As always, make some backups before using this at home,
or make profitable use of Emu48 instead

[r->] [OFF]

12. ## Re: Complex Arithmetic in SysRPL

On Sat, 16 Jun 2007 18:00:58 -0500, lcw1964 wrote:

> For example, this little snippet
> (within a properly delimited program, of course) will compile:
>
> C% 2 7 C% 6 8 %+
>
> but it seems only the real parts are added, and 8 is what is returned.

What do you expect when you use a function (%+) made only for reals
on the wrong object types?

The lucky fact that a "complex number object"
consists of one prolog followed by two real object bodies
is what produces the result you observed, without crashing.

At least you've found a shortcut for adding the real parts
of two complex numbers -- the corresponding trick,
using two C%% arguments and adding with %%+,
might also work, FWIW.

You can even "add" two strings, or almost any objects, using %+
(although the results will make no sense),
because any old sequence of bits can be "added"
and the results interpreted as a floating-point number.

It's nearly Summer in this hemisphere, anyway,
when many thoughts turn to just floating, pointlessly

[r->] [OFF]