Post Reply 
Which systems support a COMPLEX data type?
07-11-2023, 09:42 AM
Post: #1
Which systems support a COMPLEX data type?
Which calculators or computers and computer languages support the Complex type?

(Here, I define "support" as a notation like C1=C2*C3, not by specific functions like C1=CPXMUL(C2,C3), and also including common trig and log functions)

I am aware of
  • HP 15C
  • HP32S, HP32SII
  • HP35S
  • HP42S
  • HP 71B Math ROM / BASIC
  • HP RPL in the HP 48/49 family
  • Fortran
  • HP 9000/200/300 Basic 5.x
  • C++ can model a Complex type (with operator overloading, so any language with operator overloading should be able to model it, bot it is not built into the language)
  • Some CASIO calculators, as discussed here.

I am sure there are a few more.

Martin
Find all posts by this user
Quote this message in a reply
07-11-2023, 09:50 AM
Post: #2
RE: Which systems support a COMPLEX data type?
Hello,

I Think also TI-85, TI-86, TI-89, TI-92, Voyage 200
Find all posts by this user
Quote this message in a reply
07-11-2023, 11:36 AM
Post: #3
RE: Which systems support a COMPLEX data type?
Julia. Also the HP Prime, and numerous math-oriented languages (Mathematica, Maple, Pari/GP, etc.).
Find all posts by this user
Quote this message in a reply
07-11-2023, 11:40 AM
Post: #4
RE: Which systems support a COMPLEX data type?
The HP-33S also supports COMPLEX operations, similar to the 32S/32SII/35S.

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
07-11-2023, 01:11 PM
Post: #5
RE: Which systems support a COMPLEX data type?
  • HP 75C/D Math ROM / BASIC
Find all posts by this user
Quote this message in a reply
07-11-2023, 01:26 PM
Post: #6
RE: Which systems support a COMPLEX data type?
I think it may be worth noting 'how' each of the machines support the complex data type.

Certainly on one end of the spectrum is the 'simulating type' - such as C1=CPXMUL(C2,C3); and on the other end of the spectrum is the manner in which the HP48 and HP42 handle it - ie one complex value is one stack item.

Somewhere between these two is the manner in which the HP15C handles it - using two stack locations for the real and imaginary components. Others (32, 35s...) may be of this type too; I have not studied them.

I don't mean to nitpick here, but these machine mechanisms are very different and hence algorithm usage would be very different.

Thank you,
TomC

(07-11-2023 09:42 AM)Martin Hepperle Wrote:  Which calculators or computers and computer languages support the Complex type?

(Here, I define "support" as a notation like C1=C2*C3, not by specific functions like C1=CPXMUL(C2,C3), and also including common trig and log functions)

I am aware of
  • HP 15C
  • HP32S, HP32SII
  • HP35S
  • HP42S
  • HP 71B Math ROM / BASIC
  • HP RPL in the HP 48/49 family
  • Fortran
  • HP 9000/200/300 Basic 5.x
  • C++ can model a Complex type (with operator overloading, so any language with operator overloading should be able to model it, bot it is not built into the language)
  • Some CASIO calculators, as discussed here.

I am sure there are a few more.

Martin
Find all posts by this user
Quote this message in a reply
07-11-2023, 02:31 PM (This post was last modified: 07-11-2023 02:32 PM by Martin Hepperle.)
Post: #7
RE: Which systems support a COMPLEX data type?
(07-11-2023 01:26 PM)TomC Wrote:  I think it may be worth noting 'how' each of the machines support the complex data type.

Certainly on one end of the spectrum is the 'simulating type' - such as C1=CPXMUL(C2,C3); and on the other end of the spectrum is the manner in which the HP48 and HP42 handle it - ie one complex value is one stack item.

Somewhere between these two is the manner in which the HP15C handles it - using two stack locations for the real and imaginary components. Others (32, 35s...) may be of this type too; I have not studied them.

I don't mean to nitpick here, but these machine mechanisms are very different and hence algorithm usage would be very different.

Thank you,
TomC

What I had in mind was a specific type for Complex variables. So maybe the 15C was not a good example.
For example The 33S and 35S show on a single stack level something like 12.5i6 and one can apply the SIN key directly to this value.

In a program this would simply require replacing REAL variables with COMPLEX variables, otherwise the program should be the same.

Martin
Find all posts by this user
Quote this message in a reply
07-11-2023, 04:46 PM
Post: #8
RE: Which systems support a COMPLEX data type?
Hello!

(07-11-2023 09:42 AM)Martin Hepperle Wrote:  [*]HP 9000/200/300 Basic 5.x

Descendants of Rocky Mountain Baisc (which I had the pleasure to use on HP unix workstations in the late 1980ies/early 1990ies) still exist to this day for Linux and Windows, e.g. HTBasic which can be bought here: https://www.techsoft.de/index.html Regarding the cost I have no idea, but like everything that originally came from HP it will be crazy expensive.

But what a nice way that was to control all your test equipment, download huge amounts of data and process them on the go. All done with very little programming effort, just a few lines of simple code. Complex numbers, matrices, fourier transforms - all available with a single basic keyword. Try that with Python...

Regards
Max
Find all posts by this user
Quote this message in a reply
07-11-2023, 05:54 PM
Post: #9
RE: Which systems support a COMPLEX data type?
C99 adds support for complex numbers to the C language.
Find all posts by this user
Quote this message in a reply
07-11-2023, 07:26 PM
Post: #10
RE: Which systems support a COMPLEX data type?
(07-11-2023 09:42 AM)Martin Hepperle Wrote:  Which calculators or computers and computer languages support the Complex type?
I am aware of
  • C++ can model a Complex type (with operator overloading, so any language with operator overloading should be able to model it, bot it is not built into the language)

It is not quite accurate to state "can model" because the complex type is built into C and C++. C supports built-in complex types with _Complex float and _Complex double already since ISO C99 (!). C++ just uses the underlying _Complex type of C99, which is also still useable as-is in C++. The difference is how complex functions are used in C++ with complex-typed arguments. The C++ std::complex templates and associated trig functions can be imported with #include <complex> for std::complex<float>, std::complex<double> and std::complex<long double>.

Python has complex types, though complex functions require importing cmath. A complex constant is written as a built-in constant with imaginary part denoted by suffix j or with constructor Complex(re,im). For example
import cmath
cmath.sin(1j)
cmath.sin(Complex(0,1))

Ruby has a built-in Complex class and associated methods to invoke trig etc.

Common Lips has built-in complex functions and constants denoted with #C().

Heck, even Visual Basic has complex numbers! Like z = Complex(Of Double).Log10(z) which requires Dim z As New Complex(Of Double)(2, 4)

And the list of programming languages goes on and on...

- Rob

"I count on old friends to remain rational"
Visit this user's website Find all posts by this user
Quote this message in a reply
07-11-2023, 08:45 PM
Post: #11
RE: Which systems support a COMPLEX data type?
PL/1 has/had a COMPLEX type, so I assume the operators are overloaded.
Find all posts by this user
Quote this message in a reply
07-12-2023, 02:19 AM
Post: #12
RE: Which systems support a COMPLEX data type?
The hp-28 (c/s) deserves to be included in the list by name. Wink

The R programming language has a complex type too, in addition to integer and double types.

Bruno
Sanyo CZ-0124 ⋅ TI-57 ⋅ HP-15C ⋅ Canon X-07 + XP-140 Monitor Card ⋅ HP-41CX ⋅ HP-28S ⋅ HP-50G ⋅ HP-50G
Find all posts by this user
Quote this message in a reply
07-12-2023, 07:52 AM (This post was last modified: 07-12-2023 09:21 AM by Martin Hepperle.)
Post: #13
RE: Which systems support a COMPLEX data type?
Thank you - there are quite a few languages which support the complex type more or less well.

The reason why I was asking this question was linked to determining the derivative of functions with a higher degree of accuracy than using common difference schemes (centered, forward, higher order, ...). In the real world you often have a numerical function which has to be evaluated with REAL parameters, but you also sometimes need its derivative which is generally not available in analytical form.

Using complex variables is a very elegant way to achieve an very accurate result close to machine accuracy.
Ideally, this would only require replacing type definitions like REAL by COMPLEX and no further change (or even no modification, as in RPL).

In some languages like HP BASIC or Fortran, I can simply change the type from REAL to COMPLEX and no additional code changes are required. In some of the other languages more code changes are required. Languages like RPL, which detect which type of object is passed to a function, automatically call the proper function e.g. sin(REAL) or sin(COMPLEX).

Example
Determine numerically the derivative of the function 'sin(3*x)*log(x)' at x=0.7.
A finite difference approach like (f(x+h)-f(x-h))/(2*h) is not very accurate on a machine with, say, 15 relevant digits.

Example in RPL (e.g. HP 49G)
(note that there is no need to change the function 'F', it accepts its parameter either REAL or COMPLEX type)

Function f(x) to be evaluated, can be called with either a real or a complex parameter. No modification required.
Code:
<< 3 * SIN SWAP LOG * >> 'F' STO

General differentiation program calls 'F' with complex parameter, step size 1E-15. Of course, 'F' could also be supplied as a parameter on the stack.
Code:
<< (0.,1E-15) + F IM 1E-15 / >> 'DIFF' STO

Execute DIFF, leaves derivative of f(0.7):
Code:
0.7 DIFF


Example in Python
(less elegant than RPL)

Code:
# actually replaces all occurrences of sin and log by their COMPLEX counterpart. 
# It is not possible to use the REAL sin and log functions in a simple notation.

from cmath import sin, log

# here sin and log are (not visible) replaced by the corresponding cmath functions, 
# even if this function is called with REAL parameter x it returns a COMPLEX type.
def f(x):
    return sin(3*x)*log(x)

# determining the derivative at x=0.7
# step size
h = 1E-15
z = complex(0.7,h)
diff = f(z) / h
print('f\'(%.6f) = %.15f' % (z.real, diff.imag))
# prints
# f'(0.700000) = 1.773354106237344

Martin
Find all posts by this user
Quote this message in a reply
07-12-2023, 04:16 PM
Post: #14
RE: Which systems support a COMPLEX data type?
(07-12-2023 07:52 AM)Martin Hepperle Wrote:  The reason why I was asking this question was linked to determining the derivative of functions with a higher degree of accuracy than using common difference schemes (centered, forward, higher order, ...). In the real world you often have a numerical function which has to be evaluated with REAL parameters, but you also sometimes need its derivative which is generally not available in analytical form.

Using complex variables is a very elegant way to achieve an very accurate result close to machine accuracy.
[...]

See also this thread on the HP forums: https://www.hpmuseum.org/forum/thread-18482.html

The subject has been presented and discussed elsewhere before on the web, see e.g.

How to Differentiate with a Computer

Dual Numbers & Automatic Differentiation

Automatic differentiation (AD) of program code is interesting. Decades ago I redid the work of ADIFOR in a symbolic CAS-like system I called "Ctadel" to add forward and reverse AD to generate forward differentiated and adjoint Fortran code. The ADIFOR 1996 article is a good read: https://ieeexplore.ieee.org/abstract/doc...eryWjbG4vA

- Rob

"I count on old friends to remain rational"
Visit this user's website Find all posts by this user
Quote this message in a reply
07-13-2023, 07:00 AM
Post: #15
RE: Which systems support a COMPLEX data type?
Rob,

thank you for the links - I had searched this forum for "Derivative" "Complex" etc. but did not find the related thread. Excellent!.

Martin
Find all posts by this user
Quote this message in a reply
07-14-2023, 12:27 AM
Post: #16
RE: Which systems support a COMPLEX data type?
Here‘s another link you might be interested in: Derivatives on HP 42S
It uses the complex-variable method you mentioned.
Find all posts by this user
Quote this message in a reply
07-14-2023, 01:15 PM (This post was last modified: 07-14-2023 01:16 PM by johnb.)
Post: #17
RE: Which systems support a COMPLEX data type?
(07-12-2023 07:52 AM)Martin Hepperle Wrote:  Thank you - there are quite a few languages which support the complex type more or less well.

Agreed.

In fact, any language that supports basic math functions, user libraries of some type, and some type of struct or record variable can model complex numbers. This includes practically every object-oriented language.

i.e. using only the above, I can do it in C, C++, C#, Smalltalk, Java, Javascript, Ruby, Perl... the list is so long it might be better to try to figure out which languages I can't do it in.

So I think for your list, you should only take languages that support Complex-typed variables natively without having to add on any kind of library.

Just my $0.02 worth.

Daily drivers: 15c, 32sII, 35s, 41cx, 48g, WP 34s/31s. Favorite: 16c.
Latest: 15ce, 48s, 50g. Gateway drug: 28s found in yard sale ~2009.
Find all posts by this user
Quote this message in a reply
07-14-2023, 02:55 PM
Post: #18
RE: Which systems support a COMPLEX data type?
(07-14-2023 01:15 PM)johnb Wrote:  
(07-12-2023 07:52 AM)Martin Hepperle Wrote:  Thank you - there are quite a few languages which support the complex type more or less well.

Agreed.

In fact, any language that supports basic math functions, user libraries of some type, and
Just my $0.02 worth.

The criteria was: "(Here, I define "support" as a notation like C1=C2*C3, not by specific functions like C1=CPXMUL(C2,C3), and also including common trig and log functions)"

Before C99 C could not do complex operations via operators. And even now, I don't know if the library can handle complex trig functions.
Find all posts by this user
Quote this message in a reply
07-14-2023, 04:02 PM
Post: #19
RE: Which systems support a COMPLEX data type?
(07-14-2023 02:55 PM)KeithB Wrote:  
(07-14-2023 01:15 PM)johnb Wrote:  Agreed.

In fact, any language that supports basic math functions, user libraries of some type, and
Just my $0.02 worth.

The criteria was: "(Here, I define "support" as a notation like C1=C2*C3, not by specific functions like C1=CPXMUL(C2,C3), and also including common trig and log functions)"

Before C99 C could not do complex operations via operators. And even now, I don't know if the library can handle complex trig functions.

Sure it does https://en.wikipedia.org/wiki/C_mathemat...#complex.h

C99 standardized complex types and functions. Before C99 it was a non-standard extension supported by various compilers. That's how standards come about, usually.

A header file complex.h is included to declare the types and the explicit intent to use complex functions in your code, which is always nice to tell the world what you're doing. You can use _Complex_I for the imaginary unit, e.g. 1 + 2*_Complex_I. In case that's too verbose, just #define I _Complex_I or if you're an engineer Big Grin then #define J _Complex_I or something like that.

Complex arithmetic in C is performed with the standard arithmetic operators, because the complex type is a built-in type, just like float and double. Complex arithmetic in C does not require a library call, neither in the source code nor in the generated MC that just operates on floating pointer registers.

- Rob

PS. The HP Forums are great! Don't take this as crude or offense, just a bit of poking, but sometimes I feel there is a slight tendency for wishful thinking we still live in the 70s: time for everything else has stood still and can be ignored except for HP calculators Smile

"I count on old friends to remain rational"
Visit this user's website Find all posts by this user
Quote this message in a reply
07-19-2023, 12:03 AM
Post: #20
RE: Which systems support a COMPLEX data type?
(07-14-2023 02:55 PM)KeithB Wrote:  
(07-14-2023 01:15 PM)johnb Wrote:  In fact, any language that supports basic math functions, user libraries of some type, and...
Just my $0.02 worth.

The criteria was: "(Here, I define "support" as a notation like C1=C2*C3, not by specific functions like C1=CPXMUL(C2,C3), and also including common trig and log functions)"

But you left off the most important part of the quote...
(07-14-2023 01:15 PM)johnb Wrote:  So I think for your list, you should only take languages that support Complex-typed variables natively without having to add on any kind of library.

I think you and I were making, well... if not the same point then certainly similar or related points.

Daily drivers: 15c, 32sII, 35s, 41cx, 48g, WP 34s/31s. Favorite: 16c.
Latest: 15ce, 48s, 50g. Gateway drug: 28s found in yard sale ~2009.
Find all posts by this user
Quote this message in a reply
Post Reply 




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