Complex Numbers Are Points

Write a FORTRAN program to draw a 5-point star.

complex p, q
call move(p)
do i = 1, 5
p = p * q
call draw (p)
end do
Of course, I've left out the tricky initialization and all of the syntax that I've forgotten. But the important thing to remember is that ComplexNumbersAreYourFriends.

This works because the real and imaginary parts of a complex are like the x and y of a point. Neither C or Pascal had the simple ability to manage complex numbers (or points) in expressions or argument lists. But it was built into FORTRAN.

By the way, complex multiply does a rotation about the origin. Initialize p to (0,1) and q to rotate p 2/5 of the way around the circle with each call.

-- WardCunningham

[Above code amended slightly; for earlier compilers, the loop syntax would be slightly different.]


That would make q = e^(2/5 * 2 pi i), where e is the natural log base, pi is the ratio of a circle's circumference to its diameter, and i is the imaginary unit.

Amazingly, Google can evaluate the right hand side of this formula as written. Further, the above code really just finds successive integer powers of this number which Google is happy to do with searches of the form

  (e^(2/5 * 2 pi i)) ^ 3
This finds the third point in the star. Try plotting this and similar queries yourself or suggest a plotting extension to the staff at google.


I remember the huge Aha! I went through (just a few years ago) when I realized that complex numbers are best (best for me) thought of in polar coordinates, as opposed to Cartesian.

In polar coordinates, a complex number is a length and a rotation angle. This makes it a natural extension of real numbers, which are lengths with angle=0. Also, -1 is not 1 mirror imaged (as I had thought), but 1 rotated 180. In polar coordinates, multiplying vectors is multiplying lengths and adding angles.

Here's where the aha! happened. I never understood complex roots before. Suddenly, though, asking for the imaginary roots of real numbers was not a nonsense. The cube root of 1 is a number with length 1 and angle 1/3 of 360 (1/3 + 1/3 + 1/3 = once around the circle), or length 1 and angle 120. This is visually sensible, as opposed to some mathematical doubletalk. The next cube root of 1 has angle 2/3, and the final one has angle 0 or 360. Suddenly, I could get the four imaginary fifth roots of 1 with no problem! And 'i' is not imaginary, but just length 1 turned 90. i-squared is "of course" length 1 turned 180, or -1.

That formula Ward wrote above never made any sense to me, until I learned to think in (length, angle) representation of numbers. With this simple, geometric approach, I've been able to teach my 11 and 12 year-olds basic complex numbers - it's visually natural.

-- AlistairCockburn

I got this realization from the fantastic VisualComplexAnalysis which is worth reading for even the most mathematically squeamish.

The complex roots of unity are equivalent to de Moivre's Identity, and are a special case on the unit circle of the Fundamental Theorem of Algebra. The mathworld.com page for the roots of unity has a cute animated gif. See

 http://mathworld.wolfram.com/deMoivresIdentity.html
 http://mathworld.wolfram.com/RootofUnity.html
 http://mathworld.wolfram.com/FundamentalTheoremofAlgebra.html
 http://mathworld.wolfram.com/PolynomialRoots.html
There is a strong connection with what has been called the deepest equation in mathematics, e^(pi*i) = -1; see also the power series for exp(z) and generating functions.

-- DougMerritt

Doug, that is begging to be rewritten as e^(i*pi) + 1 = 0

There is a fascinating book by GeorgeLakoff and Nunez called "Where Mathematics Comes From" where they describe the cognitive underpinnings of mathematics - how mathematics is based upon the processing performed by the motor/sensory mechanisms of the brain. They use the term "metaphoric blend" to describe how the inherent ability of the brain to create metaphors is used to link higher-level abstractions to lower-level abstractions and finally to fundamental cognitive processes within the brain.

This is a perfect example of a metaphoric blend: complex numbers are not actually points, but the mathematical concept of complex numbers can be metaphorically mapped onto the domain of cartesian or polar points, which can then easily be mapped onto bodily movement (walking, turning) and thereby understood by the motor/sensory parts of the brain.

They effectively are actually points.


Just be sure not to do this sort of thing for 3D graphics! Complex numbers are your friends, but quaternions may not be. ;)

Why not? Seems that quaternions would be great for 3D graphics. Any affine transformation can be expressed by a single quaternion, composing transformations is just multiplication.

Not all affine transformations can be encoded with quaternions, though I don't doubt the more important ones can. But the whole thing just strikes me as being far too tailored. Instead of treating the general problem of points in space, you use a very specific algebraic object that happens to have some of the properties you want... it might be convenient, but I suspect there's a reason physicists abandoned quaternions in favor of vectors and tensors, and I wonder how much we'd know of higher dimensions if we stuck with them.

Actually, quaternions *are* very useful in 3D graphics/simulations, especially for slerp'ing, i.e. "spherical linear interpolation". Quaternions are important/useful in this context because they encode rotations nicely. This is due to the homomorphism between unit quaternions and 3D rotations. Note that the multiplication operations on a 4-tuple representation are much cheaper than on a 4x4 matrix. They are also isomorphic to SU(2), but I don't think this representation is used in graphics much. Quaternions were used in classical mechanics for much the same reason - physicists left them behind when they became more interested in > 3 dim, but that doesn't diminish their elegance in solving certain classical problems. They are also one easy way of avoiding the naive simulators problem of 'gimbal-lock'. There are also advantages from the point of view of numerical analysis.


[CliffordAlgebra]

Why not RefactorExtractBaseClass? on Complex and Point? This is one way of looking at CliffordAlgebra, an attempt to unify numeric and spatial computation. It results in many laws of Physics taking on very simple mathematical forms, which in certain circles is widely regarded as a Good Thing.


ProgrammingLanguage support for ComplexNumbers

Other languages with built-in ComplexNumbers: FortranLanguage, PythonLanguage, CeePlusPlus, HaskellLanguage, LispLanguage, SchemeLanguage, JayLanguage, RubyLanguage, MathematicaLanguage.

Languages with built-in quaternions -

The latest incarnation of C in C99 includes complex number handling. C++98 beat C to it, and now we're left to work out if we can ever unite their two different approaches. At least we can use this trick in C and C++ now. -- JamesDennett

There are some built in extensions for CeePlusPlus but in practice it is much better to use the header file <complex> which provides a templated framework so that

  #typedef std::complex<double> complex;
provides a usable complex type. This header file is available with the GnuCpp which is part of the GnuCompilerCollection. I am not speaking for any other implementations here. -- JohnFletcher

The ForthScientificLibrary supports point and radial ComplexNumbers, quaternions, etc for the ForthLanguage.


CategoryMath


EditText of this page (last edited April 29, 2014) or FindPage with title or text search