Automata Theory November 2002 Introduction & NFAPart 1:

18
Automata Theory November 2002 Introduction & NFA Part 1:

Transcript of Automata Theory November 2002 Introduction & NFAPart 1:

Page 1: Automata Theory November 2002 Introduction & NFAPart 1:

Automata Theory

November 2002

Introduction & NFAPart 1:

Page 2: Automata Theory November 2002 Introduction & NFAPart 1:

2

Introduction

an abstract machine

a specification with many possible implementations

issues of functionality (power) and efficiency

hierarchy of automata corresponds to hierarchy of grammars

languages generated by grammars are accepted by automata

the computational tasks performed by an automaton are very closely related to the structures & meanings modelled by the corresponding grammar.

Page 3: Automata Theory November 2002 Introduction & NFAPart 1:

3

Computing power of automata:

the simplest automata are only capable of adding numbers and recognising simple expressions

more complex automata can evaluate arbitrary expressions and compile computer programs

the most powerful automata can perform any computable task - significantly, there are tasks which cannot be computed.

automata theory also reveals limitations on what can be made efficient.

Page 4: Automata Theory November 2002 Introduction & NFAPart 1:

4

Deterministic Finite Automaton - DFA

The simplest automata - main features:

• finite number of states• state changes in response to an input symbol• no choice of move

DFA = (Q,T,F,g)

where Q = set of states, including initial state T = set of input symbolsF = set of final states, F Qg = transition function, Q T Q mapping

Page 5: Automata Theory November 2002 Introduction & NFAPart 1:

5

DFA

Transition or move defined by,• g(q,a) = q’

where q,q’ Q, a T

q q’a

Page 6: Automata Theory November 2002 Introduction & NFAPart 1:

6

DFA

Operation can be represented as a state diagram in which: - nodes represent states, - arcs represent transitions or moves, - the initial state is arrowed, - and the final states are represented as squares.

q q’a1

f

f F

a2

Initial state intermediate state final state

Page 7: Automata Theory November 2002 Introduction & NFAPart 1:

7

DFA

State of a DFA changes predictably in response to an input symbol - so at any time the entire future behaviour of a DFA is fully determined by

• 1. the current state, q

• 2. the remaining input symbols, x

Combine these into a pair (q, x) giving a complete description of current situation.

Page 8: Automata Theory November 2002 Introduction & NFAPart 1:

8

Teletext remote control example

tv text

digit1 digit2 wait

text

tv

tvtv

d

d

d

tvnewpage

d 0 9=

d

• Pressing the text button followed by three digits causes the appropriate page to be loaded and displayed.

• Pressing the tv button causes a return to the normal image.

Page 9: Automata Theory November 2002 Introduction & NFAPart 1:

9

DFA - State Transition

A move can be defined either in terms of the transition function: g(q,a) = q’

or, equivalently in terms of how the complete description evolves: (q,ax) (q’,x)

Note the state change to q’ and the fact that the input symbol a is read and then dropped.

A sequence of moves between these complete descriptions is denoted by *

An input string w T* is accepted by the automaton if there is a finite sequence of moves such that (q0,w) * (q’,) for some q’ F , i.e. the automaton is in a final state when the input string is exhausted ().

The language L(A) defined by an automaton A is the set of strings accepted by it, (a similar concept to the language generated by a grammar).

Page 10: Automata Theory November 2002 Introduction & NFAPart 1:

10

Q = {q0,q1}, F={q1}, T={0,1}where q0, q1 represent odd and even parity states respectively (binary input). Transition function is defined as follows:• g(q0,0) = q0

• g(q0,1) = q1

• g(q1,0) = q1

• g(q1,1) = q0

The machine accepts strings (in the final state q1 ) with odd parity.

Parity tester example

0 01

1

q q0 1

Odd-parity tester

Page 11: Automata Theory November 2002 Introduction & NFAPart 1:

11

Binary adder DFA example

Note that a DFA halts when its input string is exhausted (or when no move is possible for a given (state, input) pair), and not just because it has entered a final state. Some machines can also generate an output for every move. Let the output vocabulary be T*.

The state diagram shows the output to the right of each arrow.

q0 q1

(0,0) 0 (1,1) 1

(0,1) 1 (1,0) 1 (0,1) 0 (1,0) 0

(1,1) 0

(0,0) 1

input: 0 1 1 0 1 0 1input: 0 0 1 0 0 1 1

state:output: 1 0 0 1 0 0 0

q q q q q q q q0 1 1 0 1 1 1 0

T T {( , ), ( , ),( , ), ( , )}, { , }0 0 01 10 11 0 1

Page 12: Automata Theory November 2002 Introduction & NFAPart 1:

12

Binary Multiply by 3

0 0

0 1

1 1

0 0

1 0

1 1

q0 q1 q2

carry 0 carry 1 carry 2

input: 0 0 1 1 0state:

output: 1 0 0 1 0

q q q q q q0 1 2 1 0 0

T T { , }0 1

In general, a DFA to multiply by n will require n states.

No DFA can multiply an arbitrary pair of numbers.

Page 13: Automata Theory November 2002 Introduction & NFAPart 1:

13

Non-deterministic Finite Automaton - NFA

Finite automaton with a choice of moves: there may be more than one possible move for a given (state,input) pair.

The transition function is many-valued:g(q,a) Q for q Q, q T

The machine “chooses” a move from the set of possibilities, either at random or else by some mysterious unexplained process.

Non-deterministic automata are not really practical machines, but they have great theoretical importance, and lead to some useful general ideas and procedures.

Page 14: Automata Theory November 2002 Introduction & NFAPart 1:

14

NFA

Does this non-determinism increase the computing power of the machine?

The answer for a finite automaton is no:

Given any NFA it is always possible to construct an equivalent DFA. Equivalent here means that the machines accept the same strings, and generate the same output (if any).

Page 15: Automata Theory November 2002 Introduction & NFAPart 1:

15

NFA

If the set of states of the NFA is Q, then the states of the DFA are subsets of Q, with initial state {q0}. Extend the transition function to subsets of Q by defining,

G(R,a) = g(q,a) for R Q, a T qR

Thus, make transition unique by forming the union of all the possibilities in order to construct a new set (state) to go to in response to an input symbol.

Page 16: Automata Theory November 2002 Introduction & NFAPart 1:

16

NFA to DFA conversion

The non-determinism in the arcs in the original machine is embedded within the states of the new machine. We construct the states of the DFA recursively.

First define states Ra = G({q0},a) = g(q0,a) for all a, then more new states Rab = G(Ra,b) for all a,b, and so on until no new states are generated.

The final states of the DFA are those states R for whichR F

Page 17: Automata Theory November 2002 Introduction & NFAPart 1:

17

NFA to DFA conversion

Example:

q

q

q

q

a

b a

b

a

b

b

ab

a

q

0

3

1

2

4

NFA

R6

{

{

{

{

{

{

q

q

{q

q

q

q

q1

1

4

1

2

0

3

, ,q q2 4} }

}

}

}

}

} a

b

ba

b

ab

aa

a

b

b

DFA

R0

R2

R1 R4

R3

R5

Page 18: Automata Theory November 2002 Introduction & NFAPart 1:

18