{ "info": { "author": "Dmitrijs Milajevs", "author_email": "dimazest@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Intended Audience :: Education", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": "====================================\nTuring Machine as a Python Generator\n====================================\n\n.. image:: https://travis-ci.org/dimazest/turing_machine.svg?branch=master\n :target: https://travis-ci.org/dimazest/turing_machine\n\nThis is a simulator of a Turing machine with a singly-infinite tape. The\nsimulator allows one to execute a machine step-by step, check whether a machine\naccepts or rejects a particular input and see it's execution.\n\n.. contents::\n\nInstallation\n============\n\nThere are several ways of getting the simulator.\n\n* **PyPi**: great if you want to use the package as part of your\n application::\n\n pip install turing_machine\n\n* **git**: if you want to get all the files, most importantly `the notebook`_::\n\n git clone https://github.com/dimazest/turing_machine.git\n\n* **github**: if you don't bother using git::\n\n wget https://github.com/dimazest/turing_machine/archive/master.zip\n\nUsing the simulator in the IPython notebook\n===========================================\n\n`The notebook`_ (``Turing machine.ipynb``) is a great way to run the machine\ninteractively. You need to have a fresh version of IPython installed (>=3.0).\nCheck out `these IPython installation instructions using miniconda`__ if you\ndon't have it installed yet.\n\n__ http://eecs.io/python-environment-for-scientific-computing.html\n\n.. _`the notebook`: http://nbviewer.ipython.org/github/dimazest/turing_machine/blob/master/Turing%20machine.ipynb\n\nUsing the simulator inside of a Python script\n=============================================\n\nIf you dont want to be bother with IPython, you can use the simulator inside of\nyour own script, see ``w_hash_w.py``, for example::\n\n python w_hash_w.py\n q0 [1]0#10\n FindDelimiter1 X[0]#10\n FindDelimiter1 X0[#]10\n\n ... MANY OTHER CONFIGURATIONS ...\n\n qa XX#XX[]\n\nThe API\n=======\n\nThe package provides the ```TuringMachine`` class which is instantiated with\nparticular transitions. Once a Turing Machine is instantiated it can be\nexecuted. Here is an example of a machine that accepts language `w#w` (two\nidentical words separated by ``#``).\n\n>>> from turing_machine import TuringMachine\n\n\n>>> w_hash_w = TuringMachine(\n... {\n... ('q0', '#'): ('End', '#', 'R'),\n... ('End', ''): ('qa', '', 'R'),\n...\n... ('q0', '0'): ('FindDelimiter0', 'X', 'R'),\n... ('FindDelimiter0', '#'): ('Check0', '#', 'R'),\n... ('Check0', '0'): ('FindLeftmost', 'X', 'L'),\n...\n... ('q0', '1'): ('FindDelimiter1', 'X', 'R'),\n... ('FindDelimiter1', '#'): ('Check1', '#', 'R'),\n... ('Check1', '1'): ('FindLeftmost', 'X', 'L'),\n...\n... ('FindLeftmost', '0'): ('FindLeftmost', '0', 'L'),\n... ('FindLeftmost', '1'): ('FindLeftmost', '1', 'L'),\n... ('FindLeftmost', 'X'): ('FindLeftmost', 'X', 'L'),\n... ('FindLeftmost', '#'): ('FindLeftmost', '#', 'L'),\n... ('FindLeftmost', ''): ('FindNext', '', 'R'),\n...\n... ('FindNext', 'X'): ('FindNext', 'X', 'R'),\n... ('FindNext', '0'): ('FindDelimiter0', 'X', 'R'),\n... ('FindNext', '1'): ('FindDelimiter1', 'X', 'R'),\n... ('FindNext', '#'): ('End', '#', 'R'),\n...\n... ('FindDelimiter0', '0'): ('FindDelimiter0', '0', 'R'),\n... ('FindDelimiter0', '1'): ('FindDelimiter0', '1', 'R'),\n... ('FindDelimiter1', '0'): ('FindDelimiter1', '0', 'R'),\n... ('FindDelimiter1', '1'): ('FindDelimiter1', '1', 'R'),\n...\n... ('Check0', 'X'): ('Check0', 'X', 'R'),\n... ('Check1', 'X'): ('Check1', 'X', 'R'),\n...\n... ('End', 'X'): ('End', 'X', 'R'),\n... }\n... )\n\nInput acceptance\n----------------\n\nOnce we got a machine, we can check whether it accepts a particular string:\n\n>>> w_hash_w.accepts('#')\nTrue\n>>> w_hash_w.accepts('1#1')\nTrue\n>>> w_hash_w.accepts('1#10')\nFalse\n\nor rejects:\n\n>>> w_hash_w.rejects('##')\nTrue\n>>> w_hash_w.rejects('#')\nFalse\n\nStep by step execution\n----------------------\n\nThe ``.run()`` method returns a generator that executes the machine and yields\nthe configuration together with he acceptance decision:\n\n>>> execution = w_hash_w.run('1#1')\n>>> action, context = next(execution)\n>>> context['state']\n'q0'\n\nInfinite execution\n------------------\n\nBecause execution is done in a generator, it's possible to have infinite\nexecutions but the acceptance checks are limited by the number of steps they are\nallowed to perform.\n\n>>> go_right = TuringMachine(\n... {\n... ('q0', ''): ('q0', '', 'R'),\n... }\n... )\n\nIf the step limit is reached, ``None`` is returned:\n\n>>> go_right.accepts('') is None\nTrue\n\nDo 2000 steps:\n\n>>> go_right.accepts('', step_limit=2000) is None\nTrue\n\nDebugging\n---------\n\nAnother nice feature is the ability to debug the machine by observing it's\nconfiguration.\n\n\n>>> w_hash_w.debug('1#1')\nq0 [1]#1\nFindDelimiter1 X[#]1\nCheck1 X#[1]\nFindLeftmost X[#]X\nFindLeftmost [X]#X\nFindLeftmost []X#X\nFindNext [X]#X\nFindNext X[#]X\nEnd X#[X]\nEnd X#X[]\nqa X#X[]", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/dimazest/turing_machine", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "turing_machine", "package_url": "https://pypi.org/project/turing_machine/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/turing_machine/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/dimazest/turing_machine" }, "release_url": "https://pypi.org/project/turing_machine/1.0/", "requires_dist": null, "requires_python": null, "summary": "Turing Machine as a Python Generator.", "version": "1.0" }, "last_serial": 1457288, "releases": { "0.1": [], "1.0": [ { "comment_text": "", "digests": { "md5": "514a5130d7a2f101e56d38d44840a1f4", "sha256": "d54699a5ca6eb7c94c24f73f60417c7348942523de38035b68732b45fbb37d90" }, "downloads": -1, "filename": "turing_machine-1.0.tar.gz", "has_sig": false, "md5_digest": "514a5130d7a2f101e56d38d44840a1f4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6121, "upload_time": "2015-03-11T12:58:50", "url": "https://files.pythonhosted.org/packages/b2/5e/2ec2c97a5d8136f9da5bc2f939ed8e41f9c8082044abd4fe9144646459b0/turing_machine-1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "514a5130d7a2f101e56d38d44840a1f4", "sha256": "d54699a5ca6eb7c94c24f73f60417c7348942523de38035b68732b45fbb37d90" }, "downloads": -1, "filename": "turing_machine-1.0.tar.gz", "has_sig": false, "md5_digest": "514a5130d7a2f101e56d38d44840a1f4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6121, "upload_time": "2015-03-11T12:58:50", "url": "https://files.pythonhosted.org/packages/b2/5e/2ec2c97a5d8136f9da5bc2f939ed8e41f9c8082044abd4fe9144646459b0/turing_machine-1.0.tar.gz" } ] }