CS 3240: Languages and Computation - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

CS 3240: Languages and Computation

Description:

CS 3240: Languages and Computation – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 29
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 RegExp
    regular languages

2
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 the DFA ends at an accepting
    state after processing the string

3
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

4
Example
  • Accept strings containing either 101 or 11 as a
    substring

5
How does NFA work?
  • Start in start state
  • If any ? transitions, clone a machine for each ?
    transition
  • 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

6
Example Read 010110
  • How would this NFA work?

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

9
Definition NFA
  • An 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?

10
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
  • Can d(q,a) map to empty set?

11
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

12
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
    nondeterministic computation of NFA N, use many
    fingers to point at the set 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).

13
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 Work out on whiteboard.

14
Proof of DNANFA Contd
  • This construction almost works, except for
    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.

15
Closure Properties of Regular Expressions
16
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/repetetion 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,

17
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.

18
Union N N1 ? N2
N1
N2
19
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.

20
Concatenation N N1N2
21
Closure under Star N N1
N1
22
Regular Language Regular Expression
  • Formally, regular language is defined based on
    DFA.
  • 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).

23
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.

24
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

25
Example GNFA
26
Example GNFA
27
DFA M ? GNFA M
Let M have k states Qq1,,qk
- Add two states qaccept and qstart
28
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