esolang

Math++

Every line is a formula. Its result is printed, stored, or used as the number of the next line.

SuperJedi224, 2015 · Turing complete: yes · ●○○ easy · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: 0.0

The idea

SuperJedi224 made Math++ in 2015 and defined it by a Java implementation. Every value is a 64-bit double. There are 26 variables named a to z and one map from numbers to numbers. A program is lines, each an expression with an optional target after a >.

Read the story

There is no if and no while. A line whose target is $ jumps to the line its value names, so the conditions are written as arithmetic. !x is 1 when x is 0, which turns a test into a line number.

The machine

TargetDoes
out or nonePrint the value
a to zStore it in that variable
{key}Store it in the map under key
$Go to that line, cut toward 0; line 0 ends the run

The binary operators bind from tightest to loosest % / * - + & |, in that unusual order, so 8/4%3 is 8 divided by 1. The unary ones bind tighter still. They are -, !, _ (cut toward 0), log, ln, sin, cos, tan, sec, csc, cot, sqrt, cbrt and abs. ? reads a number, $e, $pi and $phi are constants, and $rand is a pseudorandom number from 0 up to but not 1.

The specification shows programs but not what they print. This implementation prints a value the way Java's println prints a double, so 5 comes out as 5.0.

Example

The truth machine.

The truth machine. On 0 the first line jumps to line 4 and prints 0. On 1 it jumps to line 2, and lines 2 and 3 print 1 forever.

The countdown from 100, shortened to 5. 2*!!a is 2 while a is not 0 and 0 when it is, so the last line either loops or ends the run.

Expected: 5.0 4.0 3.0 2.0 1.0
Expected: 0.75
Expected: 1.4142135623730951
Expected: 8.0

Further

Also in Turing tarpits

Write your own in Run Convert a program from Math++

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run math -e '?+?' --input '0.5
0.25'
shib manual math

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/math.js

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

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