Solution (source code)

= Solution

For two simple <statistical hypotheses> with joint <probability density functions> $g_0$ and $g_1$, fix a <significance level> $\alpha$. A <randomized statistical test> $\varphi(x)$ is the conditional <probability> of rejection given the data. Choose $k\geq0$ and, if necessary, randomization on the equality set so that
$$
\varphi_*(x)=\begin{cases}1,&g_1(x)>kg_0(x),\\0,&g_1(x)<kg_0(x),\\\gamma(x)\in[0,1],&g_1(x)=kg_0(x),\end{cases}
\qquad \mathbb E_0\varphi_*=\alpha.
$$
The <Neyman-Pearson lemma> says that this is a <most powerful test> among all tests with <test size> at most $\alpha$:
$$
\boxed{\mathbb E_1\varphi\leq\mathbb E_1\varphi_*\quad\text{whenever}\quad\mathbb E_0\varphi\leq\alpha.}
$$
Thus the optimal ordering rejects where the alternative-to-null <likelihood ratio> is largest. On null-impossible observations with $g_1>0$, the rejection probability is one. Randomization is dispensable whenever an ordinary threshold already attains the required <test size>.