自動機 (Automata) Time: Textbook: (new!) 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 第一章
Grading policy 45% for 2 midterm, 1 final examination 15% for each midterm 45% for homework exercise and quiz Randomly pick students to practice homework on Monday Occasionally quiz on Monday 15% for 上課筆記 No lecture slides 上課要抄筆記,學期間會抽查三次算分數 第一章
1 Introduction to the theory of computation Computer science 是很實際的學科,大多數人對 computation theory 沒有什麼興趣,除非理論能夠對他們所要解決的實際問題有幫助。 那為什麼要學習計算理論的課程呢? 理論提供一些幫助我們了解 computer science 的觀念;可以建構出一個理論的計算機,由理論的研究可知道實際電腦的限制。實際有用的東西常是依據「簡單的理論」而來。 理論觀念可應用在很多地方。 這些理論的主題是有趣、令人興奮的。 第一章
本課程的主要主題 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 來解、哪些不能。 第一章
outline 1.1 Mathematical preliminaries and notation sets 介紹一些後面會用到的專有名詞及數學 set theory functions, relations trees, graph deduction, induction, contradiction 等證明觀念 第一章
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} 第一章
關於集合(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 = 第一章
關於集合(set) DeMorgan’s laws 子集合 subset 若 S1 的元素也都是 S 的元素,則 S1 為 S 的 subset。S1 S 若 S 中存在一個元素不屬於 S1,則 S1 為 S 的 proper subset(真子集合)。 S1 S disjoint set,互斥集合,交集為空集合者。 S1 S2 = 第一章
關於集合(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} }. 第一章
關於集合(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)} 第一章
關於 functions and relations A 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。 第一章
關於 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 第一章
關於 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)) 第一章
關於 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, Θ, Ω 在演算法、 離散數學有比較詳細的描述。 第一章
關於 functions and relations 函數可以用集合的方式表示 {(x1, y1), (x2, y2), …},其中 xi 是 domain 的元素、yi 是 range 的元素。 一個集合若表示函數的話,每個 xi 只能在 pair 中第一個位置出現一次。 若有某個 xi 出現兩次以上的話,就不是 function,只能稱它為 relation。所以 relation 比函數更一般化。 第一章
關於 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. 第一章
Equivalence relation Example 1.4 除以 3 的餘數是不是 equivalence relation 呢? we define relation for nonnegative integers, x≡y iff x mod 3 = y mod 3 2≡5, 12≡0, 0≡36, … 第一章
關於 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)。 第一章
關於 Graphs and Trees loop cycle Figure 1.1 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 第一章
關於 Graphs and Trees A 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 第一章
關於 Graphs and Trees 第一章
關於 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 第一章
關於 proof techniques Example 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, …, n Inductive step: 高度為 n+1 的 binary tree 之 leaf 數最多就是 l(n) 的兩倍,因此 l(n+1) = 2 l(n) 2×2n = 2n+1。 由數學歸納法得證。 第一章
關於 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。 故由數學歸納法得證 第一章
關於 proof techniques 數學歸納法與遞迴的關係 在作遞迴函數時,求 f(n+1) 通常必須由 f(n), f(n-1), …, f(1) 來求得,這與數學歸納法中的 inductive step 是相同的。 而遞迴函數中,當執行到 n k 時,就不再作遞迴呼叫,這也與歸納法中的 basis 相同。 因此用數學歸納法證明出來的方式、都很容易直接轉換為遞迴函數的寫法。 第一章
關於 proof techniques Proof of contradiction 反證法,若我們要證明某個 statement P 成立,則先假設相反的結果、就是假設 P 不成立,然後看由這個假設是否能推導出明顯不正確的結果。 只要我們的每個推理都是正確的,那就必然導致這個假設是錯的,因此 P 就必然成立。 第一章
關於 proof techniques Example 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。 第一章
Announcement We have homework next Monday, please check my course homepage. 第一章