Turing Complete

Turing Complete

28 ratings
Turing Complete: All-level walkthrough
By qwerty
All-level solution and useful information for anyone with little or no background in CS or digital electronic design.
This guide is incomplete and subject to change.
2
   
Award
Favorite
Favorited
Unfavorite
0. Purpose of writing this guide
This walkthrough is written for anyone who needs some basics of computer science and mathematical logic to clear all levels, especially I will describe the objectives for each section of levels and how to build two types of CPU architecture: Overture and LEG.

I’d like this guide to get into the knowledge underlying this puzzle game. I hope I can make this guide more informative and suitable for all non-specialized readers interested in logic and computer science.

*This guide is temporary and being updated. I will divide this long guide into smaller ones section by section.
1. Basic logic
In this section the player is asked to make different kinds of logic gates with NAND gates so that the player can use logic gates to make the building blocks of functional units (e.g. arithmetic logic units and memory).
https://test-steamproxy.haloskins.io/sharedfiles/filedetails/?id=3078668306
https://test-steamproxy.haloskins.io/sharedfiles/filedetails/?id=3090798391
2. Arithmetic and memory
In this section the player is asked to use logic gates and other components to build an arithmetic logic unit (ALU) and memory as the building blocks of CPU architecture.
https://test-steamproxy.haloskins.io/sharedfiles/filedetails/?id=3078986482
3. CPU architecture
In this section the player will use the components created in the last section to construct a CPU: Overture, including the installation of registers, counters, programs, calculations and conditions.
https://test-steamproxy.haloskins.io/sharedfiles/filedetails/?id=3089627419
4.X Solution
Add 5
Calibrating Laser Cannons
Spacial Invasion
Storage Cracker
Masking Time
The Maze
5.X Solution
huh
X. Component preparation
Arithmetic Logic Unit (ALU)
8-Input OR
Condition Unit
Instruction Decoder
2.1 Binary number
A binary number is a number whose digits are either 0 or 1 and represent the multiple of powers of 2. The Nth digit of a binary number from the right represents the multiple of the (N-1)th power of 2. If a,b,c are digits of a binary number abc, then
  • abc=a*2^2+b*2^1+c*2^0=4a+2b+c
Hence the number 7 in base 10 can be represented as 111 in base 2 because 7=4+2+1. Every number in base 10 can be converted into a binary number by expressing its series of powers of 2.
2.2 Bits and bytes
Bits are binary digits. They are also the units of information that describe two equally possible states, such as 0 or 1. A bit of information is equal to the amount of information we need to determine which side faces up when we flip a coin. Bytes are bundles of eight bits, so a byte has 2^8=256 equally possible states. Larger units of byte are kilobytes (KB), megabytes (MB) and gigabytes (GB).
2.3 Short circuit
A short circuit is a circuit in which a wire directly connects two nodes at different voltage, such as a wire that directly connects two terminals of a battery. In a logic circuit, a short happens when a wire connects two different inputs. It is one of the most common errors to be avoided in a circuit design. Using OR gates or bit switches can avoid this type of error.
2.4 Delayed line
In a logic circuit, a delayed line is a component that creates a time difference between input and output for a signal to take. Although a delay is undesirable in most times because it reduces the efficiency of signal transmission, it can help us save signals for a long time for future use.
2.5 Loop
A loop is a closed path in a circuit, so the input of each component in a loop depends on its output. This usually causes chaos in a logic circuit because both input and output are indeterminate. It is one of the most common errors to be avoided in a circuit design as well. However, the construction of a loop is allowed if there is a delayed component placed in that loop because the signal flow to the input is delayed and does not affect the output in the same tick.
2.6 Vertical algorithm of addition
A common way to do the addition of two numbers by hand is to line up two numbers digit by digit and add up two digits in each column in turn starting from the right. A carry is the extra digit of the sum of two digits in a column when the sum reaches or exceeds the base (base 2 for bits). Then the carry is added to the sum of two digits in the next column. So, there are three digits to be added up after the first column: two digits in the column and a carry from the previous column.
5
6
8
+
2
7
3
=
7
13
11
+
1
1
=
8
4
1
This is called the vertical algorithm of addition. This algorithm underlies how a full adder works.
2.7 Representation of negative numbers
For any signed number, we have to reserve a place to denote the sign. For a binary number, the easiest way to do so is simply using the highest bit to denote the sign. But we also need to find a good way for a computer to handle both signed and unsigned numbers at the same time.
Modular arithmetic
Modular arithmetic is arithmetic involving the operations on remainders of integers with the same divisor (whole numbers divided by the same number). Let a,b are integers to be divided and n is a divisor. If the remainders of a and b are equal, then we say a is congruent to b modulo n, denoted by a=b (mod n). Modular addition has a remarkable property: the remainder of the sum of two integers is equal to the remainder of the sum of the remainders of the two integers. That is
  • (a+b) mod n = (a mod n + b mod n) mod n
So we can replace a and b with any congruent integer. For example, a 3-bit number can express eight numbers from 0 to 7. Any number less than 0 or greater than 7 can only be expressed by its remainder on the clock. For 5+4=9, 101+100=1001 in base 2, the remainder of 9 divided by 8 is 1, which corresponds to the first three digits 001 in 1001 in base 2. Similarly, because -3 is congruent to 5 and 20 is congruent to 4, 20-3=17 is congruent to 5+4=9, which is congruent to 1.
Two's complement
Therefore, we can regard the upper half of the eight numbers 4-7 as -4 to -1 and the lower half 0-3 remains the same with no change of the clock arithmetic. That is the same as the change in the highest digit from 4 to -4. If we need to calculate 3-1=2, we only need to calculate 3+7=10. Because 10 is congruent to 2, the result of 3-1 is 2. Similarly, to calculate 2-3=-1, we have 2+5=7. Because 7 represents -1, the result of 2-3 is -1. To find the opposite of a number x, we have
  • -x=0-x=8-x=(7+1)-x=(7-x)+1 (mod 8)
Because 7 is 111 in base 2, any 3-bit number subtracted from 111 is the bitwise negation of itself (0 becomes 1 and 1 becomes 0 after the subtraction). Therefore the opposite of an N-bit number (except for -2^(N-1)) is the sum of the bitwise negation of the number itself and 1. This method of representing the opposite of a binary number is called two's complement.
2.8 Encoders and decoders
Encoders are electronic components used to convert 2^N lines of signals to N-bit numbers. Decoders work in the opposite way of what encoders do. They convert N-bit numbers to 2^N lines of signals. As shown in the left figure, the four inputs on the left from top to bottom represent 0 to 3 and are encoded to 00, 01, 10 and 11, respectively. The two outputs on the right from top to bottom represent 1's and 2's place of a 2-bit number. Although encoders are unnecessary for all levels, they may inspire the player to create complex CPU architecture in the sandbox.
2.9 Arithmetic logic unit
An arithmetic logic unit (ALU) is a computational unit that performs arithmetic and bitwise operations on binary numbers. To do a computation, binary numbers and a code that indicates the operation should be put in an ALU. Addition is one of the most common operations in ALUs. The other common operations in ALUs include subtraction, bitwise AND, OR and NOT.
2.10 Memory
Computer memory is a unit that saves data and programs. Based on different uses, computer memory can be classified into registers, primary and secondary memory. A register is a type of memory that holds data for immediate use in a series of calculations. The storing time and space of a register is normally short and limited. Primary memory is a type of memory that can store data relatively longer and more than a register for immediate use in the computer, but it can't be used to exchange data between two different computers. Instead, secondary memory is a type of memory responsible for the long-term storage of a large amount of data, such as hard drives and CDs. We can attach secondary memory to a computer when we need to save or load data.
2.11 Counter
A counter is used to record the address of a code in a program. When we want a computer to execute a specific code in a program, we need to know the address of that code and set the counter to that address. Like a register, we can overwrite the counter or load the number saved in the counter to control the path of the execution of a program.
3.1 Component factory
The component factory is the workbench for the player to create components that can be used to construct complex architectures. The shape of a component depends on its layout. The player is allowed to relabel input and output and use a probe to display the signal inside a component. In order to create a new component, go to the schematic menu and name the new schematic. Then double click the schematic the player wants to edit.
3.2 Condition
A condition is a logical operation that determines whether a binary number satisfies an equation or inequality. In CPU architecture, conditions can be used to control the execution of a program by jumping to the address of the code the player wants to execute. This can be done by overwriting the counter. The basic properties of equations or inequalities are listed below:
  • Law of trichotomy: If x,y are integers, then x<y, x=y or x>y.
  • If x,y are integers, then
    Reflexivity
    x=x
    Symmetry
    If x<y, then y>x
    If x=y, then y=x
    If x>y, then y<x
    Transitivity
    If x<y and y<z, then x<z
    If x=y and y=z, then x=z
    If x>y and y>z, then x>z
  • If x,y,a are integers, then
    If
    x<y
    x=y
    x>y
    All a
    x+a<y+a
    x+a=y+a
    x+a>y+a
    a<0
    ax>ay
    ax=ay
    ax<ay
    a=0
    ax=ay=0
    ax=ay=0
    ax=ay=0
    a>0
    ax<ay
    ax=ay
    ax>ay
We can use these properties to simplify an equation or inequality in order to execute the condition instruction we've already made. For example, to determine if x=5, we can rewrite this equation into x-5=0. Then we can put the instruction "=0" and the input "x-5" in a condition unit.
3.3 Program
A program is a set of instruction codes to be executed. The address of each instruction code is recorded by a counter. In the next section the player will perform simple programming tasks. For example, if the player wants to add two numbers from input a and b, the player should first write two codes that allow a CPU to copy each input to register 1 and 2. Then write a code to carry out the addition, and then write the last code to output the result saved in register 3.
3.4 Immediate value
Immediate values are codes stored in a program in contrast to values saved in memory. For example, if the player wants to put a number in a register, the player can use the immediate value mode and directly write the number the player wants to copy in the program.
3.5 Turing completeness
A data-instruction system is Turing complete if it can simulate any Turing machine, which is an imaginary machine that can read symbols in the squares of an infinitely long tape. A Turing machine can write a new symbol, move the tape or change its state based on its current state or symbol. The following shows how a Turing machine carries out the two's complement of a binary number ("NOT" is the initial state and the first digit from the left is the initial position).
Current state
Current symbol
Overwriting symbol
Move direction
Next state
NOT
0
1
Right
NOT
NOT
1
0
Right
NOT
NOT
Blank
Blank
Left
Add 1
Add 1
0
1
Left
Reset
Add 1
1
0
Left
Add 1
Add 1
Blank
Blank
Right
Halt
Reset
0
0
Left
Reset
Reset
1
1
Left
Reset
Reset
Blank
Blank
Right
Halt
For the binary number 10100, we have
Step 0
Blank
1
0
1
0
0
Blank
NOT,1
Step 1
Blank
0
0
1
0
0
Blank
NOT,0
Step 2
Blank
0
1
1
0
0
Blank
NOT,1
Step 3
Blank
0
1
0
0
0
Blank
NOT,0
Step 4
Blank
0
1
0
1
0
Blank
NOT,0
Step 5
Blank
0
1
0
1
1
Blank
NOT,Blank
Step 6
Blank
0
1
0
1
1
Blank
Add 1,1
Step 7
Blank
0
1
0
1
0
Blank
Add 1,1
Step 8
Blank
0
1
0
0
0
Blank
Add 1,0
Step 9
Blank
0
1
1
0
0
Blank
Reset,1
Step 10
Blank
0
1
1
0
0
Blank
Reset,0
Step 11
Blank
0
1
1
0
0
Blank
Reset,Blank
Step 12
Blank
0
1
1
0
0
Blank
Halt,0
The result is 01100, as expected.
4. Programming
Objective
In this section the player needs to be familiar with simple programming tasks and the use of assembly language by editing the programming memory of the CPU created in the last section.
4.1 Instruction manual
In the game, the instruction manual allows the player to record a list of instruction codes to be executed. The list depends on the design of CPU architecture. To record a new instruction code, click the downward arrow to expand the list, click the plus sign to add a line, toggle each symbol of a byte (green denotes ON, red denotes OFF and gray with a question mark denotes either ON or OFF), and then edit the label by changing its range or name. Once the player adds a new instruction code, toggle the symbols on the panel in order to match the bit pattern of the new code.
4.2 Assembly language
Assembly language (a.k.a. symbolic machine code) is a list of names of instruction codes in the programming memory of a CPU, in contrast to bits or bytes. Using assembly language in programming is convenient for programmers to understand the algorithm of a task. For example, instead of typing a number defining addition, we can define the string "add" as that number in advance and then type the string "add" directly while coding.

When completing a programming level in the game, the player can type "const 'string' 'number' " to define a string as a number. For example, one can type "const add 68" to let "add" be "68".

The player can also use "label" to label a code address when a program needs to jump to that specific code if a condition is met. For example, one can type "label 'string' " to refer a string to a code address and then type " 'string' 'condition' " to execute the jump if the condition defined by the code is met. Otherwise, the program will normally execute the next line of code.
5. CPU architecture 2
Objective
5.1 Binary operation
5.2 LEG architecture
1 Comments
Pool_E 9 Oct, 2024 @ 2:56pm 
where is Calculations???