roots.log 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847
  1. Sat Jun 29 13:48:36 PDT 1991
  2. REDUCE 3.4, 15-Jul-91 ...
  3. 1: 1:
  4. 2: 2:
  5. 3: 3: % Tests of the root finding package.
  6. % Author: Stanley L. Kameny (stan%valley.uucp@rand.org)
  7. % Answers are rounded to the value given by rootacc (default = 6) unless
  8. % higher accuracy is needed to separate roots. Root order and format
  9. % may differ from that given here, but values should agree.
  10. % In the following, problems 20), 78) and 82) are time consuming and
  11. % been commented out to speed up the test.
  12. roots x;
  13. {X=0}
  14. % To load roots package.
  15. write "This is Roots Package test ", symbolic roots!-mod$
  16. This is Roots Package test Mod 1.92, 10 Oct 1990.
  17. % Simple root finding.
  18. showtime;
  19. Time: 476 ms
  20. % 1) multiple real and imaginary roots plus two real roots.
  21. zz:= (x-3)**2*(100x**2+113)**2*(1000000x-10000111)*(x-1);
  22. 8 7 6
  23. ZZ := 10000000000*X - 170001110000*X + 872607770000*X
  24. 5 4 3
  25. - 1974219158600*X + 2833796550200*X - 3810512046359*X
  26. 2
  27. + 3119397498913*X - 2030292260385*X + 1149222756231
  28. roots zz;
  29. {X=1.06301*I,
  30. X=1.06301*I,
  31. X=-1.06301*I,
  32. X=-1.06301*I,
  33. X=3.0,
  34. X=3.0,
  35. X=1,
  36. X=10.0001}
  37. %{X=1.06301*I,X=1.06301*I,X=-1.06301*I,X=-1.06301*I,
  38. %X=3.0,X=3.0,X=1,X=10.0001} (rootacc caused rounding to 6 places)
  39. % Accuracy is increased whenever necessary to separate distinct roots.
  40. % 2) accuracy increase to 7 required for two roots.
  41. zz:=(x**2+1)*(x-2)*(1000000x-2000001);
  42. 4 3 2
  43. ZZ := 1000000*X - 4000001*X + 5000002*X - 4000001*X + 4000002
  44. roots zz;
  45. {X=2.0,X=I,X= - I,X=2.000001}
  46. %{X=2.0,X=I,X= - I,X=2.000001}
  47. % 3) accuracy increase to 8 required.
  48. zz:= (x-3)*(10000000x-30000001);
  49. 2
  50. ZZ := 10000000*X - 60000001*X + 90000003
  51. roots zz;
  52. {X=3.0,X=3.0000001}
  53. %{X=3.0,X=3.0000001}
  54. % 4) accuracy increase required here to separate repeated root from
  55. % simple root.
  56. zz := (x-3)*(1000000x-3000001)*(x-3)*(1000000x-3241234);
  57. 4 3 2
  58. ZZ := 2*(500000000000*X - 6120617500000*X + 28085557620617*X
  59. - 57256673223702*X + 43756673585553)
  60. roots zz;
  61. {X=3.0,X=3.0,X=3.000001,X=3.24123}
  62. %{X=3.0,X=3.0,X=3.000001,X=3.24123}
  63. % other simple examples
  64. % 5) five real roots with widely different spacing.
  65. zz:= (x-1)*(10x-11)*(x-1000)*(x-1001)*(x-100000);
  66. 5 4 3 2
  67. ZZ := 10*X - 1020031*X + 2013152032*X - 1005224243011*X
  68. + 2104312111000*X - 1101100000000
  69. roots zz;
  70. {X=1,X=1.1,X=1000.0,X=1001.0,X=100000.0}
  71. %{X=1,X=1.1,X=1000.0,X=1001.0,X=100000.0}
  72. % 6) a cluster of 5 roots in complex plane in vicinity of x=1.
  73. zz:= (x-1)*(10000x**2-20000x+10001)*(10000x**2-20000x+9999);
  74. 5 4 3 2
  75. ZZ := 100000000*X - 500000000*X + 1000000000*X - 1000000000*X
  76. + 499999999*X - 99999999
  77. roots zz;
  78. {X=1,
  79. X=1.01,
  80. X=0.99,
  81. X=1 + 0.01*I,
  82. X=1 - 0.01*I}
  83. %{X=1,X=1.01,X=0.99,X=1 + 0.01*I,X=1 - 0.01*I}
  84. % 7) four closely spaced real roots.
  85. zz := (x-1)*(100x-101)*(100x-102)*(100x-103);
  86. 4 3 2
  87. ZZ := 2*(500000*X - 2030000*X + 3090550*X - 2091103*X + 530553)
  88. roots zz;
  89. {X=1.02,X=1.01,X=1,X=1.03}
  90. %{X=1.02,X=1.01,X=1,X=1.03}
  91. % 8) five closely spaced roots, 3 real + 1 complex pair.
  92. zz := (x-1)*(100x-101)*(100x-102)*(100x**2-200x+101);
  93. 5 4 3 2
  94. ZZ := 2*(500000*X - 2515000*X + 5065100*X - 5105450*X + 2575601*X
  95. - 520251)
  96. roots zz;
  97. {X=1.01,
  98. X=1,
  99. X=1.02,
  100. X=1 + 0.1*I,
  101. X=1 - 0.1*I}
  102. %{X=1.01,X=1,X=1.02,X=1 + 0.1*I,X=1 - 0.1*I}
  103. % 9) symmetric cluster of 5 roots, 3 real + 1 complex pair.
  104. zz := (x-2)*(10000x**2-40000x+40001)*(10000x**2-40000x+39999);
  105. 5 4 3 2
  106. ZZ := 100000000*X - 1000000000*X + 4000000000*X - 8000000000*X
  107. + 7999999999*X - 3199999998
  108. roots zz;
  109. {X=2.0,
  110. X=2.01,
  111. X=1.99,
  112. X=2.0 + 0.01*I,
  113. X=2.0 - 0.01*I}
  114. %{X=2.0,X=2.01,X=1.99,X=2.0 + 0.01*I,X=2.0 - 0.01*I}
  115. % 10) closely spaced real and complex pair.
  116. ss:= (x-2)*(100000000x**2-400000000x+400000001);
  117. 3 2
  118. SS := 100000000*X - 600000000*X + 1200000001*X - 800000002
  119. roots ss;
  120. {X=2.0,X=2.0 + 0.0001*I,X=2.0 - 0.0001*I}
  121. %{X=2.0,X=2.0 + 0.0001*I,X=2.0 - 0.0001*I}
  122. % 11) Zero roots and multiple roots cause no problem.
  123. % Multiple roots are shown when the switch multiroot is on
  124. %(normally on.)
  125. zz:= x*(x-1)**2*(x-4)**3*(x**2+1);
  126. 7 6 5 4 3 2
  127. ZZ := X*(X - 14*X + 74*X - 186*X + 249*X - 236*X + 176*X - 64)
  128. roots zz;
  129. {X=0,
  130. X=4.0,
  131. X=4.0,
  132. X=4.0,
  133. X=1,
  134. X=1,
  135. X=I,
  136. X= - I}
  137. %{X=0,X=4.0,X=4.0,X=4.0,X=1,X=1,X=I,X= - I}
  138. % 12) nearestroot will find a single root "near" a value, real or
  139. % complex.
  140. nearestroot(zz,2i);
  141. {X=I}
  142. %{X=I}
  143. % More difficult examples.
  144. % Three examples in which root scaling is needed in the complex
  145. % iteration process.
  146. % 13) nine roots, 3 real and 3 complex pairs.
  147. zz:= x**9-45x-2;
  148. 9
  149. ZZ := X - 45*X - 2
  150. roots zz;
  151. {X= - 0.0444444,
  152. X=1.61483,
  153. X=0.00555 + 1.60944*I,
  154. X=0.00555 - 1.60944*I,
  155. X= - 1.60371,
  156. X=1.14348 + 1.13804*I,
  157. X=1.14348 - 1.13804*I,
  158. X=-1.13237 + 1.13805*I,
  159. X=-1.13237 - 1.13805*I}
  160. %{X= - 0.0444444,X=1.61483,
  161. % X=0.00555 + 1.60944*I,X=0.00555 - 1.60944*I,
  162. % X= - 1.60371,
  163. % X=1.14348 + 1.13804*I,X=1.14348 - 1.13804*I,
  164. % X=-1.13237 + 1.13805*I,X=-1.13237 - 1.13805*I}
  165. % In the next two examples, there are complex roots with extremely
  166. % small real parts (new capability in Mod 1.91.)
  167. % 14) nine roots, 1 real and 4 complex pairs.
  168. zz:= x**9-9999x**2-0.01;
  169. 9 2
  170. 100*X - 999900*X - 1
  171. ZZ := ------------------------
  172. 100
  173. roots zz;
  174. *** precision increased to 27
  175. {X=5.0E-29 + 0.00100005*I,
  176. X=5.0E-29 - 0.00100005*I,
  177. X=3.72754,
  178. X=-0.82946 + 3.63408*I,
  179. X=-0.82946 - 3.63408*I,
  180. X=-3.3584 + 1.61732*I,
  181. X=-3.3584 - 1.61732*I,
  182. X=2.32408 + 2.91431*I,
  183. X=2.32408 - 2.91431*I}
  184. %{X=5.0E-29 + 0.00100005*I,X=5.0E-29 - 0.00100005*I,
  185. %X=3.72754,
  186. %X=-0.829456 + 3.63408*I, X=-0.829456 + 3.63408*I,
  187. %X=-3.3584 + 1.61732*I, X=-3.3584 - 1.61732*I,
  188. %X=2.32408 + 2.91431*I, X=2.32408 - 2.91431*I}
  189. % rootacc 7 produces 7 place accuracy; answers will print in bigfloat
  190. % format if floating point print >6 digits is not implemented.
  191. % 15) nine roots, 1 real and 4 complex pairs.
  192. rootacc 7;
  193. 7
  194. zz:= x**9-500x**2-0.001;
  195. 9 2
  196. 1000*X - 500000*X - 1
  197. ZZ := -------------------------
  198. 1000
  199. roots zz;
  200. {X=1.6E-26 + 0.001414214*I,
  201. X=1.6E-26 - 0.001414214*I,
  202. X=2.429781,
  203. X=-0.540677 + 2.368861*I,
  204. X=-0.540677 - 2.368861*I,
  205. X=-2.189157 + 1.054242*I,
  206. X=-2.189157 - 1.054242*I,
  207. X=1.514944 + 1.899679*I,
  208. X=1.514944 - 1.899679*I}
  209. %{X=1.6E-26 + 0.001414214*I,X=1.6E-26 - 0.001414214*I,
  210. % X=-0.540677 + 2.368861*I, X=-0.540677 - 2.368861*I,
  211. % X=-2.189157 + 1.054242*I, X=-2.189157 - 1.054242*I,
  212. % X=1.514944 + 1.899679*I, X=1.514944 - 1.899679*I}
  213. % the famous Wilkinson "ill-conditioned" polynomial and its family.
  214. % 16) W(6) four real roots plus one complex pair.
  215. zz:= 10000*(for j:=1:6 product(x+j))+27x**5;
  216. 6 5 4 3 2
  217. ZZ := 10000*X + 210027*X + 1750000*X + 7350000*X + 16240000*X
  218. + 17640000*X + 7200000
  219. roots zz;
  220. {X= - 2.950367,
  221. X=-4.452438 + 0.021235*I,
  222. X=-4.452438 - 0.021235*I,
  223. X= - 2.003647,
  224. X= - 0.9999775,
  225. X= - 6.143833}
  226. %{X= - 2.950367,X=-4.452438 + 0.021235*I,X=-4.452438 - 0.021235*I,
  227. % X= - 0.9999775,X= - 2.003647,X= - 6.143833}
  228. % 17) W(8) 4 real roots plus 2 complex pairs.
  229. zz:= 1000*(for j:=1:8 product(x+j))+2x**7;
  230. 8 7 6 5 4
  231. ZZ := 2*(500*X + 18001*X + 273000*X + 2268000*X + 11224500*X
  232. 3 2
  233. + 33642000*X + 59062000*X + 54792000*X + 20160000)
  234. roots zz;
  235. {X=-4.295858 + 0.28151*I,
  236. X=-4.295858 - 0.28151*I,
  237. X= - 2.982725,
  238. X=-6.494828 + 1.015417*I,
  239. X=-6.494828 - 1.015417*I,
  240. X= - 0.9999996,
  241. X= - 2.000356,
  242. X= - 8.437546}
  243. %{X=-4.295858 + 0.28151*I,X=-4.295858 - 0.28151*I,
  244. % X= - 2.982725,
  245. % X=-6.494828 + 1.015417*I,X=-6.494828 - 1.015417*I,
  246. % X= - 0.9999996,X= - 2.000356,X= - 8.437546}
  247. % 18) W(10) 6 real roots plus 2 complex pairs.
  248. zz:=1000*(for j:= 1:10 product (x+j))+x**9;
  249. 10 9 8 7 6
  250. ZZ := 1000*X + 55001*X + 1320000*X + 18150000*X + 157773000*X
  251. 5 4 3
  252. + 902055000*X + 3416930000*X + 8409500000*X
  253. 2
  254. + 12753576000*X + 10628640000*X + 3628800000
  255. roots zz;
  256. {X= - 4.616444,
  257. X=-6.046279 + 1.134321*I,
  258. X=-6.046279 - 1.134321*I,
  259. X= - 4.075943,
  260. X= - 2.998063,
  261. X=-8.70405 + 1.691061*I,
  262. X=-8.70405 - 1.691061*I,
  263. X=-1,
  264. X= - 2.000013,
  265. X= - 10.80988}
  266. %{X= - 4.616444,X=-6.046279 + 1.134321*I,X=-6.046279 - 1.134321*I,
  267. % X= - 4.075943,X= - 2.998063,
  268. % X=-8.70405 + 1.691061*I,X=-8.70405 - 1.691061*I,
  269. % X= -1,X= - 2.000013,X= - 10.80988}
  270. % 19) W(12) 6 real roots plus 3 complex pairs.
  271. zz:= 10000*(for j:=1:12 product(x+j))+4x**11;
  272. 12 11 10 9
  273. ZZ := 4*(2500*X + 195001*X + 6792500*X + 139425000*X
  274. 8 7 6
  275. + 1873657500*X + 17316585000*X + 112475577500*X
  276. 5 4 3
  277. + 515175375000*X + 1643017090000*X + 3535037220000*X
  278. 2
  279. + 4828898880000*X + 3716107200000*X + 1197504000000)
  280. roots zz;
  281. {X=-5.985629 + 0.809425*I,
  282. X=-5.985629 - 0.809425*I,
  283. X= - 4.880956,
  284. X= - 4.007117,
  285. X=-7.953917 + 1.948001*I,
  286. X=-7.953917 - 1.948001*I,
  287. X=-1,
  288. X=-11.02192 + 2.23956*I,
  289. X=-11.02192 - 2.23956*I,
  290. X= - 2.0,
  291. X= - 2.999902,
  292. X= - 13.1895}
  293. %{X=-5.985629 + 0.809425*I,X=-5.985629 - 0.809425*I,
  294. % X= - 4.880956,X= - 4.007117,
  295. % X=-7.953917 + 1.948001*I,X=-7.953917 - 1.948001*I,
  296. % X= -1,X=-11.02192 + 2.23956*I,X=-11.02192 - 2.23956*I,
  297. % X= - 2.0,X= - 2.999902,X= - 13.1895}
  298. % 20) W(20) 10 real roots plus 5 complex pairs. (The original problem)
  299. % This example is commented out, since it takes significant time:
  300. % zz:= x**19+10**7*for j:=1:20 product (x+j); roots zz;
  301. %{X=-10.12155 + 0.6013*I,X=-10.12155 - 0.6013*I,
  302. % X= - 8.928803,
  303. % X=-11.82101 + 1.59862*I,X=-11.82101 - 1.59862*I,
  304. % X= - 8.006075,X= - 6.999746,
  305. % X=-14.01105 + 2.44947*I,X=-14.01105 - 2.44947*I,
  306. % X=-1,X= - 6.000006,
  307. % X=-19.45964 + 1.87436*I,X=-19.45964 - 1.87436*I,
  308. % X= - 2.0,X= - 5.0,
  309. % X=-16.72504 + 2.73158*I,X=-16.72504 - 2.73158*I,
  310. % X= - 3.0,X= - 4.0,X= - 20.78881}
  311. rootacc 6;
  312. 6
  313. % 21) Finding one of a cluster of 8 roots.
  314. zz:= (10**16*(x-1)**8-1);
  315. 8 7
  316. ZZ := 10000000000000000*X - 80000000000000000*X
  317. 6 5
  318. + 280000000000000000*X - 560000000000000000*X
  319. 4 3
  320. + 700000000000000000*X - 560000000000000000*X
  321. 2
  322. + 280000000000000000*X - 80000000000000000*X
  323. + 9999999999999999
  324. nearestroot(zz,2);
  325. {X=1.01}
  326. %{X=1.01}
  327. % 22) Six real roots spaced 0.01 apart.
  328. c := 100;
  329. C := 100
  330. zz:= (x-1)*for i:=1:5 product (c*x-(c+i));
  331. 6 5 4
  332. ZZ := 40*(250000000*X - 1537500000*X + 3939625000*X
  333. 3 2
  334. - 5383556250*X + 4137919435*X - 1696170123*X + 289681938
  335. )
  336. roots zz;
  337. {X=1.03,X=1.02,X=1.04,X=1.01,X=1,X=1.05}
  338. %{X=1.03,X=1.02,X=1.04,X=1.0,X=1.01,X=1.05}
  339. % 23) Six real roots spaced 0.001 apart.
  340. c := 1000;
  341. C := 1000
  342. zz:= (x-1)*for i:=1:5 product (c*x-(c+i));
  343. 6 5 4
  344. ZZ := 40*(25000000000000*X - 150375000000000*X + 376877125000000*X
  345. 3 2
  346. - 503758505625000*X + 378762766881850*X
  347. - 151883516888703*X + 25377130631853)
  348. roots zz;
  349. {X=1.003,X=1.002,X=1.004,X=1.001,X=1,X=1.005}
  350. %{X=1.003,X=1.002,X=1.004,X=1,X=1.001,X=1.005}
  351. % 24) Five real roots spaced 0.0001 apart.
  352. c := 10000;
  353. C := 10000
  354. zz:= (x-1)*for i:=1:4 product (c*x-(c+i));
  355. 5 4
  356. ZZ := 8*(1250000000000000*X - 6251250000000000*X
  357. 3 2
  358. + 12505000437500000*X - 12507501312562500*X
  359. + 6255001312625003*X - 1251250437562503)
  360. roots zz;
  361. {X=1.0002,X=1.0003,X=1.0001,X=1,X=1.0004}
  362. %{X=1.0002,X=1.0003,X=1,X=1.0001,X=1.0004}
  363. % 25) A cluster of 9 roots, 5 real, 2 complex pairs; spacing 0.1.
  364. zz:= (x-1)*(10**8*(x-1)**8-1);
  365. 9 8 7 6
  366. ZZ := 100000000*X - 900000000*X + 3600000000*X - 8400000000*X
  367. 5 4 3
  368. + 12600000000*X - 12600000000*X + 8400000000*X
  369. 2
  370. - 3600000000*X + 899999999*X - 99999999
  371. roots zz;
  372. {X=1,
  373. X=1.1,
  374. X=1 + 0.1*I,
  375. X=1 - 0.1*I,
  376. X=0.9,
  377. X=0.929289 + 0.070711*I,
  378. X=0.929289 - 0.070711*I,
  379. X=1.07071 + 0.07071*I,
  380. X=1.07071 - 0.07071*I}
  381. %{X=1,X=1.1,X=1 + 0.1*I,X=1 - 0.1*I,X=0.9,
  382. % X=0.929289 + 0.070711*I,X=0.929289 - 0.070711*I,
  383. % X=1.07071 + 0.07071*I,X=1.07071 - 0.07071*I}
  384. % 26) Same, but with spacing 0.01.
  385. zz:= (x-1)*(10**16*(x-1)**8-1);
  386. 9 8
  387. ZZ := 10000000000000000*X - 90000000000000000*X
  388. 7 6
  389. + 360000000000000000*X - 840000000000000000*X
  390. 5 4
  391. + 1260000000000000000*X - 1260000000000000000*X
  392. 3 2
  393. + 840000000000000000*X - 360000000000000000*X
  394. + 89999999999999999*X - 9999999999999999
  395. roots zz;
  396. {X=1,
  397. X=1.01,
  398. X=1 + 0.01*I,
  399. X=1 - 0.01*I,
  400. X=0.99,
  401. X=0.992929 + 0.007071*I,
  402. X=0.992929 - 0.007071*I,
  403. X=1.00707 + 0.00707*I,
  404. X=1.00707 - 0.00707*I}
  405. %{X=1,X=1.01,X=1 + 0.01*I,X=1 - 0.01*I,X=0.99,
  406. % X=0.992929 + 0.007071*I,X=0.992929 - 0.007071*I,
  407. % X=1.00707 + 0.00707*I,X=1.00707 - 0.00707*I}
  408. % 27) Spacing reduced to 0.001.
  409. zz:= (x-1)*(10**24*(x-1)**8-1);
  410. 9 8
  411. ZZ := 1000000000000000000000000*X - 9000000000000000000000000*X
  412. 7
  413. + 36000000000000000000000000*X
  414. 6
  415. - 84000000000000000000000000*X
  416. 5
  417. + 126000000000000000000000000*X
  418. 4
  419. - 126000000000000000000000000*X
  420. 3
  421. + 84000000000000000000000000*X
  422. 2
  423. - 36000000000000000000000000*X + 8999999999999999999999999*X
  424. - 999999999999999999999999
  425. roots zz;
  426. {X=1,
  427. X=1.001,
  428. X=1 + 0.001*I,
  429. X=1 - 0.001*I,
  430. X=0.999,
  431. X=0.999293 + 0.000707*I,
  432. X=0.999293 - 0.000707*I,
  433. X=1.00071 + 0.000707*I,
  434. X=1.00071 - 0.000707*I}
  435. %{X=1,X=1.001,X=1 + 0.001*I,X=1 - 0.001*I,X=0.999,
  436. % X=0.999293 + 0.000707*I,X=0.999293 - 0.000707*I,
  437. % X=1.00071 + 0.000707*I,X=1.00071 - 0.000707*I}
  438. % 28) Eight roots divided into two clusters.
  439. zz:= (10**8*(x-1)**4-1)*(10**8*(x+1)**4-1);
  440. 8 6
  441. ZZ := 10000000000000000*X - 40000000000000000*X
  442. 4 2
  443. + 59999999800000000*X - 40000001200000000*X
  444. + 9999999800000001
  445. roots zz;
  446. {X=1.01,
  447. X= - 1.01,
  448. X=0.99,
  449. X= - 0.99,
  450. X=1 + 0.01*I,
  451. X=-1 - 0.01*I,
  452. X=-1 + 0.01*I,
  453. X=1 - 0.01*I}
  454. %{X=1.01,X= - 1.01,X=1 + 0.01*I,X=-1 - 0.01*I,
  455. % X=-1 + 0.01*I,X=1 - 0.01*I,X=0.99,X= - 0.99}
  456. % 29) A cluster of 8 roots in a different configuration.
  457. zz:= (10**8*(x-1)**4-1)*(10**8*(100x-102)**4-1);
  458. 8 7
  459. ZZ := 1000000000000000000000000*X - 8080000000000000000000000*X
  460. 6
  461. + 28562400000000000000000000*X
  462. 5
  463. - 57694432000000000000000000*X
  464. 4
  465. + 72836160149999999900000000*X
  466. 3
  467. - 58848320599199999600000000*X
  468. 2
  469. + 29716320897575999400000000*X - 8574560597551679600000000*X
  470. + 1082432149175678300000001
  471. roots zz;
  472. {X=1.01,
  473. X=1.0199,
  474. X=1.02 + 0.0001*I,
  475. X=1.02 - 0.0001*I,
  476. X=1 + 0.01*I,
  477. X=1 - 0.01*I,
  478. X=0.99,
  479. X=1.0201}
  480. %{X=1.01, X=1.0199, X=1.02 + 0.0001*I, X=1.02 - 0.0001*I,
  481. % X=1 + 0.01*I, X=1 - 0.01*I, X=0.99, X=1.0201}
  482. % 30) A cluster of 8 complex roots.
  483. zz:= ((10x-1)**4+1)*((10x+1)**4+1);
  484. 8 6 4 2
  485. ZZ := 4*(25000000*X - 1000000*X + 20000*X + 200*X + 1)
  486. roots zz;
  487. {X=0.0292893 + 0.0707107*I,
  488. X=-0.0292893 - 0.0707107*I,
  489. X=-0.0292893 + 0.0707107*I,
  490. X=0.0292893 - 0.0707107*I,
  491. X=0.170711 + 0.070711*I,
  492. X=-0.170711 - 0.070711*I,
  493. X=-0.170711 + 0.070711*I,
  494. X=0.170711 - 0.070711*I}
  495. %{X=0.0292893 + 0.0707107*I,X=-0.0292893 - 0.0707107*I,
  496. % X=-0.0292893 + 0.0707107*I,X=0.0292893 - 0.0707107*I,
  497. % X=0.170711 + 0.070711*I,X=-0.170711 - 0.070711*I,
  498. % X=-0.170711 + 0.070711*I,X=0.170711 - 0.070711*I}
  499. % In these examples, accuracy increase is required to separate a
  500. % repeated root from a simple root.
  501. % 31) Using allroots;
  502. zz:= (x-4)*(x-3)**2*(1000000x-3000001);
  503. ZZ :=
  504. 4 3 2
  505. 1000000*X - 13000001*X + 63000010*X - 135000033*X + 108000036
  506. roots zz;
  507. {X=3.0,X=3.0,X=3.000001,X=4.0}
  508. %{X=3.0,X=3.0,X=3.000001,X=4.0}
  509. % 32) Using realroots;
  510. realroots zz;
  511. {X=3.0,
  512. X=3.0,
  513. X=3.000001,
  514. X=4.0}
  515. %{X=3.0,X=3.0,X=3.000001,X=4.0}
  516. comment Tests of new capabilities in mod 1.87 for handling complex
  517. polynomials and polynomials with very small imaginary parts or very
  518. small real roots. A few real examples are shown, just to demonstrate
  519. that these still work;
  520. % 33) A trivial complex case (but degrees 1 and 2 are special cases);
  521. zz:= x-i;
  522. ZZ := - I + X
  523. roots zz;
  524. {X=I}
  525. %{X=I}
  526. % 34) Real case.
  527. zz:= y-7;
  528. ZZ := Y - 7
  529. roots zz;
  530. {Y=7.0}
  531. %{Y=7.0}
  532. % 35) Roots with small imaginary parts (new capability);
  533. zz := 10**16*(x**2-2x+1)+1;
  534. 2
  535. ZZ := 10000000000000000*X - 20000000000000000*X + 10000000000000001
  536. roots zz;
  537. {X=1 + 0.00000001*I,X=1 - 0.00000001*I}
  538. %{X=1 + 0.00000001*I,X=1 - 0.00000001*I}
  539. % 36) One real, one complex root.
  540. zz:=(x-9)*(x-5i-7);
  541. 2
  542. ZZ := - 5*I*X + 45*I + X - 16*X + 63
  543. roots zz;
  544. {X=9.0,X=7.0 + 5.0*I}
  545. %{X=9.0,X=7.0 + 5.0*I}
  546. % 37) Three real roots.
  547. zz:= (x-1)*(x-2)*(x-3);
  548. 3 2
  549. ZZ := X - 6*X + 11*X - 6
  550. roots zz;
  551. {X=2.0,X=1,X=3.0}
  552. %{X=2.0,X=1,X=3.0}
  553. % 38) 2 real + 1 imaginary root.
  554. zz:=(x**2-8)*(x-5i);
  555. 2 3
  556. ZZ := - 5*I*X + 40*I + X - 8*X
  557. roots zz;
  558. {X=2.82843,X= - 2.82843,X=5.0*I}
  559. %{X=2.82843,X= - 2.82843,X=5.0*I}
  560. % 39) 2 complex roots.
  561. zz:= (x-1-2i)*(x+2+3i);
  562. 2
  563. ZZ := I*X - 7*I + X + X + 4
  564. roots zz;
  565. {X=1 + 2.0*I,X=-2.0 - 3.0*I}
  566. %{X=1 + 2.0*I,X=-2.0 - 3.0*I}
  567. % 40) 2 irrational complex roots.
  568. zz:= x**2+(3+2i)*x+7i;
  569. 2
  570. ZZ := 2*I*X + 7*I + X + 3*X
  571. roots zz;
  572. {X=0.14936 - 2.21259*I,X=-3.14936 + 0.21259*I}
  573. %{X=0.14936 - 2.21259*I,X=-3.14936 + 0.21259*I}
  574. % 41) 2 complex roots of very different magnitudes with small imaginary
  575. % parts.
  576. zz:= x**2+(1000000000+12i)*x-1000000000;
  577. 2
  578. ZZ := 12*I*X + X + 1000000000*X - 1000000000
  579. roots zz;
  580. {X=1 - 0.000000012*I,X=-1.0E+9 - 12.0*I}
  581. %{X=1 - 0.000000012*I,X=-1.0E+9 - 12.0*I}
  582. % 42) Multiple real and complex roots cause no difficulty, provided
  583. % that input is given in integer or rational form and mode is complex.
  584. zz :=(x**2-2i*x+5)**3*(x-2i)*(x-11/10)**2;
  585. 8 7 6 5 4
  586. ZZ := ( - 800*I*X + 1760*I*X - 6768*I*X + 12760*I*X - 25018*I*X
  587. 3 2 9
  588. + 39600*I*X - 46780*I*X + 55000*I*X - 30250*I + 100*X
  589. 8 7 6 5 4 3
  590. - 220*X - 779*X + 1980*X - 9989*X + 19580*X - 28269*X
  591. 2
  592. + 38500*X - 21175*X)/100
  593. roots zz;
  594. {X=-1.44949*I,
  595. X=-1.44949*I,
  596. X=-1.44949*I,
  597. X=3.44949*I,
  598. X=3.44949*I,
  599. X=3.44949*I,
  600. X=1.1,
  601. X=1.1,
  602. X=2.0*I}
  603. %{X=-1.44949*I, X=-1.44949*I, X=-1.44949*I,
  604. % X=3.44949*I, X=3.44949*I, X=3.44949*I, X=1.1, X=1.1, X=2.0*I}
  605. % 43) 2 real, 2 complex roots.
  606. zz:= (x**2-4)*(x**2+3i*x+5i);
  607. 3 2 4 2
  608. ZZ := 3*I*X + 5*I*X - 12*I*X - 20*I + X - 4*X
  609. roots zz;
  610. {X=2.0,
  611. X= - 2.0,
  612. X=-1.2714 + 0.46633*I,
  613. X=1.2714 - 3.46633*I}
  614. %{X=2.0,X= - 2.0,X=-1.2714 + 0.466333*I,X=1.2714 - 3.46633*I}
  615. % 44) 4 complex roots.
  616. zz:= x**4+(0.000001i)*x-16;
  617. 4
  618. I*X + 1000000*X - 16000000
  619. ZZ := -----------------------------
  620. 1000000
  621. roots zz;
  622. {X=2.0 - 0.0000000625*I,
  623. X=-2.0 - 0.0000000625*I,
  624. X=-2.0*I,
  625. X=2.0*I}
  626. %{X=2.0 - 0.0000000625*I,X=-2.0*I,X=-2.0 - 0.0000000625*I,X=2.0*I}
  627. % 45) 2 real, 2 complex roots.
  628. zz:= (x**2-4)*(x**2+2i*x+8);
  629. 3 4 2
  630. ZZ := 2*I*X - 8*I*X + X + 4*X - 32
  631. roots zz;
  632. {X=2.0,X= - 2.0,X=2.0*I,X=-4.0*I}
  633. %{X=2.0,X= - 2.0,X=2.0*I,X=-4.0*I}
  634. % 46) Using realroots to find only real roots.
  635. realroots zz;
  636. {X= - 2.0,X=2.0}
  637. %{X= - 2.0,X=2.0}
  638. % 47) Same example, applying nearestroot to find a single root.
  639. zz:= (x**2-4)*(x**2+2i*x+8);
  640. 3 4 2
  641. ZZ := 2*I*X - 8*I*X + X + 4*X - 32
  642. nearestroot(zz,1);
  643. {X=2.0}
  644. %{X=2.0}
  645. % 48) Same example, but focusing on imaginary point.
  646. nearestroot(zz,i);
  647. {X=2.0*I}
  648. %{X=2.0*I}
  649. % 49) The seed parameter can be complex also.
  650. nearestroot(zz,1+i);
  651. {X=2.0*I}
  652. %{X=2.0*I}
  653. % 50) One more nearestroot example. Nearest root to real point may be
  654. %complex.
  655. zz:= (x**2-4)*(x**2-i);
  656. 2 4 2
  657. ZZ := - I*X + 4*I + X - 4*X
  658. roots zz;
  659. {X=2.0,
  660. X= - 2.0,
  661. X=0.707107 + 0.707107*I,
  662. X=-0.707107 - 0.707107*I}
  663. %{X=2.0,X= - 2.0,X=0.707107 + 0.707107*I,X=-0.707107 - 0.707107*I}
  664. nearestroot (zz,1);
  665. {X=0.707107 + 0.707107*I}
  666. %{X=0.707107 + 0.707107*I}
  667. % 51) 1 real root plus 5 complex roots.
  668. zz:=(x**3-3i*x**2-5x+9)*(x**3-8);
  669. 5 2 6 4 3
  670. ZZ := - 3*I*X + 24*I*X + X - 5*X + X + 40*X - 72
  671. roots zz;
  672. {X=2.0,
  673. X=-1 + 1.73205*I,
  674. X=-1 - 1.73205*I,
  675. X=0.981383 - 0.646597*I,
  676. X=-2.41613 + 1.19385*I,
  677. X=1.43475 + 2.45274*I}
  678. %{X=2.0, X=-1 + 1.73205*I, X=-1 - 1.73205*I,
  679. % X=0.981383 - 0.646597*I, X=-2.41613 + 1.19385*I,
  680. % X=1.43475 + 2.45274*I}
  681. nearestroot(zz,1);
  682. {X=0.981383 + 0.646597*I}
  683. %{X=0.981383 - 0.646597*I}
  684. % 52) roots can be computed to any accuracy desired, eg. (note that the
  685. % imaginary part of the second root is truncated because of its size,
  686. % and that the imaginary part of a complex root is never polished away,
  687. % even if it is smaller than the accuracy would require.)
  688. zz := x**3+10**(-20)*i*x**2+8;
  689. 1 2 3
  690. ZZ := -----------------------*I*X + X + 8
  691. 100000000000000000000
  692. rootacc 12;
  693. 12
  694. roots zz;
  695. {X=1 + 1.73205080757*I,X=1 - 1.73205080757*I,X=-2.0 - 3.33333E-21*I}
  696. rootacc 0;
  697. 6
  698. %{X=1 - 1.73205080757*I,X=1 + 1.73205080757*I,
  699. % X=-2.0 - 3.33333E-21*I}
  700. % 53) Precision increase to 12 required to find small imaginary root,
  701. % but standard accuracy can be used.
  702. zz := x**2+123456789i*x+1;
  703. 2
  704. ZZ := 123456789*I*X + X + 1
  705. roots zz;
  706. {X=0.0000000081*I,X=-123457000.0*I}
  707. %{X=0.0000000081*I,X=-123457000.0*I}
  708. % 54) Small real root is found with root 10*18 times larger(new).
  709. zz := (x+1)*(x**2+123456789*x+1);
  710. 3 2
  711. ZZ := X + 123456790*X + 123456790*X + 1
  712. roots zz;
  713. {X= - 0.0000000081,X=-1,X= - 123457000.0}
  714. %{X= - 0.0000000081,X= - 1.0,X= - 123457000.0}
  715. % 55) 2 complex, 3 real irrational roots.
  716. ss := (45*x**2+(-10i+12)*x-10i)*(x**3-5x**2+1);
  717. 4 3 2 5 4
  718. SS := - 10*I*X + 40*I*X + 50*I*X - 10*I*X - 10*I + 45*X - 213*X
  719. 3 2
  720. - 60*X + 45*X + 12*X
  721. roots ss;
  722. {X=0.469832,
  723. X= - 0.429174,
  724. X=4.95934,
  725. X=0.18139 + 0.417083*I,
  726. X=-0.448056 - 0.19486*I}
  727. %{X=0.469832,X= - 0.429174,X=4.95934,X=0.18139 + 0.417083*I,
  728. % X=-0.448056 - 0.19486*I}
  729. % 56) Complex polynomial with floating coefficients.
  730. zz := x**2+1.2i*x+2.3i+6.7;
  731. 2
  732. 12*I*X + 23*I + 10*X + 67
  733. ZZ := ----------------------------
  734. 10
  735. roots zz;
  736. {X=-0.42732 + 2.09121*I,X=0.42732 - 3.29121*I}
  737. %{X=-0.42732 + 2.09121*I,X=0.42732 - 3.29121*I}
  738. % multiple roots will be found if coefficients read in exactly.
  739. ZZ := X**3 + (1.09 - 2.4*I)*X**2 + (-1.44 - 2.616*I)*X + -1.5696;
  740. 2 3 2
  741. - 6000*I*X - 6540*I*X + 2500*X + 2725*X - 3600*X - 3924
  742. ZZ := -------------------------------------------------------------
  743. 2500
  744. roots zz;
  745. {X=1.2*I,X=1.2*I,X= - 1.09}
  746. %{X=1.2*I,X=1.2*I,X= - 1.09}
  747. % 57) Realroots, isolater and rlrootno accept 1, 2 or 3 arguments: (new)
  748. zz:= for j:=-1:3 product (x-j);
  749. 4 3 2
  750. ZZ := X*(X - 5*X + 5*X + 5*X - 6)
  751. rlrootno zz;
  752. 5
  753. % 5
  754. realroots zz;
  755. {X=0,
  756. X= - 1,
  757. X=1,
  758. X=2.0,
  759. X=3.0}
  760. %{X=0,X= -1,X=1,X=2.0,X=3.0}
  761. rlrootno(zz,positive);
  762. 3
  763. %positive selects positive, excluding 0.
  764. % 3
  765. rlrootno(zz,negative);
  766. 1
  767. %negative selects negative, excluding 0.
  768. % 1
  769. realroots(zz,positive);
  770. {X=1,X=2.0,X=3.0}
  771. %{X=1,X=2.0,X=3.0}
  772. rlrootno(zz,-1.5,2);
  773. 4
  774. %the format with 3 arguments selects a range.
  775. % 4
  776. realroots(zz,-1.5,2);
  777. {X=0,X= - 1,X=1,X=2.0}
  778. %the range is inclusive, except that:
  779. %{X=0,X=-1,X=1,X=2.0}
  780. % A specific limit b may be excluded by using exclude b. Also, the
  781. % limits infinity and -infinity can be specified.
  782. realroots(zz,exclude 0,infinity);
  783. {X=1,X=2.0,X=3.0}
  784. % equivalent to realroots(zz,positive).
  785. %{X=1,X=2.0,X=3.0}
  786. rlrootno(zz,-infinity,exclude 0);
  787. 1
  788. % equivalent to rlrootno(zz,negative).
  789. % 1
  790. rlrootno(zz,-infinity,0);
  791. 2
  792. % 2
  793. rlrootno(zz,infinity,-infinity);
  794. 5
  795. %equivalent to rlrootno zz; (order of limits does not matter.)
  796. % 5
  797. realroots(zz,1,infinity);
  798. {X=1,X=2.0,X=3.0}
  799. % finds all real roots >= 1.
  800. %{X=1,X=2.0,X=3.0}
  801. realroots(zz,1,positive);
  802. {X=2.0,X=3.0}
  803. % finds all real roots > 1.
  804. %{X=2.0,X=3.0}
  805. % New capabilities added in mod 1.88.
  806. % 58) 3 complex roots, with two separated by very small real difference.
  807. zz :=(x+i)*(x+10**8i)*(x+10**8i+1);
  808. 2 3 2
  809. ZZ := 200000001*I*X + 100000001*I*X - 10000000000000000*I + X + X
  810. - 10000000200000000*X - 100000000
  811. roots zz;
  812. {X= - I,X=-1.0E+8*I,X=-1 - 1.0E+8*I}
  813. %{X= - I,X=-1.0E+8*I,X=-1 - 1.0E+8*I}
  814. % 59) Real polynomial with two complex roots separated by very small
  815. % imaginary part.
  816. zz:= (10**14x+123456789000000+i)*(10**14x+123456789000000-i);
  817. 2
  818. ZZ := 10000000000000000000000000000*X
  819. + 24691357800000000000000000000*X
  820. + 15241578750190521000000000001
  821. roots zz;
  822. {X=-1.23457 + 1.0E-14*I,X=-1.23457 - 1.0E-14*I}
  823. %{X=-1.23457 + 1.0E-14*I,X=-1.23457 - 1.0E-14*I}
  824. % 60) Real polynomial with two roots extremely close together.
  825. zz:= (x+2)*(10**10x+12345678901)*(10**10x+12345678900);
  826. 3 2
  827. ZZ := 100*(1000000000000000000*X + 4469135780100000000*X
  828. + 6462429435342508889*X + 3048315750285017778)
  829. roots zz;
  830. {X= - 1.2345678901,X= - 1.23456789,X= - 2.0}
  831. %{X= - 1.2345678901,X= - 1.23456789,X= - 2.0}
  832. % 61) Real polynomial with multiple root extremely close to simple root.
  833. zz:= (x-12345678/10000000)*(x-12345679/10000000)**2;
  834. 3 2
  835. ZZ := (500000000000000000000*X - 1851851800000000000000*X
  836. + 2286236726108825000000*X - 940838132549050755399)/
  837. 500000000000000000000
  838. roots zz;
  839. {X=1.2345679,X=1.2345679,X=1.2345678}
  840. %{X=1.2345679,X=1.2345679,X=1.2345678}
  841. % 62) Similar problem using realroots.
  842. zz:=(x-2**30/10**8)**2*(x-(2**30+1)/10**8);
  843. 3 2
  844. ZZ := (610351562500000000*X - 19660800006103515625*X
  845. + 211106232664064000000*X - 755578637962830675968)/
  846. 610351562500000000
  847. realroots zz;
  848. {X=10.73741824,X=10.73741824,X=10.73741825}
  849. %{X=10.73741824,X=10.73741824,X=10.73741825}
  850. % 63) Three complex roots with small real separation between two.
  851. zz:= (x-i)*(x-1-10**8i)*(x-2-10**8i);
  852. 2 3
  853. ZZ := - 200000001*I*X + 300000003*I*X + 9999999999999998*I + X
  854. 2
  855. - 3*X - 10000000199999998*X + 300000000
  856. roots zz;
  857. {X=I,X=1 + 1.0E+8*I,X=2.0 + 1.0E+8*I}
  858. %{X=I,X=1 + 1.0E+8*I,X=2.0 + 1.0E+8*I}
  859. % 64) Use of nearestroot to isolate one of the close roots.
  860. nearestroot(zz,10**8i+99/100);
  861. {X=1 + 1.0E+8*I}
  862. % {X=1 + 1.0E+8*I}
  863. % 65) Slightly more complicated example with close complex roots.
  864. zz:= (x-i)*(10**8x-1234-10**12i)*(10**8x-1233-10**12i);
  865. 2
  866. ZZ := 2*( - 100005000000000000000*I*X + 1233623350000000*I*X
  867. 3
  868. + 499999999999999999239239*I + 5000000000000000*X
  869. 2
  870. - 123350000000*X - 500099999999999999239239*X
  871. + 1233500000000000)
  872. roots zz;
  873. {X=I,X=0.00001233 + 10000.0*I,X=0.00001234 + 10000.0*I}
  874. %{X=I,X=0.00001233 + 10000.0*I,X=0.00001234 + 10000.0*I}
  875. % 66) Four closely spaced real roots with varying spacings.
  876. zz:= (x-1+1/10**7)*(x-1+1/10**8)*(x-1)*(x-1-1/10**7);
  877. 4 3
  878. ZZ := (10000000000000000000000*X - 39999999900000000000000*X
  879. 2
  880. + 59999999699999900000000*X - 39999999699999800000001*X
  881. + 9999999899999900000001)/10000000000000000000000
  882. roots zz;
  883. {X=1,X=0.99999999,X=0.9999999,X=1.0000001}
  884. %{X=1,X=0.9999999,X=0.99999999,X=1.0000001}
  885. % 67) Complex pair plus two close real roots.
  886. zz:= (x**2+1)*(x-12345678/10000000)*(x-12345679/10000000);
  887. 4 3 2
  888. ZZ := (50000000000000*X - 123456785000000*X + 126207888812681*X
  889. - 123456785000000*X + 76207888812681)/50000000000000
  890. roots zz;
  891. {X=1.2345678,X=1.2345679,X=I,X= - I}
  892. %{X=1.2345678,X=1.2345679,X=I,X= - I}
  893. % 68) Same problem using realroots to find only real roots.
  894. realroots zz;
  895. {X=1.2345678,X=1.2345679}
  896. %{X=1.2345678,X=1.2345679}
  897. % The switch ratroot causes output to be given in rational form.
  898. % 69) Two complex roots with output in rational form.
  899. on ratroot,complex;
  900. zz:=x**2-(5i+1)*x+1;
  901. 2
  902. ZZ := X - (1 + 5*I)*X + 1
  903. sss:= roots zz;
  904. 17343 - 93179*I 96531 + 518636*I
  905. SSS := {X=-----------------,X=------------------}
  906. 500000 100000
  907. % 17343 - 93179*I 96531 + 518636*I
  908. %SSS := {X=-----------------,X=------------------}
  909. % 500000 100000
  910. % With roots in rational form, mkpoly can be used to reconstruct a
  911. % polynomial.
  912. zz1 := mkpoly sss;
  913. 2
  914. ZZ1 := 50000000000*X - (49999800000 + 250000100000*I)*X
  915. + (50000120977 + 42099*I)
  916. % 2
  917. %ZZ1 := 50000000000*X - (49999800000 + 250000100000*I)*X + (
  918. %
  919. % 50000120977 + 42099*I)
  920. % Finding the roots of the new polynomial zz1.
  921. rr:= roots zz1;
  922. 17343 - 93179*I 96531 + 518636*I
  923. RR := {X=-----------------,X=------------------}
  924. 500000 100000
  925. % 17343 - 93179*I 96531 + 518636*I
  926. %RR := {X=-----------------,X=------------------}
  927. % 500000 100000
  928. % The roots are stable to the extent that rr=ss, although zz1 and
  929. % zz may differ.
  930. zz1 - zz;
  931. 2
  932. 49999999999*X - (49999799999 + 250000099995*I)*X
  933. + (50000120976 + 42099*I)
  934. % 2
  935. %49999999999*X - (49999799999 + 250000099995*I)*X + (50000120976 +
  936. %
  937. % 42099*I)
  938. % 70) Same type of problem in which roots are found exactly.
  939. zz:=(x-10**8+i)*(x-10**8-i)*(x-10**8+3i/2)*(x-i);
  940. 4 3 2
  941. ZZ := (2*X - (600000000 - I)*X + 60000000000000005*X
  942. - (2000000000000000800000000 + 29999999999999999*I)*X
  943. + (30000000000000003 + 2000000000000000200000000*I))/2
  944. rr := roots zz;
  945. 200000000 - 3*I
  946. RR := {X=100000000 + I,X=100000000 - I,X=I,X=-----------------}
  947. 2
  948. % 4 3 2
  949. %ZZ := (2*X - (600000000 - I)*X + 60000000000000005*X - (
  950. %
  951. % 2000000000000000800000000 + 29999999999999999*I)*X + (
  952. %
  953. % 30000000000000003 + 2000000000000000200000000*I))/2
  954. %RR := {X=100000000 + I,X=100000000 - I,X=I,X=
  955. %
  956. % 200000000 - 3*I
  957. % -----------------}
  958. % 2
  959. % Reconstructing a polynomial from the roots.
  960. ss := mkpoly rr;
  961. 4 3 2
  962. SS := 2*X - (600000000 - I)*X + 60000000000000005*X
  963. - (2000000000000000800000000 + 29999999999999999*I)*X
  964. + (30000000000000003 + 2000000000000000200000000*I)
  965. % 4 3 2
  966. %SS := 2*X - (600000000 - I)*X + 60000000000000005*X - (
  967. %
  968. % 2000000000000000800000000 + 29999999999999999*I)*X + (
  969. %
  970. % 30000000000000003 + 2000000000000000200000000*I)
  971. % In this case, the same polynomial is obtained.
  972. ss - num zz;
  973. 0
  974. % 0
  975. % 71) Finding one of the complex roots using nearestroot.
  976. nearestroot(zz,10**8-2i);
  977. 200000000 - 3*I
  978. {X=-----------------}
  979. 2
  980. % 200000000 - 3*I
  981. %{X=-----------------}
  982. % 2
  983. % Finding the other complex root using nearestroot.
  984. nearestroot(zz,10**8+2i);
  985. {X=100000000 + I}
  986. %{X=100000000 + I}
  987. % 72) A realroots problem which requires accuracy increase to avoid
  988. % confusion of two roots.
  989. zz:=(x+1)*(10000000x-19999999)*(1000000x-2000001)*(x-2);
  990. 4 3 2
  991. ZZ := 10000000000000*X - 50000009000000*X + 60000026999999*X
  992. + 40000000000001*X - 80000035999998
  993. realroots zz;
  994. 19999999 2000001
  995. {X=-1,X=----------,X=2,X=---------}
  996. 10000000 1000000
  997. % 19999999 2000001
  998. % {X=-1,X=----------,X=2,X=---------}
  999. % 10000000 1000000
  1000. % 73) Without the accuracy increase, this example would produce the
  1001. % obviously incorrect answer 2.
  1002. realroots(zz,3/2,exclude 2);
  1003. 19999999
  1004. {X=----------}
  1005. 10000000
  1006. % 19999999
  1007. % {X=----------}
  1008. % 10000000
  1009. % Rlrootno also gives the correct answer in this case.
  1010. rlrootno(zz,3/2,exclude 2);
  1011. 1
  1012. % 1
  1013. % 74) Roots works equally well in this problem.
  1014. rr := roots zz;
  1015. 19999999 2000001
  1016. RR := {X=----------,X=2,X=-1,X=---------}
  1017. 10000000 1000000
  1018. % 19999999 2000001
  1019. % RR := {X=----------,X=-1,X=2,X=---------}
  1020. % 10000000 1000000
  1021. % 75) The function getroot is convenient for obtaining the value of a
  1022. % root.
  1023. rr1 := getroot(1,rr);
  1024. 19999999
  1025. RR1 := ----------
  1026. 10000000
  1027. % 19999999
  1028. % RR1 := ----------
  1029. % 10000000
  1030. % 76) For example, the value can be used as an argument to nearestroot.
  1031. nearestroot(zz,rr1);
  1032. 19999999
  1033. {X=----------}
  1034. 10000000
  1035. % 19999999
  1036. % {X=----------}
  1037. % 10000000
  1038. comment New capabilities added to Mod 1.90 for avoiding floating point
  1039. exceptions and exceeding iteration limits;
  1040. % 77) This and the next example would previously have aborted because
  1041. %of exceeding iteration limits:
  1042. off ratroot;
  1043. zz := x**16 - 900x**15 -2;
  1044. 16 15
  1045. ZZ := X - 900*X - 2
  1046. roots zz;
  1047. {X= - 0.665423,
  1048. X=0.069527 + 0.661817*I,
  1049. X=0.069527 - 0.661817*I,
  1050. X=0.650944 + 0.138369*I,
  1051. X=0.650944 - 0.138369*I,
  1052. X=-0.205664 + 0.632867*I,
  1053. X=-0.205664 - 0.632867*I,
  1054. X=-0.607902 + 0.270641*I,
  1055. X=-0.607902 - 0.270641*I,
  1056. X=0.332711 + 0.57633*I,
  1057. X=0.332711 - 0.57633*I,
  1058. X=0.538375 + 0.391176*I,
  1059. X=0.538375 - 0.391176*I,
  1060. X=-0.44528 + 0.494497*I,
  1061. X=-0.44528 - 0.494497*I,
  1062. X=900.0}
  1063. %{X= - 0.665423,X=0.069527 + 0.661817*I,X=0.069527 - 0.661817*I,
  1064. % X=0.650944 + 0.138369*I,X=0.650944 - 0.138369*I,
  1065. % X=-0.205664 + 0.632867*I,X=-0.205664 - 0.632867*I,
  1066. % X=-0.607902 + 0.270641*I,X=-0.607902 - 0.270641*I,
  1067. % X=0.332711 + 0.57633*I,X=0.332711 - 0.57633*I,
  1068. % X=0.538375 + 0.391176*I,X=0.538375 - 0.391176*I,
  1069. % X=-0.44528 + 0.494497*I,X=-0.44528 - 0.494497*I,X=900.0}
  1070. % 78) a still harder example.
  1071. % This example is commented out, since it takes significant time:
  1072. % z := x**30 - 900x**29 - 2; roots zz;
  1073. %{X= - 0.810021,
  1074. % X=-0.04388 + 0.808856*I,X=-0.04388 - 0.808856*I,
  1075. % X=0.805322 + 0.087587*I,X=0.805322 - 0.087587*I,
  1076. % X=0.131027 + 0.799383*I,X=0.131027 - 0.799383*I,
  1077. % X=-0.791085 + 0.174125*I,X=-0.791085 - 0.174125*I,
  1078. % X=-0.216732 + 0.780507*I,X=-0.216732 - 0.780507*I,
  1079. % X=0.767663 + 0.258664*I,X=0.767663 - 0.258664*I,
  1080. % X=0.299811 + 0.752532*I,X=0.299811 - 0.752532*I,
  1081. % X=-0.735162 + 0.340111*I,X=-0.735162 - 0.340111*I,
  1082. % X=-0.379447 + 0.715665*I,X=-0.379447 - 0.715665*I,
  1083. % X=0.694106 + 0.417645*I,X=0.694106 - 0.417645*I,
  1084. % X=-0.524417 + 0.617362*I,X=-0.524417 - 0.617362*I,
  1085. % X=0.454578 + 0.67049*I,X=0.454578 - 0.67049*I,
  1086. % X=-0.644866 + 0.490195*I,X=-0.644866 - 0.490195*I,
  1087. % X=0.588091 + 0.557094*I,X=0.588091 - 0.557094*I,X=900.0}
  1088. % 79) this deceptively simple example previously caused floating point
  1089. % overflows on some systems:
  1090. aa := x**6 - 4*x**3 + 2;
  1091. 6 3
  1092. AA := X - 4*X + 2
  1093. realroots aa;
  1094. {X=0.836719,X=1.50579}
  1095. %{X=0.836719,X=1.50579}
  1096. % 80) a harder problem, which would have failed on almost all systems:
  1097. rr := x**16 - 90000x**15 - x**2 -2;
  1098. 16 15 2
  1099. RR := X - 90000*X - X - 2
  1100. realroots rr;
  1101. {X= - 0.493299,X=90000.0}
  1102. %{X= - 0.493299,X=90000.0}
  1103. % 81) this example would have failed because of floating point
  1104. % exceptions on almost all computer systems.
  1105. rr := X**30 - 9*10**10*X**29 - 2;
  1106. 30 29
  1107. RR := X - 90000000000*X - 2
  1108. realroots rr;
  1109. {X= - 0.429188,X=9.0E+10}
  1110. %{X= - 0.429188,X=9.0E+10}
  1111. % 82) a test of allroot on this example.
  1112. % This example is commented out, since it takes significant time:
  1113. % roots rr;
  1114. %{X= - 0.429188,
  1115. % X=-0.023236 + 0.428559*I,X=-0.023236 - 0.428559*I,
  1116. % X=0.426672 + 0.046403*I,X=0.426672 - 0.046403*I,
  1117. % X=0.069435 + 0.423534*I,X=0.069435 - 0.423534*I,
  1118. % X=-0.419154 + 0.092263*I,X=-0.419154 - 0.092263*I,
  1119. % X=-0.11482 + 0.413544*I,X=-0.11482 - 0.413544*I,
  1120. % X=0.406722 + 0.13704*I,X=0.406722 - 0.13704*I,
  1121. % X=0.158859 + 0.398706*I,X=0.158859 - 0.398706*I,
  1122. % X=-0.389521 + 0.180211*I,X=-0.389521 - 0.180211*I,
  1123. % X=-0.201035 + 0.379193*I,X=-0.201035 - 0.379193*I,
  1124. % X=0.367753 + 0.22127*I,X=0.367753 - 0.22127*I,
  1125. % X=-0.277851 + 0.327111*I,X=-0.277851 - 0.327111*I,
  1126. % X=0.240855 + 0.355234*I,X=0.240855 - 0.355234*I,
  1127. % X=-0.341674 + 0.259734*I,X=-0.341674 - 0.259734*I,
  1128. % X=0.311589 + 0.295153*I,X=0.311589 - 0.295153*I,X=9.0E+10}
  1129. % 83) test of starting point for iteration: no convergence if good
  1130. % real starting point is not found.
  1131. zz := x**30 -9*10**12x**29 -2;
  1132. 30 29
  1133. ZZ := X - 9000000000000*X - 2
  1134. firstroot zz;
  1135. {X= - 0.36617}
  1136. %{X= - 0.36617}
  1137. % 84) a case in which there are no real roots and good imaginary
  1138. % starting point must be used or roots cannot be found.
  1139. zz:= 9x**16 - x**5 +1;
  1140. 16 5
  1141. ZZ := 9*X - X + 1
  1142. roots zz;
  1143. {X=0.182294 + 0.828368*I,
  1144. X=0.182294 - 0.828368*I,
  1145. X=-0.697397 + 0.473355*I,
  1146. X=-0.697397 - 0.473355*I,
  1147. X=0.845617 + 0.142879*I,
  1148. X=0.845617 - 0.142879*I,
  1149. X=-0.161318 + 0.87905*I,
  1150. X=-0.161318 - 0.87905*I,
  1151. X=-0.866594 + 0.193562*I,
  1152. X=-0.866594 - 0.193562*I,
  1153. X=0.459373 + 0.737443*I,
  1154. X=0.459373 - 0.737443*I,
  1155. X=0.748039 + 0.494348*I,
  1156. X=0.748039 - 0.494348*I,
  1157. X=-0.510014 + 0.716449*I,
  1158. X=-0.510014 - 0.716449*I}
  1159. %{X=0.182294 + 0.828368*I,X=0.182294 - 0.828368*I,
  1160. % X=-0.697397 + 0.473355*I,X=-0.697397 - 0.473355*I,
  1161. % X=0.845617 + 0.142879*I,X=0.845617 - 0.142879*I,
  1162. % X=-0.161318 + 0.87905*I,X=-0.161318 - 0.87905*I,
  1163. % X=-0.866594 + 0.193562*I,X=-0.866594 - 0.193562*I,
  1164. % X=0.459373 + 0.737443*I,X=0.459373 - 0.737443*I,
  1165. % X=0.748039 + 0.494348*I,X=0.748039 - 0.494348*I,
  1166. % X=-0.510014 + 0.716449*I,X=-0.510014 - 0.716449*I}
  1167. % 85) five complex roots.
  1168. zz := x**5 - x**3 + i;
  1169. 5 3
  1170. ZZ := X - X + I
  1171. roots zz;
  1172. {X=-0.83762*I,
  1173. X=-0.664702 + 0.636663*I,
  1174. X=0.664702 + 0.636663*I,
  1175. X=1.16695 - 0.21785*I,
  1176. X=-1.16695 - 0.21785*I}
  1177. %{X=-0.83762*I,X=-0.664702 + 0.636663*I,X=0.664702 + 0.636663*I,
  1178. % X=1.16695 - 0.21785*I,X=-1.16695 - 0.21785*I}
  1179. % Additional capabilities in Mod 1.91.
  1180. % 86) handling of polynomial with huge or infinitesimal coefficients.
  1181. on rounded;
  1182. *** Domain mode COMPLEX changed to COMPLEX-ROUNDED
  1183. zz:= 1.0e-500x**3+x**2+x;
  1184. 2
  1185. ZZ := X*(1.0E-500*X + X + 1)
  1186. roots zz;
  1187. {X=0,X=-1,X= - 1.0E+500}
  1188. off rounded;
  1189. *** Domain mode COMPLEX-ROUNDED changed to COMPLEX
  1190. %{X=0,X=-1,X= - 1.0E+500}
  1191. % switch roundbf will have been turned on in the last example in most
  1192. % computer systems. This will inhibit the use of hardware floating
  1193. % point unless roundbf is turned off.
  1194. % polynomials which make use of powergcd substitution and cascaded
  1195. % solutions.
  1196. % Uncomplicated cases.
  1197. switch powergcd;
  1198. % introduced here to verify that same answers are
  1199. % obtained with and without employing powergcd strategy. Roots are
  1200. % found faster for applicable cases when !*powergcd=t (default state.)
  1201. % 87) powergcd done at the top level.
  1202. zz := x**12-5x**9+1;
  1203. 12 9
  1204. ZZ := X - 5*X + 1
  1205. roots zz;
  1206. {X=0.848444,
  1207. X=-0.424222 + 0.734774*I,
  1208. X=-0.424222 - 0.734774*I,
  1209. X=0.152522 - 0.816316*I,
  1210. X=-0.783212 + 0.276071*I,
  1211. X=0.63069 + 0.540246*I,
  1212. X=0.152522 + 0.816316*I,
  1213. X=-0.783212 - 0.276071*I,
  1214. X=0.63069 - 0.540246*I,
  1215. X=1.70906,
  1216. X=-0.85453 + 1.48009*I,
  1217. X=-0.85453 - 1.48009*I}
  1218. %{X=0.848444,X=-0.424222 + 0.734774*I,X=-0.424222 - 0.734774*I,
  1219. % X=0.152522 - 0.816316*I,
  1220. % X=-0.783212 + 0.276071*I,X=0.63069 + 0.540246*I,
  1221. % X=0.152522 + 0.816316*I,
  1222. % X=-0.783212 - 0.276071*I,X=0.63069 - 0.540246*I,
  1223. % X=1.70906,X=-0.85453 + 1.48009*I,X=-0.85453 - 1.48009*I}
  1224. off powergcd;
  1225. roots zz;
  1226. {X=0.848444,
  1227. X=-0.424222 + 0.734774*I,
  1228. X=-0.424222 - 0.734774*I,
  1229. X=1.70906,
  1230. X=-0.783212 + 0.276071*I,
  1231. X=-0.783212 - 0.276071*I,
  1232. X=0.152522 + 0.816316*I,
  1233. X=0.152522 - 0.816316*I,
  1234. X=0.63069 + 0.540246*I,
  1235. X=0.63069 - 0.540246*I,
  1236. X=-0.85453 + 1.48009*I,
  1237. X=-0.85453 - 1.48009*I}
  1238. on powergcd;
  1239. %{X=0.848444,X=-0.424222 + 0.734774*I,X=-0.424222 - 0.734774*I,
  1240. % X=1.70906,X=-0.783212 + 0.276071*I,X=-0.783212 - 0.276071*I,
  1241. % X=0.152522 + 0.816316*I,X=0.152522 - 0.816316*I,
  1242. % X=0.63069 + 0.540246*I,X=0.63069 - 0.540246*I,
  1243. % X=-0.85453 + 1.48009*I,X=-0.85453 - 1.48009*I}
  1244. % 88) powergcd done after square free factoring.
  1245. zz := (x-1)**2*zz;
  1246. 14 13 12 11 10 9 2
  1247. ZZ := X - 2*X + X - 5*X + 10*X - 5*X + X - 2*X + 1
  1248. roots zz;
  1249. {X=1,
  1250. X=1,
  1251. X=0.848444,
  1252. X=-0.424222 + 0.734774*I,
  1253. X=-0.424222 - 0.734774*I,
  1254. X=0.152522 - 0.816316*I,
  1255. X=-0.783212 + 0.276071*I,
  1256. X=0.63069 + 0.540246*I,
  1257. X=0.152522 + 0.816316*I,
  1258. X=-0.783212 - 0.276071*I,
  1259. X=0.63069 - 0.540246*I,
  1260. X=1.70906,
  1261. X=-0.85453 + 1.48009*I,
  1262. X=-0.85453 - 1.48009*I}
  1263. %{X=1,X=1,
  1264. % X=0.848444,X=-0.424222 + 0.734774*I,X=-0.424222 - 0.734774*I,
  1265. % X=0.152522 - 0.816316*I,X=-0.783212 + 0.276071*I,
  1266. % X=0.63069 + 0.540246*I,
  1267. % X=0.152522 + 0.816316*I,X=-0.783212 - 0.276071*I,
  1268. % X=0.63069 - 0.540246*I,
  1269. % X=1.70906,X=-0.85453 + 1.48009*I,X=-0.85453 - 1.48009*I}
  1270. off powergcd;
  1271. roots zz;
  1272. {X=1,
  1273. X=1,
  1274. X=0.848444,
  1275. X=-0.424222 + 0.734774*I,
  1276. X=-0.424222 - 0.734774*I,
  1277. X=1.70906,
  1278. X=-0.783212 + 0.276071*I,
  1279. X=-0.783212 - 0.276071*I,
  1280. X=0.152522 + 0.816316*I,
  1281. X=0.152522 - 0.816316*I,
  1282. X=0.63069 + 0.540246*I,
  1283. X=0.63069 - 0.540246*I,
  1284. X=-0.85453 + 1.48009*I,
  1285. X=-0.85453 - 1.48009*I}
  1286. on powergcd;
  1287. %{X=1,X=1,
  1288. % X=0.848444,X=-0.424222 + 0.734774*I,X=-0.424222 - 0.734774*I,
  1289. % X=1.70906,X=-0.783212 + 0.276071*I,X=-0.783212 - 0.276071*I,
  1290. % X=0.152522 + 0.816316*I,X=0.152522 - 0.816316*I,
  1291. % X=0.63069 + 0.540246*I,X=0.63069 - 0.540246*I,
  1292. % X=-0.85453 + 1.48009*I,X=-0.85453 - 1.48009*I}
  1293. % 89) powergcd done after separation into real and complex polynomial.
  1294. zz := x**5-i*x**4+x**3-i*x**2+x-i;
  1295. 5 4 3 2
  1296. ZZ := X - I*X + X - I*X + X - I
  1297. roots zz;
  1298. {X=0.5 + 0.866025*I,
  1299. X=-0.5 - 0.866025*I,
  1300. X=-0.5 + 0.866025*I,
  1301. X=0.5 - 0.866025*I,
  1302. X=I}
  1303. %{X=0.5 + 0.866025*I,X=-0.5 - 0.866025*I,
  1304. % X=-0.5 + 0.866025*I,X=0.5 - 0.866025*I,X=I}
  1305. off powergcd;
  1306. roots zz;
  1307. {X=-0.5 + 0.866025*I,
  1308. X=-0.5 - 0.866025*I,
  1309. X=0.5 + 0.866025*I,
  1310. X=0.5 - 0.866025*I,
  1311. X=I}
  1312. on powergcd;
  1313. %{X=-0.5 + 0.866025*I,X=-0.5 - 0.866025*I,
  1314. % X=0.5 + 0.866025*I,X=0.5 - 0.866025*I,X=I}
  1315. % Cases where root separation requires accuracy and/or precision
  1316. % increase. In some examples we get excess accuracy, but it is hard
  1317. % avoid this and still get all roots separated.
  1318. % 90) accuracy increase required to separate close roots;
  1319. let x=y**2;
  1320. zz:= (x-3)*(100000000x-300000001);
  1321. 4 2
  1322. ZZ := 100000000*Y - 600000001*Y + 900000003
  1323. roots zz;
  1324. *** Roots precision increase to 22
  1325. {Y=1.732050808,Y= - 1.732050808,Y=1.73205081,Y= - 1.73205081}
  1326. %{Y=1.732050808,Y= - 1.732050808,Y=1.73205081,Y= - 1.73205081}
  1327. off powergcd;
  1328. roots zz;
  1329. {Y=1.732050808,Y= - 1.732050808,Y= - 1.73205081,Y=1.73205081}
  1330. on powergcd;
  1331. %{Y=1.732050808,Y= - 1.732050808,Y= - 1.73205081,Y=1.73205081}
  1332. % 91) roots to be separated are on different square free factors.
  1333. zz:= (x-3)**2*(10000000x-30000001);
  1334. 6 4 2
  1335. ZZ := 10000000*Y - 90000001*Y + 270000006*Y - 270000009
  1336. roots zz;
  1337. {Y=1.73205081,
  1338. Y=1.73205081,
  1339. Y= - 1.73205081,
  1340. Y= - 1.73205081,
  1341. Y=1.73205084,
  1342. Y= - 1.73205084}
  1343. %{Y=1.73205081 ,Y=1.73205081 ,Y= - 1.73205081 ,Y= - 1.73205081 ,
  1344. % Y=1.73205084 ,Y= - 1.73205084}
  1345. off powergcd;
  1346. roots zz;
  1347. {Y=1.73205081,
  1348. Y=1.73205081,
  1349. Y= - 1.73205081,
  1350. Y= - 1.73205081,
  1351. Y=1.73205084,
  1352. Y= - 1.73205084}
  1353. on powergcd;
  1354. %{Y=1.73205081 ,Y=1.73205081 ,Y= - 1.73205081,Y= - 1.73205081,
  1355. % Y=1.73205084 ,Y= - 1.73205084}
  1356. % 92) roots must be separated in the complex polynomial factor only.
  1357. zz :=(y+1)*(x+10**8i)*(x+10**8i+1);
  1358. 5 4 3 2
  1359. ZZ := Y + Y + (1 + 200000000*I)*Y + (1 + 200000000*I)*Y
  1360. - (10000000000000000 - 100000000*I)*Y
  1361. - (10000000000000000 - 100000000*I)
  1362. roots zz;
  1363. {Y=-1,
  1364. Y=-7071.067812 + 7071.067812*I,
  1365. Y=7071.067812 - 7071.067812*I,
  1366. Y=-7071.067777 + 7071.067847*I,
  1367. Y=7071.067777 - 7071.067847*I}
  1368. %{Y=-1,
  1369. % Y=-7071.067812 + 7071.067812*I,Y=7071.067812 - 7071.067812*I,
  1370. % Y=-7071.067777 + 7071.067847*I,Y=7071.067777 - 7071.067847*I}
  1371. % 93)
  1372. zz := (x-2)**2*(1000000x-2000001)*(y-1);
  1373. 7 6 5 4 3
  1374. ZZ := 1000000*Y - 1000000*Y - 6000001*Y + 6000001*Y + 12000004*Y
  1375. 2
  1376. - 12000004*Y - 8000004*Y + 8000004
  1377. roots zz;
  1378. {Y=1.4142136,
  1379. Y=1.4142136,
  1380. Y= - 1.4142136,
  1381. Y= - 1.4142136,
  1382. Y=1,
  1383. Y=1.4142139,
  1384. Y= - 1.4142139}
  1385. %{Y=1.4142136,Y=1.4142136,Y= - 1.4142136,Y= - 1.4142136,
  1386. % Y=1,Y=1.4142139,Y= - 1.4142139}
  1387. % 94)
  1388. zz := (x-2)*(10000000x-20000001);
  1389. 4 2
  1390. ZZ := 10000000*Y - 40000001*Y + 40000002
  1391. roots zz;
  1392. {Y=1.41421356,Y= - 1.41421356,Y=1.4142136,Y= - 1.4142136}
  1393. %{Y=1.41421356 ,Y= - 1.41421356 ,Y=1.4142136,Y= - 1.4142136}
  1394. % 95)
  1395. zz := (x-3)*(10000000x-30000001);
  1396. 4 2
  1397. ZZ := 10000000*Y - 60000001*Y + 90000003
  1398. roots zz;
  1399. {Y=1.73205081,Y= - 1.73205081,Y=1.73205084,Y= - 1.73205084}
  1400. %{Y=1.73205081 ,Y= - 1.73205081 ,Y=1.73205084 ,Y= - 1.73205084}
  1401. % 96)
  1402. zz := (x-9)**2*(1000000x-9000001);
  1403. 6 4 2
  1404. ZZ := 1000000*Y - 27000001*Y + 243000018*Y - 729000081
  1405. roots zz;
  1406. {Y=3.0,
  1407. Y=3.0,
  1408. Y= - 3.0,
  1409. Y= - 3.0,
  1410. Y=3.00000017,
  1411. Y= - 3.00000017}
  1412. %{Y=3.0,Y=3.0,Y= - 3.0,Y= - 3.0,Y=3.00000017,Y= - 3.00000017}
  1413. % 97)
  1414. zz := (x-3)**2*(1000000x-3000001);
  1415. 6 4 2
  1416. ZZ := 1000000*Y - 9000001*Y + 27000006*Y - 27000009
  1417. roots zz;
  1418. {Y=1.7320508,
  1419. Y=1.7320508,
  1420. Y= - 1.7320508,
  1421. Y= - 1.7320508,
  1422. Y=1.7320511,
  1423. Y= - 1.7320511}
  1424. %{Y=1.7320508,Y=1.7320508,Y= - 1.7320508,Y= - 1.7320508,
  1425. % Y=1.7320511,Y= - 1.7320511}
  1426. % 98) the accuracy of the root -sqrt 3 depends upon another close root.
  1427. on rounded;
  1428. *** Domain mode COMPLEX changed to COMPLEX-ROUNDED
  1429. zz := (x-3)*(y+1.732058);
  1430. 3 2
  1431. ZZ := Y + 1.732058*Y - 3*Y - 5.196174
  1432. roots zz;
  1433. {Y= - 1.732051,Y=1.73205,Y= - 1.732058}
  1434. %{Y= - 1.732051,Y=1.73205,Y= - 1.732058}
  1435. zz := (x-3)*(y+1.732051);
  1436. 3 2
  1437. ZZ := Y + 1.732051*Y - 3*Y - 5.196153
  1438. roots zz;
  1439. {Y= - 1.73205081,Y=1.73205,Y= - 1.732051}
  1440. %{Y= - 1.73205081,Y=1.73205,Y= - 1.732051}
  1441. zz := (x-3)*(y+1.73205081);
  1442. 3 2
  1443. ZZ := Y + 1.73205081*Y - 3*Y - 5.19615243
  1444. roots zz;
  1445. {Y= - 1.732050808,Y=1.73205,Y= - 1.73205081}
  1446. %{Y= - 1.732050808,Y=1.73205,Y= - 1.73205081}
  1447. % 99) minimum accuracy specified using rootacc.
  1448. rootacc 10;
  1449. 10
  1450. roots zz;
  1451. {Y= - 1.732050808,Y=1.732050808,Y= - 1.73205081}
  1452. %{Y= - 1.732050808,Y=1.732050808,Y= - 1.73205081}
  1453. % 100)
  1454. off rounded;
  1455. *** Domain mode COMPLEX-ROUNDED changed to COMPLEX
  1456. rootacc 6;
  1457. 6
  1458. zz := (y-i)*(x-2)*(1000000x-2000001);
  1459. 5 4 3 2
  1460. ZZ := 1000000*Y - (1000000*I)*Y - 4000001*Y + (4000001*I)*Y
  1461. + 4000002*Y - 4000002*I
  1462. roots zz;
  1463. {Y=1.4142136,Y= - 1.4142136,Y=1.4142139,Y= - 1.4142139,Y=I}
  1464. %{Y=1.4142136,Y= - 1.4142136,Y=1.4142139,Y= - 1.4142139,Y=I}
  1465. % 101) this example requires accuracy 15.
  1466. zz:= (y-2)*(100000000000000y-200000000000001);
  1467. 2
  1468. ZZ := 100000000000000*Y - 400000000000001*Y + 400000000000002
  1469. roots zz;
  1470. {Y=2.00000000000001,Y=2.0}
  1471. %{Y=2.0,Y=2.00000000000001}
  1472. % 102) still higher precision needed.
  1473. zz:= (y-2)*(10000000000000000000y-20000000000000000001);
  1474. 2
  1475. ZZ := 10000000000000000000*Y - 40000000000000000001*Y
  1476. + 40000000000000000002
  1477. roots zz;
  1478. {Y=2.000 00000 00000 00000 1,Y=2.0}
  1479. %{Y=2.000 00000 00000 00000 1,Y=2.0}
  1480. % 103) increase in precision required for substituted polynomial.
  1481. zz:= (x-2)*(10000000000x-20000000001);
  1482. 4 2
  1483. ZZ := 10000000000*Y - 40000000001*Y + 40000000002
  1484. roots zz;
  1485. {Y=1.41421356241,Y= - 1.41421356241,Y=1.41421356237,Y
  1486. = - 1.41421356237}
  1487. %{Y=1.41421356241,Y= - 1.41421356241,Y=1.41421356237,
  1488. % Y= - 1.41421356237}
  1489. % 104) still higher precision required for substituted polynomial.
  1490. zz:= (x-2)*(100000000000000x-200000000000001);
  1491. 4 2
  1492. ZZ := 100000000000000*Y - 400000000000001*Y + 400000000000002
  1493. roots zz;
  1494. {Y=1.414 21356 23730 99,Y= - 1.414 21356 23730 99,Y
  1495. =1.414 21356 23730 95,Y= - 1.414 21356 23730 95}
  1496. %{Y=1.414 21356 23730 99,Y= - 1.414 21356 23730 99,
  1497. % Y=1.414 21356 23730 95,Y= - 1.414 21356 23730 95}
  1498. % 105) accuracy must be increased to separate root of complex factor
  1499. % from root of real factor.
  1500. zz:=(9y-10)*(y-2)*(9y-10-9i/100000000);
  1501. 3 2
  1502. ZZ := (8100000000*Y - (34200000000 + 81*I)*Y
  1503. + (46000000000 + 252*I)*Y - (20000000000 + 180*I))/100000000
  1504. roots zz;
  1505. {Y=1.111111111,Y=2.0,Y=1.111111111 + 0.00000001*I}
  1506. %{Y=1.111111111,Y=2.0,Y=1.111111111 + 0.00000001*I}
  1507. % 106) realroots does the same accuracy increase for real root based
  1508. % upon the presence of a close complex root in the same polynomial.
  1509. % The reason for this might not be obvious unless roots is called.
  1510. realroots zz;
  1511. {Y=1.111111111,Y=2.0}
  1512. %{Y=1.111111111,Y=2.0}
  1513. % 107) realroots now uses powergcd logic whenever it is applicable.
  1514. zz := (x-1)*(x-2)*(x-3);
  1515. 6 4 2
  1516. ZZ := Y - 6*Y + 11*Y - 6
  1517. realroots zz;
  1518. {Y= - 1,
  1519. Y=1,
  1520. Y= - 1.41421,
  1521. Y=1.41421,
  1522. Y= - 1.73205,
  1523. Y=1.73205}
  1524. %{Y=-1,Y=1,Y= - 1.41421,Y=1.41421,Y= - 1.73205,Y=1.73205}
  1525. realroots(zz,exclude 1,2);
  1526. {Y=1.41421,Y=1.73205}
  1527. %{Y=1.41421,Y=1.73205}
  1528. % 108) root of degree 1 polynomial factor must be evaluated at
  1529. % precision 18 and accuracy 10 in order to separate it from a root of
  1530. % another real factor.
  1531. clear x;
  1532. zz:=(9x-10)**2*(9x-10-9/100000000)*(x-2);
  1533. 4 3 2
  1534. ZZ := (72900000000*X - 388800000729*X + 756000003078*X
  1535. - 640000004140*X + 200000001800)/100000000
  1536. roots zz;
  1537. {X=1.111111111,X=1.111111111,X=1.111111121,X=2.0}
  1538. %{X=1.111111111,X=1.111111111,X=1.111111121,X=2.0}
  1539. nearestroot(zz,1);
  1540. {X=1.111111111}
  1541. %{X=1.111111111}
  1542. nearestroot(zz,1.5);
  1543. {X=1.111111121}
  1544. %{X=1.111111121}
  1545. nearestroot(zz,1.65);
  1546. {X=2.0}
  1547. %{X=2.0}
  1548. % 109) in this example, precision >=40 is used and two roots need to be
  1549. % found to accuracy 16 and two to accuracy 14.
  1550. zz := (9x-10)*(7x-8)*(9x-10-9/10**12)*(7x-8-7/10**14);
  1551. 4
  1552. ZZ := (396900000000000000000000000000*X
  1553. 3
  1554. - 1789200000000400869000000000000*X
  1555. 2
  1556. + 3024400000001361556000000003969*X
  1557. - 2272000000001541380000000008946*X
  1558. + 640000000000581600000000005040)/100000000000000000000000000
  1559. roots zz;
  1560. {X=1.1111111111121,X=1.142 85714 28571 43,X=1.1111111111111,X
  1561. =1.142 85714 28571 53}
  1562. %{X=1.1111111111121,X=1.142 85714 28571 43,
  1563. % X=1.1111111111111,X=1.142 85714 28571 53}
  1564. % 110) very small real or imaginary parts of roots require high
  1565. % precision or exact computations, or they will be lost or incorrectly
  1566. % found.
  1567. zz := 1000000*R**18 + 250000000000*R**4 - 1000000*R**2 + 1;
  1568. 18 4 2
  1569. ZZ := 1000000*R + 250000000000*R - 1000000*R + 1
  1570. roots zz;
  1571. {R=0.00141421 + 1.6E-26*I,
  1572. R=-0.00141421 - 1.6E-26*I,
  1573. R=0.00141421 - 1.6E-26*I,
  1574. R=-0.00141421 + 1.6E-26*I,
  1575. R=2.36886 + 0.54068*I,
  1576. R=-2.36886 - 0.54068*I,
  1577. R=-2.36886 + 0.54068*I,
  1578. R=2.36886 - 0.54068*I,
  1579. R=1.05424 + 2.18916*I,
  1580. R=-1.05424 - 2.18916*I,
  1581. R=-1.05424 + 2.18916*I,
  1582. R=1.05424 - 2.18916*I,
  1583. R=2.42978*I,
  1584. R=-2.42978*I,
  1585. R=1.89968 + 1.51494*I,
  1586. R=-1.89968 - 1.51494*I,
  1587. R=-1.89968 + 1.51494*I,
  1588. R=1.89968 - 1.51494*I}
  1589. %{R=0.00141421 + 1.6E-26*I,R=-0.00141421 - 1.6E-26*I,
  1590. % R=0.00141421 - 1.6E-26*I,R=-0.00141421 + 1.6E-26*I,
  1591. % R=2.36886 + 0.54068*I,R=-2.36886 - 0.54068*I,
  1592. % R=-2.36886 + 0.54068*I,R=2.36886 - 0.54068*I,
  1593. % R=1.05424 + 2.18916*I,R=-1.05424 - 2.18916*I,
  1594. % R=-1.05424 + 2.18916*I,R=1.05424 - 2.18916*I,
  1595. % R=2.42978*I,R=-2.42978*I,
  1596. % R=1.89968 + 1.51494*I,R=-1.89968 - 1.51494*I,
  1597. % R=-1.89968 + 1.51494*I,R=1.89968 - 1.51494*I}
  1598. showtime;
  1599. Time: 573342 ms
  1600. end;
  1601. 4: 4:
  1602. Quitting
  1603. Sat Jun 29 13:58:15 PDT 1991