What is the optimal way to wash a dirty vessel with a fixed amount of water and time? This question came up for me as I was trying to wash out some milk from my toddler's cup with a bottle of water that I had in my car. I do this every day -- drive him to school while he drinks milk, and then wash out his sippy cup as much as possible so that it's clean for him to use in the afternoon when I pick him up.
Imagine that I have a sippy cup that when filled with a liquid and poured out, is left with volume $\mathit{D}$ of that liquid stuck to the inside. To start with, this is milk -- I've poured out as much milk as I can, but $\mathit{D}$ milk is still stuck to the inside of the cup. I have a finite amount $\mathit{W}$ of clean water, and a integer number of operations $\mathit{T}$ which is the number of different "pour in a quantity of clean water, shake the cup to mix up the milk with the water, and pour out the washing liquid" operations I can perform in the time that I have. 
Every time I pour in water, shake up the cup, and pour out the water, the same volume $\mathit{D}$ of this mixture sticks to the inside of the container. This volume $\mathit{D}$ is a property of the container. This means that no matter how many times I pour in water, shake, and pour out, there will always be some amount of milk left in the container (which can approach zero as the amount of water and the number of washings approaches infinity). Assume that each mixing operation mixes the remaining milk perfectly with the water that's introduced.
Doing this in my car, I was torn between two ideas. One theory is to pour in very small amounts of water at the beginning, to waste the smallest amount of water when the cup is at its dirtiest. The other theory is to use large amounts of water up front, to get the bulk of the milk out early, and use the final washings to get the cup as clean as possible. I was unable to intuit which theory was more correct.
Mathematically, what strategy minimizes the milk remaining in the container after $\mathit{T}$ washings? After these $\mathit{T}$ washings, how much milk remains in the milk-water mixture stuck to the inside of the cup?
Thanks very much for your help! I will actually use the answer to guide my behavior next time!
 A: You want to pour in the same amount $\frac WT$ of water each time.  
Each time you pour in $z$ water, mix and dump, the concentration is reduced by a factor $\frac D{D+z}$.  Because multiplication is commutative, it doesn't matter what order you put the volumes in, just the list of volumes you use.
The easiest way to see it is to let $T=2$.  We might as well measure the water in fractions of $W$, which makes $W=1$.  Let us pour in $x$ the first time and $1-x$ the second time.  After the first time you have volume $D$ left with concentration $\frac D{D+x}$.  After the second you have volume $D$ left with concentration $\frac D{(D+x)(D+1-x)}$  To have the best cleaning we want to maximize $(D+x)(D+1-x)=D^2-x^2+D+x$.  The usual technique maximizes this at $x=\frac 12$.  This shows that given two unequal pours, the final concentration will be reduced by making them equal.  Extending this, we want all the pours to be equal.
A: Suppose you perform a cleaning operation using $X$ water. Then the total fluid inside the cup is $X + D$. After pouring out the excess, the remaining amount inside the cup is $D$, so the ratio of milk inside at the beginning to milk inside at the end is equal to $\frac{X+D}{D}$, or $\frac{X}{D}+1$.
Suppose your cleaning operations use water amounts $X_1, X_2, \ldots, X_T$ which sum up to $W$.
Then the ratio of milk inside at the beginning to milk inside at the end is exactly
$$(\frac{X_1}D+1)(\frac{X_2}D+1)\cdots(\frac{X_T}D+1).$$
To maximize this ratio, we need all these $X_i$ to be equal, because if two were unequal, we could replace both by their average to get a better ratio (see later).
If all the $X_i$ are equal, then they're all equal to $W/T$.
So the best method to clean the cup will cause the amount of milk at the end to be
$$\frac{D}{\left(1+\frac WD\cdot\frac 1T\right)^T}.$$
Note that as you make $T$ larger and larger, the bottle will get cleaner and cleaner, but as $T$ goes to infinity the bottle won't become perfectly clean. There's a limit to how clean the bottle can be, and the minimal remaining amount of milk is equal to $$De^{-\frac WD}.$$
(To pass that limit, just use some more water.)

To elaborate on why using equal amounts of water each time is the best approach given fixed total water and operations:
Suppose you use two different water amounts $X$ and $Y$ to clean two times.
Then the cleaning ratio is equal to $(\frac XD + 1)(\frac YD+1) = \frac {XY}{D^2} + \frac{X+Y}D + 1$.
But now suppose you split the water you used evenly instead, by cleaning with the amount $\frac 12(X+Y)$ twice. That uses the same amount of water in total, but the new cleaning ratio is
$(\frac {X+Y}{2D} + 1)^2 = \frac{(X+Y)^2}{4D^2} + \frac{X+Y}{D} + 1$.
Okay, what's the difference? The difference between the new and old cleaning ratio is exactly
$$\frac{(X+Y)^2-4XY}{4D^2} = \frac{X^2+2XY+Y^2-4XY}{4D^2} = \frac{X^2-2XY+Y^2}{4D^2} =  \frac{(X-Y)^2}{(2D)^2}.$$
The numerator and denominator are both the square of a nonzero number, so the difference is indeed positive. Hence the new cleaning ratio is better, and averaging our water amounts between both cleaning cycles did actually help.
