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
Its more advanced brother is called While Machine and you can find its implementation here https://github.com/GabrieleMaurina/while-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
Compile While
It is possible to compile a While program into a Ram program using the method compile_ram of the class WhileMachine. You can find an implementation of the while machine here https://github.com/GabrieleMaurina/while-machine
Metadata
Release files for random-access-machine 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| random-access-machine-1.0.1.tar.gz | 2.7 kB | Without provenance | Details for random-access-machine-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| random_access_machine-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for random_access_machine-1.0.1-py3-none-any.whl |
Total release size: 5.4 kB
Release files / random-access-machine-1.0.1.tar.gz
| Download URL | random-access-machine-1.0.1.tar.gz |
|---|---|
| Size | 2.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f4282b706a253b4e02ba6792aa71eaafc59411cb22dea72d34a2b96d3f5781f5
|
|
BLAKE2b-256 checksum How to use checksums |
f39910ee88dd4352b2773d76c5f899ce528939d4aa32e1851cb12e5b94ec546e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.7
|
Release files / random_access_machine-1.0.1-py3-none-any.whl
| Download URL | random_access_machine-1.0.1-py3-none-any.whl |
|---|---|
| Size | 2.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7a6cc3d951f3c88d1e7cc2333e5f79bad0e14d623a02121238c247f4ba2c3c65
|
|
BLAKE2b-256 checksum How to use checksums |
ae2aef9266165bf669ec511980abd1df272a4e4893a39f81b746f1e3559af3a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.7
|
Security for random-access-machine 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.