roots.log 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453
  1. Codemist Standard Lisp 3.54 for DEC Alpha: May 23 1994
  2. Dump file created: Mon May 23 10:39:11 1994
  3. REDUCE 3.5, 15-Oct-93 ...
  4. Memory allocation: 6023424 bytes
  5. +++ About to read file ndotest.red
  6. % Tests of the root finding package.
  7. % Author: Stanley L. Kameny (stan%valley.uucp@rand.org)
  8. comment This test file works only with Reduce version 3.5 and later
  9. and contains examples all of which are solved by roots mod 1.94.
  10. Answers are rounded to the value given by rootacc (default = 6)
  11. unless higher accuracy is needed to separate roots. Format may differ
  12. from that given here, but root order and values should agree exactly.
  13. (Although the function ROOTS may obtain the roots in a diffferent
  14. order, they are sorted into a standard order in mod 1.94.)
  15. In the following, problems 20) and 82) are time consuming and
  16. have been commented out to speed up the test.
  17. The hard examples 111) through 115) almost double the test time
  18. but are necessary to test some logical paths.
  19. A new "hardest" example has been added as example 116). It is
  20. commented out, since it is time consuming, but it is solved by roots
  21. mod 1.94. The time needed to run the three commented-out examples is
  22. almost exactly equal to the time for the rest of the test. Users of
  23. fast computers can uncomment the lines marked with %**%. The three
  24. examples by themselves are contained in the test file rootsxtr.tst.
  25. When answers are produced which require precision increase for
  26. printing out or input of roots, roots functions cause precision
  27. increase to occur. If the precision is already higher than the
  28. default value, a message is printed out warning of the the precision
  29. normally needed for input of those values.$
  30. roots x;
  31. {x=0}
  32. % To load roots package.
  33. write "This is Roots Package test ", symbolic roots!-mod$
  34. This is Roots Package test Mod 1.94, 28 May 1993.
  35. % Simple root finding.
  36. showtime;
  37. Time: 33 ms plus GC time: 134 ms
  38. % 1) multiple real and imaginary roots plus two real roots.
  39. zz:= (x-3)**2*(100x**2+113)**2*(1000000x-10000111)*(x-1);
  40. 8 7 6
  41. zz := 10000000000*x - 170001110000*x + 872607770000*x
  42. 5 4 3
  43. - 1974219158600*x + 2833796550200*x - 3810512046359*x
  44. 2
  45. + 3119397498913*x - 2030292260385*x + 1149222756231
  46. roots zz;
  47. {x=1.06301*i,
  48. x=1.06301*i,
  49. x=-1.06301*i,
  50. x=-1.06301*i,
  51. x=3.0,
  52. x=3.0,
  53. x=1,
  54. x=10.0001}
  55. %{x=1.06301*i,x=1.06301*i,x=-1.06301*i,x=-1.06301*i,
  56. %x=3.0,x=3.0,x=1,x=10.0001} (rootacc caused rounding to 6 places)
  57. % Accuracy is increased whenever necessary to separate distinct roots.
  58. % 2) accuracy increase to 7 required for two roots.
  59. zz:=(x**2+1)*(x-2)*(1000000x-2000001);
  60. 4 3 2
  61. zz := 1000000*x - 4000001*x + 5000002*x - 4000001*x + 4000002
  62. roots zz;
  63. {x=i,
  64. x= - i,
  65. x=2.0,
  66. x=2.000001}
  67. %{x=i,x= -i,x=2.0,x=2.000001}
  68. % 3) accuracy increase to 8 required.
  69. zz:= (x-3)*(10000000x-30000001);
  70. 2
  71. zz := 10000000*x - 60000001*x + 90000003
  72. roots zz;
  73. {x=3.0,x=3.0000001}
  74. %{x=3.0,x=3.0000001}
  75. % 4) accuracy increase required here to separate repeated root from
  76. % simple root.
  77. zz := (x-3)*(1000000x-3000001)*(x-3)*(1000000x-3241234);
  78. 4 3 2
  79. zz := 2*(500000000000*x - 6120617500000*x + 28085557620617*x
  80. - 57256673223702*x + 43756673585553)
  81. roots zz;
  82. {x=3.0,
  83. x=3.0,
  84. x=3.000001,
  85. x=3.24123}
  86. %{x=3.0,x=3.0,x=3.000001,x=3.24123}
  87. % other simple examples
  88. % 5) five real roots with widely different spacing.
  89. zz:= (x-1)*(10x-11)*(x-1000)*(x-1001)*(x-100000);
  90. 5 4 3 2
  91. zz := 10*x - 1020031*x + 2013152032*x - 1005224243011*x
  92. + 2104312111000*x - 1101100000000
  93. roots zz;
  94. {x=1,
  95. x=1.1,
  96. x=1000.0,
  97. x=1001.0,
  98. x=1.0e+5}
  99. %{x=1,x=1.1,x=1000.0,x=1001.0,x=1.0E+5}
  100. % 6) a cluster of 5 roots in complex plane in vicinity of x=1.
  101. zz:= (x-1)*(10000x**2-20000x+10001)*(10000x**2-20000x+9999);
  102. 5 4 3 2
  103. zz := 100000000*x - 500000000*x + 1000000000*x - 1000000000*x
  104. + 499999999*x - 99999999
  105. roots zz;
  106. {x=0.99,
  107. x=1,
  108. x=1 + 0.01*i,
  109. x=1 - 0.01*i,
  110. x=1.01}
  111. %{x=0.99,x=1,x=1 + 0.01*i,x=1 - 0.01*i,x=1.01}
  112. % 7) four closely spaced real roots.
  113. zz := (x-1)*(100x-101)*(100x-102)*(100x-103);
  114. 4 3 2
  115. zz := 2*(500000*x - 2030000*x + 3090550*x - 2091103*x + 530553)
  116. roots zz;
  117. {x=1,
  118. x=1.01,
  119. x=1.02,
  120. x=1.03}
  121. %{x=1,x=1.01,x=1.02,x=1.03}
  122. % 8) five closely spaced roots, 3 real + 1 complex pair.
  123. zz := (x-1)*(100x-101)*(100x-102)*(100x**2-200x+101);
  124. 5 4 3 2
  125. zz := 2*(500000*x - 2515000*x + 5065100*x - 5105450*x + 2575601*x
  126. - 520251)
  127. roots zz;
  128. {x=1,
  129. x=1 + 0.1*i,
  130. x=1 - 0.1*i,
  131. x=1.01,
  132. x=1.02}
  133. %{x=1,x=1 + 0.1*i,x=1 - 0.1*i,x=1.01,x=1.02}
  134. % 9) symmetric cluster of 5 roots, 3 real + 1 complex pair.
  135. zz := (x-2)*(10000x**2-40000x+40001)*(10000x**2-40000x+39999);
  136. 5 4 3 2
  137. zz := 100000000*x - 1000000000*x + 4000000000*x - 8000000000*x
  138. + 7999999999*x - 3199999998
  139. roots zz;
  140. {x=1.99,
  141. x=2.0,
  142. x=2.0 + 0.01*i,
  143. x=2.0 - 0.01*i,
  144. x=2.01}
  145. %{x=1.99,x=2.0,x=2.0 + 0.01*i,x=2.0 - 0.01*i,x=2.01}
  146. % 10) closely spaced real and complex pair.
  147. ss:= (x-2)*(100000000x**2-400000000x+400000001);
  148. 3 2
  149. ss := 100000000*x - 600000000*x + 1200000001*x - 800000002
  150. roots ss;
  151. {x=2.0,x=2.0 + 0.0001*i,x=2.0 - 0.0001*i}
  152. %{x=2.0,x=2.0 + 0.0001*i,x=2.0 - 0.0001*i}
  153. % 11) Zero roots and multiple roots cause no problem.
  154. % Multiple roots are shown when the switch multiroot is on
  155. %(normally on.)
  156. zz:= x*(x-1)**2*(x-4)**3*(x**2+1);
  157. 7 6 5 4 3 2
  158. zz := x*(x - 14*x + 74*x - 186*x + 249*x - 236*x + 176*x - 64)
  159. roots zz;
  160. {x=0,
  161. x=4.0,
  162. x=4.0,
  163. x=4.0,
  164. x=1,
  165. x=1,
  166. x=i,
  167. x= - i}
  168. %{x=0,x=4.0,x=4.0,x=4.0,x=1,x=1,x=i,x= - i}
  169. % 12) nearestroot will find a single root "near" a value, real or
  170. % complex.
  171. nearestroot(zz,2i);
  172. {x=i}
  173. %{x=i}
  174. % More difficult examples.
  175. % Three examples in which root scaling is needed in the complex
  176. % iteration process.
  177. % 13) nine roots, 3 real and 3 complex pairs.
  178. zz:= x**9-45x-2;
  179. 9
  180. zz := x - 45*x - 2
  181. roots zz;
  182. {x= - 1.60371,
  183. x=-1.13237 + 1.13805*i,
  184. x=-1.13237 - 1.13805*i,
  185. x= - 0.0444444,
  186. x=0.00555357 + 1.60944*i,
  187. x=0.00555357 - 1.60944*i,
  188. x=1.14348 + 1.13804*i,
  189. x=1.14348 - 1.13804*i,
  190. x=1.61483}
  191. %{x= - 1.60371,x=-1.13237 + 1.13805*i,x=-1.13237 - 1.13805*i,
  192. % x= - 0.0444444,x=0.00555357 + 1.60944*i,x=0.00555357 - 1.60944*i,
  193. % x=1.14348 + 1.13804*i,x=1.14348 - 1.13804*i,x=1.61483}
  194. comment In the next two examples, there are complex roots with
  195. extremely small real parts (new capability in Mod 1.91.);
  196. % 14) nine roots, 1 real and 4 complex pairs.
  197. zz:= x**9-9999x**2-0.01;
  198. 9 2
  199. 100*x - 999900*x - 1
  200. zz := ------------------------
  201. 100
  202. roots zz;
  203. {x=-3.3584 + 1.61732*i,
  204. x=-3.3584 - 1.61732*i,
  205. x=-0.829456 + 3.63408*i,
  206. x=-0.829456 - 3.63408*i,
  207. x=5.0025e-29 + 0.00100005*i,
  208. x=5.0025e-29 - 0.00100005*i,
  209. x=2.32408 + 2.91431*i,
  210. x=2.32408 - 2.91431*i,
  211. x=3.72754}
  212. %{x=-3.3584 + 1.61732*i,x=-3.3584 - 1.61732*i,
  213. % x=-0.829456 + 3.63408*i,x=-0.829456 - 3.63408*i,
  214. % x=5.0025E-29 + 0.00100005*i,x=5.0025E-29 - 0.00100005*i,
  215. % x=2.32408 + 2.91431*i,x=2.32408 - 2.91431*i,x=3.72754}
  216. comment Rootacc 7 produces 7 place accuracy. Answers will print in
  217. bigfloat format if floating point print >6 digits is not implemented.;
  218. % 15) nine roots, 1 real and 4 complex pairs.
  219. rootacc 7;
  220. 7
  221. zz:= x**9-500x**2-0.001;
  222. 9 2
  223. 1000*x - 500000*x - 1
  224. zz := -------------------------
  225. 1000
  226. roots zz;
  227. {x=-2.189157 + 1.054242*i,
  228. x=-2.189157 - 1.054242*i,
  229. x=-0.5406772 + 2.368861*i,
  230. x=-0.5406772 - 2.368861*i,
  231. x=1.6e-26 + 0.001414214*i,
  232. x=1.6e-26 - 0.001414214*i,
  233. x=1.514944 + 1.899679*i,
  234. x=1.514944 - 1.899679*i,
  235. x=2.429781}
  236. %{x=-2.189157 + 1.054242*i,x=-2.189157 - 1.054242*i,
  237. % x=-0.5406772 + 2.368861*i,x=-0.5406772 - 2.368861*i,
  238. % x=1.6E-26 + 0.001414214*i,x=1.6E-26 - 0.001414214*i,
  239. % x=1.514944 + 1.899679*i,x=1.514944 - 1.899679*i,x=2.429781}
  240. % the famous Wilkinson "ill-conditioned" polynomial and its family.
  241. % 16) W(6) four real roots plus one complex pair.
  242. zz:= 10000*(for j:=1:6 product(x+j))+27x**5;
  243. 6 5 4 3 2
  244. zz := 10000*x + 210027*x + 1750000*x + 7350000*x + 16240000*x
  245. + 17640000*x + 7200000
  246. roots zz;
  247. {x= - 6.143833,
  248. x=-4.452438 + 0.02123455*i,
  249. x=-4.452438 - 0.02123455*i,
  250. x= - 2.950367,
  251. x= - 2.003647,
  252. x= - 0.9999775}
  253. %{x= - 6.143833,x=-4.452438 + 0.02123455*i,x=-4.452438 - 0.02123455*i,
  254. % x= - 2.950367,x= - 2.003647,x= - 0.9999775}
  255. % 17) W(8) 4 real roots plus 2 complex pairs.
  256. zz:= 1000*(for j:=1:8 product(x+j))+2x**7;
  257. 8 7 6 5 4
  258. zz := 2*(500*x + 18001*x + 273000*x + 2268000*x + 11224500*x
  259. 3 2
  260. + 33642000*x + 59062000*x + 54792000*x + 20160000)
  261. roots zz;
  262. {x= - 8.437546,
  263. x=-6.494828 + 1.015417*i,
  264. x=-6.494828 - 1.015417*i,
  265. x=-4.295858 + 0.2815097*i,
  266. x=-4.295858 - 0.2815097*i,
  267. x= - 2.982725,
  268. x= - 2.000356,
  269. x= - 0.9999996}
  270. %{x= - 8.437546,x=-6.494828 + 1.015417*i,x=-6.494828 - 1.015417*i,
  271. % x=-4.295858 + 0.2815097*i,x=-4.295858 - 0.2815097*i,
  272. % x= - 2.982725,x= - 2.000356,x= - 0.9999996}
  273. % 18) W(10) 6 real roots plus 2 complex pairs.
  274. zz:=1000*(for j:= 1:10 product (x+j))+x**9;
  275. 10 9 8 7 6
  276. zz := 1000*x + 55001*x + 1320000*x + 18150000*x + 157773000*x
  277. 5 4 3
  278. + 902055000*x + 3416930000*x + 8409500000*x
  279. 2
  280. + 12753576000*x + 10628640000*x + 3628800000
  281. roots zz;
  282. {x= - 10.80988,
  283. x=-8.70405 + 1.691061*i,
  284. x=-8.70405 - 1.691061*i,
  285. x=-6.046279 + 1.134321*i,
  286. x=-6.046279 - 1.134321*i,
  287. x= - 4.616444,
  288. x= - 4.075943,
  289. x= - 2.998063,
  290. x= - 2.000013,
  291. x= - 1}
  292. %{x= - 10.80988,x=-8.70405 + 1.691061*i,x=-8.70405 - 1.691061*i,
  293. % x=-6.046279 + 1.134321*i,x=-6.046279 - 1.134321*i,x= - 4.616444,
  294. % x= - 4.075943,x= - 2.998063,x= - 2.000013,x= - 1}
  295. % 19) W(12) 6 real roots plus 3 complex pairs.
  296. zz:= 10000*(for j:=1:12 product(x+j))+4x**11;
  297. 12 11 10 9
  298. zz := 4*(2500*x + 195001*x + 6792500*x + 139425000*x
  299. 8 7 6
  300. + 1873657500*x + 17316585000*x + 112475577500*x
  301. 5 4 3
  302. + 515175375000*x + 1643017090000*x + 3535037220000*x
  303. 2
  304. + 4828898880000*x + 3716107200000*x + 1197504000000)
  305. roots zz;
  306. {x= - 13.1895,
  307. x=-11.02192 + 2.23956*i,
  308. x=-11.02192 - 2.23956*i,
  309. x=-7.953917 + 1.948001*i,
  310. x=-7.953917 - 1.948001*i,
  311. x=-5.985629 + 0.8094247*i,
  312. x=-5.985629 - 0.8094247*i,
  313. x= - 4.880956,
  314. x= - 4.007117,
  315. x= - 2.999902,
  316. x= - 2.0,
  317. x= - 1}
  318. %{x= - 13.1895,x=-11.02192 + 2.23956*i,x=-11.02192 - 2.23956*i,
  319. % x=-7.953917 + 1.948001*i,x=-7.953917 - 1.948001*i,
  320. % x=-5.985629 + 0.8094247*i,x=-5.985629 - 0.8094247*i,
  321. % x= - 4.880956,x= - 4.007117,x= - 2.999902,x= - 2.0,x= - 1}
  322. % 20) W(20) 10 real roots plus 5 complex pairs. (The original problem)
  323. % This example is commented out, since it takes significant time without
  324. % being particularly difficult or checking out new paths:
  325. %**% zz:= x**19+10**7*for j:=1:20 product (x+j); roots zz;
  326. %{x= - 20.78881,x=-19.45964 + 1.874357*i,x=-19.45964 - 1.874357*i,
  327. % x=-16.72504 + 2.731577*i,x=-16.72504 - 2.731577*i,
  328. % x=-14.01105 + 2.449466*i,x=-14.01105 - 2.449466*i,
  329. % x=-11.82101 + 1.598621*i,x=-11.82101 - 1.598621*i,
  330. % x=-10.12155 + 0.6012977*i,x=-10.12155 - 0.6012977*i,
  331. % x= - 8.928803,x= - 8.006075,x= - 6.999746,x= - 6.000006,
  332. % x= - 5.0,x= - 4.0,x= - 3.0,x= - 2.0,x= - 1}
  333. rootacc 6;
  334. 6
  335. % 21) Finding one of a cluster of 8 roots.
  336. zz:= (10**16*(x-1)**8-1);
  337. 8 7
  338. zz := 10000000000000000*x - 80000000000000000*x
  339. 6 5
  340. + 280000000000000000*x - 560000000000000000*x
  341. 4 3
  342. + 700000000000000000*x - 560000000000000000*x
  343. 2
  344. + 280000000000000000*x - 80000000000000000*x
  345. + 9999999999999999
  346. nearestroot(zz,2);
  347. {x=1.01}
  348. %{x=1.01}
  349. % 22) Six real roots spaced 0.01 apart.
  350. c := 100;
  351. c := 100
  352. zz:= (x-1)*for i:=1:5 product (c*x-(c+i));
  353. 6 5 4
  354. zz := 40*(250000000*x - 1537500000*x + 3939625000*x
  355. 3 2
  356. - 5383556250*x + 4137919435*x - 1696170123*x + 289681938
  357. )
  358. roots zz;
  359. {x=1,
  360. x=1.01,
  361. x=1.02,
  362. x=1.03,
  363. x=1.04,
  364. x=1.05}
  365. %{x=1,x=1.01,x=1.02,x=1.03,x=1.04,x=1.05}
  366. % 23) Six real roots spaced 0.001 apart.
  367. c := 1000;
  368. c := 1000
  369. zz:= (x-1)*for i:=1:5 product (c*x-(c+i));
  370. 6 5 4
  371. zz := 40*(25000000000000*x - 150375000000000*x + 376877125000000*x
  372. 3 2
  373. - 503758505625000*x + 378762766881850*x
  374. - 151883516888703*x + 25377130631853)
  375. roots zz;
  376. {x=1,
  377. x=1.001,
  378. x=1.002,
  379. x=1.003,
  380. x=1.004,
  381. x=1.005}
  382. %{x=1,x=1.001,x=1.002,x=1.003,x=1.004,x=1.005}
  383. % 24) Five real roots spaced 0.0001 apart.
  384. c := 10000;
  385. c := 10000
  386. zz:= (x-1)*for i:=1:4 product (c*x-(c+i));
  387. 5 4
  388. zz := 8*(1250000000000000*x - 6251250000000000*x
  389. 3 2
  390. + 12505000437500000*x - 12507501312562500*x
  391. + 6255001312625003*x - 1251250437562503)
  392. roots zz;
  393. {x=1,
  394. x=1.0001,
  395. x=1.0002,
  396. x=1.0003,
  397. x=1.0004}
  398. %{x=1,x=1.0001,x=1.0002,x=1.0003,x=1.0004}
  399. % 25) A cluster of 9 roots, 5 real, 2 complex pairs; spacing 0.1.
  400. zz:= (x-1)*(10**8*(x-1)**8-1);
  401. 9 8 7 6
  402. zz := 100000000*x - 900000000*x + 3600000000*x - 8400000000*x
  403. 5 4 3
  404. + 12600000000*x - 12600000000*x + 8400000000*x
  405. 2
  406. - 3600000000*x + 899999999*x - 99999999
  407. roots zz;
  408. {x=0.9,
  409. x=0.929289 + 0.0707107*i,
  410. x=0.929289 - 0.0707107*i,
  411. x=1,
  412. x=1 + 0.1*i,
  413. x=1 - 0.1*i,
  414. x=1.07071 + 0.0707107*i,
  415. x=1.07071 - 0.0707107*i,
  416. x=1.1}
  417. %{x=0.9,x=0.929289 + 0.0707107*i,x=0.929289 - 0.0707107*i,
  418. % x=1,x=1 + 0.1*i,x=1 - 0.1*i,
  419. % x=1.07071 + 0.0707107*i,x=1.07071 - 0.0707107*i,x=1.1}
  420. % 26) Same, but with spacing 0.01.
  421. zz:= (x-1)*(10**16*(x-1)**8-1);
  422. 9 8
  423. zz := 10000000000000000*x - 90000000000000000*x
  424. 7 6
  425. + 360000000000000000*x - 840000000000000000*x
  426. 5 4
  427. + 1260000000000000000*x - 1260000000000000000*x
  428. 3 2
  429. + 840000000000000000*x - 360000000000000000*x
  430. + 89999999999999999*x - 9999999999999999
  431. roots zz;
  432. {x=0.99,
  433. x=0.992929 + 0.00707107*i,
  434. x=0.992929 - 0.00707107*i,
  435. x=1,
  436. x=1 + 0.01*i,
  437. x=1 - 0.01*i,
  438. x=1.00707 + 0.00707107*i,
  439. x=1.00707 - 0.00707107*i,
  440. x=1.01}
  441. %{x=0.99,x=0.992929 + 0.00707107*i,x=0.992929 - 0.00707107*i,
  442. % x=1,x=1 + 0.01*i,x=1 - 0.01*i,
  443. % x=1.00707 + 0.00707107*i,x=1.00707 - 0.00707107*i,x=1.01}
  444. % 27) Spacing reduced to 0.001.
  445. zz:= (x-1)*(10**24*(x-1)**8-1);
  446. 9 8
  447. zz := 1000000000000000000000000*x - 9000000000000000000000000*x
  448. 7
  449. + 36000000000000000000000000*x
  450. 6
  451. - 84000000000000000000000000*x
  452. 5
  453. + 126000000000000000000000000*x
  454. 4
  455. - 126000000000000000000000000*x
  456. 3
  457. + 84000000000000000000000000*x
  458. 2
  459. - 36000000000000000000000000*x + 8999999999999999999999999*x
  460. - 999999999999999999999999
  461. roots zz;
  462. {x=0.999,
  463. x=0.999293 + 0.000707107*i,
  464. x=0.999293 - 0.000707107*i,
  465. x=1,
  466. x=1 + 0.001*i,
  467. x=1 - 0.001*i,
  468. x=1.00071 + 0.000707107*i,
  469. x=1.00071 - 0.000707107*i,
  470. x=1.001}
  471. %{x=0.999,x=0.999293 + 0.000707107*i,x=0.999293 - 0.000707107*i,
  472. % x=1,x=1 + 0.001*i,x=1 - 0.001*i,
  473. % x=1.00071 + 0.000707107*i,x=1.00071 - 0.000707107*i,x=1.001}
  474. % 28) Eight roots divided into two clusters.
  475. zz:= (10**8*(x-1)**4-1)*(10**8*(x+1)**4-1);
  476. 8 6
  477. zz := 10000000000000000*x - 40000000000000000*x
  478. 4 2
  479. + 59999999800000000*x - 40000001200000000*x
  480. + 9999999800000001
  481. roots zz;
  482. {x= - 0.99,
  483. x=0.99,
  484. x=-1 - 0.01*i,
  485. x=1 + 0.01*i,
  486. x=-1 + 0.01*i,
  487. x=1 - 0.01*i,
  488. x= - 1.01,
  489. x=1.01}
  490. %{x= - 0.99,x=0.99, x=-1 - 0.01*i,x=1 + 0.01*i,
  491. % x=-1 + 0.01*i,x=1 - 0.01*i,x= - 1.01,x=1.01}
  492. % 29) A cluster of 8 roots in a different configuration.
  493. zz:= (10**8*(x-1)**4-1)*(10**8*(100x-102)**4-1);
  494. 8 7
  495. zz := 1000000000000000000000000*x - 8080000000000000000000000*x
  496. 6
  497. + 28562400000000000000000000*x
  498. 5
  499. - 57694432000000000000000000*x
  500. 4
  501. + 72836160149999999900000000*x
  502. 3
  503. - 58848320599199999600000000*x
  504. 2
  505. + 29716320897575999400000000*x - 8574560597551679600000000*x
  506. + 1082432149175678300000001
  507. roots zz;
  508. {x=0.99,
  509. x=1 + 0.01*i,
  510. x=1 - 0.01*i,
  511. x=1.01,
  512. x=1.0199,
  513. x=1.02 + 0.0001*i,
  514. x=1.02 - 0.0001*i,
  515. x=1.0201}
  516. %{x=0.99,x=1 + 0.01*i,x=1 - 0.01*i,x=1.01,
  517. % x=1.0199,x=1.02 + 0.0001*i,x=1.02 - 0.0001*i,x=1.0201}
  518. % 30) A cluster of 8 complex roots.
  519. zz:= ((10x-1)**4+1)*((10x+1)**4+1);
  520. 8 6 4 2
  521. zz := 4*(25000000*x - 1000000*x + 20000*x + 200*x + 1)
  522. roots zz;
  523. {x=-0.0292893 - 0.0707107*i,
  524. x=0.0292893 + 0.0707107*i,
  525. x=-0.0292893 + 0.0707107*i,
  526. x=0.0292893 - 0.0707107*i,
  527. x=-0.170711 - 0.0707107*i,
  528. x=0.170711 + 0.0707107*i,
  529. x=-0.170711 + 0.0707107*i,
  530. x=0.170711 - 0.0707107*i}
  531. %{x=-0.0292893 - 0.0707107*i,x=0.0292893 + 0.0707107*i,
  532. % x=-0.0292893 + 0.0707107*i,x=0.0292893 - 0.0707107*i,
  533. % x=-0.170711 - 0.0707107*i,x=0.170711 + 0.0707107*i,
  534. % x=-0.170711 + 0.0707107*i,x=0.170711 - 0.0707107*i}
  535. comment In these examples, accuracy increase is required to separate a
  536. repeated root from a simple root.;
  537. % 31) Using allroots;
  538. zz:= (x-4)*(x-3)**2*(1000000x-3000001);
  539. zz :=
  540. 4 3 2
  541. 1000000*x - 13000001*x + 63000010*x - 135000033*x + 108000036
  542. roots zz;
  543. {x=3.0,
  544. x=3.0,
  545. x=3.000001,
  546. x=4.0}
  547. %{x=3.0,x=3.0,x=3.000001,x=4.0}
  548. % 32) Using realroots;
  549. realroots zz;
  550. {x=3.0,
  551. x=3.0,
  552. x=3.000001,
  553. x=4.0}
  554. %{x=3.0,x=3.0,x=3.000001,x=4.0}
  555. comment Tests of new capabilities in mod 1.87 for handling complex
  556. polynomials and polynomials with very small imaginary parts or very
  557. small real roots. A few real examples are shown, just to demonstrate
  558. that these still work.;
  559. % 33) A trivial complex case (but degrees 1 and 2 are special cases);
  560. zz:= x-i;
  561. zz := - i + x
  562. roots zz;
  563. {x=i}
  564. %{x=i}
  565. % 34) Real case.
  566. zz:= y-7;
  567. zz := y - 7
  568. roots zz;
  569. {y=7.0}
  570. %{y=7.0}
  571. % 35) Roots with small imaginary parts (new capability);
  572. zz := 10**16*(x**2-2x+1)+1;
  573. 2
  574. zz := 10000000000000000*x - 20000000000000000*x + 10000000000000001
  575. roots zz;
  576. {x=1 + 0.00000001*i,x=1 - 0.00000001*i}
  577. %{x=1 + 0.00000001*i,x=1 - 0.00000001*i}
  578. % 36) One real, one complex root.
  579. zz:=(x-9)*(x-5i-7);
  580. 2
  581. zz := - 5*i*x + 45*i + x - 16*x + 63
  582. roots zz;
  583. {x=9.0,x=7.0 + 5.0*i}
  584. %{x=9.0,x=7.0 + 5.0*i}
  585. % 37) Three real roots.
  586. zz:= (x-1)*(x-2)*(x-3);
  587. 3 2
  588. zz := x - 6*x + 11*x - 6
  589. roots zz;
  590. {x=1,x=2.0,x=3.0}
  591. %{x=1,x=2.0,x=3.0}
  592. % 38) 2 real + 1 imaginary root.
  593. zz:=(x**2-8)*(x-5i);
  594. 2 3
  595. zz := - 5*i*x + 40*i + x - 8*x
  596. roots zz;
  597. {x= - 2.82843,x=2.82843,x=5.0*i}
  598. %{x= - 2.82843,x=2.82843,x=5.0*i}
  599. % 39) 2 complex roots.
  600. zz:= (x-1-2i)*(x+2+3i);
  601. 2
  602. zz := i*x - 7*i + x + x + 4
  603. roots zz;
  604. {x=-2.0 - 3.0*i,x=1 + 2.0*i}
  605. %{x=-2.0 - 3.0*i,x=1 + 2.0*i}
  606. % 40) 2 irrational complex roots.
  607. zz:= x**2+(3+2i)*x+7i;
  608. 2
  609. zz := 2*i*x + 7*i + x + 3*x
  610. roots zz;
  611. {x=-3.14936 + 0.212593*i,x=0.149358 - 2.21259*i}
  612. %{x=-3.14936 + 0.21259*i,x=0.149358 - 2.21259*i}
  613. % 41) 2 complex roots of very different magnitudes with small imaginary
  614. % parts.
  615. zz:= x**2+(1000000000+12i)*x-1000000000;
  616. 2
  617. zz := 12*i*x + x + 1000000000*x - 1000000000
  618. roots zz;
  619. {x=-1.0e+9 - 12.0*i,x=1 - 0.000000012*i}
  620. %{x=-1.0E+9 - 12.0*i,x=1 - 0.000000012*i}
  621. % 42) Multiple real and complex roots cause no difficulty, provided
  622. % that input is given in integer or rational form, (or if in decimal
  623. % fraction format, with switch rounded off or adjprec on and
  624. % coefficients input explicitly,) so that polynomial is stored exactly.
  625. zz :=(x**2-2i*x+5)**3*(x-2i)*(x-11/10)**2;
  626. 8 7 6 5 4
  627. zz := ( - 800*i*x + 1760*i*x - 6768*i*x + 12760*i*x - 25018*i*x
  628. 3 2 9
  629. + 39600*i*x - 46780*i*x + 55000*i*x - 30250*i + 100*x
  630. 8 7 6 5 4 3
  631. - 220*x - 779*x + 1980*x - 9989*x + 19580*x - 28269*x
  632. 2
  633. + 38500*x - 21175*x)/100
  634. roots zz;
  635. {x=-1.44949*i,
  636. x=-1.44949*i,
  637. x=-1.44949*i,
  638. x=3.44949*i,
  639. x=3.44949*i,
  640. x=3.44949*i,
  641. x=1.1,
  642. x=1.1,
  643. x=2.0*i}
  644. %{x=-1.44949*i, x=-1.44949*i, x=-1.44949*i,
  645. % x=3.44949*i, x=3.44949*i, x=3.44949*i, x=1.1, x=1.1, x=2.0*i}
  646. % 42a) would have failed in roots Mod 1.93 and previously (bug)
  647. realroots zz;
  648. {x=1.1,x=1.1}
  649. %{x=1.1,x=1.1}
  650. % 43) 2 real, 2 complex roots.
  651. zz:= (x**2-4)*(x**2+3i*x+5i);
  652. 3 2 4 2
  653. zz := 3*i*x + 5*i*x - 12*i*x - 20*i + x - 4*x
  654. roots zz;
  655. {x= - 2.0,
  656. x=2.0,
  657. x=-1.2714 + 0.466333*i,
  658. x=1.2714 - 3.46633*i}
  659. %{x= - 2.0,x=2.0,x=-1.2714 + 0.466333*i,x=1.2714 - 3.46633*i}
  660. % 44) 4 complex roots.
  661. zz:= x**4+(0.000001i)*x-16;
  662. 4
  663. i*x + 1000000*x - 16000000
  664. zz := -----------------------------
  665. 1000000
  666. roots zz;
  667. {x=-2.0 - 0.0000000625*i,
  668. x=-2.0*i,
  669. x=2.0*i,
  670. x=2.0 - 0.0000000625*i}
  671. %{x=-2.0 - 0.0000000625*i,x=-2.0*i,x=2.0*i,x=2.0 - 0.0000000625*i}
  672. % 45) 2 real, 2 complex roots.
  673. zz:= (x**2-4)*(x**2+2i*x+8);
  674. 3 4 2
  675. zz := 2*i*x - 8*i*x + x + 4*x - 32
  676. roots zz;
  677. {x= - 2.0,
  678. x=2.0,
  679. x=-4.0*i,
  680. x=2.0*i}
  681. %{x= - 2.0,x=2.0,x=-4.0*i,x=2.0*i}
  682. % 46) Using realroots to find only real roots.
  683. realroots zz;
  684. {x= - 2.0,x=2.0}
  685. %{x= - 2.0,x=2.0}
  686. % 47) Same example, applying nearestroot to find a single root.
  687. zz:= (x**2-4)*(x**2+2i*x+8);
  688. 3 4 2
  689. zz := 2*i*x - 8*i*x + x + 4*x - 32
  690. nearestroot(zz,1);
  691. {x=2.0}
  692. %{x=2.0}
  693. % 48) Same example, but focusing on imaginary point.
  694. nearestroot(zz,i);
  695. {x=2.0*i}
  696. %{x=2.0*i}
  697. % 49) The seed parameter can be complex also.
  698. nearestroot(zz,1+i);
  699. {x=2.0*i}
  700. %{x=2.0*i}
  701. % 50) One more nearestroot example. Nearest root to real point may be
  702. % complex.
  703. zz:= (x**2-4)*(x**2-i);
  704. 2 4 2
  705. zz := - i*x + 4*i + x - 4*x
  706. roots zz;
  707. {x= - 2.0,
  708. x=2.0,
  709. x=-0.707107 - 0.707107*i,
  710. x=0.707107 + 0.707107*i}
  711. %{x= - 2.0,x=2.0,x=-0.707107 - 0.707107*i,x=0.707107 + 0.707107*i}
  712. nearestroot (zz,1);
  713. {x=0.707107 + 0.707107*i}
  714. %{X=0.707107 + 0.707107*i}
  715. % 51) 1 real root plus 5 complex roots.
  716. zz:=(x**3-3i*x**2-5x+9)*(x**3-8);
  717. 5 2 6 4 3
  718. zz := - 3*i*x + 24*i*x + x - 5*x + x + 40*x - 72
  719. roots zz;
  720. {x=-1 + 1.73205*i,
  721. x=-1 - 1.73205*i,
  722. x=2.0,
  723. x=-2.41613 + 1.19385*i,
  724. x=0.981383 - 0.646597*i,
  725. x=1.43475 + 2.45274*i}
  726. %{x=-1 + 1.73205*i,x=-1 - 1.73205*i,x=2.0,
  727. % x=-2.41613 + 1.19385*i,x=0.981383 - 0.646597*i,x=1.43475 + 2.45274*i}
  728. nearestroot(zz,1);
  729. {x=0.981383 + 0.646597*i}
  730. %{x=0.981383 - 0.646597*i}
  731. % 52) roots can be computed to any accuracy desired, eg. (note that the
  732. % imaginary part of the second root is truncated because of its size,
  733. % and that the imaginary part of a complex root is never polished away,
  734. % even if it is smaller than the accuracy would require.)
  735. zz := x**3+10**(-20)*i*x**2+8;
  736. 2 3
  737. i*x + 100000000000000000000*x + 800000000000000000000
  738. zz := ---------------------------------------------------------
  739. 100000000000000000000
  740. rootacc 12;
  741. 12
  742. roots zz;
  743. {x=-2.0 - 3.33333333333e-21*i,x=1 - 1.73205080757*i,x
  744. =1 + 1.73205080757*i}
  745. rootacc 6;
  746. 6
  747. %{x=-2.0 - 3.33333333333E-21*i,x=1 - 1.73205080757*i,
  748. % x=1 + 1.73205080757*i}
  749. % 53) Precision of 12 required to find small imaginary root,
  750. % but standard accuracy can be used.
  751. zz := x**2+123456789i*x+1;
  752. 2
  753. zz := 123456789*i*x + x + 1
  754. roots zz;
  755. {x=-1.23457e+8*i,x=0.0000000081*i}
  756. %{x=-1.23457E+8*i,x=0.0000000081*i}
  757. % 54) Small real root is found with root 10*18 times larger(new).
  758. zz := (x+1)*(x**2+123456789*x+1);
  759. 3 2
  760. zz := x + 123456790*x + 123456790*x + 1
  761. roots zz;
  762. {x= - 1.23457e+8,x= - 1,x= - 0.0000000081}
  763. %{x= - 1.23457E+8,x= - 1,x= - 0.0000000081}
  764. % 55) 2 complex, 3 real irrational roots.
  765. ss := (45*x**2+(-10i+12)*x-10i)*(x**3-5x**2+1);
  766. 4 3 2 5 4
  767. ss := - 10*i*x + 40*i*x + 50*i*x - 10*i*x - 10*i + 45*x - 213*x
  768. 3 2
  769. - 60*x + 45*x + 12*x
  770. roots ss;
  771. {x= - 0.429174,
  772. x=0.469832,
  773. x=4.95934,
  774. x=-0.448056 - 0.19486*i,
  775. x=0.18139 + 0.417083*i}
  776. %{x= - 0.429174,x=0.469832,x=4.95934,
  777. % x=-0.448056 - 0.19486*i,x=0.18139 + 0.417083*i}
  778. % 56) Complex polynomial with floating coefficients.
  779. zz := x**2+1.2i*x+2.3i+6.7;
  780. 2
  781. 12*i*x + 23*i + 10*x + 67
  782. zz := ----------------------------
  783. 10
  784. roots zz;
  785. {x=-0.427317 + 2.09121*i,x=0.427317 - 3.29121*i}
  786. %{x=-0.427317 + 2.09121*i,x=0.427317 - 3.29121*i}
  787. % 56a) multiple roots will be found if coefficients read in exactly.
  788. % Exact read-in will occur unless dmode is rounded or complex-rounded.
  789. zz := x**3 + (1.09 - 2.4*i)*x**2 + (-1.44 - 2.616*i)*x + -1.5696;
  790. 2 3 2
  791. - 6000*i*x - 6540*i*x + 2500*x + 2725*x - 3600*x - 3924
  792. zz := -------------------------------------------------------------
  793. 2500
  794. roots zz;
  795. {x=1.2*i,x=1.2*i,x= - 1.09}
  796. %{x=1.2*i,x=1.2*i,x= - 1.09}
  797. % 57) Realroots, isolater and rlrootno accept 1, 2 or 3 arguments: (new)
  798. zz:= for j:=-1:3 product (x-j);
  799. 4 3 2
  800. zz := x*(x - 5*x + 5*x + 5*x - 6)
  801. rlrootno zz;
  802. 5
  803. % 5
  804. realroots zz;
  805. {x=0,
  806. x= - 1,
  807. x=1,
  808. x=2.0,
  809. x=3.0}
  810. %{x=0,x= -1,x=1,x=2.0,x=3.0}
  811. rlrootno(zz,positive);
  812. 3
  813. %positive selects positive, excluding 0.
  814. % 3
  815. rlrootno(zz,negative);
  816. 1
  817. %negative selects negative, excluding 0.
  818. % 1
  819. realroots(zz,positive);
  820. {x=1,x=2.0,x=3.0}
  821. %{x=1,x=2.0,x=3.0}
  822. rlrootno(zz,-1.5,2);
  823. 4
  824. %the format with 3 arguments selects a range.
  825. % 4
  826. realroots(zz,-1.5,2);
  827. {x=0,x= - 1,x=1,x=2.0}
  828. %the range is inclusive, except that:
  829. %{x=0,x= - 1,x=1,x=2.0}
  830. % A specific limit b may be excluded by using exclude b. Also, the
  831. % limits infinity and -infinity can be specified.
  832. realroots(zz,exclude 0,infinity);
  833. {x=1,x=2.0,x=3.0}
  834. % equivalent to realroots(zz,positive).
  835. %{x=1,x=2.0,x=3.0}
  836. rlrootno(zz,-infinity,exclude 0);
  837. 1
  838. % equivalent to rlrootno(zz,negative).
  839. % 1
  840. rlrootno(zz,-infinity,0);
  841. 2
  842. % 2
  843. rlrootno(zz,infinity,-infinity);
  844. 5
  845. %equivalent to rlrootno zz; (order of limits does not matter.)
  846. % 5
  847. realroots(zz,1,infinity);
  848. {x=1,x=2.0,x=3.0}
  849. % finds all real roots >= 1.
  850. %{x=1,x=2.0,x=3.0}
  851. realroots(zz,1,positive);
  852. {x=2.0,x=3.0}
  853. % finds all real roots > 1.
  854. %{x=2.0,x=3.0}
  855. % 57a) Bug corrected in mod 1.94. (handling of rational limits)
  856. zz := (x-1/3)*(x-1/5)*(x-1/7)*(x-1/11);
  857. 4 3 2
  858. 1155*x - 886*x + 236*x - 26*x + 1
  859. zz := --------------------------------------
  860. 1155
  861. realroots(zz,1/11,exclude(1/3));
  862. {x=0.0909091,x=0.142857,x=0.2}
  863. %{x=0.0909091,x=0.142857,x=0.2}
  864. realroots(zz,exclude(1/11),1/3);
  865. {x=0.142857,x=0.2,x=0.333333}
  866. %{x=0.142857,x=0.2,x=0.333333}
  867. % New capabilities added in mod 1.88.
  868. % 58) 3 complex roots, with two separated by very small real difference.
  869. zz :=(x+i)*(x+10**8i)*(x+10**8i+1);
  870. 2 3 2
  871. zz := 200000001*i*x + 100000001*i*x - 10000000000000000*i + x + x
  872. - 10000000200000000*x - 100000000
  873. roots zz;
  874. {x=-1 - 1.0e+8*i,x=-1.0e+8*i,x= - i}
  875. %{x=-1 - 1.0E+8*i,x=-1.0E+8*i,x= - i}
  876. % 59) Real polynomial with two complex roots separated by very small
  877. % imaginary part.
  878. zz:= (10**14x+123456789000000+i)*(10**14x+123456789000000-i);
  879. 2
  880. zz := 10000000000000000000000000000*x
  881. + 24691357800000000000000000000*x
  882. + 15241578750190521000000000001
  883. roots zz;
  884. {x=-1.23457 + 1.0e-14*i,x=-1.23457 - 1.0e-14*i}
  885. %{x=-1.23457 + 1.0E-14*i,x=-1.23457 - 1.0E-14*i}
  886. % 60) Real polynomial with two roots extremely close together.
  887. zz:= (x+2)*(10**10x+12345678901)*(10**10x+12345678900);
  888. 3 2
  889. zz := 100*(1000000000000000000*x + 4469135780100000000*x
  890. + 6462429435342508889*x + 3048315750285017778)
  891. roots zz;
  892. {x= - 2.0,x= - 1.2345678901,x= - 1.23456789}
  893. %{x= - 2.0,x= - 1.2345678901,x= - 1.23456789}
  894. % 61) Real polynomial with multiple root extremely close to simple root.
  895. zz:= (x-12345678/10000000)*(x-12345679/10000000)**2;
  896. 3 2
  897. zz := (500000000000000000000*x - 1851851800000000000000*x
  898. + 2286236726108825000000*x - 940838132549050755399)/
  899. 500000000000000000000
  900. roots zz;
  901. {x=1.2345679,x=1.2345679,x=1.2345678}
  902. %{x=1.2345679,x=1.2345679,x=1.2345678}
  903. % 62) Similar problem using realroots.
  904. zz:=(x-2**30/10**8)**2*(x-(2**30+1)/10**8);
  905. 3 2
  906. zz := (610351562500000000*x - 19660800006103515625*x
  907. + 211106232664064000000*x - 755578637962830675968)/
  908. 610351562500000000
  909. realroots zz;
  910. {x=10.73741824,x=10.73741824,x=10.73741825}
  911. %{x=10.73741824,x=10.73741824,x=10.73741825}
  912. % 63) Three complex roots with small real separation between two.
  913. zz:= (x-i)*(x-1-10**8i)*(x-2-10**8i);
  914. 2 3
  915. zz := - 200000001*i*x + 300000003*i*x + 9999999999999998*i + x
  916. 2
  917. - 3*x - 10000000199999998*x + 300000000
  918. roots zz;
  919. {x=i,x=1 + 1.0e+8*i,x=2.0 + 1.0e+8*i}
  920. %{x=i,x=1 + 1.0E+8*i,x=2.0 + 1.0E+8*i}
  921. % 64) Use of nearestroot to isolate one of the close roots.
  922. nearestroot(zz,10**8i+99/100);
  923. {x=1 + 1.0e+8*i}
  924. %{x=1 + 1.0E+8*i}
  925. % 65) Slightly more complicated example with close complex roots.
  926. zz:= (x-i)*(10**8x-1234-10**12i)*(10**8x-1233-10**12i);
  927. 2
  928. zz := 2*( - 100005000000000000000*i*x + 1233623350000000*i*x
  929. 3
  930. + 499999999999999999239239*i + 5000000000000000*x
  931. 2
  932. - 123350000000*x - 500099999999999999239239*x
  933. + 1233500000000000)
  934. roots zz;
  935. {x=i,x=0.00001233 + 10000.0*i,x=0.00001234 + 10000.0*i}
  936. %{x=i,x=0.00001233 + 10000.0*i,x=0.00001234 + 10000.0*i}
  937. % 66) Four closely spaced real roots with varying spacings.
  938. zz:= (x-1+1/10**7)*(x-1+1/10**8)*(x-1)*(x-1-1/10**7);
  939. 4 3
  940. zz := (10000000000000000000000*x - 39999999900000000000000*x
  941. 2
  942. + 59999999699999900000000*x - 39999999699999800000001*x
  943. + 9999999899999900000001)/10000000000000000000000
  944. roots zz;
  945. {x=0.9999999,
  946. x=0.99999999,
  947. x=1,
  948. x=1.0000001}
  949. %{x=0.9999999,x=0.99999999,x=1,x=1.0000001}
  950. % 67) Complex pair plus two close real roots.
  951. zz:= (x**2+1)*(x-12345678/10000000)*(x-12345679/10000000);
  952. 4 3 2
  953. zz := (50000000000000*x - 123456785000000*x + 126207888812681*x
  954. - 123456785000000*x + 76207888812681)/50000000000000
  955. roots zz;
  956. {x=i,
  957. x= - i,
  958. x=1.2345678,
  959. x=1.2345679}
  960. %{x=i,x= - i,x=1.2345678,x=1.2345679}
  961. % 68) Same problem using realroots to find only real roots.
  962. realroots zz;
  963. {x=1.2345678,x=1.2345679}
  964. %{x=1.2345678,x=1.2345679}
  965. % The switch ratroot causes output to be given in rational form.
  966. % 69) Two complex roots with output in rational form.
  967. on ratroot,complex;
  968. zz:=x**2-(5i+1)*x+1;
  969. 2
  970. zz := x - (1 + 5*i)*x + 1
  971. sss:= roots zz;
  972. 346859 - 1863580*i 482657 + 2593180*i
  973. sss := {x=--------------------,x=--------------------}
  974. 10000000 500000
  975. % 346859 - 1863580*i 482657 + 2593180*i
  976. %sss := {x=--------------------,x=--------------------}
  977. % 10000000 500000
  978. % With roots in rational form, mkpoly can be used to reconstruct a
  979. % polynomial.
  980. zz1 := mkpoly sss;
  981. 2
  982. zz1 := 5000000000000*x - (4999999500000 + 25000010000000*i)*x
  983. + 5000012308763 - 2110440*i
  984. % 2
  985. %zz1 := 5000000000000*x - (4999999500000 + 25000010000000*i)*x
  986. %
  987. % + 5000012308763 - 2110440*i
  988. % Finding the roots of the new polynomial zz1.
  989. rr:= roots zz1;
  990. 346859 - 1863580*i 482657 + 2593180*i
  991. rr := {x=--------------------,x=--------------------}
  992. 10000000 500000
  993. % 346859 - 1863580*i 482657 + 2593180*i
  994. %rr := {x=--------------------,x=--------------------}
  995. % 10000000 500000
  996. % The roots are stable to the extent that rr=ss, although zz1 and
  997. % zz may differ.
  998. zz1 - zz;
  999. 2
  1000. 4999999999999*x - (4999999499999 + 25000009999995*i)*x
  1001. + 5000012308762 - 2110440*i
  1002. % 2
  1003. %4999999999999*x - (4999999499999 + 25000009999995*i)*x
  1004. %
  1005. % + 5000012308762 - 2110440*i
  1006. % 70) Same type of problem in which roots are found exactly.
  1007. zz:=(x-10**8+i)*(x-10**8-i)*(x-10**8+3i/2)*(x-i);
  1008. 4 3 2
  1009. zz := (2*x - (600000000 - i)*x + 60000000000000005*x
  1010. - (2000000000000000800000000 + 29999999999999999*i)*x
  1011. + (30000000000000003 + 2000000000000000200000000*i))/2
  1012. rr := roots zz;
  1013. rr := {x=100000000 + i,
  1014. x=100000000 - i,
  1015. x=i,
  1016. 200000000 - 3*i
  1017. x=-----------------}
  1018. 2
  1019. % 4 3 2
  1020. %zz := (2*x - (600000000 - i)*x + 60000000000000005*x
  1021. %
  1022. % - (2000000000000000800000000 + 29999999999999999*i)*x
  1023. %
  1024. % + (30000000000000003 + 2000000000000000200000000*i))/2
  1025. %rr := {x=100000000 + i,x=100000000 - i,x=i,
  1026. %
  1027. % 200000000 - 3*i
  1028. % x=-----------------}
  1029. % 2
  1030. % Reconstructing a polynomial from the roots.
  1031. ss := mkpoly rr;
  1032. 4 3 2
  1033. ss := 2*x - (600000000 - i)*x + 60000000000000005*x
  1034. - (2000000000000000800000000 + 29999999999999999*i)*x
  1035. + (30000000000000003 + 2000000000000000200000000*i)
  1036. % 4 3 2
  1037. %ss := 2*x - (600000000 - i)*x + 60000000000000005*x
  1038. %
  1039. % - (2000000000000000800000000 + 29999999999999999*i)*x
  1040. %
  1041. % + (30000000000000003 + 2000000000000000200000000*i)
  1042. % In this case, the same polynomial is obtained.
  1043. ss - num zz;
  1044. 0
  1045. % 0
  1046. % 71) Finding one of the complex roots using nearestroot.
  1047. nearestroot(zz,10**8-2i);
  1048. 200000000 - 3*i
  1049. {x=-----------------}
  1050. 2
  1051. % 200000000 - 3*I
  1052. %{x=-----------------}
  1053. % 2
  1054. % Finding the other complex root using nearestroot.
  1055. nearestroot(zz,10**8+2i);
  1056. {x=100000000 + i}
  1057. %{x=100000000 + I}
  1058. % 72) A realroots problem which requires accuracy increase to avoid
  1059. % confusion of two roots.
  1060. zz:=(x+1)*(10000000x-19999999)*(1000000x-2000001)*(x-2);
  1061. 4 3 2
  1062. zz := 10000000000000*x - 50000009000000*x + 60000026999999*x
  1063. + 40000000000001*x - 80000035999998
  1064. realroots zz;
  1065. {x= - 1,
  1066. 19999999
  1067. x=----------,
  1068. 10000000
  1069. x=2,
  1070. 2000001
  1071. x=---------}
  1072. 1000000
  1073. % 19999999 2000001
  1074. % {x=-1,x=----------,x=2,x=---------}
  1075. % 10000000 1000000
  1076. % 73) Without the accuracy increase, this example would produce the
  1077. % obviously incorrect answer 2.
  1078. realroots(zz,3/2,exclude 2);
  1079. 19999999
  1080. {x=----------}
  1081. 10000000
  1082. % 19999999
  1083. % {x=----------}
  1084. % 10000000
  1085. % Rlrootno also gives the correct answer in this case.
  1086. rlrootno(zz,3/2,exclude 2);
  1087. 1
  1088. % 1
  1089. % 74) Roots works equally well in this problem.
  1090. rr := roots zz;
  1091. rr := {x= - 1,
  1092. 19999999
  1093. x=----------,
  1094. 10000000
  1095. x=2,
  1096. 2000001
  1097. x=---------}
  1098. 1000000
  1099. % 19999999 2000001
  1100. %rr := {x= - 1,x=----------,x=2,x=---------}
  1101. % 10000000 1000000
  1102. % 75) The function getroot is convenient for obtaining the value of a
  1103. % root.
  1104. rr1 := getroot(1,rr);
  1105. rr1 := -1
  1106. % 19999999
  1107. % rr1 := ----------
  1108. % 10000000
  1109. % 76) For example, the value can be used as an argument to nearestroot.
  1110. nearestroot(zz,rr1);
  1111. {x= - 1}
  1112. % 19999999
  1113. % {x=----------}
  1114. % 10000000
  1115. comment New capabilities added to Mod 1.90 for avoiding floating point
  1116. exceptions and exceeding iteration limits.;
  1117. % 77) This and the next example would previously have aborted because
  1118. %of exceeding iteration limits:
  1119. off ratroot;
  1120. zz := x**16 - 900x**15 -2;
  1121. 16 15
  1122. zz := x - 900*x - 2
  1123. roots zz;
  1124. {x= - 0.665423,
  1125. x=-0.607902 + 0.270641*i,
  1126. x=-0.607902 - 0.270641*i,
  1127. x=-0.44528 + 0.494497*i,
  1128. x=-0.44528 - 0.494497*i,
  1129. x=-0.205664 + 0.632867*i,
  1130. x=-0.205664 - 0.632867*i,
  1131. x=0.069527 + 0.661817*i,
  1132. x=0.069527 - 0.661817*i,
  1133. x=0.332711 + 0.57633*i,
  1134. x=0.332711 - 0.57633*i,
  1135. x=0.538375 + 0.391176*i,
  1136. x=0.538375 - 0.391176*i,
  1137. x=0.650944 + 0.138369*i,
  1138. x=0.650944 - 0.138369*i,
  1139. x=900.0}
  1140. %{x= - 0.665423,x=-0.607902 + 0.270641*i,x=-0.607902 - 0.270641*i,
  1141. % x=-0.44528 + 0.494497*i, x=-0.44528 - 0.494497*i,
  1142. % x=-0.205664 + 0.632867*i,x=-0.205664 - 0.632867*i,
  1143. % x=0.069527 + 0.661817*i,x=0.069527 - 0.661817*i,
  1144. % x=0.332711 + 0.57633*i,x=0.332711 - 0.57633*i,
  1145. % x=0.538375 + 0.391176*i,x=0.538375 - 0.391176*i,
  1146. % x=0.650944 + 0.138369*i,x=0.650944 - 0.138369*i,x=900.0}
  1147. % 78) a still harder example.
  1148. zz := x**30 - 900x**29 - 2;
  1149. 30 29
  1150. zz := x - 900*x - 2
  1151. roots zz;
  1152. {x= - 0.810021,
  1153. x=-0.791085 + 0.174125*i,
  1154. x=-0.791085 - 0.174125*i,
  1155. x=-0.735162 + 0.340111*i,
  1156. x=-0.735162 - 0.340111*i,
  1157. x=-0.644866 + 0.490195*i,
  1158. x=-0.644866 - 0.490195*i,
  1159. x=-0.524417 + 0.617362*i,
  1160. x=-0.524417 - 0.617362*i,
  1161. x=-0.379447 + 0.715665*i,
  1162. x=-0.379447 - 0.715665*i,
  1163. x=-0.216732 + 0.780507*i,
  1164. x=-0.216732 - 0.780507*i,
  1165. x=-0.04388 + 0.808856*i,
  1166. x=-0.04388 - 0.808856*i,
  1167. x=0.131027 + 0.799383*i,
  1168. x=0.131027 - 0.799383*i,
  1169. x=0.299811 + 0.752532*i,
  1170. x=0.299811 - 0.752532*i,
  1171. x=0.454578 + 0.67049*i,
  1172. x=0.454578 - 0.67049*i,
  1173. x=0.588091 + 0.557094*i,
  1174. x=0.588091 - 0.557094*i,
  1175. x=0.694106 + 0.417645*i,
  1176. x=0.694106 - 0.417645*i,
  1177. x=0.767663 + 0.258664*i,
  1178. x=0.767663 - 0.258664*i,
  1179. x=0.805322 + 0.0875868*i,
  1180. x=0.805322 - 0.0875868*i,
  1181. x=900.0}
  1182. %{x= - 0.810021,x=-0.791085 + 0.174125*i,x=-0.791085 - 0.174125*i,
  1183. % x=-0.735162 + 0.340111*i,x=-0.735162 - 0.340111*i,
  1184. % x=-0.644866 + 0.490195*i,x=-0.644866 - 0.490195*i,
  1185. % x=-0.524417 + 0.617362*i,x=-0.524417 - 0.617362*i,
  1186. % x=-0.379447 + 0.715665*i,x=-0.379447 - 0.715665*i,
  1187. % x=-0.216732 + 0.780507*i,x=-0.216732 - 0.780507*i,
  1188. % x=-0.04388 + 0.808856*i,x=-0.04388 - 0.808856*i,
  1189. % x=0.131027 + 0.799383*i,x=0.131027 - 0.799383*i,
  1190. % x=0.299811 + 0.752532*i,x=0.299811 - 0.752532*i,
  1191. % x=0.454578 + 0.67049*i,x=0.454578 - 0.67049*i,
  1192. % x=0.588091 + 0.557094*i,x=0.588091 - 0.557094*i,
  1193. % x=0.694106 + 0.417645*i,x=0.694106 - 0.417645*i,
  1194. % x=0.767663 + 0.258664*i,x=0.767663 - 0.258664*i,
  1195. % x=0.805322 + 0.0875868*i,x=0.805322 - 0.0875868*i,x=900.0}
  1196. % 79) this deceptively simple example previously caused floating point
  1197. % overflows on some systems:
  1198. aa := x**6 - 4*x**3 + 2;
  1199. 6 3
  1200. aa := x - 4*x + 2
  1201. realroots aa;
  1202. {x=0.836719,x=1.50579}
  1203. %{x=0.836719,x=1.50579}
  1204. % 80) a harder problem, which would have failed on almost all systems:
  1205. rr := x**16 - 90000x**15 - x**2 -2;
  1206. 16 15 2
  1207. rr := x - 90000*x - x - 2
  1208. realroots rr;
  1209. {x= - 0.493299,x=90000.0}
  1210. %{x= - 0.493299,x=90000.0}
  1211. % 81) this example would have failed because of floating point
  1212. % exceptions on almost all computer systems.
  1213. rr := x**30 - 9*10**10*x**29 - 2;
  1214. 30 29
  1215. rr := x - 90000000000*x - 2
  1216. realroots rr;
  1217. {x= - 0.429188,x=9.0e+10}
  1218. %{x= - 0.429188,x=9.0E+10}
  1219. % 82) a test of allroot on this example.
  1220. % This example is commented out because it takes significant time
  1221. % without breaking new ground.
  1222. %**% roots rr;
  1223. %{x= - 0.429188,
  1224. % x=-0.419154 + 0.092263*i,x=-0.419154 - 0.092263*i,
  1225. % x=-0.389521 + 0.180211*i,x=-0.389521 - 0.180211*i,
  1226. % x=-0.341674 + 0.259734*i,x=-0.341674 - 0.259734*i,
  1227. % x=-0.277851 + 0.327111*i,x=-0.277851 - 0.327111*i,
  1228. % x=-0.201035 + 0.379193*i,x=-0.201035 - 0.379193*i,
  1229. % x=-0.11482 + 0.413544*i,x=-0.11482 - 0.413544*i,
  1230. % x=-0.0232358 + 0.428559*i,x=-0.0232358 - 0.428559*i,
  1231. % x=0.0694349 + 0.423534*i,x=0.0694349 - 0.423534*i,
  1232. % x=0.158859 + 0.398706*i,x=0.158859 - 0.398706*i,
  1233. % x=0.240855 + 0.355234*i,x=0.240855 - 0.355234*i,
  1234. % x=0.311589 + 0.295153*i,x=0.311589 - 0.295153*i,
  1235. % x=0.367753 + 0.22127*i,x=0.367753 - 0.22127*i,
  1236. % x=0.406722 + 0.13704*i,x=0.406722 - 0.13704*i,
  1237. % x=0.426672 + 0.0464034*i,x=0.426672 - 0.0464034*i,x=9.0E+10}
  1238. % 83) test of starting point for iteration: no convergence if good
  1239. % real starting point is not found.
  1240. zz := x**30 -9*10**12x**29 -2;
  1241. 30 29
  1242. zz := x - 9000000000000*x - 2
  1243. firstroot zz;
  1244. {x= - 0.36617}
  1245. %{x= - 0.36617}
  1246. % 84) a case in which there are no real roots and good imaginary
  1247. % starting point must be used or roots cannot be found.
  1248. zz:= 9x**16 - x**5 +1;
  1249. 16 5
  1250. zz := 9*x - x + 1
  1251. roots zz;
  1252. {x=-0.866594 + 0.193562*i,
  1253. x=-0.866594 - 0.193562*i,
  1254. x=-0.697397 + 0.473355*i,
  1255. x=-0.697397 - 0.473355*i,
  1256. x=-0.510014 + 0.716449*i,
  1257. x=-0.510014 - 0.716449*i,
  1258. x=-0.161318 + 0.87905*i,
  1259. x=-0.161318 - 0.87905*i,
  1260. x=0.182294 + 0.828368*i,
  1261. x=0.182294 - 0.828368*i,
  1262. x=0.459373 + 0.737443*i,
  1263. x=0.459373 - 0.737443*i,
  1264. x=0.748039 + 0.494348*i,
  1265. x=0.748039 - 0.494348*i,
  1266. x=0.845617 + 0.142879*i,
  1267. x=0.845617 - 0.142879*i}
  1268. %{x=-0.866594 + 0.193562*i,x=-0.866594 - 0.193562*i,
  1269. % x=-0.697397 + 0.473355*i,x=-0.697397 - 0.473355*i,
  1270. % x=-0.510014 + 0.716449*i,x=-0.510014 - 0.716449*i,
  1271. % x=-0.161318 + 0.87905*i,x=-0.161318 - 0.87905*i,
  1272. % x=0.182294 + 0.828368*i,x=0.182294 - 0.828368*i,
  1273. % x=0.459373 + 0.737443*i,x=0.459373 - 0.737443*i,
  1274. % x=0.748039 + 0.494348*i,x=0.748039 - 0.494348*i,
  1275. % x=0.845617 + 0.142879*i,x=0.845617 - 0.142879*i}
  1276. % 85) five complex roots.
  1277. zz := x**5 - x**3 + i;
  1278. 5 3
  1279. zz := x - x + i
  1280. roots zz;
  1281. {x=-1.16695 - 0.217853*i,
  1282. x=-0.664702 + 0.636663*i,
  1283. x=-0.83762*i,
  1284. x=0.664702 + 0.636663*i,
  1285. x=1.16695 - 0.217853*i}
  1286. %{x=-1.16695 - 0.217853*i,x=-0.664702 + 0.636663*i,x=-0.83762*i,
  1287. % x=0.664702 + 0.636663*i,x=1.16695 - 0.217853*i}
  1288. % Additional capabilities in Mod 1.91.
  1289. % 86) handling of polynomial with huge or infinitesimal coefficients.
  1290. precision reset;
  1291. 12
  1292. on rounded;
  1293. *** Domain mode complex changed to complex-rounded
  1294. precision reset;
  1295. 12
  1296. % so that the system will start this example in floating point. Rounded
  1297. % is on so that the polynomial won't fill the page!
  1298. zz:= 1.0e-500x**3+x**2+x;
  1299. *** ROUNDBF turned on to increase accuracy
  1300. 2
  1301. zz := x*(1.0e-500*x + x + 1)
  1302. roots zz;
  1303. {x=0,x= - 1.0e+500,x= - 1}
  1304. off rounded;
  1305. *** Domain mode complex-rounded changed to complex
  1306. % rounded not normally needed for roots.
  1307. %{x=0,x= - 1.0E+500,x= - 1}
  1308. off roundbf;
  1309. comment Switch roundbf will have been turned on in the last example in
  1310. most computer systems. This will inhibit the use of hardware floating
  1311. point unless roundbf is turned off.
  1312. Polynomials which make use of powergcd substitution and cascaded
  1313. solutions.
  1314. Uncomplicated cases.;
  1315. switch powergcd;
  1316. % introduced here to verify that same answers are
  1317. % obtained with and without employing powergcd strategy. Roots are
  1318. % found faster for applicable cases when !*powergcd=t (default state.)
  1319. % 87) powergcd done at the top level.
  1320. zz := x**12-5x**9+1;
  1321. 12 9
  1322. zz := x - 5*x + 1
  1323. roots zz;
  1324. {x=-0.783212 + 0.276071*i,
  1325. x=0.152522 - 0.816316*i,
  1326. x=0.63069 + 0.540246*i,
  1327. x=-0.783212 - 0.276071*i,
  1328. x=0.152522 + 0.816316*i,
  1329. x=0.63069 - 0.540246*i,
  1330. x=-0.424222 + 0.734774*i,
  1331. x=-0.424222 - 0.734774*i,
  1332. x=0.848444,
  1333. x=-0.85453 + 1.48009*i,
  1334. x=-0.85453 - 1.48009*i,
  1335. x=1.70906}
  1336. %{x=-0.783212 + 0.276071*i,x=0.152522 - 0.816316*i,
  1337. % x=0.63069 + 0.540246*i,x=-0.783212 - 0.276071*i,
  1338. % x=0.152522 + 0.816316*i,x=0.63069 - 0.540246*i,
  1339. % x=-0.424222 + 0.734774*i,x=-0.424222 - 0.734774*i,x=0.848444,
  1340. % x=-0.85453 + 1.48009*i,x=-0.85453 - 1.48009*i,x=1.70906}
  1341. off powergcd;
  1342. roots zz;
  1343. {x=-0.85453 + 1.48009*i,
  1344. x=-0.85453 - 1.48009*i,
  1345. x=-0.783212 + 0.276071*i,
  1346. x=-0.783212 - 0.276071*i,
  1347. x=-0.424222 + 0.734774*i,
  1348. x=-0.424222 - 0.734774*i,
  1349. x=0.152522 + 0.816316*i,
  1350. x=0.152522 - 0.816316*i,
  1351. x=0.63069 + 0.540246*i,
  1352. x=0.63069 - 0.540246*i,
  1353. x=0.848444,
  1354. x=1.70906}
  1355. on powergcd;
  1356. %{x=-0.85453 + 1.48009*i,x=-0.85453 - 1.48009*i,
  1357. % x=-0.783212 + 0.276071*i,x=-0.783212 - 0.276071*i,
  1358. % x=-0.424222 + 0.734774*i,x=-0.424222 - 0.734774*i,
  1359. % x=0.152522 + 0.816316*i,x=0.152522 - 0.816316*i,
  1360. % x=0.63069 + 0.540246*i,x=0.63069 - 0.540246*i,x=0.848444,x=1.70906}
  1361. % 88) powergcd done after square free factoring.
  1362. zz := (x-1)**2*zz;
  1363. 14 13 12 11 10 9 2
  1364. zz := x - 2*x + x - 5*x + 10*x - 5*x + x - 2*x + 1
  1365. roots zz;
  1366. {x=1,
  1367. x=1,
  1368. x=-0.783212 + 0.276071*i,
  1369. x=0.152522 - 0.816316*i,
  1370. x=0.63069 + 0.540246*i,
  1371. x=-0.783212 - 0.276071*i,
  1372. x=0.152522 + 0.816316*i,
  1373. x=0.63069 - 0.540246*i,
  1374. x=-0.424222 + 0.734774*i,
  1375. x=-0.424222 - 0.734774*i,
  1376. x=0.848444,
  1377. x=-0.85453 + 1.48009*i,
  1378. x=-0.85453 - 1.48009*i,
  1379. x=1.70906}
  1380. %{x=1,x=1,
  1381. % x=-0.783212 + 0.276071*i,x=0.152522 - 0.816316*i,
  1382. % x=0.63069 + 0.540246*i,x=-0.783212 - 0.276071*i,
  1383. % x=0.152522 + 0.816316*i,x=0.63069 - 0.540246*i,
  1384. % x=-0.424222 + 0.734774*i,x=-0.424222 - 0.734774*i,x=0.848444,
  1385. % x=-0.85453 + 1.48009*i,x=-0.85453 - 1.48009*i,x=1.70906}
  1386. off powergcd;
  1387. roots zz;
  1388. {x=1,
  1389. x=1,
  1390. x=-0.85453 + 1.48009*i,
  1391. x=-0.85453 - 1.48009*i,
  1392. x=-0.783212 + 0.276071*i,
  1393. x=-0.783212 - 0.276071*i,
  1394. x=-0.424222 + 0.734774*i,
  1395. x=-0.424222 - 0.734774*i,
  1396. x=0.152522 + 0.816316*i,
  1397. x=0.152522 - 0.816316*i,
  1398. x=0.63069 + 0.540246*i,
  1399. x=0.63069 - 0.540246*i,
  1400. x=0.848444,
  1401. x=1.70906}
  1402. on powergcd;
  1403. %{x=1,x=1,
  1404. % x=-0.85453 + 1.48009*i,x=-0.85453 - 1.48009*i,
  1405. % x=-0.783212 + 0.276071*i,x=-0.783212 - 0.276071*i,
  1406. % x=-0.424222 + 0.734774*i,x=-0.424222 - 0.734774*i,
  1407. % x=0.152522 + 0.816316*i,x=0.152522 - 0.816316*i,
  1408. % x=0.63069 + 0.540246*i,x=0.63069 - 0.540246*i,
  1409. % x=0.848444,x=1.70906}
  1410. % 89) powergcd done after separation into real and complex polynomial.
  1411. zz := x**5-i*x**4+x**3-i*x**2+x-i;
  1412. 5 4 3 2
  1413. zz := x - i*x + x - i*x + x - i
  1414. roots zz;
  1415. {x=-0.5 - 0.866025*i,
  1416. x=0.5 + 0.866025*i,
  1417. x=-0.5 + 0.866025*i,
  1418. x=0.5 - 0.866025*i,
  1419. x=i}
  1420. %{x=-0.5 - 0.866025*i,x=0.5 + 0.866025*i,
  1421. % x=-0.5 + 0.866025*i,x=0.5 - 0.866025*i,x=i}
  1422. off powergcd;
  1423. roots zz;
  1424. {x=-0.5 + 0.866025*i,
  1425. x=-0.5 - 0.866025*i,
  1426. x=0.5 + 0.866025*i,
  1427. x=0.5 - 0.866025*i,
  1428. x=i}
  1429. on powergcd;
  1430. %{x=-0.5 + 0.866025*i,x=-0.5 - 0.866025*i,
  1431. % x=0.5 + 0.866025*i,x=0.5 - 0.866025*i,x=i}
  1432. % Cases where root separation requires accuracy and/or precision
  1433. % increase. In some examples we get excess accuracy, but it is hard
  1434. % avoid this and still get all roots separated.
  1435. % 90) accuracy increase required to separate close roots;
  1436. let x=y**2;
  1437. zz:= (x-3)*(100000000x-300000001);
  1438. 4 2
  1439. zz := 100000000*y - 600000001*y + 900000003
  1440. roots zz;
  1441. {y= - 1.732050808,
  1442. y=1.732050808,
  1443. y= - 1.73205081,
  1444. y=1.73205081}
  1445. %{y= - 1.732050808,y=1.732050808,y= - 1.73205081,y=1.73205081}
  1446. off powergcd;
  1447. roots zz;
  1448. {y= - 1.73205081,
  1449. y= - 1.732050808,
  1450. y=1.732050808,
  1451. y=1.73205081}
  1452. on powergcd;
  1453. %{y= - 1.73205081,y= - 1.732050808,y=1.732050808,y=1.73205081}
  1454. % 91) roots to be separated are on different square free factors.
  1455. zz:= (x-3)**2*(10000000x-30000001);
  1456. 6 4 2
  1457. zz := 10000000*y - 90000001*y + 270000006*y - 270000009
  1458. roots zz;
  1459. {y= - 1.73205081,
  1460. y= - 1.73205081,
  1461. y=1.73205081,
  1462. y=1.73205081,
  1463. y= - 1.73205084,
  1464. y=1.73205084}
  1465. %{y= - 1.73205081,y= - 1.73205081,y=1.73205081,y=1.73205081,
  1466. % y= - 1.73205084,y=1.73205084}
  1467. off powergcd;
  1468. roots zz;
  1469. {y= - 1.73205081,
  1470. y= - 1.73205081,
  1471. y=1.73205081,
  1472. y=1.73205081,
  1473. y= - 1.73205084,
  1474. y=1.73205084}
  1475. on powergcd;
  1476. %{y= - 1.73205081,y= - 1.73205081,y=1.73205081,y=1.73205081,
  1477. % y= - 1.73205084,y=1.73205084}
  1478. % 91a) A new capability for nearestroot:
  1479. nearestroot(zz,1.800000000001);
  1480. *** precision increased to 13
  1481. {y=1.732050836436}
  1482. % should find the root to 13 places.
  1483. %{y=1.732050836436}
  1484. % 92) roots must be separated in the complex polynomial factor only.
  1485. zz :=(y+1)*(x+10**8i)*(x+10**8i+1);
  1486. 5 4 3 2
  1487. zz := y + y + (1 + 200000000*i)*y + (1 + 200000000*i)*y
  1488. - (10000000000000000 - 100000000*i)*y
  1489. - (10000000000000000 - 100000000*i)
  1490. roots zz;
  1491. {y= - 1,
  1492. y=-7071.067777 + 7071.067847*i,
  1493. y=7071.067777 - 7071.067847*i,
  1494. y=-7071.067812 + 7071.067812*i,
  1495. y=7071.067812 - 7071.067812*i}
  1496. %{y= - 1,
  1497. % y=-7071.067777 + 7071.067847*i,y=7071.067777 - 7071.067847*i,
  1498. % y=-7071.067812 + 7071.067812*i,y=7071.067812 - 7071.067812*i}
  1499. % 93)
  1500. zz := (x-2)**2*(1000000x-2000001)*(y-1);
  1501. 7 6 5 4 3
  1502. zz := 1000000*y - 1000000*y - 6000001*y + 6000001*y + 12000004*y
  1503. 2
  1504. - 12000004*y - 8000004*y + 8000004
  1505. roots zz;
  1506. {y= - 1.4142136,
  1507. y= - 1.4142136,
  1508. y=1.4142136,
  1509. y=1.4142136,
  1510. y= - 1.4142139,
  1511. y=1,
  1512. y=1.4142139}
  1513. %{y= - 1.4142136,y= - 1.4142136,y=1.4142136,y=1.4142136,
  1514. % y= - 1.4142139,y=1,y=1.4142139}
  1515. % 94)
  1516. zz := (x-2)*(10000000x-20000001);
  1517. 4 2
  1518. zz := 10000000*y - 40000001*y + 40000002
  1519. roots zz;
  1520. {y= - 1.41421356,
  1521. y=1.41421356,
  1522. y= - 1.4142136,
  1523. y=1.4142136}
  1524. %{y= - 1.41421356 ,y=1.41421356 ,y= - 1.4142136,y=1.4142136}
  1525. % 95)
  1526. zz := (x-3)*(10000000x-30000001);
  1527. 4 2
  1528. zz := 10000000*y - 60000001*y + 90000003
  1529. roots zz;
  1530. {y= - 1.73205081,
  1531. y=1.73205081,
  1532. y= - 1.73205084,
  1533. y=1.73205084}
  1534. %{y= - 1.73205081 ,y=1.73205081 ,y= - 1.73205084 ,y=1.73205084}
  1535. % 96)
  1536. zz := (x-9)**2*(1000000x-9000001);
  1537. 6 4 2
  1538. zz := 1000000*y - 27000001*y + 243000018*y - 729000081
  1539. roots zz;
  1540. {y= - 3.0,
  1541. y= - 3.0,
  1542. y=3.0,
  1543. y=3.0,
  1544. y= - 3.00000017,
  1545. y=3.00000017}
  1546. %{y= - 3.0,y= - 3.0,y=3.0,y=3.0,y= - 3.00000017,y=3.00000017}
  1547. % 97)
  1548. zz := (x-3)**2*(1000000x-3000001);
  1549. 6 4 2
  1550. zz := 1000000*y - 9000001*y + 27000006*y - 27000009
  1551. roots zz;
  1552. {y= - 1.7320508,
  1553. y= - 1.7320508,
  1554. y=1.7320508,
  1555. y=1.7320508,
  1556. y= - 1.7320511,
  1557. y=1.7320511}
  1558. %{y= - 1.7320508,y= - 1.7320508,y=1.7320508,y=1.7320508,
  1559. % y= - 1.7320511,y=1.7320511}
  1560. % 98) the accuracy of the root sqrt 5 depends upon another close root.
  1561. % Although one of the factors is given in decimal notation, it is not
  1562. % necessary to turn rounded on.
  1563. rootacc 10;
  1564. 10
  1565. % using rootacc to specify the minumum desired accuracy.
  1566. zz := (y^2-5)*(y-2.2360679775);
  1567. 3 2
  1568. 400000000*y - 894427191*y - 2000000000*y + 4472135955
  1569. zz := ---------------------------------------------------------
  1570. 400000000
  1571. % in this case, adding one place to the root near sqrt 5 causes a
  1572. % required increase of 4 places in accuracy of the root at sqrt 5.
  1573. roots zz;
  1574. *** precision increased to 14
  1575. {y= - 2.236067977,y=2.2360679774998,y=2.2360679775}
  1576. %{y= - 2.236067977,y=2.2360679774998,y=2.2360679775}
  1577. realroots zz;
  1578. {y= - 2.236067977,y=2.2360679774998,y=2.2360679775}
  1579. % should get the same answer from realroots.
  1580. %{y= - 2.2360679775,y=2.2360679774998,y=2.2360679775}
  1581. % 99) The same thing also happens when the root near sqrt 5 is on a
  1582. % different square-free factor.
  1583. zz := (y^2-5)^2*(y-2.2360679775);
  1584. 5 4 3 2
  1585. zz := (400000000*y - 894427191*y - 4000000000*y + 8944271910*y
  1586. + 10000000000*y - 22360679775)/400000000
  1587. roots zz;
  1588. {y= - 2.236067977,
  1589. y= - 2.236067977,
  1590. y=2.2360679774998,
  1591. y=2.2360679774998,
  1592. y=2.2360679775}
  1593. %{y= - 2.236067977,y= - 2.236067977,y=2.2360679774998,
  1594. % y=2.2360679774998,y=2.2360679775}
  1595. realroots zz;
  1596. {y= - 2.236067977,
  1597. y= - 2.236067977,
  1598. y=2.2360679774998,
  1599. y=2.2360679774998,
  1600. y=2.2360679775}
  1601. % realroots handles this case also.
  1602. %{y= - 2.236067977,y= - 2.236067977,y=2.2360679774998,y=2.2360679774998,
  1603. % y=2.2360679775}
  1604. % 100)
  1605. rootacc 6;
  1606. 6
  1607. zz := (y-i)*(x-2)*(1000000x-2000001);
  1608. 5 4 3 2
  1609. zz := 1000000*y - 1000000*i*y - 4000001*y + 4000001*i*y
  1610. + 4000002*y - 4000002*i
  1611. roots zz;
  1612. {y= - 1.4142136,
  1613. y=1.4142136,
  1614. y= - 1.4142139,
  1615. y=1.4142139,
  1616. y=i}
  1617. %{y= - 1.4142136,y=1.4142136,y= - 1.4142139,y=1.4142139,y=i}
  1618. % 101) this example requires accuracy 15.
  1619. zz:= (y-2)*(100000000000000y-200000000000001);
  1620. 2
  1621. zz := 100000000000000*y - 400000000000001*y + 400000000000002
  1622. roots zz;
  1623. *** precision increased to 15
  1624. {y=2.0,y=2.00000000000001}
  1625. %{y=2.0,y=2.00000000000001}
  1626. % 102) still higher precision needed.
  1627. zz:= (y-2)*(10000000000000000000y-20000000000000000001);
  1628. 2
  1629. zz := 10000000000000000000*y - 40000000000000000001*y
  1630. + 40000000000000000002
  1631. roots zz;
  1632. *** precision increased to 20
  1633. {y=2.0,y=2.0000000000000000001}
  1634. %{y=2.0,y=2.0000000000000000001}
  1635. % 103) increase in precision required for substituted polynomial.
  1636. zz:= (x-2)*(10000000000x-20000000001);
  1637. 4 2
  1638. zz := 10000000000*y - 40000000001*y + 40000000002
  1639. roots zz;
  1640. {y= - 1.41421356237,
  1641. y=1.41421356237,
  1642. y= - 1.41421356241,
  1643. y=1.41421356241}
  1644. %{y= - 1.41421356237,y=1.41421356237,y= - 1.41421356241,y=1.41421356241}
  1645. % 104) still higher precision required for substituted polynomial.
  1646. zz:= (x-2)*(100000000000000x-200000000000001);
  1647. 4 2
  1648. zz := 100000000000000*y - 400000000000001*y + 400000000000002
  1649. roots zz;
  1650. *** input of these values may require precision >= 16
  1651. {y= - 1.414213562373095,
  1652. y=1.414213562373095,
  1653. y= - 1.414213562373099,
  1654. y=1.414213562373099}
  1655. %{y= - 1.414213562373095,y=1.414213562373095,
  1656. % y= - 1.414213562373099,y=1.414213562373099}
  1657. % 105) accuracy must be increased to separate root of complex factor
  1658. % from root of real factor.
  1659. zz:=(9y-10)*(y-2)*(9y-10-9i/100000000);
  1660. 3 2
  1661. zz := (8100000000*y - (34200000000 + 81*i)*y
  1662. + (46000000000 + 252*i)*y - (20000000000 + 180*i))/100000000
  1663. roots zz;
  1664. {y=1.111111111,y=2.0,y=1.111111111 + 0.00000001*i}
  1665. %{y=1.111111111,y=2.0,y=1.111111111 + 0.00000001*i}
  1666. % 106) realroots does the same accuracy increase for real root based
  1667. % upon the presence of a close complex root in the same polynomial.
  1668. % The reason for this might not be obvious unless roots is called.
  1669. realroots zz;
  1670. {y=1.111111111,y=2.0}
  1671. %{y=1.111111111,y=2.0}
  1672. % 107) realroots now uses powergcd logic whenever it is applicable.
  1673. zz := (x-1)*(x-2)*(x-3);
  1674. 6 4 2
  1675. zz := y - 6*y + 11*y - 6
  1676. realroots zz;
  1677. {y= - 1,
  1678. y=1,
  1679. y= - 1.41421,
  1680. y=1.41421,
  1681. y= - 1.73205,
  1682. y=1.73205}
  1683. %{y= - 1,y=1,y= - 1.41421,y=1.41421,y= - 1.73205,y=1.73205}
  1684. realroots(zz,exclude 1,2);
  1685. {y=1.41421,y=1.73205}
  1686. %{y=1.41421,y=1.73205}
  1687. % 108) root of degree 1 polynomial factor must be evaluated at
  1688. % precision 18 and accuracy 10 in order to separate it from a root of
  1689. % another real factor.
  1690. clear x;
  1691. zz:=(9x-10)**2*(9x-10-9/100000000)*(x-2);
  1692. 4 3 2
  1693. zz := (72900000000*x - 388800000729*x + 756000003078*x
  1694. - 640000004140*x + 200000001800)/100000000
  1695. roots zz;
  1696. {x=1.111111111,
  1697. x=1.111111111,
  1698. x=1.111111121,
  1699. x=2.0}
  1700. %{x=1.111111111,x=1.111111111,x=1.111111121,x=2.0}
  1701. nearestroot(zz,1);
  1702. {x=1.111111111}
  1703. %{x=1.111111111}
  1704. nearestroot(zz,1.5);
  1705. {x=1.111111121}
  1706. %{x=1.111111121}
  1707. nearestroot(zz,1.65);
  1708. {x=2.0}
  1709. %{x=2.0}
  1710. % 108a) new cability in mod 1.94.
  1711. realroots zz;
  1712. {x=1.111111111,
  1713. x=1.111111111,
  1714. x=1.111111121,
  1715. x=2.0}
  1716. %{x=1.111111111,x=1.111111111,x=1.111111121,x=2.0}
  1717. % 109) in this example, precision >=40 is used and two roots need to be
  1718. % found to accuracy 16 and two to accuracy 14.
  1719. zz := (9x-10)*(7x-8)*(9x-10-9/10**12)*(7x-8-7/10**14);
  1720. 4
  1721. zz := (396900000000000000000000000000*x
  1722. 3
  1723. - 1789200000000400869000000000000*x
  1724. 2
  1725. + 3024400000001361556000000003969*x
  1726. - 2272000000001541380000000008946*x
  1727. + 640000000000581600000000005040)/100000000000000000000000000
  1728. roots zz;
  1729. *** input of these values may require precision >= 16
  1730. {x=1.1111111111111,
  1731. x=1.1111111111121,
  1732. x=1.142857142857143,
  1733. x=1.142857142857153}
  1734. %{x=1.1111111111111,x=1.1111111111121,
  1735. % x=1.142857142857143,x=1.142857142857153}
  1736. % 110) very small real or imaginary parts of roots require high
  1737. % precision or exact computations, or they will be lost or incorrectly
  1738. % found.
  1739. zz := 1000000*r**18 + 250000000000*r**4 - 1000000*r**2 + 1;
  1740. 18 4 2
  1741. zz := 1000000*r + 250000000000*r - 1000000*r + 1
  1742. roots zz;
  1743. {r=2.42978*i,
  1744. r=-2.42978*i,
  1745. r=-1.05424 - 2.18916*i,
  1746. r=1.05424 + 2.18916*i,
  1747. r=-1.05424 + 2.18916*i,
  1748. r=1.05424 - 2.18916*i,
  1749. r=-0.00141421 - 1.6e-26*i,
  1750. r=0.00141421 + 1.6e-26*i,
  1751. r=-0.00141421 + 1.6e-26*i,
  1752. r=0.00141421 - 1.6e-26*i,
  1753. r=-1.89968 - 1.51494*i,
  1754. r=1.89968 + 1.51494*i,
  1755. r=-1.89968 + 1.51494*i,
  1756. r=1.89968 - 1.51494*i,
  1757. r=-2.36886 - 0.540677*i,
  1758. r=2.36886 + 0.540677*i,
  1759. r=-2.36886 + 0.540677*i,
  1760. r=2.36886 - 0.540677*i}
  1761. %{r=2.42978*i,r=-2.42978*i,
  1762. % r=-1.05424 - 2.18916*i,r=1.05424 + 2.18916*i,
  1763. % r=-1.05424 + 2.18916*i,r=1.05424 - 2.18916*i,
  1764. % r=-0.00141421 - 1.6E-26*i,r=0.00141421 + 1.6E-26*i,
  1765. % r=-0.00141421 + 1.6E-26*i,r=0.00141421 - 1.6E-26*i,
  1766. % r=-1.89968 - 1.51494*i,r=1.89968 + 1.51494*i,
  1767. % r=-1.89968 + 1.51494*i,r=1.89968 - 1.51494*i,
  1768. % r=-2.36886 - 0.540677*i,r=2.36886 + 0.540677*i,
  1769. % r=-2.36886 + 0.540677*i,r=2.36886 - 0.540677*i}
  1770. comment These five examples are very difficult root finding problems
  1771. for automatic root finding (not employing problem-specific
  1772. procedures.) They require extremely high precision and high accuracy
  1773. to separate almost multiple roots (multiplicity broken by a small high
  1774. order perturbation.) The examples are roughly in ascending order of
  1775. difficulty.;
  1776. % 111) Two simple complex roots with extremely small real separation.
  1777. c := 10^-6;
  1778. 1
  1779. c := ---------
  1780. 1000000
  1781. zz:=(x-3c^2)^2+i*c*x^7;
  1782. 7 2
  1783. zz := (1000000000000000000*i*x + 1000000000000000000000000*x
  1784. - 6000000000000*x + 9)/1000000000000000000000000
  1785. roots zz;
  1786. *** precision increased to 33
  1787. {x=-15.0732 + 4.89759*i,
  1788. x=-9.31577 - 12.8221*i,
  1789. x=-1.2e-12 + 15.8489*i,
  1790. x=2.99999999999999999999999999999997e-12
  1791. + 3.3068111527572904325663335008527e-44*i,
  1792. x=3.00000000000000000000000000000003e-12
  1793. - 3.30681115275729043256633350085321e-44*i,
  1794. x=9.31577 - 12.8221*i,
  1795. x=15.0732 + 4.89759*i}
  1796. %{x=-15.0732 + 4.89759*i,x=-9.31577 - 12.8221*i,x=-1.2E-12 + 15.8489*i,
  1797. % x=2.99999999999999999999999999999997E-12
  1798. % + 3.3068111527572904325663335008527E-44*i,
  1799. % x=3.00000000000000000000000000000003E-12
  1800. % - 3.30681115275729043256633350085321E-44*i,
  1801. % x=9.31577 - 12.8221*i,x=15.0732 + 4.89759*i}
  1802. % 112) Four simple complex roots in two close sets.
  1803. c := 10^-4;
  1804. 1
  1805. c := -------
  1806. 10000
  1807. zz:=(x^2-3c^2)^2+i*c^2*x^9;
  1808. 9 4 2
  1809. 100000000*i*x + 10000000000000000*x - 600000000*x + 9
  1810. zz := ----------------------------------------------------------
  1811. 10000000000000000
  1812. roots zz;
  1813. *** input of these values may require precision >= 15
  1814. {x=-37.8622 + 12.3022*i,
  1815. x=-23.4002 - 32.2075*i,
  1816. x=-0.00017320508075689 - 2.41778234660324e-18*i,
  1817. x=-0.000173205080756885 + 2.4177823466027e-18*i,
  1818. x=39.8107*i,
  1819. x=0.000173205080756885 + 2.4177823466027e-18*i,
  1820. x=0.00017320508075689 - 2.41778234660324e-18*i,
  1821. x=23.4002 - 32.2075*i,
  1822. x=37.8622 + 12.3022*i}
  1823. %{x=-37.8622 + 12.3022*i,x=-23.4002 - 32.2075*i,
  1824. % x=-0.00017320508075689 - 2.41778234660324E-18*i,
  1825. % x=-0.000173205080756885 + 2.4177823466027E-18*i,
  1826. % x=39.8107*i,
  1827. % x=0.000173205080756885 + 2.4177823466027E-18*i,
  1828. % x=0.00017320508075689 - 2.41778234660324E-18*i,
  1829. % x=23.4002 - 32.2075*i,x=37.8622 + 12.3022*i}
  1830. % 113) Same example, but with higher minimum root accuracy specified.
  1831. rootacc 20;
  1832. 20
  1833. roots zz;
  1834. {x=-37.862241873586290526 + 12.302188128448775345*i,
  1835. x=-23.400152368145827118 - 32.207546656274351069*i,
  1836. x=-0.00017320508075689014714 - 2.417782346603239319e-18*i,
  1837. x=-0.00017320508075688531157 + 2.417782346602699319e-18*i,
  1838. x=39.810717055651151449*i,
  1839. x=0.00017320508075688531157 + 2.417782346602699319e-18*i,
  1840. x=0.00017320508075689014714 - 2.417782346603239319e-18*i,
  1841. x=23.400152368145827118 - 32.207546656274351069*i,
  1842. x=37.862241873586290526 + 12.302188128448775345*i}
  1843. %{x=-37.862241873586290526 + 12.302188128448775345*i,
  1844. % x=-23.400152368145827118 - 32.207546656274351069*i,
  1845. % x=-0.00017320508075689014714 - 2.417782346603239319E-18*i,
  1846. % x=-0.00017320508075688531157 + 2.417782346602699319E-18*i,
  1847. % x=39.810717055651151449*i,
  1848. % x=0.00017320508075688531157 + 2.417782346602699319E-18*i,
  1849. % x=0.00017320508075689014714 - 2.417782346603239319E-18*i,
  1850. % x=23.400152368145827118 - 32.207546656274351069*i,
  1851. % x=37.862241873586290526 + 12.302188128448775345*i}
  1852. precision reset;
  1853. 33
  1854. % This resets precision and rootacc to nominal.
  1855. % 114) Two extremely close real roots plus a complex pair with extremely
  1856. % small imaginary part.
  1857. c := 10^6;
  1858. c := 1000000
  1859. zz:=(c^2*x^2-3)^2+c^2*x^9;
  1860. 9 4
  1861. zz := 1000000000000*x + 1000000000000000000000000*x
  1862. 2
  1863. - 6000000000000*x + 9
  1864. roots zz;
  1865. *** precision increased to 22
  1866. {x= - 251.189,
  1867. x=-77.6216 + 238.895*i,
  1868. x=-77.6216 - 238.895*i,
  1869. x= - 0.000001732050807568877293531,
  1870. x= - 0.000001732050807568877293524,
  1871. x=0.00000173205 + 3.41926e-27*i,
  1872. x=0.00000173205 - 3.41926e-27*i,
  1873. x=203.216 + 147.645*i,
  1874. x=203.216 - 147.645*i}
  1875. %{x= - 251.189,x=-77.6216 + 238.895*i,x=-77.6216 - 238.895*i,
  1876. % x= - 0.000001732050807568877293531,
  1877. % x= - 0.000001732050807568877293524,
  1878. % x=0.00000173205 + 3.41926E-27*i,x=0.00000173205 - 3.41926E-27*i,
  1879. % x=203.216 + 147.645*i,x=203.216 - 147.645*i}
  1880. % 114a) this example is a critical test for realroots as well.
  1881. realroots zz;
  1882. {x= - 251.189,x= - 0.000001732050807568877293531,x
  1883. = - 0.000001732050807568877293524}
  1884. %{x= - 251.189,x= - 0.000001732050807568877293531,
  1885. % x= - 0.000001732050807568877293524}
  1886. % 115) Four simple complex roots in two extremely close sets.
  1887. c := 10^6;
  1888. c := 1000000
  1889. zz:=(c^2*x^2-3)^2+i*c^2*x^9;
  1890. 9 4
  1891. zz := 1000000000000*i*x + 1000000000000000000000000*x
  1892. 2
  1893. - 6000000000000*x + 9
  1894. roots zz;
  1895. {x=-238.895 + 77.6216*i,
  1896. x=-147.645 - 203.216*i,
  1897. x=-0.00000173205080756887729353 - 2.417782346602969319022e-27*i,
  1898. x=-0.000001732050807568877293525 + 2.417782346602969318968e-27*i,
  1899. x=251.189*i,
  1900. x=0.000001732050807568877293525 + 2.417782346602969318968e-27*i,
  1901. x=0.00000173205080756887729353 - 2.417782346602969319022e-27*i,
  1902. x=147.645 - 203.216*i,
  1903. x=238.895 + 77.6216*i}
  1904. %{x=-238.895 + 77.6216*i,x=-147.645 - 203.216*i,
  1905. % x=-0.00000173205080756887729353 - 2.417782346602969319022E-27*i,
  1906. % x=-0.000001732050807568877293525 + 2.417782346602969318968E-27*i,
  1907. % x=251.189*i,
  1908. % x=0.000001732050807568877293525 + 2.417782346602969318968E-27*i,
  1909. % x=0.00000173205080756887729353 - 2.417782346602969319022E-27*i,
  1910. % x=147.645 - 203.216*i,x=238.895 + 77.6216*i}
  1911. % 116) A new "hardest example" type. This polynomial has two sets of
  1912. % extremely close real roots and two sets of extremely close conjugate
  1913. % complex roots, both large and small, with the maximum accuracy and
  1914. % precision required for the largest roots. Three restarts are
  1915. % required, at progressively higher precision, to find all roots.
  1916. % (to run this example, uncomment the following two lines.)
  1917. %**% zz1:= (10^12x^2-sqrt 2)^2+x^7$ zz2:= (10^12x^2+sqrt 2)^2+x^7$
  1918. %**% zzzz := zz1*zz2$ roots zzzz;
  1919. %{x= - 1.00000000000000000000000000009E+8,
  1920. % x= - 9.99999999999999999999999999906E+7,
  1921. % x= - 0.0000011892071150027210667183,
  1922. % x= - 0.0000011892071150027210667167,
  1923. % x=-5.4525386633262882960501E-28 + 0.000001189207115002721066718*i,
  1924. % x=-5.4525386633262882960501E-28 - 0.000001189207115002721066718*i,
  1925. % x=5.4525386633262882960201E-28 + 0.000001189207115002721066717*i,
  1926. % x=5.4525386633262882960201E-28 - 0.000001189207115002721066717*i,
  1927. % x=0.00000118921 + 7.71105E-28*i,
  1928. % x=0.00000118921 - 7.71105E-28*i,
  1929. % x=4.99999999999999999999999999953E+7
  1930. % + 8.66025403784438646763723170835E+7*i,
  1931. % x=4.99999999999999999999999999953E+7
  1932. % - 8.66025403784438646763723170835E+7*i,
  1933. % x=5.00000000000000000000000000047E+7
  1934. % + 8.66025403784438646763723170671E+7*i,
  1935. % x=5.00000000000000000000000000047E+7
  1936. % - 8.66025403784438646763723170671E+7*i}
  1937. % Realroots strategy on this example is different, but determining the
  1938. % necessary precision and accuracy is tricky.
  1939. %**% realroots zzzz;
  1940. %{x= - 1.00000000000000000000000000009E+8,
  1941. % x= - 9.9999999999999999999999999991E+7,
  1942. % x= - 0.0000011892071150027210667183,
  1943. % x= - 0.0000011892071150027210667167}
  1944. showtime;
  1945. Time: 124512 ms plus GC time: 11399 ms
  1946. end;
  1947. (TIME: roots 124545 136078)
  1948. End of Lisp run after 124.56+12.18 seconds