Hacker News new | past | comments | ask | show | jobs | submit login
Issue 10562: Change 'j' for imaginary unit into an 'i' (python.org)
48 points by redacted on Dec 3, 2010 | hide | past | favorite | 54 comments



My favourite part:

"That could work; it's a bit late to do this in 3.2, though. How about the following transition strategy for the complex output.

Python 3.3: Introduce PYTHONIMAGINARYSYMBOL environment variable (and possibly also a related command-line option to the interpreter?).

Python 3.4: Show a warning on startup if this environment variable isn't used.

Python 3.5: Make the environment variable mandatory.

Python 3.6: Make the environment variable optional again, but this time with the default output being 'i' rather than 'j'.

Python 3.7: Deprecate use of PYTHONIMAGINARYSYMBOL. (Warning on startup if it's set.)

Python 3.8: Error on startup if PYTHONIMAGINARYSYMBOL is set.

Python 3.9: Go back to ignoring PYTHONIMAGINARYSYMBOL."


Mine was

"This deterministic approach has the advantage that migration of code from one imaginary symbol to another is as easy as:

sed -e 's/k/l/' -e 's/j/k/' -e 's/i/j/' -e 's/l/i/'

provided that you restrict yourself not to use the characters i, j, k or l in identifiers, keywords or strings in the source code."


It's surprising to me that a programming language would have started out following engineering conventions rather than mathematical conventions, even if there's a strong overlap between EE and CS. That said (and speaking as a mathematician) I think it's foolish to use j over i, especially since in some cases (e.g. quaternions) it will be very confusing.


Physicists, on the other hand, have come to terms with the fact that they have fewer letters in the English and Greek alphabets than concepts they need to express, and so happily overload i and everything else, hoping to always figure it out from context.


just add a hat ^ or squiggle ~ over it, or maybe a point, or something else. I always wondered when the Hebrew alphabet would come up.


Chinese is the future.


Simplified or traditional?


Yes. We need all the symbols we can get.


We'll need mathematics professors with neater handwriting if you ever hope to be able to distinguish one hanzi from another, though...


Aleph-null?


Indeed, the use of aleph for transfinite numbers seems to be the only use of the Hebrew alphabet in the sciences that I know.

Looking at it, it seems like it would be rather hard to introduce. Any symbol which isn't already a bit too close to a misdrawn version of a Greek or Roman letter (I see three letters which look like misdrawn πs) is pretty hard to draw without practice.


Script Hebrew is a lot easier to write. Printed Hebrew is rarely written except by scribes, or typed.


I always wondered when the Hebrew alphabet would come up.

It already has:

http://en.wikipedia.org/wiki/Aleph_number


Not really. Python only supports the second square root of -1 instead of the first at the moment. They are indistinguishable from each other until you introduce the other two. It's just convention that the first one is what's in common use when you don't need all three.


The decision to use "j" was made quite a long time ago by Guido. There as a fairly short discussion about it and he made his decision. As other people have said, this is a bike shed issue. BTW, Guido's MSc is in math.


Agreed. Scheme uses i and not j, and it was created at MIT, where there isn't even a separate CS department, just EECS.


That page could be added to the list of classic examples of bike-shedding.


Except that the bikesheddiest bits are deliberate satire.


j vs i gets really confusing when you're doing a dual electrical engineering / computer science degree, since you have to remember which classes use which: electrical engineering uses j (since i is already taken to mean current), CS math uses i :)


I said something about j in my number theory class after 3 years of EE and my professor looked at me like I was an idiot. He apparently had never heard of j once in his life.


What happened to "there should be one-- and preferably only one --obvious way to do it"?

PS. I've also posted this as a comment to the bug report.


This is python's philosophy. However the ambiguity is due to different representation in other known fields, namely engineering and mathematics.

PS - I agree, (and upvoted) to your comment. I like this approach http://bugs.python.org/issue10562#msg123135


I feel a bit bad for Retro, and half hold out the hope that he’s an invented character just playing a role.


A lot of the issues he creates are very low priority or invalid , but he aggressively, un-cooperatively, and repeatedly pushes that they be fixed.


I know that cooler heads will prevail, and that python won't get this silly syntax change, but...

...everyone seems to be forgetting that i == -j (either squared is 1). Physicists usually describe traveling waves (of whatever) as something proportional to exp(kx-iwt) where that's an omega, not a w, and electrical engineers for whatever reason prefer the notation exp(kx+jwt) (note the minus sign difference). Except ee's sometimes write exp(kx-jwt), depending on the convention in use at the time.


What are you talking about? i == j, and either squared are equal to negative one. You can use them interchangeably.


Take a look at quaternions (http://en.wikipedia.org/wiki/Quaternion) where ii == jj == -1, but i != j


This discussion is talking about the notation ambiguity of i and j in denoting a classical complex number with only one real and one imaginary part. As far as I can tell, this python bug report has absolutely nothing to do with quaternions, which is an extension on complex numbers.

i == j, not i == -j in most applications. If you take the number z = a + ib and turn it into z = a - jb, and just take Im(z), you end up with two different answers otherwise.


What does Mark Dickinson mean in http://bugs.python.org/issue10562#msg122672 when he says

  'j' for *a* (not *the* </pedantry>) square root of -1 has...


j is often used instead of i in engineering and physics.

When you start talking about charge density, current, phase and frequency, you almost always start reverting back to engineering notation (i == j). In QM we used i. In Complex Analysis, we used i. In CM, with regards to oscillators/harmonic motion, we used i.

The wikipedia article on imaginary units talks about interchanging i and -j denoting the reversal of plane waves, but we never did that in advanced electrodynamics. However, I wouldn't be surprised if some people do, but as far as I know it's not that common. It's probably find for determining the EM field at some point for some time, but for the problems where you have to find the charge density on a surface of conductor induced by a EM wave, this notation would start to get confusing.


You can use i and -i interchangably, as long as you're consistent.


The reason is that i is used to denote (time changing) current in electrical engineering.


i(j) squared is -1 if we're talking about complex numbers and 1 for split-complex numbers. Each is an interesting class of numbers.


It's an imaginary number, not a jimaginary number.


I love this:

I'm personally -0.small on it

even though I don't understand it. Anyone?


In the Python community, agreement with a proposed change (“this is a good idea”) is indicated by +1, disagreement (“this is a bad idea”) is indicated by -1, and mostly indifference leaning slightly for or against (as in “I (dis)approve but don’t really care”) is indicated by +0 or -0. My guess is that -0.small is intended to mean something like “I slightly disapprove but this is utterly insignificant”.

Edit: much more amusing is Antoine’s comment “[...] Otherwise +11j from me”


probably a representation of a value smaller than 0 but larger than the nearest-to-0 possible value that can be encoded as a floating point number (that still isn't 0). or something like that.

see also http://en.wikipedia.org/wiki/Subnormal_numbers


I'd parse it to be "opposed to it but only very slightly." Similar to -σ maybe.


What module are they talking about? Could someone give an example? For instance, the following doesn't work:

  import math
  math.sqrt(-1)


That would be the 'cmath' module.


Thank you. Clearly a python noob here...


Who ever use imaginary/complex numbers anyway?



I think it was a valid (though poorly worded) question. Not really deserving -4. Thanks for the answers anyway -- I haven't touched imaginary numbers since high school.


They are important for factorising prime numbers. For example

17 = (4+i)(4-i)


If you rotate your phone's keypad 90 degrees, you can call Hogwarts!

To actually answer your question, complex numbers make signal processing algorithms much more tractable, and also make it easy to visualize many commonplace quantities and phenomena in electrical engineering. Anytime a value has both a magnitude and a time- or phase-based aspect, chances are you can use complex numbers to represent it.

Put another way: just as negative numbers allow you to specify movement along an axis, complex numbers allow you to specify rotation around an axis. Both are obviously pretty fundamental.


Wouldn't the same advantage be obtained by x and y coordinates?


No. The e^x properties of imaginary number are way easier than mucking about with much more complex equations involving sine and cosine.


Not exactly. Complex numbers greatly simplify math in that they allow us to represent phase and amplitude, for instance, using only a single term. Usually this appears as e raised to some power of i (or j) that is multiplied by an angle. x and y coordinates can't really accomplish the same thing. If I had an (x, y) pair, y would tell me something about amplitude, but I wouldn't really know anything about phase without comparing x to something else.

Check out phasors: http://en.wikipedia.org/wiki/Phasor_(sine_waves). Complex numbers make phasor math simple and elegant.


This something I found quite interesting:

The complex numbers form a ring that is isomorphic to the cross product of the ring of real numbers and itself....

C≅R×R

For those who haven't done abstract algebra:

This means your can map a complex number to (x,y), that every complex number maps to a unique (x,y), and that if you add or multiply two complex numbers and then convert the result to (x,y), you can convert the two complex numbers to (x,y) and then multiply getting the same answer. (it is also bijective, meaning it works both ways).

Importance: Complex numbers can be dealt with as coordinates and coordinates can be dealt with as complex numbers.


That's not true: the multiplication is different. (x1,y1) × (x2,y2) would have to be (x1x2 - y1y2, x1y2 + y1x2), not (x1y1, x2y2).

The addition does work as you suggest, so a more correct formal statement would be: the complex numbers form an additive group that is isomorphic to the cartesian product of the additive group of real numbers and itself; the complex numbers also happen to form a ring (indeed a field).


the mapping function doesn't need to be a direct translation.

But I believe you are right.... curse you Hungerford for teaching rings and groups simultaneously....


The imaginary component is the y coordinate. Thus your vector is one complex number, which you can manipulate in a single operation.


Sure, but have you ever used them in a real world project? And outside of academics?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: