yup
The only number you can write is 0. Everything else comes from e to the power, the natural logarithm and subtraction.
Conor O'Brien · Turing complete: unknown · ●●● hard
Tested with 5 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
yup is a stack language by Conor O'Brien where the digits 1 to 9 do not exist. 0 pushes zero, e turns the top x into e^x and | turns it into ln x. So 0e is 1, 00e- is 0 minus 1, and 0e00e-- is 1 minus minus 1, which is 2. Every other number is built from these three moves.
Read the story
The numbers are exact enough to make this work. The reference interpreter keeps them as math.js BigNumbers with 100 significant digits, so e^(ln 72) comes back as 71 and a point followed by 98 nines, and printing it as a character rounds it to 72, an H.
The logarithm of a negative number does not stop the program. math.js turns it into a complex number, so ln(-1) is iπ and e^(iπ) is -1 again. TIO's Hello World leans on this, and @ prints the real part.
The machine
One stack. A program is a string of single characters; anything else, spaces included, does nothing.
| Char | Does |
|---|---|
0 | Push 0 |
e \| | Replace the top x with e^x or ln x |
- | Pop b and a, push a minus b |
: ~ $ | Duplicate, swap, reverse the stack |
] [ | Move the top to the bottom, or the bottom to the top |
@ | Pop and print the character with that code, rounded |
# | Pop and print the number, rounded to 16 decimal places |
* | Push the code of the next input character, 0 at the end |
{ } | Loop while the top is positive |
\ | Stop |
A backquote starts a comment that runs to the end of the line. Input comes from the reference's -s flag, which hands the program the codes of a string, first character first.
Example
The first program makes 2 and prints ln 2.
The first program makes 2 and prints ln 2. The second makes 3 as 1 minus (0 minus 1 minus 1), then prints and lowers it until it is no longer positive. The third copies three input characters.
Patterns it teaches
- Turing tarpit: fourteen commands, and only one way to write a number.
- Stack machines: every value lives on the one stack.
- Encoding tricks: a character code is a chain of exponentials and logarithms that lands near an integer.
Further
- The reference interpreter, in JavaScript with math.js
See also
Also in Turing tarpits
Write your own in Run Convert a program from yup
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: yup.
Command line
shib run yup -e '*@*@*@' --input 'yup'shib manual yupSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/yup.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language