Arbitrary memory emulation
(Redirected from User:Aadenboy/Single value arbitrary memory emulation)
Note: This assumes that numbers are integers that aren't bound to a maximum and can have infinite precision up to infinity.
General idea
Given access to a single number, arbitrary memory is able to be properly emulated given simple algorithms. The idea is that:
- Each memory slot never exceeds some given "byte" value, like 255. In more regular terms, a byte of memory is at most 255.
- Unlike traditional memory, this byte size can be any arbitrary number, like 10, given the math is handled correctly. We'll call this value .
- The position of any byte where is its index in memory (starting at 0), its position as a number will be .
- For any byte's value , it's actual value will be . For example, if
v
was 5, was 8 and was 5, byte 5's contribution to the number (or it's actual value) will be , or 163840.
- For any byte's value , it's actual value will be . For example, if
- Every byte of memory is always higher than the previous one, and conversely every byte of memory is always below the previous one.
- More generally, for any given byte, and their indexes and , the position of byte will always be
For example, we'll use a byte size of 2 and memory of [1, 1, 0, 1, 0, 0, 0, 1].
- Start with a total of 0.
- Go through each value in memory and add to the total, where is the value and is the index.
- Our memory is encoded as 139.
As a second example: with a byte size of 10 and memory of [9, 5, 1, 2, 4, 3, 8], our memory (or total) is 2097673.
Reading and writing
Reading and writing from memory can be done through simple algorithms.
Any memory byte can be read through the algorithm , where is the memory as the total from earlier, is the byte size, and is the index.
Any memory byte can be written to through the algorithm , where is the value to set to.