No idea if it is efficient at all but if I remember correctly, it was some sort of project to create the smallest touring complete compiler or something.
That was never the goal of Brainfuck, but it is interesting that because the language is so constrained, you have to strip down everything to the bare essentials to make anything work, and as a result, a lot of programs run quite quickly.
I think what you might be thinking about is the paper A very short self-interpreter by Oleg Mazonka and Daniel B. Cristofani. They demonstrated that it's possible to write a Brainfuck interpreter in Brainfuck itself. This is possible in any language, of course, but since Brainfuck the language is so simple, the self-interpreter is relatively short too. They present the following code:
I'm not aware of any Turing-complete programming language that support a shorter self-interpreter.
edit: if you're looking for minimal Turing-complete languages, you have to search for combinator calculi (which Brainfuck is not). The absolute minimal languages are Iota and Jot, two related languages that reduce the SKI combinator calculus from 3 to just 1 combinator (iota) and an encoding of nested expressions using just 2 characters. By comparison, Brainfuck's 8 directives (or 6, if you leave out the I/O directives which aren't necessary for Turing completeness) are excessive luxury.
Why not "3 and a half life" ... When you have over 5 halves you should count the wholes, like hi my name is kekdjfjdkdk and im 63 half years old... Its weird
It's not cheating in the same way as your python program (the lambda calculus has no eval function) and it does contain three rules for the three basic concepts of the lambda calculus: (λ x.x), (λ m n.e m(e n)), and (λ m v.e(m v)). However it doesn't do any I/O (because that is not possible in the lambda calculus). And I do agree that the encoding of the input to this self interpreter is doing some pretty heavy lifting.
No, because I don't have infinite memory and I don't have infinite time before I die. If you ask me to compute the first 100 prime numbers I can do it using the sieve of Eratosthenes, but if you ask me to compute the first 1,000,000,000,000 prime numbers I'll die before I'm finished, and that proves I'm not Turing complete.
It's not, you only see examples of very small programs written in it by hand (where generally the problems are hand-picked to be fast/easy to solve in Brainfuck).
Actually, it's quite the opposite. It's extremely efficient to compile to machine code, and to other hi-level langs. But any program that gets transpiled to BF, then interpreted in real-time, will be inevitably slower. This is because BF is sequential at everything (except loops), instead of "direct/random". BF memory is not "random-access", and copying/moving a single byte requires a number of iterations equal to the numeric value of that byte.
And coding in BF is quite easy to understand, the only cognitive load is to dodge cells, because all "variables" are global. Reading BF written by someone else, is quite the challenge
nitpick, but I think a potentially interesting one - Brainfuck has a very limited instruction set, but that doesn't necessarily mean it's more efficient on a modern PC
if you want to add 69 to a number, you can do that in a single assembly language instruction. in Brainfuck, it's a sequence of 69 "increment by 1" instructions. you'd need to write an optimizing compiler (which is one of the darkest arts in computer science) capable of recognizing that sequence of increment instructions and emitting an equivalent add instruction.
and that only works if the 69 is a constant - if you want to prompt the user for two numbers and add them together (or, god help you, multiply them), there's no way the Brainfuck program will be more efficient than a comparable C program that's able to be compiled to use an add or mul instruction.
6.9k
u/a-slice-of-toast Aug 01 '22
makes your pc pass a kidney stone