A birthday cake has lit candles. At each step you pick a number uniformly at random and blow out candles. If any candles remain lit, the process repeats (using a new value of ). As a function of , what is the expected number of rounds needed to blow out all the candles?
Two commenters came up with the right answer; congratulations! Here’s my solution. Since it’s more fun this way, I’m going to explain not just the solution itself but also the process I went through in finding it.
First, let denote the expected number of steps to blow out all the candles starting from lit candles. As a base case, , that is, you don’t need any steps if no candles are lit in the first place. Now, let’s think about an expression for when . If you blow out some candles, leaving , then you expect to need more steps in addition to the one step you just took. Each from to is equally likely, so we can average all these cases to find the expected value of , that is,
We can simplify this a bit: the sum involves adding up copies of the number in addition to , which yields , which we then immediately divide by again. So in fact
.
That is, you always need step, plus whatever is needed on average for what remains.
At this point, instead of analyzing further, I just computed (by hand!) for small values of :
I left unreduced since it seemed clear at this point that can be written as a fraction with in the denominator, which seemed nice.
At this point I actually just looked up the sequence of denominators , , , , in the wonderful Online Encyclopedia of Integer Sequences, and found sequence A000254, “unsigned Stirling numbers of the first kind”. Sounds neat! I scanned through the page and this comment jumped out at me: “The numerator of the fraction when we sum (without simplification) the terms in the harmonic sequence. (; ; ; ). The denominator of this fraction is .” At this point my mouth dropped open with surprise, since the definition of does not, on the face of it, look anything like the definition of the harmonic numbers! The harmonic numbers are partial sums of fractions , that is,
and so on. Is it really possible that ? Computing the first few , it sure seems to be so: , and , and so on. But this might just be a coincidence for small values of ; can we prove that for all ?
Sometimes, just getting an idea of what you should try to prove makes all the difference. Once I had this clue, I was able to prove by induction that indeed . (And perhaps at this point you might like to stop and try to prove it yourself!) Clearly . In the inductive case,
(Typically when I write a calculational proof like this, I like to typeset it with the reason for each step written in between the lines; but that is difficult to do on this blog, and you will probably have more fun figuring out the reasoning yourself!)
Thus, the expected number of steps needed to blow out candles is the th harmonic number, . Incidentally, we have of course discovered an interesting harmonic number identity: just substitute for in our original recurrence!
After arriving at this result, I tried to see whether there is a more intuitive way to understand it. Here’s what I came up with. Number the candles from to , such that we always blow out the higest-numbered candles first, and candle number is the last to be blown out. Say that each step of blowing out candles is “charged” to the lowest-numbered candle to be blown out; the remaining candles are blown out “for free”. We then consider how much it “costs” to blow out a particular candle. Candle 1 definitely costs 1 step: it will always be charged for the step on which it is blown out. Candle 2 costs, on average, : either it is the lowest-numbered candle to be blown out, leaving the first candle still lit, in which case it incurs the cost for that step; or else it is blown out for free if the first candle is also blown out in that step. Since these are equally likely, the expected cost is . Likewise, there are three equally likely scenarios for candle ; in one case it incurs a cost of , and in the other two cases it is blown out for free, yielding an expected cost of , and so on. Since the expectation of a sum is the sum of expectations (i.e. expectation is linear), the expected total cost is the sum of the individual expected costs, . I am confident this can be made into a perfectly rigorous argument, which would actually constitute an alternative, “combinatorial” proof that .
As a final aside, according to a classic result , where is the Euler-Mascheroni constant. So we can also say that the expected number of rounds to blow out candles is approximately the natural logarithm of . Apparently, the fact that the expectation is logarithmic in the number of candles (as opposed to linear) can be surprising to people. It was intuitively obvious to me, but that’s probably just because I’ve done a lot of computer science; this problem would fit very well into an analysis of algorithms course.
Mark has already covered the first five parts of the (23-part) message, with more to come. You should see if you can decipher each part before reading the explanation! The first part is shown below.
A birthday cake has lit candles. At each step you pick a number uniformly at random and blow out candles. If any candles remain lit, the process repeats (using a new value of ). As a function of , what is the expected number of rounds needed to blow out all the candles?
For example, suppose the cake starts out with 14 lit candles. You roll a fair 14-sided die^{2} to choose a number between 1 and 14. Suppose you roll a 6. You then blow out 6 candles, leaving 8 lit candles. You now roll a fair 8-sided die; suppose you roll a 3. You blow out 3 candles, leaving 5. So you roll a fair 5-sided die. Maybe this time you actually roll a 5, so you blow out all the remaining candles and you are done. In this particular case, the whole process took three rounds; the question is to determine how many rounds it will take on average.
If one starts with lit candles, it seems clear that the average number of rounds will be less than (it would be very unlucky to roll a 1 every single time) but greater than (it is pretty lucky to roll an on the first try, although not nearly as much so as rolling all 1’s).
Have fun thinking about it. There is, in fact, a nice analytical solution, which I will explain in a future post!
US states visited: 9 (Massachusetts, Vermont, New York, Michigan, Wisconsin, Iowa, Kansas, Missouri, Arkansas); countries visited: 4 (US, Canada, Netherlands, Germany); plane flights: 10; hours of driving: 40; beds: 13; unexpected two-week detours to stay with in-laws: 1; number of days late by which the moving company delivered our belongings: 25.↩
You can make a fair -sided die for any out of a bipyramid with an -gonal base.↩
Recall that the equation for the curve is . The big blue circle corresponds to the term—it is a circle of radius and makes one complete revolution before the animation restarts. The medium orange circle corresponds to : it has a radius of and rotates times as fast as the blue circle. The small green circle corresponds to . It rotates times as fast as the blue circle, but in the opposite direction. It has a radius of , and starts out rotation out of phase with the others, since multiplying by corresponds to a rotation in the complex plane. (Notice that whenever the blue and orange circles are pointing in exactly the same direction, the green circle is perpendicular to them.)
One interesting thing to note is that addition of complex numbers is commutative—which means that we could just as well put the fast green circle in the middle, and the big blue circle next, and the orange circle on the outside, or any other ordering. The red point would always trace exactly the same curve.
Edited to add: can you see how the numbers 1, 6, and -14 result in 5-fold symmetry? Hint: how many times per day do the hands of a clock line up? (Farris proves this analytically in his book, but it wasn’t until staring at this animation that I feel like I really “got it”.)
Mike Croucher also posted an interactive version using Jupyter notebook, where you can play with sliders to control the parameters of the curve and watch it evolve.
This is a plot of the parametric equation
in the complex plane. In general, Farris considers parametric equations of the form
,
where are complex numbers, are integers, and as usual . All such equations correspond to cyclic plots in the complex plane; he analyzes what sorts of symmetry they will have based on the parameters .
He also spends some time talking about the aesthetics of picking values for and that result in beautiful curves. Instead of making carefully considered choices in this kind of situations, I often like to employ randomness to just generate a bunch of different instantiations and see what comes up (although there is still a certain amount of art in choosing the distributions for the random parameters). So, here are 50 random curves. Each one has
I really like seeing these all together. They are not all great individually, but as a group, it’s fun seeing their differences, similarities, and idiosyncracies.
Don’t ask me what the parameters are for an individual curve because the program I used to generate them does not save the parameters anywhere! The code is here if you want to see it; of course it is written in Haskell and uses the diagrams framework.
I also want to help spread the word that Matthew Watkins’ wonderful Secrets of Creation Trilogy has been republished in a new edition by Liberalis Books. I previously reviewed the first and second books in the trilogy (tl;dr: they are fabulous). I have now read the third book in the trilogy (depicted above), which is just as fabulous, though I never reviewed it here. And if you don’t believe me you can see what others (including Sir Roger Penrose and Clifford Pickover) have said about it. I highly recommend that you check them out if you haven’t already!
You can buy high-quality prints from Imagekind. (If you order soon you should have them before Christmas! =) I’m really quite happy with imagekind, the print quality is fantastic and the prices seem reasonable. You can choose among different sizes—I suggest 32"x20" ($26 on the default matte paper, + shipping), but the next smaller size (24"x15", $17) is probably OK too.
If you have ideas for variant posters you’d like to see, let me know (though I probably won’t be able to do anything until after the new year).
Note that Jeremy also has a variety of factorization diagram posters for sale.
For more information, including links to the source code, a high-resolution PNG, and other things, see this factorization diagrams page.
“But”, I hear you protest, “Pi Day was ages ago!” Ah, but I didn’t say Pi Day, I said PIE Day. To clarify:
(Actually, I’m only going to begin explaining it today; it’s getting too long for a single blog post!) In any case, the overall goal is to finish up my long-languishing series on a combinatorial proof of a curious identity (though this post is self-contained so there’s no need to go back and reread that stuff yet). The biggest missing piece of the pie is… well, PIE! I’ve been having trouble figuring out a good way to explain it in sufficient generality—it’s one of those deceptively simple-seeming things which actually hides a lot of depth. Like a puddle which turns out to be a giant pothole. (Except more fun.)
In a previous post (now long ago) I asked for some advice and got a lot of great comments—if my explanation doesn’t make sense you can try reading some of those!
So, what’s the Principle of Inclusion-Exclusion all about? The basic purpose is to compute the total size of some overlapping sets.
To start out, here is a diagram representing some non-overlapping sets.
Each set is represented by a colored circle and labelled with the number of elements it contains. In this case, there are 25 people who like bobsledding (the red circle), six people who like doing laundry (the blue circle), and 99 people who like math (the green circle). The circles do not overlap at all, meaning that none of the people who like math also like laundry or bobsledding; none of the people who like doing laundry also like bobsledding or math; and so on. So, how many people are there in total? Well, that’s easy—just add the three numbers! In this case we get 130.
Now, consider this Venn diagram which shows three overlapping sets.
Again, I’ve labelled each region with the number of elements it contains. So there are two people who like bobsledding but not math or laundry; there are three people who like bobsledding and math but not laundry; there is one person who likes all three; and so on. It’s still easy to count the total number of elements: just add up all the numbers again (I get 14).
So what’s the catch?
The catch is that in many situations, we do not know the number of elements in each region! More typically, we know something like:
The total number of elements in each set. Say, we might know that there are 7 people who like bobsledding in total, but have no idea how many of those 7 like math or laundry; and similarly for the other two sets.
The total number of elements in each combination of sets. For example, we might know there are two people who like bobsledding and laundry—but we don’t know whether either of them likes math.
This is illustrated below for another instance of our ongoing example. The top row shows that there are sixteen people who like bobsledding in total, eleven who like laundry in total, and eighteen who like math—but again, these are total counts which tell us nothing about the overlap between the sets. (I’ve put each diagram in a box to emphasize that they are now independent—unlike in the first diagram in this post, having three separate circles does not imply that the circles are necessarily disjoint.) So is probably too many because we would be counting some people multiple times. The next row shows all the intersections of two sets: there are three people who like bobsledding and laundry (who may or may not like math), eight people who like bobsledding and math; and six people who like laundry and math. Finally, there is one person who likes all three.
The question is, how can we deduce the total number of people, starting from this information?
Well, give it a try yourself! Once you have figured that out, think about what would happen if we added a fourth category (say, people who like gelato), or a fifth, or… In a future post I will explain more about the general principle.
The deadline for submitting a paper has passed, but the Workshop on Functional Art, Music, Modeling and Design (FARM 2013) is currently seeking proposals for 10-20 minute demonstrations to be given during the workshop. For example, a demonstration could consist of a short tutorial, an exhibition of some work, or even a livecoding performance. Slots for demonstrations will be shorter than slots for accepted papers, and will not be published as part of the formal proceedings, but can be a great way to show off interesting work and get feedback from other workshop participants. A demonstration slot could be a particularly good way to get feedback on work-in-progress.
A demo proposal should consist of a 1 page abstract, in PDF format, explaining the proposed content of the demonstration and why it would be of interest to the attendees of FARM. Proposals will be judged on interest and relevance to the stated goals and themes of the workshop.
Submissions can be made via EasyChair.