Recall: Regular Languages The language recognized by a finite - - PDF document

recall regular languages
SMART_READER_LITE
LIVE PREVIEW

Recall: Regular Languages The language recognized by a finite - - PDF document

CSE 2001: Introduction to Theory of Computation Summer 2013 Yves Lesperance lesperan@cse.yorku.ca Office: CSEB 3052A Phone: 416-736-2100 ext 70146 Course page: http://www.cse.yorku.ca/course/2001 Slides are mostly taken from Suprakash


slide-1
SLIDE 1

1

13-06-03 CSE 2001, Summer 2013 1

CSE 2001: Introduction to Theory of Computation

Summer 2013

Yves Lesperance

lesperan@cse.yorku.ca Office: CSEB 3052A Phone: 416-736-2100 ext 70146 Course page: http://www.cse.yorku.ca/course/2001

Slides are mostly taken from Suprakash Datta’s for Winter 2013

13-06-03 CSE 2001, Summer 2013 2

Recall: Regular Languages

The language recognized by a finite automaton M is denoted by L(M). A regular language is a language for which there exists a recognizing finite automaton.

slide-2
SLIDE 2

2

13-06-03 CSE 2001, Summer 2013 3

Terminology: closure

  • A set is defined to be closed under an
  • peration if that operation on members
  • f the set always produces a member of

the same set. (adapted from wikipedia)

E.g.:

  • The integers are closed under addition, multiplication.
  • The integers are not closed under division
  • Σ* is closed under concatenation
  • A set can be defined by closure -- Σ* is called the

(Kleene) closure of Σ under concatenation.

13-06-03 CSE 2001, Summer 2013 4

Terminology: Regular Operations

Pages 44-47 (Sipser) The regular operations are:

  • 1. Union
  • 2. Concatenation
  • 3. Star (Kleene Closure): For a language A,

A* = {w1w2w3…wk| k ≥ 0, and each wi ∈A}

slide-3
SLIDE 3

3

13-06-03 CSE 2001, Summer 2013 5

Closure Properties

  • Set of regular languages is closed

under

  • - Complementation

– Union – Concatenation – Star (Kleene Closure)

13-06-03 CSE 2001, Summer 2013 6

Complement of a regular language

  • Swap the accepting and non-accept

states of M to get M’.

  • The complement of a regular language

is regular.

slide-4
SLIDE 4

4

13-06-03 CSE 2001, Summer 2013 7

Other closure properties

Union: Can be done with DFA, but using a complicated construction. Concatenation: We tried and failed Star: ???

We introduced non-determinism in FA

13-06-03 CSE 2001, Summer 2013 8

Recall: NFA drawing conventions

  • Not all transitions are labeled
  • Unlabeled transitions are assumed to

go to a reject state from which the automaton cannot escape

slide-5
SLIDE 5

5

13-06-03 CSE 2001, Summer 2013 9

Closure under regular operations

Union (new proof):

13-06-03 CSE 2001, Summer 2013 10

Closure under regular operations

Concatenation:

slide-6
SLIDE 6

6

13-06-03 CSE 2001, Summer 2013 11

Closure under regular operations

Star:

13-06-03 CSE 2001, Summer 2013 12

Incorrect reasoning about RL

  • Since L1 = {w| w=an, n ∈ N},

L2 = {w| w = bn, n ∈ N} are regular, therefore L1 • L2 = {w| w=an bn, n ∈ N} is regular

  • If L1 is a regular language, then

L2 = {wR| w ∈ L1} is regular, and Therefore L1 • L2 = {w wR | w ∈ L1} is regular

slide-7
SLIDE 7

7

13-06-03 CSE 2001, Summer 2013 13

Are NFA more powerful than DFA?

  • NFA can solve every problem that DFA

can (DFA are also NFA)

  • Can DFA solve every problem that NFA

can?

13-06-03 CSE 2001, Summer 2013 14

Equivalence of NFA, DFA

  • Pages 54-58 (Sipser, 2nd ed)
  • We will prove that every NFA is

equivalent to a DFA (with upto exponentially more states).

  • Non-determinism does not help FA’s to

recognize more languages!

slide-8
SLIDE 8

8

13-06-03 CSE 2001, Summer 2013 15

Epsilon Closure

  • Let N=(Q,Σ,δ,q0,F) be any NFA
  • Consider any set R ⊆ Q
  • E(R) = {q|q can be reached from a state

in R by following 0 or more ε-transitions}

  • E(R) is the epsilon closure of R under ε-

transitions

13-06-03 CSE 2001, Summer 2013 16

Proving equivalence

* languages all For Σ ⊆ L M N M L L iff N L L DFA NFA some for some for ) ( ) ( = =

One direction is easy:

A DFA M is also a NFA N. So N does not have to be `constructed’ from M

slide-9
SLIDE 9

9

13-06-03 CSE 2001, Summer 2013 17

Proving equivalence – contd.

  • N = (Q,Σ,δ,q0,F)
  • Construct M= (Q’,Σ,δ’,q’0,F’) such

that,

– for any string w ∈ Σ*, – w is accepted by N iff w is accepted by M

The other direction:

Construct M from N

13-06-03 CSE 2001, Summer 2013 18

Special case

  • Assume that ε is not used in the NFA N.
  • Need to keep track of each subset of N
  • So Q’ = P (Q), q’0 = {q0}
  • δ’(R,a) = ∪(δ(r,a)) over all r ∈ R, R ∈ Q’
  • F’ = {R ∈ Q’| R contains an accept state of

N}

  • Now let us assume that ε is used.
slide-10
SLIDE 10

10

13-06-03 CSE 2001, Summer 2013 19

Construction (general case)

  • 1. Q’ = P(Q)
  • 2. q’0 = E({q0})
  • 3. for all R ∈ Q’ and a∈ Σ

δ’(R, a) = {q ∈ Q|q ∈ E(δ(r,a)) for some r∈R}

  • 4. F’ = { R ∈ Q’| R contains an accept

state of N}

13-06-03 CSE 2001, Summer 2013 20

Why the construction works

  • for any string w ∈ Σ*,
  • w is accepted by N iff w is accepted by

M

  • Can prove using induction on the

number of steps of computation…

slide-11
SLIDE 11

11

13-06-03 CSE 2001, Summer 2013 21

State minimization

It may be possible to design DFA’s without the exponential blowup in the number of states. Consider the NFA and DFA below. 0,1 0,1 1 1 1 0,1 1 1 1

13-06-03 CSE 2001, Summer 2013 22

Characterizing FA languages

  • Regular expressions
slide-12
SLIDE 12

12

13-06-03 CSE 2001, Summer 2013 23

Regular Expressions (Def. 1.52)

Given an alphabet Σ, R is a regular expression if: (INDUCTIVE DEFINITION)

  • R = a, with a∈Σ
  • R = ε
  • R = ∅
  • R = (R1∪R2), with R1 and R2 regular expressions
  • R = (R1•R2), with R1 and R2 regular expressions
  • R = (R1*), with R1 a regular expression

Precedence order: *, •,∪

13-06-03 CSE 2001, Summer 2013 24

Regular Expressions

  • Unix ‘grep’ command: Global Regular

Expression and Print

  • Lexical Analyzer Generators (part of

compilers)

  • Both use regular expression to DFA

conversion

slide-13
SLIDE 13

13

13-06-03 CSE 2001, Summer 2013 25

Examples

  • e1 = a ∪ b, L(e1) = {a,b}
  • e2 = ab ∪ ba, L(e2) = {ab,ba}
  • e3 = a*, L(e3) = {a}*
  • e4 = (a ∪ b)*, L(e4) = {a,b}*
  • e5 = (em . en), L(e5) = L(em) • L(en)
  • e6 = a*b ∪ a*bb,

L(e6) = {w| w ∈ {a,b}* and w has 0 or more a’s followed by 1 or 2 b’s}

13-06-03 CSE 2001, Summer 2013 26

Characterizing Regular Expressions

We prove that languages described by Regular expressions (RE) and Regular Languages are the same set, i.e., RE = RL

slide-14
SLIDE 14

14

13-06-03 CSE 2001, Summer 2013 27

Thm 1.54: RL ~ RE

We need to prove both ways:

  • If a language is described by a regular expression,

then it is regular (Lemma 1.55) (We will show we can convert a regular expression R into an NFA M such that L(R)=L(M))

  • The second part:

If a language is regular, then it can be described by a regular expression (Lemma 1.60)

13-06-03 CSE 2001, Summer 2013 28

Regular expression to NFA

Claim: If L = L(e) for some RE e, then L = L(M) for some NFA M Construction: Use inductive definition 1. R = a, with a∈Σ 2. R = ε 3. R = ∅ 4. R = (R1∪R2), with R1 and R2 regular expressions 5. R = (R1•R2), with R1 and R2 regular expressions 6. R = (R1*), with R1 a regular expression a

1. 2. 3. 4,5,6: similar to

closure of RL under regular operations.

slide-15
SLIDE 15

15

13-06-03 CSE 2001, Summer 2013 29

Examples of RE to NFA conv.

L = {ab,ba} L = {ab,abab,ababab,……} L = {w | w = ambn, m<10, n>10}

13-06-03 CSE 2001, Summer 2013 30

Back to RL ~ RE

  • The second part (Lemma 1.60):

If a language is regular, then it can be described by a regular expression.

  • Proof strategy:

§ regular implies equivalent DFA. § convert DFA to GNFA (generalized NFA) § convert GNFA to NFA.

GNFA: NFA that have regular expressions as transition labels

slide-16
SLIDE 16

16

13-06-03 CSE 2001, Summer 2013 31

Example GNFA

qS qA

01* 0* ∪ 11 0110 ∅ ε

13-06-03 CSE 2001, Summer 2013 32

Generalized NFA - defn

Generalized non-deterministic finite automaton M=(Q, Σ, δ, qstart, qaccept) with

  • Q finite set of states
  • Σ the input alphabet
  • qstart the start state
  • qaccept the (unique) accept state
  • δ:(Q - {qaccept})×(Q - {qstart}) → R is the transition

function (R is the set of regular expressions over Σ) (NOTE THE NEW DEFN OF δ)

slide-17
SLIDE 17

17

13-06-03 CSE 2001, Summer 2013 33

Characteristics of GNFA’s δ

  • δ:(Q\{qaccept})×(Q\{qstart}) → R

The interior Q\{qaccept,qstart} is fully connected by δ From qstart only ‘outgoing transitions’ To qaccept only ‘ingoing transitions’ Impossible qi→qj transitions are labeled “δ(qi,qj) = ∅” qS qA R∈R Observation: This GNFA recognizes the language L(R)

13-06-03 CSE 2001, Summer 2013 34

Proof Idea of Lemma 1.60

Proof idea (given a DFA M): Construct an equivalent GNFA M’ with k≥2 states Reduce one-by-one the internal states until k=2 This GNFA will be of the form This regular expression R will be such that L(R) = L(M) qS qA R

slide-18
SLIDE 18

18

13-06-03 CSE 2001, Summer 2013 35

DFA M → Equivalent GNFA M’

Let M have k states Q={q1,…,qk} with start state q1

  • Add two states qaccept and qstart

qS q1

ε

  • Connect qstart to original q1:

qi

qj

  • Complete missing transitions by

qA qj

ε

  • Connect old accepting states to qaccept
  • Join multiple transitions:

qi qj

1

becomes qi

0∪1

qj

13-06-03 CSE 2001, Summer 2013 36

Remove Internal state of GNFA

If the GNFA M has more than 2 states, ‘rip’ internal qrip to get equivalent GNFA M’ by:

  • Removing state qrip: Q’=Q\{qrip}
  • Changing the transition function δ by

δ’(qi,qj) = δ(qi,qj) ∪ (δ(qi,qrip)(δ(qrip,qrip))*δ(qrip,qj))

for every qi∈Q’\{qaccept} and qj∈Q’\{qstart} qi

R4∪(R1R2*R3)

qj qi R2 qj

R4

qrip R1 R3 =

slide-19
SLIDE 19

19

13-06-03 CSE 2001, Summer 2013 37

Proof Lemma 1.60

Let M be DFA with k states Create equivalent GNFA M’ with k+2 states Reduce in k steps M’ to M’’ with 2 states The resulting GNFA describes a single regular expressions R The regular language L(M) equals the language L(R) of the regular expression R

13-06-03 CSE 2001, Summer 2013 38

Proof Lemma 1.60 - continued

  • Use induction (on number of states of

GNFA) to prove correctness of the conversion procedure.

  • Base case: k=2.
  • Inductive step: 2 cases – qrip is/is not on

accepting path.

qi

R4∪(R1R2*R3)

qj qi R2 qj

R4

qrip R1 R3 =

slide-20
SLIDE 20

20

13-06-03 CSE 2001, Summer 2013 39

Recap RL = RE

Let R be a regular expression, then there exists an NFA M such that L(R) = L(M) The language L(M) of a DFA M is equivalent to a language L(M’) of a GNFA = M’, which can be converted to a two-state M’’ The transition qstart ⎯R→ qacceptof M’’

  • beys L(R) = L(M’’)

Hence: RE ⊆ NFA = DFA ⊆ GNFA ⊆ RE

13-06-03 CSE 2001, Summer 2013 40

Example

L = {w| the sum of the bits of w is odd}