We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Single Variable Algebra

From Esolang
Jump to navigation Jump to search
Single Variable Algebra
Paradigm(s) functional
Designed by Armin Schäfer (User:772)
Appeared in 2024
Computational class Turing complete (with -v flag)
Major implementations Rust

Single Variable Algebra (SVA) is an educational, minimalist esoteric programming language created by User:772. Its defining feature is that every valid SVA program is also syntactically correct middle-school mathematics: it uses only a single variable (x), numbers, basic arithmetic operators (+, -, *, /, ^), and user-defined functions built from these elements.

SVA is not intended as a general-purpose language but as a bridge between programming and mathematical concepts. It uses an "Accelerated Simulator" to optimize certain recursive function patterns, allowing it to efficiently simulate Turing machines (e.g., the Busy Beaver BB(4)).

Syntax

A program consists of a series of function definitions followed by a final expression to evaluate. Function definitions take the form:

f(x) = <expression>

Expressions can use x, numeric literals, the operators above, and calls to previously defined functions. Iterated function application is written with a bracket notation: f^[n](x) applies f to x a total of n times.

EBNF:

<single_variable_algebra> ::= <funcdef> "\nf" <findex> "(" <number> ")" | <funcdef> "\n" <single_variable_algebra>
<funcdef> ::= "f" <n> "(" <variable> ")" "=" <e>
<e> ::= <variable> | <number> | "(" <e> ")" | <e> <op> <e> | "f" <findex> "(" <e> ")"
<findex> ::= <n> | <n> "^[" <e> "]"
<op> ::= "+" | "-" | "*" | "/" | "^"
<n> ::= <digit> | <n> <digit>
<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
<variable> ::= "x"
<number> ::= <digit> | <digit> "." <digit>

Examples

Replace any digit 1 with digit 7

decimals(x) = 50
abs(x) = (x^2)^(1/2)
H(x) = (x+abs(x))/(2*x)
tiny(x) = 10^(-decimals(x))
ge0(x) = H(x+tiny(x)/10)
lt1(x) = 1-ge0(x-1)
is0(x) = ge0(x)*lt1(x)
is1(x) = is0(x-1)
is2(x) = is0(x-2)
is3(x) = is0(x-3)
is4(x) = is0(x-4)
is5(x) = is0(x-5)
is6(x) = is0(x-6)
is7(x) = is0(x-7)
is8(x) = is0(x-8)
is9(x) = is0(x-9)
floor1(x) = is1(x)+2*is2(x)+3*is3(x)+4*is4(x)+5*is5(x)+6*is6(x)+7*is7(x)+8*is8(x)+9*is9(x)
right(x) = x*10-floor1(x*10)+floor1(x*10)*tiny(x)
left(x) = right^[49](x)
replace_1_by_7(x) = right(x+is1(x*10)*0.6)
f(x) = replace_1_by_7^[50](x)
f(0.2821011111110111236333746311231819159841234293491)

Output: 0.2827077777770777236333746377237879759847234293497

Floor function (recursive, requires -v)

decimals(x) = 50
abs(x) = (x^2)^(1/2)
H(x) = (x+abs(x))/(2*x)
tiny(x) = 10^(-decimals(x))
ge0(x) = H(x+tiny(x)/10)
lt1(x) = 1-ge0(x-1)
decimals2(x) = lt1(x)*x+(1-lt1(x))*decimals2(x-1)
floor(x) = x-decimals2(x)
floor(500.3742839482)

Output: 500

This example demonstrates recursion, which is only possible when the interpreter is run with the "very strongly zero" flag (-v or --very-strongly-zero), allowing expressions like 0 * undefined = 0.

Computational class

As seen in the last example, SVA is Turing complete when run with the --very-strongly-zero flag, as it permits unbounded recursion. Without --very-strongly-zero, the language is restricted to primitive recursion through iterated function application.

External resources