CS2490 Session 4 - Slides

Definition of Deterministic Finite Automata (DFA)

  • Formal definition: Let Σ\Sigma be an alphabet. A deterministic finite automaton (DFA) AA over Σ\Sigma is defined by a 5-tuple containing four essential mathematical components:

    • A finite set QQ: where each element represents the name of a state.

    • An initial state q0Qq_0 \in Q: the starting state in which all computations begin.

    • A subset FQF \subseteq Q: where each element is an accepting state (also called a final state).

    • A transition function δ:Σ×QQ\delta : \Sigma \times Q \rightarrow Q: defining the state transition such that when in state qq and reading symbol aa, the automaton transitions to state δ(a,q)\delta(a, q).

  • DFA Example Structure:

    • Finite set of states: Q={init,state1,state2,trap}Q = \{\text{init}, \text{state1}, \text{state2}, \text{trap}\}

    • Initial state: q0=initq_0 = \text{init}

    • Set of transitions over alphabet Σ={0,1}\Sigma = \{0, 1\}:

    • δ(0,init)=init\delta(0, \text{init}) = \text{init}

    • δ(1,init)=state2\delta(1, \text{init}) = \text{state2}

    • δ(0,state1)=state2\delta(0, \text{state1}) = \text{state2}

    • δ(1,state1)=init\delta(1, \text{state1}) = \text{init}

    • δ(0,state2)=state1\delta(0, \text{state2}) = \text{state1}

    • δ(1,state2)=trap\delta(1, \text{state2}) = \text{trap}

    • δ(0,trap)=trap\delta(0, \text{trap}) = \text{trap}

    • δ(1,trap)=trap\delta(1, \text{trap}) = \text{trap}

Computation and Acceptance

  • Computation Definition:

    • Let A=(Σ,Q,δ,q0,F)A = (\Sigma, Q, \delta, q_0, F) be a DFA.

    • The computation (or run) of automaton AA on an input word w=w1w2wnΣw = w_1 w_2 \dots w_n \in \Sigma^* is defined as the sequence of states s0,s1,,snQs_0, s_1, \dots, s_n \in Q satisfying:

    • s0=q0s_0 = q_0

    • si=δ(wi,si1)s_i = \delta(w_i, s_{i-1}) for all 1in1 \le i \le n

    • Procedurally, computation means following the sequence of state transitions generated while reading symbols from ww sequentially from left to right until reaching the end of the word.

  • Acceptance Condition:

    • A computation run is successful when the final state sns_n belongs to the accepting set FF (snFs_n \in F).

    • When snFs_n \in F, automaton AA is said to accept the word ww.

Step-by-Step Computation Example

  • Input string w=110110011010110001{0,1}w = 110110011010110001 \in \{0, 1\}^*

  • Full trace of state transitions step by step:

    • Step 0 (Start): Start in initial state init\text{init}. Sequence: init\text{init}

    • Step 1 (Read 11): δ(1,init)=state2\delta(1, \text{init}) = \text{state2}. Sequence: init,state2\text{init}, \text{state2}

    • Step 2 (Read 11): δ(1,state2)=state1\delta(1, \text{state2}) = \text{state1}. Sequence: init,state2,state1\text{init}, \text{state2}, \text{state1}

    • Step 3 (Read 00): δ(0,state1)=state2\delta(0, \text{state1}) = \text{state2}. Sequence: init,state2,state1,state2\text{init}, \text{state2}, \text{state1}, \text{state2}

    • Step 4 (Read 11): δ(1,state2)=state1\delta(1, \text{state2}) = \text{state1}. Sequence: init,state2,state1,state2,state1\text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}

    • Step 5 (Read 11): δ(1,state1)=init\delta(1, \text{state1}) = \text{init}. Sequence: init,state2,state1,state2,state1,init\text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}

    • Step 6 (Read 00): δ(0,init)=init\delta(0, \text{init}) = \text{init}. Sequence: init,state2,state1,state2,state1,init,init\text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}, \text{init}

    • Step 7 (Read 00): δ(0,init)=init\delta(0, \text{init}) = \text{init}. Sequence: init,state2,state1,state2,state1,init,init,init\text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}, \text{init}, \text{init}

    • Step 8 (Read 11): δ(1,init)=state2\delta(1, \text{init}) = \text{state2}. Sequence: init,state2,state1,state2,state1,init,init,init,state2\text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}, \text{init}, \text{init}, \text{state2}

    • Step 9 (Read 11): δ(1,state2)=state1\delta(1, \text{state2}) = \text{state1}. Sequence: init,state2,state1,state2,state1,init,init,init,state2,state1\text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}, \text{init}, \text{init}, \text{state2}, \text{state1}

    • Step 10 (Read 00): δ(0,state1)=state2\delta(0, \text{state1}) = \text{state2}. Sequence: init,state2,state1,state2,state1,init,init,init,state2,state1,state2\text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}, \text{init}, \text{init}, \text{state2}, \text{state1}, \text{state2}

    • Step 11 (Read 11): δ(1,state2)=state1\delta(1, \text{state2}) = \text{state1}. Sequence: init,state2,state1,state2,state1,init,init,init,state2,state1,state2,state1\text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}, \text{init}, \text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}

    • Step 12 (Read 00): δ(0,state1)=state2\delta(0, \text{state1}) = \text{state2}. Sequence: init,state2,state1,state2,state1,init,init,init,state2,state1,state2,state1,state2\text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}, \text{init}, \text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{state2}

    • Step 13 (Read 11): δ(1,state2)=state1\delta(1, \text{state2}) = \text{state1}. Sequence: init,state2,state1,state2,state1,init,init,init,state2,state1,state2,state1,state2,state1\text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}, \text{init}, \text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{state2}, \text{state1}

    • Step 14 (Read 11): δ(1,state1)=init\delta(1, \text{state1}) = \text{init}. Sequence: init,state2,state1,state2,state1,init,init,init,state2,state1,state2,state1,state2,state1,init\text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}, \text{init}, \text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}

    • Step 15 (Read 00): δ(0,init)=init\delta(0, \text{init}) = \text{init}. Sequence: init,state2,state1,state2,state1,init,init,init,state2,state1,state2,state1,state2,state1,init,init\text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}, \text{init}, \text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}, \text{init}

    • Step 16 (Read 00): δ(0,init)=init\delta(0, \text{init}) = \text{init}. Sequence: init,state2,state1,state2,state1,init,init,init,state2,state1,state2,state1,state2,state1,init,init,init\text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}, \text{init}, \text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}, \text{init}, \text{init}

    • Step 17 (Read 00): δ(0,init)=init\delta(0, \text{init}) = \text{init}. Sequence: init,state2,state1,state2,state1,init,init,init,state2,state1,state2,state1,state2,state1,init,init,init,init\text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}, \text{init}, \text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}, \text{init}, \text{init}, \text{init}

    • Step 18 (Read 11): δ(1,init)=state2\delta(1, \text{init}) = \text{state2}. Sequence: init,state2,state1,state2,state1,init,init,init,state2,state1,state2,state1,state2,state1,init,init,init,init,state2\text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}, \text{init}, \text{init}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{state2}, \text{state1}, \text{init}, \text{init}, \text{init}, \text{init}, \text{state2}

  • Ending state of computation: state2\text{state2}.

Extended Transition Function

  • Definition and Intuition:

    • Let A=(Σ,Q,δ,q0,F)A = (\Sigma, Q, \delta, q_0, F) be a DFA, and let wΣw \in \Sigma^* be a word over Σ\Sigma.

    • δ(w,q0)\delta^*(w, q_0) denotes the final state reached at the end of the run of AA on input word ww.

    • Generalizing to any state qQq \in Q, δ(w,q)\delta^*(w, q) represents the last state reached in the run of AA on word ww assuming qq were the starting state.

  • Inductive Mathematical Definition:

    • The extended transition function δ:Σ×QQ\delta^* : \Sigma^* \times Q \rightarrow Q is defined recursively as follows:

    • Base case: δ(ε,q)=q\delta^*(\varepsilon, q) = q for all qQq \in Q, where ε\varepsilon is the empty string.

    • Recursive step: δ(wa,q)=δ(a,δ(w,q))\delta^*(wa, q) = \delta(a, \delta^*(w, q)) for all aΣa \in \Sigma, wΣw \in \Sigma^*, and qQq \in Q

Languages Accepted by DFAs

  • Definition of Accepted Language:

    • Let A=(Σ,Q,δ,q0,F)A = (\Sigma, Q, \delta, q_0, F) be a DFA.

    • The language accepted by AA, denoted L(A)L(A), is the formal set of all words accepted by AA:     L(A)={wΣδ(w,q0)F}L(A) = \{w \in \Sigma^* \mid \delta^*(w, q_0) \in F\}

    • Terminology variants: L(A)L(A) is also called the language recognized by AA, or simply the language of AA

Parity Automaton Example

  • Automaton Definition:

    • State Set: Q={even # of 1’s,odd # of 1’s}Q = \{\text{even \# of 1's}, \text{odd \# of 1's}\}

    • Alphabet: Σ={0,1}\Sigma = \{0, 1\}

    • Initial State: q0=even # of 1’sq_0 = \text{even \# of 1's}

    • Accepting State Set: F={even # of 1’s}F = \{\text{even \# of 1's}\}

    • Transition Function Rules:

    • δ(0,even # of 1’s)=even # of 1’s\delta(0, \text{even \# of 1's}) = \text{even \# of 1's}

    • δ(1,even # of 1’s)=odd # of 1’s\delta(1, \text{even \# of 1's}) = \text{odd \# of 1's}

    • δ(0,odd # of 1’s)=odd # of 1’s\delta(0, \text{odd \# of 1's}) = \text{odd \# of 1's}

    • δ(1,odd # of 1’s)=even # of 1’s\delta(1, \text{odd \# of 1's}) = \text{even \# of 1's}

  • Target Language Claim:

    • Hypothesis: L(A)={w{0,1}w has an even number of 1’s}L(A) = \{w \in \{0, 1\}^* \mid w \text{ has an even number of 1's}\}

Rigorous Mathematical Proof for Parity Automaton

  • Proof Structure:

    • To prove equality L(A)={w{0,1}w has an even number of 1’s}L(A) = \{w \in \{0, 1\}^* \mid w \text{ has an even number of 1's}\}, two inclusions must be proven:

    • Direction 1: Every word accepted by AA has an even number of 11's (L(A){w{0,1}w has an even number of 1’s}L(A) \subseteq \{w \in \{0, 1\}^* \mid w \text{ has an even number of 1's}\}).

    • Direction 2: Every word with an even number of 11's is accepted by AA ($\ authorization {w \in {0, 1}^* \mid w \text{ has an even number of 1's}} \subseteq L(A)).\n- Key Lemma (Inductive Property):\n - Claim: For all n \in \mathbb{N},therunof, the run ofAonanywordon any wordwoflengthof lengthnendsinthestate"ends in the state "p \text{ # of 1's}",where", wherepistheparityofthenumberofis the parity of the number of1sin's inw\n - Proof of Key Lemma by Induction on n = |w|:\n - Base Case (n = 0):\n - |w| = 0 \implies w = \varepsilon\n - The count of 1sin's in\varepsilonisis0,whichiseven(, which is even (p = \text{even}).\n - The run on \varepsilonstartsandremainsintheinitialstatestarts and remains in the initial state\text{even # of 1's}.\n - Base case holds trivially.\n - Induction Step:\n - Induction Hypothesis: Assume the statement holds for all words of length n \in \mathbb{N}.\n - Let w = w_1 w_2 \dots w_n w_{n+1}beawordoflengthbe a word of lengthn + 1$.

      • Applying the induction hypothesis to prefix w1wnw_1 \dots w_n of length nn, the run on w1wnw_1 \dots w_n ends in state "p # of 1’sp \text{ \# of 1's}", where pp is the parity of the count of 11's in w1wnw_1 \dots w_n

      • The run on ww is one step longer than the run on w1wnw_1 \dots w_n, determined by symbol wn+1w_{n+1}:

      • If wn+1=0w_{n+1} = 0, the ending state remains unchanged ("p # of 1’sp \text{ \# of 1's}"), and pp is also the parity of the number of 11's in ww

      • If wn+1=1w_{n+1} = 1, the ending state switches to the opposite state, and the parity of the count of 11's in ww is the opposite of pp

      • In both cases, the parity of the total number of 11's in ww matches the ending state of the run.

  • Proof of Direction 1 (Soundness):

    • If AA accepts word ww, then by definition the run of AA on ww ends in accepting state even # of 1’s\text{even \# of 1's}.

    • By the key lemma, the parity of the number of 11's in ww must be even.

  • Proof of Direction 2 (Completeness):

    • If word ww contains an even number of 11's, then by the key lemma, the run of AA on ww ends in state even # of 1’s\text{even \# of 1's}.

    • Since even # of 1’sF\text{even \# of 1's} \in F, automaton AA accepts ww

Language Analysis Challenge

  • Deterministic Finite Automaton Details:

    • Initial state: init\text{init}

    • States: Q={init,state1,state2,trap}Q = \{\text{init}, \text{state1}, \text{state2}, \text{trap}\}

    • Transitions:

    • δ(0,init)=init\delta(0, \text{init}) = \text{init}, δ(1,init)=state2\delta(1, \text{init}) = \text{state2}

    • δ(0,state1)=state2\delta(0, \text{state1}) = \text{state2}, δ(1,state1)=init\delta(1, \text{state1}) = \text{init}

    • δ(0,state2)=state1\delta(0, \text{state2}) = \text{state1}, δ(1,state2)=trap\delta(1, \text{state2}) = \text{trap}

    • δ(0,trap)=trap\delta(0, \text{trap}) = \text{trap}, δ(1,trap)=trap\delta(1, \text{trap}) = \text{trap}

  • Language Question:

    • Formally analyze and determine L(A)L(A) for this four-state automaton.