Cobb–Douglas utility maximized by spending a "fixed fraction of income on each good"? Consider a Cobb–Douglas utility function having the form
$$u(x) = \prod_{j=1}^n x_j^{a_j} $$
where $x$ is an allocation vector and $a_j$ are utility parameters with $\sum a_j = 1$. My question has to do with the demand of a buyer with a Cobb–Douglas utility function and fixed prices budget. That is, $$\arg \max_x \lbrace u(x) : \pi^T x \leq w \rbrace$$
where $\pi$ is a fixed price vector and $w$ is the budget.
This is easy to solve, but I am confused by the following claim, which I read in an optimization textbook [1]:

It is not difficult to show that a trader with a Cobb–Douglas utility function spends a fixed fraction of her income on each good.

This is clearly true when $a_j = 1/n, \forall j$ and the prices are the same.
But suppose $n = 2$, $\pi = (1, 1)$, $w = 1$, and $a = 0.8, 0.2$. Then &quot;spending a fixed fraction of the budget on each good&quot; would mean spending $w / n = 0.5$ on each good, or buying $0.5$ units of each good, implying $x^* = (0.5, 0.5)$. This is clearly suboptimal, as the following table of values shows:
 x_1  x_2  u(x)
 0.0  1.0  0.0
 0.1  0.9  0.155185
 0.2  0.8  0.263902
 0.3  0.7  0.355399
 0.4  0.6  0.433789
 0.5  0.5  0.5
 0.6  0.4  0.553265
 0.7  0.3  0.590885
 0.8  0.2  0.606287   (*)
 0.9  0.1  0.579955
 1.0  0.0  0.0

Instead, the maximum is at $x = (0.8, 0.2)$, which I would describe verbally as

A trader with a Cobb–Douglas utility function allocates each good in proportion to its utility per unit cost.

In this example, resource 1 yields $a_1 / \pi_1 = 0.8$ utils per dollar, resource 2 yields $0.2$ utils per dollar, and the optimal allocation is a scalar times $(0.8, 0.2)$.
Is my interpretation correct? Is the textbook's interpretation quoted above correct? If both are correct, what explains the discrepancy in the example above?
Please note that I am not asking how to compute the demand of a trader with a Cobb–Douglas utility function. I am asking about the specific claim that the trader spends a &quot;fixed fraction of her income&quot; on each product.

[1] Nisan, Noam, Tim Roughgarden, Éva Tardos, and Vijay V. Vazirani, eds. 2007.
Algorithmic Game Theory. Cambridge University Press.
A &quot;fixed fraction&quot; doesn't mean an &quot;equal fraction&quot;, or at least that's not the intended meaning.
It can be easily verified that the solution to
\begin{equation}
\max_{x_1,x_2}\;x_1^{a_1}x_2^{a_2}\qquad\text{s.t.}\; \pi_1x_1+\pi_2x_2\le w
\end{equation}
is
\begin{equation}
x_1^*=\frac{a_1}{a_1+a_2}\frac{w}{\pi_1}\quad\text{and}\quad x_2^*=\frac{a_2}{a_1+a_2}\frac{w}{\pi_2}.
\end{equation}
Plugging in the values you used: $a_1=0.8,a_2=0.2,\pi_1=\pi_2=1$, the solution is consistent with your numerical simulation.
Generalizing to the $n$-goods case (with $\sum_ia_i=1$), the demand for $x_i$ is
\begin{equation}
x_i^*=\frac{a_i}{\pi_i}w,
\end{equation}
where the &quot;fixed&quot; fraction refers to $a_i/\pi_i$.