     • date post

07-Aug-2019
• Category

Documents

• view

219

0

Embed Size (px)

Transcript of Deterministic Finite Automata - Research School of ... Deterministic Finite Automata COMP2600...

• Deterministic Finite Automata

COMP2600 — Formal Methods for Software Engineering

Katya Lebedeva

Australian National University

Semester 2, 2016

Slides by Ranald Clouston and Katya Lebedeva.

COMP 2600 — Deterministic Finite Automata 1

• A Deterministic Finite State Automaton (DFA) is a quintuple

(Σ,S,s0,F,δ)

where

1. Σ is a finite set of input symbols (the alphabet)

2. S is a finite state of states

3. s0 is the start (or initial) state: s0 ∈ S

4. F is a set of final (or accepting) states: F ⊆ S

5. δ : S×Σ → S is a transition function

COMP 2600 — Deterministic Finite Automata 2

• Example

����- S0 @ @R 0��61 ����S1 �

��1 ��� 0

����� ��S2� 1 ��

0

• alphabet - {0,1}

• states - {S0,S1,S2}

• initial state - S0

• final states - {S2}

• transition function

0 1 S0 S1 S0 S1 S1 S2 S2 S1 S0

Note that the actual names of states are irrelevant.

COMP 2600 — Deterministic Finite Automata 3

• Transition Function

as a diagram

����- S0 @@R

0��61 ����S1 � ��1 ���

0

����� ��S2� 1 ��

0

as a transition table 0 1 S0 S1 S0 S1 S1 S2 S2 S1 S0

δ(S0,0) = S1 δ(S0,1) = S0 δ(S1,0) = S1 δ(S1,1) = S2 δ(S2,0) = S1 δ(S2,1) = S0

COMP 2600 — Deterministic Finite Automata 4

• Extended Transition Function

We want to extend δ to multiple transitions:

δ : S×Σ → S

δ∗ : S×Σ∗ → S

����- S0 @@R

0��61 ����S1 � ��1 ���

0

����� ��S2� 1 ��

0

Input 0101 takes the DFA from S0 to S2. Hence δ∗(S0,0101) = S2. Input 1011 takes the DFA from S1 to S0. Hence δ∗(S1,1011) = S0.

COMP 2600 — Deterministic Finite Automata 5

• δ∗(s,w) = q denotes that starting at state s, the input string w will take the automaton to state q.

In other words:

If

w = a1a2 . . .an

and

δ(s,a1) = p1

δ(p1,a2) = p2

. . .

δ(pn−1,an) = q

then

δ∗(s,a1a2 . . .an) = q

COMP 2600 — Deterministic Finite Automata 6

• Definition by induction

Basis: δ∗(s,ε) = s (1)

Induction: δ∗(s,aα) = δ∗(δ(s,a),α) (2)

Note that a ∈ Σ (i.e. a is a symbol) and α is a string.

Thus δ∗ is defined by breaking the input string into a single symbol followed by a string. We exploit the fact that strings are defined inductively!

Since we informally thinking about δ∗ as operating on a string, it should not matter how we break the input string for δ∗. Indeed, we can show that for any state s and strings α and β the following holds:

δ∗(s,αβ) = δ∗(δ∗(s,α),β)

COMP 2600 — Deterministic Finite Automata 7

• Append Theorem

δ∗(s,αβ) = δ∗(δ∗(s,α),β)

Proof:

By induction on the length of α.

Base case: α = ε

LHS = δ∗(s,εβ) = δ∗(s,β)

RHS = δ∗(δ∗(s,ε),β)

= δ∗(s,β) = LHS (by (1))

COMP 2600 — Deterministic Finite Automata 8

• Inductive case:

Suppose δ∗(s,αβ) = δ∗(δ∗(s,α),β) (IH)

LHS = δ∗(s,(aα)β)

= δ∗(s,a(αβ))

= δ∗(δ(s,a),αβ) (by (2))

= δ∗(δ∗(δ(s,a),α),β) (by IH)

RHS = δ∗(δ∗(s,aα),β)

= δ∗(δ∗(δ(s,a),α),β) (by (2))

Corollary: when β is a single symbol b

δ∗(s,αb) = δ(δ∗(s,α),b)

COMP 2600 — Deterministic Finite Automata 9

• Example:

����- S0 @@R

0��61 ����S1 � ��1 ���

0

����� ��S2� 1 � �

0

δ∗(S1,1011) = δ∗(δ(S1,1),011)

= δ∗(S2,011)

= δ∗(S1,11)

= δ∗(S2,1)

= δ∗(S0,ε)

= S0

COMP 2600 — Deterministic Finite Automata 10

• Language accepted by a DFA

We say a DFA accepts a string if, starting from the start state, it terminates in

one of the final states. More precisely, let A = (S,Σ,δ,s0,F) be a DFA and w be a string in Σ∗.

We say w is accepted by A if

δ∗(s0,w) ∈ F

The language accepted by A is the set of all strings accepted by A:

L(A) = {w ∈ Σ∗ | δ∗(s0,w) ∈ F}

That is, w ∈ L(A) iff δ∗(s0,w) ∈ F .

COMP 2600 — Deterministic Finite Automata 11

• A1: ����- S0 @ @R 0��61 ����S1 �

��1 ��� 0

����� ��S2� 1 ��

0

0011101 takes the machine from state S0 through the sequence of states S1, S1, S2, S0, S0, S1 to the final state S2

δ∗(S0,0011101) = δ∗(S1,011101) = δ∗(S1,11101) = . . .= δ∗(S1,1) = S2

COMP 2600 — Deterministic Finite Automata 12

• A1: ����- S0 @ @R 0��61 ����S1 �

��1 ��� 0

����� ��S2� 1 ��

0

Strings accepted by A1: 01, 001, 101, 0001, 0101, 00101101 . . .

Strings not accepted by A1: ε, 0, 1, 00, 10, 11, 100 . . .

What is the difference between strings that are accepted by A1 and that are not?

How do we justify our guess at this answer?

COMP 2600 — Deterministic Finite Automata 13

• To prove that a machine M accepts the language that is characterised by a predicate P:

1. prove that any string satisfying P is accepted by M

2. prove that any string accepted by M satisfies P

Our claim: A1 accepts the language with only words finishing with 01.

We need to prove the following:

1. If a string ends in 01, then it is accepted by A1. I.e.:

for all α ∈ Σ∗, δ∗(S0,α01) ∈ F

2. If a string is accepted by A1, then it ends in 01. I.e.:

for all w ∈ Σ∗, if δ∗(S0,w) ∈ F then exists α ∈ Σ∗. w = α01

COMP 2600 — Deterministic Finite Automata 14

• Part 1: for all α ∈ Σ∗, δ∗(S0,α01) = S2 By the “append” theorem,

δ∗(S0,α01) = δ∗(δ∗(S0,α),01) A1: ����- S0 @@R

0��61 ����S1 � ��1 ���

0

����� ��S2� 1 ��

0

Observe that δ∗(s,01) = S2 holds for all s ∈ S.

Indeed, there exist only three possible cases:

δ∗(S0,01) = δ∗(S1,1) = S2 δ∗(S1,01) = δ∗(S1,1) = S2 δ∗(S2,01) = δ∗(S1,1) = S2

Hence,

δ∗(S0,α01) = δ∗(δ∗(S0,α),01) = S2

COMP 2600 — Deterministic Finite Automata 15

• Part 2: for all w if δ∗(S0,w) = S2 then exists α ∈ Σ∗. w = α01

• w = ε δ∗(S0,ε) = S0 and S0 is not equal to S2. Hence, the antecedent is false and the claim is true by the rules of propositional logic.

• |w|= 1 (w is a single symbol) The antecedent is false because there is no single step path from S0 to S2. Hence, the claim is true.

• |w|> 1. There are paths from S0 to S2 of two or more steps. Suppose δ∗(S0,αxy) = S2. By the corollary to the “append” theorem,

δ(δ∗(S0,αx),y) = S2.

����- S0 @@R

0��61 ����S1 � ��1 ���

0

����� ��S2� 1 ��

0

By the definition of δ, y must be 1 and δ∗(S0,αx) must be S1. Similarly, since δ(δ∗(S0,α),x) = S1, x is 0 by the definition of δ. �

COMP 2600 — Deterministic Finite Automata 16

• Limitations of DFAs

What class of languages can be recognised by DFAs ?

A very important example:

Consider this language: L = { anbn | n ∈ N}

That is, L = {ε,ab,aabb,aaabbb,a4b4,a5b5, ...}

This language cannot be recognised by any finite state automaton!

This is because DFA cannot remember how many ‘a’s it has seen.

COMP 2600 — Deterministic Finite Automata 17

Suppose A is a DFA that accepts L. That is L = L(A).

Each of the following expressions denotes a state of A

δ∗(S0,a), δ∗(S0,aa), δ∗(S0,a3) . . .

Since this list is infinite and the number of states in A is finite, some of these expressions must denote the same state.

Choose distinct i and j such that δ∗(S0,ai) = δ∗(S0,a j).

What we have done here is pick two initial string fragments that the automaton will not

be able to distinguish in terms of what is allowed for the rest of the string

COMP 2600 — Deterministic Finite Automata 18

• Since aibi is accepted, we know

δ∗(S0,aibi) ∈ F

By the “append” theorem

δ∗(S0,aibi) = δ∗(δ∗(S0,ai),bi) ∈ F

Since δ∗(S0,ai) = δ∗(S0,a j)

δ∗(δ∗(S0,a j),bi) ∈ F

δ∗(δ∗(S0,a j),bi) = δ∗(S0,a jbi) ∈ F

Thus a jbi is accepted by A. But a jbi is not in L, contradicting the initial assumption.

COMP 2600 — Deterministic Finite Automata 19

• Pigeon-Hole Principle

We used the pigeon-hole principle in the preceding proof:

If we have more pigeons than pigeon-holes, then at least two pigeons must

be sharing a