dcp 3122 introduction to formal languages - …wgtzeng/courses/fl2017springunder/1... · formal...
TRANSCRIPT
![Page 1: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/1.jpg)
Introduction
Wen-Guey Tzeng
Computer Science Department
National Chiao Tung University
![Page 2: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/2.jpg)
Formal languages and finite automata
• We have been building computing machines for solving computing problems.22222
• Computers are everywhere.• Questions
– What is a computing machine?– What problems can be solved by a computing machine?– What problems cannot be solved?
• Finite automata: abstract models of computing machines
• Formal languages: formal representation of computing problems
22017 Spring
![Page 3: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/3.jpg)
Classification
• Finite automata: by types of memories– Finite automata
– Pushdown automata
– Turing machines
• Formal languages: by types of grammars– Regular languages
– Context-free languages
– Recursive languages (solvable)
– Recursively enumerable languages (semi-solvable)
– …
32017 Spring
![Page 4: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/4.jpg)
Relations
• Finite automata and regular languages
• Pushdown down automata and context-free
languages
• Turing machines and recursive languages
• Complexity classes: by runtime or space used by
Turing machines– P: polynomial time computable
– NP: non-deterministic polynomial time computable
– EXP: solvable in exponential time
– …
42017 Spring
![Page 5: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/5.jpg)
5
Computing problems
Computing machines
Finite automata
Form
aliz
atio
n
Formal languages
Ab
stra
ctio
n
Relations
Classification by: memory,
runtime, space, etc.
Classification by: grammars, machines, etc. • Regular vs. finite automata
• Context-free vs. pushdown• Recursive vs. Turing machines• Complexity classes• …
Yes/No problems
2017 Spring
![Page 6: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/6.jpg)
Applications
• Programming languages• Compilers• Natural language processing• Algorithm design• Software engineering• Pattern recognitions• Machine learning• …
62017 Spring
![Page 7: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/7.jpg)
72017 Spring
![Page 8: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/8.jpg)
8
How to compile a Java program, like the above?• We need a grammar for the Java programming
language• Context-free grammar
• We need a compiler to compile it• Pushdown automata
2017 Spring
![Page 9: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/9.jpg)
92017 Spring
![Page 10: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/10.jpg)
Mathematical notation
• Set: a collection of elements
– |S|: the number of elements in S
– SxT={(x, y) | xS, yT}
• Function
– f: S1S2
• Binary relation
– R S1xS2
– xS1 and yS2 has relation R if (x, y)R
102017 Spring
![Page 11: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/11.jpg)
Three Basic Concepts
1. Languages– Symbol set (alphabet) ={a, b, c, …}
– String: w=a1a2…an, n0, ai
• |w|: length of string
• String concatenation: w1w2
• String reversing: wR=anan-1…a1
• an = aa… a (repeated n times)
• Prefix(w)={, a1, a1a2, …, a1a2…an}
• Suffix(w)={, an, an-1an, …, a1a2…an}
• Empty string , – ||=0
– w= w=w112017 Spring
Alphabet={a,b}
Strings:aba, baba, …
Languages:L={aba, abbaa,
aaba, aa, …}
![Page 12: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/12.jpg)
– A language L over is a subset of strings over
– The language consists of all strings: *
• * over {a,b} = {, a, b, aa, ab, ba, bb, …}
– The language consists of all non-empty strings +
• + = * - {}
– Operations over languages• Reverse L: LR = {wR: wL }
• Complementation of L: Lc = * - L
• Concatenation: L1L2 = {xy: xL1, yL2}
• Ln = {x1x2…xn: xiL}– L0 = {}
– L* = L0 L1 …
– L+ = L1 L2 …
122017 Spring
![Page 13: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/13.jpg)
2. Grammar: a set of rules for generating strings
– G=(V, T, P, S)
– V: set of variables
– T: set of terminals (symbols)
– P: set of production rules
– SV: the start variable
132017 Spring
![Page 14: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/14.jpg)
Example
G=({S,A,B}, {a,b}, {SaA, AbS, S}, S)
• String generation/derivation
• The language generated by G
– L(G) = {w | S * w}
142017 Spring
![Page 15: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/15.jpg)
• Problem: find grammars for languages over ={a, b}
– L1 = {anbn | n0}
– L2 = {w | na(w)=nb(w)}
– L3 = {anbm | nm0}
152017 Spring
![Page 16: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/16.jpg)
3. Automaton: an abstract model of a digital computer
– Input
– Control unit: represented by “states”
– Storage
– Output
– Operating in discrete time frame
162017 Spring
![Page 17: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/17.jpg)
172017 Spring
![Page 18: DCP 3122 Introduction to Formal Languages - …wgtzeng/courses/FL2017SpringUnder/1... · Formal languages and finite automata •We have been building computing machines for solving](https://reader030.vdocuments.mx/reader030/viewer/2022021611/5b913dbd09d3f252108d9895/html5/thumbnails/18.jpg)
Language representation
• Informal description
– L = {aa, aaa, aab, aaaa, …}
– L = {anbn | n0 }
• Formal description
– Grammar: language generator
• It tells us how a string in a language is generated
– Automata: language acceptor
• It tells us whether a given string belongs to a language
2017 Spring 18