Crinkly Curves
Total Page:16
File Type:pdf, Size:1020Kb
A reprint from American Scientist the magazine of Sigma Xi, The Scientific Research Society This reprint is provided for personal and noncommercial use. For any other use, please send a request Brian Hayes by electronic mail to [email protected]. Computing Science Crinkly Curves Brian Hayes n 1877 the german mathemati- If you were designing such a route, Ician Georg Cantor made a shock- Some curves are you might start out with the kind of ing discovery. He found that a two- path that’s good for mowing a lawn: dimensional surface contains no more points than a one-dimensional line. so convoluted they Cantor compared the set of all points forming the area of a square with the wiggle free of the set of points along one of the line seg- But there’s a problem with these zig- ments on the perimeter of the square. one-dimensional world zags and spirals. A mathematical lawn He showed that the two sets are the mower cuts a vanishingly narrow same size. Intuition rebels against and fill up space swath, and so you have to keep re- this notion. Inside a square you could ducing the space between successive draw infinitely many parallel line seg- passes. Unfortunately, the limiting pat- ments side by side. Surely an area with invented, as well as curves that fill up tern when the spacing goes to zero is room for such an infinite array of lines a three-dimensional volume or even a not a filled area; it is a path that forever must include more points than a single region of some n-dimensional space. retraces the same line along one edge line—but it doesn’t. Cantor himself The very concept of dimension was of the square or around its perimeter, was incredulous: “I see it, but I don’t undermined. leaving the interior blank. believe it,” he wrote. Circa 1900, these space-filling curves The first successful recipe for a Yet the fact was inescapable. Cantor were viewed as mysterious aberra- space-filling curve was formulated defined a one-to-one correspondence tions, signaling how far mathematics in 1890 by Giuseppe Peano, an Ital- between the points of the square and had strayed from the world of every- ian mathematician also noted for his the points of the line segment. Every day experience. The mystery has nev- axioms of arithmetic. Peano did not point in the square was associated er entirely faded away, but the curves provide a diagram or even an explicit with a single point in the segment; ev- have grown more familiar. They are description of what his curve might ery point in the segment was matched playthings of programmers now, nice- look like; he merely defined a pair of with a unique point in the square. No ly adapted to illustrating certain algo- mathematical functions that give x and points were left over or used twice. rithmic techniques (especially recur- y coordinates inside a square for each It was like pairing up mittens: If you sion). More surprising, the curves have position t along a line segment. come out even at the end, you must turned out to have practical applica- Soon David Hilbert, a leading light have started with equal numbers of tions. They serve to encode geographic of German mathematics in that era, de- lefts and rights. information; they have a role in image vised a simplified version of Peano’s Geometrically, Cantor’s one-to-one processing; they help allocate resourc- curve and discussed its geometry. The mapping is a scrambled affair. Neigh- es in large computing tasks. And they illustration at the top of the opposite boring points on the line scatter to tickle the eye of those with a taste for page is a redrawing of a diagram widely separated destinations in the intricate geometric patterns. from Hilbert’s 1891 paper, showing square. The question soon arose: Is the first three stages in the construc- there a continuous mapping between How to Fill Up Space tion of the curve. a line and a surface? In other words, It’s easy to sketch a curve that com- can one trace a path through a square pletely fills the interior of a square. The Programming by Procrastination without ever lifting the pencil from the finished product looks like this: The lower illustration on the opposite paper and touch every point at least page shows a later stage in the evolu- once? It took a decade to find the first tion of the Hilbert curve, when it has such curve. Then dozens more were become convoluted enough that one might begin to believe it will eventu- Brian Hayes is senior writer for American Scien- How uninformative! It’s not enough to ally reach all points in the square. The tist. Additional material related to the Comput- know that every point is covered by the curve was drawn by a computer pro- ing Science column appears at http://bit-player. passage of the curve; we want to see gram written in a recursive style that I org. Address: 11 Chandler St. #2, Somerville, MA how the curve is constructed and what call programming by procrastination. 02144. E-mail: [email protected] route it follows through the square. The philosophy behind the approach 178 American Scientist, Volume 101 © 2013 Brian Hayes. Reproduction with permission only. Contact [email protected]. is this: Plotting all those twisty turns 1 2 3 4 1 2 3 16 1 64 looks like a tedious job, so why not put it off as long as we can? Maybe we’ll 6 7 10 11 never have to face it. 2 3 Let us eavesdrop on a computer pro- gram named Hilbert as it mumbles to 5 8 9 12 itself while trying to solve this problem: 3 13 Hmm. I’m supposed to draw a 4 14 curve that fills a square. I don’t 1 4 2 3 1 2 15 16 know how to do that, but maybe 1 4 I can cut the problem down to 64 size. Suppose I had a subroutine A space-filling curve evolves through successive stages of refinement as it grows to cover the that would fill a smaller square, area of a square. This illustration is a redrawing of the first published diagram of such a curve; say one-fourth as large. I could the original appeared in an 1891 paper by David Hilbert. The idea behind the construction invoke that procedure on each is to divide a line segment into four intervals and divide a square into four quadrants, then quadrant of the main square, get- establish a correspondence between the points of corresponding intervals and quadrants. The ting back four separate pieces of process continues with further recursive subdivisions. the space-filling curve. Then, if I just draw three line segments to link the four pieces into one long curve, I’ll be finished! Of course I don’t actually have a subroutine for filling in a quad- rant. But a quadrant of a square is itself a square. There’s a program named Hilbert that’s supposed to be able to draw a space-filling curve in any square. I’ll just hand each of the quadrants off to Hilbert. The strategy described in this mono- logue may sound like a totally point- less exercise. The Hilbert program keeps subdividing the problem but has no plan for ever actually solving it. However, this is one of those rare and wonderful occasions when procrasti- nation pays off, and the homework as- signment you lazily set aside last night is miraculously finished when you get up in the morning. Consider the sizes of the successive subsquares in Hilbert’s divide-and- conquer process. At each stage, the side length of the square is halved, and the area is reduced to one-fourth. The limiting case, if the process goes on in- definitely, is a square of zero side length and zero area. So here’s the procrasti- nator’s miracle: Tracing a curve that After seven stages of elaboration the Hilbert curve meanders through 47 = 16,384 subdivisions of touches all the points inside a size-zero the square. The curve is an unbranched path with end points at the lower left and lower right. It square is easy, because such a square is is continuous in the sense that it has no gaps or jumps, but it is not smooth: All of the right angles in fact a single point. Just draw it! are points where the curve has no tangent (or, in terms of calculus, no derivative). Continuing the Practical-minded readers will object subdivision process leads to a limiting case where the curve fills the entire square, showing that a that a program running in a finite ma- two-dimensional square has no more points than a one-dimensional line segment. chine for a finite time will not actually reach the limiting case of squares that lustration above, I stopped the program curve, but a finite drawing like this one shrink away to zero size. I concede the after seven levels of recursion, when the is at least a guide to the imagination. point. If the recursion is halted while squares were small but certainly larger There is one more important aspect the squares still contain multiple points, than a single point. The wiggly blue of this algorithm that I have glossed one of those points must be chosen as a line connects the centers of 47 = 16,384 over.