Frackit
A stack of fractions. To compare two numbers, divide one by the other and ask whether you got 1.
islptng · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 6 known programs · Test method
Run it
The idea
islptng made Frackit around fractions. Every value on the stack is a fraction, and the one test the language has is whether a value is exactly 1. To compare two numbers a program divides one by the other with / and * and branches on the result. Loops run forever until a - breaks out of them.
Read the story
A program that starts with a number n reads and writes in powers of n. With a 2 in front, reading 16 pushes 65536 and printing 65536 shows 16, so multiplying two inputs adds them.
The specification shows it Turing complete twice, with a tag system and with counter machines. A counter is a fraction that starts at 1, goes up by multiplying with a constant and down by dividing by it, and the test for 1 tells when it is back at zero.
The machine
| Command | Does |
|---|---|
#n | Push the whole number n |
/ | Turn the top upside down |
* | Multiply the top two |
^ | Replace the top with its denominator |
: % ! | Duplicate, swap, pop |
< > | Move the top to the bottom, or the bottom to the top |
[code] | Run code forever; - breaks out and + starts the next round |
(a|b) | Pop, then run a if it was 1 and b if not |
, . | Read a fraction or a whole number; pop one and print it |
'c | Print the character c |
Fractions stay in lowest terms, and . ends each number with a line feed. The specification links an interpreter on Try It Online. This implementation follows it where the specification leaves a detail open, and follows the specification's table where the two differ. That interpreter gives the numerator for ^ and fails on >.
Example
The truth machine branches on whether its input is 1.
The truth machine branches on whether its input is 1. On 1 it prints 1 forever.
The A+B works in base 2. Reading 3 and 5 pushes 8 and 32, their product is 256, and 256 prints as 8.
Three halves times a third is a half, and it prints as 1/2.
The interpreter takes the logarithm in floating point, so in base 10 a thousand does not quite print as 3.
The tag system runs Wikipedia's 2-tag example on the word baa, with a, b, c and H as 1 to 4. It prints nothing and stops in its sixth round, when H comes to the front of the word.
Patterns it teaches
- Stack machines: with
<and>the stack works as a queue too. - Tag systems: the proof of Turing completeness.
- Counter machines: a counter is a power of a constant.
- Turing completeness: one test, for 1, is enough.
Further
See also
Stack-based
Write your own in Run Convert a program from Frackit
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: frackit.
Command line
shib run frackit -e ''\''4'shib manual frackitSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/frackit.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org