Nondeterministic Finite Automata - Research School Finite Automata COMP2600 — Formal Methods for...

download Nondeterministic Finite Automata - Research School Finite Automata COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian National University Semester 2, 2016

of 39

  • date post

    26-May-2018
  • Category

    Documents

  • view

    212
  • download

    0

Embed Size (px)

Transcript of Nondeterministic Finite Automata - Research School Finite Automata COMP2600 — Formal Methods for...

  • Nondeterministic Finite Automata

    COMP2600 Formal Methods for Software Engineering

    Katya Lebedeva

    Australian National University

    Semester 2, 2016

    Slides by Katya Lebedeva.

    COMP 2600 Nondeterministic Finite Automata 1

  • For a Deterministic Finite Automaton (s,a) is a unique state for all s S andfor all a .

    For a Nondeterministic Finite Automaton the transition function does notdefine a unique state, but defines a set of states.

    It may

    be the empty set

    be a singleton set (i.e. set with just one element)

    contain more than one element

    An NFA has the ability to be in several states at once.

    COMP 2600 Nondeterministic Finite Automata 2

  • Nondeterministic Finite State Automata

    s0start s1 s2

    0,1

    1 0,1

    COMP 2600 Nondeterministic Finite Automata 3

  • State diagram for 0111

    s0start s1 s2

    0,1

    1 0,1

    s0 s0

    s0

    s0

    s0

    1

    s111

    s1 s2 accept!1

    11

    s1 s2 stuck1

    10

    COMP 2600 Nondeterministic Finite Automata 4

  • Informally, an NFA accepts a string if there exists at least one path in the state

    diagram that

    starts in the start state

    does not get stuck before the entire string has been read

    ends in the accepting state

    The fact that some choices of states using the input symbols of the string lead

    to a nonaccepting state, or do not lead to any state at all does not prevent the

    string from being accepted by the NFA.

    The NFA from the previous slide accepts strings that have 1 as the second

    symbol from the end of the string.

    COMP 2600 Nondeterministic Finite Automata 5

  • A Nondeterministic Finite State Automaton (DFA) is a 5-tuple

    (,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. is a transition function such that : S 2S,i.e. takes a state in S and an input symbol in as arguments andreturns a subset of S.

    Notice that the only difference between DFA and NFA is the type of value that returns!

    COMP 2600 Nondeterministic Finite Automata 6

  • s0start s1 s2

    0,1

    1 0,1

    The NFA can be specified formally as

    ({0,1},{s0,s1,s2,},s0,{s2},)

    where the transition function is given by the transition table

    0 1

    s0 {s0} {s0,s1}s1 {s2} {s2}s2 /0 /0

    COMP 2600 Nondeterministic Finite Automata 7

  • Extended Transition Function

    s0 s0

    s0

    s0

    s0

    1

    s111

    s1 s2 accept!1

    11

    s1 s2 stuck1

    10

    COMP 2600 Nondeterministic Finite Automata 8

  • The extended transition function of a NFA is the function : S 2S

    defined as follows:

    for all s S, for all a , for all

    (s,) = {s}

    (s,a) =

    p(s,)(p,a)

    I.e. if (s,) = {p1, p2, . . . pk} then

    (s,a) = (p1,a)(p2,a) (pk,a)

    Informally: we first compute (s,) and then follow any transition that islabeled with a from any of these states.

    COMP 2600 Nondeterministic Finite Automata 9

  • Input: 0111

    s0start s1 s2

    0,1

    1 0,1

    1. (s0,) = {s0} the basis rule!

    2. (s0,0) = (s0,0) = {s0}

    3. (s0,01) = (s0,1) = {s0,s1}

    4. (s0,011) = (s0,1)(s1,1) = {s0,s1}{s2}= {s0,s1,s2}

    5. (s0,0111)= (s0,1)(s1,1)(s2,1)= {s0,s1}{s2} /0= {s0,s1,s2}

    COMP 2600 Nondeterministic Finite Automata 10

  • Different views of non-determinism

    The NFA always makes the right choice (of a successor state accordingto ) to insure reaching the final state (if possible at all)

    The NFA simultaneously explores multiple paths

    At each nondeterministic choice point the NFA spawns off mutiple copiesof itself

    Note: The various path/computations evolve completely independently from

    each other (this is different from parallel computations which may synchronise

    at a certain point)

    COMP 2600 Nondeterministic Finite Automata 11

  • Language accepted by an NFA

    If AN = (,S,s0,F,) is an NFA, then

    L(AN) = {w | (s0,w)F 6= /0}

    That is, L(AN) is the set of strings w in such that (s0,w) contains at leastone accepting state.

    COMP 2600 Nondeterministic Finite Automata 12

  • Equivalence of DFAs and NFAs

    It may be easier to construct an NFA than a DFA for a given language.

    However, every language that can be described by some NFA can also be

    described by some DFA (and vice versa)!!!

    If an NFA has n states, the equivalent DFA will have at most 2n states.

    In most cases, the DFA has about as many states as the equivalent NFA, but

    more transitions.

    COMP 2600 Nondeterministic Finite Automata 13

  • Proof idea of the equivalence of DFAs and NFAs

    We have to prove:

    L(DFA) L(NFA)

    Whenever we have a DFA AD, we can construct a NFA AN such thatL(AD) = L(AN).

    This is easy to show! Why?

    L(NFA) L(DFA)

    For every NFA AN there is a DFA AD such that L(AD) = L(AN).

    The proof of this direction involves Subset Construction.

    COMP 2600 Nondeterministic Finite Automata 14

  • Subset Construction

    Intuition

    The NFA AN can perform more than one computation on a given input string.

    Construct a DFA AD that runs all these different computations simultaneously:

    the state that AD is in after having read an initial part of the input string corre-sponds exactly to the set of all states that AN can reach after having read thesame part of the input string

    COMP 2600 Nondeterministic Finite Automata 15

  • Idea for the construction of AD from AN

    A subset of AN s states corresponds to a state in AD:

    s0 s0

    s0

    s0

    s0

    1

    s111

    s1 s2 accept!1

    11

    s1 s2 stuck1

    10

    {s0} {s0} {s0 ,s1} {s0 ,s2} {s0 ,s1}1110

    COMP 2600 Nondeterministic Finite Automata 16

  • s0start s1 s2

    0,1

    1 0,1

    The set of states of the DFA we have

    to construct is associated with the set

    of all subsets of the states of the given

    NFA.

    0 1

    /0

    {s0}{s1}{s2}

    {s0,s1}{s0,s2}{s1,s2}

    {s0,s1,s2}

    COMP 2600 Nondeterministic Finite Automata 17

  • s0start s1 s2

    0,1

    1 0,1

    When we are in no state in the initial

    NFA, regardless what the input symbol

    is, we continue to be in no state.

    0 1

    /0 /0 /0

    {s0}{s1}{s2}

    {s0,s1}{s0,s2}{s1,s2}

    {s0,s1,s2}

    COMP 2600 Nondeterministic Finite Automata 18

  • s0start s1 s2

    0,1

    1 0,1

    When we in s0 in the NFA and the inputis 0, the transition function of the NFAtakes us to {s0}.When we in s0 in the NFA and the inputis 1, the transition function of the NFAtakes us to {s0,s1}.

    0 1

    /0 /0 /0

    {s0} {s0} {s0,s1}{s1}{s2}

    {s0,s1}{s0,s2}{s1,s2}

    {s0,s1,s2}

    COMP 2600 Nondeterministic Finite Automata 19

  • s0start s1 s2

    0,1

    1 0,1

    When we in s1 in the NFA and the inputis 0, the transition function of the NFAtakes us to {s2}.When we in s1 in the NFA and the inputis 1, the transition function of the NFAtakes us to {s2}.

    0 1

    /0 /0 /0

    {s0} {s0} {s0,s1}{s1} {s2} {s2}{s2}

    {s0,s1}{s0,s2}{s1,s2}

    {s0,s1,s2}

    COMP 2600 Nondeterministic Finite Automata 20

  • s0start s1 s2

    0,1

    1 0,1

    When we in s2 in the NFA and the inputis 0, the transition function of the NFAtakes us to /0 (i.e. it takes us to none ofthe states of the NFA).

    When we in s1 in the NFA and the inputis 1, the transition function of the NFAtakes us to /0.

    0 1

    /0 /0 /0

    {s0} {s0} {s0,s1}{s1} {s2} {s2}{s2} /0 /0

    {s0,s1}{s0,s2}{s1,s2}

    {s0,s1,s2}

    COMP 2600 Nondeterministic Finite Automata 21

  • s0start s1 s2

    0,1

    1 0,1

    Mark the start state.

    Mark the accepting states.

    Accepting states are those in which

    appears at least one accepting state

    of our NFA.

    0 1

    /0 /0 /0

    {s0} {s0} {s0,s1}{s1} {s2} {s2}{s2} /0 /0{s0,s1} {s0,s2} {s0,s1,s2}{s0,s2} {s0} {s0,s1}{s1,s2} {s2} {s2}

    {s0,s1,s2} {s0,s2} {s0,s1,s2}

    COMP 2600 Nondeterministic Finite Automata 22

  • s0start s1 s2

    0,1

    1 0,1

    This transition table determines the

    transition function of our DFA!!!

    It belongs to a Deterministic Au-

    tomaton!

    Each of these sets is a state of

    our DFA!

    0 1

    /0 /0 /0

    {s0} {s0} {s0,s1}{s1} {s2} {s2}{s2} /0 /0{s0,s1} {s0,s2} {s0,s1,s2}{s0,s2} {s0} {s0,s1}{s1,s2} {s2} {s2}

    {s0,s1,s2} {s0,s2} {s0,s1,s2}

    COMP 2600 Nondeterministic Finite Automata 23

  • s0start s1 s2

    0,1

    1 0,1

    0 1

    /0 /0 /0

    {s0} {s0} {s0,s1}{s1} {s2} {s2}{s2} /0 /0{s0,s1} {s0,s2} {s0,s1,s2}{s0,s2} {s0} {s0,s1}{s1,s2} {s2} {s2}

    {s0,s1,s2} {s0,s2} {s0,s1,s2}

    COMP 2600 Nondeterministic Finite Automata 24

  • s0start s1 s2

    0,1

    1 0,1

    0 1

    A A A

    B B EC D D

    *D A A

    E F H

    *F B E

    *G D D

    *H F H

    0 1

    A /0 A /0 A /0

    B{s0} B {s0} E {s0,s1}C {s1} D {s2} D {s2}

    *D {s2} A /0 A /0E {s0,s1} F {s0,s2} H {s0,s1,s2}

    *F {s0,s2} B {s0} E {s0,s1}*G {s1,s2} D {s2} D {s2}

    *H {s0,s1,s2} F {s0,s2} H {s0,s1,s2}

    COMP 2600 Nondeterministic Finite Automata 25

  • s0start s1 s2

    0,1

    1 0,1

    0 1

    A A A

    B B EC D D

    *D A A

    E F H

    *F B E

    *G D D

    *H F H

    COMP