Solution (source code)

= Solution

Write $S_m=\sum_{i=1}^m x_i$ and $S=S_N$. Use shape-rate notation for the <Gamma distribution>, as in the authoritative PDF: shape $a$ and rate $b$ give a density proportional to $z^{a-1}e^{-bz}$. Conditional independence of the <Poisson distributions> gives a <likelihood function> proportional to
$$
\lambda^{S_m}e^{-m\lambda}\phi^{S-S_m}e^{-(N-m)\phi}.
$$
The product of factorial terms depends only on the data and can be absorbed into the normalizing constant. Multiplying by the two independent <Gamma distribution> prior kernels and the uniform prior on the possible indices gives the <Poisson count change-point model with gamma priors>:
$$
\boxed{\pi(\lambda,\phi,m\mid x)\propto\lambda^{\alpha+S_m-1}e^{-(\beta+m)\lambda}\phi^{\gamma+S-S_m-1}e^{-(\delta+N-m)\phi}\,\mathbf1_{\{\lambda>0,\phi>0,\ m\in\{1,\ldots,N\}\}}.}
$$
Because the hyperparameters are positive, each possible index gives finite positive gamma integrals, and summing over the finitely many indices yields a proper <posterior distribution>. At $m=N$ the second likelihood factor is one, so the posterior law of its unused rate $\phi$ remains its prior $\operatorname{Gamma}(\gamma,\delta)$.