Random Access Machine implemented in python.
Project description
random-access-machine
Random Access Machine implemented in python.
RAM is an abstract machine that is turing complete and can compute any partial recursive function. Find out more here https://en.wikipedia.org/wiki/Random-access_machine
Install
Run inside terminal:
python -m pip install random-access-machine
Usage
To execute a ram source file:
python -m ram <ram source file> <integer input>
To import it in your script:
from ram import RAM
data = 4
program = 'inc 0'
ram = RAM()
result = ram.compute(program, data)
print(result) # 1
How it works
A ram machine has infinite registers numbered from 0, 1, 2..., the input is loaded on register 1 before the execution starts, the output is taken from register 0 when the execution ends.
Instructions:
A ram machine supports only 3 basic instructions:
Increment register k by 1:
inc k
Decrement register k by 1:
dec k
Jump to instruction i if register k is zero:
jz k i
Example
An example program that will double whatever input you give to the machine:
jz 1 6
inc 0
inc 0
dec 1
jz 2 1
dec 1
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for random-access-machine-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1159584793fd8d213161c434520c65e293d4267c36beb34ecbb4ed2a2d0872c |
|
MD5 | 96b0b92cc51dc8daa7e7252bdbf8f472 |
|
BLAKE2b-256 | 0fdcea681b67c300b188c7bff2cac08b325bff3cd9f356356dc77f17258662c4 |
Hashes for random_access_machine-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e5a5cf7dbee9e81b49dd4c326bcc04d197f9662d3a518b182a0772e19d4d015 |
|
MD5 | 729cce77c5a5ba65c7fdd1f31b08b2a0 |
|
BLAKE2b-256 | e44ec65bade6d2c562b0a589ca50206cca8970e66c04f5d2cbfd2091e10cd1af |