Search code examples
javaarithmetic-expressionscellular-automata

Evaluation of arithmetic expressions with a cellular automaton


Stephen Wolfram talked about this thing called cellular automaton. The idea was building what are seemingly complex systems from simple rules and starting configurations. Some examples such as Milton Bradley's game of life are demonstrated in this video.

Now I've heard up the grapevine that through the use of computer science arithmetic expressions can be modeled and solved. So for my final APCS project i want to take a given expression using +, -, *, or /, and model it with a cellular automaton. If anyone has resources that you could point me to or some ideas on how to approach this that would be greatly appreciated.


Solution

  • The name of the topic you chose is evaluation of arithmetic expressions, of which plenty of examples can be found, here they're discussing it.

    A cellular automation with Rule 110 (see also this) is said to be Turing-complete in the sense that it can simulate a Turing machine, sort of minimal model of a computer.

    So you'd need to find or write a compiler to a Turing machine, which translates arithmetic expressions to instructions, which the Turing machine can understand. Here they're discussing such stuff, citing an existing expressions-to-turing-machine-instructions compiler written in ruby.

    Creating a parser for an expression langage isn't that hard really (its the hello-world example in the parser world), you could use Antlr, where you'll find complete examples, or rely on existing Java implementations.

    The remaining part is an implementation of a Turing machine leveraging rule 110, which is able to execute the compiled code.

    One would also have to tell the Turing machine how to add, subtract and so on, it can't do that by default. Here they're discussing addition, with links to subtraction and multiplication.

    After some more research it turned out, that there is an existing Java implementation simulating a Turing machine in Conway's game of life, with some sample Turing-machine code by Paul Rendell running on it.

    Also there is a universal Turing machine (one, that can simulate any other Turing machine) running in game of life mentioned by Rendell (als see this) and, eventually, even an 8-bit computer by Nicolas Loizeau running in game of life (resources on Github). If you'd use the latter, you'd have to compile to its instruction set, which may be way less uncomfortable than a plain Turing machine. Here's the code for the fibonacci numbers in that form:

    write a 1
    write b 1
    add a b a
    print a
    add a b b
    print b
    goto 2