If you're over the age of 30 and I ask you for the square root of 17 over 10 you'd probably pull out a dusty Casio calculator and respond to me:
1.303840481
If you're 30 years of age or younger, you'd probably enter this into Google and get back the same answer. (Go to love Google!)
If you're a mathematician, you'd probably (a) be appalled at this post and (b) reply that the above is most certainly *not* the square root of 17 over 10. At best it's a crude approximation. Perhaps you'd suggest that it's best to keep the expression as a well known set of symbols:
Sure, you don't have a simple series of digits, but you also don't have the wrong answer.
If you're a programmer, you've got a unique third option. Joe Marshall explains:
Instead of representing a real number as a nearby rational number with an error introduced by rounding, we'll represent a real number as computer program that generates the digits. The number of digits generated is potentially infinite, but the program that generates them is definitely finite.
Once you've got this program (which Joe was kind enough to write for us) you can do:
(define the-answer (gosper-sqrt 0 17 10 0))
And the-answer contains the answer to our quandary. When you print out the answer, you need to provide the number of digits you want to see (trying to show the infinite number of digits may take a while). Here's the-answer to 100 places:
1.303840481040529742916594311485836883305618755782013091790079369896765385576397896545183528886788497
But, we could have just as easily asked it to 1,000 places or 1,000,000 places.
I find this Third Solution pretty dang amazing; and not just because it fills the gap nicely between a rough approximation and a purely symbolic one. More importantly, it shows the power that programmers wield. Instead of being limited to a static universe (a string of digits or series of symbols that represent a computation), the programmer can think in terms of an active one (using an executable program to represent numbers).
This goes far beyond math. An image doesn't just need to be a collection of colored pixels, it can be a program that generates the colored pixels. Music doesn't need to be a series of notes, but could be a program that generates these series of notes.
There are many skills that a programmer must learn (for example, debugging a program or how to split a large problem into small problems) and often these skills can be mastered in any field (say, plumbing or cooking). But this reimagining of the world--that may actually be unique to programming. So learn to program, so you can learn to re-see the universe.
No comments:
Post a Comment