Skip to content

Algorithm for running Turing Machines in reverse (written in Scala)

License

Notifications You must be signed in to change notification settings

ljwagerfield/reverse-turing-machine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reverse Turing Machine

Algorithm for running Turing Machines in reverse (to generate inputs rather than interpret them).

Traditionally, Turing Machines are run forwards: you start at an initial state (e.g. start) with a full tape. The tape is then consumed until a final state is reached (e.g. valid/invalid), at which point you have your result.

Running in reverse means the opposite: you start at a final state (e.g. valid) with an empty tape. The tape is then populated until an initial state is reached (e.g. start), at which point execution stops, and you have your input.

Why do this? To automatically derive input generators from predicates (has applications in testing frameworks).

Exploring the repository

This repository is written in Scala (using Cats).

Note: these algorithms have been optimised, so forgive the occasional bit of non-FP code!

Getting started

The scalacheck tests assert the set of inputs generated by our algorithm match the set of inputs generated by a hand-written generator for all 3 example predicates in the test suite.

sbt test

Using the algorithm is simple:

  1. Write a turing machine (Machine[S, I, O]) -- this is the tedious part.

  2. Call machine.generate() to generate a sequence of inputs.

  3. Done!

License

This software is licensed under the MIT license.

About

Algorithm for running Turing Machines in reverse (written in Scala)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages