I'm reading "Theory of Computation" by Michael Sipser and I've encountered a solution (provided by the book) that I don't understand.
The question:
Show that the collection of Turing-recognizable languages is closed under the operation of union.
The answer:
For any two Turing-Recognizable languages $L_1$ and $L_2$, let $M_1$ and $M_2$ be the $\textsf{TM}$s that recognize them. We construct a $\textsf{TM}$ $M'$ that recognize the union of $L_1$ and $L_2$:
On input $w$:
- Run $M_1$ and $M_2$ alternately on $w$ step by step. If either accpts, $accept$. If both half and reject, $reject$.
If either $M_1$ or $M_2$ accepts $w$, $M'$ accepts $w$ because the accepting $\textsf{TM}$ arrives to its accepting state after a finite number of steps. Note that if both $M_1$ and $M_2$ reject and either of them does so by looping, then $m'$ will loop.
Why does alternating Turing machines work for checking union? That sounds like a good approach for perfect shuffle, but not unions.
I'm also not sure why the book's answer for the same question for decidable languages (below) is not sufficient.
On input $w$:
- Run $M_1$ on $w$. If it accepts, $accept$.
- Run $M_2$ on $w$. If it accepts, $accept$. Otherwise, $reject$.
The difference between Turing-recognizable and decidable, as far as I can tell, is that deciders always halt.