A better Turing machine tape model
nickdrozd.github.io
nickdrozd.github.io
To represent the tape of a Turing Machine, you need a doubly linked list. In imperative languages, it's obvious how to implement doubly linked lists efficiently and simply, but in functional languages it's not. The author proposes using two stacks to represent a doubly linked list in a functional language: The first stack is for the part of the list to the left of the current node, and the second stack is for the part of the list to the right of the current node (including the current node). A generalisation of this idea for representing doubly-linked data structures in functional programming is called a Zipper [1].
I believe there should be an asterisk saying "in Idris". I don't believe this method removes any extra bounds checking or array-indexing at the assembly level.
I completely agree that in functional programing a dual list method makes more sense than an index into a list. I wouldn't be surprised if the compiler just optimizes better with the more functional code.
> Instead of a list, a single number can be used as a span. Implement Tape (ScanNSpan Nat). (Hint: this amounts to a sort of Gödel numbering.)
If you can restrict the `Color` to a finite set (which is necessary for any turing machine), you can just use multiplication and division which should be vastly faster than encoding based on primes.
Turning never made and never intended to make such a machine - it's a mathematical abstraction.
All calculation that could be performed on Turning's most simple machine, can also be performed by all equivalent or better machines. The point of Turing's machine is that as long as your fancy new device can model that minimal behavior, your device can be said to calculate and all conclusions about computability apply to your device.
(Edit: Added name and link to HN article)
Here's for example a stackexchange answer from 2012 using this: https://cs.stackexchange.com/questions/2832/is-a-push-down-a...
I once was working with an xml-like language and asking myself if it was turing complete. You could create scores in that language which were basically integer variables.
The trick is to then only have 0 and 1 as a valid alphabet. That meant that an integer can be represented as a stack of 0’s and 1’s. Add another integer and now you have two stacks.
You could also make a Turing Machine just by using prime numbers.