Proof (case distinction lemma)

Let $M = (Σ, Q, P)$ and $M_i = (Σ, Q_i, P_i)$. As before, assume $Q\cap Q_i = \emptyset$, $Q_i\cap Q_j = \set{q_\mathrm{H}}$ and $P_i(q_\mathrm{H}) = P_j(q_{\mathrm{H}})$ for all distinct $i,j\leq k$.

Let $q_{\mathrm{S},i}$ be the start state of $M_i$ and $\hat q_i$ be the answer states of $M$. Let $\hat P_i$ be the program $P_i$, replacing all instances of $q_{\mathrm{S},i}$ with $\hat q_i$. Define $$ \begin{align*} \hat M = \left(Σ, \quad Q \cup \bigcup_{i\leq k} (Q_i \setminus \set{q_{\mathrm{S},i}}), \quad P \cup \bigcup_{i\leq k} \hat P_i\right). \end{align*} $$ Then $\hat M$ performs the operation $g$.