1、2019/7/27,1/88,Lecture for Computation Theory,Book :计算理论导引Introduction to the Theory of Computation Chapter 3 Turing Machine Prof : 唐常杰TangC Http:/ : Phd, MS in CS . 2000- 2006, SCU Style : Lecture / Seminar,2019/7/27,2/88,Outline for today,Section 3.13.2 :Computability(补充)3.1 Turing machines TM-com
2、putable/recognizable languages3.2 Variants of TMs (多带机,不确定机),2019/7/27,3/88,2019/7/27,4/88,2019/7/27,5/88,Intersection & Complement,上次例题解法2 :Is A= n+2 |n in N, n in binary a RL? 解: =0,1 , * is RL 以1 开始的二进编码 是RL, 1. * (即自然数集合NA= 1.(* -0,1,2 ,2019/7/27,6/88,Union Closure Properties,复习 上周已讲 Lemma: Let
3、A1 and A2 be two CF languages, then the union A1A2 is context free as well.Proof: Assume that the two grammars are G1=(V1,R1,S1) and G2=(V2,R2,S2). Construct a third grammar G3=(V3,R3,S3) by: V3 = V1 V2 S3 (new start variable) with R3 = R1 R2 S3 S1S2 . It follows that L(G3) = L(G1) L(G2).,2019/7/27,
4、7/88,Intersection & Complement?,复习: CFL 对 交运算和补运算不封闭 Let again A1 and A2 be two CF languages. One can prove that, in general, the intersection A1 A2 , and the complement 1= *A1 are not CF languages.直观解释:PDA资源不够多,记忆能力不够,不能作复杂集合(如CFL)的减法,One proves this with specific examples of languages (see homewor
5、k).,2019/7/27,8/88,Intersection & Complement?,复习: CFL 对 交运算和补运算不封闭 Let again A1 and A2 be two CF languages. One can prove that, in general, the intersection A1 A2 , and the complement 1= *A1 are not CF languages.直观解释:PDA资源不够多,记忆能力不够,不能作复杂集合(如CFL)的减法,One proves this with specific examples of language
6、s (see homework).,9/88,What do we really know? 引出问题,Can we always decide if a language L is regular / Context-free or not? We know: 1x | x = 0 mod 7 is regular(比较规律,可有限描述)= 1111111 * 1x | x is prime is not regular(比较复杂。现在数学家还不能简单描述)But what about 1x | x and x+2 are prime ? This is (yet) unknown. 说明对
7、语言的描述和判定 是个需要研究的问题,2019/7/27,10/88,What do we really know? 引出问题,Can we always decide if a language L is regular/ context-free or not? We know: 1x | x = 0 mod 7 is regular(比较规律,可有限描述) 1x | x is prime is not regular(比较复杂。现在数学家还不能简单描述)But what about 1x | x and x+2 are prime ? This is (yet) unknown. 说明
8、对语言的描述和判定 是个需要研究的问题,2019/7/27,11/88,Describing a Language,The problem lies in the informal notion of a description. Consider: n | n2,a,b,c: an+bn = cn 费马问题,已解决,是空集 x | in year x the first female US president 让历史告诉未来 x | x is “an easy to remember number” 描述太含糊 We have to define what we mean by “descr
9、iption” and “method of deciding,2019/7/27,12/88,Describing a Language,The problem lies in the informal notion of a description. Consider: n | n2,a,b,c: an+bn = cn 费马问题,已解决,是空集 x | in year x the first female US president 让历史告诉未来 x | x is “an easy to remember number” 描述太含糊 We have to define what we me
10、an by “description” and “method of deciding”.,2019/7/27,13/88,Describing a Language,The problem lies in the informal notion of a description. Consider: n | a,b,c: an+bn = cn 费马问题,现已经解决是空集 x | in year x the first female US president 让历史告诉未来 x | x is “an easy to remember number” 描述太含糊 We have to defin
11、e what we mean by “description” and “method of deciding”.,2019/7/27,14/88,计算机科学历史上关于概念的争论,什么是计算 什么是操作系统 基本上解决 什么internet ?什么是数据库 什么是数据仓库 还在争论 什么是数据网格 解决方法, 给出 大众能理解的 代表 下页,2019/7/27,15/88,计算机科学历史上关于概念的争论,解决的办法, 给出一个 代表 什么是 3的倍数 3N |N=1,2,3 ,x| x mod 3 =0代表元 :0 什么是操作系统 代表元:Windows, Unix 什么internet 代表
12、元 大众理解:Web , IE 什么是计算? 代表元 图灵机,2019/7/27,16/88,计算机科学历史上关于概念的争论,解决的办法, 给出一个 代表 什么是 3的倍数 3N |N=1,2,3 ,x| x mod 3 =0代表元 :0 什么是操作系统 代表元:Windows, Unix 什么internet 代表元 大众理解:Web , IE 什么是计算? 代表元 图灵机,2019/7/27,17/88,计算机科学历史上关于概念的争论,解决的办法, 给出一个 代表 什么是 3的倍数 3N |N=1,2,3 ,x| x mod 3 =0代表元 :0 什么是操作系统 代表元:Windows,
13、Unix 什么internet 代表元 大众理解:Web , IE 什么是计算? 多个模型, 代表元; 图灵机, 或 递归函数论,2019/7/27,18/88,Chap 3 Turing Machines ep125 cp87,在还没有计算机的时候, 凭想象力把后来出现的 把计算机的理论模型建立起来了。想得如此周到、严密好像从高度文明的外星 来的文化使者,2019/7/27,19/88,Chap 3 Turing Machines ep125 cp 87,After Alan M. Turing (19121954),In 1936, Turing introduced his abstra
14、ct model for computation in his article “On Computable Numbers, with an application to the Entscheidungsproblem”.,At the same time, Alonzo Church published similar ideas and results.,However, the Turing model has become the standard model in theoretical computer science.,2019/7/27,20/88,Chap 3 Turin
15、g Machines ep125 cp87,After Alan M. Turing (19121954),In 1936, Turing introduced his abstract model for computation in his article “On Computable Numbers, with an application to the Entscheidungsproblem”.,At the same time, Alonzo Church published similar ideas and results.,However, the Turing model
16、has become the standard model in theoretical computer science.,2019/7/27,21/88,Chap 3 Turing Machines ep125 cp87,After Alan M. Turing (19121954),In 1936, Turing introduced his abstract model for computation in his article “On Computable Numbers,”.,At the same time, Alonzo Church published similar id
17、eas and results. 殊途同归,However, the Turing model has become the standard model in theoretical computer science.,2019/7/27,22/88,Chap 3 Turing Machines,复习: 关于自动机和下推机中的状态的几种比喻 1 目标 。Goto 的 目标, 标号2 停顿 。连续动作离散化的停顿,(直观启示 可能来自于 手摇计算机,齿轮动作实现,是离散的,一步) 思考。新的起点,歇一口气,根据当前输入,思考下一步动作。(自动机不看历史,下推机看一点很短的历史 - 栈顶值)后面
18、的图灵机中,三者都有,2019/7/27,23/88,Informal Description TM ep 126 cp87,根据当前状态和字符 xi,决定 写 移 转三动作 -写 letter, 有存储器 - 左或右移动 转移状态 可以作循环语句 磁带相当于数组,可读写。这是增加的重要资源,At every step, the head of the TM M reads a letter xi from the one-way infinite tape. 读写头在单向无穷带上左右移动并读写,,2019/7/27,24/88,Informal Description TM ep 126 c
19、p87,根据当前状态和字符 xi,决定 写 移 转三动作 -写 letter, 有存储器 - 左或右移动 转移状态 可以作循环语句 磁带相当于数组,可读写。这是增加的重要资源,At every step, the head of the TM M reads a letter xi from the one-way infinite tape. 读写头在单向无穷带上左右移动并读写,,2019/7/27,25/88,Informal Description TM ep 126 cp87,根据当前状态和字符 xi,决定 写 移 转三动作 -写 letter, 有存储器 - 左或右移动 转移状态 可
20、以作循环语句 磁带相当于数组,可读写。这是增加的重要资源,At every step, the head of the TM M reads a letter xi from the one-way infinite tape. 读写头在单向无穷带上左右移动并读写,,2019/7/27,26/88,Input Convention ep126-128,state q0,初始, the tape contains the input w*, padded with blanks “_”, and the TM is in start state q0.,During the computatio
21、n, the head moves left and right (but not beyond the leftmost point), the internal state of the machine changes, and the content of the tape is rewritten.,数组结构,2019/7/27,27/88,Input Convention ep126-128,state q0,初始, the tape contains the input w*, padded with blanks “_”, and the TM is in start state
22、 q0.,During the computation, the head moves left and right (but not beyond the leftmost point), the internal state of the machine changes, and the content of the tape is rewritten.,数组结构,2019/7/27,28/88,Input Convention ep126-128,state q0,初始, the tape contains the input w*, padded with blanks “_”, an
23、d the TM is in start state q0.,During the computation, the head moves left and right (but not beyond the leftmost point), the internal state of the machine changes, and the content of the tape is rewritten.,数组结构,2019/7/27,29/88,Output Conventionep 126-129,The computation can proceed indefinitely, or
24、 the machines reaches one of the two halting states: 三种前途,接受、拒绝、死循环, bool someFunc( ),2019/7/27,30/88,Output Conventionep 126-129,The computation can proceed indefinitely, or the machines reaches one of the two halting states: 三种前途,接受、拒绝、死循环, bool someFunc( ),2019/7/27,31/88,Turing Machine (Def. c4.
25、1) ep128 cp88,元组式定义 A Turing machine M is defined by a 7-tuple (Q,q0,qaccept,qreject), withQ finite set of states 状态集合,相当于程序标号 finite input alphabet (without “_”) 输入字符 finite tape alphabet with _ 带字符q0 start state Q 开始状态qaccept accept state Q 接受状态qreject reject state Q 拒绝状态 the transition function 转
26、移函数 相当于移动+goto: Qqaccept,qreject Q L,R状态。当前字符 转, 写, 移,2019/7/27,32/88,Turing Machine (Def. c4.1) ep128 cp88,元组式定义 A Turing machine M is defined by a 7-tuple (Q,q0,qaccept,qreject), withQ finite set of states 状态集合,相当于程序标号 finite input alphabet (without “_”) 输入字符 finite tape alphabet with _ 带字符q0 star
27、t state Q 开始状态qaccept accept state Q 接受状态qreject reject state Q 拒绝状态 (状态相当预程序中标号) the transition function 转移函数 相当于移动+goto: Qqaccept,qreject Q L,R状态。当前字符 转, 写, 移,2019/7/27,33/88,Turing Machine (Def. c4.1) ep128 cp88,元组式定义 A Turing machine M is defined by a 7-tuple (Q,q0,qaccept,qreject), withQ finite
28、 set of states 状态集合,相当于程序标号 finite input alphabet (without “_”) 输入字符 finite tape alphabet with _ 带字符q0 start state Q 开始状态qaccept accept state Q 接受状态qreject reject state Q 拒绝状态 the transition function 转移函数 相当于移动+goto: Qqaccept,qreject Q L,R状态。当前字符 转, 写, 移,2019/7/27,34/88,Configuration of a TM ep129 c
29、p88 图稍有不同,格局=状态已经处理部分今后任务, 目前形式与任务 The configuration of a Turing machine consists ofthe current state q Qthe current tape contents *the current head location 0,1,2,This can be expressed as an element of *Q*:,2019/7/27,35/88,Configuration of a TM ep129 cp88 图稍有不同,格局=状态已经处理部分今后任务, 目前形式与任务 The configur
30、ation of a Turing machine consists ofthe current state q Qthe current tape contents *the current head location 0,1,2,This can be expressed as an element of *Q*:,2019/7/27,36/88,An Elementary TM Step ep129 cp89,Let u,v * ; a,b,c ; qi,qjQ, and M a TM with transition function . 格局C1产生格局C2 We say that t
31、he configuration “uaqibv” yields the configuration “uacqjb” if and only if: (qi,b) = (qj,c,R). 格局产生 即 格局 按机演化翻译成 格局演进 似更恰当 Similarly, if (qi,b) = (qj,c,L) / 把当前的b改为c 且左移then “uaqibv” yields “uqjacb”(At the leftmost side of the tape different.),2019/7/27,37/88,An Elementary TM Step ep129 cp89,Let u,v
32、 * ; a,b,c ; qi,qjQ, and M a TM with transition function . 格局C1产生格局C2 We say that the configuration “uaqibv” yields the configuration “uacqjv” if and only if: (qi,b) = (qj,c,R). 格局产生 即 格局 按机演化翻译成 格局演进 似更恰当 Similarly, if (qi,b) = (qj,c,L) / 把当前的b改为c 且左移then “uaqibv” yields “uqjacv”(At the leftmost si
33、de of the tape different.),2019/7/27,38/88,Terminology 格局,starting configuration on input w: “q0w” 初始格局accepting configuration: “uqacceptv” 接受格局 返回truerejecting configuration: “uqrejectv” 拒绝格局 返回falseThe accepting and rejecting configurations are the halting configurations.,2019/7/27,39/88,Terminolo
34、gy 格局,starting configuration on input w: “q0w” 初始格局accepting configuration: “uqacceptv” 接受格局 返回truerejecting configuration: “uqrejectv” 拒绝格局 返回falseThe accepting and rejecting configurations are the halting configurations.,2019/7/27,40/88,用格局概念描述 Accepting ep129 ,cp89,A Turing machine M accepts inpu
35、t w* if and only if there is a finite sequence of configurations C1,C2,Ck with C1 the starting configuration “q0w”for all i=1,k1 Ci yields Ci+1 (following Ms )Ck is an accepting configuration “uqacceptv”The language that consists of all inputs that are accepted by M is denoted by L(M).比喻: bool M(w)
36、最后返回true,2019/7/27,41/88,用格局概念描述 Accepting ep129 ,cp89,A Turing machine M accepts input w* if and only if there is a finite sequence of configurations C1,C2,Ck with C1 the starting configuration “q0w”for all i=1,k1 Ci yields Ci+1 (following Ms )Ck is an accepting configuration “uqacceptv”The languag
37、e that consists of all inputs that are accepted by M is denoted by L(M).比喻: bool M(w) 最后返回true,2019/7/27,42/88,用格局概念描述 Accepting ep129 ,cp89,A Turing machine M accepts input w* if and only if there is a finite sequence of configurations C1,C2,Ck with C1 the starting configuration “q0w”for all i=1,k1
38、 Ci yields Ci+1 (following Ms )Ck is an accepting configuration “uqacceptv”The language that consists of all inputs that are accepted by M is denoted by L(M).比喻: bool M(w) 最后返回true,2019/7/27,43/88,用格局概念描述 Accepting ep129 ,cp89,比喻 录取 会议论文 Turing machine M 录取标准,程序委员会 accepts input w* 字符串,论文, configura
39、tions C1,C2,Ck 评审过程 accepting configuration “uqacceptv” 录用uqrejectv” 拒绝评审无反响 - 死机,2019/7/27,44/88,Turing Recognizable (Def. 3.2) ep130 cp89,A language L is Turing-recognizable if and only if there is a TM M such that L=L(M). 图灵可识: 对 wL 函数M(w)返回true, 对wL,无承诺,Note: On an input wL, the machine M can ha
40、lt in a rejecting state, or it can loop indefinitely.,How do you distinguish between a very long computation and one that will never halt? 问题:如何区别 长计算 与 死循环?,Also called: a recursively enumerable language. L 又称为 递归可枚举语言,2019/7/27,45/88,Turing Recognizable (Def. 3.2) ep130 cp89,A language L is Turing
41、-recognizable if and only if there is a TM M such that L=L(M). 图灵可识: 对 wL 函数M(w)返回true, 对wL,无承诺,Note: On an input wL, the machine M can halt in a rejecting state, or it can loop indefinitely.,How do you distinguish between a very long computation and one that will never halt? 问题:如何区别 长计算 与 死循环?,Also
42、 called: a recursively enumerable language. L 又称为 递归可枚举语言,2019/7/27,46/88,Turing Recognizable (Def. 3.2) ep130 cp89,A language L is Turing-recognizable if and only if there is a TM M such that L=L(M). 图灵可识: 对 wL 函数M(w)返回true, 对wL,无承诺,Note: On an input wL, the machine M can halt in a rejecting state,
43、 or it can loop indefinitely.,How do you distinguish between a very long computation and one that will never halt? 问题:如何区别 长计算 与 死循环?,Also called: a recursively enumerable language. L 又称为 递归可枚举语言,2019/7/27,47/88,Turing Decidable (Def. 3.3) 图灵可判定 ep130, cp84,Also called: a recursive language. 递归语言,比递
44、归可枚举 要求高,A language L=L(M) is decided by the TM M if on every w, the TM finishes in a halting configuration. (That is: qaccept for wL and qreject for all wL.)图灵可判定: 对 wL 函数M(w) 返回true, 对wL,返回false,A language L is Turing-decidable if and only if there is a TM M that decides L.图灵可判定语言,2019/7/27,48/88,
45、Turing Decidable (Def. 3.3) 图灵可判定 ep130, cp89,Also called: a recursive language. 递归语言,比递归可枚举 要求高,A language L=L(M) is decided by the TM M if on every w, the TM finishes in a halting configuration. (That is: qaccept for wL and qreject for all wL.)图灵可判定: 对 wL 函数M(w) 返回true, 对wL,返回false,A language L is
46、 Turing-decidable if and only if there is a TM M that decides L.图灵可判定语言,2019/7/27,49/88,Turing Decidable (Def. 3.3) 图灵可判定 ep130, cp89,Also called: a recursive language. 递归语言,比递归可枚举 要求高,A language L=L(M) is decided by the TM M if on every w, the TM finishes in a halting configuration. (That is: qacce
47、pt for wL and qreject for all wL.)图灵可判定: 对 wL 函数M(w) 返回true, 对wL,返回false,A language L is Turing-decidable if and only if there is a TM M that decides L.图灵可判定语言,2019/7/27,50/88,Exa. 3.4: 判定 A = 0j | j=2n ,n=0 ep131, cp90,Bool M( w) /用C语言模拟TM, 注意不要超标使用资源 if (1 appear in w) return false; j=length(w);lo
48、op: If ( j=1) return true;if ( j mod 2=0) i-; goto loop; else return false ; /注意无论 j 为何值,总有结果 ,Check if j=0 or j=1, accept/reject accordingly Check, by going left to right if the string has even or odd number of zeros If odd then “reject” If even then go back left, erasing half the zeros goto 1 算法伪码,