Debian Codegraph @

texmf-dist/tex/generic/polexpr/polexprsturm.tex

raw
1 %% filename: polexprsturm.tex
2 %% Part of the polexpr package (0.8.7a, 2022/05/19)
3 %%
4 %% Implements the Sturm localization Algorithm
5 %% Added at polexpr 0.4
6 %%
7 %% 0.5 uses primitive polynomials for faster evaluations afterwards
8 %% 0.6 corrects misuse of \@ifstar (mumble). \PolToSturm* was broken.
9 %% 0.6's \PolToSturm* defines both normalized and unnormalized, the
10 %% unnormalized using two underscores, so both are available
11 %% Sole difference is that \PolToSturm* also declares them as
12 %% user polynomials, whereas the non-starred only keeps the macros
13 %% holding the coefficients in memory
14 %% 0.6 fixes the case of a constant polynomial P which caused division
15 %% by zero error from P'.
16 %% 0.8 - fixes 0.7.5 compatibility bug with xint 1.4 internal format
17 %% regarding the defined \xintexpr variables holding the localization
18 %% intervals extremities
19 %% - also, it uses the prem() in computing the Sturm chain, with a 3X
20 %% speed gain in the case of the "perturbed" first Wilkinson example
21 %% 0.8.6 has better a priori bounds for positive and negative roots
22 \newcount\POL@count
23 \newif\ifPOL@tosturm@makefirstprimitive\POL@tosturm@makefirstprimitivetrue
24 \newif\ifPOL@isolz@nextwillneedrefine
25 %%
26 \def\PolToSturm{\POL@ifstar{\PolToSturm@@}{\PolToSturm@}}%
27 \def\POL@aux@toint#1{\xintREZ{\xintNum{#1}}}% for polynomials with int. coeffs!
28 %% Attention that some macros rely upon this one defining \POL@sturmname
29 %% and \POL@sturm@N as it currently does
30 \def\PolToSturm@#1#2{%
31 \edef\POL@sturmname{#2}%
32 % 0.6 uses 2 underscores (one before index, one after) to keep in memory
33 % the unnormalized chain
34 % This supposes #1 to be a genuine polynomial, not only a name with
35 % a \POLuserpol@#1 macro
36 \POL@let{\POL@sturmname _0_}{#1}%
37 \ifnum\PolDegree{#1}=\z@
38 \def\POL@sturm@N{0}%
39 \POL@count\z@
40 % if I applied the same as for positive degree, I should make it -1
41 % if constant is negative. I also don't worry if polynomial is zero.
42 \XINT_global\@namedef{POLuserpol@\POL@sturmname _0}{0.\empty{1/1[0]}}%
43 \else
44 \ifPOL@tosturm@makefirstprimitive\POL@makeprimitive{\POL@sturmname _0_}\fi
45 \POL@tosturm@dosturm
46 \fi
47 \expandafter
48 \let\csname PolSturmChainLength_\POL@sturmname\endcsname\POL@sturm@N
49 % declare the normalized ones as full-fledged polynomials
50 % \POL@count\z@
51 \xintloop
52 \POL@newpol{\POL@sturmname _\the\POL@count}%
53 \unless\ifnum\POL@sturm@N=\POL@count
54 \advance\POL@count\@ne
55 \repeat
56 }%
57 \def\PolToSturm@@#1#2{\PolToSturm@{#1}{#2}\POL@tosturm@declareunnormalized}%
58 \def\POL@tosturm@declareunnormalized{%
59 % optionally declare also the unnormalized ones
60 \POL@count\z@
61 \xintloop
62 \POL@newpol{\POL@sturmname _\the\POL@count _}%
63 \unless\ifnum\POL@sturm@N=\POL@count
64 \advance\POL@count\@ne
65 \repeat
66 }%
67 \def\POL@tosturm@dosturm{%
68 \POL@Diff@@one{\POL@sturmname _0_}{\POL@sturmname _1_}%
69 \POL@makeprimitive{\POL@sturmname _1_}% does not do \POL@newpol
70 \POL@count\@ne
71 \xintloop
72 \POL@getprem{\POL@sturmname _\the\numexpr\POL@count-\@ne\relax _}%
73 {\POL@sturmname _\the\POL@count _}%
74 \expandafter\POL@split\POL@R;\POL@degR\POL@polR
75 \unless\ifnum\POL@degR=\m@ne
76 \advance\POL@count\@ne
77 \XINT_global\expandafter\let
78 \csname POLuserpol@\POL@sturmname _\the\POL@count _\endcsname\POL@R
79 \edef\POL@makeprim@icontent{-\POL@icontent\POL@polR}%
80 % this avoids the \POL@newpol from \PolMapCoeffs
81 \POL@mapcoeffs\POL@makeprim@macro{\POL@sturmname _\the\POL@count _}%
82 \repeat
83 \edef\POL@sturm@N{\the\POL@count}%
84 % normalize (now always done even by starred variant)
85 \ifnum\PolDegree{\POL@sturmname _\POL@sturm@N _}>\z@
86 % \POL@count\POL@sturm@N\relax
87 \xintloop
88 \advance\POL@count\m@ne
89 \POL@divide{\POL@sturmname _\the\POL@count _}%
90 {\POL@sturmname _\POL@sturm@N _}%
91 \XINT_global\expandafter
92 \let\csname POLuserpol@\POL@sturmname _\the\POL@count\endcsname\POL@Q
93 % quotient actually belongs to Z[X] and is primitive
94 \POL@mapcoeffs\POL@aux@toint{\POL@sturmname _\the\POL@count}%
95 \ifnum\POL@count>\z@
96 \repeat
97 \XINT_global\@namedef{POLuserpol@\POL@sturmname _\POL@sturm@N}{0.\empty{1/1[0]}}%
98 \else % they are already normalized
99 \advance\POL@count\@ne % attention to include last one also
100 \xintloop
101 \advance\POL@count\m@ne
102 \XINT_global\expandafter\let
103 \csname POLuserpol@\POL@sturmname _\the\POL@count\expandafter\endcsname
104 \csname POLuserpol@\POL@sturmname _\the\POL@count _\endcsname
105 \ifnum\POL@count>\z@
106 \repeat
107 \fi
108 % Back to \PolToSturm@, \POL@count holds 0
109 }%
110 \def\PolSturmChainLength#1{%
111 \romannumeral`&&@\csname PolSturmChainLength_#1\endcsname
112 }%
113 \def\PolSetToSturmChainSignChangesAt{%
114 \POL@chkopt\POL@oPolSetToSturmChainSignChangesAt[\global]%
115 }%
116 \def\POL@oPolSetToSturmChainSignChangesAt[#1]#2#3#4{%
117 \edef\POL@sturmchain@X{\xintREZ{#4}}%
118 \edef\POL@sturmname{#3}%
119 \edef\POL@sturmlength{\PolSturmChainLength{\POL@sturmname}}%
120 \POL@sturmchain@getSV@at\POL@sturmchain@X
121 #1\let#2\POL@sturmchain@SV
122 }%
123 % attention that this modifies current \POL@count value
124 \def\POL@sturmchain@getSV@at#1{%
125 \def\POL@sturmchain@SV{0}%
126 \edef\POL@sturmchain@sign{\xintiiSgn{\POL@eval{\POL@sturmname _0}{#1}}}%
127 \let\POL@isolz@lastsign\POL@sturmchain@sign
128 \POL@count \z@
129 \ifnum\POL@isolz@lastsign=\z@
130 \edef\POL@isolz@lastsign
131 {\xintiiSgn{\POL@eval{\POL@sturmname _1}{#1}}}%
132 \POL@count \@ne
133 \fi
134 \xintloop
135 \unless\ifnum\POL@sturmlength=\POL@count
136 \advance\POL@count \@ne
137 \edef\POL@isolz@newsign
138 {\xintiiSgn{\POL@eval{\POL@sturmname _\the\POL@count}{#1}}}%
139 \ifnum\POL@isolz@newsign=\numexpr-\POL@isolz@lastsign\relax
140 \edef\POL@sturmchain@SV{\the\numexpr\POL@sturmchain@SV+\@ne}%
141 \let\POL@isolz@lastsign=\POL@isolz@newsign
142 \fi
143 \repeat
144 }%
145 \def\PolSetToNbOfZerosWithin{%
146 \POL@chkopt\POL@oPolSetToNbOfZerosWithin[\global]%
147 }%
148 \def\POL@oPolSetToNbOfZerosWithin[#1]#2#3#4#5{%
149 \edef\POL@tmpA{\xintREZ{#4}}%
150 \edef\POL@tmpB{\xintREZ{#5}}%
151 \edef\POL@sturmname{#3}%
152 \edef\POL@sturmlength{\PolSturmChainLength{\POL@sturmname}}%
153 \POL@sturmchain@getSV@at\POL@tmpA
154 \let\POL@SVA\POL@sturmchain@SV
155 \POL@sturmchain@getSV@at\POL@tmpB
156 \let\POL@SVB\POL@sturmchain@SV
157 \ifnum\POL@SVA<\POL@SVB\space
158 #1\edef#2{\the\numexpr\POL@SVB-\POL@SVA}%
159 \else
160 #1\edef#2{\the\numexpr\POL@SVA-\POL@SVB}%
161 \fi
162 }%
163 % 0.6 added starred variant to count multiplicities
164 % 0.7 added double starred variant to locate all rational roots
165 \def\PolSturmIsolateZeros{\POL@ifstar
166 {\PolSturmIsolateZerosAndGetMultiplicities}%
167 {\PolSturmIsolateZeros@}%
168 }%
169 \def\PolSturmIsolateZerosAndGetMultiplicities{\POL@ifstar
170 {\PolSturmIsolateZerosGetMultiplicitiesAndRationalRoots}%
171 {\PolSturmIsolateZerosAndGetMultiplicities@}%
172 }%
173 \def\POL@xintfrac@getNDE #1%
174 {\expandafter\POL@xintfrac@getNDE@i\romannumeral`&&@#1}%
175 \def\POL@xintfrac@getNDE@i #1/#2[#3]#4#5#6{\def#4{#1}\def#5{#2}\def#6{#3}}%
176 %
177 \def\PolSturmIsolateZerosGetMultiplicitiesAndRationalRoots{%
178 \POL@chkopt\POL@oPolSturmIsolateZerosGetMultiplicitiesAndRationalRoots[\empty]%
179 }%
180 \def\POL@oPolSturmIsolateZerosGetMultiplicitiesAndRationalRoots[#1]#2{%
181 \PolSturmIsolateZerosAndFindRationalRoots[#1]{#2}%
182 \ifnum\POL@isolz@NbOfRoots>\z@
183 % get multiplicities of irrational (real) roots, if any
184 \ifnum\POL@findrat@nbofirrroots>\z@
185 \POL@findrat@getirrmult
186 \fi
187 \POL@isolzmult@defvar@M
188 \fi
189 }%
190 % added at 0.7
191 \def\PolSturmIsolateZerosAndFindRationalRoots{%
192 \POL@chkopt\POL@oPolSturmIsolateZerosAndFindRationalRoots[\empty]%
193 }%
194 \def\POL@oPolSturmIsolateZerosAndFindRationalRoots[#1]#2{%
195 % #1 optional E such that roots are searched in -10^E < x < 10^E
196 % both -10^E and +10^E must not be roots!
197 % #2 name of Sturm chain (already pre-computed)
198 \edef\POL@sturmname{#2}%
199 \edef\POL@sturm@N{\@nameuse{PolSturmChainLength_\POL@sturmname}}%
200 % isolate the roots (detects case of constant polynomial)
201 \PolSturmIsolateZeros@{\POL@sturmname}%
202 \XINT_global
203 \expandafter\let
204 \csname POLuserpol@\POL@sturmname\POL@sqfnorr\expandafter\endcsname
205 \csname POLuserpol@\POL@sturmname _0\endcsname
206 \XINT_global
207 \expandafter\let
208 \csname POLuserpol@\POL@sturmname\POL@norr\expandafter\endcsname
209 \csname POLuserpol@\POL@sturmname _0_\endcsname
210 \ifnum\POL@isolz@NbOfRoots=\z@
211 % no real roots, define empty arrays nevertheless
212 \begingroup\globaldefs\@ne
213 \expandafter\xintAssignArray\expandafter\to\csname POL_ZM\POL@sturmname*\endcsname
214 \expandafter\xintAssignArray\expandafter\to\csname POL_RI\POL@sturmname*\endcsname
215 \endgroup
216 \else
217 % all we currently know is that multiplicities are at least one
218 \begingroup\globaldefs\@ne
219 \expandafter\POL@initarray\csname POL_ZM\POL@sturmname*\endcsname{1}%
220 \endgroup
221 % D and its exponent E will get updated along the way
222 \edef\POL@findrat@D{\xintAbs{\PolLeadingCoeff{\POL@sturmname _0}}}%
223 \POL@xintfrac@getNDE\POL@findrat@D\POL@findrat@Dint\POL@_\POL@findrat@Dexp
224 \xintiiifOne{\POL@findrat@Dint}
225 {\let\POL@findrat@E\POL@findrat@Dexp} % aussi ok pour 1[0]
226 {\edef\POL@findrat@E{\the\numexpr\xintLen{\POL@findrat@Dint}%
227 +\POL@findrat@Dexp}}%
228 \POL@initarray\POL@IfMultIsKnown\xint_secondoftwo
229 \let\POL@findrat@nbofirrroots\POL@isolz@NbOfRoots
230 % find all rational roots, and their multiplicities,
231 % factor them out from original (Sturm root) polynomial
232 \ifnum\POL@findrat@E<7 %
233 \def\POL@findrat@index{1}%
234 \POL@findrat@loop@secondpass@direct
235 \else
236 % we do a first pass scanning for "small" roots p/q (i.e. q < 1000)
237 \def\POL@findrat@index{1}%
238 \POL@findrat@loop@firstpass
239 % and now we do the final pass finding them all
240 \def\POL@findrat@index{1}%
241 \POL@findrat@loop@secondpass
242 \fi
243 % declare the array holding the interval indices for the rational roots
244 \expandafter\POL@findrat@doRRarray\csname POL_RI\POL@sturmname*\endcsname
245 \fi
246 % declare the new polynomials (also if no real roots exist)
247 \POL@newpol{\POL@sturmname\POL@sqfnorr}% without multiplicities
248 \POL@newpol{\POL@sturmname\POL@norr}% with multiplicities
249 }%
250 \def\POL@findrat@doRRarray#1{%
251 \edef\POL@temp{%
252 \xintiloop[1+1]
253 \romannumeral0\csname POL_ZK\POL@sturmname*\xintiloopindex\endcsname
254 \xintbracediloopindex % I should have named it \xintiloopbracedindex...
255 {}%
256 \ifnum\xintiloopindex<\POL@isolz@NbOfRoots\space
257 \repeat }%
258 \begingroup\globaldefs\@ne
259 \xintAssignArray\POL@temp\to#1%
260 \endgroup
261 }%
262 \def\POL@findrat@loop@firstpass{%
263 \PolSturmIfZeroExactlyKnown{\POL@sturmname}{\POL@findrat@index}%
264 \POL@findrat@loop@decimal% get its multiplicity
265 \POL@findrat@loop@aa % refine interval and check
266 \edef\POL@findrat@index{\the\numexpr\POL@findrat@index+\@ne}%
267 \ifnum\POL@findrat@index>\POL@isolz@NbOfRoots
268 \else
269 \expandafter\POL@findrat@loop@firstpass
270 \fi
271 }%
272 \def\POL@findrat@loop@aa{%
273 % we do a first pass to identify roots with denominators < 1000
274 \PolEnsureIntervalLength{\POL@sturmname}{\POL@findrat@index}{-6}%
275 % attention that perhaps now the root is known!
276 \PolSturmIfZeroExactlyKnown{\POL@sturmname}{\POL@findrat@index}%
277 \POL@findrat@loop@decimal
278 \POL@findrat@loop@a
279 }%
280 \def\POL@findrat@loop@decimal{% we have an already found decimal root
281 % we do not go via @storeit, as it is already stored
282 \POL@xintfrac@getNDE
283 {\xintIrr{\POL@xintexprGetVar{\POL@sturmname L_\POL@findrat@index}}[0]}%
284 \POL@findrat@xN\POL@findrat@xD\POl@_
285 % we can't move this to updatequotients because other branch will
286 % need to do the division first anyhow
287 \edef\POLuserpol@_findrat@oneterm{1.\noexpand\empty
288 {\xintiiOpp\POL@findrat@xN/1[0]}{\POL@findrat@xD/1[0]}}%
289 \POL@divide{\POL@sturmname\POL@sqfnorr}{_findrat@oneterm}% the one without mult.
290 %\expandafter\POL@split\POL@R;\POL@degR\POL@polR
291 \POL@findrat@loop@updatequotients
292 \POL@findrat@loop@getmultiplicity
293 }%
294 % lacking from xint 1.3c, but \xintSgn has overhead, so we define ii version
295 \def\xintiiifNeg{\romannumeral0\xintiiifneg }%
296 \def\xintiiifneg #1%
297 {%
298 \ifcase \xintiiSgn{#1}
299 \expandafter\xint_stop_atsecondoftwo
300 \or\expandafter\xint_stop_atsecondoftwo
301 \else\expandafter\xint_stop_atfirstoftwo
302 \fi
303 }%
304 \def\POL@findrat@getE #1/1[#2]{#2}%
305 \def\POL@findrat@loop@a{%
306 % attention that the width may have been already smaller than 10^{-6}
307 \POL@get@IsoLeft@rawin
308 \POL@get@IsoRight@rawin
309 \edef\POL@findrat@localW
310 {\the\numexpr-\expandafter\POL@findrat@getE
311 \romannumeral0\xintrez
312 {\xintSub{\POL@IsoRight@rawin}{\POL@IsoLeft@rawin}}%
313 }% at least 6, maybe larger
314 \expandafter\POL@get@Int@aux
315 \POL@IsoLeft@rawin\POL@IsoLeft@Int{-\POL@findrat@localW}%
316 \expandafter\POL@get@Int@aux
317 \POL@IsoRight@rawin\POL@IsoRight@Int{-\POL@findrat@localW}%
318 % in case of odd, some waste here
319 \edef\POL@findrat@halflocalW{\the\numexpr(\POL@findrat@localW+1)/2-1}%
320 % Legendre Theorem will be used now but we separate a branch where
321 % everything can be done with \numexpr
322 \ifnum\POL@findrat@localW>9 %
323 % not implemented yet by lazyness!
324 % this root will be handled in second pass only
325 \else
326 \POL@findrat@gcdloop
327 \fi
328 }%
329 \def\POL@findrat@gcdloop{%
330 % we must be careful with sign
331 % but we are certain no extremity is a root
332 \let\POL@findrat@ifnegative\xint_secondoftwo
333 \xintiiifSgn\POL@IsoLeft@Int
334 \POL@findrat@gcdloop@n
335 \POL@error@thisisimpossible
336 \POL@findrat@gcdloop@p
337 }%
338 \def\POL@findrat@gcdloop@n{%
339 \let\POL@findrat@ifnegative\xint_firstoftwo
340 \let\POL@temp\POL@IsoRight@Int
341 \edef\POL@IsoRight@Int{\xintiiOpp{\POL@IsoLeft@Int}}%
342 \edef\POL@IsoLeft@Int{\xintiiOpp{\POL@temp}}%
343 \POL@findrat@gcdloop@p
344 }%
345 \def\POL@findrat@gcdloop@p{%
346 \edef\POL@findrat@gcdloop@Ap{\xintDec{\xintDouble\POL@IsoRight@Int}}%
347 \edef\POL@findrat@gcdloop@A
348 % at most 2e9: this is acceptable to \numexpr
349 {2\romannumeral\xintreplicate\POL@findrat@localW{0}}%
350 \xintAssign
351 \xintiiDivision\POL@findrat@gcdloop@Ap\POL@findrat@gcdloop@A
352 \to\POL@findrat@gcdloop@B\POL@findrat@gcdloop@An
353 % we will drop integral part in our updating P
354 \let\POL@findrat@gcdloop@Binitial\POL@findrat@gcdloop@B
355 \def\POL@findrat@gcdloop@B{0}% do as if B1 = 0
356 \def\POL@findrat@gcdloop@Pp{1}% P0
357 \def\POL@findrat@gcdloop@P{0}% P1
358 \def\POL@findrat@gcdloop@Qp{0}% Q0
359 \def\POL@findrat@gcdloop@Q{1}% Q1
360 % A2=An can not be zero, as Ap (=A0) is odd and A (=A1=200...000) is even
361 % first Binitial + P1/Q1 ( = Binitial) can not be root
362 \let\POL@findrat@gcdloop@Ap\POL@findrat@gcdloop@A % A1
363 \let\POL@findrat@gcdloop@A\POL@findrat@gcdloop@An % A2
364 \def\next{\POL@findrat@gcdloop@update}%
365 \def\POL@findrat@gcdloop@done{0}%
366 \POL@findrat@gcdloop@body
367 }%
368 \def\POL@findrat@gcdloop@body{%
369 \edef\POL@findrat@gcdloop@B
370 {\the\numexpr(\POL@findrat@gcdloop@Ap+\POL@findrat@gcdloop@A/2)/%
371 \POL@findrat@gcdloop@A - \@ne}%
372 \edef\POL@findrat@gcdloop@An
373 {\the\numexpr\POL@findrat@gcdloop@Ap-%
374 \POL@findrat@gcdloop@B*\POL@findrat@gcdloop@A}%
375 \edef\POL@findrat@gcdloop@Pn
376 {\the\numexpr\POL@findrat@gcdloop@Pp+%
377 \POL@findrat@gcdloop@B*\POL@findrat@gcdloop@P}%
378 \edef\POL@findrat@gcdloop@Qn
379 {\the\numexpr\POL@findrat@gcdloop@Qp+%
380 \POL@findrat@gcdloop@B*\POL@findrat@gcdloop@Q}%
381 \ifnum\expandafter\xintLength\expandafter{\POL@findrat@gcdloop@Qn}%
382 >\POL@findrat@halflocalW\space
383 \let\next\empty % no solution was found
384 \else
385 % with these conditions on denom, only candidates are by Legendre
386 % theorem among the convergents as computed here
387 \ifnum\POL@findrat@gcdloop@Qn>\POL@findrat@gcdloop@An\space
388 % means that P/Q is in interval and is thus a candidate
389 % it is automatically irreducible
390 \edef\POL@findrat@x{\xintiiAdd
391 {\xintiiMul{\POL@findrat@gcdloop@Qn}{\POL@findrat@gcdloop@Binitial}}%
392 {\POL@findrat@gcdloop@Pn}/\POL@findrat@gcdloop@Qn[0]}%
393 \POL@findrat@gcdloop@testit
394 \if1\POL@findrat@gcdloop@done
395 \let\next\empty % a solution was found
396 \fi
397 \fi
398 \fi
399 \next
400 }%
401 \def\POL@findrat@gcdloop@update{%
402 \ifnum\POL@findrat@gcdloop@An>\z@
403 \let\POL@findrat@gcdloop@Ap\POL@findrat@gcdloop@A
404 \let\POL@findrat@gcdloop@A\POL@findrat@gcdloop@An
405 \let\POL@findrat@gcdloop@Pp\POL@findrat@gcdloop@P
406 \let\POL@findrat@gcdloop@P\POL@findrat@gcdloop@Pn
407 \let\POL@findrat@gcdloop@Qp\POL@findrat@gcdloop@Q
408 \let\POL@findrat@gcdloop@Q\POL@findrat@gcdloop@Qn
409 \expandafter\POL@findrat@gcdloop@body
410 \fi
411 }%
412 \def\POL@findrat@gcdloop@testit{%
413 % zero should never occur here
414 \POL@findrat@ifnegative{\edef\POL@findrat@x{-\POL@findrat@x}}{}%
415 \POL@xintfrac@getNDE\POL@findrat@x\POL@findrat@xN\POL@findrat@xD\POL@_
416 \edef\POLuserpol@_findrat@oneterm{1.\noexpand\empty
417 {\xintiiOpp{\POL@findrat@xN}/1[0]}{\POL@findrat@xD/1[0]}}%
418 \POL@divide{\POL@sturmname\POL@sqfnorr}{_findrat@oneterm}% the one without mult.
419 \expandafter\POL@split\POL@R;\POL@degR\POL@polR
420 \ifnum\POL@degR=\m@ne % found a root
421 \POL@findrat@loop@storeit
422 \POL@findrat@loop@updatequotients
423 \POL@findrat@loop@getmultiplicity % will continue updating the mult. one
424 \def\POL@findrat@gcdloop@done{1}%
425 \fi
426 }%
427 % This is second phase
428 \def\POL@findrat@loop@secondpass{%
429 \PolSturmIfZeroExactlyKnown{\POL@sturmname}{\POL@findrat@index}%
430 {}% nothing more to be done, already stored
431 \POL@findrat@loop@bb % refine interval and check
432 \edef\POL@findrat@index{\the\numexpr\POL@findrat@index+\@ne}%
433 \ifnum\POL@findrat@index>\POL@isolz@NbOfRoots
434 \else
435 \expandafter\POL@findrat@loop@secondpass
436 \fi
437 }%
438 \def\POL@findrat@loop@secondpass@direct{%
439 \PolSturmIfZeroExactlyKnown{\POL@sturmname}{\POL@findrat@index}%
440 \POL@findrat@loop@decimal
441 \POL@findrat@loop@bb
442 \edef\POL@findrat@index{\the\numexpr\POL@findrat@index+\@ne}%
443 \ifnum\POL@findrat@index>\POL@isolz@NbOfRoots
444 \else
445 \expandafter\POL@findrat@loop@secondpass@direct
446 \fi
447 }%
448 \def\POL@findrat@loop@bb{%
449 \PolEnsureIntervalLength{\POL@sturmname}{\POL@findrat@index}{-\POL@findrat@E}%
450 % ATTENTION THAT PERHAPS NOW THE ROOT IS KNOWN!
451 \PolSturmIfZeroExactlyKnown{\POL@sturmname}{\POL@findrat@index}%
452 \POL@findrat@loop@decimal
453 \POL@findrat@loop@b
454 }%
455 \def\POL@findrat@loop@b{%
456 \edef\POL@findrat@Lscaled{\xintMul{\POL@findrat@D}%
457 {\POL@xintexprGetVar{\POL@sturmname L_\POL@findrat@index}}}%
458 \edef\POL@findrat@Rscaled{\xintMul{\POL@findrat@D}%
459 {\POL@xintexprGetVar{\POL@sturmname R_\POL@findrat@index}}}%
460 % using ii version is an abuse
461 \xintiiifNeg{\POL@findrat@Lscaled}%
462 {% negative interval (right bound possibly zero!)
463 % truncate towards zero (i.e. to the right) the left bound
464 \edef\POL@findrat@Num{\xintNum{\POL@findrat@Lscaled}/1[0]}%
465 % interval boundaries are not root hence in case that was exact
466 % this will not be found as a root; check if in interval
467 \xintifLt\POL@findrat@Num\POL@findrat@Rscaled
468 \POL@findrat@loop@c
469 {}% iterate
470 }%
471 {% positive interval (left bound possibly zero!)
472 % truncate towards zero (i.e. to the left) the right bound
473 \edef\POL@findrat@Num{\xintNum{\POL@findrat@Rscaled}/1[0]}%
474 % check if in interval
475 \xintifGt\POL@findrat@Num\POL@findrat@Lscaled
476 \POL@findrat@loop@c
477 {}% iterate
478 }%
479 }%
480 \def\POL@findrat@loop@c{%
481 % safer to do the edef as \POL@findrat@x used later in storeit
482 \edef\POL@findrat@x{\xintIrr{\xintDiv\POL@findrat@Num\POL@findrat@D}[0]}%
483 \POL@xintfrac@getNDE\POL@findrat@x\POL@findrat@xN\POL@findrat@xD\POL@_
484 \edef\POLuserpol@_findrat@oneterm{1.\noexpand\empty
485 {\xintiiOpp{\POL@findrat@xN}/1[0]}{\POL@findrat@xD/1[0]}}%
486 \POL@divide{\POL@sturmname\POL@sqfnorr}{_findrat@oneterm}% the one without mult.
487 \expandafter\POL@split\POL@R;\POL@degR\POL@polR
488 \ifnum\POL@degR=\m@ne % found a root
489 \POL@findrat@loop@storeit
490 \POL@findrat@loop@updatequotients
491 \POL@findrat@loop@getmultiplicity % will continue updating the mult. one
492 \fi
493 % iterate
494 }%
495 \def\POL@findrat@loop@storeit{%
496 % update storage, I can not use storeleftandright here (due to rawout etc...)
497 \expandafter
498 \xdef\csname POL_ZL\POL@sturmname*\POL@findrat@index\endcsname
499 {\PolDecToString{\POL@findrat@x}}%
500 \global\expandafter
501 \let\csname POL_ZR\POL@sturmname*\POL@findrat@index\expandafter\endcsname
502 \csname POL_ZL\POL@sturmname*\POL@findrat@index\endcsname
503 \global\expandafter
504 \let\csname POL_ZK\POL@sturmname*\POL@findrat@index\endcsname
505 \xint_stop_atfirstoftwo
506 \begingroup\xintglobaldefstrue
507 % skip some overhead of \xintdefvar...
508 % BUT attention to changes in xint 1.4 internal format !
509 \XINT_expr_defvar_one{\POL@sturmname L_\POL@findrat@index}%
510 {{\POL@findrat@x}}%
511 \XINT_expr_defvar_one{\POL@sturmname R_\POL@findrat@index}%
512 {{\POL@findrat@x}}%
513 \XINT_expr_defvar_one{\POL@sturmname Z_\POL@findrat@index _isknown}%
514 {{1}}%
515 \endgroup
516 }%
517 \def\POL@findrat@loop@updatequotients{%
518 % attention last division must have been one testing vanishing of\POL@sqfnorr
519 \XINT_global\expandafter\let\csname POLuserpol@\POL@sturmname\POL@sqfnorr\endcsname\POL@Q
520 % quotient belongs to Z[X] and is primitive
521 \POL@mapcoeffs\POL@aux@toint{\POL@sturmname\POL@sqfnorr}%
522 % update the one with multiplicities
523 \POL@divide{\POL@sturmname\POL@norr}{_findrat@oneterm}%
524 \XINT_global\expandafter\let\csname POLuserpol@\POL@sturmname\POL@norr\endcsname\POL@Q
525 \POL@mapcoeffs\POL@aux@toint{\POL@sturmname\POL@norr}
526 % updating of \POL@findrat@D at end of execution of getmultiplicity
527 }%
528 \def\POL@findrat@loop@getmultiplicity{%
529 % the one without multiplicity must not be divided again!
530 % check if we have remaining multiplicity
531 \POL@divide{\POL@sturmname\POL@norr}{_findrat@oneterm}%
532 \expandafter\POL@split\POL@R;\POL@degR\POL@polR
533 \ifnum\POL@degR=\m@ne % yes
534 \XINT_global\expandafter\let\csname POLuserpol@\POL@sturmname\POL@norr\endcsname\POL@Q
535 \POL@mapcoeffs\POL@aux@toint{\POL@sturmname\POL@norr}%
536 \expandafter
537 \xdef
538 \csname POL_ZM\POL@sturmname*\POL@findrat@index\endcsname
539 {\the\numexpr
540 \csname POL_ZM\POL@sturmname*\POL@findrat@index\endcsname+\@ne}%
541 \expandafter\POL@findrat@loop@getmultiplicity
542 \else
543 % done with multiplicity for this rational root, update stuff
544 \edef\POL@findrat@nbofirrroots
545 {\the\numexpr\POL@findrat@nbofirrroots-\@ne}%
546 \@namedef{POL@IfMultIsKnown\POL@findrat@index}{\xint_firstoftwo}%
547 \edef\POL@findrat@D{\xintAbs{\PolLeadingCoeff{\POL@sturmname\POL@sqfnorr}}}%
548 \POL@xintfrac@getNDE\POL@findrat@D\POL@findrat@Dint\POL@_\POL@findrat@Dexp
549 \xintiiifOne{\POL@findrat@Dint}
550 {\let\POL@findrat@E\POL@findrat@Dexp} % aussi ok pour 1[0]
551 {\edef\POL@findrat@E{\the\numexpr\xintLen{\POL@findrat@Dint}%
552 +\POL@findrat@Dexp}}%
553 \fi
554 }%
555 \def\POL@findrat@getirrmult{%
556 % first get the GCD of remaining pol with its derivative
557 \POL@divide{\POL@sturmname\POL@norr}{\POL@sturmname\POL@sqfnorr}%
558 \expandafter\let
559 \csname POLuserpol@@_1\POL@sturmname _\endcsname\POL@Q
560 \ifnum\PolDegree{@_1\POL@sturmname _}>\z@
561 \POL@makeprimitive{@_1\POL@sturmname _}%
562 \let\POL@originalsturmname\POL@sturmname
563 % trick to get isolzmult@loop to define @@lastGCD to @_1sturmname_
564 % because it will do \POL@sturmname _\POL@sturm@N _
565 \edef\POL@sturmname{@_1\POL@sturmname}%
566 \let\POL@sturm@N\@gobble% !
567 \let\POL@isolz@NbOfRoots@with_unknown_mult\POL@findrat@nbofirrroots
568 \POL@tosturm@makefirstprimitivefalse
569 \expanded{\unexpanded{%
570 \unless\ifxintveryverbose\xintverbosefalse\polnewpolverbosefalse\fi
571 \POL@isolzmult@loop
572 }\ifxintverbose\noexpand\xintverbosetrue\fi
573 \ifpolnewpolverbose\noexpand\polnewpolverbosetrue\fi}%
574 \POL@tosturm@makefirstprimitivetrue
575 \let\POL@sturmname\POL@originalsturmname
576 \fi
577 }%
578 \def\PolSturmIsolateZerosAndGetMultiplicities@{%
579 \POL@chkopt\POL@oPolSturmIsolateZerosAndGetMultiplicities@[\empty]%
580 }%
581 \def\POL@oPolSturmIsolateZerosAndGetMultiplicities@[#1]#2{%
582 % #1 optional E such that roots are searched in -10^E < x < 10^E
583 % both -10^E and +10^E must not be roots!
584 % #2 name of Sturm chain (already pre-computed)
585 \edef\POL@sturmname{#2}%
586 \edef\POL@sturm@N{\@nameuse{PolSturmChainLength_\POL@sturmname}}%
587 % isolate the roots (detects case of constant polynomial)
588 \PolSturmIsolateZeros@{\POL@sturmname}%
589 \ifnum\POL@isolz@NbOfRoots=\z@
590 % no roots, define empty array nevertheless
591 \begingroup\globaldefs\@ne
592 \expandafter\xintAssignArray\expandafter\to\csname POL_ZM\POL@sturmname*\endcsname
593 \endgroup
594 \else
595 % all we currently know is that multiplicities are at least one
596 \begingroup\globaldefs\@ne
597 \expandafter\POL@initarray\csname POL_ZM\POL@sturmname*\endcsname{1}%
598 \endgroup
599 % check if GCD had positive degree (hence some roots, maybe complex, have
600 % multiplicity)
601 \ifnum\PolDegree{\POL@sturmname _\POL@sturm@N _}>\z@
602 % scratch array of flags to signal known multiplicities
603 \POL@initarray\POL@IfMultIsKnown\xint_secondoftwo
604 % this count has utility for the case there are other roots
605 % either complex or outside interval (in case of optional argument)
606 \let\POL@isolz@NbOfRoots@with_unknown_mult\POL@isolz@NbOfRoots
607 % store Sturm chain name, it is needed and altered in isolzmult@loop
608 \let\POL@originalsturmname\POL@sturmname
609 \POL@tosturm@makefirstprimitivefalse
610 \expanded{\unexpanded{%
611 \unless\ifxintveryverbose\xintverbosefalse\polnewpolverbosefalse\fi
612 \POL@isolzmult@loop
613 }\ifxintverbose\noexpand\xintverbosetrue\fi
614 \ifpolnewpolverbose\noexpand\polnewpolverbosetrue\fi}%
615 \POL@tosturm@makefirstprimitivetrue
616 \let\POL@sturmname\POL@originalsturmname
617 \fi
618 \POL@isolzmult@defvar@M
619 \fi
620 }%
621 \def\POL@isolzmult@defvar@M{%
622 % Attention that this is used not only in ...GetMultiplicities@ but also
623 % in FindRationalRoots
624 \begingroup\xintglobaldefstrue
625 % added at 0.7
626 \let\x\POL@isolz@NbOfRoots
627 \xintloop
628 % skip some overhead of \xintdefvar...
629 % ATTENTION to xint 1.4 internal changes !
630 \XINT_expr_defvar_one{\POL@sturmname M_\x}%
631 {{\csname POL_ZM\POL@sturmname*\x\endcsname}}%
632 \edef\x{\the\numexpr\x-\@ne}%
633 \ifnum\x>\z@
634 \repeat
635 \endgroup
636 }%
637 \def\POL@isolzmult@loop{%
638 % we are here only if last iteration gave a new GCD still of degree > 0
639 % \POL@sturm@N is the one from last iteration
640 % Attention to not use \POL@sturmname directly in first arg. of \PolToSturm
641 % Attention that we need for the case of known roots also to have the last
642 % GCD (with its multiplicities) known as a genuine polynomial
643 % - because of usage of \POL@eval in @isknown branch
644 % - because \PolToSturm@ does a \POL@let which would be anomalous
645 % if the extended structure is not existing
646 \edef\POL@isolzmult@lastGCD{\POL@sturmname _\POL@sturm@N _}%
647 \edef\POL@isolzmult@newsturmname{@_1\POL@sturmname}%
648 \POL@newpol{\POL@isolzmult@lastGCD}%
649 \PolToSturm@{\POL@isolzmult@lastGCD}{\POL@isolzmult@newsturmname}%
650 % now both \POL@sturmname and \POL@sturm@N have changed
651 \edef\POL@isolzmult@newGCDdegree{\PolDegree{\POL@sturmname _\POL@sturm@N _}}%
652 \let\POL@isolzmult@index\POL@isolz@NbOfRoots
653 \xintloop
654 % ATTENTION that this executes macros which also modifies \POL@sturmname!
655 % (but not \POL@sturm@N)
656 \POL@isolzmult@doone
657 \edef\POL@isolzmult@index{\the\numexpr\POL@isolzmult@index-\@ne}%
658 \if1\ifnum\POL@isolz@NbOfRoots@with_unknown_mult=\z@ 0\fi
659 \ifnum\POL@isolzmult@index=\z@ 0\fi 1%
660 \repeat
661 \let\POL@sturmname\POL@isolzmult@newsturmname
662 \if1\ifnum\POL@isolz@NbOfRoots@with_unknown_mult=\z@ 0\fi
663 % (if new GCD is constant, time to abort)
664 \ifnum\POL@isolzmult@newGCDdegree=\z@ 0\fi 1%
665 \expandafter\POL@isolzmult@loop
666 \fi
667 }%
668 \def\POL@isolzmult@doone{%
669 \csname POL@IfMultIsKnown\POL@isolzmult@index\endcsname
670 {}% nothing to do
671 {\POL@SturmIfZeroExactlyKnown{\POL@originalsturmname}%
672 {\POL@isolzmult@index}%
673 \POL@isolzmult@loop@isknown
674 \POL@isolzmult@loop@isnotknown
675 \POL@isolzmult@loop@sharedbody
676 }%
677 }%
678 \def\POL@isolzmult@loop@isknown{%
679 \xintifZero
680 % attention that \POL@eval requires a declared polynomial
681 {\POL@eval{\POL@isolzmult@lastGCD}%
682 {\POL@xintexprGetVar{\POL@originalsturmname L_\POL@isolzmult@index}}}%
683 {\let\POL@isolzmult@haszero\@ne}%
684 {\let\POL@isolzmult@haszero\z@}%
685 }%
686 \def\POL@isolzmult@loop@isnotknown{%
687 \edef\POL@isolzmult@loop@A
688 {\POL@xintexprGetVar{\POL@originalsturmname L_\POL@isolzmult@index}}
689 \edef\POL@isolzmult@loop@B
690 {\POL@xintexprGetVar{\POL@originalsturmname
691 R_\POL@isolzmult@index}}
692 % attention that \PolSetToNbOfZerosWithin sets \POL@sturmname to 2nd argument
693 \PolSetToNbOfZerosWithin
694 \POL@isolzmult@haszero % nb of zeros A < x <= B, here 0 or 1
695 \POL@isolzmult@newsturmname
696 \POL@isolzmult@loop@A
697 \POL@isolzmult@loop@B
698 }%
699 \def\POL@isolzmult@loop@sharedbody{%
700 \ifnum\POL@isolzmult@haszero>\z@
701 \expandafter
702 \xdef
703 \csname POL_ZM\POL@originalsturmname*\POL@isolzmult@index\endcsname
704 {\the\numexpr
705 \csname POL_ZM\POL@originalsturmname
706 *\POL@isolzmult@index\endcsname+\@ne}%
707 \else
708 % multiplicity now known, no need to check this index in future
709 \@namedef{POL@IfMultIsKnown\POL@isolzmult@index}{\xint_firstoftwo}%
710 \edef\POL@isolz@NbOfRoots@with_unknown_mult
711 {\the\numexpr\POL@isolz@NbOfRoots@with_unknown_mult-\@ne}%
712 \fi
713 }%
714 \def\PolSturmIsolateZeros@{%
715 \POL@chkopt\POL@oPolSturmIsolateZeros@[\empty]%
716 }%
717 \def\POL@oPolSturmIsolateZeros@[#1]#2{%
718 % #1 optional E such that roots are searched in -10^E < x < 10^E
719 % both -10^E and +10^E must not be roots!
720 % #2 name of Sturm chain (already pre-computed from a given polynomial)
721 % For reasons I have forgotten this code **must** be used
722 % with a *normalized* Sturm chain.
723 \edef\POL@sturmname{#2}%
724 \edef\POL@sturmlength{\PolSturmChainLength{#2}}%
725 % attention to constant polynomial, we must redefine the arrays then
726 \ifnum\POL@sturmlength>\z@
727 \ifx\empty#1\relax
728 \POL@isolz@getsignchanges@plusinf
729 \POL@isolz@getsignchanges@minusinf
730 \else
731 \edef\POL@isolz@E@pos{\the\numexpr\xint_zapspaces #1 \xint_gobble_i\relax}%
732 \let\POL@isolz@E@neg\POL@isolz@E@pos
733 \POL@sturmchain@getSV@at{1[\POL@isolz@E@pos]}%
734 \let\POL@isolz@plusinf@SV \POL@sturmchain@SV
735 \let\POL@isolz@plusinf@sign\POL@sturmchain@sign
736 \POL@sturmchain@getSV@at{-1[\POL@isolz@E@neg]}%
737 \let\POL@isolz@minusinf@SV \POL@sturmchain@SV
738 \let\POL@isolz@minusinf@sign\POL@sturmchain@sign
739 \ifnum\POL@isolz@plusinf@sign=\z@
740 \PackageError{polexpr}%
741 {The polynomial #2 vanishes at set upper bound 10^\POL@isolz@E@pos}%
742 {Try again with a larger exponent. (X to abort).}%
743 \fi
744 \ifnum\POL@isolz@minusinf@sign=\z@
745 \PackageError{polexpr}%
746 {The polynomial #2 vanishes at set lower bound -10^\POL@isolz@E@neg}%
747 {Try again with a larger exponent. (X to abort).}%
748 \fi
749 \fi
750 \edef\POL@isolz@NbOfRoots
751 {\the\numexpr\POL@isolz@minusinf@SV-\POL@isolz@plusinf@SV}%
752 \else
753 % constant polynomial
754 \def\POL@isolz@NbOfRoots{0}%
755 \fi
756 \ifnum\POL@isolz@NbOfRoots=\z@
757 \begingroup\globaldefs\@ne
758 \expandafter\xintAssignArray\expandafter\to\csname POL_ZL#2*\endcsname
759 \expandafter\xintAssignArray\expandafter\to\csname POL_ZR#2*\endcsname
760 \expandafter\xintAssignArray\expandafter\to\csname POL_ZK#2*\endcsname
761 \endgroup
762 \else
763 \begingroup\globaldefs\@ne
764 \expandafter\POL@initarray\csname POL_ZL#2*\endcsname{0}%
765 \expandafter\POL@initarray\csname POL_ZR#2*\endcsname{0}%
766 \expandafter\POL@initarray\csname POL_ZK#2*\endcsname
767 \xint_stop_atsecondoftwo
768 \endgroup
769 \ifx\empty#1\relax\expandafter\POL@isolz@getaprioribound\fi
770 \expandafter\POL@isolz@main
771 \fi
772 }%
773 \def\POL@initarray#1#2{%
774 % ATTENTION, if only one item, \xintAssignArray UNBRACES IT
775 % (is this to be considered as a bug of xinttools?)
776 % We use an \empty trick to avoid that.
777 \expandafter\xintAssignArray\expandafter\empty
778 \romannumeral\xintreplicate{\POL@isolz@NbOfRoots}{{#2}}\to#1%
779 }%
780 \def\POL@isolz@getsignchanges@plusinf{%
781 % Count number of sign changes at plus infinity in Sturm sequence
782 \def\POL@isolz@plusinf@SV{0}%
783 \edef\POL@isolz@lastsign{\xintiiSgn{\PolLeadingCoeff{\POL@sturmname _0}}}%
784 \let\POL@isolz@plusinf@sign\POL@isolz@lastsign
785 \POL@count\@ne
786 \xintloop
787 \edef\POL@isolz@newsign
788 {\xintiiSgn{\PolLeadingCoeff{\POL@sturmname _\the\POL@count}}}%
789 \unless\ifnum\POL@isolz@newsign=\POL@isolz@lastsign
790 \edef\POL@isolz@plusinf@SV{\the\numexpr\POL@isolz@plusinf@SV+\@ne}%
791 \fi
792 \let\POL@isolz@lastsign=\POL@isolz@newsign
793 \ifnum\POL@sturmlength>\POL@count
794 \advance\POL@count\@ne
795 \repeat
796 }%
797 \def\POL@isolz@getsignchanges@minusinf{%
798 % Count number of sign changes at minus infinity in Sturm sequence
799 \def\POL@isolz@minusinf@SV{0}%
800 \edef\POL@isolz@lastsign{\xintiiSgn{\PolLeadingCoeff{\POL@sturmname _0}}}%
801 \ifodd\PolDegree{\POL@sturmname _0}
802 \edef\POL@isolz@lastsign{\xintiiOpp{\POL@isolz@lastsign}}%
803 \fi
804 \let\POL@isolz@minusinf@sign\POL@isolz@lastsign
805 \POL@count\@ne
806 \xintloop
807 \edef\POL@isolz@newsign
808 {\xintiiSgn{\PolLeadingCoeff{\POL@sturmname _\the\POL@count}}}%
809 \ifodd\PolDegree{\POL@sturmname _\the\POL@count}
810 \edef\POL@isolz@newsign{\xintiiOpp{\POL@isolz@newsign}}%
811 \fi
812 \unless\ifnum\POL@isolz@newsign=\POL@isolz@lastsign
813 \edef\POL@isolz@minusinf@SV{\the\numexpr\POL@isolz@minusinf@SV+\@ne}%
814 \fi
815 \let\POL@isolz@lastsign=\POL@isolz@newsign
816 \ifnum\POL@sturmlength>\POL@count
817 \advance\POL@count\@ne
818 \repeat
819 }%
820 % This utility macro bounds positive roots (strictly) by a 10^Epos
821 % and negative roots strictly by some -10^Eneg.
822 % (prior to 0.8.6, an E was found with -10^E < all roots < 10^E)
823 % To obtain Epos, the Cauchy bound "1 + max_j {-a_j/lc(P)|}"
824 % is used, where non-negative a_j/lc(P)'s are ignored.
825 % In case the a_j's all have same sign as lc(P) or vanish, there are
826 % no positive roots. And the macro in this case outputs an E=0 exponent.
827 % But if at least one non-zero a_j has opposite sign to the leading coeff,
828 % the produced E will be at least 1.
829 % Thus if E=0 on exit, it is proof that there are no (positive) roots.
830 \def\POL@isolz@updateE #1;%
831 {\unless\ifnum#1<\POL@isolz@E\space\edef\POL@isolz@E{\the\numexpr#1+\@ne}\fi}%
832 \def\POL@isolz@getaprioribound{%
833 \PolAssign{\POL@sturmname _0}\toarray\POL@arrayA
834 \edef\POL@isolz@leading{\POL@arrayA{\POL@arrayA{0}}}%
835 \POL@count\z@
836 \xintloop
837 \advance\POL@count\@ne
838 \ifnum\POL@arrayA{0}>\POL@count
839 \expandafter\edef\csname POL@arrayA\the\POL@count\endcsname
840 {\xintDiv{\POL@arrayA\POL@count}\POL@isolz@leading}%
841 \repeat
842 % We want an E such that 0 < positive roots < +10^E
843 \def\POL@isolz@E{0}%
844 \advance\POL@count\m@ne
845 \xintloop
846 \ifnum\POL@count>\z@
847 % only those coefficients with opposite sign to the leading coefficient
848 % trigger an E update
849 \xintiiifSgn{\POL@arrayA\POL@count}%
850 {\expandafter\POL@isolz@updateE
851 \the\numexpr\xintilogten{\xintAdd{1/1[0]}{\xintiiOpp{\POL@arrayA\POL@count}}};%
852 }{}{}%
853 \advance\POL@count\m@ne
854 \repeat
855 \let\POL@isolz@E@pos\POL@isolz@E
856 % We want an E such that 0 > negative roots > -10^E
857 \def\POL@isolz@E{0}%
858 \POL@count\POL@arrayA{0}\relax
859 \advance\POL@count\m@ne
860 \xintloop
861 \ifnum\POL@count>\@ne
862 \xintiiifSgn{\xintiiOpp{\POL@arrayA\POL@count}}%
863 {\expandafter\POL@isolz@updateE
864 \the\numexpr\xintilogten{\xintAdd{1/1[0]}{\POL@arrayA\POL@count}};%
865 }{}{}%
866 \advance\POL@count\m@ne
867 \xintiiifSgn{\POL@arrayA\POL@count}%
868 {\expandafter\POL@isolz@updateE
869 \the\numexpr\xintilogten{\xintAdd{1/1[0]}{\xintiiOpp{\POL@arrayA\POL@count}}};%
870 }{}{}%
871 \advance\POL@count\m@ne
872 \repeat
873 \ifnum\POL@count=\@ne
874 \xintiiifSgn{\xintiiOpp{\POL@arrayA\POL@count}}%
875 {\expandafter\POL@isolz@updateE
876 \the\numexpr\xintilogten{\xintAdd{1/1[0]}{\POL@arrayA\POL@count}};%
877 }{}{}%
878 \fi
879 \let\POL@isolz@E@neg\POL@isolz@E
880 \ifxintverbose
881 \xintMessage{polexpr}{Info}{Epos=\POL@isolz@E@pos, Eneg=\POL@isolz@E@neg.}%
882 \fi
883 }%
884 \def\POL@IsoRight@raw{\POL@IsoRight@Int/1[\POL@isolz@E]}%
885 \def\POL@IsoLeft@raw {\POL@IsoLeft@Int/1[\POL@isolz@E]}%
886 \def\POL@IsoRight@rawout{%
887 \ifnum\POL@IsoRightSign=\z@\expandafter\xintREZ\fi\POL@IsoRight@raw
888 }%
889 \def\POL@IsoLeft@rawout{%
890 \ifnum\POL@IsoRightSign=\z@
891 \expandafter\xint_firstoftwo\else\expandafter\xint_secondoftwo
892 \fi{\xintREZ\POL@IsoRight@raw}%
893 {\POL@IsoLeft@Int/1[\POL@isolz@E]}%
894 }%
895 \def\POL@isolz@main {%
896 \global\POL@isolz@nextwillneedrefinefalse
897 \def\POL@IsoRight@Int{0}%
898 \POL@sturmchain@getSV@at\POL@IsoRight@raw
899 \let\POL@IsoRightSV \POL@sturmchain@SV
900 \let\POL@IsoRightSign\POL@sturmchain@sign
901 \let\POL@IsoAtZeroSV \POL@IsoRightSV
902 \let\POL@IsoAtZeroSign\POL@IsoRightSign
903 \ifnum\POL@IsoAtZeroSign=\z@
904 \xdef\POL@isolz@IntervalIndex
905 {\the\numexpr\POL@isolz@minusinf@SV-\POL@IsoRightSV}%
906 \POL@refine@storeleftandright % store zero root, \POL@IsoRightSign is zero
907 \edef\POL@IsoRightSV{\the\numexpr\POL@IsoRightSV+\@ne}%
908 % subtlety here if original polynomial had multiplicities, but ok. I checked!
909 \edef\POL@IsoRightSign % evaluated twice, but that's not so bad
910 {\xintiiOpp{\xintiiSgn{\POL@eval{\POL@sturmname _1}{0/1[0]}}}}%
911 \fi
912 \def\POL@IsoLeft@Int{-1}% -10^E isn't a root!
913 \let\POL@IsoLeftSV \POL@isolz@minusinf@SV
914 \let\POL@IsoLeftSign\POL@isolz@minusinf@sign
915 % \POL@IsoRight@SV was modified if zero is a root
916 \edef\POL@isolz@NbOfNegRoots{\the\numexpr\POL@IsoLeftSV-\POL@IsoRightSV}%
917 \gdef\POL@isolz@IntervalIndex{0}%
918 % 0.8.6 has separate initial E's for positive and negative roots
919 \let\POL@isolz@E\POL@isolz@E@neg
920 \ifnum\POL@isolz@NbOfNegRoots>\z@
921 % refactored at 0.7 to fix cases leading to intervals having zero as end-point
922 \POL@isolz@findroots@neg
923 \fi
924 \let\POL@isolz@E\POL@isolz@E@pos
925 \def\POL@IsoLeft@Int{0}%
926 \let\POL@IsoLeftSV \POL@IsoAtZeroSV % véritable SV en zéro
927 \let\POL@IsoLeftSign\POL@IsoAtZeroSign% véritable signe en zéro
928 \ifnum\POL@IsoLeftSign=\z@
929 \xdef\POL@isolz@IntervalIndex{\the\numexpr\POL@isolz@IntervalIndex+\@ne}%
930 \fi
931 \let\POL@@IsoRightSV \POL@isolz@plusinf@SV
932 \let\POL@@IsoRightSign\POL@isolz@plusinf@sign % 10^E not a root!
933 \edef\POL@isolz@NbOfPosRoots
934 {\the\numexpr\POL@IsoLeftSV-\POL@@IsoRightSV}% attention @@
935 \ifnum\POL@isolz@NbOfPosRoots>\z@
936 % always do that to avoid zero as end-point whether it is a root or not
937 \global\POL@isolz@nextwillneedrefinetrue
938 \POL@isolz@findroots@pos
939 \fi
940 }%
941 \def\POL@isolz@findroots@neg{%
942 \def\POL@IsoRight@Int{-1}%
943 \POL@isolz@findnextzeroboundeddecade@neg
944 \def\POL@IsoLeft@Int{-10}%
945 \let\POL@@IsoRightSign\POL@IsoRightSign % a zero there is possible
946 \let\POL@@IsoRightSV \POL@IsoRightSV
947 % this will do possibly recursive \POL@isolz@check's
948 \POL@isolz@explorenexteightsubdecades@neg
949 \ifnum\POL@isolz@IntervalIndex<\POL@isolz@NbOfNegRoots\space
950 % above did not explore -2, -1 for this optimization (SV known at Right)
951 \def\POL@IsoRight@Int{-1}%
952 \let\POL@IsoRightSign\POL@@IsoRightSign
953 \let\POL@IsoRightSV \POL@@IsoRightSV
954 \POL@isolz@check
955 \ifnum\POL@isolz@IntervalIndex<\POL@isolz@NbOfNegRoots\space
956 \def\POL@IsoLeft@Int{-1}%
957 \let\POL@IsoLeftSign\POL@@IsoRightSign
958 \let\POL@IsoLeftSV \POL@@IsoRightSV
959 % I don't like being inside TeX conditionals
960 \expandafter\expandafter\expandafter\POL@isolz@findroots@neg
961 \fi
962 \fi
963 }%
964 \def\POL@isolz@findnextzeroboundeddecade@neg{%
965 \xintloop
966 \edef\POL@isolz@E{\the\numexpr\POL@isolz@E-\@ne}%
967 \POL@sturmchain@getSV@at\POL@IsoRight@raw
968 \let\POL@IsoRightSV \POL@sturmchain@SV
969 \let\POL@IsoRightSign\POL@sturmchain@sign
970 % would an \ifx test be quicker? (to be checked)
971 \ifnum\POL@IsoRightSV=\POL@IsoLeftSV\space
972 % no roots in-between, iterate
973 \repeat
974 }%
975 \def\POL@isolz@explorenexteightsubdecades@neg{%
976 \xintloop
977 \edef\POL@IsoRight@Int{\the\numexpr\POL@IsoLeft@Int+\@ne}%
978 % we could arguably do a more efficient dichotomy here
979 \POL@sturmchain@getSV@at\POL@IsoRight@raw
980 \let\POL@IsoRightSV \POL@sturmchain@SV
981 \let\POL@IsoRightSign\POL@sturmchain@sign
982 \POL@isolz@check % may recurse if multiple roots are to be found
983 \ifnum\POL@isolz@IntervalIndex=\POL@isolz@NbOfNegRoots\space
984 \expandafter\xintbreakloop
985 \fi
986 \let\POL@IsoLeft@Int\POL@IsoRight@Int
987 \let\POL@IsoLeftSign\POL@IsoRightSign
988 \let\POL@IsoLeftSV\POL@IsoRightSV
989 \ifnum\POL@IsoRight@Int < -\tw@
990 \repeat
991 }%
992 \def\POL@isolz@findroots@pos{%
993 \def\POL@IsoRight@Int{1}%
994 \POL@isolz@findnextzeroboundeddecade@pos
995 \unless\ifnum\POL@IsoRightSV=\POL@IsoLeftSV\space
996 % this actually explores the whole of some interval (0, 10^{e-1}]
997 % in a context where some roots are known to be in (10^{e-1}, 10^{e}]
998 % and none are larger
999 \POL@isolz@check % will recurse inside groups if needed with modified E
1000 \fi
1001 % we now get the roots in the last 9 decades from 10^{e-1} to 10^{e}
1002 % we should arguably do a more efficient dichotomy here
1003 \def\POL@IsoLeft@Int{1}%
1004 \let\POL@IsoLeftSV\POL@IsoRightSV
1005 \let\POL@IsoLeftSign\POL@IsoRightSign
1006 \xintloop
1007 \edef\POL@IsoRight@Int{\the\numexpr\POL@IsoLeft@Int+\@ne}%
1008 \POL@sturmchain@getSV@at\POL@IsoRight@raw
1009 \let\POL@IsoRightSV \POL@sturmchain@SV
1010 \let\POL@IsoRightSign\POL@sturmchain@sign
1011 \POL@isolz@check % recurses in needed
1012 \let\POL@IsoLeft@Int\POL@IsoRight@Int
1013 \let\POL@IsoLeftSign\POL@IsoRightSign
1014 \let\POL@IsoLeftSV\POL@IsoRightSV
1015 \ifnum\POL@isolz@IntervalIndex=\POL@isolz@NbOfRoots\space
1016 \expandafter\xintbreakloop
1017 \fi
1018 \ifnum\POL@IsoLeft@Int < \xint_c_ix
1019 \repeat
1020 \ifnum\POL@isolz@IntervalIndex<\POL@isolz@NbOfRoots\space
1021 % get now the last, rightmost, root (or roots)
1022 \def\POL@IsoRight@Int{10}%
1023 \let\POL@IsoRightSign\POL@@IsoRightSign
1024 \let\POL@IsoRightSV\POL@@IsoRightSV
1025 \POL@isolz@check
1026 \fi
1027 }%
1028 \def\POL@isolz@findnextzeroboundeddecade@pos{%
1029 \xintloop
1030 \edef\POL@isolz@E{\the\numexpr\POL@isolz@E-\@ne}%
1031 \POL@sturmchain@getSV@at\POL@IsoRight@raw
1032 \let\POL@IsoRightSV \POL@sturmchain@SV
1033 \let\POL@IsoRightSign\POL@sturmchain@sign
1034 \ifnum\POL@IsoRightSV=\POL@@IsoRightSV\space
1035 \let\POL@@IsoRightSign\POL@IsoRightSign % root here possible!
1036 \repeat
1037 }%
1038 \def\POL@isolz@check{% \POL@IsoRightSign must be ready for use here
1039 % \ifxintverbose
1040 % \xintMessage{polexpr}{Info}%
1041 % {\the\numexpr\POL@IsoLeftSV-\POL@IsoRightSV\relax\space roots
1042 % in (\POL@IsoLeft@raw,\POL@IsoRight@raw] (E = \POL@isolz@E)}%
1043 % \fi
1044 \ifcase\numexpr\POL@IsoLeftSV-\POL@IsoRightSV\relax
1045 % no root in ]left, right]
1046 \global\POL@isolz@nextwillneedrefinefalse
1047 \or
1048 % exactly one root in ]left, right]
1049 \xdef\POL@isolz@IntervalIndex{\the\numexpr\POL@isolz@IntervalIndex+\@ne}%
1050 \ifnum\POL@IsoRightSign=\z@
1051 % if right boundary is a root, ignore previous flag
1052 \global\POL@isolz@nextwillneedrefinefalse
1053 \fi
1054 % if left boundary is known to have been a root we refine interval
1055 \ifPOL@isolz@nextwillneedrefine
1056 \expandafter\expandafter\expandafter\POL@isolz@refine
1057 \else
1058 % \POL@IsoRightSign is zero iff root now exactly known
1059 \POL@refine@storeleftandright
1060 \ifnum\POL@IsoRightSign=\z@
1061 \global\POL@isolz@nextwillneedrefinetrue
1062 \fi
1063 \fi
1064 \else
1065 % more than one root, we need to recurse
1066 \expandafter\POL@isolz@recursedeeper
1067 \fi
1068 }%
1069 \def\POL@isolz@recursedeeper{%
1070 % NOTE 2018/02/16. I SHOULD DO A REAL BINARY DICHOTOMY HERE WHICH ON AVERAGE
1071 % SHOULD BRING SOME GAIN (LIKE WHAT IS ALREADY DONE FOR THE "refine" MACROS.
1072 % THUS IN FUTURE THIS MIGHT BE REFACTORED.
1073 \begingroup
1074 \edef\POL@isolz@E{\the\numexpr\POL@isolz@E-\@ne}%
1075 \edef\POL@@IsoRight@Int{\xintDSL{\POL@IsoRight@Int}}%
1076 \let\POL@@IsoRightSign \POL@IsoRightSign
1077 \let\POL@@IsoRightSV \POL@IsoRightSV
1078 \edef\POL@IsoLeft@Int {\xintDSL{\POL@IsoLeft@Int}}%
1079 \xintiloop[1+1]
1080 \edef\POL@IsoRight@Int{\xintInc{\POL@IsoLeft@Int}}%
1081 \POL@sturmchain@getSV@at\POL@IsoRight@raw
1082 \let\POL@IsoRightSV \POL@sturmchain@SV
1083 \let\POL@IsoRightSign\POL@sturmchain@sign
1084 \POL@isolz@check
1085 \let\POL@IsoLeft@Int\POL@IsoRight@Int
1086 \let\POL@IsoLeftSV\POL@IsoRightSV
1087 \let\POL@IsoLeftSign\POL@IsoRightSign% not used, actually
1088 \ifnum\POL@IsoLeftSV=\POL@@IsoRightSV\space
1089 \expandafter\xintbreakiloop
1090 \fi
1091 \ifnum\xintiloopindex < \xint_c_ix
1092 \repeat
1093 \let\POL@IsoRight@Int\POL@@IsoRight@Int
1094 \let\POL@IsoRightSign\POL@@IsoRightSign
1095 \let\POL@IsoRightSV \POL@@IsoRightSV
1096 % if we exited the loop via breakiloop this is superfluous
1097 % but it only costs one \ifnum
1098 \POL@isolz@check
1099 \endgroup
1100 }%
1101 \def\POL@isolz@refine{%
1102 % starting point is first root = left < unique second root < right
1103 % even if we hit exactly via refinement second root, we set flag false as
1104 % processing will continue with original right end-point, which isn't a root
1105 \global\POL@isolz@nextwillneedrefinefalse
1106 \begingroup
1107 \let\POL@@IsoRightSign\POL@IsoRightSign % already evaluated
1108 \xintloop
1109 \edef\POL@isolz@E{\the\numexpr\POL@isolz@E-\@ne}%
1110 \edef\POL@IsoLeft@Int {\xintDSL{\POL@IsoLeft@Int}}%
1111 \edef\POL@IsoRight@Int{\xintInc{\POL@IsoLeft@Int}}%
1112 \edef\POL@IsoRightSign
1113 {\xintiiSgn{\POL@eval{\POL@sturmname _0}{\POL@IsoRight@raw}}}%
1114 \ifnum\POL@IsoRightSign=\POL@@IsoRightSign\space
1115 \repeat
1116 % now second root has been separated from the one at left end point
1117 \edef\POL@@IsoRight@Int{\xintDSL{\xintInc{\xintDSR{\POL@IsoLeft@Int}}}}%
1118 \let\POL@IsoLeft@Int\POL@IsoRight@Int
1119 \let\POL@IsoLeftSign\POL@IsoRightSign
1120 \ifnum\POL@IsoRightSign=\z@ % check if new Left is actually a root
1121 \else
1122 \edef\POL@IsoRight@Int{\xintDec{\POL@@IsoRight@Int}}%
1123 \edef\POL@IsoRightSign
1124 {\xintiiSgn{\POL@eval{\POL@sturmname _0}{\POL@IsoRight@raw}}}%
1125 \ifnum\POL@IsoRightSign=\POL@@IsoRightSign\space
1126 \POL@refine@doonce % we need to locate in interval (1, 9) in local scale
1127 \else
1128 \let\POL@IsoLeft@Int\POL@IsoRight@Int
1129 \ifnum\POL@IsoRightSign=\z@
1130 \def\POL@IsoLeftSign{0}%
1131 \else
1132 \let\POL@IsoRight@Int\POL@@IsoRight@Int
1133 % the IsoRightSign is now wrong but here we don't care
1134 \fi\fi
1135 \fi
1136 % on exit, exact root has been found iff \POL@IsoRightSign is zero
1137 \POL@refine@storeleftandright
1138 \endgroup
1139 }%
1140 \def\POL@refine@doonce{% if exact root is found, always in IsoRight on exit
1141 % NOTE: FUTURE REFACTORING WILL GET RID OF \xintiiAdd WHICH ARE A BIT COSTLY
1142 % BUT BASICALLY NEEDED TO HANDLE BOTH NEGATIVE AND POSITIVE HERE.
1143 % I WILL RE-ORGANIZE THE WHOLE THING IN FUTURE TO GET ROOTS STARTING FROM
1144 % THE ORIGIN AND SIMPLY RE-LABEL THE NEGATIVE ONE AT THE END. 2018/02/16.
1145 \let\POL@@IsoRight@Int\POL@IsoRight@Int % 9
1146 \let\POL@@IsoRightSign\POL@IsoRightSign
1147 \edef\POL@IsoRight@Int{\xintiiAdd{4}{\POL@IsoLeft@Int}}% 5
1148 \edef\POL@IsoRightSign
1149 {\xintiiSgn{\POL@eval{\POL@sturmname _0}{\POL@IsoRight@raw}}}%
1150 \ifnum\POL@IsoRightSign=\POL@IsoLeftSign\space
1151 \let\POL@IsoLeft@Int\POL@IsoRight@Int % 5
1152 \edef\POL@IsoRight@Int{\xintiiAdd{2}{\POL@IsoLeft@Int}}%
1153 \edef\POL@IsoRightSign
1154 {\xintiiSgn{\POL@eval{\POL@sturmname _0}{\POL@IsoRight@raw}}}%
1155 \ifnum\POL@IsoRightSign=\POL@IsoLeftSign\space
1156 \let\POL@IsoLeft@Int\POL@IsoRight@Int % 7
1157 \edef\POL@IsoRight@Int{\xintInc{\POL@IsoLeft@Int}}%
1158 \edef\POL@IsoRightSign
1159 {\xintiiSgn{\POL@eval{\POL@sturmname _0}{\POL@IsoRight@raw}}}%
1160 \ifnum\POL@IsoRightSign=\POL@IsoLeftSign\space
1161 \let\POL@IsoLeft@Int\POL@IsoRight@Int % 8
1162 \let\POL@IsoRight@Int\POL@@IsoRight@Int % 9
1163 \let\POL@IsoRightSign\POL@@IsoRightSign % opposite of one at left
1164 \fi % else 7, 8 with possible root at 8
1165 \else
1166 \ifnum\POL@IsoRightSign=\z@
1167 \let\POL@IsoLeft@Int\POL@IsoRight@Int % root at 7
1168 \def\POL@IsoLeftSign{0}%
1169 \else
1170 \let\POL@@IsoRight@Int\POL@IsoRight@Int % 7
1171 \edef\POL@IsoRight@Int{\xintInc{\POL@IsoLeft@Int}}% 6
1172 \edef\POL@IsoRightSign
1173 {\xintiiSgn{\POL@eval{\POL@sturmname _0}{\POL@IsoRight@raw}}}%
1174 \ifnum\POL@IsoRightSign=\POL@IsoLeftSign\space
1175 \let\POL@IsoLeft@Int\POL@IsoRight@Int % 6
1176 \let\POL@IsoRight@Int\POL@@IsoRight@Int % 7
1177 \let\POL@IsoRightSign\POL@@IsoRightSign
1178 \fi % else 5, 6 with possible root at 6
1179 \fi\fi
1180 \else
1181 \ifnum\POL@IsoRightSign=\z@
1182 \let\POL@IsoLeft@Int\POL@IsoRight@Int % root at 5
1183 \def\POL@IsoLeftSign{0}%
1184 \else
1185 \let\POL@@IsoRight@Int\POL@IsoRight@Int % 5
1186 \edef\POL@IsoRight@Int{\xintiiAdd{2}{\POL@IsoLeft@Int}}%
1187 \edef\POL@IsoRightSign
1188 {\xintiiSgn{\POL@eval{\POL@sturmname _0}{\POL@IsoRight@raw}}}%
1189 \ifnum\POL@IsoRightSign=\POL@IsoLeftSign\space
1190 \let\POL@IsoLeft@Int\POL@IsoRight@Int % 3
1191 \edef\POL@IsoRight@Int{\xintInc{\POL@IsoLeft@Int}}% 4
1192 \edef\POL@IsoRightSign
1193 {\xintiiSgn{\POL@eval{\POL@sturmname _0}{\POL@IsoRight@raw}}}%
1194 \ifnum\POL@IsoRightSign=\POL@IsoLeftSign\space
1195 \let\POL@IsoLeft@Int\POL@IsoRight@Int % 4
1196 \let\POL@IsoRight@Int\POL@@IsoRight@Int % 5
1197 \let\POL@IsoRightSign\POL@@IsoRightSign
1198 \fi % else 3, 4 with possible root at 4
1199 \else
1200 \ifnum\POL@IsoRightSign=\z@
1201 \let\POL@IsoLeft@Int\POL@IsoRight@Int % root at 3
1202 \def\POL@IsoLeftSign{0}%
1203 \else
1204 \let\POL@@IsoRight@Int\POL@IsoRight@Int % 3
1205 \edef\POL@IsoRight@Int{\xintInc{\POL@IsoLeft@Int}}% 2
1206 \edef\POL@IsoRightSign
1207 {\xintiiSgn{\POL@eval{\POL@sturmname _0}{\POL@IsoRight@raw}}}%
1208 \ifnum\POL@IsoRightSign=\POL@IsoLeftSign\space
1209 \let\POL@IsoLeft@Int\POL@IsoRight@Int % 2
1210 \let\POL@IsoRight@Int\POL@@IsoRight@Int % 3
1211 \let\POL@IsoRightSign\POL@@IsoRightSign
1212 \fi % else 1, 2 with possible root at 2
1213 \fi\fi
1214 \fi\fi
1215 }%
1216 \def\POL@refine@storeleftandright{%
1217 \expandafter
1218 \xdef\csname POL_ZL\POL@sturmname*\POL@isolz@IntervalIndex\endcsname
1219 {\PolDecToString{\POL@IsoLeft@rawout}}%
1220 \expandafter
1221 \xdef\csname POL_ZR\POL@sturmname*\POL@isolz@IntervalIndex\endcsname
1222 {\PolDecToString{\POL@IsoRight@rawout}}%
1223 % added at 0.6
1224 \ifnum\POL@IsoRightSign=\z@
1225 \global
1226 \expandafter
1227 \let\csname POL_ZK\POL@sturmname*\POL@isolz@IntervalIndex\endcsname
1228 \xint_stop_atfirstoftwo
1229 \fi
1230 \begingroup\xintglobaldefstrue
1231 % skip some overhead of \xintdefvar...
1232 \XINT_expr_defvar_one{\POL@sturmname L_\POL@isolz@IntervalIndex}%
1233 {{\POL@IsoLeft@rawout}}%
1234 \XINT_expr_defvar_one{\POL@sturmname R_\POL@isolz@IntervalIndex}%
1235 {{\POL@IsoRight@rawout}}%
1236 % added at 0.7
1237 \XINT_expr_defvar_one{\POL@sturmname Z_\POL@isolz@IntervalIndex _isknown}%
1238 {{\ifnum\POL@IsoRightSign=\z@ 1\else 0\fi}}%
1239 \endgroup
1240 }%
1241 %% \PolRefineInterval
1242 \def\POL@xintexprGetVar#1{\expandafter\expandafter\expandafter\xint_firstofone
1243 \csname XINT_expr_varvalue_#1\endcsname}%
1244 % attention, also used by \POL@findrat@loop@a
1245 \def\POL@get@IsoLeft@rawin{%
1246 \edef\POL@IsoLeft@rawin
1247 {\POL@xintexprGetVar{\POL@sturmname L_\POL@isolz@IntervalIndex}}%
1248 }%
1249 % attention, also used by \POL@findrat@loop@a
1250 \def\POL@get@IsoRight@rawin{%
1251 \edef\POL@IsoRight@rawin
1252 {\POL@xintexprGetVar{\POL@sturmname R_\POL@isolz@IntervalIndex}}%
1253 }%
1254 % attention, also used by \POL@findrat@loop@a
1255 \def\POL@get@Int@aux #1/1[#2]#3#4{\edef#3{\xintDSH{#4-#2}{#1}}}%
1256 \def\POL@get@IsoLeft@Int{%
1257 \expandafter\POL@get@Int@aux\POL@IsoLeft@rawin\POL@IsoLeft@Int\POL@isolz@E
1258 }%
1259 \def\PolRefineInterval{\POL@ifstar\POL@srefine@start\POL@refine@start}%
1260 \def\POL@refine@start{%
1261 \POL@chkopt\POL@oPOL@refine@start[1]%
1262 }%
1263 \def\POL@oPOL@refine@start[#1]#2#3{%
1264 \edef\POL@isolz@IntervalIndex{\the\numexpr#3}%
1265 \edef\POL@sturmname{#2}%
1266 \expandafter\POL@refine@sharedbody\expandafter
1267 {\expandafter\POL@refine@loop\expandafter{\the\numexpr#1}}%
1268 }%
1269 \def\POL@srefine@start#1#2{%
1270 \edef\POL@isolz@IntervalIndex{\the\numexpr#2}%
1271 \edef\POL@sturmname{#1}%
1272 \POL@refine@sharedbody
1273 {\let\POL@refine@left@next\POL@refine@main % we want to recurse if needed
1274 \let\POL@refine@right@next\POL@refine@main % we want to recurse if needed
1275 \POL@refine@main}%
1276 }%
1277 \def\POL@refine@sharedbody#1{%
1278 \POL@get@IsoLeft@rawin
1279 \edef\POL@IsoLeftSign
1280 {\xintiiSgn{\POL@eval{\POL@sturmname _0}{\POL@IsoLeft@rawin}}}%
1281 \ifnum\POL@IsoLeftSign=\z@
1282 % do nothing if that interval was already a singleton
1283 \else
1284 % else both end-points are not roots and there is a single one in-between
1285 \POL@get@IsoRight@rawin
1286 \edef\POL@IsoRightSign{\the\numexpr-\POL@IsoLeftSign}%
1287 \edef\POL@isolz@E{\expandafter\POL@refine@getE
1288 % je pense que le xintrez ici est superflu
1289 \romannumeral0\xintrez{\xintSub{\POL@IsoRight@rawin}{\POL@IsoLeft@rawin}}}%
1290 \POL@get@IsoLeft@Int
1291 \edef\POL@IsoRight@Int{\xintInc{\POL@IsoLeft@Int}}%
1292 #1%
1293 \POL@refine@storeleftandright % \POL@IsoRightSign not zero
1294 \fi
1295 }%
1296 \def\POL@refine@loop#1{%
1297 \let\POL@refine@left@next \empty % no recursion at end sub-intervals
1298 \let\POL@refine@right@next\empty
1299 \xintiloop[1+1]
1300 \POL@refine@main
1301 \ifnum\POL@IsoRightSign=\z@
1302 \expandafter\xintbreakiloop
1303 \fi
1304 \ifnum\xintiloopindex<#1 %
1305 \repeat
1306 }%
1307 \def\POL@refine@main{%
1308 \edef\POL@isolz@E{\the\numexpr\POL@isolz@E-\@ne}%
1309 \edef\POL@IsoLeft@Int{\xintDSL{\POL@IsoLeft@Int}}%
1310 \edef\POL@IsoRight@Int{\xintDSL{\POL@IsoRight@Int}}%
1311 \let\POL@@IsoRight@Int\POL@IsoRight@Int
1312 \let\POL@@IsoRightSign\POL@IsoRightSign
1313 \edef\POL@IsoRight@Int{\xintInc{\POL@IsoLeft@Int}}%
1314 \edef\POL@IsoRightSign
1315 {\xintiiSgn{\POL@eval{\POL@sturmname _0}{\POL@IsoRight@raw}}}%
1316 \ifnum\POL@IsoRightSign=\z@
1317 \let\POL@IsoLeft@Int\POL@IsoRight@Int % root at 1
1318 \def\POL@IsoLeftSign{0}%
1319 \let\POL@next\empty
1320 \else
1321 \ifnum\POL@IsoRightSign=\POL@@IsoRightSign\space
1322 \let\POL@next\POL@refine@left@next % may be \empty or \POL@refine@main for recursion
1323 \let\POL@refine@right@next\empty
1324 \else
1325 \let\POL@IsoLeft@Int\POL@IsoRight@Int
1326 \edef\POL@IsoRight@Int{\xintDec{\POL@@IsoRight@Int}}%
1327 \edef\POL@IsoRightSign
1328 {\xintiiSgn{\POL@eval{\POL@sturmname _0}{\POL@IsoRight@raw}}}%
1329 \ifnum\POL@IsoRightSign=\z@
1330 \let\POL@IsoLeft@Int\POL@IsoRight@Int % root at 9
1331 \def\POL@IsoLeftSign{0}%
1332 \let\POL@next\empty
1333 \else
1334 \ifnum\POL@IsoRightSign=\POL@@IsoRightSign\space
1335 \let\POL@next\POL@refine@doonce
1336 \else
1337 \let\POL@IsoLeft@Int\POL@IsoRight@Int
1338 \let\POL@IsoRight@Int\POL@@IsoRight@Int
1339 \let\POL@IsoRightSign\POL@@IsoRightSign
1340 \let\POL@next\POL@refine@right@next
1341 \let\POL@refine@left@next\empty
1342 \fi
1343 \fi
1344 \fi\fi
1345 \POL@next
1346 }%
1347 % lacking pre-defined xintfrac macro here (such as an \xintRawExponent)
1348 \def\POL@refine@getE#1[#2]{#2}% \xintREZ already applied, for safety
1349 %
1350 %
1351 \def\PolIntervalWidth#1#2{%
1352 \romannumeral0\xintrez{\xintSub{\@nameuse{POL_ZR#1*}{#2}}%
1353 {\@nameuse{POL_ZL#1*}{#2}}}
1354 }%
1355 \def\PolEnsureIntervalLengths#1#2{% #1 = Sturm chain name,
1356 % localize roots in intervals of length at most 10^{#2}
1357 \edef\POL@sturmname{#1}%
1358 \edef\POL@ensure@targetE{\the\numexpr#2}%
1359 \edef\POL@nbofroots{\csname POL_ZL\POL@sturmname*0\endcsname}%
1360 \ifnum\POL@nbofroots>\z@
1361 \expandafter\POL@ensureintervallengths
1362 \fi
1363 }%
1364 \def\POL@ensureintervallengths{%
1365 \POL@count\z@
1366 % attention that \POL@count would be modified by \POL@sturmchain@getSV@at
1367 % but this latter macro not invoked by \POL@ensure@one
1368 \xintloop
1369 \advance\POL@count\@ne
1370 \edef\POL@isolz@IntervalIndex{\the\POL@count}%
1371 \POL@ensure@one
1372 \ifnum\POL@nbofroots>\POL@count
1373 \repeat
1374 }%
1375 \def\PolEnsureIntervalLength#1#2#3{% #1 = Sturm chain name,
1376 % #2 = index of interval
1377 % localize roots in intervals of length at most 10^{#3}
1378 \edef\POL@sturmname{#1}%
1379 \edef\POL@ensure@targetE{\the\numexpr#3}%
1380 \edef\POL@isolz@IntervalIndex{\the\numexpr#2}%
1381 \ifnum\POL@isolz@IntervalIndex>\z@
1382 \ifnum\csname POL_ZL\POL@sturmname*0\endcsname>\z@
1383 \POL@ensure@one
1384 \fi
1385 \fi
1386 }%
1387 \def\POL@ensure@one{%
1388 \POL@get@IsoLeft@rawin
1389 \POL@get@IsoRight@rawin
1390 \edef\POL@ensure@delta{\xintREZ{\xintSub{\POL@IsoRight@rawin}{\POL@IsoLeft@rawin}}}%
1391 \xintiiifZero{\POL@ensure@delta}
1392 {}
1393 {\edef\POL@isolz@E{\expandafter\POL@refine@getE\POL@ensure@delta}%
1394 \POL@get@IsoLeft@Int
1395 \edef\POL@IsoRight@Int{\xintInc{\POL@IsoLeft@Int}}%
1396 \ifnum\POL@isolz@E>\POL@ensure@targetE\space
1397 \edef\POL@IsoLeftSign
1398 {\xintiiSgn{\POL@eval{\POL@sturmname _0}{\POL@IsoLeft@raw}}}%
1399 % at start left and right are not roots, and values of opposite signs
1400 % \edef\POL@IsoRightSign{\the\numexpr-\POL@IsoLeftSign}%
1401 \xintloop
1402 \POL@ensure@Eloopbody % decreases E by one at each iteration
1403 % if separation level is still too coarse we recurse at deeper level
1404 \ifnum\POL@isolz@E>\POL@ensure@targetE\space
1405 \repeat
1406 % will check if right is at a zero, it needs \POL@IsoRightSign set up
1407 \POL@refine@storeleftandright
1408 \fi
1409 }%
1410 }%
1411 \def\POL@ensure@Eloopbody {%
1412 \edef\POL@isolz@E{\the\numexpr\POL@isolz@E-\@ne}%
1413 \edef\POL@IsoLeft@Int{\xintDSL{\POL@IsoLeft@Int}}%
1414 % this will loop at most ten times
1415 \xintloop
1416 \edef\POL@IsoRight@Int{\xintInc{\POL@IsoLeft@Int}}%
1417 \edef\POL@IsoRightSign
1418 {\xintiiSgn{\POL@eval{\POL@sturmname _0}{\POL@IsoRight@raw}}}%
1419 % if we have found a zero at right boundary the \ifnum test will fail
1420 % and we exit the loop
1421 % else we exit the loop if sign at right boundary is opposite of
1422 % sign at left boundary (the latter is +1 or -1, never 0)
1423 % this is a bit wasteful if we go ten times to the right, because
1424 % we know that there the sign will be opposite, evaluation was superfluous
1425 \ifnum\POL@IsoLeftSign=\POL@IsoRightSign\space
1426 \let\POL@IsoLeft@Int\POL@IsoRight@Int
1427 \repeat
1428 % check for case when we exited the inner loop because we actually
1429 % found a zero, then we force exit from the main (E decreasing) loop
1430 \ifnum\POL@IsoRightSign=\z@
1431 \expandafter\xintbreakloop
1432 \fi
1433 }%
1434 %
1435 %% \PolPrintIntervals
1436 \catcode`_ 8 %
1437 \catcode`& 4 %
1438 \def\PolPrintIntervals{\POL@ifstar{\PolPrintIntervals@@}{\PolPrintIntervals@}}%
1439 % As explained in the docs, the starred version is an example of customization
1440 % It is itself basically not easily customizable, except for this:
1441 \def\PolPrintIntervals@@arraystretch{2}% (the 2 was hardcoded prior to 0.8.6)
1442 \def\PolPrintIntervals@@{%
1443 \begingroup
1444 \def\POL@AfterPrintIntervals{\endgroup}%
1445 \let\PolPrintIntervalsPrintExactZero\POL@@PrintIntervalsPrintExactZero
1446 \let\PolPrintIntervalsUnknownRoot\POL@@PrintIntervalsUnknownRoot
1447 \let\PolPrintIntervalsKnownRoot\POL@@PrintIntervalsKnownRoot
1448 \ifdefined\array
1449 \let\arraystretch\PolPrintIntervals@@arraystretch
1450 \def\PolPrintIntervalsBeginEnv{\[\begin{array}{cl}}%\]
1451 \def\PolPrintIntervalsEndEnv{\end{array}\]}%
1452 \else
1453 \def\PolPrintIntervalsBeginEnv{$$\tabskip0pt plus 1000pt minus 1000pt
1454 \halign to\displaywidth\bgroup
1455 \hfil\vrule height \PolPrintIntervals@@arraystretch\ht\strutbox
1456 depth \PolPrintIntervals@@arraystretch\dp\strutbox
1457 width \z@
1458 $####$\tabskip6pt&$####$\hfil
1459 \tabskip0pt plus 1000pt minus 1000pt\cr}%$$
1460 \def\PolPrintIntervalsEndEnv{\crcr\egroup$$}%$$
1461 \fi
1462 \PolPrintIntervals@
1463 }%
1464 \def\PolPrintIntervals@{%
1465 \POL@chkopt\POL@oPolPrintIntervals@[Z]%
1466 }%
1467 \def\POL@oPolPrintIntervals@[#1]#2{%
1468 \def\PolPrintIntervalsTheVar{#1}%
1469 \def\PolPrintIntervalsTheSturmName{#2}%
1470 \ifnum\@nameuse{POL_ZL#2*}{0}=\z@
1471 \PolPrintIntervalsNoRealRoots
1472 \else
1473 \gdef\PolPrintIntervalsTheIndex{1}%
1474 \POL@PrintIntervals@DoDefs
1475 \begingroup\edef\POL@tmp{\endgroup
1476 \unexpanded\expandafter{\PolPrintIntervalsBeginEnv}%
1477 \unexpanded\expandafter{\POL@PrintIntervals@Loop}%
1478 % This is added at 0.8.6 to allow usage of amsmath environment as they typeset
1479 % twice: we must prepare for a second execution. Adds slight general overhead.
1480 \gdef\noexpand\PolPrintIntervalsTheIndex{1}%
1481 \noexpand\POL@PrintIntervals@DoDefs
1482 \unexpanded\expandafter{\PolPrintIntervalsEndEnv}%
1483 }\POL@tmp
1484 \fi
1485 \POL@AfterPrintIntervals
1486 \def\PolPrintIntervalsTheVar{#1}%
1487 \def\PolPrintIntervalsTheSturmName{#2}%
1488 }%
1489 \let\POL@AfterPrintIntervals\empty
1490 \let\PolPrintIntervalsNoRealRoots\empty
1491 \def\PolPrintIntervalsArrayStretch{1}% used by non-starred version
1492 \ifdefined\array
1493 \def\PolPrintIntervalsBeginEnv{\[\begin{array}{rcccl}}%
1494 \def\PolPrintIntervalsEndEnv{\end{array}\]}%
1495 \else
1496 \def\PolPrintIntervalsBeginEnv
1497 {$$\tabskip 0pt plus 1000pt minus 1000pt
1498 \halign to\displaywidth\bgroup
1499 \hfil\vrule height\PolPrintIntervalsArrayStretch\ht\strutbox
1500 depth \PolPrintIntervalsArrayStretch\dp\strutbox
1501 width \z@
1502 $##$\tabskip 6pt &\hfil $##$\hfil &\hfil $##$\hfil &\hfil $##$\hfil &$##$\hfil
1503 \tabskip 0pt plus 1000pt minus 1000pt \cr
1504 }%$$
1505 \def\PolPrintIntervalsEndEnv{\crcr\egroup$$}%$$
1506 \fi
1507 \def\PolPrintIntervalsKnownRoot{%
1508 &&\PolPrintIntervalsTheVar_{\PolPrintIntervalsTheIndex}%
1509 &=&\PolPrintIntervalsPrintExactZero
1510 }%
1511 \def\PolPrintIntervalsUnknownRoot{%
1512 \PolPrintIntervalsPrintLeftEndPoint&<&%
1513 \PolPrintIntervalsTheVar_{\PolPrintIntervalsTheIndex}&<&%
1514 \PolPrintIntervalsPrintRightEndPoint
1515 }%
1516 \def\PolPrintIntervalsPrintExactZero {\PolPrintIntervalsTheLeftEndPoint}%
1517 \def\PolPrintIntervalsPrintLeftEndPoint {\PolPrintIntervalsTheLeftEndPoint}%
1518 \def\PolPrintIntervalsPrintRightEndPoint{\PolPrintIntervalsTheRightEndPoint}%
1519 %
1520 \ifdefined\mbox
1521 \def\PolPrintIntervalsPrintMultiplicity{(\mbox{mult. }\PolPrintIntervalsTheMultiplicity)}%
1522 \else
1523 \def\PolPrintIntervalsPrintMultiplicity{(\hbox{mult. }\PolPrintIntervalsTheMultiplicity)}%
1524 \fi
1525 %
1526 \def\POL@@PrintIntervalsKnownRoot{%
1527 \PolPrintIntervalsPrintMultiplicity&%
1528 \PolPrintIntervalsTheVar_{\PolPrintIntervalsTheIndex}=%
1529 \PolPrintIntervalsPrintExactZero
1530 }%
1531 \ifdefined\frac
1532 \def\POL@@PrintIntervalsPrintExactZero{%
1533 \displaystyle
1534 \xintTeXsignedFrac{\PolPrintIntervalsTheLeftEndPoint}%
1535 }%
1536 \else
1537 \def\POL@@PrintIntervalsPrintExactZero{%
1538 \displaystyle
1539 \xintTeXsignedOver{\PolPrintIntervalsTheLeftEndPoint}%
1540 }%
1541 \fi
1542 \def\POL@@PrintIntervalsUnknownRoot{%
1543 \PolPrintIntervalsPrintMultiplicity&%
1544 \xintifSgn{\PolPrintIntervalsTheLeftEndPoint}%
1545 {\xintifSgn{\PolPrintIntervalsTheRightEndPoint}
1546 {\PolPrintIntervalsTheVar_{\PolPrintIntervalsTheIndex}=%
1547 \PolPrintIntervalsPrintRightEndPoint\dots}%
1548 {0>\PolPrintIntervalsTheVar_{\PolPrintIntervalsTheIndex}>%
1549 \PolPrintIntervalsPrintLeftEndPoint}%
1550 {\PolErrorThisShouldNotHappenPleaseReportToAuthorA}}%
1551 {\xintifSgn{\PolPrintIntervalsTheRightEndPoint}
1552 {\PolErrorThisShouldNotHappenPleaseReportToAuthorB}%
1553 {\PolErrorThisShouldNotHappenPleaseReportToAuthorC}%
1554 {0<\PolPrintIntervalsTheVar_{\PolPrintIntervalsTheIndex}<%
1555 \PolPrintIntervalsPrintRightEndPoint}}%
1556 {\xintifSgn{\PolPrintIntervalsTheRightEndPoint}
1557 {\PolErrorThisShouldNotHappenPleaseReportToAuthorD}%
1558 {\PolErrorThisShouldNotHappenPleaseReportToAuthorE}%
1559 {\PolPrintIntervalsTheVar_{\PolPrintIntervalsTheIndex}=%
1560 \PolPrintIntervalsPrintLeftEndPoint\dots}}%
1561 }%
1562 \catcode`& 7 %
1563 \catcode`_ 11 %
1564 \def\POL@PrintIntervals@Loop{%
1565 \POL@SturmIfZeroExactlyKnown\PolPrintIntervalsTheSturmName
1566 \PolPrintIntervalsTheIndex
1567 \PolPrintIntervalsKnownRoot
1568 \PolPrintIntervalsUnknownRoot
1569 \xdef\PolPrintIntervalsTheIndex{\the\numexpr\PolPrintIntervalsTheIndex+\@ne}%
1570 \unless\ifnum\PolPrintIntervalsTheIndex>
1571 \@nameuse{POL_ZL\PolPrintIntervalsTheSturmName*0}
1572 \POL@PrintIntervals@DoDefs
1573 \xint_afterfi{\PolPrintIntervalsRowSeparator\POL@PrintIntervals@Loop}%
1574 \fi
1575 }%
1576 % added at 0.8.6:
1577 \ifdefined\array
1578 \def\PolPrintIntervalsRowSeparator{\\}%
1579 \else
1580 \def\PolPrintIntervalsRowSeparator{\cr}%
1581 \fi
1582 \def\POL@PrintIntervals@DoDefs{%
1583 \xdef\PolPrintIntervalsTheLeftEndPoint{%
1584 \csname POL_ZL\PolPrintIntervalsTheSturmName*\PolPrintIntervalsTheIndex
1585 \endcsname
1586 }%
1587 \xdef\PolPrintIntervalsTheRightEndPoint{%
1588 \csname POL_ZR\PolPrintIntervalsTheSturmName*\PolPrintIntervalsTheIndex
1589 \endcsname
1590 }%
1591 \xdef\PolPrintIntervalsTheMultiplicity{%
1592 \ifcsname POL_ZM\PolPrintIntervalsTheSturmName*\PolPrintIntervalsTheIndex
1593 \endcsname
1594 \csname POL_ZM\PolPrintIntervalsTheSturmName*\PolPrintIntervalsTheIndex
1595 \endcsname
1596 \else
1597 ?% or use 0 ?
1598 \fi
1599 }%
1600 }%
1601 %
1602 %% Expandable interface
1603 %
1604 \def\PolSturmIfZeroExactlyKnown#1#2{% #1 = sturmname, #2=index
1605 \romannumeral0\csname POL_ZK#1*\endcsname{#2}%
1606 }%
1607 \def\POL@SturmIfZeroExactlyKnown#1#2{% #1 = sturmname, #2=index
1608 \romannumeral0\csname POL_ZK#1*\the\numexpr#2\endcsname
1609 }%
1610 \def\PolSturmIsolatedZeroMultiplicity#1#2{%
1611 \romannumeral`&&@\csname POL_ZM#1*\endcsname{#2}%
1612 }%
1613 \def\PolSturmIsolatedZeroLeft#1#2{%
1614 \romannumeral`&&@\csname POL_ZL#1*\endcsname{#2}%
1615 }%
1616 \def\PolSturmIsolatedZeroRight#1#2{%
1617 \romannumeral`&&@\csname POL_ZR#1*\endcsname{#2}%
1618 }%
1619 \def\PolSturmNbOfIsolatedZeros#1{%
1620 \romannumeral`&&@\csname POL_ZL#1*0\endcsname
1621 }%
1622 \def\PolSturmRationalRoot#1#2{%
1623 \romannumeral`&&@\csname POL_ZL#1*%
1624 \csname POL_RI#1*\endcsname{#2}\endcsname
1625 }%
1626 \def\PolSturmRationalRootIndex#1#2{%
1627 \romannumeral`&&@\csname POL_RI#1*\endcsname{#2}%
1628 }%
1629 \def\PolSturmRationalRootMultiplicity#1#2{%
1630 \romannumeral`&&@\csname POL_ZM#1%
1631 *\csname POL_RI#1*\endcsname{#2}\endcsname
1632 }%
1633 \def\PolSturmNbOfRationalRoots#1{%
1634 \romannumeral`&&@\csname POL_RI#1*0\endcsname
1635 }%
1636 \def\PolSturmNbOfRationalRootsWithMultiplicities#1{%
1637 % means the \POL@norr must not have been changed in-between...
1638 \the\numexpr\PolDegree{#1}-\PolDegree{#1\POL@norr}\relax
1639 }%
1640 \def\PolSturmIntervalIndex#1#2#3{\the\numexpr\POL@eval@fork
1641 #2\PolSturmIntervalIndexAt
1642 \At\PolSturmIntervalIndexAtExpr\krof {#1}{#3}%
1643 }%
1644 \def\PolSturmIntervalIndexAtExpr#1#2{%
1645 \PolSturmIntervalIndexAt{#1}{\xinttheexpr#2\relax}%
1646 }%
1647 % ! is of catcode 11 in all of polexpr
1648 \def\PolSturmIntervalIndexAt#1#2{%
1649 \expandafter\POL@sturm@index@at\romannumeral`&&@#2!{#1}\xint_bye\relax
1650 }%
1651 \def\POL@sturm@index@at#1!#2%
1652 {%
1653 \expandafter\POL@sturm@index@at@iloop
1654 \romannumeral`&&@\PolSturmNbOfIsolatedZeros{#2}!{#2}{#1}%
1655 }%
1656 % implementation is sub-optimal as it should use some kind of binary tree
1657 % search rather than comparing to the intervals from right to left as here
1658 \def\POL@sturm@index@at@iloop #1!%
1659 {%
1660 \ifnum #1=\z@ 0\expandafter\xint_bye\fi
1661 \POL@sturm@index@at@iloop@a #1!%
1662 }%
1663 \def\POL@sturm@index@at@iloop@a #1!#2#3%
1664 {% #1 = index, #2 = sturmname, #3 value
1665 \PolSturmIfZeroExactlyKnown{#2}{#1}
1666 {\xintifCmp{#3}{\POL@xintexprGetVar{#2L_#1}}%
1667 {}%
1668 {#1\xint_bye}%
1669 {0\xint_bye}%
1670 }%
1671 {\xintifGt{#3}{\POL@xintexprGetVar{#2L_#1}}%
1672 {\xintifLt{#3}{\POL@xintexprGetVar{#2R_#1}}%
1673 {#1\xint_bye}%
1674 {0\xint_bye}%
1675 }%
1676 {}%
1677 }%
1678 % attention that catcode of ! is 11 in polexpr.sty
1679 \expandafter\POL@sturm@index@at@iloop\the\numexpr#1-\@ne !{#2}{#3}%
1680 }%
1681 %
1682 \def\POL@leq@fork#1\LessThanOrEqualTo#2#3\krof{#2}%
1683 \def\PolSturmNbOfRootsOf#1#2#3{%
1684 \romannumeral`&&@\POL@leq@fork
1685 #2\PolNbOfRootsLessThanOrEqualTo
1686 \LessThanOrEqualTo\PolNbOfRootsLessThanOrEqualToExpr
1687 \krof {#1}{#3}%
1688 }%
1689 \def\PolNbOfRootsLessThanOrEqualToExpr#1#2{%
1690 \PolNbOfRootsLessThanOrEqualTo{#1}{\xinttheexpr#2\relax}%
1691 }%
1692 \def\PolNbOfRootsLessThanOrEqualTo#1{%
1693 \ifnum\PolSturmNbOfIsolatedZeros{#1}=\z@
1694 \expandafter\xint_firstofthree\expandafter0%
1695 \else
1696 \expandafter\PolNbOfRootsLessThanOrEqualTo@%
1697 \fi {#1}%
1698 }%
1699 \def\PolNbOfRootsLessThanOrEqualTo@ #1#2%
1700 {%
1701 \expandafter\POL@nbofrootsleq@prep\romannumeral`&&@#2!{#1}%
1702 }%
1703 \def\POL@nbofrootsleq@prep#1!#2%
1704 {%
1705 \expandafter\POL@nbofrootsleq@iloop\expandafter 1\expandafter !%
1706 \romannumeral0\xintsgn{\POL@eval{#2_0}{#1}}!%
1707 #1!{#2}%
1708 }%
1709 \def\POL@nbofrootsleq@iloop#1!#2!#3!#4%
1710 {% #1 = index, #2 = sign of evaluation at value, #3 = value, #4 = sturmname
1711 \xintifCmp{#3}{\POL@xintexprGetVar{#4L_#1}}%
1712 {\POL@nbofrootsleq@return #1-\@ne !}%
1713 {\POL@nbofrootsleq@return
1714 \PolSturmIfZeroExactlyKnown{#4}{#1}{#1}{#1-\@ne}!%
1715 }%
1716 % in third branch we are sure that if root is exactly known
1717 % the test \xintifLt will be negative
1718 {\xintifLt{#3}{\POL@xintexprGetVar{#4R_#1}}%
1719 {\POL@nbofrootsleq@return
1720 #1\ifnum#2=\xintSgn{\POL@eval{#4_0}{\POL@xintexprGetVar{#4L_#1}}}
1721 -\@ne\fi !%
1722 }%
1723 {\ifnum#1=\PolSturmNbOfIsolatedZeros{#4}
1724 \expandafter\POL@nbofrootsleq@rightmost
1725 \fi \expandafter\POL@nbofrootsleq@iloop \the\numexpr\@ne+%
1726 }%
1727 }%
1728 #1!#2!#3!{#4}%
1729 }%
1730 \def\POL@nbofrootsleq@return #1!#2!#3!#4!#5{\the\numexpr #1\relax}%
1731 \def\POL@nbofrootsleq@rightmost\expandafter\POL@nbofrootsleq@iloop
1732 \the\numexpr\@ne+#1!#2!#3!#4{#1}%
1733 %
1734 \def\PolSturmNbWithMultOfRootsOf#1#2#3{%
1735 \the\numexpr0\POL@leq@fork
1736 #2\PolNbWithMultOfRootsLessThanOrEqualTo
1737 \LessThanOrEqualTo\PolNbWithMultOfRootsLessThanOrEqualToExpr\krof {#1}{#3}%
1738 }%
1739 \def\PolNbWithMultOfRootsLessThanOrEqualToExpr#1#2{%
1740 \PolNbWithMultOfRootsLessThanOrEqualTo{#1}{\xinttheexpr#2\relax}%
1741 }%
1742 \def\PolNbWithMultOfRootsLessThanOrEqualTo#1{%
1743 \ifnum\PolSturmNbOfIsolatedZeros{#1}=\z@
1744 \expandafter\POL@nbwmofroots@noroots
1745 \else
1746 \expandafter\PolNbWithMultOfRootsLessThanOrEqualTo@%
1747 \fi {#1}%
1748 }%
1749 \def\POL@nbwmofroots@noroots#1#2{\relax}%
1750 \def\PolNbWithMultOfRootsLessThanOrEqualTo@ #1#2%
1751 {%
1752 \expandafter\POL@nbwmofrootsleq@prep\romannumeral`&&@#2!{#1}%
1753 }%
1754 \def\POL@nbwmofrootsleq@prep#1!#2%
1755 {%
1756 \expandafter\POL@nbwmofrootsleq@iloop\expandafter 1\expandafter !%
1757 \romannumeral0\xintsgn{\POL@eval{#2_0}{#1}}!%
1758 #1!{#2}%
1759 }%
1760 \def\POL@nbwmofrootsleq@iloop#1!#2!#3!#4%
1761 {% #1 = index, #2 = sign of evaluation at value, #3 = value, #4 = sturmname
1762 \xintifCmp{#3}{\POL@xintexprGetVar{#4L_#1}}%
1763 {\POL@nbwmofrootsleq@return !}%
1764 {\POL@nbwmofrootsleq@return
1765 \PolSturmIfZeroExactlyKnown{#4}{#1}%
1766 {+\PolSturmIsolatedZeroMultiplicity{#4}{#1}}{}!%
1767 }%
1768 % in third branch we are sure that if root is exactly known
1769 % the test \xintifLt will be negative
1770 {\xintifLt{#3}{\POL@xintexprGetVar{#4R_#1}}%
1771 {\POL@nbwmofrootsleq@return
1772 \unless
1773 \ifnum#2=\xintSgn{\POL@eval{#4_0}{\POL@xintexprGetVar{#4L_#1}}}
1774 +\PolSturmIsolatedZeroMultiplicity{#4}{#1}\fi !%
1775 }%
1776 {+\PolSturmIsolatedZeroMultiplicity{#4}{#1}%
1777 \ifnum#1=\PolSturmNbOfIsolatedZeros{#4}
1778 \expandafter\POL@nbwmofrootsleq@return\expandafter !%
1779 \fi
1780 \expandafter\POL@nbwmofrootsleq@iloop \the\numexpr\@ne+%
1781 }%
1782 }%
1783 #1!#2!#3!{#4}%
1784 }%
1785 \def\POL@nbwmofrootsleq@return #1!#2!#3!#4!#5{#1\relax}%
1786 \endinput