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
More Related Content
Presentation Transcript
Lecture Notes for DB Book :计算理论引论 by Michel Sipser Chapter0 概念与语言, 第 1章 确定自动机 Prof : 唐常杰 TangChangjie@cs.scu.edu.cn Http://teacher.scu.edu.cn/~chjtang Students : MS in CS . 2003, SCU Style : Lecture / Seminar
第 0章 概念与语言, 第 1章 确定自动机 • Outline for today • Chapter 0: (中文1章) • set notation and languages • Chapter 1: (中文2章) • deterministic finite automata (DFA)确定自动机 • nondeterministic FA (NFA)不确定自动机 • 教学方法:以教材为基础,适当补充,调整次序 • 讲课 : 讲思想、方法,难易 ,想得正确,直观,理解 • 写文章:要正规,形式化,严格,说得明白,写得清楚 • 笔记:可以记下幻灯篇页数(sp1-15),书页数(ep15,cp15) • 再记录心得,可少记一些
Languages 语言,字词的集合 ep.42,cp.25 • Given an alphabet , we can make a word or string by concatenating the letters of . 字母表 • Concatenation of “x” and “y” is “xy” 字母的链接 • Typical example: ={0,1}, the possible words over are the finite bit strings. 01位串为单词 • A language is a set of words. 语言,字词的集合 • 定义: • 设 是字母表, 则称2的子集A为上的语言。
More about Languages • The empty string is the unique string with zero length. • Concatenation of two langauges: A•B = { xy | xA and yB } • 两个语言的链接 : 字集之链 = 链字之集 • Typical examples: L = { x | x is a bit string with two zeros } L = { anbn | n N } L = {1n | n is prime} 每个词是素数个1链成
A Word of Warning 注意 Do not confuse the concatenation of languages with the Cartesian product of sets. 语语连接 != 迪卡积 For example, let A = {0,00} then A•A = { 00, 000, 0000 } with |A•A|=3, 连接 一维 AA = { (0,0), (0,00), (00,0), (00,00) } 叉乘 二维 with |AA|=4
Recognizing Languages 识别语言 cp22 • Let L be a language S • 自动机识别语言的直观描述(后面有形式化定义)用有限描述无限。 • : 入语言, 出判定(Y:N) • a machine M recognizes L if “accept” if and only if xL xS M “reject” if and only if xL
Finite Automaton 有限自动机ep.55,cp.34 The most simple machine that is not just a finite list of words. 最简:有限个词的集合 “Read once”, “no write” procedure. 只读,不写,,无内存,无变量,无数组,无堆栈 ,无推理,无想象力 Typical is its limited memory. 内存有限, 只有寄存器,能记住状态(窍门:造自动机时遇到困难加状态,等于是加寄存器扩大了记忆力) Think cell-phone, elevator door, etc. 简单例子,火车线路图,电梯, 录音机, 电子表 状态和按扭
Finite Automaton 有限自动机ep.55,cp.34 The most simple machine that is not just a finite list of words. 最简:有限个词的集合 “Read once”, “no write” procedure. 只读,不写,,无内存,无变量,无数组,无堆栈 ,无推理,无想象力 Typical is its limited memory. 内存有限, 只有寄存器,能记住状态(窍门:造自动机时遇到困难加状态,等于是加寄存器扩大了记忆力),状态相当于标号,goto,增加标号相当与增加语句和转向语句 Think cell-phone, elevator door, etc. 简单例子,火车线路图,电梯, 录音机, 电子表 状态和按扭
Finite Automaton 有限自动机ep.55,cp.34 The most simple machine that is not just a finite list of words. 最简:有限个词的集合 “Read once”, “no write” procedure. 只读,不写,,无内存,无变量,无数组,无堆栈 ,无推理,无想象力 Typical is its limited memory. 内存有限, 只有寄存器,能记住状态(窍门:造自动机时遇到困难加状态,等于是加寄存器扩大了记忆力) Think cell-phone, elevator door, etc. 简单例子,火车线路图,电梯, 录音机, 电子表 状态和按扭
States状态 transition rules 变换规则 0 1 1 0 q1 q2 q3 0,1 始态starting state accepting state 受态,粗圈或双线圈 A Simple Automaton (0) ep34, cp20 cp22
A Simple Automaton (3) 用C语言描述 对不熟悉C语言的读者,FA更直观, 对熟悉C语言的读者,C语言解释自动机更简单(查旧则可知新,人们总是用熟悉的知识解释新的知识) 注意一点,不要超标用资源, 只能用 if goto 不能用数组,变量,只能用状态作记忆 在后面的推理中,SCU教案将广泛用C语言表示自动机、下推机、图灵机。
A Simple Automaton (3) 用C语言描述 对不熟悉C语言的读者,FA更直观, 对熟悉C语言的读者,C语言解释自动机更简单(查旧则可知新,人们总是用熟悉的知识解释新的知识) 注意一点,不要超标用资源, 只能用 if goto(状态) 不能用数组,变量,只能用状态作记忆 在后面的推理中,SCU教案将广泛用C语言表示自动机、下推机、图灵机。
自动机的背景 在词法分析中是如何用的 • 造一个C语言,Basic ,DOS解释器,HBASE解释器 • 语法分析器, • 先把拟实现的语句设计好,例如 • List Field A1,A1 for age>5 to printer • Display [All] field for …. To … • Index On Name to Name.NDX • 抽象 找规律 ,巴克斯范式,状态转换函数的变形 • 命令行=动词[user_str][介词短语]* • 动词=List|Display|Index • 介词短语=介词[表达式|UserStr] • 介词短语=for|on|to|field • UserStr=[a-z,A-Z,_][a-z,A-Z|0-9]*
自动机的背景 在词法分析中是如何用的 • 造一个C语言,Basic ,DOS解释器,HBASE解释器 • 语法分析器, • 先把拟实现的语句设计好,例如 • List Field A1,A1 for age>5 to printer • Display [All] field for …. To … • Index On Name to Name.NDX • 抽象 找规律 ,巴克斯范式,状态转换函数的变形 • 命令行=动词[user_str][介词短语]* • 动词=List|Display|Index • 介词短语=介词[表达式|UserStr] • 介词短语=for|on|to|field • UserStr=[a-z,A-Z,_][a-z,A-Z|0-9]*
Finite Automaton (def.) 有限自动机定义 cp21 • A deterministic finite automaton (DFA) M is defined by a 5-tuple M=(Q,,,q0,F) • Q: finite set of states 状态集 • : finite alphabet 字母表 • : transition function :QQ 转换函数 • q0Q: start state 始态 • FQ: set of accepting states 受态 • 介绍集中定义方法;元组式,递归式, • Let 式 Let, It is said to be …. If …….
Finite Automaton (def.) 有限自动机定义 cp21 • A deterministic finite automaton (DFA) M is defined by a 5-tuple M=(Q,,,q0,F) • Q: finite set of states 状态集 • : finite alphabet 字母表 • : transition function :QQ 转换函数 • q0Q: start state始态 • FQ: set of accepting states受态 • 介绍集中定义方法;元组式,递归式, • Let 式 Let, It is said to be …. If …….
0 1 1 0 q1 q2 q3 0,1 M = (Q,,,q,F) ep36 cp22 states Q = {q1,q2,q3} alphabet = {0,1} start state q1 accept states F={q2} transition function: 转换函数用矩阵
Recognizing Languages (def) 识别语言 cp21 FA的定义(元组式定义法) A Finite Automaton M = (Q,,,q,F)accepts a string/word w = w1…wn if and only if there is a sequence r0…rn of states in Q such that: 1) r0 = q0 起态 2) (ri,wi+1) = ri+1 for all i = 0,…,n–1 3) rn F 按图
Regular Languages 正规语言,3型语言 被FA接受的语言 cp24 The language recognized by a finiteautomaton M is denoted by L(M). A regular language is a language for which there exists a recognizing finite automaton.
Two DFA Questions 确定 有限 自动机 问题: 给机(图形,有限描述),找语(符号集合) : Given the description of a finite automaton M = (Q,,,q,F), what is the language L(M) that it recognizes? 问题 :给机,找语言族: In general, what kind of languages can be recognized by finite automata? (What are the regular languages?) 应用技巧1:语言L1找机 M1, 语言L2找机M2,两机合成 h(M1,M2)=M3, M3识别L3, 从而证明L3也是正规语言 合成可以是连接、并 、星运算 思想类似 xlog(x), ylog(y),log(x)+log(y)= log(x*y),然后求出 x*y 技巧2造自动机时,遇到困难加状态,等于是加寄存器 扩大了记忆力)
Two DFA Questions 确定 有限 自动机 问题: 给机(图形,有限描述),找语(符号集合) : Given the description of a finite automaton M = (Q,,,q,F), what is the language L(M) that it recognizes? 问题 :给机,找语言族: In general, what kind of languages can be recognized by finite automata? (What are the regular languages?) 应用技巧1:语言L1找机 M1, 语言L2找机M2,两机合成 h(M1,M2)=M3, M3识别L3, 从而证明L3也是正规语言 合成可以是连接、并 、星运算 思想类似 xlog(x), ylog(y),log(x)+log(y)= log(x*y),然后求出 x*y 技巧2造自动机时,遇到困难加状态,等于是加寄存器 扩大了记忆力)