✝️ 1 Corinthians 2:7
No, we declare God’s wisdom, a mystery that has been hidden and that God destined for our glory before time began.
# NOTE
Real modern computers use numbers that wrap around, not infinite numbers!
# How is discrete math related to assembly?
Let's begin by looking at the machine's state, all of it's registers by making a little ISA, the possible states of this ISA can all be put into one set called all_possible_states, for example:
```
all_possible_states = Z x Z x Z
```
Each state would look like this:
```
(ip, reg0, reg1)
```
If you are confused about what `Z` means, it means the set of integers, so when doing `Z x Z x Z` it means we are creating a set of triples with each element being an integer.
Now, a computer needs rules to do stuff with the state, and the rules are called instructions. At it's purest form, instructions operate on the state of the machine, but how can an instruction be modeled in discrete math? An instruction can be modeled in two ways, the first way being a functions, which have one input and one output, the functions for this ISA can be defined like so:
```
FUNCTION_xchg_r0_r1: all_possible_states -> all_possible_states
FUNCTION_xchg_r0_r1(ip, reg0, reg1) = (ip + 1, reg1, reg0)
FUNCTION_mov_r0_r1: all_possible_states -> all_possible_states
FUNCTION_mov_r0_r1(ip, reg0, reg1) = (ip + 1, reg1, reg1)
FUNCTION_mov_r1_r0: all_possible_states -> all_possible_states
FUNCTION_mov_r1_r0(ip, reg0, reg1) = (ip + 1, reg0, reg0)
FUNCTION_inc_r0: all_possible_states -> all_possible_states
FUNCTION_inc_r0(ip, reg0, reg1) = (ip + 1, reg0 + 1, reg1)
FUNCTION_dec_r0: all_possible_states -> all_possible_states
FUNCTION_dec_r0(ip, reg0, reg1) = (ip + 1, reg0 - 1, reg1)
FUNCTION_inc_r1: all_possible_states -> all_possible_states
FUNCTION_inc_r1(ip, reg0, reg1) = (ip + 1, reg0, reg1 + 1)
FUNCTION_dec_r1: all_possible_states -> all_possible_states
FUNCTION_dec_r1(ip, reg0, reg1) = (ip + 1, reg0, reg1 - 1)
```
Now, we can apply the function to a certain state:
```
state0 = (0, 0, 0)
state1 = FUNCTION_inc_r0(state0)
state2 = FUNCTION_inc_r0(state1)
state3 = FUNCTION_inc_r0(state2)
state4 = FUNCTION_xchg_r0_r1(state3)
...
```
That is a way to model what a computer does with functions, sets, and triples, but notice how I said there were 2 ways to model an instruction? Let me show you relations. Functions have a rule, one input -> one output, but with relations that rule is not there... So we can have the following instruction:
```
RELATION_random_r0 ⊆ all_possible_states X all_possible_states
RELATION_random_r0 = (((ip, reg0, reg1), (ip + 1, num, reg1)) | ip ∈ Z ∧ ip + 1 ∈ Z ∧ reg0 ∈ Z ∧ reg1 ∈ Z ∧ num ∈ Z)
```
We now can have the following:
```
state0 = (0, 0, 0)
(state0, state1) ∈ RELATION_random_r0
FUNCTION_xchg_r0_r1(state1)
(state2, state3) ∈ RELATION_random_r0
```
Functions are actually relations with the rule being "one input maps to one output." So we can define a new relation as follows:
```
RELATION_inc_r0 ⊆ all_possible_states X all_possible_states
RELATION_inc_r0 = (((ip, reg0, reg1), (ip + 1, reg0 + 1, reg1)) | ip ∈ Z ∧ ip + 1 ∈ Z ∧ reg0 ∈ Z ∧ reg1 ∈ Z)
```
So we can now do:
```
state0 = (0, 0, 0)
(state0, state1) ∈ RELATION_inc_r0
```
Everything in assembly can be tied back to discrete math, state in the form of sets and instructions in the form of relations and functions. This is a toy ISA to just show how discrete math ties to assembly, real ISAs are way more complex but follow the same ideas.