Complex numbers - ideal display representation?



#2

A question for those who are hard-core complex number users. A simple question, hopefully there is a simple answer.

What is the ideal way to display complex numbers on the stack? If you could design the format for complex numbers display, how would you do it? Don't worry about any display size limitions or character sets. If you have an area 22 characters across and 4 lines deep to play with, what would be the perfect way of displaying a complex number?

Many thanks for ideas and suggestions here. As part of a program I am writing, I want to do something similar to "Pretty Print" for complex but not being a user of them, how I would display them could be a low-budget solution!

Thank you,

Mark


#3

this came up during the uWatch complex number feature. we had a 16 char line. the problem is that this is not enough to display all of both parts of the number. The same is the case for you with 22 (although it's nearly enough). so firstly, there needs to be a "show" button that shows all the digits. Since i had 2 lines, my show feature simply displays all of both parts, one on each line.

then there was the very good idea to use custom chars to create +i and -i characters, so that 1 character is saved on the line. There were also people who wanted "j" instead of "i". this was not implemented in the end, but was a good idea. You could do the same with exponents too if you get fancy.

then there's the problem of polar forms. if you support polar forms, how do you display them. i didn't, but we did think about it.

what happened in the end is that it tries to fit as much as possible in the space. when both parts are competing, i show more of the real part than the imaginary part. something like 8 vs 5 digits. Also, i implemented a tidier that tries to compact the string representation eg 0.1 -> .1 and 1.23e-07 -> 1.23e-7 and a few things like that. this only happens when you're short of space, because when you want to display the real number 0.123, it's nice to have the "0." for clarity.


#4

Thanks Hugh - you've already given me some good points for thought.

I was banking on using 2 lines so if I did it this way, some questions:

1. Should there be a comma between the parts at the end of line 1?

2. Are thousands separators useful?

3. For the i or j, should this be a prefix or suffix on the imaginary part?

4. Space character between the number and the i or j?

5. For polar mode, if I use an angle symbol (128 CHR on a 48), use this as a prefix and again, with or without space and the number?

6. Should the both parts be enclosed in one pair of brackets?

The starting format of the number will be the current mode the 48 is set to which determines various factors and there will be no interaction once the formatting is done as this is simply for display purposes only.

Thanks,

Mark


#5

If you're using two lines, then 22 chars per line ought to be plenty without any tricks. you're going to need a way to make this visually look like one result rather than two numbers on the stack. You might like to experiment with using "i" or "j" maybe with a leading space. However, i don't have an answer for what might look best on two lines.

As Raymund has pointed out there's also the (a,b) format. I didnt use this on a single line since the brackets take up space, but on two lines, maybe it works.

#6

Quote:
1. Should there be a comma between the parts at the end of line 1?

No.

Quote:
2. Are thousands separators useful?

I like them, some may not. Can't it be left as a personal choice?

Quote:
3. For the i or j, should this be a prefix or suffix on the imaginary part?

Prefix.

Quote:

4. Space character between the number and the i or j?


Hmmm. 1.2345 + i6.7890 or 1.2345 + i 6.7890. Nah, no space necessary.

Quote:
5. For polar mode, if I use an angle symbol (128 CHR on a 48), use this as a prefix and again, with or without space and the number?

Yes prefix. No space.

Quote:
6. Should the both parts be enclosed in one pair of brackets?

If you are going to use two lines, I guess you need to somehow identify that the two lines represent a complex number. I loathe the brackets or parentheses or whatever that the 48/49/50 insist on putting around complex values. Maybe indent the bottom line (imaginary part or angle) one space from the top line (real or magnitude.) That, plus the "i" or angle symbol on the bottom line should sufficiently identify the two values as a single complex number.

Just my two cents. For numerous posts on how complex numbers should be entered, displayed, and in general handled by the "perfect" calculator, search the archives for posts by me and/or Karl Schneider. (for example, here and here.)

edited to add links to previous threads


Edited: 7 Aug 2009, 8:35 a.m. after one or more responses were posted


#7

I agree with Jeff on most points. Differences:

Quote:
4. Space character between the number and the i or j?

I vote for a multiplication sign: 1,2345 + i*6,7890 or the same with "j".

Quote:
6. Should the both parts be enclosed in one pair of brackets?

No brackets. Indentation plus "i" will do.

My 0,02 Euros only.

#8

The HP71B with Math-Pac display complex nummers like (123,456).
Furthermore FIX/SCI/ENG modi are supported.
So i:=3.1415, j:= 2.5 in SCI 2 results in (3.14E0,2.5E0).
Also entering complex values is possible in the form (i,j).

BR

Raymund

#9

I use complex numbers a lot. A couple of points:

The use of 'i' and 'j' in complex numbers is not the same as it is in vectors. In vectors the 'i' unit vector is the vector of unit length and 0 degrees. The j vector is a vector of unit length and 90 counterclockwise degrees. The 'k' vector is unit length at 90 degrees to the plane formed by 'i' and 'j' vectors.

For complex numbers, both 'i' and 'j' are unit length at 90 degrees. Mathematicians use 'i' and electrical engineers use 'j' because the letter 'i' is used for current flow.

You mentioned pretty print which would require the format a + ib (or a +jb for electrical engineers). If polar form is to be included it should be a/_30 where the /_ is the angle sign (alpha-shift-6 on the HP49G for example.

The 42S (as in Free42) uses about as the best implementation for a scientific. The 48G through 50G calcs have the overall best. (My opinion)

My $3.50 worth (that's 2 cents with inflation.)

John

#10

Here's an idea that I haven't seen mentioned.

Think of the display as a window into the real and imaginary parts of 4 numbers. So normally, it shows the real part of 4 numbers. Press a button and it shows the corresponding imaginary parts of the numbers. Press the button again and it toggles back to the real part.

In other words, the way to efficiently show complex numbers is: "DON'T". :) Instead let the user toggle back and forth between the real and complex parts.

You could use a single character on each line to indicate that there is a complex part of the number. This would serve as a hint to the user. You'd also need an indicator to tell whether the display is currently showing the real or complex part of each number.

This doesn't help with polar representation much. I suppose you could have the display toggle between angle and magnitude, but that might be awkward.

This *does* solve the problem of using "i" vs "j" for the imaginary part since you don't need to show either. Perhaps the real/imaginary indicator could show "i" or "j" depending on the user's preference.

Dave


#11

Quote:
Think of the display as a window into the real and imaginary parts of 4 numbers. So normally, it shows the real part of 4 numbers. Press a button and it shows the corresponding imaginary parts of the numbers. Press the button again and it toggles back to the real part.

In fact, it's wasteful of display space to show the entire real part or entire imaginary part at once. If the precision is 12 digits, you could use a key to switch between the leftmost six digits and the right most six digits of each part.

Obviously I'm being facetious to make a point, though the Casio Mini, introduced in 1972, did exactly what I've described.

If I've got a complex number in the stack, I want to see all of it, even if that means that by default I see fewer decimal places. I don't want the imaginary part to be hidden, because that might mislead me into thinking that it is a real number.

#12

After reading this thread it should be apparent that there is no single ideal. If you are going to implement something on something, then I'd suggest that you support 2 or 3 of the most popular and allow the user to select. You may also need sub options, e.g. I want 'i', not 'j'. For the advanced user perhaps you can allow them to store a printf/scanf format string. For me flexibility is ideal.

I suppose your next question would be, "what is the ideal way to input complex numbers?"


#13

Thank you everyone for your input - all very useful and has given me far more insight into what people want than I would have deduced myself.

One thing I perhaps ought to clarify is that this requirement is for output only. I may not have made this clear in my original post. The intention is to display a complex number in a format that is technically correct, "textbook" style and independent of the format used for entering the values. Originally, I wasn't going to support complex numbers in the program but as the method of display used in the RPL calcs is more of a generic number pair display, I decided to include it and the code overhead isn't going to be too heavy.

Thanks again for all the help and suggestions.

Mark

#14

Mark --

Quite a bit of input here. Like John and Jeff, I am a power-system engineer who uses complex numbers routinely. Here is an archived post of mine:

http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv014.cgi?read=63415#63415

The HP-42S, in my view, offers the ideal representation of complex-valued numbers. It also has two lines and the ability to display 22 digits per line. Complete, rounded complex numbers can be displayed, even with exponentiated values. SHOW will display the full values of each part of a complex number, one part per line.

I dislike the parenthesized ordered pairs of the HP-71B and RPL-based models, because that representation is ambiguous.

Showing one part of a complex number at a time (rectangular format only) is what had to be done on the HP-15C, due to display limitations. However, it's not the ideal, as imaginary parts can be overlooked.

-- KS


#15

I think any EE would second that post.

Andreas

#16

Thanks Karl - I'll read and digest your thread and specification. Thanks for the details.

Using the search feature in the forum has been mentioned above a few times. I hate to admit this but I find the search facility incredibly confusing and rarely get good results from it. Time to eat humble pie and ask about how to use search! I'll do this in another thread to keep this one clean.

Mark

#17

Very nice coverage of the topic, Karl. I personally am very comfortable with the ordered pair approach (48, 49, and 50); but overall I think your spec would be a brilliant way to approach it on a scientific.

John


Possibly Related Threads...
Thread Author Replies Views Last Post
  HP Prime: complex numbers in CAS. Alberto Candel 1 590 12-06-2013, 02:36 PM
Last Post: parisse
  [HP Prime] Plots containing complex numbers bug? Chris Pem10 7 1,141 12-05-2013, 07:40 AM
Last Post: cyrille de Brébisson
  Complex Number Entry on Prime Jeff O. 19 2,066 11-16-2013, 12:34 PM
Last Post: Jeff O.
  comparing numbers on the WP 34S Kiyoshi Akima 7 1,023 10-19-2013, 09:28 AM
Last Post: walter b
  HP Prime: Operations with Large Numbers Eddie W. Shore 0 317 10-19-2013, 12:24 AM
Last Post: Eddie W. Shore
  HP Prime complex results Javier Goizueta 0 366 10-06-2013, 12:59 PM
Last Post: Javier Goizueta
  HP Prime Solving Nonlinear System of Equations for Complex Results Helge Gabert 11 1,479 09-30-2013, 03:44 AM
Last Post: From Hong Kong
  HHC 2013 room numbers David Hayden 2 509 09-20-2013, 05:34 PM
Last Post: sjthomas
  [HP-Prime xcas] operations with complex numbers + BUGs + Request CompSystems 9 1,248 09-08-2013, 10:40 PM
Last Post: CompSystems
  TED Talk: Adam Spencer: Why I fell in love with monster prime numbers Les Bell 3 634 09-05-2013, 12:54 PM
Last Post: Ken Shaw

Forum Jump: