图灵机开发说明文档
- 格式:doc
- 大小:605.50 KB
- 文档页数:25
图灵机实验报告图灵机实验报告引言:图灵机是由英国数学家艾伦·图灵在1936年提出的一种理论计算模型,它被认为是现代计算机的理论基础之一。
本实验旨在通过模拟图灵机的工作原理,探索计算机科学的基本概念和算法设计。
一、图灵机的基本原理图灵机由一个无限长的纸带和一个可移动的读写头组成。
纸带被划分为一系列格子,每个格子上可以写入一个字符。
读写头可以在纸带上左右移动,并根据当前所处格子上的字符执行相应的操作。
二、图灵机的操作图灵机的操作分为三种:读取、写入和移动。
读取操作是指读取当前格子上的字符,并根据字符执行相应的算法。
写入操作是指将指定的字符写入当前格子上。
移动操作是指将读写头在纸带上向左或向右移动一个格子。
三、图灵机的程序设计图灵机的程序设计是通过一系列规则来描述的。
每个规则包含三个部分:当前状态、当前字符和下一步操作。
通过这些规则,图灵机可以执行各种复杂的计算任务。
四、图灵机的应用图灵机的应用非常广泛,它可以用来解决各种计算问题。
例如,可以使用图灵机来模拟其他计算机的工作原理,设计和验证算法,甚至用来解决一些数学难题。
五、图灵机的局限性尽管图灵机是一种非常强大的计算模型,但它也有一些局限性。
首先,图灵机只能处理离散的输入和输出。
其次,图灵机的计算能力是有限的,它无法解决一些无法被计算的问题。
六、图灵机的发展与未来图灵机的概念为计算机科学的发展奠定了基础,它不仅帮助人们理解计算机的本质,还推动了算法设计和计算理论的发展。
未来,随着技术的不断进步,图灵机的应用将会更加广泛,同时也会面临更多的挑战和机遇。
结论:通过本次图灵机实验,我们深入了解了图灵机的基本原理、操作和程序设计。
图灵机作为计算机科学的基石,为我们理解和应用计算机提供了重要的思维工具。
通过不断探索和研究,我们相信图灵机的概念将会在未来的科学研究和技术创新中发挥更加重要的作用。
1300 Henley CourtPullman, WA 99163509.334.6306Motor Shield™ Reference ManualRevised June 29, 2017This manual applies to the Motor Shield rev. DOverviewThe Motor Shield is an expansion board for use with the Uno32 and uC32. It provides additional circuitry and connectors for the Uno32 and uC32 to drive various motors types.The Motor Shield is designed to drive DC motors, servo motors, and stepper motors. It also provides additional I/O via an I2C I/O extender.Features include:∙Two DC motor driver channels, accessiblewith either a JST 6-pin connector or aterminal block.∙Two DC motor encoder input signals foreach DC motor channel.∙Four servo motor channels.∙I2C General purpose I/O expander with 4LEDs 2 push buttons and 2 user settablejumpers.∙One 4-wire unipolar stepper motor channel.∙Standard Shield connectors.The Motor Shield.1 Functional DescriptionThe Motor Shield is designed to be used with the Uno32 or uC32 board. When used with these boards, the microcontroller and shield provide the necessary supporting hardware and connectors to control most types of small motors. The rest of this document will only reference the Uno32; however, the shield can also be used with the uC32.The Motor Shield has the following connectors:J1: Power Supply for the DC motor driverThis connector provides power to the DVR8833RTY motor driver for the DC motors. Motor supply voltage range is 2.7-10.8 V.J3 & J6: DC motor 6-pin JST connectorThese connections provide power and feedback signals for DC motors. The pin-outs are compatible with the Digilent DC gear-motors.J5 & J7: DC motor terminal block connectorThese connections provide the power supply pin-out for most two wire DC motors.J2: DC motor driver disableShorting these two pins (or driving the NS signal pin low) will put the DC motor driver into sleep mode. This disables the motor driver and therefore reduces power consumption. This option is useful for low power applications.J4: DC motor driver fault indicatorThe NF signal will be driven low when there is a fault detected within the DC motor driver. Possible reasons for fault include overcurrent, overheat, and low voltage.J8 & J9: DC motor feedback signal headersHeaders for connecting DC motor feedback signals.J10: Power Supply for Stepper motorThis connector provides power for driving the stepper motor.J12 & J13: Stepper motor terminal block connectorsThese connections are used for driving a stepper motor.J14: Power Supply for servo motorsThis connector provides external power for driving the servo motors. If using this header remove JP6 to ensure that servo power supply is not shorted to the 5 Volt Uno32 power supply.J11 & J15: Digital Signal Pass-Through ConnectorsThis connector passes the digital I/O pins on the Uno32 through to the Motor Shield.J21: I2C #1 Daisy Chain ConnectorThis is a 2x4 pin header connector that provides access to the I2C signals SDA and SCL as well as power from the 3.3V power bus and ground. This can be used to extend the I2C bus off of the board and to power external I2C devices. Digilent has cables and a selection of I2C peripheral modules that can be accessed using this connector.J19: Analog Signal Pass-Through ConnectorThis connector passes the analog input pins on the Uno32 through the Motor Shield.J22: Power Pass-Through ConnectorThis connector passes the power connector from the Uno32 through the Motor Shield, and powers the Motor Shield from the Uno32.2 DC Motor ControllerThe Motor Shield provides a means to control 2 independent DC motors via a DRV883 dual H-bridge motor driver. The motor driver must be powered via J1 to operate, voltages between 2.7 and 10.8 volts are acceptable. Each channel is contr olled by an “enable” and “direction” signal.Uno32 Pin #PIC32Pin #Signal Notes3 46 Enable1: OC1/RD04 59 Direction1: RF13/5 46/49 Enable2: OC1/RD0 or OC2/RD1 Select with JP14/34 59/53 Direction2: RF1 or PMRD/CN14/RD5 Select with JP2Channel 2 can be set up for identical or independent operation from channel 1 using JP1 and JP2.PWM levels on enable pins will regulate the speed of the motors. Logic levels on direction pins will determine the motors rotation direction of the attached DC motors. The Uno32 uses a demultiplexer and pull-down resistors on the inputs to the DRV8833 H-Bridge pins to ensure that the H-Bridge only works in fast decay mode. Table 1 lists the motor responses that result from various input combinations.DIR1EN1Result0 0 Stop0 1/PWM Forward1 0 Stop1 1/PWM ReverseDIR2 EN2 Result0 0 Stop0 1/PWM Forward1 0 Stop1 1/PWM ReverseThe DRV8833 chip provides overcurrent protection on the motor drive circuits. Each internal drive FET is independently monitored for an overcurrent condition and will be shut down internally to protect the chip. When an overcurrent condition is sensed the chip will shut down the FET with the fault and then set the NFAULT pin low signaling a fault condition on the chip. The remaining FETs will continue to operate as normal. When the fault condition is over, the chip will self-reset and return the NFAULT logic level to logic high. (See Table 2 for connector descriptions.)There are two Schmitt trigger buffered inputs on connectors J3, J6, J8 and J9 that bring motor speed feedback signals to the controlling system board. The Digilent motor and gearbox have hall-effect sensors arranged in a quadrature encoder format. These buffers have 5V tolerant inputs, when operated at 3.3V.The quadrature encoder signals are a pair of square waves whose frequency is proportional to motor rotation speed and with the pulses 90 out of phase. You can determine the motor speed with the frequency and motor rotation direction by the phase relationship between the two signals.3 Stepper Motor ControllerThe stepper motor controller has 4 output signals. It is composed of 4 open-drain transistor amplifiers.Uno32 Pin #PIC32Pin #Signal Notes26 60 A: PMD0/RE027 61 B: PMD1/RE128 62 C: PMD2/RE229 63 D: PMD3/RE3The stepper motor driver can be powered by either VIN, or an external power source connected to J10. If connecting an external power source, JP5 should be removed to prevent shorting the stepper motor voltages to the input voltage of the board.4 Servo MotorsThe Motor Shield has 4 servo motor connections. They can be powered from VCC5V0 or an external power source connected to J14. If connecting an external power source, JP6 should be removed. The voltage of the power source can be measured on analog pin A11 via a resistor divider network (see the schematic for more details).Uno32 Pin #PIC32Pin #Signal Notes30 64 Servo1: PMD4/RE4 J1631 1 Servo2: PMD5/RE5 J1732 2 Servo3: PMD6/RE6 J1833 3 Servo4: PMD7/RE7 J205 I2C Bus and ConnectorsThe Inter-Integrated Circuit (I2C) Interface provides a medium speed (100K or 400K bps) synchronous serial communications bus. The I2C interface provides master and slave operation using either 7 bit or 10 bit device addressing. Each device is given a unique address, and the protocol provides the ability to address packets to a specific device or to broadcast packets to all devices on the bus. Refer to the Microchip PIC32MX3XX data sheet and the PIC32 Family Reference Manual for detailed information on configuring and using the I2C interface.The PIC32MX320 microcontroller on the Uno32 provides for two independent I2C interfaces. The Motor Shield is designed to provide access to one of these interfaces, I2C #1 (SCL1, SDA1). I2C #1 is accessed through the standard Wire library. Connector J21 provides access to I2C port #1.Connector J21 can be used to extend the I2C bus off of the board to connect to external I2C devices. This is a standard 2x4 pin header connector with 0.100” spaced pins. It provides access to the I2C signals, SCL1 and SDA1, plus VCC3V3 and ground. The VCC3V3 can be used to power external I2C devices.The I2C bus uses open collector drivers to allow multiple devices to drive the bus signals. This means that pull-up resistors must be provided to supply the logic high state for the signals. The Motor Shield provides 2.2Kohm pull-up resistors on I2C #1.Generally, only one set of pull-ups are used on the bus. Jumpers JP7 and JP8 can be used to disable the on-board pull-ups on I2C #1 if a different value is needed or some other device on the bus is providing the pull-ups or if I2C #1 isn’t being used and the pull-ups are interfering with the use of the pins. The on-board pull-ups are enabled by install shorting blocks on JP7 and JP8. Removing the shorting blocks disables the pull-ups.Digilent has several small I/O modules available that can be connected using the I2C connector. These include a 3-axis accelerometer, 4-channel, 12-bit A/D converter, serial character LCD panel, 3-axis gyroscope, and a real-time clock/calendar. The on-board I/O expander is also controlled via I2C #1.6 I/O ExpanderThe Motor Shield contains an I/O expander module that gives access to 4 LEDs, 2 pushbuttons, and 2 jumper-switches. The I/O expander is controlled via I2C #1. The outputs can be easily controlled using the Motor Shield MPIDE library.Appendix: Motor Shield Pin-out Tables J1 PinsUno32 Pin #PIC32Pin #Pin Signal NotesJ1-01 VM (motor driver power supply) 2.7-10.8 VJ1-02 GNDJ2 PinsUno32 Pin #PIC32Pin #Pin Signal NotesJ2-01 Motor Driver NSLEEP Pull low to sleepJ2-02 GNDJ4 PinsUno32 Pin #PIC32Pin #Pin Signal NotesJ4-01 Motor Driver NFAULT Goes low on errorJ4-02 GNDJ3 PinsUno32 Pin #PIC32Pin #Pin Signal NotesJ3-01 SB1-INJ3-02 SA1-INJ3-03 GNDJ3-04 VCC3V3J3-05 M1+J3-06 M1-J6 PinsUno32 Pin #PIC32Pin #Pin Signal NotesJ6-01 SB2-INJ6-02 SA2-INJ6-03 GNDJ6-04 VCC3V3J6-05 M2+J6-06 M2- J5 PinsUno32 Pin #PIC32Pin #Pin Signal NotesJ5-01 M1+J5-02 M1+J7 PinsUno32 Pin #PIC32Pin #Pin Signal NotesJ7-01 M2+J7-02 M2-J8 PinsUno32 Pin #PIC32Pin #Pin Signal NotesJ8-01 SA1-IN/ Jumper#3 See JP320/A6 13 J8-02 SB1-IN/A6J8-03 GNDJ8-04 VCC3V3 J9 PinsUno32 Pin #PIC32Pin #Pin Signal Notes7 43 J9-01 SA2-IN/IC2/INT2/RD937 55 J9-02 SB1-IN/CN16/RD7J9-03 GNDJ9-04 VCC3V3JP3 PinsUno32 Pin #PIC32Pin #Pin Signal Notes2 42 JP3-01 IC1/INT1/RD8JP3-02 SB1-IN Select with jumper 35 45 JP3-03 IC4/PMCS1/PMAI4/INT4/R11J10, J12, J13 Pins (Stepper Motor Connections)Uno32 Pin #PIC32Pin #Pin Signal NotesJ10-01 External V+/VIN Select with JP5J10-02 External V-/GND26 60 J12-01 StepperA/PMD0/RE027 61 J12-02 StepperB/PMD1/RE128 62 J13-01 StepperC/PMD2/RE229 63 J13-02 StepperD/PMD3/RE3J14, J16, J17, J18, J20 Pins (Servo Motor Connections)Uno32 Pin #PIC32Pin #Pin Signal NotesJ14-01 External Vs+/VCC5V0 Select with JP6J14-02 GND30 64 J16-01 PMD4/RE4J16-02 External Vs+/VCC5V0J16-03 GND31 1 J17-01 PMD5/RE5J17-02 External Vs+/VCC5V0J17-03 GND32 2 J18-01 PMD6/RE6J18-02 External Vs+/VCC5V0J18-03 GND33 3 J19-01 PMD7/RE7J19-02 External Vs+/VCC5V0J19-03 GNDJ21 Pins (I2C)Uno32 Pin #PIC32Pin #Pin Signal Notes46 37 J21-01 SCL1/RG2 46 37 J21-02 SCL1/RG2 45 36 J21-03 SDA1/RG3 45 36 J21-04 SDA1/RG3J21-05 GNDJ21-06 GNDJ21-07 VCC3V3J21-08 VCC3V3。
怎样动手“造”一台图灵机作者:陈凯来源:《中国信息技术教育》2018年第09期在基础教育阶段的信息技术教材中,如果是回顾计算机发展历程的章节,常会提到图灵和他的图灵机,教材编写者通常会强调图灵机的重要意义,但对图灵机本身的描述却不多,涉及文字也很少,恐怕最多只能让人知道一个人的名字再加上一种机器的名称,更何况图灵在论文中提到的图灵机是一个理论上的模型,他没有亲自把图灵机造出来(对于他的论文来说,也没有真正制作出来的必要)。
而现在,人们也并不真正需要按图灵构想的原样实现一台图灵机来当作计算工具使用,一个没有实物对应的抽象模型,是比较难让普通初学者产生深入探索的兴趣的,也就更难让初学者自发产生动力,去思考为什么图灵机对于后来通用的电子计算机发展有着非常重要的意义。
如果只有40分钟的课时来介绍一下图灵机,那么应该怎样充分利用好这短暂的时间呢?其实只要40分钟,就可以将一台图灵机的搭建过程大致演示出来。
这里讲的并不是用程序来模拟图灵机,而是怎样用基础的电子元件来搭建一台图灵机,因为,当前绝大部分程序设计语言都与图灵等价,用程序语言来模拟图灵机,就体现不出“造”的过程。
为了使图灵机的工作过程更生动直观地展现出来,笔者“请”来一群变色龙来做游戏,游戏过程实际上就对应着图灵机的一般工作过程。
● 一只大变色龙和一只小变色龙的相遇(10分钟)想象一个有趣的场景,假设大变色龙A可变两种颜色——绿色和黄色,小变色龙B也可变两种颜色——绿色和黄色(如图1)。
当变色龙A遇到变色龙B时,则总共可能出现四种情况:绿色—绿色;绿色—黄色;黄色—绿色;黄色—黄色。
现实中变色龙的变色能力很强,还能变出其他颜色来,不过这里为了简化问题描述,就假设它们只能变两种颜色。
既然变色龙具有变色的能力,那么,当两只变色龙相遇后,它们各自的颜色有可能会变,也有可能不变。
假如有一个能力强大的变色龙驯兽师,能够让两只变色龙相遇后,按驯兽师预先设置的规则来改变,或不改变颜色。
基于Android 的图灵聊天机器人设计作者:柳琳罗军来源:《电脑知识与技术》2016年第17期摘要:聊天机器人基于 Android平台,调用图灵机器人API,具有聊天问答、娱乐互动、信息查询、计算等功能。
首先获得图灵机器人API Key,在Eclipse中集成图灵机器人API,再设计聊天界面,将用户输入内容发送到图灵机器人,并将返回结果显示给用户。
测试结果表明,图灵机器人应用程序能够顺利加载,与用户正常交流,可用于聊天或者查询,具有娱乐和实用价值。
关键词:Android;聊天;图灵机器人;API;APP中图分类号:TP18 文献标识码:A 文章编号:1009-3044(2016)17-0169-03Abstract: The chat robot based on Android platform and called Turing Robot API designs the function of chatting, interactive entertainment, information query, calculation, etc. First, get Turing robots API Key to Integrate API in Eclipse. Then design chat interface to send the input content to the Turing robot, and return the result to the user. Test results show that the application program of Turing Robot can load smoothly and communicate normally with users. It can use for chatting and querying so that it has entertainment and practical value.Key words: Android; chat; Turing Robot; API; APP1 背景随着人工智能和自然语言处理的不断发展,人工智能交互不断完善。
TURIN ROBOTICS图灵工业机器人通用操作手册上海图灵智造机器人有限公司版本TRC2-V2.0声 明本说明书对图灵工业机器人的构成、操作等内容进行了全面的说明。
请务必在认真阅读并充分理解的基础上操作本机器人。
●维护手册中的图解,为了说明细节取下盖子或安全罩进行绘制,运转此类部件时,务必按规定将盖子或安全罩还原后,再按说明书要求运转。
●说明书中的图及照片,为代表性示例,可能与所购买产品不同。
●说明书有时由于产品改进、规格变更及说明书自身更便于使用等原因而进行适当的修改。
●客户擅自进行产品改造,不在保修范围之内,本公司概不负责。
目 录1基本介绍 (1)1.1机器人系统 (1)1.2机器人本体 (1)1.3控制柜 (2)1.3.1控制柜外观 (2)1.3.2按钮/指示灯介绍 (3)1.4示教器 (4)1.4.1示教器外观 (4)1.4.2按键功能说明 (5)1.4.3触摸屏界面布局 (5)2机器人的坐标系 (7)2.1机器人轴和坐标系 (7)2.1.1机器人轴的定义 (7)2.1.2机器人坐标系的种类 (7)2.2关节坐标系 (7)2.3直角坐标系 (8)2.4工具坐标系 (9)2.4.1工具坐标系的定义 (9)2.4.2工具坐标系的标定 (10)2.4.3选择工具坐标系号 (11)3示教编程 (13)3.1示教前准备 (13)3.1.1钥匙开关选择本地 (13)3.1.2确认急停键 (13)3.1.3示教编程界面 (13)3.1.4程序编写区域构成 (14)3.2手动运动机器人 (15)3.2.1坐标系选择 (15)3.2.2工具和用户坐标系号选择 (15)3.2.3手动速度选择 (15)3.3运动指令 (16)3.3.1关节运动类型 (16)3.3.2直线运动类型 (17)3.3.3圆弧运动类型 (19)3.3.4修改运动位置 (21)3.3.5修改运动速度 (22)3.4通用指令操作 (23)3.4.1添加一条指令 (23)3.4.2指令的删除 (25)3.4.3指令的修改 (25)3.5程序文件管理 (26)4 程序工艺 (34)4.1焊接工艺 (34)4.1.1焊接工艺描述 (34)4.1.2焊接参数设定 (34)4.1.3焊接工艺指令 (37)4.2码垛工艺 (37)4.3喷涂工艺 (37)4.4视觉和跟踪工艺 (37)5程序运行 (38)5.1编写循环运行的程序 (38)5.2程序检查 (41)5.3自动运行前准备 (41)5.3.1自动运行时注意事项 (41)5.3.2自动运行速度 (42)5.4程序启动和暂停 (42)6参数设定 (43)6.1系统登录 (43)6.1.1 操作员登录设置 (43)6.1.2 系统登录设置 (43)6.2关节参数设置 (43)6.4工具坐标系标定 (45)6.5系统设置 (45)6.5.1按键定义 (45)6.5.2 日志打印设置 (46)6.6远程操作 (47)7基本指令列表 (48)7.1运动指令 (48)7.2逻辑指令 (49)7.3输入/输出指令 (49)7.4常规指令 (50)7.5焊接指令 (50)8系统诊断 (51)8.1运行日志 (51)8.2 I/O (52)8.2.1 I/O 控制 (52)8.2.2 DA控制 (53)8.3实时显示坐标值 (53)1基本介绍1.1机器人系统图灵机器人系统主要包括:机器人本体、控制柜、编程示教盒三部分。
典型图灵机的Java编程示例一图灵机概述图灵机(TM)是一种重要的计算模型,它由英国数学家A.M.Turing于1936年提出。
这个模型很好的描述了计算过程。
无数的事实表明,任何算法都可以用一个图灵机来描述,这就是著名的丘奇论题。
图灵机在可计算性理论中起着重要作用。
可以证明图灵机识别的语言就是0型语言。
图灵机的组成如下图所示:它由一个状态控制器,一个读写头和一个输入带组成。
其中输入带左右端可以无限伸长。
带上的每一格恰好有一个字符。
开始时,带上从编号为0开始的n个格存放着由有限输入字母表上的字符组成的字符串,第0格及其左边和第n+1格及其右边各格均为空白。
空白是一个特殊的带符号,它不属于输入字母表。
读写头一次可以在带上读或写一个字符,并可根据指令向左或向右移一格。
状态控制器根据当前的状态,读到输入字符并发布指令。
指令的内容包括状态转换,在带上的一格写上(更换)字符,以及读写头向左或向右移动一格等。
带子上的无穷多个小格可写、可擦;读写头可沿带子左右移动并在带上读写;每个图灵机有一个状态集Q,其中有一个开始状态和一个结束状态;还有一个符号集Σ={0,1,*};可形式化地描述为:图灵机是一个七元组M=(Q,T,Σ,δ,q0,B,H) 其中:Q ---有限的状态集合;Σ---有限的带字符集合;B ---空白符号,B∈Σ;T ---输入字符集合, T⊆Σ且B∉T;δ---下一次动作函数,是从QxΣ到QxΣx{L,R}的映射,即控制器的规则集合q0 ---初始状态,q0 ∈Q;H ---终止状态集合,H⊆Q.工作过程:首先从开始状态启动,每次动作都由控制器根据图灵机所处的当前状态和读写头所对准的符号决定下一步动作(或称操作)其中每一步包含三件事。
各符号写到读写头当前对准的那个小格内,取代原来的符号。
读写头向左或向右转动一格、或不动。
一次动作会引起:(1)控制器改变状态;(2)在当前扫描到的单元上,重写一个字符取代原来的字符;(3)读写头左移或右移一个单元;根据控制器的命令用某个状态(可以是原状态)取代当前的状态,使用图灵机进入一个新的状态。
控制器的命令:(状态、符号)→(写符号,移动、状态),当图灵机进入一个结束状态就停机。
计算任务宣告完成,带上的内容即为输出结果。
二图灵机模拟器编程1 软件开发环境简介(1)Java JDK —— Java开发的底层支持工具(2)Eclipse 3.2—— Java开发的IDE工具,用于编写图灵机的功能实现类和调用界面2 图灵机概要设计首先以下面的例子剖析一下设计图灵机的算法思想2.1 含有同等数量a和b的字符串识别器分析: 最初,图灵机M的带上已有字符a..b..a,前后都跟无限多个空白符#,如下图(a),M开始动作的第一步先读到最左边的第一个a(或b),并改写为X,如下图(b).然后右移去读最左边的第一个b(或a),并改写为X,如下图(c).又左移当发现最边的X时,再看紧接着X之后是否为a(或b),若为a(或b),将其改写为X,然后再右移找X,若紧接X之后是b(或a),又将其改写为X.如此反复进行.图灵机M按以上反复动作过程中,会出现以下情况:(1)当找a(b)时,如果不再有a(b),M应转向找b(a),如果还能找到b(a),说明b(a)的个数多于a(b)的个数,则M停止,表示不接受. 如果找不到b(a),说明a(b)与b(a)的个数相同,M应该进入终止状态.表示接受.(2)当找b(a)时,出现空白符#,说明a(b)的个数多于b(a)的个数,M停止,不接受.通过上面的分析,可构造图灵机M=(Q,T,Σ,δ,q0,#,F),其中:Q ={q0,q1,q2,q3,q4} T = {a,b}Σ={a,b,X,#}; F ={q4}δ函数定义如下:δ(q0,a)=(q1,X,R) δ(q2,a)=(q2,a,L)δ(q0,X)=(q3,X,R) δ(q2,X)=(q0,X,R)δ(q1,a)=(q1,a,R) δ(q2,X)=(q2,X,L)δ(q1,b)=(q2,X,L) δ(q3,X)=(q3,X,R)δ(q1,X)=(q1,X,R) δ(q3,#)=(q4,#,R)当M接受句子aabb时,其动作过程用格局表示为:q0aabb┠Xq1abb 所使用的函数δ(q0,a)=(q1,X,R)┠Xaq1bb 所使用的函数δ(q1,a)=(q1,a,R)┠Xq2aJb 所使用的函数δ(q1,b)=(q2,X,L)┠q2XaXb 所使用的函数δ(q2,a)=(q2,a,L)┠Xq0aXb 所使用的函数δ(q2,X)=(q0,X,R)┠XXq1Xb 所使用的函数δ(q0,a)=(q1,X,R)┠XXXq1b 所使用的函数δ(q1,X)=(q1,X,R)┠XXq2XX 所使用的函数δ(q1,b)=(q2,X,L)┠Xq2XXX 所使用的函数δ(q2,X)=(q2,X,L)┠XXq0XX 所使用的函数δ(q2,X)=(q0,X,R)┠XXXq3X 所使用的函数δ(q0,X)=(q3,X,R)┠XXXXq3 所使用的函数δ(q3,X)=(q3,X,R)┠XXXXq4 所使用的函数δ(q3,#)=(q4,#,R) 进一步,在设计过程中如何将已规划好的函数及格局等体现在图灵机执行过程中,用下面的例2说明。
2.2 用于计算“x+1”的图灵机。
我们根据图灵机的原理,利用二进制来设计一个专门计算“x+1”的图灵机,要求计算完成时读写头要回归原位。
于是我们设计的图灵机为:状态集合Q:{start, add ,carry, noncarry, overflow, return, halt}字母表∑:{0,1,*}初始状态q0:start停机状态H:halt规则集合δ:(见表2.1)有了以上这些假设,我们来看该图灵机是如何具体进行计算动作的:假定x=5,则图灵机的初始状态如图2.2所示,箭头表示读写头当前的位置。
再从规则表2.1可知,当前状态为“add”,当前符号为“1”时,读写头的响应为:改写当前符号为“0”,并向左移动一格,内部状态改变为“carry”表示有进位,如图2.4所示:接下来从规则表2.1可知,读写头应改写当前符号为“1”,并向左移动一格,进入“noncarry”状态,表明没有进位,如图2.5所示:此时,从规则表2.1知道:读写头不改写当前符号,只是继续向左移动一格,指向“*”,如图2.6所示:这时实际已经完成“5+1=6”的计算,因为我们要求读写头要回归原位,按规则接下来就是将读写头一路右移直到原位“*”,内部状态保持为“return”状态,如图2.7所示:从读写头状态可知,图灵机这时还处在运行状态,从规则表中可知,当读写头状态为“return”且当前符号为“*”时,则应进入“halt”状态,由于“halt”状态是该图灵机的停机状态,所以,图灵机停止运行,圆满地完成了计算要求,如图2.8所示:有了上面设计算法思想的铺垫,下面给出本次开发的某一特定功能图灵机的工作过程示意。
图灵机模拟器编程示例:2.3 一元至二元的转换功能:将输入的字母的个数转换成二进制数目前状态和输入,用黄色高亮显示。
我们追踪其执行。
扫描到当前输入是A,图灵机根据状态转移箭头匹配:A:X,图灵机将当前输入A改写为X。
带头从此位置左移一个位置,到达下一个状态(新的状态标识为L左移)。
下图为其上描述的第一步。
当前单元格内容为:#,图灵机根据状态转移箭头匹配:#:1,图灵机将当前#改写为1,带头从此位置右移一个位置,到达下一个状态(新的状态标识为R右移)。
下图是接下来的几个步骤示意图:循环直至所有的输入都被改写覆盖为X,图灵机除去所有的X(即用#覆盖),并到停机状态。
灵机上文所述的转换,从一元至二元。
即如果输入构成的N一连续的,那么图灵机打印数N在二元到左边的序列一的(和覆盖一的与X的)。
在上面的例子中,输入由6个字母A组成的串,图灵机将其改写为二进制数110到输入带上。
执行节结果图如下:3 图灵机功能实现程序结构剖析(八种常用图灵机模型示例)3.1 二进数加法Binary Adder:binaryadder.tur,模型如下图:3.2 二进制计数器Binary Counter:binarycounter.tur,模型图如下:3.3 二元回文Binary Palindrome Decider:binarypalin.tur,模型图如下:3.4 同等数量a和b的识别器Equal Number of a's and b's:equalab.tur,模型图如下:3.5 3的倍数识别器Multiple of 3 Decider3:mult3.tur,模型图如下:3.6 括号匹配器Parenthesis Matcher:paren.tur,模型图如下:3.7 含有偶数个a的字符串识别器Parity Decider:parity.tur,模型图如下:3.8 一元至二元转换器Unary-to-Binary Converter:unarytobinary.tur,第二部分2.3中已分析过其功能,模型图如下:4 图灵机执行代码结构剖析每一个主要图灵机组件(输入带,转换,控制状态)使用良好的面向对象的原则。
•输入带,Tape.java(类方法结构图如上左)是代表无界图灵机的输入带。
它支持下列功能:左移,右移带头,读取当前单元格中的字符,改写当前单元格的内容。
为实现上述功能,使用两个栈(一是存储所有左移的符号,二是存储所有右移的符号)。
为显示输入带内容,首先将第一个栈中内容的逆向并将其显示,其次是当前元素,最后是第二个栈的内容。
•状态,Vertex.java(类方法结构图如上右):一个点代表图灵机的一个状态。
变量“name”是用于唯一标识状态的字符串,每个状态有一个名字和类型;“haltStatus”可以取五种值(左移,右移,停机,接受,或拒绝),标识带在进入一个状态时的移动方向,或标识停机状态。
“xpos”和“ypos”有0和1.0两者取值,用于标识图灵机图形化界面中点的中心位置(用高和宽即横纵坐标一起标识,(0,0)表示处在屏幕界面的左上方,(1.0,1.0)表示在右下方)。
•Ege,java(类方法结构图如上左):包含图灵机图形的边的信息。
在图形化用户界面中,一条边是连接两个点的一条线,本程序中它代表两个状态之间的转换,转换条件会触发该次转换。
如果当前处于旧状态,带上同步标识旧标识,当前状态将转移至新状态并将新标识改写至当前带位置。
变量“curve”取值在-1.0和1.0之间,用于标识边的弯曲率,若取0,即边为一直线;取-1.0和1.0时,边都为一半圆弧线,正值时,边为逆时针方向从旧状态指向新状态,负值时,边为顺时针方向从新状态指向旧状态。