Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Knuth song complexity

871 views

Published on

knuth's class

  • Be the first to comment

Knuth song complexity

  1. 1. SPECIAL SECTION Guest Editor Peter Neumann The Complexity of Songs DONALD E. KNUTH Every day brings new evidence that the concepts of By the Distributive Law and the Commutative Law [4], computer science are applicable to areas of life which we have have little or nothing to do with computers. The pur- c= n- (V+R)m + mV pose of this survey paper is to demonstrate that impor- tant aspects of popular songs are best understood in = n- Vm-Rm + Vm (3) terms of modern complexity theory. =n-Rm. It is known [3] that almost all songs of length n re- quire a text of length ~ n. But this puts a considerable The lemma follows. [3 space requirement on ones memory if many songs are to be learned; hence, our ancient ancestors invented (It is possible to generalize this lemma to the case of the concept of a refrain [14]. When the song has a verses of differing lengths V1, V2. . . . ~Vm, provided that refrain, its space complexity can be reduced to cn, the sequence (Vk) satisfies a certain smoothness condi- where c < 1 as shown by the following lemma. tion. Details will appear in a future paper.) A significant improvement on Lemma 1 was discov- LEMMA 1. ered in medieval European Jewish communities where Let S be a song containing m verses of length V and a an anonymous composer was able to reduce the com- refrain of length R where the refrain is to be sung first, plexity to O(x/n). His song "Ehad Mi Yodea" or "Who last, and between adjacent verses. Then, the space Knows One?" is still traditionally sung near the end of complexity of S is ( V / ( V + R)) n + O(1) for fixed V the Passover ritual, reportedly in order to keep the chil- and R as m ~ oo. dren awake [6]. It consists of a refrain and 13 verses vl . . . . . v13, where v~ is followed by vk-1 • .. v2vl before PROOF. the refrain is repeated; hence m verses of text lead to T h e l e n g t h of S when s u n g i s 1/2m2 .-F O(m) verses of singing. A similar song called "Green Grow the Rushes O" or "The Dilly Song" is n =R+(V+R)m (1) often sung in western Britain at Easter time [1], but it has only twelve verses (see [1]), where Breton, Flemish, while its space complexity is German, Greek, Medieval Latin, Moldavian, and Scottish c = R + Vm. (2) versions are cited. The coefficient of ~n was further improved by a Scot- tish farmer named O. MacDonald, whose construction~ appears in Lemma 2. The research reported here was supported in part by the National Institute of Wealth under grant $262,144. ActuallyMacDonaldspriorityhas beendisputedby somescholars;Peter Kennedy([8],p. 676)claimsthat "1BoughtMyselfa Cock"and similarfarm- ©1984ACMO001-0782/84/0400-0344 75¢ yard songsare actuallymucholder.344 Communications of the ACM April 1984 Volume 27 Number 4
  2. 2. Special SectionL E M M A 2. when a is fixed. Therefore if MacDonalds farm animalsGiven positive integers a and X, there exists a song ultimately have long names they should make slightlywhose complexity is (20 + X + a) ~/n/(30 + 2)0 + O(1). shorter noises. Similar results were achieved by a French CanadianPROOF. ornithologist, who named his song schema "Alouette"Consider the following schema [9]. [2, 15]; and at about the same time by a Tyrolean butcher whose schema [5] is popularly called "Ist das V o = Old MacDonald had a farm, Ri nicht ein Schnitzelbank?" Several other cumulative R1 = Ee-igh, ,2 oh! songs have been collected by Peter Kennedy [8], in- cluding "The Mallard" with 17 verses and "The Barley R2(x) -- Vo And on this farm he had Mow" with 18. More recent compositions, like "Theres a Hole in the Bottom of the Sea" and "I Know an Old some x, R1 With a Lady Who Swallowed a Fly" unfortunately have com- U~(x, x) = x, x here and a x, x there; paratively large coefficients. A fundamental improvement was claimed in England U2(x, y) = xhere a y, in 1824, when the true love of U. Jack gave to him a U3(x, x) = Ui(x, x) U2(g, x) U2(t, x ) total of 12 ladies dancing, 22 lords a-leaping, 30 drum- mers drumming, 36 pipers piping, 40 maids a-milking, U2(everyw, x , x) 42 swans a-swimming, 42 geese a-laying, 40 golden rings, 36 collie birds, 30 french hens, 22 turtle doves, Vk = U3(Wk, W~)Vk-i for k _> 1 and 12 partridges in pear trees during the twelve dayswhere of Christmas [11]. This amounted to 1/6 m 3 -.b 1/2 m 2 -b 1/a m gifts in m days, so the complexity appeared to be W1 = chick, W2 = quack, O(3~n); however, it was soon pointed out [10] that his W3 = gobble, Wk = oink, (5) computation was based on n gifts rather than n units of singing. A complexity of order ~/n/log n was finally W5 = moo, W6 = hee , established (.see [7]). We have seen that the p a r t r i ~ in the pear tree gaveand an improvement of only 1/Vlog n; but the importance W~- = W k for k#6;W~ =haw. (6) of this discovery should not be underestimated since it showed that the n °5 barrier could be broken. The nextThe song of order m is defined by big breakthrough was in fact obtained by generalizing (7) the partridge schema in a remarkably simple way. It was J. W. Blatz of Milwaukee, Wisconsin who first dis- J~,~ = R2(W;[i)VmJ~-I for m_>l, covered a class of songs known as "m Bottles of Beer onwhere the Wall"; her elegant construction2 appears in the fol- lowing proof of the first major result in the theory. W~ = chicks, W~ = ducks, THEOREM 1. W3 = turkeys, W ~ = pigs, " (8) There exis t songs of complexity O(log n). W~ = cows, W~ = d o n k e y s . PROOF. Consider the schemaThe length of Y (m) is Vk = TkBW, n = 30m 2 + 153m TkB; + 4(m/1 + (m - 1)/2 -4- . . . + /m) If one of those bottles should (12) + (al + . . . + am) (9) happen to fall, while the length of the corresponding schema is Tk-iB W. c = 20m + 211 + (/1 + . . . + / , , ) where + (al + . . . + a,,). (10) B = bottles of beer , (13)HereA = IWkl + IW/I and ak = IW~Yl,where Ixldenotes the length of string x. The result follows at W = on the wall ,once, if we assume that ,~ = X and ak = a for alllarge k. [3 and where Tk is a translation of the integer k into Eng- Note that the coefficient (20 + X + a ) / ~ / ~ + 2X 2 Again Kennedy ([8], p. 631) claims priority for the English, in this caseassumes its m i n i m u m value at because of the song "I11 drink m if youll drink m + 1." However, the English start at m = 1 and get no higher than m = 9, possibly because they actually k = max(l, a-lO) (11) drink the beer instead of allowing the bottles to fall.April 1984 Volume 27 Number 4 Communications of the ACM 34S
  3. 3. Special Section lish. It requires only O(m) space to define Tk for all Acknowledgment I wish to thank J. M. Knuth and J. S. k < 10" since we can define Knuth for suggesting the topic of this paper. Tq.lo.,.r = Tq times 10 to the Tin plus T, (14) REFERENCES for 1 _< q _< 9 and 0 _< r < 10m-L 1. Rev. S. Baring-Gould, Rev. H. Fleetwood Sheppard, and F.W. Bus- sell, Songs of the West (London: Methuen, 1905}, 23, 160-161. Therefore the songs Sk defined by 2. Oscar Brand, Singing Holidays (New York: Alfred Knopf, 1957), 68- 69. So=e,Sk= VkSk-1 for k>_ 1 (15) 3. G.J. Chaitin, "On the length of programs for computing finite binary sequences: Statistical considerations," J. ACM 16 (1969), 145-159. have length n X k log k, but the schema which defines 4. G. Chrystal, Algebra, an Elementary Textbook (Edinburgh: Adam and them has length O(log k); the result follows. [3 Charles Black, 1886), Chapter 1. 5. A. D6rrer, Tiroler Fasnacht (Wien, 1949), 480 pp. Theorem 1 was the best result known until recently 3, 6. Encyclopedia Judaica (New York: Macmillan, 1971), v. 6 p. 503; The perhaps because it satisfied all practical requirements Jewish Encyclopedia (New York: Funk and Wagnalls, 1903); articles for song generation with limited memory space. In fact, on Ehad Mi Yodea. 7. U. Jack, "Logarithmic growth of verses," Acta Perdix 15 (1826), 99 bottles of beer usually seemed to be more than suffi- 1-65535. cient in most cases. 8. Peter Kennedy, Folksongs of Britain and Ireland (New York: Schirmer, 1975), 824 pp. However, the advent of modern drugs has led to 9. Norman Lloyd. The New Golden Song Book (New York: Golden Press, demands for still less memory, and the ultimate im- 1955), 20-21. provement of Theorem 1 has consequently just been 10. N. Picker, "Once sefiores brincando al mismo tiempo," Acta Perdix 12 (1825), 1009. announced: 11. ben shahn, a partridge in a pear tree (New York: the museum of modern art, 1949), 28 pp. (unnumbered). THEOREM 2. 12. Cecil J. Sharp, ed., One Hundred English Folksongs (Boston: Oliver There exist arbitrarily long songs of complexity O(1). Ditson, 1916), xlii. 13. Christopher J. Shaw, "that old favorite, A p i a p t / a Christmastime al- PROOF: (due to Casey and the Sunshine Band). Consider gorithm," with illustrations by Gene Oltan, Datamation 10, 12 (De- cember 1964), 48-49. Reprinted in Jack Moshman, ed., Faith, Hope the songs Sk defined by (15), but with and Parity (Washington, D.C.: Thompson, 1966), 48-51. 14. Gustav Thurau, Beitr~ge zur Geschichte und Charakteristik des Refrains Vk = Thats the way, U I like it, U (16) in derfranzosischen Chanson (Weimar: Felber, 1899), 47 pp. 15. Marcel Vigneras, ed., Chansons de France (Boston: D.C. Heath. 1941), U = uh huh, uh huh 52 pp. for all k. [3 Permission to copy without fee all or part of this material is granted It remains an open problem to study the complexity provided that the copies are not made or distributed for direct commer- of nondeterministic songs. cial advantage, the ACM copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of 3 The chief rival for this honor was "This old man, he played m, he played the Association for Computing Machinery. To copy otherwise, or to knick-knack.... republish, requires a fee a n d / o r specific permission.346 Communications of the ACM April 1984 Volume 27 Number 4

×