GithubHelp home page GithubHelp logo

oelin / urm Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 9 KB

Unlimited register machine implementation in Python.

License: MIT License

Python 100.00%
assembly-language computational-model programming-language theoretical-computer-science theory-of-computation unlimited-register-machine

urm's Introduction

URM

An unlimited register machine implementation in Python.

Introduction

An unlimited register machine (URM) is a Turing-complete model of computation which resembles a rudimentary assembly language. It's often used in theoretical computer science during proofs as a stand-in for Turing machines due to it's more familiar syntax. The code below implements a URM program which computes r2 = r0 + r1 where r0, r1 and r2 are the first, second and third registers respectively. In total there are an unlimited number of registers to select from (hence the name).

# r2 = r0 + r1

m 0 2
z 3
s 2
s 3
j 3 1 6
j 0 0 2
x

Instruction Set

This implementation supports just four simple instructions. These instructions are sufficient for Turing completeness.

Zero

Sets the value of register n to zero.

z <n> 

Successor

Increments the value of register n by 1.

s <n>

Move

Copies the value of register n into register m.

m <n> <m>

Jump

Branches execution to instruction i if the value of register n equals the value of register m.

j <n> <m> <i>

API

URM exposes a simple interface for executing URM programs; namely through the UnlimitedRegisterMachine.execute() method.

from urm import UnlimitedRegisterMachine

i, registers = UnlimitedRegisterMachine.execute(<register map>, <code>)

This method takes in a register map and source code string, and returns a new register map as well as the instruction index at which the program terminated. Here's an example using the addition program shown in the introduction.

from urm import UnlimitedRegisterMachine

addition = '''m 0 2
z 3
s 2
s 3
j 3 1 6
j 0 0 2
x'''

x = 1
y = 2

_, registers = UnlimitedRegisterMachine.execute({ 0: x, 1: y }, addition)
z = registers[2]

print(f'{x} + {y} = {z}')

Conclusion

URMs are useful constructions for theoretical computer scientists. This Python package aims to make them more concrete for research or fun.

urm's People

Contributors

oelin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.