Algemene voorwaarden Boksfit

advertisement

Finite Automata

Manipulating finite automata

Finite automata and regular languages

Radboud University Nijmegen

Deterministic Finite Automata

H. Geuvers and T. van Laarhoven

Institute for Computing and Information Sciences – Intelligent Systems

Radboud University Nijmegen

Version: fall 2014

H. Geuvers & T. van Laarhoven Version: fall 2014

Formal Languages, Grammars and Automata

1 / 17

Outline

Finite Automata

Manipulating finite automata

Finite automata and regular languages

Radboud University Nijmegen

Finite Automata

Manipulating finite automata

Finite automata and regular languages

H. Geuvers & T. van Laarhoven Version: fall 2014

Formal Languages, Grammars and Automata

2 / 17

Finite Automata

Manipulating finite automata

Finite automata and regular languages

Radboud University Nijmegen

Deterministic Finite State Automaton (DFA)

Intuition. Let Σ = { a , b } . Consider the DFA M : a , b a start q

0 b a q

1 b q

2

Letters a , b are the moves in the graph

A w ∈ Σ

∗ is a sequence of moves

Start state is indicated by ‘start → ’,

Accepting states by double circle

(there can be several accepting states)

The word abba is accepted , but baab is not accepted (rejected)

M = ( Q , q

0

, δ, F ) with Q = { q

0

, q

1

, q

2

} , F = { q

2

} and δ given by

δ a b q

0 q

0 q

1 q q

1

2 q

0 q

2 q q

2

2

H. Geuvers & T. van Laarhoven Version: fall 2014

Formal Languages, Grammars and Automata

4 / 17

Finite Automata

Manipulating finite automata

Finite automata and regular languages

Radboud University Nijmegen

Deterministic Finite Automata formally

M is a DFA over Σ if M = ( Q , q

0

, δ, F ) with

Σ is a finite alphabet

Q q

0

∈ Q

F ⊆ Q is a finite set of is the initial states state is a finite set of final states

δ : Q × Σ → Q is the transition function

Reading function δ

(often given by a table or a transition diagram)

: Q × Σ

→ Q (multi-step transition)

δ

( q , λ ) = q

δ

( q , a ) = δ ( q , a )

δ

( q , aw ) = δ

( δ ( q , a ) , w )

The language accepted by M , notation L ( M ), is:

L ( M ) = { w ∈ Σ

| δ

( q

0

, w ) ∈ F }

H. Geuvers & T. van Laarhoven Version: fall 2014

Formal Languages, Grammars and Automata

5 / 17

Finite Automata

Manipulating finite automata

Finite automata and regular languages

Reading words w ∈ Σ

Radboud University Nijmegen

Computation for δ

( q

0

, w ) in the example DFA. Take w = abba :

[ q

0

, abba ] ` [ δ ( q

0

, a ) , bba ] = [ q

0

, bba ]

` [ δ ( q

0

, b ) , ba ] = [ q

1

, ba ]

` [ δ ( q

1

, b ) , a ] = [ q

2

, a ]

` [ δ ( q

2

, a ) , λ ] = [ q

2

, λ ]

[ q

0

, aba ] ` [ δ ( q

0

, a ) , ba ] = [ q

0

, ba ]

` [ δ ( q

0

, b ) , a ] = [ q

1

, a ]

` [ δ ( q

1

, a ) , λ ] = [ q

0

, λ ]

So abba is acepted and aba is not accepted.

The language accepted by M (of the first slide) is regular. It is the language

L (( a + b )

∗ bb ( a + b )

) .

H. Geuvers & T. van Laarhoven Version: fall 2014

Formal Languages, Grammars and Automata

6 / 17

Finite Automata

Manipulating finite automata

Finite automata and regular languages

Radboud University Nijmegen

From transition table to state diagram

Consider the automaton M over Σ = { a , b } with

• Q = { 0 , 1 , 2 , 3 , 4 } ,

• q

0

= 0,

F = { 4 }

δ a b

0 1 0

1 1 2

2 1 3

3 4 0

4 4 4

1

2

3

Which of the following words is accepted?

abba , baba , bba

Is it the case that { w | | w | b is even } ⊆ L ( M )?

Is it the case that { w | w contains aabbaa } ⊆ L ( M )?

H. Geuvers & T. van Laarhoven Version: fall 2014

Formal Languages, Grammars and Automata

7 / 17

Finite Automata

Manipulating finite automata

Finite automata and regular languages

Radboud University Nijmegen

Manipulating Finite Automata: products for intersection start start a

0 b

M a a b p a start 0 , p b b a a

0 , q a

1 , p

1 , q b

1 a,b q b b

L ( M )

L

1

= { w | | w | a is even }

L

2

= { w | | w | b

≥ 1 }

L

1

∩ L

2

=

{ w | | w | a is even and | w | b

≥ 1 }

H. Geuvers & T. van Laarhoven Version: fall 2014

Formal Languages, Grammars and Automata

9 / 17

Finite Automata

Manipulating finite automata

Finite automata and regular languages

Product of two DFAs

Radboud University Nijmegen

Given two DFAs over the same Σ

M

1

M

2

=

=

(

(

Q

Q

1

2

, q

01

, q

02

, δ

1

, F

1

)

, δ

2

, F

2

)

Define

M

1

× M

2

= ( Q

1

× Q

2

, q

0

, δ, F ) with

Then with

F := F

1

× F

2

:= { ( q

1

, q

2

) | q

1

∈ F

1 and q

2

∈ F

2

} we have q

0

:= ( q

01

, q

02

)

δ (( q

1

, q

2

) , a ) := ( δ

1

( q

1

, a ) , δ

2

( q

2

, a ))

L ( M

1

× M

2

) = L ( M

1

) ∩ L ( M

2

)

H. Geuvers & T. van Laarhoven Version: fall 2014

Formal Languages, Grammars and Automata

10 / 17

Finite Automata

Manipulating finite automata

Finite automata and regular languages

Closure Properties

Radboud University Nijmegen

Proposition Closure under complement

If L is accepted by some DFA, then so is

L = Σ

− L .

Proof.

Suppose that L is accepted by M = ( Q , q

0

, δ, F ).

Then L is accepted by M = ( Q , q

0

, δ, F ).

-

Proposition Closure under intersection and union

If L

1

, and L

2 are accepted by some DFA, then so are L

1

∩ L

2 and

L

1

∪ L

2

.

Proof.

For the intersection, this follows from the product construction on the previous slide.

For the union, this can be seen by the product construction, taking a different F (which one?) or by noticing that L

1

∪ L

2

= L

1

∩ L

2

.

-

H. Geuvers & T. van Laarhoven Version: fall 2014

Formal Languages, Grammars and Automata

11 / 17

Finite Automata

Manipulating finite automata

Finite automata and regular languages

Kleene’s Theorem

Radboud University Nijmegen

Theorem The languages accepted by DFAs are exactly the regular languages

We will prove this in this and the next lecture by

1

If L = L ( M ), for some DFA M , then there is a regular expression e such that L = L ( e ) (this lecture).

2

3

If L = L ( e ), for some regular expression e , then there is a non-deterministic finite automaton (NFA) M such that

L = L ( M ). (next lecture).

For every NFA M , there is a DFA M

L ( M ) = L ( M

0

) (next lecture)

0 such that

H. Geuvers & T. van Laarhoven Version: fall 2014

Formal Languages, Grammars and Automata

12 / 17

Finite Automata

Manipulating finite automata

Finite automata and regular languages

Radboud University Nijmegen

From DFAs to regular expressions

Given the DFA M = ( Q , q

0

, δ, F ), we construct a regular expression e such that

L ( e ) = L ( M ) .

Procedure:

• We remove states, replacing symbols from Σ by words from Σ

,

• until we end up with a “simple automaton” from which we can read off e .

H. Geuvers & T. van Laarhoven Version: fall 2014

Formal Languages, Grammars and Automata

14 / 17

Finite Automata

Manipulating finite automata

Finite automata and regular languages

Simple automata

Radboud University Nijmegen start start u q

0 start

M w q

0 w q

0 x y start u q

0 x y v q

1 v q

1 e such that L ( e ) = L ( M ) w

∗ u

( u +

0 xv

∗ y ) x ( v + yu

∗ x )

H. Geuvers & T. van Laarhoven Version: fall 2014

Formal Languages, Grammars and Automata

15 / 17

Finite Automata

Manipulating finite automata

Finite automata and regular languages

Eliminating states

Radboud University Nijmegen

Remove a state p , while adding arrows q → q

0 between other pairs of states.

Before: v q x p y q

0

After: xv

∗ y q p q

0

H. Geuvers & T. van Laarhoven Version: fall 2014

Formal Languages, Grammars and Automata

16 / 17

Finite Automata

Manipulating finite automata

Finite automata and regular languages

Special cases

Join arrows using + x q q

0 y

First create a single final state

Radboud University Nijmegen q x + y q

0 q q

0

λ p

λ q q

0

Beware of loops v x q p y q xv

∗ y p

H. Geuvers & T. van Laarhoven Version: fall 2014

Formal Languages, Grammars and Automata

17 / 17

Download