Automata

57
The theory of Automata Lecture no 1 Syed Asif Ali Email: [email protected] [email protected]

Transcript of Automata

Page 1: Automata

The theory of Automata

Lecture no 1

Syed Asif Ali

E–mail: [email protected]

[email protected]

Page 2: Automata

Course Title: Theory of Computer Science [AUTOMATA]

Prerequisites: Discrete Mathematic

Degree(s): BCS

Duration: 18 weeks in Fifth semester

Lectures: 48 in total, 3 per week, including some examples.

Laboratories: none

Page 3: Automata

Course Description:

Finite Automata.

Deterministic Finite automata (DFA).

Non-Deterministic Finite Automata (NFA).

Regular Expression & Language.

Properties of Regular Languages.

Context–Free Grammar & Language.

Properties of Context–Free Languages.

Push–Down Automata.

Turing Machines.

Page 4: Automata

Reference Books:

K.L.P. Mishra, N.

Chandrasekaran,

Theory of Computer Science

(Automata, Languages &

Computation), Second Edition,

Prentice Hall of India, 1999

Page 5: Automata

Textbooks:

Daniel I.A. Cohen

Introduction to Computer Theory

Page 6: Automata

Reference Books:

John.E. Hopcroft, R. Motwani, and J.D.

Ullman, Introduction to Automata

Theory, Language and Computation,

Second Edition, Pearson Education

Asia, 2001.

Page 7: Automata

Reference Books:

J.C. Martin, Introduction to

Languages and Theory of

Computation, Second Edition,

McGraw Hill 1991.

Page 8: Automata

Marks DistributionClass Attendance 05

Class–

Tests/Presentation

15

Quizzes 20

Mid–Term Examination 20

Final Examination 40

Total 100

Page 9: Automata

AUTOMATA

Automata is Greek letters .Automata is a word formulated from automation, which means machine designing or replacing human beings with machines.

Every machine design requires some hardware part and some software part.

A machine could be a finite state machine ,a Turing Machine, a pushdown automata, or any other restricted version of a Turing machine.

Page 10: Automata

Input File

Sequence of symbols

Internal State

of Control Unit

Next-State Transition Function

May have Temporary Storage

Input File

Sto

rage

Control Unit

Output

Automata

Page 11: Automata

Automata

Theory

Sets

Theory

Graph

Theory

Page 12: Automata

Sets

Sets are collections in which order of elements and duplication of

elements do not matter.

{1,a,1,1} = {a,a,a,1} = {a,1}

Size

Size of set mean number of elements in set e.g. |{a,b,c}| = 3

Special Sets

Empty Set

Universal Set U

Page 13: Automata

Set Relations

Subset {a,c} {a,b,c}

Proper Subset {a,c} {a,b,c}

is-element-of b {a,b,c}

Set Operations

Union X Y

Intersection X Y

Difference X – Y

Complement X (always with respect to Universe)

Disjoint S1 S2 =

• Powerset 2x

• Is it possible for |S| = |2S|?

A x B = {(a,b): for all a A and b B}

Page 14: Automata

DeMorgan’s Laws S1 S2 = S1 S2

S1 S2 = S1 S2

Functions : S1 S2

S1 = Domain

S2 = Range

S1 may be same as S2

Equivalence Relations

Reflexive

Symmetric

Transitive

a, b S, we write a b if a is equivalent to b

Page 15: Automata

What is a graph?

It's an abstract notion, used to represent the idea of some

kind of connection between pairs of objects.

A graph consists of:

A collection of "vertices", draw as small circles.

A collection of "edges", each connecting some two vertices.

Mathematical Definition

G = (V, E)

V = {v1,v2,…,vn} = Vertices

E = {e1, e2, …, em} = Edges

Page 16: Automata

Graph Terminology

Walk = Sequence of edges

Path = Walk with no repeated edges

Simple Path = No vertices repeated

Cycle = Path from vi back to vi

Simple Cycle = Cycle with no vertices repeated

Page 17: Automata

Character or Alphabet: An alphabet S is a set of symbols (characters, letters).

or

A finite set of symbols/ An abstract set of distinct symbols over which a language is defined

String :A string (or word) over S is a sequence of symbols. The empty string is the string containing no symbols at all, and is denoted by ε.

Length/Size of String: The length of a string is the number of symbols that it

contains (repetitions allowed). Absolute values are used to denote length.

The length of a string w is denoted |w|.

For example |00100| = 5

|aab| = 3

| epsilon | = 0

Page 18: Automata

Concatenation : The concatenation of two strings is the string resulting from putting them together from left to right.

If u=one and v=two then u · v=onetwo and

v · u=twoone.

Dot is usually omitted; just write uv for u · v.

Laws:

u · (v · w) = (u · v) · w

u · ε = u

ε · u = u

|u · v| = |u| + |v|

Page 19: Automata

Regular Expression/Relational Expression

• Let Σ be an alphabet. The regular expressions(regex) are

defined inductively as follows:

– ø is a regular expression denoting {},

– ε is a regular expression denoting {},

– for each a Є Σ¸ a is a regular expression denoting

{a},

– Assume r and s are regular expressions denoting

sets R and S, then

. rs denotes RS,

. r + s denoted R υ S,

. r* denotes R*

Page 20: Automata

Positive Kleene a+

a*= {a ,aa ,aaa ,aaaa ,aaaaa ,………..}

Kleene Star a*

a*= {ε,a ,aa ,aaa ,aaaa ,aaaaa ……………..}

Page 21: Automata

Proof of Kleene Star

Let L0 and Li =L.L i-1 where i>=1 then Kleene closure of L

is L*.L* is the set such that L* =Ui=0 Li i=0 L0={ε}

SolutionSuppose L={01,10}

L* = L0 U L1 U L2 U ………Ln

Its given that L0={ε}

Take i=1

L1 =L L 1-1

Page 22: Automata

L1 =L L0

L1={01,10}.{ε}

L1={01 ε,10 ε}

L1={01,10}

Now Take i=2

L2 =L.L 2-1

L2 =L.L1

L2={01,10}. {01,10}

L2={0101,0110,1001,1010}

Now L*=L0 U L1 U L2 ….U Ln

L*={ε} U {01,10} U {0101,0110,1001,1010}…….

In a Kleene Star form it may be written as L*={01,10}*

Page 23: Automata

Regular Language/Rational Language, Recognizable

Language.

A regular, rational, or recognizable language is one

that fulfils

one of the following equivalent criteria:

L is defined by a regular expression.

There are a finite number of L-cones.

L is recognized by a finite state automaton or FSA.

Page 24: Automata

Language Expression Meaning Transition

Graph/Automata

L={0,1} r.e=(0+1)

r.e=(0/1)

r.e=(0 1)

choosing

from r1 or r2

L={0,1} r.e=(0.1)

r.e=(01)

r.e=(o∩1)

concatenati

on of r1 and

r2

L={0} r*=(0) zero or

more times

(Kleene

closure)

L={0} r+ =(0) one or more

times

0

1

0 1

0

0

0 0

Page 25: Automata

Types of Automata

Automata

Finite Automata Push Down Automata Turing Machine

(FA) (PDA) (TM)

Deterministic Non-Deterministic

Finite Automata (DFA) Finite Automata (NFA)

Page 26: Automata

FINITE AUTOMATA (FA)

NON-DETERMINISTIC FINITE

AUTOMATA

(NFA)

DETERMINISTIC FINITE

AUTOMATA

(DFA)

FINITE AUTOMATA

(FA)

Page 27: Automata

What is the difference between the

two?

Is there a single DFA for a

corresponding NFA?

Why do we want to do this anyway?

Page 28: Automata

Deterministic Finite Automata

For every state and every alphabet symbol there is exactly one move that the machine can make

Mathematical Definition

A Deterministic Finite Automata is a 5-tuple (Q, Σ, δ, qo, F)

where

Q→Total numbers of State(s)

Σ→Input(s)/Alphabets(s)

δ→Transition Function QXΣ

q0→Initial State(s)

F→Final State(s)

Page 29: Automata

Finite Automata State Graphs

An Input

A state

The start state

An accepting state

A transition a

a,b,…0,1,2…

Page 30: Automata

Example r.e =a.b

Q→Total numbers of State(s) = {q0,q1,q2}

Σ→Input(s)/Alphabets(s)={a,b}

q0→Initial State(s)={q0}

F→Final State(s)={q2}

δ→Transition Function QXΣ

QXΣ Input a Input b

q0 q1 є

q1 є q2

q2 є є

q0q1 q2

a bq2

Acceptance State

/Final State

Initial

State

Page 31: Automata

Nondeterministic Finite Automata

At each state, for each symbol, the machine can move into 0 or more states.

Mathematical Definition

A Non-Deterministic Finite Automata is a 5-tuple (Q,Σ,δ, qo, F)

where

Q→Total numbers of State(s)

Σ→Input(s)/Alphabets(s)

δ→Transition Function 2 pow Q

q0→Initial State(s)

F→Final State(s)

Page 32: Automata

Nondeterministic Finite Automata

Two non-deterministic elements:

Lambda transitions or epsilon

transitions

2 out arcs with same symbol

Page 33: Automata

Non-Deterministic Finite Automata

Example L={a}

a

a

a

1q 2q

3q

0q No transition:

the automaton hangs

Acceptance state/Final State

Two choices

QX Σ Input a

q0 q1 U q3

q1 q2

q2 є

q3 є

Page 34: Automata

Nondeterministic Finite Automata

Non-determinism

When machine is in a given state and reads a

symbol, the machine will have a choice of

where to move to next.

There may be states where, after reading a

given symbol, the machine has nowhere to go.

Applying the transition function will give, not 1

state, but 0 or more states.

Page 35: Automata

Non-Deterministic Finite Automata

1q 2q

3q

a

a

a

0q

No transition:

the automaton hangs

“accept”Two choices

Example: L = {a}

Page 36: Automata

Non-Deterministic Finite Automata

Example: L corresponds to the regular expression

{11 + 110}*0

1

q1

q2 q3

q0 q4

1 1

1 0

0start

Page 37: Automata

Non-Deterministic Finite Automata

L = set of strings ending in ab

q0 q1 q2starta b

a,b

Page 38: Automata

REGULAR EXPRESSION

RegularExpressions

NondeterministicFinite Automata(NFA)

DeterministicFinite Automata(DFA)

ImplementationOf DFA

Page 39: Automata

REGULAR EXPRESSION

Theorem If L is accepted by a DFA, then L is denoted by a regular expression.

The language of FA (regular language) is the set of strings that label paths that go from the start state to some accepting state.

The languages accepted by DFA, NFA,

e-NFA, Regular Expressions are called

regular languages

Page 40: Automata

REGULAR EXPRESSION

The regular expressions over are the

smallest set of expressions including

where

where A,B are rexp over

" " "

where A is a rexp over

‘c’

A+B

AB

A*

e

c

Page 41: Automata

Regular Expression Notation

a: an ordinary letter

ε: the empty string

r1 | r2: choosing from r1 or r2

r1r2 : concatenation of r1 and r2

r*: zero or more times (Kleene closure)

r+: one or more times

Page 42: Automata

NFA to DFA Conversion

What is the difference between the two?

Is there a single DFA for a corresponding

NFA?

Why do we want to do this anyway?

Page 43: Automata

Nondeterministic Finite Automata

Non-determinism

When machine is in a given state and reads a

symbol, the machine will have a choice of

where to move to next.

There may be states where, after reading a

given symbol, the machine has nowhere to go.

Applying the transition function will give, not 1

state, but 0 or more states.

Page 44: Automata

Nondeterministic Finite Automata

At each state, for each symbol, the machine can move into 0 or more states.

A Non-Deterministic Finite Automata is a

5-tuple (Q, S, d, qo, F) where

Input alphabet, i.e.

Transition function 2 pow Q

Initial state i.e.

Final states i.e.

:Q

:

:

:0q

:F

Set of states, i.e. { q0, q1, q2, q3, q4}

{1,0}

{q0}

{q4}

Page 45: Automata

Nondeterministic Finite Automata

Two non-deterministic elements:

Lambda transitions or epsilon transitions

2 out arcs with same symbol

Page 46: Automata

For every state and every alphabet symbol there is exactly one move that the machine can make

A Deterministic Finite Automata is a

5-tuple (Q, S, d, qo, F) where

Deterministic Finite Automata

:Q

:

:

:0q

:F

Input alphabet

Transition function Q x I

Initial state

Final states

Set of states

Page 47: Automata

DFA CYCLE

Regular Expression

NFA (e-move)

NFA (without e-move)

DFA

Page 48: Automata

Regular Expressions to NFA

For each kind of rexp, define an NFA

Notation: NFA for rexp M

•For e

•For input a

M

e

a

Page 49: Automata

NFA Empty Move

For A B

A Be

For A | B

A

B

e

e

e

e

Page 50: Automata

NFA Empty Move

For A*

Aee

e

e

Page 51: Automata

For re=r1*

e

e

e r1 eS A B Fstart

r1 r1S BAF Astart

r1

NFA (e-move)

DFA

States/

input

r1

S BFBA=BAF

A BAF

B

F

BAF BAF

Transaction table:

r1*BAFS

r1start

r1

NFA ->DFA (EXAMPLE-1)

Page 52: Automata

NFA ->DFA (EXAMPLE-2)

For re=r1.r2

NFA (e-move)

For r1 For r2

For r1.r2

A Br1

start C Dr2

start

A B C Der1 r2

start

Page 53: Automata

NFA ->DFA (EXAMPLE-2 cont….)

States/

input

r1 r2

A BC

B

C D

D

BC D

DFA

Transaction table:

A BC Dr2r1start

CA BC Dr2r1 r2start

r1.r2

Page 54: Automata

NFA ->DFA (EXAMPLE-3)

For re=r1+r2

For r1 For r2

C Dr2

startA Br1start

e eA B

r1

C Dr2

start S F

ee

For r1+r2

Page 55: Automata

NFA ->DFA (EXAMPLE-3 cont….)

FD

States/inpu

t

r1 r2

S BF DF

A BF

B

C DF

D

F

BF

DF

Transaction table:

DFABDFstart

r1/r2S

r1+r2

r1r1

BF A

DF Cr2

start S

r2

BF

DF

start S

r1

r2

Page 56: Automata

NFA ->DFA (EXAMPLE-1)

q0 q1 q2starta b

a,b

q0 q0q1 q0q2starta b

b

a

a

b

States

/

input

a b

q0 q1q0 q0

q1 q2

q2

q1q0 q1q0 q0q

2

q0q2 q1q2 q0

Transaction table:

NFA

Equivalent DFA

Page 57: Automata

NFA ->DFA (EXAMPLE-2)

B A

C

start

0

0

1

10

B ABCstart0

0

1AC

1

A

B ABCstart0

0

1AC

1

NFA

Equivalent DFA

States

/

input

0 1

B BAC

A AC

C

ABC ABC AC

AC AC

Transaction table: