My best tea-refilling strategy


The problem I’d set out last week: I have a teapot good for about three cups of tea. I want to put milk in the once, before the first cup. How much should I drink before topping up the cup, to have the most milk at the end?

I have expectations. Some of this I know from experience, doing other problems where things get replaced at random. Here, tea or milk particles get swallowed at random, and replaced with tea particles. Yes, ‘particle’ is a strange word to apply to “a small bit of tea”. But it’s not like I can call them tea molecules. “Particle” will do and stop seeming weird someday.

Random replacement problems tend to be exponential decays. That I know from experience doing problems like this. So if I get an answer that doesn’t look like an exponential decay I’ll doubt it. I might be right, but I’ll need more convincing.

I also get some insight from extreme cases. We can call them reductios. Here “reductio” as in the word we usually follow with “ad absurdum”. Make the case ridiculous and see if that offers insight. The first reductio is to suppose I drink the entire first cup down to the last particle, then pour new tea in. By the second cup, there’s no milk left. The second reductio is to suppose I drink not a bit of the first cup of milk-with-tea. Then I have the most milk preserved. It’s not a satisfying break. But it leads me to suppose the most milk makes it through to the end if I have a lot of small sips and replacements of tea. And to look skeptically if my work suggests otherwise.

So that’s what I expect. What actually happens? Here, I do a bit of reasoning. Suppose that I have a mug. It can hold up to 1 unit of tea-and-milk. And the teapot, which holds up to 2 more units of tea-and-milk. What units? For the mathematics, I don’t care.

I’m going to suppose that I start with some amount — call it a — of milk. a is some number between 0 and 1. I fill the cup up to full, that is, 1 unit of tea-and-milk. And I drink some amount of the mixture. Call the amount I drink x . It, too, is between 0 and 1. After this, I refill the mug up to full, so, putting in x units of tea. And I repeat this until I empty the teapot. So I can do this \frac{2}{x} times.

I know you noticed that I’m short on tea here. The teapot should hold 3 units of tea. I’m only pouring out 3 - a . I could be more precise by refilling the mug \frac{2 + a}{x} times. I’m also going to suppose that I refill the mug with x amount of tea a whole number of times. This sounds necessarily true. But consider: what if I drank and re-filled three-quarters of a cup of tea each time? How much tea is poured that third time?

I make these simplifications for good reasons. They reduce the complexity of the calculations I do without, I trust, making the result misleading. I can justify it too. I don’t drink tea from a graduated cylinder. It’s a false precision to pretend I do. I drink (say) about half my cup and refill it. How much tea I get in the teapot is variable too. Also, I don’t want to do that much work for this problem.

In fact, I’m going to do most of the work of this problem with a single drawing of a square. Here it is.

A unit square representing the milk-and-tea problem. There's a horizontal strip, of height 'a', representing the milk. There's a vertical strip, of width 'x', representing how much is drunk between refills and replaced with tea.
You may protest that my tea is not layered so the milk is all on the bottom, and that I do not drink a vertical column from it. To this I say: how do you know how I drink my tea?

So! I start out with a units of tea in the mixture. After drinking x units of milk-and-tea, what’s left is a\cdot(1 - x) units of milk in the mixture.

How about the second refill? The process is the same as the first refill. But where, before, there had been a units of milk in the tea, now there are only a\cdot(1 - x) units in. So that horizontal strip is a little narrower is all. The same reasoning applies and so, after the second refill, there’s a\cdot(1 - x)\cdot(1 - x) milk in the mixture.

If you nodded to that, you’d agree that after the third refill there’s a\cdot(1 - x)\cdot(1 - x)\cdot(1 - x) . And are pretty sure what happens at the fourth and fifth and so on. If you didn’t nod to that, it’s all right. If you’re willing to take me on faith we can continue. If you’re not, that’s good too. Try doing a couple drawings yourself and you may convince yourself. If not, I don’t know. Maybe try, like, getting six white and 24 brown beads, stir them up, take out four at random. Replace all four with brown beads and count, and do that several times over. If you’re short on beads, cut up some paper into squares and write ‘B’ and ‘W’ on each square.

But anyone comfortable with algebra can see how to reduce this. The amount of milk remaining after j refills is going to be

a\cdot(1 - x)^j

How many refills does it take to run out of tea? That we knew from above: it’s \frac{2}{j} refills. So my last full mug of tea will have left in it

a\cdot(1 - x)^{\frac{2}{x}}

units of milk.

Anyone who does differential equations recognizes this. It’s the discrete approximation of the exponential decay curve. Discrete, here, because we take out some finite but nonzero amount of milk-and-tea, x , and replace it with the same amount of pure tea.

Now, again, I’ve seen this before so I know its conclusions. The most milk will make it to the end of x is as small as possible. The best possible case would be if I drink and replace an infinitesimal bit of milk-and-tea each time. Then the last mug would end with a\cdot e^{-2} of milk. That’s e as in the base of the natural logarithm. Every mathematics problem has an e somewhere in it and I’m not exaggerating much. All told this would be about 13 and a half percent of the original milk.

Drinking more realistic amounts, like, half the mug before refilling, makes the milk situation more dire. Replacing half the mug at a time means the last full mug has only one-sixteenth what I started with. Drinking a quarter of the mug and replacing it lets about one-tenth the original milk survive.

But all told the lesson is clear. If I want milk in the last mug, I should put some in each refill. Putting all the milk in at the start and letting it dissolve doesn’t work.

When should I refill my tea?


I’ve been taking milk in my tea lately. I have a teapot good for about three cups of tea. So that’s got me thinking about how to keep the most milk in the last of my tea. You may ask why I don’t just get some more milk when I refill the cup. I answer that if I were willing to work that hard I wouldn’t be a mathematician.

It’s easy to spot the lowest amount of milk I could have. If I drank the whole of the first cup, there’d be only whatever milk was stuck by surface tension to the cup for the second. And so even less than that for the third. But if I drank half a cup, poured more tea in, drank half again, poured more in … without doing the calculation, that’s surely more milk for the last full cup.

So what’s the strategy for the most milk I could get in the final cup? And how much is in there?

I haven’t done the calculations yet. Wanted to put the problem out and see if my intuition about this matches anyone else’s, and how close that might be to right. Or at least calculated. I suspect it’s one of a particular kind of problem, though.

Autocorrected Monkeys and Pulled Tea


The Twop Twips account on Twitter — I’m not sure how to characterize what it is exactly, but friends retweet it often enough — had the above advice about the infinite monkeys problem, and what seems to me correct advice that turning on autocorrect will get them to write the works of Shakespeare more quickly. And then John Kovaleski’s monkey-featuring comic strip Bo Nanas featured the infinite monkey problem today, so obviously I have to spend more time thinking of it.

It seems fair that monkeys with autocorrect will be more likely to hit a word than a monkey without will be. Let’s try something simpler than Shakespeare and just consider the chance of typing the word “the”, and to keep the numbers friendly let’s imagine that the keyboard has just the letters and a space bar. We’ll not care about punctuation or numbers; that’s what copy editors would be for, if anyone had been employed as a copy editor since 1996, when someone in the budgeting office discovered there was autocorrect.

Anyway, there’s 27 characters on this truncated keyboard, and if the monkeys were equally likely to hit any one of them, then, there’d be 27 times 27 times 27 — that is, 19,683 — different three-character strings they might hit. Exactly one of them is the desired word “the”. So, roughly, we would expect the monkey to get the word right one time in each 19,683 attempts at a three-character string. (We wouldn’t have to wait quite so long if we’ll accept the monkey as writing continuously and pluck out three characters in a row wherever they appear, but that’s more work than I feel like doing, and I doubt it would significantly change the qualitative results, of how much faster it’d be if autocorrect were on.)

But how many tries would be needed to hit a word that gets autocorrected to “the”? And here we get into the mysteries of the English language. I’d be surprised by a spell checker that couldn’t figure out “teh” probably means “the”. Similarly “hte” should get back to “the”. So we can suppose the five other permutations of the letters in “the” will be autocorrected. So there’s six different strings of the 19,683 possibilities that will get fixed to “the”. The monkey has one chance in 3280.5 of getting one of them and so, on average, the monkey can be expected to be right once in every 3281 attempts.

But there’s other typos possible: “thw” is probably just my finger slipping, and “ghe” isn’t too implausible either. At least my spell checker recognizes both as most likely meant to be “the”. Let’s suppose that a spell checker can get to the right word if any one letter is mistaken. This means that there are some 78 other three-character strings that would get fixed to “the”, for a total of 84 possible three-character strings which are either “the” or would get autocorrected to “the”. With that many, there’s one chance in a touch more than 234 that a three-character string will get corrected to “the”, and we have to wait, considering, not very long at all.

It gets better if two-character errors are allowed, but I can’t make myself believe that the spell check will turn “yje” into “the”, and that’s something which might be typed if you just had the right hand on the wrong keys. My checker hasn’t got any idea what “yje” is supposed to be anyway, so, one wrong letter is probably the limit.

Except. “tie” is one character wrong for “the” and no spell checker will protest “tie”. Similarly “she” and “thy” and a couple of other words. And it’d be a bit much to expect “t e” or “ he” to be turned back into “the” even though both are just the one keystroke off. And a spell checker would probably suppose that “tht” is a typo for “that”. It’s hard to guess how many of the one-character-off words will not actually be caught. Let’s say that maybe half the one-character-off words will be corrected to “the”; that’s still a pretty good 39 one-character misspellings, plus five permutations, plus the correct spelling or 45 candidate three-character strings for autocorrect to get. So our monkey has something like one chance in 450 of getting “the” in banging on the keyboard three times.

For four-letter words there are many more combinations — 531,441, if we just list the strings of our 27 allowed characters — but then there are more strings which would get autocorrected. Let’s say we want the string “thus”; there are 23 ways to arrange those letters in addition to the correct one. And there are 104 one-character-off strings; supposing that half of them will get us to “thus”, then, there’s 76 strings that get one to the desired “thus”. That’s a pretty dismal one chance in about 7,000 of typing one of them, unfortunately. Things get a little better if we suppose that some two-character errors are going to be corrected, although I can’t find one which my spell checker will accept right now, and if a single error and a transposition are viable.

With longer words yet there’s more chances for spell checker forgiveness: you can get pretty far off “accommodate” or “aneurysm” and still be saved by the spell checker, which is good for me as I last spelled “accommodate” correctly sometime in 1992, and I thought it looked wrong then.

So the conclusion has to be: you’ll get a bit of an improvement in speed by turning on autocorrect, for the obvious reason that you’re more likely to get one right out of 450 than you are to get one right out of 19,000. But it’s not going to help you very much; the number of ways to spell things so completely wrong that not even spell check can find you just grows far too rapidly to be helped. If I get a little bored I might work out the chance of getting a permutation-or-one-off for strings of different lengths.

And your monkey might be ill-served by autocorrect anyway. When I lived in Singapore I’d occasionally have teh tarik (“pulled tea”), black tea with sugar and milk tossed back and forth until it’s nice and frothy. It’s a fine drink but hard to write back home about because even if you get past the spell checker, the reader assumes the “teh” is a typo and mentally corrects for it. When this came up I’d include a ritual emphasis that I actually meant what I wrote, but you see the problem. Fortunately Shakespeare wrote relatively little about southeast Asian teas, but if you wanted to expand the infinite monkey problem to the problem of guiding tourists through Singapore, you’d have to turn the autocorrect off to have any hope of success.