2. Special Section
L E M M A 2. when a is fixed. Therefore if MacDonald's farm animals
Given positive integers a and X, there exists a song ultimately have long names they should make slightly
whose complexity is (20 + X + a) ~/n/(30 + 2)0 + O(1). shorter noises.
Similar results were achieved by a French Canadian
PROOF. 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 "There's
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) = x'here 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 days
where 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 gave
and
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 next
The 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 on
where 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 schema
The 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 Ixl
denotes the length of string x. The result follows at W = ' on the wall' ,
once, if we assume that ,~ = X and ak = a for all
large 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 case
assumes its m i n i m u m value at because of the song "I'11 drink m if you'll 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. 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 Yode'a.
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 = 'That's 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