The Museum of HP Calculators

HP Forum Archive 19

 Complex numbers - ideal display representation?Message #1 Posted by Mark Edmonds on 6 Aug 2009, 4:54 p.m. 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

 Re: Complex numbers - ideal display representation?Message #2 Posted by hugh steers on 6 Aug 2009, 5:33 p.m.,in response to message #1 by Mark Edmonds 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.

 Re: Complex numbers - ideal display representation?Message #3 Posted by Mark Edmonds on 6 Aug 2009, 5:59 p.m.,in response to message #2 by hugh steers 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

 Re: Complex numbers - ideal display representation?Message #4 Posted by hugh steers on 6 Aug 2009, 6:40 p.m.,in response to message #3 by Mark Edmonds 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.

 Re: Complex numbers - ideal display representation?Message #5 Posted by Jeff O. on 6 Aug 2009, 9:05 p.m.,in response to message #3 by Mark Edmonds 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

 Re: Complex numbers - ideal display representation?Message #6 Posted by Walter B on 7 Aug 2009, 1:39 a.m.,in response to message #5 by Jeff O. 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.

 Re: Complex numbers - ideal display representation?Message #7 Posted by Raymund Heuvel on 6 Aug 2009, 6:20 p.m.,in response to message #1 by Mark Edmonds 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

 Re: Complex numbers - ideal display representation?Message #8 Posted by John Cadick on 6 Aug 2009, 8:05 p.m.,in response to message #1 by Mark Edmonds 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

 Re: Complex numbers - ideal display representation?Message #9 Posted by David Hayden on 6 Aug 2009, 8:49 p.m.,in response to message #1 by Mark Edmonds 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

 Re: Complex numbers - ideal display representation?Message #10 Posted by Eric Smith on 7 Aug 2009, 2:56 a.m.,in response to message #9 by David Hayden 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.

 Re: Complex numbers - ideal display representation?Message #11 Posted by Egan Ford on 7 Aug 2009, 11:00 a.m.,in response to message #1 by Mark Edmonds 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?"

 Re: Complex numbers - ideal display representation?Message #12 Posted by Mark Edmonds on 7 Aug 2009, 2:25 p.m.,in response to message #11 by Egan Ford 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

 Re: Complex numbers - ideal display representation?Message #13 Posted by Karl Schneider on 7 Aug 2009, 3:40 p.m.,in response to message #1 by Mark Edmonds 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: 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

 Re: Complex numbers - ideal display representation?Message #14 Posted by marais on 7 Aug 2009, 3:53 p.m.,in response to message #13 by Karl Schneider I think any EE would second that post. Andreas

 Re: Complex numbers - ideal display representation?Message #15 Posted by Mark Edmonds on 7 Aug 2009, 6:03 p.m.,in response to message #13 by Karl Schneider 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

 Re: Complex numbers - ideal display representation?Message #16 Posted by John Cadick on 7 Aug 2009, 9:16 p.m.,in response to message #13 by Karl Schneider 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

Go back to the main exhibit hall