113491792 automata theory

41
Dr. N. R. Ansari Theory of Computation 1 Dr. N. R. Ansari Theory of Computation (Theory of Automata) (Introduction) LECTURE: 1

Upload: irem-civelek

Post on 28-Dec-2015

31 views

Category:

Documents


1 download

TRANSCRIPT

Dr. N. R. Ansari

Theory of Computation

11

Dr. N. R. Ansari

Theory of Computation

(Theory of Automata)

(Introduction)

LECTURE: 1

Dr. N. R. Ansari

Theory of Computation

22

About Me Education

2001, MCS Bahria Institute / Peshawar University

2005, M.S. (Software Engineering) NUST

2008, Ph.D. (Computer Engineering) Graz University of Technology, Austria.

Research Interests Model-based and Qualitative Reasoning

Distributed Computing

Verification and Validation

Test Pattern Generation

Theoretical Computer Sciences

Dr. N. R. Ansari

Theory of Computation

33

About Me Work Experiences

Permanent Faculty Member, COMSATS IIT Islamabad.

Visiting Faculty Member, COMSATS, AIOU

Research Assistant, Graz University of Technology, Austria

Senior Researcher in a Defence Organization

Offshore Post-Doc Researcher, Graz University of Technology.

Contact [email protected]

0331-5260536

Dr. N. R. Ansari

Theory of Computation

44

Pragmatics Pre-Requisites

No Pre-Requisite

Text book Introduction to Computer Theory by Daniel I.A. Cohen

Quizzes Roughly once every two weeks

Marks Distribution

Theoretical Course

40 % Mid-term, 40% Final, 20 % Quizzes

Dr. N. R. Ansari

Theory of Computation

55

Course Objectives The major objective of this course is to introduce the student to the

concepts of theory of computation in computer science. The student should acquire insights into the relationship among formal languages, formal grammars, and automata.

Upon successful completion of this course, students will be able to:

Apply a number of proof techniques to theorems in language design.

Develop a clear understanding of un-decidability.

Understand the equivalence between Nondeterministic Finite State Automata and Deterministic Finite State Automata.

Understand the equivalence between Context-Free Grammars and Nondeterministic Pushdown Automata.

Appreciate the power of the Turing Machine, as an abstract

automaton, that describes computation, effectively and efficiently.

Dr. N. R. Ansari

Theory of Computation

66

Course Outline(1) Introduction and Languages. (2) Regular Expressions. (3) Finite Automata. (4) Transition Graphs. (5) Kleene's Theorem. (6) Finite Automata with Output. (Moore /Mealy Machines) (7) Regular Languages. (8) Decidability. (9) Context-Free Grammars. (10)Grammatical Format. (11)Pushdown Automata.(12)CFG = PDA. (13)Context-Free Languages. (14)Decidability. (15)Turing Machines.(16)Minsky's Theorem. (17)Computers.

Dr. N. R. Ansari

Theory of Computation

77

Theory of Computation The theory of computation is the branch of computer science

and mathematics that deals with whether and how efficiently problems can be solved on a model of computation, using an algorithm.

A model of computation is the definition of the set of allowable operations used in computation and their respective costs

The field is divided into two major branches

computability theory and

complexity theory

Computability theory deals primarily with the question of the extent to which a problem is solvable on a computer.

Complexity theory considers not only whether a problem can be solved at all on a computer, but also how efficiently the problem can be solved.

Dr. N. R. Ansari

Theory of Computation

88

Automata Theory Automata theory is the study of abstract machines and

problems which they are able to solve

A typical abstract machine consists of a definition in terms of input, output, and the set of allowable operations used to turn the former into the latter.

Automata theory is a step in abstracting your attention away from any particular kind of computer or particular programming language

In English we have letter, words and sentences (relationship)

Not all collection of letters form a valid word, not all collections of words form a valid sentence

Dr. N. R. Ansari

Theory of Computation

99

Automata Theory Same in Computer Languages

Certain character strings are recognized (do, if, While)

Certain strings of words are recognizable commands

Certain set of commands become a program

Its important to adopt a structure, where the decision whether certain smaller units constitute a larger unit is based on explicit rules and not guesswork.

It is important that a program compiles whether or not it does what the programmer intended

If it compiles Its Valid and machine is responsible for executing the specified instructions

Its hard to state all the rules for the language ENGLISH

But in programming languages we can insist on precise rules, computers cannot understand informal speech

Dr. N. R. Ansari

Theory of Computation

1010

Introduction to defining languages Today, we will begin with only one finite set of fundamental

units out of which we build structures, it is called alphabet.

A certain specified set of strings of characters from the alphabet is called the language.

The strings which are permissible in the language are called words.

We shall allow a string to have no letters. This we call the empty string or null string and denote with the symbol Λ.

Lets start with an alphabet having only one letter, the ‘x’

Σ = {x}

L1 = {x xx xxx xxxx ……..}

Or L1 = {xn for n = 1 2 3 4…..}

Similarly L2 = {x xxx xxxxx xxxxxxx ……….}

L2 = {x2n+1 for n = 0 1 2 3 4……..}

Dr. N. R. Ansari

Theory of Computation

1111

Length and Reverse of a string and Palindrome We define the length of the string to be the number of letters in

the string.

If a = xxxx then length(a) = 4

Length(428) = 3

Length(Λ) = 0

If ‘a’ is a word in some language L, then reverse(a) is the same string of letters spelled backward, called the reverse of ‘a’.

Reverse(xxx) = xxx

Reverse(420) = 024

If Σ = { a b} then PALINDROME = { Λ, and all strings x such that reverse(x) = x}

PALINDROME = {Λ a b aa bb aaa aba bab bbb aaaa abba………}

This language has some very interesting properties which we will examine later.

Dr. N. R. Ansari

Theory of Computation

1212

KLEENE CLOSURE Given an alphabet Σ, we wish to define a language in which

any string of letters from Σ is a word, even the null string

This is called closure of the alphabet and denoted by Σ*

This notation is sometimes known as kleene star

If Σ = {x}, then

Σ* = L1 = {Λ x xx xxx xxxx……….}

If Σ = {0 1} then

Σ* = L2 = {Λ 0 1 00 01 10 11 000 001…….}

If Σ = {a b c} then

Σ* = L3 = {Λ a b c aa ab ac ba bb bc ca cb cc aaa …..}

Dr. N. R. Ansari

Theory of Computation

1313

KLEENE CLOSURE If S is a set of words, then by S*, we mean the set of all finite

string formed by concatenating words from S, where null string is also included.

If S = {aa b} then

S* = { Λ plus any word composed of factors of a and ab}

S* = { Λ b aa bb aab baa bbb aaaa aabb baab bbaa bbbb aaaab ……..}

If we wish to modify the concept of closure to refer to only the concatenation of some (non-zero) strings from a set S, we use the notation + instead of *

If Σ = {x} then

Σ+ = {x xx xxx xxxx ………}

Dr. N. R. Ansari

Theory of Computation

1414

Quiz # 0 This Quiz carries “0” marks and will provide you the idea of

the quizzes you are going to get in this course.

Exercises at the end of the chapter are important.

Consider the language S*, where S = {ab ba}

Is the string (abbba) a word in this language?

What about abababababba

Write out all the words in S* that have seven or fewer letters.

Let S = {ab bb} and let T = {ab bb bbbb}, show that S* = T*

Let S = {ab bb} and let T = {ab bb bbb}, show that S* ≠ T*

Dr. N. R. Ansari

Theory of Computation

1515

We have completed Chapter 1 and Chapter 2

Forget about Chapter 1 (Not important)

Next time we will not have any MULTIMEDIA

Dr. N. R. Ansari

Theory of Computation

1616

Dr. N. R. Ansari

Theory of Computation

(Theory of Automata)

(Context Free Grammars)

Chapter 12

Dr. N. R. Ansari

Theory of Computation

1717

Grammars Numerical numbers

1, 2, 3, ………

I, II, III,……..

١,٢,٣ ,…….

Binary, Octal, Hex

Character sets are different, Grammars can be different

G = <N, T, P, S>

N = {S, A, V, C} // Nonterminal, parts of speech

T = {(,), and , not, or, boolean variables} // Terminal, vocabulary

P = { S (S) SA SV S C

S b S S and S S S or S S not S }

A sentence is a string of symbols generated from the start symbol

not((b1 or b2) and (b2 or b3))

Dr. N. R. Ansari

Theory of Computation

1818

Context Free Grammars We have just studies Context Free Grammar (CFG)

Context free as sentence can be generated in any sequence

On the left hand side of production rules we have a non-terminal and on the right hand side we have a sequence of terminal and non-terminals.

The language generated by G is the set of all possible sentences that may be generated from the start symbol S.

Context-free grammars are important because they are powerful enough to describe the syntax of programming languages.

almost all programming languages are defined via context-free grammars

Formal Definition from BOOK

Dr. N. R. Ansari

Theory of Computation

Grammars Grammars express languages

Example: the English language

verbpredicate

nounarticlephrasenoun

predicatephrasenounsentence

_

_

walksverb

runsverb

dognoun

catnoun

thearticle

aarticle

Dr. N. R. Ansari

Theory of Computation

2020

Context Free Grammars• A derivation of “the dog walks”:

Another grammar (derive ab)

Whats the language?

walksdogthe

verbdogthe

verbnounthe

verbnounarticle

verbphrasenoun

predicatephrasenounsentence

_

_

S

aSbS

abaSbS

aSbS S

Dr. N. R. Ansari

Theory of Computation

Derivation Order

ABS .1

A

aaAA

.3

.2

B

BbB

.5

.4

aabaaBbaaBaaABABS54321

Leftmost derivation:

aabaaAbAbABbABS32541

Rightmost derivation:

Dr. N. R. Ansari

Theory of Computation

|AB

bBbA

aABS

Leftmost derivation:

abbbbabbbbB

abbBbbBabAbBabBbBaABS

Rightmost derivation:

abbbbabbBbb

abAbabBbaAaABS

Dr. N. R. Ansari

Theory of Computation

More Examples from Book

Derivation Trees

Dr. N. R. Ansari

Theory of Computation

ABS

ABS |aaAA |BbB

S

BA

Dr. N. R. Ansari

Theory of Computation

ABS |aaAA |BbB

aaABABS

a a A

S

BA

Dr. N. R. Ansari

Theory of Computation

ABS |aaAA |BbB

aaABbaaABABS S

BA

a a A B b

Dr. N. R. Ansari

Theory of Computation

ABS |aaAA |BbB

aaBbaaABbaaABABS S

BA

a a A B b

Dr. N. R. Ansari

Theory of Computation

ABS |aaAA |BbB

aabaaBbaaABbaaABABS S

BA

a a A B b

Derivation Tree

Dr. N. R. Ansari

Theory of Computation

aabaaBbaaABbaaABABS

yield

aab

baa

S

BA

a a A B b

Derivation Tree

ABS |aaAA |BbB

Dr. N. R. Ansari

Theory of Computation

Ambiguity

Dr. N. R. Ansari

Theory of Computation

aEEEEEE |)(|| aaa

E

EE

EE

a

a a

aaaEaa

EEaEaEEE

*

leftmost derivation

Dr. N. R. Ansari

Theory of Computation

aEEEEEE |)(|| aaa

E

EE

a a

EE a

aaaEaa

EEaEEEEEE

leftmost derivation

Dr. N. R. Ansari

Theory of Computation

aEEEEEE |)(|| aaa

E

EE

a a

EE a

E

EE

EE

a

a a

Two derivation trees

Dr. N. R. Ansari

Theory of Computation

The grammar aEEEEEE |)(|| is ambiguous:

E

EE

a a

EE a

E

EE

EE

a

a a

string aaa has two derivation trees

Dr. N. R. Ansari

Theory of Computation

string aaa has two leftmost derivations

aaaEaa

EEaEEEEEE

aaaEaa

EEaEaEEE

*

The grammar aEEEEEE |)(|| is ambiguous:

Dr. N. R. Ansari

Theory of Computation

Why do we care about ambiguity?

E

EE

a a

EE a

E

EE

EE

a

a a

aaa

take 2a

Dr. N. R. Ansari

Theory of Computation

E

EE

EE

E

EE

EE

6222

2

2 2 2 2

2

8222

4

2 2

2

6

2 2

24

8

Dr. N. R. Ansari

Theory of Computation

• We want to remove ambiguity

• Ambiguity is bad for programming languages

Dr. N. R. Ansari

Theory of Computation

We fix the ambiguous grammar:

aEEEEEE |)(||

New non-ambiguous grammar:

aF

EF

FT

FTT

TE

TEE

)(

Dr. N. R. Ansari

Theory of Computation

aF

EF

FT

FTT

TE

TEE

)(

aaaFaaFFa

FTaTaTFTTTEE

E

E T

T F

F

a

T

F

a

a

aaa

Dr. N. R. Ansari

Theory of Computation

Total Language Tree From Book