by rajaraodv
通过rajaraodv
JavaScript正在完善—解释 (JavaScript Is Turing Complete— Explained)
If you start learning functional programming in JavaScript, you’ll probably hear about lambda calculus, Turing machine, Turing complete and somehow “JavaScript is Turing complete”.
如果您开始学习JavaScript函数编程,您可能会听说有关lambda演算 , Turing机器 , Turing完成以及“ JavaScript是Turing完成”的信息。
But, no one seem to explain, in simple terms, what it actually means. What’s the relation b/w a Turing “machine” and JavaScript “language”? Also, most people use jargon to explain jargon like so:
但是,似乎没有人用简单的术语来解释其实际含义。 图灵“机器”和JavaScript“语言”之间的关系是什么? 同样,大多数人使用术语来解释术语,如下所示:
In computability theory, a system of data-manipulation rules (such as a computer’s instruction set, a programming language, or a cellular automaton) is said to be Turing complete or computationally universal if it can be used to simulate any single-taped Turing machine. The concept is named after English mathematician Alan Turing. A classic example is lambda calculus.
在可计算性理论中 ,如果可以将数据操纵规则系统(例如计算机的指令集 , 编程语言或元胞自动机 )用于模拟任何一种单带式Turing机器,则称该系统为Turing完整或计算通用的 。 这个概念以英国数学家艾伦·图灵(Alan Turing )的名字命名。 一个典型的例子是lambda演算 。
So this is my attempt at explaining these comcepts simply.
因此,这是我试图简单解释这些概念的尝试。
图灵机 (Turing Machines)
Back in the day, people wanted to know how to create a machine that could do all the calculations they were doing by hand. They wanted to know how to build such a machine and how it might work.
过去,人们想知道如何创建一台可以手动完成所有计算的机器。 他们想知道如何构建这样的机器,以及它如何工作。
Alan Turing came up with a hypothetical machine that could take any program of any complexity and run it. It could be implemented using a simple tape, a head that moves left and right, could store data by reading, writing, and erasing the contents of square cells. Given long enough tape and enough time, it could compute any program.
艾伦·图灵(Alan Turing)提出了一个假设的机器,该机器可以采用任何复杂程度的程序并运行它。 它可以使用简单的磁带来实现,磁带可以左右移动,可以通过读取,写入和擦除方形单元格的内容来存储数据。 给定足够长的磁带和足够的时间,它就可以计算任何程序。
In other words, he explained how someone can build a computer. And called the computer a “Turing machine”
换句话说,他解释了某人如何构建计算机。 并将计算机称为“图灵机”
Trivia: Back in Alan Turing’s days, the word “Computer” meant the person who manually computes programs (not the machines) :)
琐事:在艾伦·图灵(Alan Turing)时代,“计算机”一词是指手动计算程序的人(而不是机器):)
如此强大但如此简单 (So powerful yet so simple)
Turing machines soon became very popular, and eventually a standard because while they provided a powerful mechanism to calculate anything, they were also easy to understand. As described in the video below, Turing machines use a tape to keep track of states and run computations.
图灵机很快变得非常流行,并最终成为一种标准,因为它们虽然提供了强大的机制来计算任何东西,但也很容易理解。 如以下视频所述,图灵机使用磁带来跟踪状态并运行计算。
“单”对“多”带图灵机 (“Single” Vs “Multi” Tape Turing Machines)
One other jargon you’ll hear about Turing machines is the concept of “single” tape.
关于图灵机,您还将听到的另一行话是“单”带的概念。
The initial version of the Turing machine had just a long single tape. Later on, people came up with the concept of “multiple” tape Turing machines that used two to five tapes. Multi-tape Turing machines were not any more powerful than single-tape ones, but they helped to simplify programs.
图灵机的初始版本只有一长条磁带。 后来,人们想到了使用两到五个磁带的“多”磁带图灵机的概念。 多带图灵机没有单带机强大,但它们有助于简化程序。
So explicitly saying “single” tape isn’t necessary.
因此,无需明确地说出“单个”磁带。
图灵完成 (Turing Complete)
If a physical machine (like a computer) or virtual machine, which is a software, (like JavaVM) can take any program and run it just like a Turing machine, then that machine is called “Turing Complete”. PS: It’s kind of a certification.
如果物理机(如计算机)或虚拟机(即软件)(如JavaVM)可以采用任何程序并像图灵机一样运行它,则该计算机称为“图灵完备”。 PS:这是一种认证。
示例:图灵完整版与图灵不完整机 (Examples: Turing complete Vs Turing incomplete machine)
A calculator is a good example of a Turing incomplete machine because it can only perform a small pre-defined subset of calculations.
计算器是图灵不完整机器的一个很好的例子,因为它只能执行小的预定义计算子集。
However a home computer (Mac or a PC) is a Turing complete machine because it can do any calculation that a Turing machine can do if we give it enough memory and time.
但是,家用计算机(Mac或PC)是图灵完整的计算机,因为如果我们给它足够的内存和时间,它可以执行图灵计算机可以执行的任何计算。
“ JavaScript正在完成图灵” (“JavaScript Is Turing Complete”)
If you think about it, a Turing machine is just a concept — it means that any “thing”(physical or virtual) that takes any program and run it is essentially a Turing Machine. And if that “thing” can run every program that a “Turing Machine” can run, then it is called “Turing Complete”.
如果您考虑一下,图灵机只是一个概念-它意味着需要任何程序并运行它的任何“ 事物 ”(物理的或虚拟的)本质上都是图灵机。 如果该“事物”可以运行“ Turing Machine”可以运行的每个程序,则称为“ Turing Complete”。
Now if you think about any modern programming language, they also take programs(written by us) as input and run them. Further, any program that can be theoretically written to run for a Turing machine can also be written in JavaScript. Thus, JavaScript is Turing complete.
现在,如果您考虑使用任何现代编程语言,它们也将程序(由我们编写)作为输入并运行它们。 此外,理论上可以编写为图灵机运行的任何程序也可以用JavaScript编写。 因此,JavaScript已完成。
That’s it!
而已!
??? If you like this post, please 1. ❤❤❤ it below on Medium and 2. please share it on Twitter. You may retweet the below card???
??? 如果您喜欢这篇文章,请1.在下面的Medium中进行 ❤❤❤ , 然后2.在Twitter上分享。 您可以转发以下卡吗???
我的其他帖子 (My Other Posts)
LATEST: Functional Programming In JS — With Practical Examples (Part 1)
功能编程 (Functional Programming)
Functional Programming In JS — With Practical Examples (Part 1)
ES6 (ES6)
Web包装 (WebPack)
Webpack & Hot Module Replacement [HMR] (under-the-hood)
Webpack和热模块更换[HMR] (在内部)
Draft.js (Draft.js)
React And Redux: (React And Redux :)
A Guide For Building A React Redux CRUD App (3-page app)
构建React Redux CRUD应用程序指南 (3页应用程序)
销售队伍 (Salesforce)
Thanks for reading!
谢谢阅读!
翻译自: https://www.freecodecamp.org/news/javascript-is-turing-complete-explained-41a34287d263/