1 / 83

Lecture Notes for Computation

Lecture Notes for Computation. Book : 《 计算理论导引 》 Introduction to the Theory of Computation Chap5 Deciding context-free languages Professor : 唐常杰 TangChangjie@cs.scu.edu.cn Http://teacher.scu.edu.cn/~chjtang Students : Ph.D. 2000---2007, SCU

Download Presentation

Lecture Notes for Computation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture Notes for Computation Book :《计算理论导引》 Introduction to the Theory of Computation Chap5 Deciding context-free languages Professor : 唐常杰 TangChangjie@cs.scu.edu.cn Http://teacher.scu.edu.cn/~chjtang Students : Ph.D. 2000---2007, SCU Style : Lecture / Seminar

  2. 上次已经讲完定理 4.1—4.8 • 本周稍作复习, 可从停机问题开始。

  3. 今天课程 • Chapter 4: • 4.1.1 Deciding RL properties 复习上周 • 4.1.2 Deciding context-free languages • 4.2 The Halting Problem • 4.2 Countable and uncountable infinities • 4.2 Diagonalization arguments

  4. Deciding Languages 准备引入通用图灵机 cp107 复习 : 下列问题可判定 ADFA = { B,w | B is a DFA that accepts w } ACFG = { G,w | G is a CFG that generates w } are TM decidable. 。 即可写算法,算出个 成员籍的 yes / no 不断提出问题 ,满足好奇心是基础研究的方法之一。 问题 :What about the obvious next candidate ATM = {M,w | M is a TM that accepts w }? Is one TM M1 capable of simulating all other TMs?

  5. Deciding Languages 准备引入通用图灵机 cp107 复习 : 下列问题可判定 ADFA = { B,w | B is a DFA that accepts w } ACFG = { G,w | G is a CFG that generates w } are TM decidable. 。 即可写算法,算出个 成员籍的 yes / no 不断提出问题 ,满足好奇心是基础研究的方法之一。 问题 :What about the obvious next candidate ATM = {M,w | M is a TM that accepts w }? Is one TM M1 capable of simulating all other TMs?

  6. Deciding Languages 准备引入停机问题 cp107 不断提出问题 ,满足好奇心是基础研究的方法之一。 问题 : ATM = {M,w | M is a TM that accepts w }? 是否可判定?) A --Accept ATM 又称为 接受问题 或停机问题(名称来源稍后解释)后面将证,停机问题 可被识别,但不能被判定) 如果有个TM Deter_Accept,对任意对子<M,w>,判断出它是否在ATM中,即M是否接受w。 下面用他来解决哥德巴赫猜想( 可能有错,暂时不删除,作错误记号)

  7. Deciding Languages 准备引入通用图灵机 cp107 问题 :下列想法是否正确,说出理由。 ATM = {M,w | M is a TM that accepts w }? 是否可判定?(正确答案,它可识别,但不能被判定) 如果有个通用机U,对任意 对子 <M,w>,判断出它是否在ATM中,即M是否接受w,下面试图用它来解决哥德巴赫猜想. 造 TM G 如下: bool G(2n) { start: stop=false; result=true; 把2n分解为 { (1,2n-1),(3,2n-3),…} 如果所有 对子 中,至少有一个非素数, { stop=true; result=false;} //找到了一个大偶数,不能分成1+1,猜想为假 if stop return(result) else { n=n+2; goto start; } } 再用 Deter_Accept去判断 <G,0>是否在ATM中。不在,则该猜想为假。

  8. The Universal TM U 仿真的直观感觉 Win中模拟DOS上的dir Win 是TM, Dos 是TM, Dos可以编码成为串”M” 仿真时 Win相当于 通用图灵机 Win(“M”,”dir”) {分配M所需的空间S, 把”M”复制到S上去; 在Win的监控下,在S上运行DOS,运行 dir 善后,退出; } 用3带机 Win 仿真控制带 被模拟机带S: Dos 演算带,Buff当前内容

  9. The Universal TM U 仿真的直观感觉 Win中模拟DOS上的dir WinExec(“command.com/C”,”dir”); Win 是TM, Dos 是TM, Dos可以编码成为串”M” 仿真时 Win相当于 通用图灵机 Win(“M”,”dir”) {分配M所需的空间S, 把”M”复制到S上去; 在Win的监控下,在S上运行DOS,运行 dir 善后,退出; } 用3带机 Win 仿真控制带 被模拟机带S: Dos 演算带,Buff当前内容 Win垂帘听DOS 之政 或Win 挟天子以令诸侯

  10. The Universal TM U:ATM是图灵可识别的, cp104 Given a description M,w of a TM M and input w, can U simulates M on w? We can do so via a universal TM U (2-tape): • Check if M is a proper TMLet M = (Q,,,,q0,qaccept,qreject) • Write down the starting configuration  q0w  on the second tape • Repeat until halting configuration is reached: • Replace configuration on tape 2 by nextconfiguration according to  • “Accept” if qaccept is reached; “reject” if qreject 简言之:bool U(M,w) { return( M (w) ) ;} //如果M不死循环,U也不

  11. The Universal TM U:ATM是图灵可识别的, cp107 Given a description M,w of a TM M and input w, can U simulates M on w? We can do so via a universal TM U (2-tape): • Check if M is a proper TMLet M = (Q,,,,q0,qaccept,qreject) • Write down the starting configuration  q0w  on the second tape • Repeat until halting configuration is reached: • Replace configuration on tape 2 by nextconfiguration according to  • “Accept” if qaccept is reached; “reject” if qreject 简言之:bool U(M,w) { return( M (w) ) ;} //如果M不死循环,U也不

  12. The Universal TM U:ATM是图灵可识别的, cp107 Given a description M,w of a TM M and input w, can U simulates M on w? We can do so via a universal TM U (2-tape): • Check if M is a proper TMLet M = (Q,,,,q0,qaccept,qreject) • Write down the starting configuration  q0w  on the second tape • Repeat until halting configuration is reached: • Replace configuration on tape 2 by nextconfiguration according to  • “Accept” if qaccept is reached; “reject” if qreject 简言之:bool U(M,w) { return( M (w) ) ;} //如果M不死循环,U也不 U垂帘听 M 之政, 或M做事,U出头露面

  13. 4.2 The Halting Problem ATM cp108 上页已经证明 可识性 ATM = {M,w | M is a TM that accepts w } is TM-recognizable, but can we also decide it ? The problem lies with the cases when M does not halt on w. In short: the halting problem. 问题焦点 :M 死循环的判断。 所以ATM又称停机问题 We will see that this is an insurmountable problem: in general one cannot decide if a TMwill halt on w or not, hence ATM is undecidable. 先揭谜底:停机问题不可判定, 从而ATM不可判定 为证明它(下周),先补充一系列预备知识,

  14. 4.2 The Halting Problem ATM cp108 上页已经证明 可识性 ATM = {M,w | M is a TM that accepts w } is TM-recognizable, but can we also decide it ? The problem lies with the cases when M does not halt on w. In short: the halting problem. 问题焦点 :M 死循环的判断。 所以ATM又称停机问题 We will see that this is an insurmountable problem: in general one cannot decide if a TMwill halt on w or not, hence ATM is undecidable. 先揭谜底:停机问题不可判定, 从而ATM不可判定 为证明它(下周),先补充一系列预备知识,

  15. 4.2 The Halting Problem ATM U上页已经证明 可识性 ATM = {M,w | M is a TM that accepts w } is TM-recognizable, but can we also decide it ? The problem lies with the cases when M does not halt on w. In short: the halting problem. 问题焦点 :M 死循环的判断。 所以ATM又称停机问题 We will see that this is an insurmountable problem: in general one cannot decide if a TMwill halt on w or not, hence ATM is undecidable. 先揭谜底:停机问题不可判定, 从而ATM不可判定 为证明它,先补充一系列预备知识,

  16. How Many Languages? 康托 cp109

  17. How Many Languages? 康托 cp109 For ={0,1}, there are 2k words of length k.Hence, there are languages L  k. Proof: L has two options for every word k;L can be represented by a string . 当k=10,共有21024个语言 That’s a lot, but finite. There are infinitely many languages  *.But we can say more than that… Georg Cantor defined a way of comparing infinities.

  18. How Many Languages? 康托 cp109 For ={0,1}, there are 2k words of length k.Hence, there are languages L  k. Proof: L has two options for every word k;L can be represented by a string . 当k=10,共有21024个语言 That’s a lot, but finite. There areinfinitely many languages  *.But we can say more than that… Georg Cantor defined a way of comparing infinities.

  19. Mappings and Functions 用映射比较集合大小 cp109 F The function F:ABmaps one set A to another set B: A B F is one-to-one (injective 内射, 不同源 有 不同像 ,源<-像) if every xA has a unique image F(x): If F(x)=F(y) then x=y. F is onto (surjective满射) if every zB is ‘hit’ by F:If zB then there is an xA such that F(x)=z. F is a correspondence (bijection双射) between A and B if it is both one-to-one and onto. 一样多

  20. Mappings and Functions 用映射比较集合大小 cp109 F The function F:ABmaps one set A to another set B: A B F is one-to-one (injective 内射, 不同源 有 不同像 ,源<-像) if every xA has a unique image F(x): If F(x)=F(y) then x=y. F is onto (surjective满射) if every zB is ‘hit’ by F:If zB then there is an xA such that F(x)=z. F is a correspondence (bijection双射) between A and B if it is both one-to-one and onto. 一样多

  21. Mappings and Functions 用映射比较集合大小 cp109 F The function F:ABmaps one set A to another set B: A B F is one-to-one (injective 内射, 不同源 有 不同像 ,源<-像) if every xA has a unique image F(x): If F(x)=F(y) then x=y. F is onto (surjective满射) if every zB is ‘hit’ by F:If zB then there is an xA such that F(x)=z. F is a correspondence (bijection双射) between A and B if it is both one-to-one and onto. 一样多

  22. Cardinality 基数 有限集合元素个数的推广(推到无线集合) cp109 A set S has k elements if and only if there isa bijection possible between S and {1,2,…,k}. S and {1,…,k} have the same cardinality. If there is a surjection possible from {1,…,n} to S, then n  |S|. We can generalize this way of comparing the sizes of sets to infinite ones.

  23. Cardinality 基数 有限集合元素个数的推广(推到无线集合) cp109 A set S has k elements if and only if there isa bijection possible between S and {1,2,…,k}. S and {1,…,k} have the same cardinality. If there is a surjection possible from {1,…,n} to S, then n  |S|. We can generalize this way of comparing the sizes of sets to infinite ones.

  24. Countable Infinite Sets 可数无穷集 cp109 A set S is infiniteif there exists a surjectivefunction F:SN. 基数>=自然数集数 “The set N has not more elements than S.” A set S is countable if there exists a surjectivefunction F:NS “The set S has not more elements than N.” 有限集可数,与自然数集合等势 可数 A set S is countable infinite if there exists a bijective function F:NS. 可数无穷 与N 等势 “The sets N and S are of equal size.”

  25. Countable Infinite Sets 可数无穷集 cp110 A set S is infiniteif there exists a surjectivefunction F:SN. 基数>=自然数集数 “The set N has not more elements than S.” A set S iscountable if there exists a surjectivefunction F:NS “The set S has not more elements than N.” 有限集可数,与自然数集合等势 可数 A set S is countable infinite if there exists a bijective function F:NS. 可数无穷 与N 等势 “The sets N and S are of equal size.”

  26. Countable Infinite Sets 可数无穷集 cp110 A set S is infiniteif there exists a surjectivefunction F:SN. 基数>=自然数集数 “The set N has not more elements than S.” A set S is countable if there exists a surjectivefunction F:NS “The set S has not more elements than N.” 有限集可数,与自然数集合等势 可数 A set S is countable infinite if there exists a bijective function F:NS. 可数无穷 与N 等势 “The sets N and S are of equal size.”

  27. Countable Infinite Sets 可数无穷集 cp110 有理数集合可数 每个 n/m 都能被数到

  28. Some Countable Infinite Sets One can make bijections between N andZ, N2, {a}*, {a,b}*:

  29. A Big Countable Set N* Consider the set N*, the set of finite sequencesof numbers: (0)N*, (4,63)N*, (1,0,…,1)N*. 用素因子为作为整数的正交坐标基 This set is also countable infinite. How do make the bijection between N* and N? • There are infinitely many primes p1=2, p2=3, p3=5, … • Every number n{2,3,…} has a unique primefactorization: 84 = p1·p1·p2·p4

  30. Bijection between N and N* Let (n1,n2,…,nk)N* (n1,n2,…,nk) | N*  N 是1-1满映射 所以N*是可数的

  31. A set S is countable infinite if there is a bijectionpossible between {0,1,2,…} and S. 可数无穷ep 161A set S is countable, if you can make a lists1,s2,… of all the elements of S. The sets N, N2, {0,1}*, N* are all countable infinite.Example for {0,1}*: the lexicographical ordering: {0,1}* = {,0,1,00,01,10,11,000,…} 按字典序排

  32. Uncountable Sets 从可数集 造 不可数集合,cp111 There are infinite sized sets that are not countable.Typical examples are P(N) and P({0,1}*) 用对角线方法: 从 可数集 造 不可数集合 We prove this by a diagonalization argument. In short, if S is countable, then you can make alist s1,s2,… of all elements of S. Diagonalization shows that given such a list,there will always be an element x of S thatdoes not occur in s1,s2,…

  33. Uncountable Sets 可数集 造 不可数集合,cp111 There are infinite sized sets that are not countable.Typical examples are P(N) and P({0,1}*) 用对角线方法: 从 可数集 造 不可数集合 We prove this by adiagonalization argument. In short, if S is countable, then you can make alist s1,s2,… of all elements of S. Diagonalization shows that given such a list,there will always be an element x of S thatdoes not occur in s1,s2,…

  34. Uncountability of P(N) The set P (N) contains all the subsets of {0,1,2,…}. Each subset X can be identified by an infinitestring of bits x0x1x2... such that xj=1 iff jX. 命题 There is bijection between P (N) and {0,1}N { 1,2,3,4}  11110000.000 { 1,3,4,5}  10111000…000 Proof by contradiction: 反设Assume P (N) countable. Hence there must exist a surjection F from N to the set of infinite bit strings. “There is a list of all infinite bit strings.”

  35. Uncountability of P(N) The set P (N) contains all the subsets of {0,1,2,…}. Each subset X can be identified by an infinitestring of bits x0x1x2... such that xj=1 iff jX. 命题 There is bijection between P (N) and {0,1}N { 1,2,3,4}  11110000.000 { 1,3,4,5}  10111000…000 Proof by contradiction: 反设Assume P (N) countable. Hence there must exist a surjection F from N to the set of infinite bit strings. “There is a list of all infinite bit strings.”

  36. Uncountability of P(N) The set P (N) contains all the subsets of {0,1,2,…}. Each subset X can be identified by an infinitestring of bits x0x1x2... such that xj=1 iff jX. 命题 There is bijection between P (N) and {0,1}N { 1,2,3,4}  11110000.000 { 1,3,4,5}  10111000…000 Proof by contradiction: 反设Assume P (N)countable. Hence there must exist a surjection F from N to the set of infinite bit strings. “There is a list of all infinite bit strings.”

  37. Diagonalization 对角线方法 比cp111 更一般 Try to list all possible infinite bit strings,然假定可数,就依次列出如下: Look at the bit string on the diagonal of this table:对角线上元素 0101… The negation of this string 反码串 (“1010…”) does not appear in the table. 它的第K分量与第K列的第K分量相反,所以不同于第K列, (K=1,2…), 即被漏数,与该集合 可数 矛盾

  38. Diagonalization 对角线方法 比cp111 更一般 Try to list all possible infinite bit strings,然假定可数,就依次列出如下: Look at the bit string on the diagonal of this table:对角线上元素 0101… The negation of this string 反码串(“1010…”) does not appear in the table. 它的第K分量与第K列的第K分量相反,所以不同于第K列, (K=1,2…), 即被漏数,与该集合 可数 矛盾

  39. No Surjection N  {0,1}N ,无满射把上页的形式化(稍微难懂一点) Let F be a functionN {0,1}N.F(0),F(1),F(2),… are all infinite bit strings. Define the infinite string Y=Y0Y1Y2… by Yj = NOT(j-th bit of F(j)) //对角线元素的反码 On the one hand Y {0,1}H, but on the other hand: for every jH we know that F(j)  Y because F(j) and Y differ in the j-th bit. Y被漏掉了。 F cannot be a surjection: {0,1}H is uncountable.

  40. No Surjection N  {0,1}N ,无满射把上页的形式化(稍微难懂一点) Let F be a functionN {0,1}N.F(0),F(1),F(2),… are all infinite bit strings. Define the infinite string Y=Y0Y1Y2… by Yj = NOT(j-th bit of F(j)) //对角线页数的反码 On the one hand Y {0,1}H, but on the other hand: for every jH we know that F(j)  Y because F(j) and Y differ in the j-th bit. Y被漏掉了。 F cannot be a surjection: {0,1}H is uncountable.

  41. Uncountability 不可数 We just showed that there it is impossible tohave surjection from N to the set {0,1}N. Similar proofs are possible for the uncountabilityof the sets , P ({0,1}*), et cetera. What does this have to do with Turing machine computability? 似乎扯远了点?

  42. Uncountability 不可数 We just showed that there it is impossible tohave surjection from N to the set {0,1}N. Similar proofs are possible for the uncountabilityof the sets , P ({0,1}*), et cetera. What does this have to do with Turing machine computability? 似乎扯远了点?

  43. Counting TMs 有多少图灵机“摸一摸, 有多少石头诞生在西藏?”—尔甲:天上拉萨 Observation: Every TM has a finite description;there is only a countable number of different TMs. (A description M can consist of a finite stringof bits, and the set {0,1}* is countable.) C语言程序,只有可数个,文章只有可数篇,同理, 图灵机由有限个字符描述,编码后按字典序排,只有可数个。 Our definition of Turing recognizable languagesis a mapping between the set of TMs {M1,M2 ,…} and the set of languages {L(M1),L(M2),…} P (*). Question: How many languages are there?

  44. Counting TMs 有多少图灵机“数一数, 有多少圣湖闪亮在心灵?”—尔甲:天上拉萨 Observation: Every TM has a finite description;there is only a countable number of different TMs. (A description M can consist of a finite stringof bits, and the set {0,1}* is countable.) C语言程序,只有可数个,文章只有可数篇,同理, 图灵机由有限个字符描述,编码后按字典序排,只有可数个。 Our definition of Turing recognizable languagesis a mapping between the set of TMs {M1,M2 ,…} and the set of languages {L(M1),L(M2),…} P (*). Question: How many languages are there?

  45. Counting Languages 数一数语言ep164,cp107“念一念, 有多少真言 弥漫在风中”—尔甲:天上拉萨 There are uncountable many different languages over the alphabet ={0,1} (the languages L  {0,1}*). With the lexicographical ordering ,0,1,00,01,… of *, every L coincides with an infinite bit string via its characteristic sequence L. Example for L={0,00,01,000,001,…} with L= 0101100… 语言 特征串(有X , 无 空格), 字符串(字典序)

  46. Counting TMs and Languages cp112 There is a bijection between the set of languagesover the alphabet ={0,1} and the uncountableset of infinite bit strings {0,1}N. There are uncountable many different languages L {0,1}*. 语言 不可数 • Hence there is no surjection possible from the countable set of TMs to the set of languages. Specifically, the mapping L(M) is not surjective. 但图灵机(程序、系统)只有可数个 Conclusion: There are languages that are notTuring-recognizable. (A lot of them.) 不可识别的的语言 不但存在, 而且占了绝大部分。

  47. Counting TMs and Languages cp112 There is a bijection between the set of languagesover the alphabet ={0,1} and the uncountableset of infinite bit strings {0,1}N. There are uncountable many different languages L {0,1}*. 语言 不可数 • Hence there is no surjection possible from the countable set of TMs to the set of languages. Specifically, the mapping L(M) is not surjective. 但图灵机(程序、系统)只有可数个 Conclusion: There are languages that are notTuring-recognizable. (A lot of them.) 不可识别的的语言 不但存在, 而且占了绝大部分。

  48. Is This Really Interesting? cp112 We now know that there are languages that are not Turing recognizable, but we do not know what kind of languages are non-TM recognizable. Are there interesting languages for which we can prove that there is no Turingmachine that recognizes it? 是否有不可识别的有意义的语言?

More Related