ROOTS.TST 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. % Tests of the root finding package.
  2. % Author: Stanley L. Kameny (stan_kameny@rand.org)
  3. comment Addition for roots mod 1.95. The function multroot has been
  4. added to the roots package in mod 1.95. This provides the capability
  5. to solve a nest of n polynomials in n variables, provided that each
  6. polynomial either is univariate or introduces a new variable to the
  7. set. The solutions can be either real solutions only, or complex
  8. solutions. All solutions to the new examples, problems 117) and
  9. subsequent, are correct to all digits shown. As in the prior examples,
  10. root order and values should agree exactly with that given here.
  11. comment This test file works only with Reduce version 3.5 and later
  12. and contains examples all of which are solved by roots mod 1.94.
  13. Answers are rounded to the value given by rootacc (default = 6)
  14. unless higher accuracy is needed to separate roots. Format may differ
  15. from that given here, but root order and values should agree exactly.
  16. (Although the function ROOTS may obtain the roots in a different order,
  17. they are sorted into a standard order in mod 1.94 and later.)
  18. In the following, problems 20) and 82) are time consuming and
  19. have been commented out to speed up the test.
  20. The hard examples 111) through 115) almost double the test time
  21. but are necessary to test some logical paths.
  22. A new "hardest" example has been added as example 116). It is
  23. commented out, since it is time consuming, but it is solved by roots
  24. mod 1.94. The time needed to run the three commented-out examples is
  25. almost exactly equal to the time for the rest of the test. Users of
  26. fast computers can uncomment the lines marked with %**%. The three
  27. examples by themselves are contained in the test file rootsxtr.tst.
  28. When answers are produced which require precision increase for
  29. printing out or input of roots, roots functions cause precision
  30. increase to occur. If the precision is already higher than the
  31. default value, a message is printed out warning of the the precision
  32. normally needed for input of those values.$
  33. realroots x; % To load roots package.
  34. write "This is Roots Package test ", symbolic roots!-mod$
  35. % Simple root finding.
  36. % 1) multiple real and imaginary roots plus two real roots.
  37. zz:= (x-3)**2*(100x**2+113)**2*(1000000x-10000111)*(x-1); roots zz;
  38. %{x=1.06301*i,x=1.06301*i,x=-1.06301*i,x=-1.06301*i,
  39. %x=3.0,x=3.0,x=1,x=10.0001} (rootacc caused rounding to 6 places)
  40. % Accuracy is increased whenever necessary to separate distinct roots.
  41. % 2) accuracy increase to 7 required for two roots.
  42. zz:=(x**2+1)*(x-2)*(1000000x-2000001); roots zz;
  43. %{x=i,x= -i,x=2.0,x=2.000001}
  44. % 3) accuracy increase to 8 required.
  45. zz:= (x-3)*(10000000x-30000001); roots zz;
  46. %{x=3.0,x=3.0000001}
  47. % 4) accuracy increase required here to separate repeated root from
  48. % simple root.
  49. zz := (x-3)*(1000000x-3000001)*(x-3)*(1000000x-3241234); roots zz;
  50. %{x=3.0,x=3.0,x=3.000001,x=3.24123}
  51. % other simple examples
  52. % 5) five real roots with widely different spacing.
  53. zz:= (x-1)*(10x-11)*(x-1000)*(x-1001)*(x-100000); roots zz;
  54. %{x=1,x=1.1,x=1000.0,x=1001.0,x=1.0E+5}
  55. % 6) a cluster of 5 roots in complex plane in vicinity of x=1.
  56. zz:= (x-1)*(10000x**2-20000x+10001)*(10000x**2-20000x+9999); roots zz;
  57. %{x=0.99,x=1,x=1 + 0.01*i,x=1 - 0.01*i,x=1.01}
  58. % 7) four closely spaced real roots.
  59. zz := (x-1)*(100x-101)*(100x-102)*(100x-103); roots zz;
  60. %{x=1,x=1.01,x=1.02,x=1.03}
  61. % 8) five closely spaced roots, 3 real + 1 complex pair.
  62. zz := (x-1)*(100x-101)*(100x-102)*(100x**2-200x+101); roots zz;
  63. %{x=1,x=1 + 0.1*i,x=1 - 0.1*i,x=1.01,x=1.02}
  64. % 9) symmetric cluster of 5 roots, 3 real + 1 complex pair.
  65. zz := (x-2)*(10000x**2-40000x+40001)*(10000x**2-40000x+39999); roots zz;
  66. %{x=1.99,x=2.0,x=2.0 + 0.01*i,x=2.0 - 0.01*i,x=2.01}
  67. % 10) closely spaced real and complex pair.
  68. ss:= (x-2)*(100000000x**2-400000000x+400000001); roots ss;
  69. %{x=2.0,x=2.0 + 0.0001*i,x=2.0 - 0.0001*i}
  70. % 11) Zero roots and multiple roots cause no problem.
  71. % Multiple roots are shown when the switch multiroot is on
  72. %(normally on.)
  73. zz:= x*(x-1)**2*(x-4)**3*(x**2+1); roots zz;
  74. %{x=0,x=4.0,x=4.0,x=4.0,x=1,x=1,x=i,x= - i}
  75. % 12) nearestroot will find a single root "near" a value, real or
  76. % complex.
  77. nearestroot(zz,2i);
  78. %{x=i}
  79. % More difficult examples.
  80. % Three examples in which root scaling is needed in the complex
  81. % iteration process.
  82. % 13) nine roots, 3 real and 3 complex pairs.
  83. zz:= x**9-45x-2; roots zz;
  84. %{x= - 1.60371,x=-1.13237 + 1.13805*i,x=-1.13237 - 1.13805*i,
  85. % x= - 0.0444444,x=0.00555357 + 1.60944*i,x=0.00555357 - 1.60944*i,
  86. % x=1.14348 + 1.13804*i,x=1.14348 - 1.13804*i,x=1.61483}
  87. comment In the next two examples, there are complex roots with
  88. extremely small real parts (new capability in Mod 1.91.);
  89. % 14) nine roots, 1 real and 4 complex pairs.
  90. zz:= x**9-9999x**2-0.01; roots zz;
  91. %{x=-3.3584 + 1.61732*i,x=-3.3584 - 1.61732*i,
  92. % x=-0.829456 + 3.63408*i,x=-0.829456 - 3.63408*i,
  93. % x=5.0025E-29 + 0.00100005*i,x=5.0025E-29 - 0.00100005*i,
  94. % x=2.32408 + 2.91431*i,x=2.32408 - 2.91431*i,x=3.72754}
  95. comment Rootacc 7 produces 7 place accuracy. Answers will print in
  96. bigfloat format if floating point print >6 digits is not implemented.;
  97. % 15) nine roots, 1 real and 4 complex pairs.
  98. rootacc 7; zz:= x**9-500x**2-0.001; roots zz;
  99. %{x=-2.189157 + 1.054242*i,x=-2.189157 - 1.054242*i,
  100. % x=-0.5406772 + 2.368861*i,x=-0.5406772 - 2.368861*i,
  101. % x=1.6E-26 + 0.001414214*i,x=1.6E-26 - 0.001414214*i,
  102. % x=1.514944 + 1.899679*i,x=1.514944 - 1.899679*i,x=2.429781}
  103. % the famous Wilkinson "ill-conditioned" polynomial and its family.
  104. % 16) W(6) four real roots plus one complex pair.
  105. zz:= 10000*(for j:=1:6 product(x+j))+27x**5; roots zz;
  106. %{x= - 6.143833,x=-4.452438 + 0.02123455*i,x=-4.452438 - 0.02123455*i,
  107. % x= - 2.950367,x= - 2.003647,x= - 0.9999775}
  108. % 17) W(8) 4 real roots plus 2 complex pairs.
  109. zz:= 1000*(for j:=1:8 product(x+j))+2x**7; roots zz;
  110. %{x= - 8.437546,x=-6.494828 + 1.015417*i,x=-6.494828 - 1.015417*i,
  111. % x=-4.295858 + 0.2815097*i,x=-4.295858 - 0.2815097*i,
  112. % x= - 2.982725,x= - 2.000356,x= - 0.9999996}
  113. % 18) W(10) 6 real roots plus 2 complex pairs.
  114. zz:=1000*(for j:= 1:10 product (x+j))+x**9; roots zz;
  115. %{x= - 10.80988,x=-8.70405 + 1.691061*i,x=-8.70405 - 1.691061*i,
  116. % x=-6.046279 + 1.134321*i,x=-6.046279 - 1.134321*i,x= - 4.616444,
  117. % x= - 4.075943,x= - 2.998063,x= - 2.000013,x= - 1}
  118. % 19) W(12) 6 real roots plus 3 complex pairs.
  119. zz:= 10000*(for j:=1:12 product(x+j))+4x**11; roots zz;
  120. %{x= - 13.1895,x=-11.02192 + 2.23956*i,x=-11.02192 - 2.23956*i,
  121. % x=-7.953917 + 1.948001*i,x=-7.953917 - 1.948001*i,
  122. % x=-5.985629 + 0.8094247*i,x=-5.985629 - 0.8094247*i,
  123. % x= - 4.880956,x= - 4.007117,x= - 2.999902,x= - 2.0,x= - 1}
  124. % 20) W(20) 10 real roots plus 5 complex pairs. (The original problem)
  125. % This example is commented out, since it takes significant time without
  126. % being particularly difficult or checking out new paths:
  127. %**% zz:= x**19+10**7*for j:=1:20 product (x+j); roots zz;
  128. %{x= - 20.78881,x=-19.45964 + 1.874357*i,x=-19.45964 - 1.874357*i,
  129. % x=-16.72504 + 2.731577*i,x=-16.72504 - 2.731577*i,
  130. % x=-14.01105 + 2.449466*i,x=-14.01105 - 2.449466*i,
  131. % x=-11.82101 + 1.598621*i,x=-11.82101 - 1.598621*i,
  132. % x=-10.12155 + 0.6012977*i,x=-10.12155 - 0.6012977*i,
  133. % x= - 8.928803,x= - 8.006075,x= - 6.999746,x= - 6.000006,
  134. % x= - 5.0,x= - 4.0,x= - 3.0,x= - 2.0,x= - 1}
  135. rootacc 6;
  136. % 21) Finding one of a cluster of 8 roots.
  137. zz:= (10**16*(x-1)**8-1); nearestroot(zz,2);
  138. %{x=1.01}
  139. % 22) Six real roots spaced 0.01 apart.
  140. c := 100; zz:= (x-1)*for i:=1:5 product (c*x-(c+i)); roots zz;
  141. %{x=1,x=1.01,x=1.02,x=1.03,x=1.04,x=1.05}
  142. % 23) Six real roots spaced 0.001 apart.
  143. c := 1000; zz:= (x-1)*for i:=1:5 product (c*x-(c+i)); roots zz;
  144. %{x=1,x=1.001,x=1.002,x=1.003,x=1.004,x=1.005}
  145. % 24) Five real roots spaced 0.0001 apart.
  146. c := 10000; zz:= (x-1)*for i:=1:4 product (c*x-(c+i)); roots zz;
  147. %{x=1,x=1.0001,x=1.0002,x=1.0003,x=1.0004}
  148. % 25) A cluster of 9 roots, 5 real, 2 complex pairs; spacing 0.1.
  149. zz:= (x-1)*(10**8*(x-1)**8-1); roots zz;
  150. %{x=0.9,x=0.929289 + 0.0707107*i,x=0.929289 - 0.0707107*i,
  151. % x=1,x=1 + 0.1*i,x=1 - 0.1*i,
  152. % x=1.07071 + 0.0707107*i,x=1.07071 - 0.0707107*i,x=1.1}
  153. % 26) Same, but with spacing 0.01.
  154. zz:= (x-1)*(10**16*(x-1)**8-1); roots zz;
  155. %{x=0.99,x=0.992929 + 0.00707107*i,x=0.992929 - 0.00707107*i,
  156. % x=1,x=1 + 0.01*i,x=1 - 0.01*i,
  157. % x=1.00707 + 0.00707107*i,x=1.00707 - 0.00707107*i,x=1.01}
  158. % 27) Spacing reduced to 0.001.
  159. zz:= (x-1)*(10**24*(x-1)**8-1); roots zz;
  160. %{x=0.999,x=0.999293 + 0.000707107*i,x=0.999293 - 0.000707107*i,
  161. % x=1,x=1 + 0.001*i,x=1 - 0.001*i,
  162. % x=1.00071 + 0.000707107*i,x=1.00071 - 0.000707107*i,x=1.001}
  163. % 28) Eight roots divided into two clusters.
  164. zz:= (10**8*(x-1)**4-1)*(10**8*(x+1)**4-1); roots zz;
  165. %{x= - 0.99,x=0.99, x=-1 - 0.01*i,x=1 + 0.01*i,
  166. % x=-1 + 0.01*i,x=1 - 0.01*i,x= - 1.01,x=1.01}
  167. % 29) A cluster of 8 roots in a different configuration.
  168. zz:= (10**8*(x-1)**4-1)*(10**8*(100x-102)**4-1); roots zz;
  169. %{x=0.99,x=1 + 0.01*i,x=1 - 0.01*i,x=1.01,
  170. % x=1.0199,x=1.02 + 0.0001*i,x=1.02 - 0.0001*i,x=1.0201}
  171. % 30) A cluster of 8 complex roots.
  172. zz:= ((10x-1)**4+1)*((10x+1)**4+1); roots zz;
  173. %{x=-0.0292893 - 0.0707107*i,x=0.0292893 + 0.0707107*i,
  174. % x=-0.0292893 + 0.0707107*i,x=0.0292893 - 0.0707107*i,
  175. % x=-0.170711 - 0.0707107*i,x=0.170711 + 0.0707107*i,
  176. % x=-0.170711 + 0.0707107*i,x=0.170711 - 0.0707107*i}
  177. comment In these examples, accuracy increase is required to separate a
  178. repeated root from a simple root.;
  179. % 31) Using allroots;
  180. zz:= (x-4)*(x-3)**2*(1000000x-3000001); roots zz;
  181. %{x=3.0,x=3.0,x=3.000001,x=4.0}
  182. % 32) Using realroots;
  183. realroots zz;
  184. %{x=3.0,x=3.0,x=3.000001,x=4.0}
  185. comment Tests of new capabilities in mod 1.87 for handling complex
  186. polynomials and polynomials with very small imaginary parts or very
  187. small real roots. A few real examples are shown, just to demonstrate
  188. that these still work.;
  189. % 33) A trivial complex case (but degrees 1 and 2 are special cases);
  190. zz:= x-i; roots zz;
  191. %{x=i}
  192. % 34) Real case.
  193. zz:= y-7; roots zz;
  194. %{y=7.0}
  195. % 35) Roots with small imaginary parts (new capability);
  196. zz := 10**16*(x**2-2x+1)+1; roots zz;
  197. %{x=1 + 0.00000001*i,x=1 - 0.00000001*i}
  198. % 36) One real, one complex root.
  199. zz:=(x-9)*(x-5i-7); roots zz;
  200. %{x=9.0,x=7.0 + 5.0*i}
  201. % 37) Three real roots.
  202. zz:= (x-1)*(x-2)*(x-3); roots zz;
  203. %{x=1,x=2.0,x=3.0}
  204. % 38) 2 real + 1 imaginary root.
  205. zz:=(x**2-8)*(x-5i); roots zz;
  206. %{x= - 2.82843,x=2.82843,x=5.0*i}
  207. % 39) 2 complex roots.
  208. zz:= (x-1-2i)*(x+2+3i); roots zz;
  209. %{x=-2.0 - 3.0*i,x=1 + 2.0*i}
  210. % 40) 2 irrational complex roots.
  211. zz:= x**2+(3+2i)*x+7i; roots zz;
  212. %{x=-3.14936 + 0.21259*i,x=0.149358 - 2.21259*i}
  213. % 41) 2 complex roots of very different magnitudes with small imaginary
  214. % parts.
  215. zz:= x**2+(1000000000+12i)*x-1000000000; roots zz;
  216. %{x=-1.0E+9 - 12.0*i,x=1 - 0.000000012*i}
  217. % 42) Multiple real and complex roots cause no difficulty, provided
  218. % that input is given in integer or rational form, (or if in decimal
  219. % fraction format, with switch rounded off or adjprec on and
  220. % coefficients input explicitly,) so that polynomial is stored exactly.
  221. zz :=(x**2-2i*x+5)**3*(x-2i)*(x-11/10)**2; roots zz;
  222. %{x=-1.44949*i, x=-1.44949*i, x=-1.44949*i,
  223. % x=3.44949*i, x=3.44949*i, x=3.44949*i, x=1.1, x=1.1, x=2.0*i}
  224. % 42a) would have failed in roots Mod 1.93 and previously (bug)
  225. realroots zz;
  226. %{x=1.1,x=1.1}
  227. % 43) 2 real, 2 complex roots.
  228. zz:= (x**2-4)*(x**2+3i*x+5i); roots zz;
  229. %{x= - 2.0,x=2.0,x=-1.2714 + 0.466333*i,x=1.2714 - 3.46633*i}
  230. % 44) 4 complex roots.
  231. zz:= x**4+(0.000001i)*x-16; roots zz;
  232. %{x=-2.0 - 0.0000000625*i,x=-2.0*i,x=2.0*i,x=2.0 - 0.0000000625*i}
  233. % 45) 2 real, 2 complex roots.
  234. zz:= (x**2-4)*(x**2+2i*x+8); roots zz;
  235. %{x= - 2.0,x=2.0,x=-4.0*i,x=2.0*i}
  236. % 46) Using realroots to find only real roots.
  237. realroots zz;
  238. %{x= - 2.0,x=2.0}
  239. % 47) Same example, applying nearestroot to find a single root.
  240. zz:= (x**2-4)*(x**2+2i*x+8); nearestroot(zz,1);
  241. %{x=2.0}
  242. % 48) Same example, but focusing on imaginary point.
  243. nearestroot(zz,i);
  244. %{x=2.0*i}
  245. % 49) The seed parameter can be complex also.
  246. nearestroot(zz,1+i);
  247. %{x=2.0*i}
  248. % 50) One more nearestroot example. Nearest root to real point may be
  249. % complex.
  250. zz:= (x**2-4)*(x**2-i); roots zz;
  251. %{x= - 2.0,x=2.0,x=-0.707107 - 0.707107*i,x=0.707107 + 0.707107*i}
  252. nearestroot (zz,1);
  253. %{X=0.707107 + 0.707107*i}
  254. % 51) 1 real root plus 5 complex roots.
  255. zz:=(x**3-3i*x**2-5x+9)*(x**3-8); roots zz;
  256. %{x=-1 + 1.73205*i,x=-1 - 1.73205*i,x=2.0,
  257. % x=-2.41613 + 1.19385*i,x=0.981383 - 0.646597*i,x=1.43475 + 2.45274*i}
  258. nearestroot(zz,1);
  259. %{x=0.981383 - 0.646597*i}
  260. % 52) roots can be computed to any accuracy desired, eg. (note that the
  261. % imaginary part of the second root is truncated because of its size,
  262. % and that the imaginary part of a complex root is never polished away,
  263. % even if it is smaller than the accuracy would require.)
  264. zz := x**3+10**(-20)*i*x**2+8; rootacc 12; roots zz; rootacc 6;
  265. %{x=-2.0 - 3.33333333333E-21*i,x=1 - 1.73205080757*i,
  266. % x=1 + 1.73205080757*i}
  267. % 53) Precision of 12 required to find small imaginary root,
  268. % but standard accuracy can be used.
  269. zz := x**2+123456789i*x+1; roots zz;
  270. %{x=-1.23457E+8*i,x=0.0000000081*i}
  271. % 54) Small real root is found with root 10*18 times larger(new).
  272. zz := (x+1)*(x**2+123456789*x+1); roots zz;
  273. %{x= - 1.23457E+8,x= - 1,x= - 0.0000000081}
  274. % 55) 2 complex, 3 real irrational roots.
  275. ss := (45*x**2+(-10i+12)*x-10i)*(x**3-5x**2+1); roots ss;
  276. %{x= - 0.429174,x=0.469832,x=4.95934,
  277. % x=-0.448056 - 0.19486*i,x=0.18139 + 0.417083*i}
  278. % 56) Complex polynomial with floating coefficients.
  279. zz := x**2+1.2i*x+2.3i+6.7; roots zz;
  280. %{x=-0.427317 + 2.09121*i,x=0.427317 - 3.29121*i}
  281. % 56a) multiple roots will be found if coefficients read in exactly.
  282. % Exact read-in will occur unless dmode is rounded or complex-rounded.
  283. zz := x**3 + (1.09 - 2.4*i)*x**2 + (-1.44 - 2.616*i)*x + -1.5696;
  284. roots zz;
  285. %{x=1.2*i,x=1.2*i,x= - 1.09}
  286. % 57) Realroots, isolater and rlrootno accept 1, 2 or 3 arguments: (new)
  287. zz:= for j:=-1:3 product (x-j); rlrootno zz;
  288. % 5
  289. realroots zz;
  290. %{x=0,x= -1,x=1,x=2.0,x=3.0}
  291. rlrootno(zz,positive); %positive selects positive, excluding 0.
  292. % 3
  293. rlrootno(zz,negative); %negative selects negative, excluding 0.
  294. % 1
  295. realroots(zz,positive);
  296. %{x=1,x=2.0,x=3.0}
  297. rlrootno(zz,-1.5,2); %the format with 3 arguments selects a range.
  298. % 4
  299. realroots(zz,-1.5,2); %the range is inclusive, except that:
  300. %{x=0,x= - 1,x=1,x=2.0}
  301. % A specific limit b may be excluded by using exclude b. Also, the
  302. % limits infinity and -infinity can be specified.
  303. realroots(zz,exclude 0,infinity);
  304. % equivalent to realroots(zz,positive).
  305. %{x=1,x=2.0,x=3.0}
  306. rlrootno(zz,-infinity,exclude 0); % equivalent to rlrootno(zz,negative).
  307. % 1
  308. rlrootno(zz,-infinity,0);
  309. % 2
  310. rlrootno(zz,infinity,-infinity);
  311. %equivalent to rlrootno zz; (order of limits does not matter.)
  312. % 5
  313. realroots(zz,1,infinity); % finds all real roots >= 1.
  314. %{x=1,x=2.0,x=3.0}
  315. realroots(zz,1,positive); % finds all real roots > 1.
  316. %{x=2.0,x=3.0}
  317. % 57a) Bug corrected in mod 1.94. (handling of rational limits)
  318. zz := (x-1/3)*(x-1/5)*(x-1/7)*(x-1/11);
  319. realroots(zz,1/11,exclude(1/3));
  320. %{x=0.0909091,x=0.142857,x=0.2}
  321. realroots(zz,exclude(1/11),1/3);
  322. %{x=0.142857,x=0.2,x=0.333333}
  323. % New capabilities added in mod 1.88.
  324. % 58) 3 complex roots, with two separated by very small real difference.
  325. zz :=(x+i)*(x+10**8i)*(x+10**8i+1); roots zz;
  326. %{x=-1 - 1.0E+8*i,x=-1.0E+8*i,x= - i}
  327. % 59) Real polynomial with two complex roots separated by very small
  328. % imaginary part.
  329. zz:= (10**14x+123456789000000+i)*(10**14x+123456789000000-i); roots zz;
  330. %{x=-1.23457 + 1.0E-14*i,x=-1.23457 - 1.0E-14*i}
  331. % 60) Real polynomial with two roots extremely close together.
  332. zz:= (x+2)*(10**10x+12345678901)*(10**10x+12345678900); roots zz;
  333. %{x= - 2.0,x= - 1.2345678901,x= - 1.23456789}
  334. % 61) Real polynomial with multiple root extremely close to simple root.
  335. zz:= (x-12345678/10000000)*(x-12345679/10000000)**2; roots zz;
  336. %{x=1.2345679,x=1.2345679,x=1.2345678}
  337. % 62) Similar problem using realroots.
  338. zz:=(x-2**30/10**8)**2*(x-(2**30+1)/10**8); realroots zz;
  339. %{x=10.73741824,x=10.73741824,x=10.73741825}
  340. % 63) Three complex roots with small real separation between two.
  341. zz:= (x-i)*(x-1-10**8i)*(x-2-10**8i); roots zz;
  342. %{x=i,x=1 + 1.0E+8*i,x=2.0 + 1.0E+8*i}
  343. % 64) Use of nearestroot to isolate one of the close roots.
  344. nearestroot(zz,10**8i+99/100);
  345. %{x=1 + 1.0E+8*i}
  346. % 65) Slightly more complicated example with close complex roots.
  347. zz:= (x-i)*(10**8x-1234-10**12i)*(10**8x-1233-10**12i); roots zz;
  348. %{x=i,x=0.00001233 + 10000.0*i,x=0.00001234 + 10000.0*i}
  349. % 66) Four closely spaced real roots with varying spacings.
  350. zz:= (x-1+1/10**7)*(x-1+1/10**8)*(x-1)*(x-1-1/10**7); roots zz;
  351. %{x=0.9999999,x=0.99999999,x=1,x=1.0000001}
  352. % 67) Complex pair plus two close real roots.
  353. zz:= (x**2+1)*(x-12345678/10000000)*(x-12345679/10000000); roots zz;
  354. %{x=i,x= - i,x=1.2345678,x=1.2345679}
  355. % 68) Same problem using realroots to find only real roots.
  356. realroots zz;
  357. %{x=1.2345678,x=1.2345679}
  358. % The switch ratroot causes output to be given in rational form.
  359. % 69) Two complex roots with output in rational form.
  360. on ratroot,complex; zz:=x**2-(5i+1)*x+1; sss:= roots zz;
  361. % 346859 - 1863580*i 482657 + 2593180*i
  362. %sss := {x=--------------------,x=--------------------}
  363. % 10000000 500000
  364. % With roots in rational form, mkpoly can be used to reconstruct a
  365. % polynomial.
  366. zz1 := mkpoly sss;
  367. % 2
  368. %zz1 := 5000000000000*x - (4999999500000 + 25000010000000*i)*x
  369. %
  370. % + 5000012308763 - 2110440*i
  371. % Finding the roots of the new polynomial zz1.
  372. rr:= roots zz1;
  373. % 346859 - 1863580*i 482657 + 2593180*i
  374. %rr := {x=--------------------,x=--------------------}
  375. % 10000000 500000
  376. % The roots are stable to the extent that rr=ss, although zz1 and
  377. % zz may differ.
  378. zz1 - zz;
  379. % 2
  380. %4999999999999*x - (4999999499999 + 25000009999995*i)*x
  381. %
  382. % + 5000012308762 - 2110440*i
  383. % 70) Same type of problem in which roots are found exactly.
  384. zz:=(x-10**8+i)*(x-10**8-i)*(x-10**8+3i/2)*(x-i); rr := roots zz;
  385. % 4 3 2
  386. %zz := (2*x - (600000000 - i)*x + 60000000000000005*x
  387. %
  388. % - (2000000000000000800000000 + 29999999999999999*i)*x
  389. %
  390. % + (30000000000000003 + 2000000000000000200000000*i))/2
  391. %rr := {x=100000000 + i,x=100000000 - i,x=i,
  392. %
  393. % 200000000 - 3*i
  394. % x=-----------------}
  395. % 2
  396. % Reconstructing a polynomial from the roots.
  397. ss := mkpoly rr;
  398. % 4 3 2
  399. %ss := 2*x - (600000000 - i)*x + 60000000000000005*x
  400. %
  401. % - (2000000000000000800000000 + 29999999999999999*i)*x
  402. %
  403. % + (30000000000000003 + 2000000000000000200000000*i)
  404. % In this case, the same polynomial is obtained.
  405. ss - num zz;
  406. % 0
  407. % 71) Finding one of the complex roots using nearestroot.
  408. nearestroot(zz,10**8-2i);
  409. % 200000000 - 3*I
  410. %{x=-----------------}
  411. % 2
  412. % Finding the other complex root using nearestroot.
  413. nearestroot(zz,10**8+2i);
  414. %{x=100000000 + I}
  415. % 72) A realroots problem which requires accuracy increase to avoid
  416. % confusion of two roots.
  417. zz:=(x+1)*(10000000x-19999999)*(1000000x-2000001)*(x-2);
  418. realroots zz;
  419. % 19999999 2000001
  420. % {x=-1,x=----------,x=2,x=---------}
  421. % 10000000 1000000
  422. % 73) Without the accuracy increase, this example would produce the
  423. % obviously incorrect answer 2.
  424. realroots(zz,3/2,exclude 2);
  425. % 19999999
  426. % {x=----------}
  427. % 10000000
  428. % Rlrootno also gives the correct answer in this case.
  429. rlrootno(zz,3/2,exclude 2);
  430. % 1
  431. % 74) Roots works equally well in this problem.
  432. rr := roots zz;
  433. % 19999999 2000001
  434. %rr := {x= - 1,x=----------,x=2,x=---------}
  435. % 10000000 1000000
  436. % 75) The function getroot is convenient for obtaining the value of a
  437. % root.
  438. rr1 := getroot(1,rr);
  439. % 19999999
  440. % rr1 := ----------
  441. % 10000000
  442. % 76) For example, the value can be used as an argument to nearestroot.
  443. nearestroot(zz,rr1);
  444. % 19999999
  445. % {x=----------}
  446. % 10000000
  447. comment New capabilities added to Mod 1.90 for avoiding floating point
  448. exceptions and exceeding iteration limits.;
  449. % 77) This and the next example would previously have aborted because
  450. %of exceeding iteration limits:
  451. off ratroot; zz := x**16 - 900x**15 -2; roots zz;
  452. %{x= - 0.665423,x=-0.607902 + 0.270641*i,x=-0.607902 - 0.270641*i,
  453. % x=-0.44528 + 0.494497*i, x=-0.44528 - 0.494497*i,
  454. % x=-0.205664 + 0.632867*i,x=-0.205664 - 0.632867*i,
  455. % x=0.069527 + 0.661817*i,x=0.069527 - 0.661817*i,
  456. % x=0.332711 + 0.57633*i,x=0.332711 - 0.57633*i,
  457. % x=0.538375 + 0.391176*i,x=0.538375 - 0.391176*i,
  458. % x=0.650944 + 0.138369*i,x=0.650944 - 0.138369*i,x=900.0}
  459. % 78) a still harder example.
  460. zz := x**30 - 900x**29 - 2; roots zz;
  461. %{x= - 0.810021,x=-0.791085 + 0.174125*i,x=-0.791085 - 0.174125*i,
  462. % x=-0.735162 + 0.340111*i,x=-0.735162 - 0.340111*i,
  463. % x=-0.644866 + 0.490195*i,x=-0.644866 - 0.490195*i,
  464. % x=-0.524417 + 0.617362*i,x=-0.524417 - 0.617362*i,
  465. % x=-0.379447 + 0.715665*i,x=-0.379447 - 0.715665*i,
  466. % x=-0.216732 + 0.780507*i,x=-0.216732 - 0.780507*i,
  467. % x=-0.04388 + 0.808856*i,x=-0.04388 - 0.808856*i,
  468. % x=0.131027 + 0.799383*i,x=0.131027 - 0.799383*i,
  469. % x=0.299811 + 0.752532*i,x=0.299811 - 0.752532*i,
  470. % x=0.454578 + 0.67049*i,x=0.454578 - 0.67049*i,
  471. % x=0.588091 + 0.557094*i,x=0.588091 - 0.557094*i,
  472. % x=0.694106 + 0.417645*i,x=0.694106 - 0.417645*i,
  473. % x=0.767663 + 0.258664*i,x=0.767663 - 0.258664*i,
  474. % x=0.805322 + 0.0875868*i,x=0.805322 - 0.0875868*i,x=900.0}
  475. % 79) this deceptively simple example previously caused floating point
  476. % overflows on some systems:
  477. aa := x**6 - 4*x**3 + 2; realroots aa;
  478. %{x=0.836719,x=1.50579}
  479. % 80) a harder problem, which would have failed on almost all systems:
  480. rr := x**16 - 90000x**15 - x**2 -2; realroots rr;
  481. %{x= - 0.493299,x=90000.0}
  482. % 81) this example would have failed because of floating point
  483. % exceptions on almost all computer systems.
  484. rr := x**30 - 9*10**10*x**29 - 2; realroots rr;
  485. %{x= - 0.429188,x=9.0E+10}
  486. % 82) a test of allroot on this example.
  487. % This example is commented out because it takes significant time
  488. % without breaking new ground.
  489. %**% roots rr;
  490. %{x= - 0.429188,
  491. % x=-0.419154 + 0.092263*i,x=-0.419154 - 0.092263*i,
  492. % x=-0.389521 + 0.180211*i,x=-0.389521 - 0.180211*i,
  493. % x=-0.341674 + 0.259734*i,x=-0.341674 - 0.259734*i,
  494. % x=-0.277851 + 0.327111*i,x=-0.277851 - 0.327111*i,
  495. % x=-0.201035 + 0.379193*i,x=-0.201035 - 0.379193*i,
  496. % x=-0.11482 + 0.413544*i,x=-0.11482 - 0.413544*i,
  497. % x=-0.0232358 + 0.428559*i,x=-0.0232358 - 0.428559*i,
  498. % x=0.0694349 + 0.423534*i,x=0.0694349 - 0.423534*i,
  499. % x=0.158859 + 0.398706*i,x=0.158859 - 0.398706*i,
  500. % x=0.240855 + 0.355234*i,x=0.240855 - 0.355234*i,
  501. % x=0.311589 + 0.295153*i,x=0.311589 - 0.295153*i,
  502. % x=0.367753 + 0.22127*i,x=0.367753 - 0.22127*i,
  503. % x=0.406722 + 0.13704*i,x=0.406722 - 0.13704*i,
  504. % x=0.426672 + 0.0464034*i,x=0.426672 - 0.0464034*i,x=9.0E+10}
  505. % 83) test of starting point for iteration: no convergence if good
  506. % real starting point is not found.
  507. zz := x**30 -9*10**12x**29 -2; firstroot zz;
  508. %{x= - 0.36617}
  509. % 84) a case in which there are no real roots and good imaginary
  510. % starting point must be used or roots cannot be found.
  511. zz:= 9x**16 - x**5 +1; roots zz;
  512. %{x=-0.866594 + 0.193562*i,x=-0.866594 - 0.193562*i,
  513. % x=-0.697397 + 0.473355*i,x=-0.697397 - 0.473355*i,
  514. % x=-0.510014 + 0.716449*i,x=-0.510014 - 0.716449*i,
  515. % x=-0.161318 + 0.87905*i,x=-0.161318 - 0.87905*i,
  516. % x=0.182294 + 0.828368*i,x=0.182294 - 0.828368*i,
  517. % x=0.459373 + 0.737443*i,x=0.459373 - 0.737443*i,
  518. % x=0.748039 + 0.494348*i,x=0.748039 - 0.494348*i,
  519. % x=0.845617 + 0.142879*i,x=0.845617 - 0.142879*i}
  520. % 85) five complex roots.
  521. zz := x**5 - x**3 + i; roots zz;
  522. %{x=-1.16695 - 0.217853*i,x=-0.664702 + 0.636663*i,x=-0.83762*i,
  523. % x=0.664702 + 0.636663*i,x=1.16695 - 0.217853*i}
  524. % Additional capabilities in Mod 1.91.
  525. % 86) handling of polynomial with huge or infinitesimal coefficients.
  526. precision reset;
  527. on rounded; precision reset;
  528. % so that the system will start this example in floating point. Rounded
  529. % is on so that the polynomial won't fill the page!
  530. zz:= 1.0e-500x**3+x**2+x;
  531. roots zz; off rounded; % rounded not normally needed for roots.
  532. %{x=0,x= - 1.0E+500,x= - 1}
  533. off roundbf;
  534. comment Switch roundbf will have been turned on in the last example in
  535. most computer systems. This will inhibit the use of hardware floating
  536. point unless roundbf is turned off.
  537. Polynomials which make use of powergcd substitution and cascaded
  538. solutions.
  539. Uncomplicated cases.;
  540. switch powergcd; % introduced here to verify that same answers are
  541. % obtained with and without employing powergcd strategy. Roots are
  542. % found faster for applicable cases when !*powergcd=t (default state.)
  543. % 87) powergcd done at the top level.
  544. zz := x**12-5x**9+1; roots zz;
  545. %{x=-0.783212 + 0.276071*i,x=0.152522 - 0.816316*i,
  546. % x=0.63069 + 0.540246*i,x=-0.783212 - 0.276071*i,
  547. % x=0.152522 + 0.816316*i,x=0.63069 - 0.540246*i,
  548. % x=-0.424222 + 0.734774*i,x=-0.424222 - 0.734774*i,x=0.848444,
  549. % x=-0.85453 + 1.48009*i,x=-0.85453 - 1.48009*i,x=1.70906}
  550. off powergcd; roots zz; on powergcd;
  551. %{x=-0.85453 + 1.48009*i,x=-0.85453 - 1.48009*i,
  552. % x=-0.783212 + 0.276071*i,x=-0.783212 - 0.276071*i,
  553. % x=-0.424222 + 0.734774*i,x=-0.424222 - 0.734774*i,
  554. % x=0.152522 + 0.816316*i,x=0.152522 - 0.816316*i,
  555. % x=0.63069 + 0.540246*i,x=0.63069 - 0.540246*i,x=0.848444,x=1.70906}
  556. % 88) powergcd done after square free factoring.
  557. zz := (x-1)**2*zz; roots zz;
  558. %{x=1,x=1,
  559. % x=-0.783212 + 0.276071*i,x=0.152522 - 0.816316*i,
  560. % x=0.63069 + 0.540246*i,x=-0.783212 - 0.276071*i,
  561. % x=0.152522 + 0.816316*i,x=0.63069 - 0.540246*i,
  562. % x=-0.424222 + 0.734774*i,x=-0.424222 - 0.734774*i,x=0.848444,
  563. % x=-0.85453 + 1.48009*i,x=-0.85453 - 1.48009*i,x=1.70906}
  564. off powergcd; roots zz; on powergcd;
  565. %{x=1,x=1,
  566. % x=-0.85453 + 1.48009*i,x=-0.85453 - 1.48009*i,
  567. % x=-0.783212 + 0.276071*i,x=-0.783212 - 0.276071*i,
  568. % x=-0.424222 + 0.734774*i,x=-0.424222 - 0.734774*i,
  569. % x=0.152522 + 0.816316*i,x=0.152522 - 0.816316*i,
  570. % x=0.63069 + 0.540246*i,x=0.63069 - 0.540246*i,
  571. % x=0.848444,x=1.70906}
  572. % 89) powergcd done after separation into real and complex polynomial.
  573. zz := x**5-i*x**4+x**3-i*x**2+x-i; roots zz;
  574. %{x=-0.5 - 0.866025*i,x=0.5 + 0.866025*i,
  575. % x=-0.5 + 0.866025*i,x=0.5 - 0.866025*i,x=i}
  576. off powergcd; roots zz; on powergcd;
  577. %{x=-0.5 + 0.866025*i,x=-0.5 - 0.866025*i,
  578. % x=0.5 + 0.866025*i,x=0.5 - 0.866025*i,x=i}
  579. % Cases where root separation requires accuracy and/or precision
  580. % increase. In some examples we get excess accuracy, but it is hard
  581. % avoid this and still get all roots separated.
  582. % 90) accuracy increase required to separate close roots;
  583. let x=y**2;
  584. zz:= (x-3)*(100000000x-300000001); roots zz;
  585. %{y= - 1.732050808,y=1.732050808,y= - 1.73205081,y=1.73205081}
  586. off powergcd; roots zz; on powergcd;
  587. %{y= - 1.73205081,y= - 1.732050808,y=1.732050808,y=1.73205081}
  588. % 91) roots to be separated are on different square free factors.
  589. zz:= (x-3)**2*(10000000x-30000001); roots zz;
  590. %{y= - 1.73205081,y= - 1.73205081,y=1.73205081,y=1.73205081,
  591. % y= - 1.73205084,y=1.73205084}
  592. off powergcd; roots zz; on powergcd;
  593. %{y= - 1.73205081,y= - 1.73205081,y=1.73205081,y=1.73205081,
  594. % y= - 1.73205084,y=1.73205084}
  595. % 91a) A new capability for nearestroot:
  596. nearestroot(zz,1.800000000001); % should find the root to 13 places.
  597. %{y=1.732050836436}
  598. % 92) roots must be separated in the complex polynomial factor only.
  599. zz :=(y+1)*(x+10**8i)*(x+10**8i+1); roots zz;
  600. %{y= - 1,
  601. % y=-7071.067777 + 7071.067847*i,y=7071.067777 - 7071.067847*i,
  602. % y=-7071.067812 + 7071.067812*i,y=7071.067812 - 7071.067812*i}
  603. % 93)
  604. zz := (x-2)**2*(1000000x-2000001)*(y-1); roots zz;
  605. %{y= - 1.4142136,y= - 1.4142136,y=1.4142136,y=1.4142136,
  606. % y= - 1.4142139,y=1,y=1.4142139}
  607. % 94)
  608. zz := (x-2)*(10000000x-20000001); roots zz;
  609. %{y= - 1.41421356 ,y=1.41421356 ,y= - 1.4142136,y=1.4142136}
  610. % 95)
  611. zz := (x-3)*(10000000x-30000001); roots zz;
  612. %{y= - 1.73205081 ,y=1.73205081 ,y= - 1.73205084 ,y=1.73205084}
  613. % 96)
  614. zz := (x-9)**2*(1000000x-9000001); roots zz;
  615. %{y= - 3.0,y= - 3.0,y=3.0,y=3.0,y= - 3.00000017,y=3.00000017}
  616. % 97)
  617. zz := (x-3)**2*(1000000x-3000001); roots zz;
  618. %{y= - 1.7320508,y= - 1.7320508,y=1.7320508,y=1.7320508,
  619. % y= - 1.7320511,y=1.7320511}
  620. % 98) the accuracy of the root sqrt 5 depends upon another close root.
  621. % Although one of the factors is given in decimal notation, it is not
  622. % necessary to turn rounded on.
  623. rootacc 10; % using rootacc to specify the minumum desired accuracy.
  624. zz := (y^2-5)*(y-2.2360679775);
  625. % in this case, adding one place to the root near sqrt 5 causes a
  626. % required increase of 4 places in accuracy of the root at sqrt 5.
  627. roots zz;
  628. %{y= - 2.236067977,y=2.2360679774998,y=2.2360679775}
  629. realroots zz; % should get the same answer from realroots.
  630. %{y= - 2.2360679775,y=2.2360679774998,y=2.2360679775}
  631. % 99) The same thing also happens when the root near sqrt 5 is on a
  632. % different square-free factor.
  633. zz := (y^2-5)^2*(y-2.2360679775);
  634. roots zz;
  635. %{y= - 2.236067977,y= - 2.236067977,y=2.2360679774998,
  636. % y=2.2360679774998,y=2.2360679775}
  637. realroots zz; % realroots handles this case also.
  638. %{y= - 2.236067977,y= - 2.236067977,y=2.2360679774998,y=2.2360679774998,
  639. % y=2.2360679775}
  640. % 100)
  641. rootacc 6;
  642. zz := (y-i)*(x-2)*(1000000x-2000001); roots zz;
  643. %{y= - 1.4142136,y=1.4142136,y= - 1.4142139,y=1.4142139,y=i}
  644. % 101) this example requires accuracy 15.
  645. zz:= (y-2)*(100000000000000y-200000000000001);
  646. roots zz;
  647. %{y=2.0,y=2.00000000000001}
  648. % 102) still higher precision needed.
  649. zz:= (y-2)*(10000000000000000000y-20000000000000000001); roots zz;
  650. %{y=2.0,y=2.0000000000000000001}
  651. % 103) increase in precision required for substituted polynomial.
  652. zz:= (x-2)*(10000000000x-20000000001); roots zz;
  653. %{y= - 1.41421356237,y=1.41421356237,y= - 1.41421356241,y=1.41421356241}
  654. % 104) still higher precision required for substituted polynomial.
  655. zz:= (x-2)*(100000000000000x-200000000000001); roots zz;
  656. %{y= - 1.414213562373095,y=1.414213562373095,
  657. % y= - 1.414213562373099,y=1.414213562373099}
  658. % 105) accuracy must be increased to separate root of complex factor
  659. % from root of real factor.
  660. zz:=(9y-10)*(y-2)*(9y-10-9i/100000000); roots zz;
  661. %{y=1.111111111,y=2.0,y=1.111111111 + 0.00000001*i}
  662. % 106) realroots does the same accuracy increase for real root based
  663. % upon the presence of a close complex root in the same polynomial.
  664. % The reason for this might not be obvious unless roots is called.
  665. realroots zz;
  666. %{y=1.111111111,y=2.0}
  667. % 107) realroots now uses powergcd logic whenever it is applicable.
  668. zz := (x-1)*(x-2)*(x-3); realroots zz;
  669. %{y= - 1,y=1,y= - 1.41421,y=1.41421,y= - 1.73205,y=1.73205}
  670. realroots(zz,exclude 1,2);
  671. %{y=1.41421,y=1.73205}
  672. % 108) root of degree 1 polynomial factor must be evaluated at
  673. % precision 18 and accuracy 10 in order to separate it from a root of
  674. % another real factor.
  675. clear x; zz:=(9x-10)**2*(9x-10-9/100000000)*(x-2); roots zz;
  676. %{x=1.111111111,x=1.111111111,x=1.111111121,x=2.0}
  677. nearestroot(zz,1);
  678. %{x=1.111111111}
  679. nearestroot(zz,1.5);
  680. %{x=1.111111121}
  681. nearestroot(zz,1.65);
  682. %{x=2.0}
  683. % 108a) new cability in mod 1.94.
  684. realroots zz;
  685. %{x=1.111111111,x=1.111111111,x=1.111111121,x=2.0}
  686. % 109) in this example, precision >=40 is used and two roots need to be
  687. % found to accuracy 16 and two to accuracy 14.
  688. zz := (9x-10)*(7x-8)*(9x-10-9/10**12)*(7x-8-7/10**14); roots zz;
  689. %{x=1.1111111111111,x=1.1111111111121,
  690. % x=1.142857142857143,x=1.142857142857153}
  691. % 110) very small real or imaginary parts of roots require high
  692. % precision or exact computations, or they will be lost or incorrectly
  693. % found.
  694. zz := 1000000*r**18 + 250000000000*r**4 - 1000000*r**2 + 1; roots zz;
  695. %{r=2.42978*i,r=-2.42978*i,
  696. % r=-1.05424 - 2.18916*i,r=1.05424 + 2.18916*i,
  697. % r=-1.05424 + 2.18916*i,r=1.05424 - 2.18916*i,
  698. % r=-0.00141421 - 1.6E-26*i,r=0.00141421 + 1.6E-26*i,
  699. % r=-0.00141421 + 1.6E-26*i,r=0.00141421 - 1.6E-26*i,
  700. % r=-1.89968 - 1.51494*i,r=1.89968 + 1.51494*i,
  701. % r=-1.89968 + 1.51494*i,r=1.89968 - 1.51494*i,
  702. % r=-2.36886 - 0.540677*i,r=2.36886 + 0.540677*i,
  703. % r=-2.36886 + 0.540677*i,r=2.36886 - 0.540677*i}
  704. comment These five examples are very difficult root finding problems
  705. for automatic root finding (not employing problem-specific
  706. procedures.) They require extremely high precision and high accuracy
  707. to separate almost multiple roots (multiplicity broken by a small high
  708. order perturbation.) The examples are roughly in ascending order of
  709. difficulty.;
  710. % 111) Two simple complex roots with extremely small real separation.
  711. c := 10^-6;
  712. zz:=(x-3c^2)^2+i*c*x^7; roots zz;
  713. %{x=-15.0732 + 4.89759*i,x=-9.31577 - 12.8221*i,x=-1.2E-12 + 15.8489*i,
  714. % x=2.99999999999999999999999999999997E-12
  715. % + 3.3068111527572904325663335008527E-44*i,
  716. % x=3.00000000000000000000000000000003E-12
  717. % - 3.30681115275729043256633350085321E-44*i,
  718. % x=9.31577 - 12.8221*i,x=15.0732 + 4.89759*i}
  719. % 112) Four simple complex roots in two close sets.
  720. c := 10^-4;
  721. zz:=(x^2-3c^2)^2+i*c^2*x^9; roots zz;
  722. %{x=-37.8622 + 12.3022*i,x=-23.4002 - 32.2075*i,
  723. % x=-0.00017320508075689 - 2.41778234660324E-18*i,
  724. % x=-0.000173205080756885 + 2.4177823466027E-18*i,
  725. % x=39.8107*i,
  726. % x=0.000173205080756885 + 2.4177823466027E-18*i,
  727. % x=0.00017320508075689 - 2.41778234660324E-18*i,
  728. % x=23.4002 - 32.2075*i,x=37.8622 + 12.3022*i}
  729. % 113) Same example, but with higher minimum root accuracy specified.
  730. rootacc 20;
  731. roots zz;
  732. %{x=-37.862241873586290526 + 12.302188128448775345*i,
  733. % x=-23.400152368145827118 - 32.207546656274351069*i,
  734. % x=-0.00017320508075689014714 - 2.417782346603239319E-18*i,
  735. % x=-0.00017320508075688531157 + 2.417782346602699319E-18*i,
  736. % x=39.810717055651151449*i,
  737. % x=0.00017320508075688531157 + 2.417782346602699319E-18*i,
  738. % x=0.00017320508075689014714 - 2.417782346603239319E-18*i,
  739. % x=23.400152368145827118 - 32.207546656274351069*i,
  740. % x=37.862241873586290526 + 12.302188128448775345*i}
  741. precision reset;
  742. % This resets precision and rootacc to nominal.
  743. % 114) Two extremely close real roots plus a complex pair with extremely
  744. % small imaginary part.
  745. c := 10^6;
  746. zz:=(c^2*x^2-3)^2+c^2*x^9; roots zz;
  747. %{x= - 251.189,x=-77.6216 + 238.895*i,x=-77.6216 - 238.895*i,
  748. % x= - 0.000001732050807568877293531,
  749. % x= - 0.000001732050807568877293524,
  750. % x=0.00000173205 + 3.41926E-27*i,x=0.00000173205 - 3.41926E-27*i,
  751. % x=203.216 + 147.645*i,x=203.216 - 147.645*i}
  752. % 114a) this example is a critical test for realroots as well.
  753. realroots zz;
  754. %{x= - 251.189,x= - 0.000001732050807568877293531,
  755. % x= - 0.000001732050807568877293524}
  756. % 115) Four simple complex roots in two extremely close sets.
  757. c := 10^6;
  758. zz:=(c^2*x^2-3)^2+i*c^2*x^9; roots zz;
  759. %{x=-238.895 + 77.6216*i,x=-147.645 - 203.216*i,
  760. % x=-0.00000173205080756887729353 - 2.417782346602969319022E-27*i,
  761. % x=-0.000001732050807568877293525 + 2.417782346602969318968E-27*i,
  762. % x=251.189*i,
  763. % x=0.000001732050807568877293525 + 2.417782346602969318968E-27*i,
  764. % x=0.00000173205080756887729353 - 2.417782346602969319022E-27*i,
  765. % x=147.645 - 203.216*i,x=238.895 + 77.6216*i}
  766. % 116) A new "hardest example" type. This polynomial has two sets of
  767. % extremely close real roots and two sets of extremely close conjugate
  768. % complex roots, both large and small, with the maximum accuracy and
  769. % precision required for the largest roots. Three restarts are
  770. % required, at progressively higher precision, to find all roots.
  771. % (to run this example, uncomment the following two lines.)
  772. %**% zz1:= (10^12x^2-sqrt 2)^2+x^7$ zz2:= (10^12x^2+sqrt 2)^2+x^7$
  773. %**% zzzz := zz1*zz2$ roots zzzz;
  774. %{x= - 1.00000000000000000000000000009E+8,
  775. % x= - 9.99999999999999999999999999906E+7,
  776. % x= - 0.0000011892071150027210667183,
  777. % x= - 0.0000011892071150027210667167,
  778. % x=-5.4525386633262882960501E-28 + 0.000001189207115002721066718*i,
  779. % x=-5.4525386633262882960501E-28 - 0.000001189207115002721066718*i,
  780. % x=5.4525386633262882960201E-28 + 0.000001189207115002721066717*i,
  781. % x=5.4525386633262882960201E-28 - 0.000001189207115002721066717*i,
  782. % x=0.00000118921 + 7.71105E-28*i,
  783. % x=0.00000118921 - 7.71105E-28*i,
  784. % x=4.99999999999999999999999999953E+7
  785. % + 8.66025403784438646763723170835E+7*i,
  786. % x=4.99999999999999999999999999953E+7
  787. % - 8.66025403784438646763723170835E+7*i,
  788. % x=5.00000000000000000000000000047E+7
  789. % + 8.66025403784438646763723170671E+7*i,
  790. % x=5.00000000000000000000000000047E+7
  791. % - 8.66025403784438646763723170671E+7*i}
  792. % Realroots strategy on this example is different, but determining the
  793. % necessary precision and accuracy is tricky.
  794. %**% realroots zzzz;
  795. %{x= - 1.00000000000000000000000000009E+8,
  796. % x= - 9.9999999999999999999999999991E+7,
  797. % x= - 0.0000011892071150027210667183,
  798. % x= - 0.0000011892071150027210667167}
  799. % 117) multroot examples. Multroot can be called directly, or it can be
  800. % called by giving roots or realroots a list of polynomials as argument.
  801. % Here, multroot is called directly. Realroots is used unless the switch
  802. % compxroots is on. In this example, p1 must be computed at accuracy 33
  803. % in order to yield an accuracy of 20 for p2.
  804. res := % Structure is {eq1(p1,p2),eq2(p1)}
  805. { - 65193331905902035840886401184447471772856493442267717*P1**13
  806. - 1664429561324832520726401259146912155464247056480012434*P1**12
  807. - 6261475374084274810766056740641579522309310708502887990*P1**11
  808. + 58050875148721867394302891225676265051604299348469583622*P1**10
  809. - 25149162547648105419319267662238682603649922079217227285*P1**9
  810. - 440495842372965561251919788209759089436362766115660350108*P1**8
  811. + 1031835865631194068430476093579502290454870220388968336688*P1**7
  812. - 176560168441303582471783015188457142709772508915411137856*P1**6
  813. - 3394297397883799767380936436924078166849454318674637153232*P1**5
  814. + 8572159983028240622274769676964404195355003175115163884096*P1**4
  815. - 11689989317682872105592244166702248132836279639925035950656*P1**3
  816. + 9646776768609439752430866001814626337809195004192011294976*P1**2
  817. - 4455646388442119339178004445898515058096390082146233345536*P1
  818. + 4709370575236909034773453200518274143851133066819671040*P2
  819. + 886058257542744466307567014351806947093655767531394713600,
  820. 53271*P1**14 + 1393662*P1**13 + 6077030*P1**12 - 41382626*P1**11
  821. + 6240255*P1**10 + 313751524*P1**9 - 698694844*P1**8
  822. + 134987928*P1**7 + 2322386256*P1**6 - 6102636608*P1**5
  823. + 8722164608*P1**4 - 7907887488*P1**3 + 4508378368*P1**2
  824. - 1477342720*P1 + 213248000}$
  825. multroot(20,res);
  826. %{{p1= - 16.330244199212269912,p2= - 12.905402440394357204},{p1
  827. % = - 13.071850241794867852,p2= - 20.369934278813005573}}
  828. % 118) structure is {p1(x1,x3,x4),p2(x2,x4),p3(x2,x3,x4),p4(x4)}
  829. h := {36439926476029643745*x1 + 36439926476029643745*x3
  830. - 966689910765785535050240000*x4**17
  831. + 2589213991952971388822784000*x4**16
  832. - 1455736281904024746728256000*x4**15
  833. - 1114734065976529083327407360*x4**14
  834. + 720240539282202478990426752*x4**13
  835. + 419779761544955697624679296*x4**12
  836. - 168749980172837712266699840*x4**11
  837. + 290913179471491189688854560*x4**10 - 432958804125555395247740688*x4**9
  838. + 10386593827154614897599504*x4**8 + 155547361883654478618679440*x4**7
  839. - 31113996003728470659075480*x4**6 - 41175755320900503555096780*x4**5
  840. + 33003268068791208924709740*x4**4 - 6778828915691466390091200*x4**3
  841. - 1496167017611703417373950*x4**2 + 149688116448660711183825*x4
  842. + 138148004064999041884935,
  843. - 36439926476029643745*x2 - 784034192593211415232000000*x4**17
  844. + 2099814921874128508369920000*x4**16
  845. - 1180307545285783973854272000*x4**15
  846. - 904159020650675303719168000*x4**14
  847. + 583907514538684395627559680*x4**13
  848. + 340458856280381353403249664*x4**12
  849. - 136785894094420325707236352*x4**11
  850. + 235962131906791901454310848*x4**10
  851. - 351090033711917923140908256*x4**9 + 8379974606095284871931520*x4**8
  852. + 126131069262992237456374584*x4**7 -25220359028157888406315896*x4**6
  853. - 33393008746801847984243640*x4**5 + 26761347051713933045852160*x4**4
  854. - 5495296446381334401240210*x4**3 - 1213098761225775782417310*x4**2
  855. + 121243165959568584810870*x4 + 112046752277725240396125,
  856. 145759705904118574980*x3**2 - 3866759643063142140200960000*x3*x4**17
  857. + 10356855967811885555291136000*x3*x4**16
  858. - 5822945127616098986913024000*x3*x4**15
  859. - 4458936263906116333309629440*x3*x4**14
  860. + 2880962157128809915961707008*x3*x4**13
  861. + 1679119046179822790498717184*x3*x4**12
  862. - 674999920691350849066799360*x3*x4**11
  863. + 1163652717885964758755418240*x3*x4**10
  864. - 1731835216502221580990962752*x3*x4**9
  865. + 41546375308618459590398016*x3*x4**8
  866. + 622189447534617914474717760*x3*x4**7
  867. - 124455984014913882636301920*x3*x4**6
  868. - 164703021283602014220387120*x3*x4**5
  869. + 132013072275164835698838960*x3*x4**4
  870. - 27115315662765865560364800*x3*x4**3
  871. - 5984668070446813669495800*x3*x4**2 + 598752465794642844735300*x3*x4
  872. + 552592016259996167539740*x3 + 3550270013715070172487680000*x4**17
  873. - 9573649159583488469933568000*x4**16
  874. + 5464438450196473162575360000*x4**15
  875. + 4096921924516221821604523520*x4**14
  876. - 2717026023466705910519606784*x4**13
  877. - 1554544907157405816469959168*x4**12
  878. + 636859360057972319632500992*x4**11
  879. - 1065163663567422851531986944*x4**10
  880. + 1612243029585251439302638656*x4**9
  881. - 48252032958282805311135168*x4**8 - 579133322758350220074700320*x4**7
  882. + 117976179842506552019678280*x4**6 + 152287445048713077301910400*x4**5
  883. - 123053170142513516618082960*x4**4 + 25533441675517563881962200*x4**3
  884. + 5583415080801636858130200*x4**2 - 574247940288215661001800*x4
  885. - 518304795930023609925945,
  886. - 5120000*x4**18 + 18432000*x4**17 - 20352000*x4**16 + 1208320*x4**15
  887. + 9255936*x4**14 - 1296384*x4**13 - 2943488*x4**12 + 2365440*x4**11
  888. - 3712896*x4**10 + 2169600*x4**9 + 772560*x4**8 - 924480*x4**7
  889. - 66000*x4**6 + 375840*x4**5 - 197100*x4**4 + 25200*x4**3 + 8100*x4**2
  890. - 675}$
  891. multroot(20,h);
  892. %{{x1= - 0.12444800707566022364,x2=0.40264591905223704246,x3
  893. % =0.70281784593572688134,x4=0.92049796029182926078},
  894. % {x1= - 0.12444800707566022364,x2=0.92049796029182926078,x3
  895. % =0.70281784593572688134,x4=0.40264591905223704246},
  896. % {x1=0.22075230018295426413,x2=0.48100256896929398759,x3
  897. % =0.74057635603986743051,x4=0.93049526909398804249},
  898. % {x1=0.22075230018295426413,x2=0.93049526909398804249,x3
  899. % =0.74057635603986743051,x4=0.48100256896929398759},
  900. % {x1=0.70281784593572688134,x2=0.40264591905223704246,x3
  901. % = - 0.12444800707566022364,x4=0.92049796029182926078},
  902. % {x1=0.70281784593572688134,x2=0.92049796029182926078,x3
  903. % = - 0.12444800707566022364,x4=0.40264591905223704246},
  904. % {x1=0.74057635603986743051,x2=0.48100256896929398759,x3
  905. % =0.22075230018295426413,x4=0.93049526909398804249},
  906. % {x1=0.74057635603986743051,x2=0.93049526909398804249,x3
  907. % =0.22075230018295426413,x4=0.48100256896929398759}}
  908. % System precision will have been set to 20 in the two previous
  909. % examples. In the following examples, the roots will be given to
  910. % accuracy 12, because rootacc 12; was input. If rootacc had not been
  911. % input, the roots would be given at system precision, which could
  912. % different answers on different systems if precision had been reset,
  913. % or else it would have been 20 because of example 118).
  914. rootacc 12;
  915. % 119)
  916. ss := {x^2-2,y^2-x^2,z^2-x-y}; % structure is {p1(x),p2(x,y),p3(x,y,z)}
  917. realroots ss;
  918. %{{x= - 1.41421356237,y=1.41421356237,z=0},
  919. % {x= - 1.41421356237,y=1.41421356237,z=0},
  920. % {x=1.41421356237,y= - 1.41421356237,z=0},
  921. % {x=1.41421356237,y= - 1.41421356237,z=0},
  922. % {x=1.41421356237,y=1.41421356237,z= - 1.68179283051},
  923. % {x=1.41421356237,y=1.41421356237,z=1.68179283051}}
  924. roots ss;
  925. %{{x= - 1.41421356237,y= - 1.41421356237,z=1.68179283051*i},
  926. % {x= - 1.41421356237,y= - 1.41421356237,z= - 1.68179283051*i},
  927. % {x= - 1.41421356237,y=1.41421356237,z=0},
  928. % {x= - 1.41421356237,y=1.41421356237,z=0},
  929. % {x=1.41421356237,y= - 1.41421356237,z=0},
  930. % {x=1.41421356237,y= - 1.41421356237,z=0},
  931. % {x=1.41421356237,y=1.41421356237,z= - 1.68179283051},
  932. % {x=1.41421356237,y=1.41421356237,z=1.68179283051}}
  933. % 120)
  934. realroots {x^5-45x+2,y^2-x+1};
  935. %{{x=2.57878769906,y= - 1.25649818904},{x=2.57878769906,y
  936. % =1.25649818904}}
  937. realroots {x^5-45x+2,y^2-x-1};
  938. %{{x=0.0444444482981,y= - 1.02198064967},
  939. % {x=0.0444444482981,y=1.02198064967},
  940. % {x=2.57878769906,y= - 1.89176840524},
  941. % {x=2.57878769906,y=1.89176840524}}
  942. % 121)
  943. realroots {x^2-2,y^2+x^2};
  944. % {}
  945. roots {x^2+2,y^2-x^2};
  946. %{{x=1.41421356237*i,y=1.41421356237*i},
  947. % {x=1.41421356237*i,y= - 1.41421356237*i},
  948. % {x= - 1.41421356237*i,y=1.41421356237*i},
  949. % {x= - 1.41421356237*i,y= - 1.41421356237*i}}
  950. % 122)
  951. roots {x^2-y^2,x^2+y^2+3};
  952. %multroot fails because no univariate polynomial was given.
  953. %multroot(12,{x**2 - y**2,x**2 + y**2 + 3})$
  954. % 122a)
  955. roots{x^2+y^2,x^2-y^2-z,z^2-z-1};
  956. %*** multroot failure: at least one polynomial has no single base.
  957. %multroot(12,{x**2 + y**2,(x**2 - y**2) - z,(z**2 - z) - 1})$
  958. % 123)
  959. roots {x^2-2,y^2+3,x+z-2,y-z+2};
  960. %{}
  961. % 124)
  962. zz := {x^5-5x+3,x^2+y^2,x^3+z^3};
  963. realroots zz;
  964. %{}
  965. realroots {x^5-5x+3,x^2-y^2,x^3+z^3};
  966. %{{x= - 1.61803398875,y= - 1.61803398875,z=1.61803398875},
  967. % {x= - 1.61803398875,y=1.61803398875,z=1.61803398875},
  968. % {x=0.61803398875,y= - 0.61803398875,z= - 0.61803398875},
  969. % {x=0.61803398875,y=0.61803398875,z= - 0.61803398875},
  970. % {x=1.27568220365,y= - 1.27568220365,z= - 1.27568220365},
  971. % {x=1.27568220365,y=1.27568220365,z= - 1.27568220365}}
  972. % These show previous capability
  973. %------------------------------------------------------------------
  974. % These are new capability
  975. % 125)
  976. roots{x**2 - x - y,x*y - 2*y,y**2 - 2*y};
  977. %{{x=0,y=0},{x=1,y=0},{x=2.0,y=2.0}}
  978. % 126)
  979. roots({x^2-9,y^3-27,x*y+9});
  980. %{{x= - 3.0,y=3.0}}
  981. % 127)
  982. multroot(12,{y^2-z,y*z,z*(z-1)});
  983. %{{y=0,z=0},{y=0,z=0}}
  984. % 127a)
  985. multroot(12,{y^2-z,y*z,z*(z-1),x^2-x-y});
  986. %{{x=0,y=0,z=0},
  987. % {x=0,y=0,z=0},
  988. % {x=1,y=0,z=0},
  989. % {x=1,y=0,z=0}}
  990. % 128)
  991. roots{y*z,z*(z-1)};
  992. %{{z=0},{y=0,z=1}}
  993. % 129)
  994. zzl := {z*(z-1)*(z-2),(z-2)*z*y^2+(z-1)*z*y+z+1};
  995. roots zzl;
  996. %{{y= - 1.5,z=2.0},
  997. % {y= - 1.41421356237,z=1},
  998. % {y=1.41421356237,z=1}}
  999. % 129a)
  1000. zzla := {z*(z-1)*(z-2),(z-2)*z*y^2+(z-1)*z*y+z+1,x^2-x-y};
  1001. roots zzla;
  1002. %{{x= - 0.790044015673,y=1.41421356237,z=1},
  1003. % {x=0.5 + 1.11803398875*i,y= - 1.5,z=2.0},
  1004. % {x=0.5 - 1.11803398875*i,y= - 1.5,z=2.0},
  1005. % {x=0.5 + 1.07898728555*i,y= - 1.41421356237,z=1},
  1006. % {x=0.5 - 1.07898728555*i,y= - 1.41421356237,z=1},
  1007. % {x=1.79004401567,y=1.41421356237,z=1}}
  1008. % 130)
  1009. zzl0 := {z*(z-1)*(z-2),(z-2)*z*y^2+(z-1)*z*y+z};
  1010. roots zzl0;
  1011. %{{y=-1,z=1},{y=-1,z=2.0},{z=0},{y=1,z=1}}
  1012. % 131)
  1013. zzl3a := {z*(z-1)*(z-2),(z-2)*z*y^2+(z-1)*z*y+z,x^2+y*x*z+z};
  1014. roots zzl3a;
  1015. %{{x=0.866025403784*i - 0.5,y=1,z=1},
  1016. % {x= - 0.866025403784*i - 0.5,y=1,z=1},
  1017. % {x=0,z=0},
  1018. % {x=0,z=0},
  1019. % {x=0.866025403784*i + 0.5,y=-1,z=1},
  1020. % {x= - 0.866025403784*i + 0.5,y=-1,z=1},
  1021. % {x=i + 1,y=-1,z=2.0},
  1022. % {x= - i + 1,y=-1,z=2.0}}$
  1023. % 132)
  1024. zzl3c := {z*(z-1)*(z-2),(z-2)*z*y^2+(z-1)*z*y+z,x^2+y*x+z};
  1025. roots zzl3c;
  1026. %*** for some root value, a variable dependends on an arbitrary variable
  1027. %multroot(12,{z**3 - 3*z**2 + 2*z,y**2*z**2 - 2*y**2*z + y*z**2 - y*z + z,
  1028. % x**2 + x*y + z})$
  1029. % 133)
  1030. xyz := {x^2-x-2,y^2+y,x^3+y^3+z+5};
  1031. roots xyz;
  1032. %{{x=-1,y=-1,z= - 3.0},
  1033. % {x=-1,y=0,z= - 4.0},
  1034. % {x=2.0,y=-1,z= - 12.0},
  1035. % {x=2.0,y=0,z= - 13.0}}
  1036. % 134) here, we had to eliminate a spurious imaginary part of z.
  1037. axyz := {a-1,a+x^2-x-2,a+y^2+y,a+x^3+y^3+z+5};
  1038. roots axyz;
  1039. %{{a=1,x= - 0.61803398875,y= - 0.5 + 0.866025403784*i,z= - 6.7639320225},
  1040. % {a=1,x= - 0.61803398875,y= - 0.5 - 0.866025403784*i,z= - 6.7639320225},
  1041. % {a=1,x=1.61803398875,y= - 0.5 + 0.866025403784*i,z= - 11.2360679775},
  1042. % {a=1,x=1.61803398875,y= - 0.5 - 0.866025403784*i,z= - 11.2360679775}}
  1043. % 134a) here, we had to eliminate a spurious real part of x.
  1044. roots{y^4+y^3+y^2+y+1,x^2+3*y^5+2};
  1045. %{{x=2.2360679775*i,y= - 0.809016994375 + 0.587785252292*i},
  1046. % {x=-2.2360679775*i,y= - 0.809016994375 + 0.587785252292*i},
  1047. % {x=-2.2360679775*i,y= - 0.809016994375 - 0.587785252292*i},
  1048. % {x=2.2360679775*i,y= - 0.809016994375 - 0.587785252292*i},
  1049. % {x=-2.2360679775*i,y=0.309016994375 + 0.951056516295*i},
  1050. % {x=2.2360679775*i,y=0.309016994375 + 0.951056516295*i},
  1051. % {x=2.2360679775*i,y=0.309016994375 - 0.951056516295*i},
  1052. % {x=-2.2360679775*i,y=0.309016994375 - 0.951056516295*i}}
  1053. % 135)
  1054. axyz2 := {a-1,a-1+x^2-x-2,a-1+y^2+y,x^3+y^3+z+5};
  1055. roots axyz2;
  1056. %{{a=1,x=-1,y=-1,z= - 3.0},
  1057. % {a=1,x=-1,y=0,z= - 4.0},
  1058. % {a=1,x=2.0,y=-1,z= - 12.0},
  1059. % {a=1,x=2.0,y=0,z= - 13.0}}
  1060. zyxa2 := reverse axyz2;
  1061. roots zyxa2;
  1062. % (same as above)
  1063. % 137)
  1064. rsxuv := {u^2+u*r+s*x*v,s+r^2,x-r-2,r+v,v^2-v-6};
  1065. roots rsxuv;
  1066. %{{r= - 3.0,s= - 9.0,u=1.5 + 4.97493718553*i,v=3.0,x=-1},
  1067. % {r= - 3.0,s= - 9.0,u=1.5 - 4.97493718553*i,v=3.0,x=-1},
  1068. % {r=2.0,s= - 4.0,u= - 1 + 5.56776436283*i,v= - 2.0,x=4.0},
  1069. % {r=2.0,s= - 4.0,u= - 1 - 5.56776436283*i,v= - 2.0,x=4.0}}
  1070. % 138)
  1071. rsxuv2 := {u^2+u*r+s*x,s+r,x-r-2,r+v,v^2-v-6};
  1072. roots rsxuv2;
  1073. %{{r= - 3.0,s=3.0,u= - 0.791287847478,v=3.0,x=-1},
  1074. % {r= - 3.0,s=3.0,u=3.79128784748,v=3.0,x=-1},
  1075. % {r=2.0,s= - 2.0,u= - 4.0,v= - 2.0,x=4.0},
  1076. % {r=2.0,s= - 2.0,u=2.0,v= - 2.0,x=4.0}}
  1077. % 139) combining both types of capabilities.
  1078. axyz3 := {a-1,a-1+x^2-x-2,a-1+y^2+y,x^3+y^3+z+5,y^2-x^2};
  1079. roots axyz3;
  1080. %{{a=1,x=-1,y=-1,z= - 3.0}}
  1081. % 140) spurious real and imag. parts had to be eliminated from z and y.
  1082. ayz := {a^2+a+1,z^2+a^3+3,y^3-z^2};
  1083. roots ayz;
  1084. %{{a= - 0.5 + 0.866025403784*i,y= - 1.58740105197,z=2.0*i},
  1085. % {a= - 0.5 + 0.866025403784*i,y= - 1.58740105197,z=-2.0*i},
  1086. % {a= - 0.5 - 0.866025403784*i,y= - 1.58740105197,z=-2.0*i},
  1087. % {a= - 0.5 - 0.866025403784*i,y= - 1.58740105197,z=2.0*i},
  1088. % {a= - 0.5 + 0.866025403784*i,y=0.793700525984 + 1.374729637*i,z=2.0*i},
  1089. % {a= - 0.5 + 0.866025403784*i,y=0.793700525984 - 1.374729637*i,z=2.0*i},
  1090. % {a= - 0.5 + 0.866025403784*i,y=0.793700525984 + 1.374729637*i,z=-2.0*i},
  1091. % {a= - 0.5 + 0.866025403784*i,y=0.793700525984 - 1.374729637*i,z=-2.0*i},
  1092. % {a= - 0.5 - 0.866025403784*i,y=0.793700525984 - 1.374729637*i,z=-2.0*i},
  1093. % {a= - 0.5 - 0.866025403784*i,y=0.793700525984 + 1.374729637*i,z=-2.0*i},
  1094. % {a= - 0.5 - 0.866025403784*i,y=0.793700525984 - 1.374729637*i,z=2.0*i},
  1095. % {a= - 0.5 - 0.866025403784*i,y=0.793700525984 + 1.374729637*i,z=2.0*i}}
  1096. % 141) some small real or imaginary parts are not spurious; they are kept.
  1097. zz:= {x**9-9999x**2-0.01,y^2+y-x};
  1098. roots zz;
  1099. %{{x= - 3.35839794887 + 1.61731917877*i,y= - 0.944735689647 -
  1100. % 1.81829254591*i},
  1101. % {x= - 3.35839794887 - 1.61731917877*i,y= - 0.944735689647 +
  1102. % 1.81829254591*i},
  1103. % {x= - 3.35839794887 + 1.61731917877*i,y= - 0.0552643103532 +
  1104. % 1.81829254591*i},
  1105. % {x= - 3.35839794887 - 1.61731917877*i,y= - 0.0552643103532 -
  1106. % 1.81829254591*i},
  1107. % {x= - 0.829455794538 + 3.6340832074*i,y= - 1.74509731832 -
  1108. % 1.45935709359*i},
  1109. % {x= - 0.829455794538 - 3.6340832074*i,y= - 1.74509731832 +
  1110. % 1.45935709359*i},
  1111. % {x= - 0.829455794538 + 3.6340832074*i,y=0.745097318317 +
  1112. % 1.45935709359*i},
  1113. % {x= - 0.829455794538 - 3.6340832074*i,y=0.745097318317 -
  1114. % 1.45935709359*i},
  1115. % {x=5.00250075018E-29 + 0.00100005000375*i,y= - 1.0000010001 -
  1116. % 0.00100004800346*i},
  1117. % {x=5.00250075018E-29 - 0.00100005000375*i,y= - 1.0000010001 +
  1118. % 0.00100004800346*i},
  1119. % {x=5.00250075018E-29 + 0.00100005000375*i,y=0.00000100009500904 +
  1120. % 0.00100004800346*i},
  1121. % {x=5.00250075018E-29 - 0.00100005000375*i,y=0.00000100009500904 -
  1122. % 0.00100004800346*i},
  1123. % {x=2.3240834909 + 2.91430845907*i,y= - 2.29755558063 -
  1124. % 0.810630973104*i},
  1125. % {x=2.3240834909 - 2.91430845907*i,y= - 2.29755558063 +
  1126. % 0.810630973104*i},
  1127. % {x=2.3240834909 + 2.91430845907*i,y=1.29755558063 + 0.810630973104*i},
  1128. % {x=2.3240834909 - 2.91430845907*i,y=1.29755558063 - 0.810630973104*i},
  1129. % {x=3.72754050502,y= - 2.49437722235},
  1130. % {x=3.72754050502,y=1.49437722235}}$
  1131. % 142) if quotient, only numerator is used as polynomial, so this works.
  1132. vv := {x+1+1/x,y^2-x^3};
  1133. roots vv;
  1134. %{{x= - 0.5 + 0.866025403784*i,y=-1},{x= - 0.5 - 0.866025403784*i,y=-1},
  1135. % {x= - 0.5 + 0.866025403784*i,y=1},{x= - 0.5 - 0.866025403784*i,y=1}}
  1136. % 143) and this also works.
  1137. ii := {x^2-2x+3/r,r^3-5};
  1138. roots ii;
  1139. %{{r= - 0.854987973338 + 1.48088260968*i,x= - 0.464963274745 -
  1140. % 0.518567329174*i},
  1141. % {r= - 0.854987973338 - 1.48088260968*i,x= - 0.464963274745 +
  1142. % 0.518567329174*i},
  1143. % {r= - 0.854987973338 + 1.48088260968*i,x=2.46496327474 +
  1144. % 0.518567329174*i},
  1145. % {r= - 0.854987973338 - 1.48088260968*i,x=2.46496327474 -
  1146. % 0.518567329174*i},
  1147. % {r=1.70997594668,x=1 + 0.868568156754*i},
  1148. % {r=1.70997594668,x=1 - 0.868568156754*i}}
  1149. % 144)
  1150. bb := {y+x+3,x^2+r+s-3,x^3+r+s-7,r^2-r,s^2+3s+2};
  1151. roots bb;
  1152. %{{r=0,s=-1,x=2.0,y= - 5.0},{r=1,s= - 2.0,x=2.0,y= - 5.0}}
  1153. end;