CS 3240: Languages and Computation - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

CS 3240: Languages and Computation

Description:

One start state q0. One or more ... In other words, DFA and NFA are equivalent ... Let M have k states Q={q1,...,qk} - Add two states qaccept and ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 31
Provided by: ble87
Category:

less

Transcript and Presenter's Notes

Title: CS 3240: Languages and Computation


1
CS 3240 Languages and Computation
  • Nondeterministic Finite Automata andEquivalence
    with Regular Expressions

2
Review Regular Expressions
  • Symbols and alphabet
  • A symbol is a valid character in a language
  • Alphabet is set of legal symbols
  • Typically denoted as ?
  • Metacharacters/metasymbols
  • Defining reg-ex operations
  • Escape character (\)
  • Empty string ? and empty set ?
  • Basic regular expressions
  • Basic operations union, concatenation, repetition

3
Review DFA
  • A DFA is a five-tuple consisting of
  • Alphabet ??
  • A set of states Q
  • A transition function d Q??? ? Q
  • One start state q0
  • One or more accepting states F ? Q
  • A language accepted by a DFA is the set of
    strings such that DFA ends at an accepting state
    after processing the string

4
Outline
  • Nondeterministic Finite Automata (NFA)
  • Equivalence between DFA and NFA
  • Closure properties of regular languages
  • Equivalence between regular expressions DFAs, and
    NFAs

5
NFA
  • Nondeterministic Finite Automaton
  • Same input may produce multiple paths
  • Allows transition with an empty string or
    transition from one state to different states
    given a character

q2
1
?
q1
q1
q2
q3
1
empty string transition
nondeterministic transition
6
Example
  • Accept strings containing either 101 or 11 as a
    substring

7
Another Example
  • Accept strings containing a 1 in the third
    position from the back

8
How does NFA work?
  • Start in start state
  • If any ? transitions, clone a machine for each
  • Read a symbol, clone a machine for each matching
    transition
  • If a symbol is read and there is no way to exit
    from a state, then that machine dies
  • At end of input if any machine accepts then accept

9
Example Read 010110
  • How would this NFA work?

10
Read 010110
11
Definition NFA
  • A nondeterministic finite automaton (NFA) is
    defined by a 5-tuple, with
  • Alphabet ??
  • A set of states Q
  • A transition function d Q ?Se? P(Q)
  • One start state q0
  • One or more accepting states F ? Q
  • Notation Se S?e P(Q) is power set of Q
  • What is the difference from DFA?

12
Nondeterministic Transition
  • The function d Q ?Se? P(Q) is the key
    difference!
  • When reading symbol a while in state q, it may
    go to one of the states in d(q,a)?Q.
  • e in Se allows empty-string transitions

13
Languages
  • Language accepted by a NFA is the set of strings
    such that NFA ends at an accepting state
  • Each string of language is c1c2cn with ci?Se
    (possibly with e)
  • States are qi ? d(qi-1,ci) for i1n
  • qn is an accepting state

14
DFA NFA
  • Theorem For every language L accepted by an NFA,
    there is a DFA that accepts L.
  • In other words, DFA and NFA are equivalent
    computational models.
  • Proof idea When keeping track of a
    nondeterministic computation of an NFA N, use
    many fingers to point at the subset ? Q of
    states of N that can be reached on a given input
    string. We can simulate this computation with a
    DFA M with state space P(Q).

15
Proof of DNANFA
  • More formal proof Let A be the language
    recognized by the NFA N (Q,S,d,q0,F). Define
    the DFA M (Q,S,d,q0,F) by
  • Q P(Q)
  • d(R,a) q?Q q?d(r,a) for an r?R
  • q0 q0
  • F R?Q R contains an accept state of N
  • Example

16
Proof of DNANFA Contd
  • This construction almost works, except for the
    e-transitions
  • Solution Define- E(R) q q reachable from
    R using e steps - d(R,a) q?Q
    q?E(d(r,a)) for an r?R - q0 E(q0)
  • DFA M accepts the same language as N.
  • Therefore, a language is regular if and only if
    it is accepted by an NFA.

17
NFA and Regular Expressions
18
Regular Operations
  • For languages L1 and L2, we define the following
    regular operations
  • Union L1?L2 x x?L1 or x?L2
  • Concatenation L1L2 xy x?L1 and y?L2
  • Star L1 x1xk xj?L1 for all 1jk, k0
  • Example L100,11, L20,1L1?L2
    0,1,00,11L1L2 000,001,110,111L1
    e,00,11,0000,0011,1100,1111,000000,
  • Recall definition of regular expressions

19
Closure under Union
  • The regular languages are closed under the
    union operation. In other words, if L1 and L2 are
    regular languages, then so is L1 ? L2.
  • Proof idea Construct a third automaton M3 such
    that L(M3) L1 ? L2.

20
Union N N1 ? N2
N1
N2
21
Closure under Concatenation
  • The regular languages are closed under
    concatenation. In other words, if L1 and L2 are
    regular, then so is L1L2.
  • Proof idea Construct a third automaton M3 such
    that L(M3) L1 L2.

22
Concatenation N N1N2
23
Closure under Star N N1
N1
24
Regular Language Regular Expression
  • As the names suggest, the following result holds
  • Theorem A language is regular if and only if
    some regular expression describes it.
  • Lemma If a language is described by a regular
    expression, then it is regular. (This follows
    from the closure properties of regular
    languages).
  • Lemma If a language is regular, then it can be
    described by a regular expression.
  • (This is harder and requires the notion of
    Generalized Nondeterministic Finite Automata
    (GNFA)).

25
Regular Language ?Regular Expression
  • If a language is regular, then it can be
    described by a regular expression.
  • Proof Idea Use generalized nondeterministic
    finite automata where the labels on the
    transition arrows are regular expressions. For
    an R?R this GNFA recognizes L(R)
  • Given a NFA/GNFA, repeatedly reduce it into a
    GNFA with a smaller number of states until only
    two states left.

26
Example GNFA
27
Example GNFA
28
Definition Generalized NFA
  • A Generalized nondeterministic finite automaton
    (GNFA) is defined by M(Q, S, d, qstart,
    qaccept) with
  • Q finite set of states
  • S the input alphabet
  • qstart the start state
  • qaccept the accept state
  • d(Q\qaccept)?(Q\qstart) ? R the transition
    function
  • R is the set of regular expressions over S

29
DFA M ? GNFA M
Let M have k states Qq1,,qk
- Add two states qaccept and qstart
30
Rip Internal state of GNFA
  • If the GNFA M has more than 2 states, rip
    internal qrip to get equivalent GNFA M
  • - Remove state qrip QQ\qrip
  • - Change the transition function d to d(qi,qj)
    d(qi,qj) ? (d(qi,qrip)(d(qrip,qrip))d(qrip,qj))
    for every qi?Q\qaccept and qj?Q\qstart
Write a Comment
User Comments (0)
About PowerShow.com