Exercise 4.2.8: Let $L$ be a language. Define $half(L)$ to be the set of first halves of strings in $L$, that is $\{w| \text{ for some $x$ such that $|x|=|w|$. we have $wx$ in $L$}\}$. Prove that if $L$ is a regular language, so is $half(L)$.
[Introduction to automata theory, languages and computation- Ullman et. al]
Proof: Let $A$ be a DFA for $L$. We construct DFA $B$ for $half(L)$. The state of $B$ is of the form $[q,S]$, where:
- $q$ is the state A would be in after reading whatever input $B$ has read so far.
- $S$ is the set of states of $A$ such that $A$ can get from exactly these states to an accepting state by reading any input string whose length is the same as the length of the string $B$ has read so far.
It is important to realize that it is not necessary for $B$ to know how many inputs it has read so far; it keeps this information up-to-date each time it reads a new symbol. The rule that keeps things up to date is:
$$\delta_B([q,S],a) = [\delta_A(q,a),T]$$, where $T$ is the set of states $p$ of $A$ such that there is a transition from $p$ to any state of $S$ on any input symbol. In this manner, the first component continues to simulate $A$, while the second component now represents states that can reach an accepting state following a path that is one longer than the paths represented by $S$.
To complete the construction of $B$, we have only to specify:
- The initial state is $[q_0,F]$, that is, the initial state of $A$ and the accepting states of $A$. This choice reflects the situation when $A$ has read $0$ inputs: it is still in its initial state, and the accepting states are exactly the ones that can reach an accepting state on a path of length $0$.
- The accepting states of $B$ are those states $[q,S]$ such that $q$ is in $S$. The justification is that it is exactly these states that are reached by some string of length $n$, and there is some other string of length $n$ that will take state $q$ to an accepting state. $\square$