# So what exactly is a complex number?

Steve Holden steve at holdenweb.com
Tue Sep 4 07:10:22 CEST 2007

```Roy Smith wrote:
> Boris Borcic <bborcic at gmail.com> wrote:
>> Complex numbers are like a subclass of real numbers
>
> I wouldn't use the term "subclass".  It certainly doesn't apply in the same
> sense it applies in OOPLs.  For example, you can't say, "All complex
> numbers are real numbers".  In fact, just the opposite.
>
> But, it's equally wrong to say, "real numbers are a subclass of complex
> numbers", at least not if you believe in LSP
> (http://en.wikipedia.org/wiki/Liskov_substitution_principle).  For example,
> it is true that you can take the square root of all complex numbers.  It is
> not, however, true that you can take square root of all real numbers.
>
That's not true. I suspect what you are attempting to say is that the
complex numbers are closed with respect to the square root operation,
but the reals aren't. Clearly you *can* take the square root of all real
numbers, since a real number *is* also a complex number with a zero
imaginary component. They are mathematically equal and equivalent.

> Don't confuse "subset" with "subclass".  The set of real numbers *is* a
> subset of the set of complex numbers.  It is *not* true that either reals
> or complex numbers are a subclass of the other.

I don't think "subclass" has a generally defined meaning in mathematics
(though such an assertion from me is usually a precursor to someone
presenting evidence of my ignorance, so I should know better than to
make them).

obpython: I have always thought that the "key widening" performed in
dictionary lookup is a little quirk of the language:

>>> d = {2: "indeedy"}
>>> d[2.0]
'indeedy'
>>> d[2.0+0j]
'indeedy'
>>>

but it does reflect the fact that the integers are a subset of the
reals, which are (as you correctly point out) a subset of the complexes.

regards
Steve
--
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

```