第一章 1 自動機 (automata) time: 1:10~2:00 monday: homework practice, quiz 2:10~4:00...

28
1 第第第 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages and Automata, 3rd Edition, Peter Linz

Post on 21-Dec-2015

230 views

Category:

Documents


15 download

TRANSCRIPT

Page 1: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 1

自動機 (Automata)

Time:1:10~2:00 Monday: homework practice, quiz2:10~4:00 Wednesday: lecture

Textbook: (new!)An Introduction to Formal Languages and

Automata, 3rd Edition, Peter Linz

Page 2: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 2

Grading policy

45% for 2 midterm, 1 final examination15% for each midterm

45% for homework exercise and quizRandomly pick students to practice homework on

MondayOccasionally quiz on Monday

15% for 上課筆記No lecture slides 上課要抄筆記,學期間會抽查三次算分數

Page 3: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 3

1 Introduction to the theory of computation

Computer science 是很實際的學科,大多數人對 computation theory 沒有什麼興趣,除非理論能夠對他們所要解決的實際問題有幫助。那為什麼要學習計算理論的課程呢?理論提供一些幫助我們了解 computer science 的觀念;可以建構出一個理論的計算機,由理論的研究可知道實際電腦的限制。實際有用的東西常是依據「簡單的理論」而來。

理論觀念可應用在很多地方。這些理論的主題是有趣、令人興奮的。

Page 4: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 4

本課程的主要主題Automata: An automaton is a construct that possesses all the indispensable features of a digital computer.

A formal language is an abstraction of the general characteristics of programming languages.

之後再討論 mechanical computation 的概念,也就是 algorithm 的觀念,以及哪些問題適合用 algorithm 來解、哪些不能。

Page 5: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 5

outline

1.1 Mathematical preliminaries and notation sets介紹一些後面會用到的專有名詞及數學set theory functions, relations trees, graph deduction, induction, contradiction 等證明觀念

Page 6: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 6

1.1 Mathematical Preliminaries and Notation

集 合 Sets : A set is a collection of elements, without any structure other than membership.S = {0, 1, 2}, 可判斷 x S 與 x S

S = {i : i > 0, i 是偶數 }

union 聯集、 intersection 交集、 difference 差S1 S2 = { x: x S1 or x S2}

S1 S2 = { x: x S1 and x S2}

S1 - S2 = { x: x S1 and x S2}

Page 7: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 7

關於集合 (set)

complementation: The complement of a set S consists of all elements not in S.

Universal set U: 代表所有可能的元素。

空集合 Φ 或 ,empty set 或 null set :就是不包含任何元素的集合。S = S - = S, S =

},:{ SxUxxS

S

SSU ,

Page 8: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 8

關於集合 (set)

DeMorgan’s laws

子集合 subset若 S1 的元素也都是 S 的元素,則 S1 為 S 的 subset 。 S1 S

若 S 中存在一個元素不屬於 S1,則 S1 為 S 的 proper subset( 真子集合 ) 。 S1 S

disjoint set ,互斥集合,交集為空集合者。S1 S2 =

2121

2121

SSSS

SSSS

Page 9: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 9

關於集合 (set)有限集合 finite sets ,元素個數為有限者;其他的為 infinite sets 無限集合。集合 S 的元素個數記成 |S| 。冪集合 powerset: 所有子集合所形成的集合稱為冪集合。令 2S 為 S 的 powerset ,其元素個數為 2|S| 。S = {a, b, c}

2S = {, {a}, {b}, {c}, {a,b}, {b, c}, {c, a},

{a, b, c} }.

Page 10: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 10

關於集合 (set)

Cartesian product

S = S1 S2 = { (x, y) : x S1 and y S2 }

S1 S2 … Sn = {(x1, x2, …, xn ) : xi Si}

Example 1.2 令 S1 = {2, 4}, S2 = {2, 3, 5, 6}

S1 S2 = {(2,2), (2, 3), (2, 5), (2, 6), (4, 2),

(4, 3), (4, 5), (4, 6)}

Page 11: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 11

關於 functions and relationsA function is a rule that assigns to elements of one set a unique element of another set.

f : S1 →S2

其中 f 的 domain( 定義域 ) 是 S1 的 subset 、 f 的 range( 值域 ) 是 S2 的 subset 。如果 S1 就是 f 的 domain ,則 f 稱為 total function 、否則稱為 partial function。

Page 12: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 12

關於 functions and relations

We are often interested in functions their domain and range are in the set of positive

integers their behavior when arguments are very large

Page 13: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 13

關於 functions and relations

令 f(n) 與 g(n) 是兩個正整數函數(domain 是正整數的 subset) 。 If there exists a positive constant c such that for all n, f(n) c g(n) , 則 稱 「 f has order at most g 」, f(n) = O(g(n))若 |f(n)| c |g(n)|, 「 f has order at least g 」 , f(n) = Ω (g(n))

若存在 c1 與 c2 兩個常數, c1 |g(n)| |f(n)| c2 |g(n)|, 「 f and g have the same order of magnitude 」 , f(n) = Θ (g(n))

Page 14: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 14

關於 functions and relations

Example 1.3

f(n) = 2n2 + 3n

g(n) = n3

h(n) = 10 n2 + 100

則f(n) = O(g(n))

g(n) = Ω(h(n))

f(n) = Θ(h(n))

只與最高次項有關、其餘的項目對函數的成長速度關係較少

關於 O, Θ, Ω 在演算法、離散數學有比較詳細的描述。

Page 15: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 15

關於 functions and relations

函數可以用集合的方式表示{(x1, y1), (x2, y2), …} , 其 中 xi 是 domain 的元素、 yi 是 range 的元素。一個集合若表示函數的話,每個 xi 只能在 pair 中第一個位置出現一次。若有某個 xi 出現兩次以上的話,就不是 function ,只能稱它為 relation 。所以 relation 比函數更一般化。

Page 16: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 16

關於 functions and relations

一種特別的 relation 稱為 equivalence relation; (x,y) 若屬於一個 equivalence relation 的話,記成 x≡y 。一個 equivalence relation 必須滿足下列三個條件: the reflexivity rule( 反身性 ), x≡x for all x, the symmetry rule( 對稱性 ), if x≡y then y≡x the transitivity rule( 遞移性 ), if x≡y and

y≡z , then x≡z.

Page 17: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 17

Equivalence relation

Example 1.4 除 以 3 的 餘 數 是 不 是 equivalence relation 呢?we define relation for nonnegative integers,

x≡y iff x mod 3 = y mod 32≡5, 12≡0, 0≡36, …

Page 18: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 18

關於 Graphs and Trees

Graph G = (V, E) , V = {v1, v2, …, vn} 是 vertex set 點集合 , E = {e1, e2, … em} 是 edge set 邊集合,兩者皆為有限集合,有限圖形。ei = (vj, vk) 是從 vj 連到 vk 的邊、有方向的邊; ei 是 vj 的 outgoing edge,是 vk 的 incoming edge。

邊 都 有 方 向 的 圖 形 、 稱 為 有 向 圖 directed graph, digraph。圖形的點或邊都可以有名稱 (label) 。

Page 19: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 19

關於 Graphs and Trees

v 1 v 3v 2

V={v1,v2,v3}, E={(v1,v3), (v3, v1), (v3, v2), (v3, v3)}

walk from v1 to v2 : (v1, v3), (v3, v3), (v3, v2)

path: 沒有重複邊的 walk, simple path : 沒有重複 vertex 的 path

length, cycle, simple cycle, loop

Figure 1.1

loopcycle

Page 20: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 20

關於 Graphs and TreesA tree is a directed graph that has no cycle.

There is exactly one path from the root to every other vertex.

root 沒有 incoming edge 、其他 vertex 都有一條 incoming edge ;parent, child, leaves, level: root 到該點的 edge 數 , height。ordered trees,同一個 level 的 node 都有順序。degree: in-degree 與 out-degree

Page 21: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 21

關於 Graphs and Treesroot

leaf

level 0

level 3

Height = 3

Figure 1.2

Page 22: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 22

關於 proof techniques必須擁有「了解證明的能力」。最 常 用 、 最 重 要 的 兩 個 證 明 : proof by induction 歸納法、 proof by contradiction 矛盾證法、反證法。歸納法證明通常是證明 P1, P2, … 每個 statement 都是正確的,包括幾個部份Basis: 已知 P1, P2, …, Pk, for k 1, 是正確的Inductive assumption: 假設 P1, P2, …, Pn 是正確的, for some n k 。

Inductive step :證明 P1, P2, …, Pn → Pn+1, for any n k

Page 23: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 23

關於 proof techniquesExample 1.5 A binary tree is a tree in which no parent can have more than two children. Prove that a binary tree of height n has at most 2n leaves.

Proof: 令 l(n) 代表高度為 n 的 binary tree 最多的 leaf 數。因此等於要證明 l(n) 2n.

Basis: l(0) = 1 20,故成立。Inductive assumption: l(i) 2i, for i = 0, 1, …, nInductive step: 高度為 n+1 的 binary tree 之 leaf 數最多就是 l(n) 的兩倍,因此 l(n+1) = 2 l(n) 2×2n = 2n+1 。

由數學歸納法得證。

Page 24: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 24

關於 proof techniques

Example 1.6 證明

Basis: S0 = 0 = 0(0+1)/2

因為 Sn+1 = Sn + n + 1, 所以 Sn+1 = n(n+1)/2 + n + 1

= (n+1)(n+2)/2 。故由數學歸納法得證

2

)1(

0

nniS

n

in

2

)1(

0

nniS

n

in

Page 25: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 25

關於 proof techniques

數學歸納法與遞迴的關係在作遞迴函數時,求 f(n+1) 通常必須由 f(n), f(n-1), …, f(1) 來求得,這與數學歸納法中的 inductive step 是相同的。而遞迴函數中,當執行到 n k 時,就不再作遞迴呼叫,這也與歸納法中的 basis 相同。因此用數學歸納法證明出來的方式、都很容易直接轉換為遞迴函數的寫法。

Page 26: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 26

關於 proof techniques

Proof of contradiction 反證法,若我們要證明某個 statement P 成立,則先假設相反的結果、就是假設 P 不成立,然後看由這個假設是否能推導出明顯不正確的結果。只要我們的每個推理都是正確的,那就必然導致這個假設是錯的,因此 P 就必然成立。

Page 27: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 27

關於 proof techniquesExample 1.7 A rational number( 有理數 ) is a number that can be expressed as the ration of two integers n and m so that n and m have no common factor. 否 則 就 是 irrational。請證明√ 2 為 irrational 。

Proof: 假設 √ 2 為有理數,令 √ 2 = n/m ,且 gcd(m,n) = 1 。

所以 n 一定是 2 的倍數,令 n = 2k 則

因此、 m 也是 2 的倍數, gcd (m, n) 2 ,產生矛盾。因此 √ 2 必然為 irrational 。

222

2

222 nmm

n

m

n

222222 2422 kmkmnm

Page 28: 第一章 1 自動機 (Automata) Time: 1:10~2:00 Monday: homework practice, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages

第一章 28

Announcement

We have homework next Monday, please check my course homepage.