Propositional Logic
Examples in natural language
| Proposition | Truth value (bool) |
| Humans are living beings | True, true, 1 |
| Iron is a living being | False, false, 0 |
Digital circuits represent bool
| Circuit value | bool |
| High level | 1 |
| Low level | 0 |
The hardware implementation of digital circuits is not handled here. I donโt know the details either
[logic-operator] logical and, or, not
- And, ,
and, logical conjunction - Or, ,
or, logical disjunction - Not, ,
not, logical negation
Examples in natural language
| Proposition | Truth value |
| Humans are living beings and 1 is a natural number | 1 |
| Humans are living beings and 1 = 2 | 0 |
Formal language
| 1 | 1 | 1 |
| 1 | 0 | 0 |
| 0 | 1 | 0 |
| 0 | 0 | 0 |
| 1 | 1 | 1 |
| 1 | 0 | 1 |
| 0 | 1 | 1 |
| 0 | 0 | 0 |
| 1 | 0 |
| 0 | 1 |
Digital circuit and logic gate representations of
Are gates designed to disallow reverse current?
A not gate turns low level into high level, which shows the hardware implementation of a gate needs external energy, it needs to be powered
are โredundantโ, e.g. logically equivalently, we can use to represent
Circuit gate implementation starts with not,nand, i.e., . But I think maintaining the symmetry of is useful, whether cognitively or in terms of the duality of with respect to
[computability] Computability of circuits
Any function can be made using logic gates
(image from p.85 of ref-1)


Consider the input and output of the function separately
- Construction of inputs
According to the image above, using circuits + not gates + and gates , for a total of input possibilities
Some functions only need a part of the inputs, not all of them. In these cases, some wires donโt need to be connected
represents the โmultiplicativeโ property of value parallel circuits
Regarding the output, letโs first discuss the output
- Construction of output
Among the inputs, connect the wires that you want to output as to an or gate
Example not xor function. Connect the inputs to the output or gate
xor is called exclusive or, . The truth table for this function
| 1 | 1 | 0 |
| 1 | 0 | 1 |
| 0 | 1 | 1 |
| 0 | 0 | 0 |
- Construction of output. Can be thought of as as its components
If a full function isnโt needed, the circuit computing elements donโt necessarily have to be built in this fixed way. They can be further simplified based on the situation to reduce the number of gates used. But we wonโt get into details here
A symbolic representation for multiple input or output lines in a computing unit (p. 54 of ref-1) (3 inputs 2 outputs)
[control-circuit] Control circuit, selector or multiplexer
is the control circuit. Its function is
- When , outputs to , doesnโt output to
- When , outputs to , doesnโt output to
(p. 81โ82 of ref-1)


inputs need control circuits
[De-Morgan-law] negative dual ๅพ or De Morgan ๅพ
Prove by exhaustion, just like how humans counting is actually exhaustion. Same below
[boolean-algebra]
bool algebra is denoted as or
[bool-distributive-law] Distributive Law
ๅ ถ negative dual
Inductively ( and refers to taking all functions)
Similarly
[bool-commutative-law] ไบคๆขๅพ . same for
[bool-associative-law] ็ปๅๅพ . same for
[periodic-circuit] Periodic Circuit
Implemented by crystal oscillators
[memory-circuit] Circuit Memory
Black box model
Possible implementation
- The middle of the diagram uses a loop circuit to reuse the Bool value from the previous cycle. If write control is turned off, the values of remain unchanged
- Inverters (
notgates) ensure current direction and prevent attenuation (via external energy) - Suppose the value of the yellow part in the loop circuit is , and the blue part is . To write into an existing , a higher write voltage than the one in the loop circuit is needed to override the loop, i.e. using higher voltage thus to override the existing
[finite-machine] Finite State Machine
[i/o] The input of a circuit might come from the outside world (e.g. sensors, keyboards), and the output of a circuit might also go to the outside world (e.g. signal lights, screens)
The rhythm of external inputs is usually inconsistent with the rhythm of the computerโs internal periodic circuits, so the external inputs need to pass through synchronization components first
[memory-array] Memory array
Example is the number of steps taken when counting from 000, 001, 010 to 111, although this assumes we can recognize three bits. ,
Use the range of natural numbers contained in multiple bits, for example 3 bits as parameters, to correspond to real-world content. Example The representation of characters in a computer e.g. ASCII, Unicode, the position and color of pixels on a screen
(image modified from wiki media about ASCII. Hex refers to hexadecimal)
In practical applications, multiple bits per address is better than 1 bit per address, or rather, a two-dimensional memory array is more efficient than a one-dimensional one
(p. 265 of ref-1)
[instruction] ๆไปค
Control the computer to complete some circuit tasks through instructions. Instructions are also represented by binary (multi-bit data). The instruction stream is generated by the compiler based on the source code and stored in memory, then read and executed by the CPU
Some common circuit tasks
- Addition of natural numbers
- Judging whether bit data meets the required conditions, for example, judging if
- Jumping to the execution of other instructions
Assume an instruction is completed within one circuit cycle (single-cycle computer)
Example add instruction. add x_1 x_2. The bit data fields of the instruction are divided into three areas, representing different types of information

-
Reading the
addinstruction- The
addinstruction atadress_0(add x_1 x_2as well asadress_1, adress 2come from source code and compiler generation) - The value
adress_0stored at the fixed memory addressadress_of_instructionis read out, the data in the index area of theaddinstruction is sent to the control signal component (control unit), then control signals are calculated and output (too many details, see ref-1)
- The
-
Execute the
addinstruction- The output control signals are input to the memoryโs control circuit components, reading out
x_1inadress_1andx_2inadress_2from memory, and inputting them into the arithmetic component (ALU) - Based on the output control signals, the output
x_1 + x_2from the arithmetic component is written toadress_1(overwriting the value ofx_1)
- The output control signals are input to the memoryโs control circuit components, reading out
-
Enter and fetch the instruction for the next cycle
- The value
adress_0stored inadress_of_instructionis sent by the pre-designed circuit to the arithmetic component to calculateadress_0 + 1i.e. the next instruction address, which is then written into the data withinadress_of_instruction.adress_0 + 1will be executed in the next circuit cycle
- The value
Other instructions might have more than two data areas (non-instruction index areas)
Instruction stream
Example [loop]
The speed of the cycle circuit is far higher than human speed (1 GHz = 10^9 cycles per second)
Loops in high-level programming languages
let i : int = 0;
while (i < 10) {
i = i + 1;
} // result = 10
let i : int = 0;
while (i < 10) {
i = i + 1;
} // result = 10
-
Fetch instruction
The
bgt(branch_grater_than) instruction is stored atadress_0. (Instructions are generated from source code and the compiler.)10is in one data area ofbgt, and the number of instructions needed for the while loop3is in another data area ofbgt -
Execute instruction
Execute condition check
Read out
iand10, compare their sizes in the arithmetic unit, give a control signal based on the result, and combine it with the control signal given by thebgtindex areaAccording to the result of the conditional judgment, perform different tasks
- When
The arithmetic unit outputs a control signal based on this judgment, changing the value stored in
adress_of_instructionto the address of the next instructionadress_0 + 1-
The instruction at
adress_0 + 1needs to perform the taskUse the
addinstruction to calculatei + 1and write it back toadress_1 -
After executing
add, go back to the judgment for the next loopThe instruction following the
addinstruction is ajumpinstruction atadress_0 + 2; its execution result is modifying the value ofadress_of_instructiontoadress_of_instruction - 2 = (adress_0 + 2) - 2 = adress_0, achieving an instruction jump to perform the next loop judgment
- When
The arithmetic unit outputs a control signal based on thisbgtjudgment, changing the value stored inadress_of_instructiontoadress_0 + 3instead ofadress_0 + 1, jumping out of the while loop to execute the subsequent instructions
[compile] [parse]
Use a parser or compiler to verify the correctness of the token stream language; essentially, it traverses all language rules and then stores them in memory as structured data (some visual descriptions: tables, nodes, trees)
One implementation method is recursive descent, enum + match (or if else) + recursion
If you want to make software run on a computer, you have to turn the token stream of the source code into structured data, and then into an instruction stream
If language rules are complex, they can be categorized and decomposed (multiple times), first traversing categories, then traversing rules within those categories. Example split into โsyntax checkโ and โsemantics checkโ
Heuristic examples of the concepts of abstraction and API (application programming interface): objects around you, you can use them conveniently without knowing their manufacturing principles, because they were designed that way
Computers, besides the advantage of high-speed periodic circuits, other advantages include memory storage capacity (1 GB = 2^(30+3) bit = 8589934592 bit) and memory persistence (power-on time)
Complex data structures and calculation functions can be constructed in memory. This might also be useful for many other fields
The motivation for variables or variable names is that humans cannot memorize and process that many addresses; variable names are intended to use semantics to assist human memory and usage, and let computers handle addresses automatically
Variables or variable names allow the values stored in memory to be reused through addresses, minimizing the memory and use of new addresses as much as possible