ArticleslgStudy

science

Malbolge

Malbolge is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Malbolge rather than just read about it. In short: Malbolge () is a public-domain esoteric programming language invented by Ben Olmstead in 1998, named after the eighth circle of hell in Dante's Inferno, the Malebolge. It was specifically designed to be almost impossible to use, via a counter-intuitive "crazy operation", base-three arithmetic, and self-altering code.

Malbolge — main illustration
Malbolge — illustration

Key takeaways

  • Malbolge belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Malbolge to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Malbolge from memory before moving on to harder problems.

Reference excerpt

Malbolge () is a public-domain esoteric programming language invented by Ben Olmstead in 1998, named after the eighth circle of hell in Dante's Inferno, the Malebolge. It was specifically designed to be almost impossible to use, via a counter-intuitive "crazy operation", base-three arithmetic, and self-altering code. It builds on the difficulty of earlier challenging esoteric languages (such as Brainfuck and Befunge) but exaggerates this aspect to an extreme degree, playing on the entangled histories of computer science and encryption. Despite this design, it is possible to write useful Malbolge programs.

Programming in Malbolge Malbolge was very difficult to understand when it arrived, taking two years for the first Malbolge program to appear. The author himself has never written a Malbolge program. The first program was not written by a human being; it was generated by a beam search algorithm designed by Andrew Cooke and implemented in Lisp. Later, Lou Scheffer posted a cryptanalysis of Malbolge and provided a program to copy its input to its output. He also saved the original interpreter and specification after the original site stopped functioning and offered a general strategy of writing programs in Malbolge as well as some thoughts on its Turing completeness. Olmstead believed Malbolge to be a linear bounded automaton. There is a discussion about whether one can implement sensible loops in Malbolge—it took many years before the first non-terminating one was introduced. A correct 99 Bottles of Beer program, which deals with non-trivial loops and conditions, was not announced for seven years; the first correct one was by Hisashi Iizawa in 2005. Hisashi Iizawa et al. also proposed a guide for programming in Malbolge for the purpose of obfuscation for software protection. In 2020, Kamila Szewczyk published a Lisp interpreter written in Malbolge Unshackled.

Example programs

Hello, World! This program displays "Hello, World!".

(=<`#9]~6ZY327Uv4-QsqpMn&+Ij"'E%e{Ab~w=_:]Kw%o44Uqp0/Q?xNvL:`H%c#DD2^WV>gY;dts76qKJImZkj

cat program This program reads a string from a user and prints that string, similar to the Unix command-line utility cat.(=BA#9"=<;:3y7x54-21q/p-,+*)"!h%B0/. ~P< <:(8& 66#"!~}|{zyxwvu gJ%

Design Malbolge is machine language for a ternary virtual machine, the Malbolge interpreter. The standard interpreter and the official specification do not match perfectly. One difference is that the compiler stops execution with data outside the 33–126 range. Although this was initially considered a bug in the compiler, Ben Olmstead stated that it was intended and there was in fact "a bug in the specification".

Registers Malbolge has three registers, a, c, and d. When a program starts, the value of all three registers is zero. a stands for "accumulator", set to the value written by all write operations on memory and used for standard I/O. c, the code pointer, is special: it points to the current instruction. d is the data pointer. It is automatically incremented after each instruction, but the location it points to is used for the data manipulation commands.

Pointer notation d can hold a memory address; [d] is register indirect; the value stored at that address. [c] is similar.

Memory The virtual machine has 59,049 (310) memory locations that can each hold a ten-trit ternary number. Each memory location has an address from 0 to 59048 and can hold a value from 0 to 59048. Incrementing past this limit wraps back to zero. The language uses the same memory space for both data and instructions. This was influenced by how hardware such as x86 architecture worked. Before a Malbolge program starts, the first part of memory is filled with the program. All whitespace in the program is ignored and, to make programming more difficult, everything else in the program must start out as one of the instructions below. The rest of memory is filled by using the crazy operation (see below) on the previous two addresses ([m] = crz [m - 2], [m - 1]). Memory filled this way will repeat every twelve addresses (the individual ternary digits will repeat every three or four addresses, so a group of ternary digits is guaranteed to repeat every twelve). Note that the official specification does not cover the edge case of one-instruction programs, where trying to fill the second memory position using the crazy operation, as indicated before, will result in [m - 2] pointing outside the program's memory region. The reference implementation does not explicitly consider this case either and incurs in undefined behavior. In 2007, Ørjan Johansen created Malbolge Unshackled, a version of Malbolge which does not have the arbitrary memory limit. The hope was to create a Turing-complete language while keeping as much in the spirit of Malbolge as possible. No other rules are changed, and all Malbolge programs that do not reach the memory limit are still completely functional.

Instructions Malbolge has eight instructions. Malbolge figures out which instruction to execute by taking the value [c], adding the value of c to it, and taking the remainder when this is divided by 94. The final result tells the interpreter what to do:

After each instruction is executed, it gets encrypted (see below) so that it will not do the same thing next time, unless a jump just happened. Right after a jump, Malbolge will encrypt the instruction just prior to the one it jumped to instead. Then, the values of both c and d are increased by one and the next instruction is executed.

Crazy operation For each ternary digit of both inputs, use the following table to get a ternary digit of the result. For example, crz 0001112220, 0120120120 gives 1120020211.

Encipherment After an instruction is executed, the value at [c] (without anything added to it) will be replaced with itself mod 94. Then, the result is enciphered with one of the following two equivalent methods.

Method 1 Find the result below. Store the ASCII code of the character below it at [c].

Method 2 Find the result below. Store the encrypted version at [c].

Lou Scheffer's cryptanalysis of Malbolge mentions six different cycles in the permutation. They are listed here:

… excerpt ends here. Continue reading the full article.

Illustrations

Malbolge illustration

Worked examples

Example 1 — a first encounter with Malbolge

Start with the simplest possible case. Write down what Malbolge claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Malbolge before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Malbolge ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Malbolge

In research
Malbolge appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Malbolge in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Malbolge is common in secondary-school and first-year university syllabi. It links to neighbouring topics Esoteric programming languages, Non-English-based programming languages, Programming languages created in 1998, so understanding it makes those chapters shorter.
In everyday life
Look for Malbolge outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Malbolge” →

How to study Malbolge in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Malbolge means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Malbolge out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Malbolge in simple terms?

Malbolge () is a public-domain esoteric programming language invented by Ben Olmstead in 1998, named after the eighth circle of hell in Dante's Inferno, the Malebolge. It was specifically designed to be almost impossible to use, via a counter-intuitive "crazy operation", base-three arithmetic, and…

Why does Malbolge matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Malbolge?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Malbolge.

Tags

  • Esoteric programming languages
  • Non-English-based programming languages
  • Programming languages created in 1998

Keep exploring