Dbfi

From Esolang
Jump to navigation Jump to search

Dbfi is a brainfuck self-interpreter written by Daniel B. Cristofani [1] and described in detail in [2]. This is the shortest known brainfuck self-interpreter and possibly the shortest self-interpreter amongst all imperative languages. Note that a big part of dbfi code is devoted to ASCII decoding, comment handling, and avoiding undefined behaviour. Removing this would reduce the size to nearly half.

As dbfi is now licensed under Creative Commons Attribution-ShareAlike 4.0 International License, we are unable to offer the source code of it.

Dbfi inspired Clive Gifford to write the fastest Brainfuck self-interpreter (since dbfi is the shortest, but not the fastest) [3]. Its compressed version is

>>>>>+[->>++>+>+++++++[<++++>>++<-]++>>+>+>+++++[>++>++++++<<-]+>>>,<++[[>[->>
]<[>>]<<-]<[<]<+>>[>]>[<+>-[[<+>-]>]<[[[-]<]++<-[<+++++++++>[<->-]>>]>>]]<<]>[
-]+<<[--[[-]>>->+<<<]>>[-<<<<[>+<-]>>>>>>+<]<<]>>[-]<<>>>[<<<+>>>-]<<<]>>>+<<<
<[<<]>>[[<+>>+<-]+<-[-[-[-[-[-[-[->->>[>>]>>[>>]<+<[<<]<<[<<]<]>[->>[>>]>>[>>]
<,<[<<]<<[<<]]<]>[->>[>>]>>[>>]<-<[<<]<<[<<]]<]>[->>[>>]>>[>>]<.<[<<]<<[<<]]<]
>[->>[>>]>>[>>]<<-<<[<<]<<[<<]]<]>[->>[>>]>>[>>]+[<<]<<[<<]]<]>[->>[>>]>>[>>]<
[>+>>+<<<-]>[<+>-]>>[<<+>>[-]]+<<[>>-<<-]>>[<<+>>>>+<<-]>>[<<+>>-]<<[>>+<<-]+>
>[<<->>-]<<<<[-<<[<<]<<[<<]<<<<<++>>]>>[-<<<<<<[<<]<<[<<]<]>]<]>[->>[>>]>>[>>]
<[>+>>+<<<-]>[[<+>-]>>[-]+<<]>>[<<+>>>>+<<-]>>[<<+>>-]<<[>>+<<-]+>>[<<->>-]<<<
<[-<<[<<]<<[<<]<<<<<+>>]>>[-<<<<<<[<<]<<[<<]<]>]>[<+>-]<<<<<<[>>+<<-[->>->>+[>
>>[-<+>>+<]+<-[-[[-]>[-]<]>[-<<<+>>>]<]>[-<<<->>>]>[-<+>]<<<<[>>+<<-]>>]<<<<<<
]>>[-<<+[>>>[-<+>>+<]+<-[-[[-]>[-]<]>[-<<<->>>]<]>[-<<<+>>>]>[-<+>]<<<<[<<+>>-
]<<]]]>>>>>>>]

Below is relative comparison of time to run a simple program with a stack of two self-interpreters.

Lower SI Upper SI Time
cgbfi cgbfi 9.1
cgbfi dbfi 7.0
dbfi cgbfi 35.0
dbfi dbfi 21.3

Here cgbfi stands for Clive Gifford Brainfuck Interpreter. Time is given in seconds, which does not matter, because only relative values are important.

The second line shows faster result because DBFI is shorter than CGBFI, and this outweighs the speed benefit of the faster self-interpreter used in the second level in the stack of interpreters. The short program used for the comparison is

>+>+>+>+>++<[>[<+++>-]<<]> [>+>+<<-]>[-]>.!

and the interpreter bff4.c.

Dbfi also inspired people to make brainfuck interpreters in other esolangs (like StegFuck and Factor) since it is very short.