1. DFAs and NFAs

Introduction

Definitions

Concatenation

Strings

xyxy is y concatenated to xx, where xx and yy are either strings or characters.

Concatenation of strings is associative: brackets are not needed.

Languages

AB={xyxA and yB} AB = \{ xy \mid x\in A \text{ and } y\in B \}

i.e. A.map(a => B.map(b => a+b))

Language concatenation is associative.

{ϵ}\{ \epsilon \} is the identity language: {ϵ}A=A{ϵ}=A\{ \epsilon \}A = A\{ \epsilon \} = A.

Powers: Strings/Characters

ana^n is the string/character concatenated nn times

Base case: a0=ϵan+1=anaa^0 = \epsilon \therefore a^{n+1} = a^n a.

Powers: Languages

A0={ϵ}A1=AA=nNAn=An=A0A1A2A3A+=A1A2A3 \begin{aligned} A^0 &= \{ \epsilon \} \\ A^1 &= A \\ A^* &= \bigcup_{n\in N}{A^n} = A^n = A^0 \cup A^1 \cup A^2 \cup A^3 \cup \dots \\ A^+ &= A^1 \cup A^2 \cup A^3 \cup \dots \end{aligned}

Thus, AA^* will always contain the empty string, while A+A^+ will only contain it if it is a member of AA.

Properties
AA=A=AA==A \begin{aligned} A^* A^* &= A^{**} = A^* \\ \emptyset A &= \emptyset = A\emptyset \end{aligned}

Deterministic Finite Automata

M=(Q,Σ,δ,q0,F) M = (Q, \Sigma, \delta, q_0, F)

Where:

MM reading the input string wZw\in Z^* symbol by symbol. For each symbol, the transition function is run using with the current symbol and state. The input string is accepted if MM ends in an end state.

Extended Transition Function

δ^\hat{\delta} extends δ\delta to take in strings (and not just symbols) as the transition by processing each symbol in the string and passing the remaining substring recursively.

δ^:Q×ΣQδ^(q,ϵ)=qδ^(q,ax)=δ^(δ(q,a),x) where aΣ,xΣ and the input string is ax \begin{aligned} \hat{\delta}: Q\times \Sigma^* \rightarrow Q \\ \hat{\delta}(q, \epsilon) = q \\ \hat{\delta}(q, ax) = \hat{\delta}(\delta (q,a), x) \text{ where } a \in \Sigma, x \in \Sigma^* \text{ and the input string is } ax \end{aligned}

All finite languages are regular (e.g. OR every single string) but not all infinite languages are regular.

Regular languages are closed over:

Proving Regular Languages Are Closed under the Complement Operator

Let AΣA\subseteq \Sigma^* be regular. Show Aˉ\bar{A} is regular.

By their definitions, A=L(M)A = L(M) for some DFA M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta , q_0, F).

Swap accepting and non-accepting states:

Let M=(Q,Σ,δ,q0,QF)M' = (Q, \Sigma, \delta , q_0, Q - F). Now, show that L(M)=AˉL(M') = \bar{A}.

To do this, we first show that MM' is regular. This means that L(M)={wZδ^(q0,w)F}L(M) = \{ w \in Z^* \mid \hat{\delta}(q_0, w) \in F \}.

The first requirement, wZw\in Z^* is obviously fulfilled. The second bit will be:

δ^(q0,w)QF \hat{\delta}(q_0,w) \in Q-F

QFQ-F is the complement of FF, so: δ^(q0,w)F\hat{\delta}(q_0, w) \notin F

The definition of the extended transition function is δ^(q0,w)F\hat{\delta}(q_0, w)\in F, which is the complement of above. Thus, this means it satisfies the opposite of L(M)L(M):

wL(M)wL(M)wA \begin{aligned} w &\notin L(M) \\ w &\in \overline{L(M)} \\ w &\in A \end{aligned}

Intersection of Two Automata

Let A,BΣA, B \subseteq \Sigma^* be regular. Show that ABA \cap B will be regular.

A=L(M1)A = L(M_1) for DFA M1=(Q1,Σ,δ1,q1,F1)M_1 = (Q_1, \Sigma, \delta _1, q_1, F_1).

B=L(M1)B = L(M_1) for DFA M2=(Q2,Σ,δ2,q2,F2)M_2 = (Q_2, \Sigma, \delta _2,q_2,F_2 )

Only the alphabet is the same between the automata

Idea: keep track of the state M1M_1 is in and the state M2M_2 is in at the same time. Define the state as a pair of two states.

Let M=(Q1×Q2,Σ,δ,(q1,q2),F1×F2) \text{Let } M = (Q_1 \times Q_2, \Sigma, \delta, (q_1,q_2), F_1 \times F_2)

Now, we need to define the transition function where aΣa \in \Sigma is the transition symbol, wΣw \in \Sigma^* is the transition string, p1Q1p_1 \in Q_1 and p2Q2p_2 \in Q_2:

δ((p1,p2),a)=(δ1(p1,a),δ2(p2,a))δ^((p1,p2),w)=(δ1^(p1,w),δ2^(p2,w)) \begin{aligned} \delta((p_1,p_2), a) &= (\delta _1(p_1, a), \delta _2(p_2, a)) \\ \hat{\delta}((p_1, p_2), w) &= (\widehat{\delta_1}(p_1, w), \widehat{\delta_2}(p_2, w)) \end{aligned}

Need to show L(M)=L(M1)L(M2)L(M) = L(M_1) \cap L(M_2). For any string wΣw \in \Sigma^* where wL(M)w \in L(M):

δ^((q1,q2),w)F1×F2(δ1^(q1,w),δ2^(q2,w))F1×F2 \begin{aligned} \hat{\delta}((q_1, q_2), w) &\in F_1 \times F_2 \\ (\widehat{\delta_1}(q_1, w),\widehat{\delta_2}(q_2, w)) &\in F_1 \times F_2 \end{aligned}
δ1^(q1,w)F1 and δ2^(q2,w)F2wL(M1) and wL(M2)wL(M1)L(M2) as required \begin{aligned} \widehat{\delta_1}(q_1, w) \in F_1 \text{ and } \widehat{\delta_2}(q_2, w) \in F_2 \\ w\in L(M_1) \text{ and } w\in L(M_2) \\ w\in L(M_1) \cap L(M_2) \text{ as required} \end{aligned}

Union of Two Automata

Let A,BΣA, B \subseteq \Sigma^* be regular. Show that ABA \cup B will be regular.

ABAˉBˉA \cup B \leftrightarrow \overline{\bar{A} \cap \bar{B}} by De Morgan’s law. There is closure under the complement and intersection, so there must be closure under the union operation.

Non-Deterministic Finite Automata

NFA: a state can have zero or multiple transitions using a single symbol.

M=(Q,Σ,δ,q0,F) M = (Q, \Sigma, \delta , q_0, F)

δ:Q×ΣP(Q)\delta: Q\times \Sigma \rightarrow P(Q), where P(Q)P(Q) is the power set. That is, the transition function will return a set of states. If multiple states are returned, MM can move to any of those states. If the empty set is returned, MM will get stuck and that route should be ignored.

If any route leads to an accept state, the string should be accepted.

Extended Transition Relation

δ^:Q×ΣP(Q) \hat{\delta}: Q\times \Sigma^* \rightarrow P(Q)
δ^(q,ϵ)={q}δ^(q,ax)=pδ(q,a)δ^(p,x),aΣ,xΣ \begin{aligned} \hat{\delta}(q, \epsilon) &= \{ q \} \\ \hat{\delta}(q, ax) &= \bigcup_{p\in \delta(q, a)}{\hat{\delta}(p, x)}, a\in \Sigma, x\in \Sigma^* \end{aligned}

That is, for every state it can be in, calculate the possible transition(s) for the next symbol, put them all in a set, and repeat until the input string is empty.

ww is accepted by MM if and only if δ^(q0,w)F\hat{\delta}(q_0, w) \in F \neq \emptyset.

The language accepted by MM is the set of all strings where the above is true:

L(M)={wΣδ^(q0,w)F} L(M) = \{ w\in \Sigma^* \mid \hat{\delta}(q_0, w)\in F \neq \emptyset \}

NFDA to DFA Conversion Through Subset Construction

States become a set containing all states it could be in given the transitions. If it can be in the states {qx,qy,qz}\{ q_x, q_y, q_z \} then denote the state as qxyzq_{xyz}. Accept all states where the set contains any element from the accept states set. Add a new reject state with a self-transition under all symbols to ensure that every state has transitions for every symbol.

Proving Every NFA is Accepted by a DFA

M=(Q,Σ,δ,q0,F) M = (Q, \Sigma, \delta, q_0, F)

Idea: keep track of all states the NFA MM can be in while reading the input.

Subset automaton (DFA) M=(P(Q),Σ,δ,{q0},F)M' = (P(Q), \Sigma, \delta', \{ q_0 \}, F') where F={SQSF}F' = \{ S\subseteq Q \mid S \cap F \neq \emptyset \} (any state where one or more elements of the state contains an element from the accept states).

δ:P(Q)×ΣP(Q) \delta': P(Q) \times \Sigma \rightarrow P(Q)
δ(S,a)=qSδ(q,a)δ^(S,w)=qSδ^(q,w) \begin{aligned} \delta'(S, a) &= \bigcup_{q \in S}{\delta (q, a)} \\ \hat{\delta}'(S, w) &= \bigcup _{q \in S}{\hat{\delta}(q,w)} \end{aligned}

Now show that L(M)=L(M)L(M') = L(M). For any wΣw \in \Sigma^*, if wL(M)w \in L(M'):

The definition of L(M)L(M'): δ^({q0},w)F\hat{\delta'}(\{ q_0 \}, w) \in F'.

δ^({q0},w)F(q{q0}δ^(q,w))Fδ^(q0,w)F \begin{aligned} \hat{\delta'}(\{ q_0 \}, w) \cap F &\neq \emptyset \\ \left(\bigcup_{q\{ q_0 \}}{\hat{\delta}(q, w)}\right) \cap F &\neq \emptyset \\ \hat{\delta}(q_0, w) \cap F &\neq \emptyset \end{aligned}

Hence, wL(M)w \in L(M).

NDFA with ϵ\epsilon-Transitions

Example use case: union of two regular languages: one new start state, with two ϵ\epsilon transitions to each regular language.

ϵΣδ:Q×(Σ{ϵ})P(Q) \epsilon \notin \Sigma \\ \delta: Q \times (\Sigma \cup \{ \epsilon \}) \rightarrow P(Q)

ϵ\epsilon-closure of qq: E(q)={pQp is reachable from q with a sequence of ϵ transitions}E(q) = \{ p \in Q \mid p \text{ is reachable from } q \text{ with a sequence of } \epsilon \text{ transitions} \}.

The sequence can be of length zero, or be arbitrarily long. Note that the E(q)E(q) will always contain qq.

To convert an NDFA with ϵ\epsilon-transitions to a DFA, run the same process as for NFAs:

Extended Transition Relation

δ^(q,ϵ)=E(q)δ^(q,ax)=pE(q)pδ(q,a))δ^(p,x),aΣ,xΣ \begin{aligned} \hat{\delta}(q, \epsilon) &= E(q) \\ \hat{\delta}(q, ax) & = \bigcup_{p\in E(q)}{\bigcup_{p\in \delta(q, a))}{\hat{\delta}(p,x)}}, a\in \Sigma, x\in \Sigma^* \end{aligned}