Every Computer System is a State Machine -- TLA+ series (1)

栏目: IT技术 · 发布时间: 3年前

内容简介:This is the first post of a series of posts I plan to make about TLA+.First, let's take a look at a very philosophical question -- "what is a computer?". I am writing this post on my computer, which has 32 GB of RAM and 8 2.4 GHz cores. Most likely you are

This is the first post of a series of posts I plan to make about TLA+.

What is a computer

First, let's take a look at a very philosophical question -- "what is a computer?". I am writing this post on my computer, which has 32 GB of RAM and 8 2.4 GHz cores. Most likely you are reading this post on your computer as well (or smartphone, which is also a computer). We are surrounded by computers nowadays (smart phones, laptops, game consoles, smart speaker, smart home devices, etc.). But what is a computer ?

Is computer the thing on your desk right now with billions of transistors? Well, that describes the computer on your desk, or more generally a class of computers of this kind. But this certainly doesn't describe all computers. If I just throw a billion transistors in a trash can, the trash can is not a computer.

Is computer a set of transistors wired up in a very specific way? This can describe computers of certain architecture, maybe e.g. x86. But this certainly doesn't describe all computers of different architectures. We need abstraction. Maybe we should not look at the physical presence of a computer. But instead, describe and define a computer by what it can do. You might have guessed it already, a computer is a Turing Machine . And Turing Machine describes and defines all possible behaviors of all computers in the world.

What is a Turing Machine

Ben Eater has a very good video explaining Turing Machine . So any algorithm, program, distributed system, the most complicated system interaction you can ever imagine, can be described as a state machine, which can be implemented by a Turing Machine. This makes sense intuitively as well. Computer, physically, is nothing more than a storage of various states, and combinational logic based on all the states (Program Counter, register values, RAM, Carry Flag, etc.) for state transition.

View every system as a state machine

Anything computable can be done by the Turing Machine. And Turing Machine can be described as a state machine. So naturally, a state machine is sufficient to describe anything computable. Behaviors can be described in programming languages, but they are often too concrete. State machine is very flexible and easy-to-use at describing system behaviors.

Let's look at the following tiny example:

a = get_random_number()
a += 1

We can describe this program behavior as a state machine of two variables: a and pc (stands for program counter). An example run can be <a:10, pc:start> -> <a:11, pc:middle> -> <a:11, pc:done>. The state machine describing its behavior would look something like:

if pc == start:
    a = get_random_number()
else if pc == middle:
    a += 1
else:
    halt

You should not read this like python which executes the program from top to bottom. And in fact it's not a program that you run at all. It's a spec and it just specifies the state transitions for this state machine.

State machine is simpler

Python (replace with your favorite language) can also be used to describe program behaviors. It's just that states in a program are much harder to manage and describe because they are represented differently. For the simple python program above, there are "hidden" states like heap, stack, program counter, etc. States in a state machine are just variables. It's consistent, which makes it easier to use for describing behaviors.


以上所述就是小编给大家介绍的《Every Computer System is a State Machine -- TLA+ series (1)》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

操作系统基础教程

操作系统基础教程

戴维斯 / 第1版 (2006年7月1日) / 2006-7 / 34.0

这是一本关于操作系统基本原理的教科书,其最大特点就是从操作系统的分层概念出发,深入浅出地介绍了操作系统的基本概念和基本框架。本书可以作为高等院校非计算机专业相关课程的教材或参考书,也适合具有高中以上数学基础的计算机用户自学,还可以作为社会上计算机培训机构的教材。对所有想了解计算机操作系统,但又不需要或不打算深入学习其理论和实现细节的读者来说,本书是一本极具价值的入门指导书。一起来看看 《操作系统基础教程》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

在线进制转换器
在线进制转换器

各进制数互转换器