Floor
Arithmetic on exact fractions, and floor as the only way to decide anything.
2023 · Turing complete: no · ●●○ moderate · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
Floor is from 2023. A program is a list of functions, and each one is a single arithmetic expression over its arguments. There are no conditions, no loops and no recursion. A function may call only the functions above it, so every program ends.
Read the story
The one way to branch is floor. It gives 0 for a number between 0 and 1, but -1 for a number between -1 and 0. From that asymmetry the specification builds tests for zero, for sign and for less than, and then an if that multiplies by those tests. Repetition comes from ^ on a function, which applies it a number of times.
The machine
| Write | Means |
|---|---|
name: a b -> expr | Define a function of a and b |
+ - * / | Exact arithmetic on fractions |
x^n x² | A power; the exponent is rounded down |
floor x | The largest whole number not above x |
g^n x y | Apply g to x n times, passing y to each call |
# ... | A comment line |
The program runs f on the numbers of the input and prints what it returns. Brackets bind first, then ^, then signs, then * and /, then + and -. A function takes the operands right after it, so floor x + 1/2 is (floor x)+(1/2). Dividing by 0 gives 0, but 0/0 and 0^0 give 1.
The specification's interpreter can also show the result as text, its bytes taken from the lowest up. That is the mode string, and in it the Hello World prints Hello, World!.
Example
The first is the Hello World, printed as the number it is.
The first is the Hello World, printed as the number it is. The second is the multiplication by repeated adding, with an f to call it. The third shows the rules for 0.
The minimum picks with floor. lt x y is 1 when x is below y and 0 otherwise, and if adds x times the test to y times one minus the test.
The Fibonacci program keeps two numbers in one fraction, x + 1/y, and steps it with ^. fib 0 and fib 1 are both 1, so fib 20 is 10,946.
Further
See also
Functional paradigm
Write your own in Run Convert a program from Floor
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: floor.
Command line
shib run floor -e 'f: -> 2645608968345021733469237830984'shib manual floorSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/floor.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org