Solution (source code)

= Solution

Let $s=\sum_{j=1}^nx_j$. The <Bernoulli distribution> likelihood is proportional to $\theta^s(1-\theta)^{n-s}$. Multiplication by the <beta distribution> prior gives
$$
\pi(\theta\mid x)\propto\theta^{a+s-1}(1-\theta)^{b+n-s-1}.
$$
Normalizing with the <beta function> therefore gives
$$
\boxed{\theta\mid x\sim\operatorname{Beta}(a+s,b+n-s),\qquad\pi(\theta\mid x)=\frac{\theta^{a+s-1}(1-\theta)^{b+n-s-1}}{B(a+s,b+n-s)}.}
$$
The parameters remain positive. This is <Beta-binomial conjugacy>: successes add to the first shape parameter and failures to the second.