Polynomial

From Esolang
Jump to navigation Jump to search

Polynomial is an esoteric language created by User:Maedhros777. It is designed in such a way that each program is simply a polynomial function, where all of the language statements are done by the zeroes of the function. Therefore, Polynomial programs are often very difficult to understand, due to the time-consuming nature of finding the zeroes of a function with high degree.

Specification

A Polynomial program is of the form f(x) = 3x^2 + x + 7, where the polynomial begins with f(x) = , the monomials in the polynomial are in order from highest degree to lowest degree (the final term may omit , leaving only the constant), any term may be omitted if its coefficient is 0, and every coefficient is an integer. Language statements are executed based on the zeroes (values of for which ) of the function, and both real and complex zeroes are allowed (complex conjugates are only executed once, since negative values of b in are nops).

The language works in such a way that there is a single integer register that all operations modify. The imaginary zeroes i and 2i output and input the register, respectively. Complex zeroes of the form , where and , are operations on the register in which a is the operand and b is the operator. Here is a table (where a is always any nonzero integer):

Operator C code b
+= register += a; 1
-= register -= a; 2
*= register *= a; 3
/= register /= a; 4
%= register %= a; 5
^ register = pow(register, a); 6

Real zeroes translate to the following instructions (where the real number is represented by x):

Operator C code x
if if (register > 0) { 1
endif } (at the end of an if block) 2
if if (register < 0) { 3
if if (register == 0) { 4
while while (register > 0) { 5
endwhile } (at the end of a while block) 6
while while (register < 0) { 7
while while (register == 0) { 8

A special encoding is used when creating a Polynomial program, so that the compiler can distinguish in which order zeroes should be executed (thanks to Hiato for the idea). Ascending primes are used; essentially, each zero x is transformed to , where p is the smallest unused prime (complex zeroes are transformed to ). For example, consider writing a small portion of Polynomial code that prints the value of the register if it is positive. The zeroes needed are simply 1, i, -i, and 2. So we might be tempted to deduce . But to let the compiler know which statements occur first, we need to change it to the following:

The reason that changes to instead of is that it is a complex conjugate of the actual statement and is therefore disregarded (only positive values of b are accepted). If there were more statements, we would also have to use , etc. This method works because the compiler first searches for a zero such that is an integer, then a zero such that is an integer, etc.

Cat

This program prints standard input back to standard output. Since Polynomial returns -1 on EOF, the program halts on EOF (and does not print the EOF, since negative values of output are ignored in Polynomial). Here are the zeroes in order (excluding complex conjugates and before encoding):

Here is the final result:

f(x) = x^10 - 4827056x^9 + 1192223600x^8 - 8577438158x^7 + 958436165464x^6 - 4037071023854x^5 + 141614997956730x^4 - 365830453724082x^3 + 5225367261446055x^2 - 9213984708801250x + 21911510628393750

Hello, world!

Example by User:Enedil:

f(x) = x^50 - 752x^49 + 141960856x^48 - 97823530588x^47 + 6924620364389108x^46 - 4341495724143788540x^45 + 138060613405951923767380x^44 - 79197535132424777586735700x^43 + 979470645655071268126749786680x^42 - 513709357652108230631577128358860x^41 + 770486975689768419626951634418461748x^40 - 273098373735611746286126693707899401476x^39 + 72291664762156559225098986515946802509588x^38 - 14676371828550521943557197189472305446692764x^37 + 2471742454496740843240034728256092024085665124x^36 - 357063163931791512794128153482861289523023882820x^35 + 45115851521103966434436591937303467605719233317170x^34 - 5069635951879805027132623517548283799346981648434460x^33 + 511526544745104457693634223308476770566099272565371060x^32 - 46728094385862876640770832231671877988577394475660885100x^31 + 3886421195321910267418249490411801624852449948925639780700x^30 - 295635895529267179921164468879651662866454307976481821361700x^29 + 20633888636784455204085657939750648669099906931549131855360060x^28 - 1324758206148788859378449344375818925652874503976726821800318620x^27 + 78373487486427853675250519103675553581406450490324786426443578960x^26 - 4277231098063905708498485183459770277016249837260045512086373052580x^25 + 215527455786956603087839057660424758386928544182537723602033298390620x^24 - 10026110853984647107902422007895365708427081026500238164561801279215980x^23 + 430739270392505977394209904953365441102532225723377537121532050266775740x^22 - 17069848872478164030368242448759544641115144627455141327323776464849764020x^21 + 623936547617549209386439841779658427511784043378068133194757937607564613452x^20 - 20993646278144108287371096576875982712212020201505201591115504952836958294764x^19 + 649720717047168714688810604703691057371212844616863730695724642230626940206117x^18 - 18454026326119048562742802386720336605855036106533711987860949339189893357832516x^17 + 480018892566368384981391161715990091416104911769766606211141965273638983019962276x^16 - 11414153815128096188736407808171635605448552508496871507135456079041095632029582920x^15 + 247119850164804163572258046131475110258272489534699880387365447880963300945559555680x^14 - 4862888340475792547245763823711545181858124995375533140243229121347892936079946665360x^13 + 86558002997403388455068105800951021320526816961235127777233671733610160673351674179520x^12 - 1386482271878483438155022114100676424860940250972419166903097785395468148849738551671520x^11 + 19959534586392149266660053142048372043141602919486809273490667168324165973826526352280224x^10 - 253920856155736764038716331406024220136995093667781379719894495826380342450009767792895808x^9 + 2887129000992839385500945493765474545949855475497573514091738434731704727401676275341829504x^8 - 28042509855580438356130080622916737041825853230142162026166889394236138282841003530143152512x^7 + 243032092343346343074179476562493169914690027874421758235567822233002208656757155592889900032x^6 - 1676296630217806396090935946022990777465901542969002129717262721145539754562003915533804752640x^5 + 10587973167254746886025389198053813468704398306519586773922038052938514572005258639168462438400x^4 - 43524882144413253508544104946208809101516451661691038559426656724816915089318151748332891328000x^3 + 204551020411993140063611540392697605993557638942587387542307354260755646692402296279038165920000x^2 - 274800267060219615571000061411061421786428150600591471312149973459733252174021048995828038400000x + 1142695050742106476607449533181123418012829436119125708025689288735734639370685118360020240000000

Implementations

See also