esolang

bitch

One accumulator and only bitwise operations. Even adding two numbers is a loop of XOR, AND and shifts.

Helen, 2019 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 4 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: Hi

The idea

Helen made bitch in 2019, after Arphimigon's BITCHWISE. There is one place to keep a value, the accumulator, and the only arithmetic is AND, OR, XOR, NOT and shifts. There is no +. The addition program repeats "XOR for the sum bits, AND and shift left for the carries" until the carry is 0.

Read the story

Two ideas make that possible. First, the bits that a right shift pushes out are not lost. They go onto a storage of bits, and a left shift pulls them back in, so the storage works as a stack. Second, an argument can be a whole instruction. ^]32 XORs the accumulator with itself shifted right by 32, worked out on a copy, so a value can meet a shifted version of itself without a second register.

The machine

An accumulator holding an integer without bounds, and a storage of bits.

InstructionDoes
#nSet the accumulator to n, empty the storage
&n \|n ^nAND, OR, XOR with n
~NOT
]nShift right by n; the lost bits go on top of the storage
[nShift left by n, filling from the top of the storage
\Read into the accumulator, empty the storage
/Print the accumulator
> <Mark a place, jump back to the last mark
: ;Run the next instruction only if the accumulator is 0, or only if it is not
.End the program

Any n can be a number or an instruction, which runs on a copy. The spec reads and prints numbers; TIO runs all three interpreters with characters instead, and so does this implementation.

Example

The second is the addition program.
Expected: B

The second is the addition program. It reads ! (33) and parks it in the storage with ]32, then ORs in the second !. Inside the loop the two halves of the accumulator are combined into sum bits and carry bits until no carry is left. 33 + 33 is 66, B.

Patterns it teaches

  • Turing tarpit: a stack of bits and a loop are enough for a Turing machine, which the specification builds.
  • Encoding tricks: two numbers live in one accumulator, in its upper and lower 32 bits.

Further

Also in Turing tarpits

Write your own in Run Convert a program from bitch

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: bitch.

Command line

shib run bitch -e '#65]3[3/'
shib manual bitch

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/bitch.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org