Formal Languages and Automata http mail im tku

  • Slides: 26
Download presentation
形式語言 Formal Languages and Automata 淡江大學 資訊管理系 侯 永 昌 http: //mail. im. tku.

形式語言 Formal Languages and Automata 淡江大學 資訊管理系 侯 永 昌 http: //mail. im. tku. edu. tw/~ychou ftp: //mail. im. tku. edu. tw/Prof_Hou

教科書:An Introduction to Formal Languages and Automata, 5 th Edition, by Peter Linz, Jones

教科書:An Introduction to Formal Languages and Automata, 5 th Edition, by Peter Linz, Jones & Bartlett Learning 出版,開發圖書總經銷 淡江大學資訊管理系侯永昌 1

第一章 計算理論 (Theory of Computation)

第一章 計算理論 (Theory of Computation)

集合(Set) Union: S 1 S 2 = { x : x S 1 or

集合(Set) Union: S 1 S 2 = { x : x S 1 or x S 2} Intersection: S 1 S 2 = { x : x S 1 and x S 2} Difference: S 1 – S 2 = { x : x S 1 and x S 2} Complementation: S = { x : x U, x S} De. Morgan’s law: S 1 S 2 = S 1 S 2 § Powerset (set of subset): 2 S § Cartesian product: S = S 1 × S 2 = {(x, y) : x S 1, y S 2} § § § 淡江大學資訊管理系侯永昌 3

圖形(Graph) § § Path: a walk in which no edge is repeated Simple path:

圖形(Graph) § § Path: a walk in which no edge is repeated Simple path: a path with no vertex is repeated Cycle: a path from vi to it self Simple cycle: a cycle with no vertex other than the base are repeated § Loop: an edge from a vertex to itself 淡江大學資訊管理系侯永昌 6

Languages § Alphabet: a finite, nonempty set of symbols § String: finite sequences of

Languages § Alphabet: a finite, nonempty set of symbols § String: finite sequences of symbols from the alphabet § 例: = {a, b}, then abab and aaabbba are strings on § 通常用a, b, c, …代表字母,u, v, w, …代表 字串 § Concatenation of two strings: if w = a 1 a 2…an, v = b 1 b 2…bm, then wv = a 1 a 2…anb 1 b 2…bm 淡江大學資訊管理系侯永昌 15

Languages § Reverse of a string: if w = a 1 a 2…an, then

Languages § Reverse of a string: if w = a 1 a 2…an, then w. R = an…a 2 a 1 § Length of a string: |w| § Substring: any string of consecutive symbols in w § If w = uv, then substring u and v are said to be a prefix and suffix of w § If w = uv, then |w| = |u| + |v| 淡江大學資訊管理系侯永昌 16

Languages § If w is a string, then wn stands for the string obtained

Languages § If w is a string, then wn stands for the string obtained by repeating w n times § Empty string: = w 0 , | | = 0 § If is an alphabet, then * denotes the set of strings obtained by concatenating zero or more symbols from § 例: = {a, b}, then * = { , a, b, aa, ab, ba, bb, aaa, aab, …} § + = * – { } 淡江大學資訊管理系侯永昌 17

Languages § Language: any set of strings on an alphabet l l L 1

Languages § Language: any set of strings on an alphabet l l L 1 = {a, aab} is a finite language on L 2 = {anbn : n 0} = { , ab, aabb, aaabbb, …} is a infinite language on § Sentence: a string in a language L l l l aaaabbbb is in L 2 aab is not in L 2 注意:aabbba is not in L 2 § 因為語言是一個句子的集合,因此所有集合 的運算(交集、聯集、…)都可以用在語言上 淡江大學資訊管理系侯永昌 18

Languages § Complement of L: L = * – L § Reverse of L:

Languages § Complement of L: L = * – L § Reverse of L: LR = {w. R : w L} § Concatenation of L 1 and L 2: L 1 L 2 = {xy : x L 1, y L 2} § L concatenated with itself n times: Ln l l L 0 = { } L 1 = L L* = L 0 L 1 L 2 … L+ = L 1 L 2 L 3 … 淡江大學資訊管理系侯永昌 19

Languages § 例:L = {anbn : n 0}, then L 2 = {anbnambm :

Languages § 例:L = {anbn : n 0}, then L 2 = {anbnambm : n 0, m 0} L 2 = {aabbaaabbb, abab, aaabbb, …} § 例:L = {anbn : n 0}, then LR = {bnan : n 0} § 例:L = {anbn : n 0}, then L 2 可否寫成 {anbn : n 0}?它有什麼問題? 淡江大學資訊管理系侯永昌 20

Grammars § A grammar G = (V, T, S, P), where l l V

Grammars § A grammar G = (V, T, S, P), where l l V is a finite set of objects called variables T is a finite set of objects called terminal symbols S V is a special symbol call the start variable P is a finite set of productions § Production transforms one string into another § 例:Production x y 表示 x 可以用 y 來取代 § 例:string w = uxv, production x y,表示 w 可以寫成另一個string z = uyv,我們用w z 來表示 淡江大學資訊管理系侯永昌 21

Automata (Transition functions) 淡江大學資訊管理系侯永昌 24

Automata (Transition functions) 淡江大學資訊管理系侯永昌 24

Automata § Transition function: give the next state in term of the current state,

Automata § Transition function: give the next state in term of the current state, the current input symbol, and the information currently in the temporary storage § Configuration: a particular state of the control unit § Move: the transition of the automation from one configuration to the next § Deterministic automata: each move is uniquely determined by the current configuration § Nondeterministic automata: at each point it may have several possible moves, so we can only predict a set of possible actions 淡江大學資訊管理系侯永昌 25