esolang

Polynomial

A program is one polynomial. To read it you have to find its zeroes.

Maedhros777, 2010 · Turing complete: unknown · ●●● hard · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: meow

The idea

Maedhros777 made Polynomial in 2010. A program is a single line such as f(x) = x^2 + 9, and the statements are the zeroes of that function. Real zeroes are control flow, and complex zeroes a + bi work on a single integer register, with a the operand and b the operator.

Read the story

A polynomial has no order among its zeroes, so the order is written into them with primes. The first statement uses 2, the next 3, then 5, 7 and so on. A real statement x becomes the zero p^x, and a complex one a + bi becomes a + p^b i. Its conjugate a - p^b i has to be there too, as the coefficients are integers, and it does nothing.

The machine

ZeroDoes
p iPrint the register as a character, unless it is negative
p^2 iRead a byte into the register, -1 at the end of input
a + p ir += a
a + p^2 ir -= a
a + p^3 i ... a + p^6 ir *= a, r /= a, r %= a, r = pow(r, a)
p^1 p^3 p^4if (r > 0) {, if (r < 0) {, if (r == 0) {
p^5 p^7 p^8while (r > 0) {, while (r < 0) {, while (r == 0) {
p^2 p^6The } of an if, of a while

The register starts at 0 and has no bounds. This implementation finds each zero exactly. It tries p^x for each x, and for a + p^b i it finds the one root that the real and imaginary parts of f(t + p^b i) share modulo the prime 2^127 - 1, then checks it in whole numbers and divides it out.

Example

The cat from the specification has the zeroes 1 + i, 5, 2i, i, 1 + i, 6 before encoding.

The cat from the specification has the zeroes 1 + i, 5, 2i, i, 1 + i, 6 before encoding. So it adds 1, and while the register is positive it reads, prints and adds 1. The end of input reads -1, which prints nothing and becomes 0, and the loop ends.

Hi takes four statements. The zeroes 72 ± 2i add 72, ±3i prints H, 33 ± 5i add 33 and ±7i prints i.

Expected: Hi

The Hello World by Enedil is a polynomial of degree 50 with a constant of 97 digits. Its 25 statements add and subtract the steps between letters and print Hello World! and a line feed.

Patterns it teaches

  • Encoding tricks: the order of the statements lives in prime powers.
  • Hostile design: reading a program means finding the roots of a large polynomial.

Further

Zero-dimensional languages

Write your own in Run Convert a program from Polynomial

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run polynomial -e 'f(x) = x^10 - 4827056x^9 + 1192223600x^8 - 8577438158x^7 + 958436165464x^6 - 4037071023854x^5 + 141614997956730x^4 - 365830453724082x^3 + 5225367261446055x^2 - 9213984708801250x + 21911510628393750' --input 'Hello, cat!'
shib manual polynomial

Source

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

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

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