|
| 1 | + |
| 2 | +# Introduction |
| 3 | + |
| 4 | +Brainfuck is the most famous esoteric programming language ever made. It's an esoteric language, so it was not meant to be used |
| 5 | +in solving real-world problems (but, no one forbids You too!). The language can't be classified clearly. Partly it's a very high-level language - Brainfuck doesn't bind itself to any architecture making it very portable language. On the other hand, it's very |
| 6 | +low-level language - it supports only addition and subtraction, basic control structure (`while`-like loop), basic I/O (terminal |
| 7 | +only, shrinking capabilities to the absolute minimum), and indefinitely long tape where any byte can be stored arbitrarily. Brainfuck |
| 8 | +is Turing complete, meaning that it is in the same computational class as universal Turing machines. This, plus its amount of |
| 9 | +instructions, makes it a most popular example of a Turing tarpit. This can be proven in many ways, with various restrictions on |
| 10 | +the brainfuck program or interpreter. |
| 11 | + |
| 12 | +Daniel Cristofani wrote universal Turing machine emulator in Brainfuck which is so small we can quote it here: |
| 13 | + |
| 14 | +```bf |
| 15 | ++++>++>>>+[>>,[>+++++<[[->]<<]<[>]>]>-[<<+++++>>-[<<---->>-[->]<]]<[<-<[<]+<+[>]<<+>->>>]<]<[< |
| 16 | +]>[-[>++++++<-]>[<+>-]+<<<+++>+>[-[<<+>->-[<<[-]>>-[<<++>+>-[<<-->->>+++<-[<<+>+>>--<-[<<->->- |
| 17 | +[<<++++>+>>+<-[>-<-[<<->->-[<<->>-[<<+++>>>-<-[<<---->>>++<-[<<++>>>+<-[>[-]<-[<<->>>+++<-[<<- |
| 18 | +>>>--<-[<<++++>+>>+<-[<<[-]>->>++<-[<<+++++>+>>--<-[<->>++<[<<->>-]]]]]]]]]]]]]]]]]]]]]]<[->>[ |
| 19 | +<<+>>-]<<<[>>>+<<<-]<[>>>+<<<-]]>>]>[-[---[-<]]>]>[+++[<+++++>--]>]+<++[[>+++++<-]<]>>[-.>] |
| 20 | +``` |
| 21 | + |
| 22 | +Simulation is one way to prove Turing completeness: |
| 23 | + |
| 24 | + > If an interpreter for A can be implemented in B, then B can solve at least as many problems as A can. |
| 25 | +
|
| 26 | +There are some difficulties with this way of proving Turing completeness (ℒ), but for Brainfuck, it's entirely sufficient. By theory, |
| 27 | +it's ℒ-complete too, so the proof is fully valid. |
| 28 | + |
| 29 | +Brainfuck is an amazing language. One must still understand where it would be suitable, and where it doesn't particularly excel |
| 30 | +at. |
0 commit comments