Complex literals (was Re: I am never going to complain about Python again)

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Oct 10 21:27:11 EDT 2013


On Fri, 11 Oct 2013 00:25:27 +1100, Chris Angelico wrote:

> On Fri, Oct 11, 2013 at 12:09 AM, Roy Smith <roy at panix.com> wrote:
>> BTW, one of the earliest things that turned me on to Python was when I
>> discovered that it uses j as the imaginary unit, not i.  All
>> right-thinking people will agree with me on this.
> 
> I've never been well-up on complex numbers; can you elaborate on this,
> please? All I know is that I was taught that the square root of -1 is
> called i, and that hypercomplex numbers include i, j, k, and maybe even
> other terms, and I never understood where j comes from. Why is Python
> better for using j?

Being simple souls and not Real Mathematicians, electrical engineers get 
confused by the similarity between I (current) and i (square root of -1), 
so they used j instead. Real Mathematicians are hardy folk completely at 
home with such ambiguity -- if you can deal with superscript -1 meaning 
both "inverse function" and "reciprocal" *in the same equation*, i vs I 
hold no fears for you.

<wink>

But seriously... I think the convention to use j for complex numbers 
comes from the convention of using i, j, k as unit vectors, i being in 
the X direction (corresponding to the real axis), j being in the Y 
direction (corresponding to the imaginary axis), and k being in the Z 
direction.

For what it's worth, there is no three-dimensional extension to complex 
numbers, but there is a four-dimensional one, the quaternions or 
hypercomplex numbers. They look like 1 + 2i + 3j + 4k, where i, j and k 
are all distinct but i**2 == j**2 == k**2 == -1. Quaternions had a brief 
period of popularity during the late 19th century but fell out of 
popularity in the 20th. In recent years, they're making something of a 
comeback, as using quaternions for calculating rotations is more 
numerically stable than traditional matrix calculations.

Unlike reals and complex numbers, quaternions are non-commutative: in 
general, q1*q2 != q2*q1.

There are also octonions, eight-dimensional numbers which are non-
commutative and non-associative, (o1*o2)*o3 != o1*(o2*o3), and sedenions, 
a 16-dimensional number.



-- 
Steven



More information about the Python-list mailing list