Osis
Write the rule for one term of a sequence, give the first few terms, and ask for any n.
A, 2019 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 10 known programs · Test method
Run it
The idea
The esolangs.org user A made Osis in 2019 as a cut-down Oasis, the golfing language for sequences, without its golfing shortcuts. A program is a formula and its base cases. {}+ 1 0 is the Fibonacci sequence. { pushes the previous term, } the one before it, and + adds them. The base cases come after the formula, last term first, so 1 0 says a(0) is 0 and a(1) is 1. The input is n and the output is a(n).
Read the story
The terms are worked out in order from a(0) up and kept, so no term is ever computed twice. The specification says Osis finds the 1,000th Fibonacci number in a split second, and so does this implementation.
The machine
| Command | Does |
|---|---|
0 to 9 | Push the digit |
{ } ( | Push a(n-1), a(n-2) or a(n-3) |
; | Pop t, push a(n-t) |
: | Pop t, push a(t) |
_ " | $ | Negate, double, halve or square the top |
! , | The factorial; the t-th prime, 2 being the 0th |
+ - * / % ^ | Add, subtract, multiply, divide, remainder or power, the lower item first |
A backquote pushes n itself. A term is the top of the stack when the formula ends. Without input this implementation prints the whole sequence, one term per line, until it is stopped.
The command table calls the top item a and computes a-b. Its own period programs only come out the other way round, with the item below the top first, and this implementation follows the programs.
Example
The factorial multiplies n by the previous term, starting from a(0) = 1.
The factorial multiplies n by the previous term, starting from a(0) = 1. Powers of 2 double the previous term.
The period [1,3] pushes 2 and -1, raises -1 to the power n and takes that from 2. The period [1,2] adds 1 to n modulo 2.
Further
Ideas it shows
See also
Functional paradigm
Write your own in Run Convert a program from Osis
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: osis.
Command line
shib run osis -e '{" 1' --input '10'shib manual osisSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/osis.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org