Talk:Polynomial

Combine this with Fractran and you have a truly unusable mess.--Xolroc (talk) 02:40, 13 December 2012 (UTC)

Interpreter
I just wrote an interpreter in Mathematica, but it tends to crash for larger functions, including the Hello World program. Note that the variable can be anything, as long as it is 1 character long. Invalid input produces undefined behavior. LegionMammal978 (talk) 13:33, 9 July 2015 (UTC) run[prog_] := ToExpression[ "reg=0;in=OpenRead[If[$OperatingSystem==\"Windows\",\"!type con\",\ \"!cat\"]];" <> StringJoin[ prog /. {I -> "WriteString[$Output,If[reg<0,\"\",FromCharacterCode[reg]]];", 2 I -> "reg=Read[in,Byte]/.EndOfFile->-1;", Complex[a_Integer, 1] :> "reg+=" <> IntegerString[a] <> ";", Complex[a_Integer, 2] :> "reg-=" <> IntegerString[a] <> ";", Complex[a_Integer, 3] :> "reg*=" <> IntegerString[a] <> ";", Complex[a_Integer, 4] :> "reg=IntegerPart[reg/" <> IntegerString[a] <> "];", Complex[a_Integer, 5] :> "reg=Mod[reg," <> IntegerString[a] <> ";", Complex[a_Integer, 6] :> "reg=IntegerPart[reg^" <> IntegerString[a] <> "];", 1 -> "If[reg>0,", 2 | 6 -> "];", 3 -> "If[reg<0,", 4 -> "If[reg==0,", 5 -> "While[reg>0,", 7 -> "While[reg<0,", 8 -> "While[reg==0,"}] <> "Close[in];"]; sort[zeros_] := SortBy[If[Im[#] == 0, FactorInteger[#] 1 , FactorInteger[Im[#]] 1 {1, I} + {0, Re[#]}] & /@ zeros, First] All, 2 ; zeros[input_] := Select[Solve[ToExpression[StringDrop[input, 7]] == 0, Symbol[StringTake[input, {3}]], Complexes] All, 1, 2 , NonNegative@*Im]; If[Length[$ScriptCommandLine] < 2, Print["USAGE: " <> $ScriptCommandLine 1 <> " "]; Quit[]]; run[sort[zeros[Import[$ScriptCommandLine 2, "Text"]]]];
 * 1) !/usr/local/bin/WolframScript -script

Hello World example is fake
Suppose it was true. Last coefficient is the product of roots of the polynomial. Let f(x) be the input polynomial. Let t = f(0) = -611392605770821583281602313540767104622218840531412047272348323116466189132132314542079626967192155939298340170675960484343482356334590

Obviously, t is the product of roots. If b!=0 and 0=f(a+p^bi), then f(a-p^bi)=0, therefore t is divisible by a^2+p^(2b). That means that f can't contain any output instruction. If it did, t would be divisible by p^2 for some p, s.t. CountPrimesBelow(p+1) <= degree(f) (since the number of used primes doesn't surpass the degree). However, direct inspections shows that it's not the case. In fact, I can't even factor t in full. These are the factors that I was able to retrieve:

P1 = 2 P1 = 5 P5 = 87697 P7 = 2721421 P9 = 121723913

In fact, there are no roots of form a+p**b, where p<233, b<7, |a|<128.

I propose exchanging example to one that I generated:


 * 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

One may check, that the roots (before encoding, and excluding complex conjugates) are (in format (a, b) equivalent to a+ib):


 * (72, 1), (0, 1), (29, 1), (0, 1), (7, 1), (0, 1), (0, 1), (3, 1), (0, 1), (79, 2), (0, 1), (55, 1), (0, 1), (24, 1), (0, 1), (3, 1), (0, 1), (6, 2), (0, 1), (8, 2), (0, 1), (67, 2), (0, 1), (23, 2), (0, 1)