A quick review of Lecture 25.
You need to know this fact but we won’t ask you anything about the “only if” direction from DFAs/NFAs to regular expressions.
Languages represented by NFAs, DFAs, and regular expressions are called regular languages.
Regular, context-free, and other languages.
How do we prove that all finite languages are regular? By showing how to construct a DFA/NFA/RegEx for every finite language!
How do we prove that all regular languages are context-free? By showing how to construct a CFG for every regular language!
We saw in Lecture 21 that the language $B$ of all binary palindromes can be represented by a CFG. We also said that $B$ can’t be represented by any regular expression. How would you prove that?
This is the intuition for why $B$ is not regular. Let’s see how to turn this intuition into a formal proof.
We choose an infinite set $S$ of prefixes. This choice must ensure that for every pair of prefixes in $s_a\neq s_b\in S$, there is a suffix $t$ such that one of of $s_at, s_bt$ is in $B$ but not the other.
Suppose that some DFA $M$ recognizes $B$. We show $M$ accepts or rejects a string it shouldn’t. Consider the set $S = \{0^n1 : n \geq 0 \}$.
Since there are finitely many states in $M$ and infinitely many strings in $S$, there exist strings $0^a1 \in S$ and $0^b1 \in S$ with $a\neq b$ that end in the same state of $M$.
Important: We don’t get to choose $a$ and $b$! We just know they exist.
Now, consider appending $0^a$ to both strings.
Since $0^a1$ and $0^b1$ end in the same state, so do $0^a10^a$ and $0^b10^a$, call it $q$. But then $M$ must make a mistake: $q$ needs to be an accept state since $0^a10^a \in B$, but then $M$ would accept $0^b10^a \not\in B$, which is an error. $\square$
A proof template for showing that a language is not regular.
① Suppose for contradiction that some DFA $M$ recognizes $L$.
② Consider the set $S = $ {$\ldots$}.
③ Since $S$ is infinite and $M$ has finitely many states, there must be two strings $s_a, s_b$ $\in S$ such that $s_a \neq s_b$ and both end in the same state of $M$.
④ Consider appending $t$ to both $s_a$ and $s_b$.
⑤ Since $s_a$ and $s_b$ end in the same state of $M$, then $s_at$ and $s_bt$ also end in the same state $q$ of $M$. Since $s_at\in L$ and $s_bt\not\in L$, $M$ does not recognize $L$.
⑥ Since $M$ was arbitrary, no DFA recognizes $L$.
$S$ must be infinite, and for every pair of prefixes $s_a\neq s_b\in S$, there is a suffix $t$ such that one of of $s_at, s_bt$ is in $L$ but not the other.
We don’t get to choose $s_a$ and $s_b$!
$t$ should be an accept suffix for $s_a$ but not $s_b$.
Suppose for contradiction that some DFA $M$ recognizes $L$.
Consider the set $S = $ $\{0^n : n\geq 0 \}$.
Since $S$ is infinite and $M$ has finitely many states, there must be two strings $0^a, 0^b$ $\in S$ with $a \neq b$ that both end in the same state of $M$.
Consider appending $1^a$ to both $0^a$ and $0^b$.
Since $0^a$ and $0^b$ end in the same state of $M$, then $0^a1^a$ and $0^b1^a$ also end in the same state $q$ of $M$. Since $0^a1^a\in L$ and $0^b1^a\not\in L$, $M$ does not recognize $L$.
Since $M$ was arbitrary, no DFA recognizes $L$.
Suppose for contradiction that some DFA $M$ recognizes $L$.
Consider the set $S = $ $\{(^n : n\geq 0 \}$.
Since $S$ is infinite and $M$ has finitely many states, there must be two strings $(^a, (^b$ $\in S$ with $a \neq b$ that both end in the same state of $M$.
Consider appending $)^a$ to both $(^a$ and $(^b$.
Since $(^a$ and $(^b$ end in the same state of $M$, then $(^a)^a$ and $(^b)^a$ also end in the same state $q$ of $M$. Since $(^a)^a\in L$ and $(^b)^a\not\in L$, $M$ does not recognize $L$.
Since $M$ was arbitrary, no DFA recognizes $L$.
Suppose that for a language $L$, the set $S$ is a largest set of prefix strings with the property that for every pair $s_a \neq s_b \in S$, there is some string $t$ such that one of $s_at, s_bt$ is in $L$ but the other isn’t.
If $S$ is infinite, then $L$ is not regular.
If $S$ is finite, then the minimal DFA for $L$ has precisely $|S|$ states, one reached by each member of $S$.