Debian Codegraph @

texmf-dist/doc/generic/polexpr/polexpr-ref.rst.txt

raw
1 .. comment: -*- fill-column: 72; mode: rst -*-
2
3 ===================
4 polexpr reference
5 ===================
6
7 .. _quick:
8
9 Syntax overview via examples
10 ----------------------------
11
12 The syntax to define a new polynomial is::
13
14 \poldef polname(x):= expression in variable x;
15
16 ..
17
18 The expression will be parsed by the services of xintexpr_, with some
19 polynomial aware functions added to its syntax; they are described in
20 detail :ref:`below <polexpr08>`. The parser accepts and will handle
21 exactly arbitrarily big integers or fractions.
22
23 .. note::
24
25 xintexpr_ does not automatically reduce fractions to lowest terms,
26 and, so far (but this may change in future) neither does :ref:`\\poldef
27 <poldef;>`.
28 See :ref:`rdcoeffs() <rdcoeffs>` and the macro
29 :ref:`\\PolReduceCoeffs <PolReduceCoeffs>`.
30
31
32 - In place of ``x`` an arbitrary *dummy variable* is authorized,
33 i.e. per default one ``a, .., z, A, .., Z`` (more letters can be declared
34 under Unicode engines).
35
36 - ``polname`` is a word (no space) built with *letters*, *digits*, and
37 the ``@``, ``_`` and ``'`` characters are allowed. The polynomial
38 name **must** start with a letter.
39
40 For guidelines regarding ``_`` and ``@`` see Technicalities_.
41
42 - The colon before the equality sign is optional and its (reasonable)
43 catcode does not matter.
44
45 - The semi-colon at the end of the expression is mandatory. It is not
46 allowed to arise from expansion (despite the fact that the expression
47 itself will be parsed using only expansion), it must be "visible"
48 immediately.
49
50 There are some potential problems (refer to the Technicalities_ section at
51 bottom of this page) with the semi-colon as expression terminator, so an
52 alternative syntax is provided, which avoids it altogether::
53
54 \PolDef[optional letter]{<polname>}{<expr. using letter as indeterminate>}
55
56 The ``\PolDef`` optional first argument defaults to ``x`` and must be
57 used as the indeterminate in the expression.
58
59 Examples:
60
61 ``\poldef f(x):= 1 - x + quo(x^5,1 - x + x^2);``
62
63 ``\PolDef{f}{1 - x + quo(x^5,1 - x + x^2)}``
64 Both parse the polynomial
65 expression, and they create internally macros serving to
66 incarnate the polynomial, its coefficients, and the associated
67 polynomial function.
68
69 The polynomial can then be used in further polynomial definitions,
70 be served as argument to package macros, or appear as a variable in
71 various functions `described later <polexpr08_>`_.
72
73 .. warning::
74
75 Both the function ``quo()`` (as shown in the example above), and
76 the infix operator ``/`` are mapped to the Euclidean quotient.
77
78 This usage of ``/`` to stand for the Euclidean quotient is
79 **deprecated** and reserved for a (somewhat improbable) possible
80 extension of the package to handle rational functions as well.
81
82 .. _warningtacit:
83
84 .. attention::
85
86 Tacit multiplication rules let the parser when encountering
87 ``1/2 x^2`` skip the space and thus handle it as ``1/(2*x^2)``.
88 But then it gives zero, because `/` stands for the Euclidean
89 quotient operation here.
90
91 Thus one must use ``(1/2)x^2`` or ``1/2*x^2`` or
92 ``(1/2)*x^2`` for disambiguation: ``x - 1/2*x^2 + 1/3*x^3...``. It is
93 simpler to move the denominator to the right: ``x - x^2/2 +
94 x^3/3 - ...``.
95
96 It is worth noting that ``1/2(x-1)(x-2)`` suffers the same issue:
97 xintexpr_\ 's tacit multiplication always "ties more", hence this
98 gets interpreted as ``1/(2*(x-1)*(x-2))`` not as
99 ``(1/2)*(x-1)*(x-2)`` and then gives zero by
100 polynomial division. Thus, in such cases, use one of
101 ``(1/2)(x-1)(x-2)``, ``1/2*(x-1)(x-2)`` or ``(x-1)(x-2)/2``.
102
103 ``\poldef P(x):=...;`` defines ``P`` as a *polynomial function*,
104 which can be used inside ``\xinteval``, as::
105
106 \xinteval{P(3 + 7 + 11)}
107
108 or even as::
109
110 \xinteval{P(Q1 + Q2 + Q3)}
111
112 where ``Q1``, ``Q2``, ``Q3`` are polynomials. The evaluation result,
113 if not a scalar, will then be printed as ``pol([c0,c1,...])`` which
114 stands for a polynomial variable having the listed coefficients; see
115 :ref:`pol() <pol>`.
116
117 Indeed, as seen above with ``Q1``, the symbol ``P`` also stands for
118 a *variable of polynomial type*, which serves as argument to
119 polynomial specific functions such as :ref:`deg() <deg>` or
120 :ref:`polgcd() <polgcd>`, or as argument to other polynomials (as
121 above), or even simply stands for its own in algebraic expressions
122 such as::
123
124 \poldef Q(z):= P^2 + z^10;
125
126 Notice that in the above, the ``(z)`` part is mandatory, as it informs
127 ``\poldef`` of the letter used for the indeterminate. In the above
128 ``P(z)^2`` would give the same as ``P^2`` but the latter is slightly
129 more efficient.
130
131 One needs to acquire a good understanding of when the symbol ``P``
132 will stand for a function and when it will stand for a variable.
133
134 - If ``P`` and
135 ``Q`` are both declared polynomials then::
136
137 (P+Q)(3)% <--- attention, does (P+Q)*3, not P(3)+Q(3)
138
139 is currently evaluated as ``(P+Q)*3``, because ``P+Q`` is not
140 known as a *function*, but *only as a variable of polynomial
141 type*. Note that :ref:`evalp(P+Q,3) <evalp>` gives as expected
142 the same as ``P(3)+Q(3)``.
143
144 - Also::
145
146 (P)(3)% <--- attention, does P*3, not P(3)
147
148 will compute ``P*3``, because one can not in current xintexpr_ syntax
149 enclose a function name in parentheses: consequently it is the variable
150 which is used here.
151
152 There is a *meager possibility* that in future some internal changes
153 to xintexpr_ would let ``(P)(3)`` actually compute ``P(3)`` and
154 ``(P+Q)(3)`` compute ``P(3) + Q(3)``, but note that ``(P)(P)`` will
155 then do ``P(P)`` and not ``P*P``, the latter, current
156 interpretation, looking more intuitive. Anyway, do not rely too
157 extensively on tacit ``*`` and use explicit ``(P+Q)*(1+2)`` if this
158 is what is intended.
159
160
161 ``\PolLet{g}={f}``
162 saves a copy of ``f`` under name ``g``. Also usable without ``=``.
163
164 Has exactly the same effect as ``\poldef g(x):=f;`` or ``\poldef
165 g(w):=f(w);``\ .
166
167 ``\poldef f(z):= f^2;``
168 redefines ``f`` in terms of itself. Prior to ``0.8`` one needed
169 the right hand side to be ``f(z)^2``. Also, now ``sqr(f)`` is
170 possible (also ``sqr(f(x))`` but not ``sqr(f)(x)``).
171
172 It may look strange that an indeterminate variable is used on
173 left-hand-side even though it may be absent of right-hand-side, as
174 it seems to define ``f`` always as a polynomial function.
175
176 This is a legacy of pre-``0.8`` context.
177
178 .. important::
179
180 Note that ``f^2(z)`` or ``sqr(f)(z)`` will give a logical but
181 perhaps unexpected result: first ``f^2`` is computed, then the
182 opening parenthesis is seen which inserts a tacit multiplication
183 ``*``, so in the end it is as if the input had been ``f^2 * z``.
184 Although ``f`` is both a variable and a function, ``f^2`` is
185 computed as a polynomial *variable* and ceases being a function.
186
187 ``\poldef f(T):= f(f);``
188 again modifies ``f``. Here it is used both as variable and as
189 a function. Prior to ``0.8`` it needed to be ``f(f(T))``.
190
191 ``\poldef k(z):= f-g(g^2)^2;``
192 if everybody followed, this should now define the zero polynomial...
193 And ``f-sqr(g(sqr(g)))`` computes the same thing.
194
195 We can check this in a typeset document like this::
196
197 \poldef f(x):= 1 - x + quo(x^5,1 - x + x^2);%
198 \PolLet{g}={f}%
199 \poldef f(z):= f^2;%
200 \poldef f(T):= f(f);%
201 \poldef k(w):= f-sqr(g(sqr(g)));%
202 $$f(x) = \vcenter{\hsize10cm \PolTypeset{f}} $$
203 $$g(z) = \PolTypeset{g} $$
204 $$k(z) = \PolTypeset{k} $$
205 \immediate\write128{f(x)=\PolToExpr{f}}% ah, here we see it also
206
207 ``\poldef f'(x):= diff1(f);``
208 (new at ``0.8``)
209
210 ``\PolDiff{f}{f'}``
211 Both set ``f'`` (or any other chosen name) to the derivative
212 of ``f``.
213
214 .. important::
215
216 This is not done automatically. If some new definition needs to use
217 the derivative of some available polynomial, that derivative
218 polynomial must have been previously defined: something such as
219 ``f'(3)^2`` will not work without a prior definition of ``f'``.
220
221 But one can now use ``diff1(f)`` for on-the-spot construction with no
222 permanent declaration, so here ``evalp(diff1(f),3)^2``. And
223 ``diff1(f)^2`` is same as ``f'^2``, assuming here ``f'`` was declared
224 to be the derived polynomial.
225
226 Notice that the name ``diff1()`` is experimental and may change. Use
227 ``\PolDiff{f}{f'}`` as the stable interface.
228
229 ``\PolTypeset{P}``
230 Typesets (switching to math mode if in text mode)::
231
232 \poldef f(x):=(3+x)^5;%
233 \PolDiff{f}{f'}\PolDiff{f'}{f''}\PolDiff{f''}{f'''}%
234 $$f(z) = \PolTypeset[z]{f} $$
235 $$f'(z) = \PolTypeset[z]{f'} $$
236 $$f''(z) = \PolTypeset[z]{f''} $$
237 $$f'''(z)= \PolTypeset[z]{f'''} $$
238
239 See `its documentation <PolTypeset_>`_ for the configurability
240 via macros.
241
242 Since ``0.8`` `\\PolTypeset <PolTypeset_>`_ accepts directly an
243 expression, it does not have to be a pre-declared polynomial name::
244
245 \PolTypeset{mul(x-i,i=1..5)}
246
247 ``\PolToExpr{P}``
248 Expandably (contrarily to `\\PolTypeset <PolTypeset_>`_)
249 produces ``c_n*x^n + ... + c_0`` starting from the leading
250 coefficient. The ``+`` signs are omitted if followed by negative
251 coefficients.
252
253 This is useful for console or file output. This syntax is Maple and
254 PSTricks ``\psplot[algebraic]`` compatible; and also it is
255 compatible with ``\poldef`` input syntax, of course. See
256 `\\PolToExprCaret`_ for configuration of the ``^``, for example to
257 use rather ``**`` for Python syntax compliance.
258
259 Changed at ``0.8``: the ``^`` in output is by default of catcode 12
260 so in a draft document one can use ``\PolToExpr{P}`` inside the
261 typesetting flow (without requiring math mode, where the ``*`` would
262 be funny and ``^12`` would only put the ``1`` as exponent anyhow;
263 but arguably in text mode the ``+`` and ``-`` are not satisfactory
264 for math, except sometimes in monospace typeface, and anyhow TeX is
265 unable to break the expression across lines, barring special help).
266
267 See :ref:`\\PolToExpr{\<pol. expr.\>} <PolToExpr>` and related macros for customization.
268
269 Extended at ``0.8`` to accept as argument not only the name of a
270 polynomial variable but more generally any polynomial expression.
271
272
273 Using defined polynomials in floating point context
274 ---------------------------------------------------
275
276 Exact manipulations with fractional coefficients may quickly lead to
277 very large denominators. For numerical evaluations, it is advisable
278 to a use a floating point context. But for the polynomial to be
279 usable as a function in floating point context, an extra step beyond
280 ``\poldef`` is required: see `\\PolGenFloatVariant`_. Then the
281 ``\xintfloateval`` macro from xintexpr_ will recognize the polynomial
282 as a genuine function (with already float-rounded coefficients, and
283 using a Horner scheme).
284
285 But `\\PolGenFloatVariant`_ must be used each time the polynomial gets
286 redefined or a new polynomial is created out of it. Functions such as
287 for example :ref:`deg() <deg>` which handle the polynomial as an entity
288 are only available within the ``\poldef`` and ``\xinteval`` (or
289 ``\xintexpr``) parsers. Inside ``\xintfloateval`` a polynomial can only
290 serve as a numerical function (and only after declaration via
291 `\\PolGenFloatVariant`_), and not as a variable.
292
293 In some cases one may wish to replace a polynomial having acquired
294 very big fractional coefficients with a new one whose coefficients
295 have been float-rounded. See :ref:`\\PolMapCoeffs <PolMapCoeffs>`
296 which can be used for example with the ``\xintFloat`` macro from the
297 xintfrac_ package to achieve this.
298
299
300 .. _polexpr08:
301
302 The polexpr ``0.8`` extensions to the ``\xintexpr`` syntax
303 ----------------------------------------------------------
304
305 All the syntax elements described in this section can be used in the
306 ``\xintexpr/\xinteval`` context (where polynomials can be obtained from
307 the ``pol([])`` constructor, once polexpr is loaded): their usage is
308 not limited to only ``\poldef`` context.
309
310 .. note::
311
312 If a variable ``myPol`` defined via ``\xintdefvar`` turns out
313 to be a polynomial, the difference with those declared via ``\poldef``
314 will be:
315
316 1. ``myPol`` is not usable as *function*, but only as a variable.
317 Attention that ``f(x)`` if ``f`` is only a variable (even a
318 polynomial one) will actually compute ``f * x``.
319
320 2. ``myPol`` is not known to the polexpr package, hence for example the
321 macros to achieve localization of its roots are unavailable.
322
323 In a parallel universe I perhaps have implemented this expandably
324 which means it could then be accessible with syntax such as
325 ``rightmostroot(pol([42,1,34,2,-8,1]))`` but...
326
327
328 Warning about unstability of the new syntax
329 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
330
331 .. warning::
332
333 Consider the entirety of this section as **UNSTABLE** and
334 **EXPERIMENTAL** (except perhaps regarding ``+``, ``-`` and ``*``).
335
336 And this applies even to items not explicitly flagged with one of
337 **unstable**, **Unstable**, or **UNSTABLE** which only reflect that
338 documentation was written over a period of time exceeding one minute,
339 enough for the author mood changes to kick in.
340
341 It is hard to find good names at the start of a life-long extension
342 program of functionalities, and perhaps in future it will be
343 preferred to rename everything or give to some functions other
344 meanings. Such quasi-complete renamings happened already a few times
345 during the week devoted to development.
346
347
348 Infix operators ``+, -, *, /, **, ^``
349 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
350
351 As has been explained in the `Syntax overview via examples`_
352 section these infix operators have been made polynomial aware, not
353 only in the ``\poldef`` context, but generally in any
354 ``\xintexpr/\xinteval`` context, inclusive of ``\xintdeffunc``.
355
356 Conversely functions declared via ``\xintdeffunc`` and making use of
357 these operators will automatically be able to accept polynomials
358 declared from ``\poldef`` as variables.
359
360 Usage of ``/`` for euclidean division of polynomials is **deprecated**.
361 Only in case of a scalar denominator is it to be considered stable.
362 Please use rather ``quo()``.
363
364 Experimental infix operators ``//, /:``
365 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
366
367 Here is the tentative behaviour of ``A//B`` according to types:
368
369 - ``A`` non scalar and ``B`` non scalar: euclidean quotient,
370
371 - ``A`` scalar and ``B`` scalar: floored division,
372
373 - ``A`` scalar and ``B`` non scalar: produces zero,
374
375 - ``A`` non scalar and ``B`` scalar: coefficient per
376 coefficient floored division.
377
378 This is an **experimental** overloading of the ``//`` and ``/:``
379 from ``\xintexpr``.
380
381 The behaviour in the last case, but not only, is to be considerd
382 **unstable**. The alternative would be for ``A//B`` with ``B``
383 scalar to act as ``quo(A,B)``. But, we have currently chosen to let
384 ``//B`` for a scalar ``B`` act coefficient-wise on the numerator.
385 Beware that it thus means it can be employed with the idea of doing
386 euclidean division only by checking that ``B`` is non-scalar.
387
388 The ``/:`` operator provides the associated remainder so always
389 ``A`` is reconstructed from ``(A//B)*B + A/:B``.
390
391 If ``:`` is active character use ``/\string:`` (it is safer to use
392 ``/\string :`` if it is not known if ``:`` has catcode other, letter,
393 or is active, but note that ``/:`` is fine and needs no precaution if
394 ``:`` has catcode letter, it is only an active ``:`` which is
395 problematic, like for all other characters possibly used in an
396 expression).
397
398 **UNSTABLE**
399
400 As explained above, there are (among other things) hesitations
401 about behaviour with ``pol2`` a scalar.
402
403 Comparison operators ``<, >, <=, >=, ==, !=``
404 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
405
406 **NOT YET IMPLEMENTED**
407
408 As the internal representation by xintfrac_ and xintexpr_ of
409 fractions does not currently require them to be in reduced terms,
410 such operations would be a bit costly as they could not benefit from
411 the ``\pdfstrcmp`` engine primitive. In fact xintexpr_ does not use
412 it yet anywhere, even for normalized pure integers, although it could
413 speed up signifcantly certain aspects of core arithmetic.
414
415 Equality of polynomials can currently be tested by computing the
416 difference, which is a bit costly. And of course the ``deg()``
417 function allows comparing degrees. In this context note the
418 following syntax::
419
420 (deg(Q)) ?? { zero } { non-zero scalar } { non-scalar }
421
422 for branching.
423
424
425 .. _pol:
426
427 ``pol(<nutple expression>)``
428 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
429
430 This converts a nutple ``[c0,c1,...,cN]`` into the polynomial
431 variable having these coefficients. Attention that the square
432 brackets are **mandatory**, except of course if the argument is
433 actually an expression producing such a "nutple".
434
435 Currently, this process will not normalize the coefficients (such
436 as reducing to lowest terms), it only trims out the leading zero
437 coefficients.
438
439 Inside ``\xintexpr``, this is the only (allowed) way to create ex
440 nihilo a polynomial variable; inside ``\poldef`` it is an alternative
441 input syntax which is more efficient than the input ``c0 + c1 * x + c2 *
442 x^2 + ...``.
443
444 .. important::
445
446 Whenever an expression with polynomials collapses to a constant, it
447 becomes a scalar. There is currently no distinction during the
448 parsing of expressions by ``\poldef``
449 or ``\xintexpr`` between constant polynomial variables and scalar
450 variables.
451
452 Naturally, ``\poldef`` can be used to declare a constant polynomial
453 ``P``, then ``P`` can also be used as function having a value
454 independent of argument, but as a variable, it is non-distinguishable
455 from a scalar (of course functions such as ``deg()`` tacitly
456 consider scalars to be constant polynomials).
457
458 Notice that we tend to use the vocable "variable" to refer to
459 arbitrary expressions used as function arguments, without implying
460 that we are actually referring to pre-declared variables in the sense
461 of ``\xintdefvar``.
462
463 .. _lpol:
464
465 ``lpol(<nutple expression>)``
466 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
467
468 This converts a nutple ``[cN,...,c1,c0]`` into the polynomial
469 variable having these coefficients, with leading coefficients coming
470 first in the input. Attention that the square brackets are
471 **mandatory**, except of course if the argument is actually an
472 expression producing such a "nutple".
473
474 Currently, this process will not normalize the coefficients (such
475 as reducing to lowest terms), it only trims out the leading zero
476 coefficients.
477
478 **NAME UNSTABLE**
479
480 It can be used in ``\poldef`` as an alternative input syntax, which
481 is more efficient than using the algebraic notation with monomials.
482
483 (new with ``0.8.1``, an empty nutple will cause breakage)
484
485 .. _xintevalpolexpr:
486
487 ``\xinteval{<pol. expr.>}``
488 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
489
490 This is documented here for lack of a better place: it evaluates the
491 polynomial expression then outputs the "string" ``pol([c0, c1, ..., cN])``
492 if the degree ``N`` is at least one (and the usual scalar output else).
493
494 The "pol" word uses letter catcodes, which is actually mandatory for
495 this output to be usable as input, but it does not make sense to use
496 this inside ``\poldef`` or ``\xintexpr`` at it means basically
497 executing ``pol(coeffs(..expression..))`` which is but a convoluted
498 way to obtain the same result as ``(..expression..)`` (the
499 parentheses delimiting the polynomial expression).
500
501 For example, ``\xinteval{(1+pol([0,1]))^10}`` expands (in two steps)
502 to::
503
504 pol([1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1])
505
506 You do need loading polexpr for this, else of course ``pol([])``
507 remains unknown to ``\xinteval{}`` as well as the polynomial algebra !
508 This example can also be done as
509 ``\xinteval{subs((1+x)^10,x=pol([0,1]))}``.
510
511 I hesitated using as output the polynomial notation as produced by
512 `\\PolToExpr{} <poltoexpr_>`_, but finally opted for this.
513
514 .. _evalp:
515
516 ``evalp(<pol. expr.>, <pol. expr>)``
517 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
518
519 Evaluates the first argument as a polynomial function of the
520 second. Usually the second argument will be scalar, but this is not
521 required::
522
523 \poldef K(x):= evalp(-3x^3-5x+1,-27x^4+5x-2);
524
525 If the first argument is an already declared polynomial ``P``, use
526 rather the functional form ``P()`` (which can accept a numerical as
527 well as polynomial argument) as it is more efficient.
528
529 One can also use ``subs()`` syntax [#]_ (see xintexpr_ documentation)::
530
531 \poldef K(x):= subs(-3y^3-5y+1, y = -27x^4+5x-2);
532
533 but the ``evalp()`` will use a Horner evaluation scheme which is
534 usually more efficient.
535
536 .. [#] by the way Maple uses the opposite, hence wrong, order
537 ``subs(x=..., P)`` but was written before computer science
538 reached the xintexpr_ heights. However it makes validating
539 Maple results by polexpr sometimes cumbersome, but perhaps
540 they will update it at some point.
541
542 ..
543
544 **name unstable**
545
546 ``poleval``? ``evalpol``? ``peval``? ``evalp``? ``value``?
547 ``eval``? ``evalat``? ``eval1at2``? ``evalat2nd``?
548
549 Life is so complicated when one asks questions. Not everybody does,
550 though, as is amply demonstrated these days.
551
552 **syntax unstable**
553
554 I am hesitating about permuting the order of the arguments.
555
556 .. _deg:
557
558 ``deg(<pol. expr.>)``
559 ~~~~~~~~~~~~~~~~~~~~~
560
561 Computes the degree.
562
563 .. important::
564
565 As ``\xintexpr`` does not yet support infinities, the degree of
566 the zero polynomial is ``-1``. Beware that this breaks additivity
567 of degrees, but ``deg(P)<0`` correctly detects the zero polynomial,
568 and ``deg(P)<=0`` detects scalars.
569
570 ``coeffs(<pol. expr.>)``
571 ~~~~~~~~~~~~~~~~~~~~~~~~
572
573 Produces the nutple ``[c0,c1,...,cN]`` of coefficients. The highest
574 degree coefficient is always non zero (except for the zero
575 polynomial...).
576
577 **name unstable**
578
579 I am considering in particular using ``polcoeffs()`` to avoid
580 having to overload ``coeffs()`` in future when matrix type
581 will be added to xintexpr_.
582
583 .. _lcoeffs:
584
585 ``lcoeffs(<pol. expr.>)``
586 ~~~~~~~~~~~~~~~~~~~~~~~~~
587
588 Produces the nutple ``[cN,....,c1,c0]`` of coefficients, starting
589 with the highest degree coefficient.
590
591 (new with ``0.8.1``)
592
593 ``coeff(<pol. expr.>, <num. expr.>)``
594 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
595
596 As expected. Produces zero if the numerical index is negative or
597 higher than the degree.
598
599 **name, syntax and output unstable**
600
601 I am hesitating with ``coeff(n,pol)`` syntax and also perhaps using
602 ``polcoeff()`` in order to avoid having to overload ``coeff()``
603 when matrix type will be added to xintexpr_.
604
605 The current behaviour is at odds with legacy
606 :ref:`\\PolNthCoeff{\<polname\>}{\<index\>} <PolNthCoeff>` regarding negative indices.
607 Accessing leading or sub-leading coefficients can be done with
608 other syntax, see `lc(<pol. expr.>)`_, and in some contexts it
609 is useful to be able to rely on the fact that coefficients with
610 negative indices do vanish, so I am for time being maintaining this.
611
612 .. _lc:
613
614 ``lc(<pol. expr.>)``
615 ~~~~~~~~~~~~~~~~~~~~
616
617 The leading coefficient. The same result can be obtained from
618 ``coeffs(pol)[-1]``, which shows also how to generalize to access
619 sub-leading coefficients. See the xintexpr_ documentation for
620 Python-like indexing syntax.
621
622 ``monicpart(<pol. expr.>)``
623 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
624
625 Divides by the leading coefficient, except that ``monicpart(0)==0``.
626
627 **unstable**
628
629 Currently the coefficients are reduced to lowest terms (contrarily
630 to legacy behaviour of `\\PolMakeMonic <polmakemonic_>`_), and
631 additionally the xintfrac_ ``\xintREZ`` macro is applied which
632 extracts powers of ten from numerator or denominator and stores
633 them internally separately. This is generally beneficial to
634 efficiency of multiplication.
635
636 .. _cont:
637
638 ``cont(<pol. expr.>)``
639 ~~~~~~~~~~~~~~~~~~~~~~
640
641 The (fractional) greatest common divisor of the polynomial
642 coefficients. It is always produced as an irreducible (non-negative)
643 fraction. According to Gauss theorem the content of a product is the
644 product of the contents.
645
646 .. commentaire 8 avril 2021
647
648 surprenamment après avoir utilisé `\\PolIContent <PolIContent_>`_
649 une fois on peut utiliser `\\PolIContent`_ directement.
650
651 avec docutils 0.16
652
653 ..
654
655 **name and syntax unstable**
656
657 At ``0.8`` it was created as ``icontent()`` to match the legacy
658 macro `\\PolIContent <PolIContent_>`_, whose name in 2018 was
659 chosen in relation to Maple's function ``icontent()``, possibly
660 because at that time I had not seen that Maple also had a
661 ``content()`` function. Name changed at ``0.8.1``.
662
663 It will change syntax if in future multivariate polynomials are
664 supported, and ``icontent()`` will then make a come-back.
665
666 ``primpart(<pol. expr.>)``
667 ~~~~~~~~~~~~~~~~~~~~~~~~~~
668
669 The quotient (except for the zero polynomial) by
670 ``cont(<pol. expr.>)``. This is thus a polynomial with
671 integer coefficients having ``1`` as greatest common divisor. The
672 sign of the leading coefficient is the same as in the original.
673
674 And ``primpart(0)==0``.
675
676 The trailing zeros of the integer coefficients are extracted
677 into a power of ten exponent part, in the internal representation.
678
679 ``quorem(<pol. expr.>, <pol. expr.>)``
680 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
681
682 Produces a nutple ``[Q,R]`` with ``Q`` the euclidean quotient and
683 ``R`` the remainder.
684
685 **name unstable**
686
687 ``poldiv()``?
688
689 ``quo(<pol. expr.>, <pol. expr.>)``
690 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
691
692 The euclidean quotient.
693
694 The deprecated ``pol1/pol2`` syntax computes the same polynomial.
695
696 ``rem(<pol. expr.>, <pol. expr.>)``
697 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
698
699 The euclidean remainder. If ``pol2`` is a (non-zero) scalar, this is
700 zero.
701
702 There is no infix operator associated to this, for lack of evident
703 notation. Please advise.
704
705 ``/:`` can be used if one is certain that ``pol2`` is of
706 degree at least one. But read the warning about it being unstable
707 even in that case.
708
709 .. not implemented
710
711 ``spquorem(pol1,pol2)``
712 ~~~~~~~~~~~~~~~~~~~~~~~
713
714 Produces a tuple ``[Q,R]`` with the pseudo-quotient and
715 pseudo-remainder. See `prem(pol1, pol2) <prem_>`_ for
716 their definitions.
717
718 **NOT IMPLEMENTED**
719
720 I am hesitating returning rather the nutple ``[b^f, Q, R]`` or
721 ``[f, Q, R]``. Note that the number of non-zero coefficients of
722 a polynomial ``P`` can be computed as ``add(?(c),c=coeffs(P))``,
723 and in this context I am hesitating abstracting a function to
724 provide this [#]_. The usual problem is that I don't know how to
725 name the function.
726
727 I am also hesitating providing rather a function returning only
728 ``f`` and ``R``, not ``Q``, which for modular computations we don't
729 need to carry along.
730
731 .. [#] one can embed ``\xintiiexpr add(?(c),c=coeffs(P))\relax``
732 inside ``\xintexpr`` and it will be more efficient for long
733 polynomials, but naturally a core implementation using a
734 single ``\numexpr`` would be quite more efficient still.
735
736 .. _prem:
737
738 ``prem(<pol. expr. 1>, <pol. expr. 2>)``
739 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
740
741 Produces a nutple ``[m, spR]`` where ``spR`` is the (special) pseudo
742 Euclidean remainder. Its description is:
743
744 - the standard euclidean remainder ``R`` is ``spR/m``
745
746 - ``m = b^f`` with ``b`` equal to the **absolute value** of the
747 leading coefficient of ``pol2``,
748
749 - ``f`` is the number of non-zero coefficients in the euclidean
750 quotient, if ``deg(pol2)>0`` (even if the remainder vanishes).
751
752 If ``pol2`` is a scalar however, the function outputs ``[1,0]``.
753
754 With these definitions one can show that if both ``pol1`` and
755 ``pol2`` have integer coefficients, then this is also the case of
756 ``spR``, which makes its interest (and also ``m*Q`` has integer
757 coefficients, with ``Q`` the euclidean quotient, if ``deg(pol2)>0``).
758 Also, ``prem()`` is computed faster than ``rem()`` for such integer
759 coefficients polynomials.
760
761 .. hint::
762
763 If you want the euclidean quotient ``R`` evaluated via ``spR/m``
764 (which may be faster, even with non integer coefficients) use
765 ``subs(last(x)/first(x),x=prem(P,Q))`` syntax as it avoids
766 computing ``prem(P,Q)`` twice. This does the trick both in
767 ``\poldef`` or in ``\xintdefvar``.
768
769 However, as is explained in the xintexpr_ documentation, using
770 such syntax in an ``\xintdeffunc`` is (a.t.t.o.w) illusory, due to
771 technicalities of how ``subs()`` gets converted into nested
772 expandable macros. One needs an auxiliary function like this::
773
774 \xintdeffunc lastoverfirst(x):=last(x)/first(x);
775 \xintdeffunc myR(x)=lastoverfirst(prem(x));
776
777 Then, ``myR(pol1,pol2)`` will evaluate ``prem(pol1,pol2)`` only
778 once and compute a polynomial identical to the euclidean
779 remainder (internal representations of coefficients may differ).
780
781 In this case of integer coefficients polynomials, the polexpr
782 internal representation of the integer coefficients in the pseudo
783 remainder will be with unit denominators only if that was already the
784 case for those of ``pol1`` and ``pol2`` (no automatic reduction to
785 lowest terms is made prior or after computation).
786
787 Pay attention here that ``b`` is the **absolute value** of the
788 leading coefficient of ``pol2``. Thus the coefficients of the
789 pseudo-remainder have the same signs as those of the standard
790 remainder. This diverges from Maple's function with the same name.
791
792
793 ``divmod(<pol. expr. 1>, <pol. expr. 2>)``
794 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
795
796 Overloads the scalar ``divmod()`` and associates it with the
797 experimental ``//`` and ``/:`` as extended to the polynomial type.
798
799 In particular when both ``pol1`` and ``pol2`` are scalars, this is
800 the usual ``divmod()`` (as in Python) and for ``pol1`` and ``pol2``
801 non constant polynomials, this is the same as ``quorem()``.
802
803 **Highly unstable** overloading of ``\xinteval``\ 's ``divmod()``.
804
805 ``mod(<pol. expr. 1>, <pol. expr. 2>)``
806 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
807
808 The ``R`` of the ``divmod()`` output. Same as ``R`` of ``quorem()``
809 when the second argument ``pol2`` is of degree at least one.
810
811 **Highly unstable** overloading of ``\xinteval``\ 's ``mod()``.
812
813 ``polgcd(<pol. expr. 1>, <pol. expr. 2>, ...)``
814 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
815
816 Evaluates to the greatest common polynomial divisor of all the
817 polynomial inputs. The output is a **primitive** (in particular,
818 with integer coefficients) polynomial. It is zero if and only if all
819 inputs vanish.
820
821 Attention, there must be either at least two polynomial variables, or
822 alternatively, only one argument which then must be a bracketed list
823 or some expression or variable evaluating to such a "nutple" whose
824 items are polynomials (see the documentation of the scalar ``gcd()``
825 in xintexpr_).
826
827 The two variable case could (and was, during development) have been
828 defined at user level like this::
829
830 \xintdeffunc polgcd_(P,Q):=
831 (deg(Q))??{P}{1}{polgcd_(Q,primpart(last(prem(P,Q))))};
832 \xintdeffunc polgcd(P,Q):=polgcd_(primpart(P),primpart(Q));%
833
834 This is basically what is done internally for two polynomials, up
835 to some internal optimizations.
836
837 **UNSTABLE**
838
839 I hesitate between returning a *primitive* or a *monic* polynomial.
840 Maple returns a primitive polynomial if all inputs [#]_ have integer
841 coefficients, else it returns a monic polynomial, but this is
842 complicated technically for us to add such a check and would add
843 serious overhead.
844
845 Internally, computations are done using primitive
846 integer-coefficients polynomials (as can be seen in the function
847 template above). So I decided finally to output a primitive
848 polynomial, as one can always apply ``monicpart()`` to it.
849
850 Attention that this is at odds with behaviour of the legacy
851 `\\PolGCD <PolGCD_>`_ (non expandable) macro.
852
853 .. [#] actually, only two polynomial arguments are allowed by Maple's
854 ``gcd()`` as far as I know.
855
856 ``resultant(<pol. expr. 1>, <pol. expr. 2>)``
857 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
858
859 The resultant.
860
861 **NOT YET IMPLEMENTED**
862
863 ``disc(<pol. expr.>)``
864 ~~~~~~~~~~~~~~~~~~~~~~
865
866 The discriminant.
867
868 **NOT YET IMPLEMENTED**
869
870 ``polpowmod(<pol. expr. 1>, <num. expr.>, <pol. expr. 2>)``
871 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
872
873 Modular exponentiation: ``mod(pol1^N, pol2)`` in a more efficient
874 manner than first computing ``pol1^N`` then reducing modulo ``pol2``.
875
876 Attention that this is using the ``mod()`` operation, whose current
877 experimental status is as follows:
878
879 - if ``deg(pol2)>0``, the euclidean remainder operation,
880 - if ``pol2`` is a scalar, coefficient-wise reduction modulo ``pol2``.
881
882
883 **UNSTABLE**
884
885 This is currently implemented at high level via ``\xintdeffunc`` and
886 recursive definitions, which were copied over from a scalar example
887 in the xintexpr_ manual::
888
889 \xintdeffunc polpowmod_(P, m, Q) :=
890 isone(m)?
891 % m=1: return P modulo Q
892 { mod(P,Q) }
893 % m > 1: test if odd or even and do recursive call
894 { odd(m)? { mod(P*sqr(polpowmod_(P, m//2, Q)), Q) }
895 { mod( sqr(polpowmod_(P, m//2, Q)), Q) }
896 }
897 ;%
898 \xintdeffunc polpowmod(P, m, Q) := (m)?{polpowmod_(P, m, Q)}{1};%
899
900 Negative exponents are not currently implemented.
901
902 For example::
903
904 \xinteval{subs(polpowmod(1+x,100,x^7),x=pol([0,1]))}
905 \xinteval{subs(polpowmod(1+x,20,10), x=pol([0,1]))}
906
907 produce respectively::
908
909 pol([1, 100, 4950, 161700, 3921225, 75287520, 1192052400])
910 pol([1, 0, 0, 0, 5, 4, 0, 0, 0, 0, 6, 0, 0, 0, 0, 4, 5, 0, 0, 0, 1])
911
912 .. perte de temps terrible pourquoi j'écris cela
913 When ``pol2`` is as scalar then the degrees of the modular powers
914 ``mod(pol1^N, pol2)`` will in general increase linearly in ``N``
915 hence become big. But one can play with modifying the above
916 template and nesting two ``mod()``, one with an integer modulus,
917 say ``7``, and the other the a monic integer coefficients
918 polynomial such as ``Q = x^2+1``. Then an integer coefficients
919 polynomial ``P`` will have an integer coefficient remainder modulo
920 ``Q``, and
921
922 .. _rdcoeffs:
923
924 ``rdcoeffs(<pol. expr.>)``
925 ~~~~~~~~~~~~~~~~~~~~~~~~~~
926
927 This operates on the internal representation of the coefficients,
928 reducing them to lowest terms.
929
930 **name HIGHLY undecided**
931
932 ``rdzcoeffs(<pol. expr.>)``
933 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
934
935 This operates on the internal representation of the coefficients,
936 reducing them to lowest terms then extracting from numerator
937 or denominator the maximal power of ten to store as a decimal
938 exponent.
939
940 This is sometimes favourable to more efficient polynomial algebra
941 computations.
942
943 **name HIGHLY undecided**
944
945 ``diff1(<pol. expr.>)``
946 ~~~~~~~~~~~~~~~~~~~~~~~
947
948 The first derivative.
949
950 **name UNSTABLE**
951
952 This name may be used in future to be the partial derivative with
953 respect to a first variable.
954
955 ``diff2(<pol. expr.>)``
956 ~~~~~~~~~~~~~~~~~~~~~~~
957
958 The second derivative.
959
960 **name UNSTABLE**
961
962 This name may be used in future to be the partial derivative with
963 respect to a second variable.
964
965
966 ``diffn(<pol. expr. P>, <num. expr. n>)``
967 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
968
969 The ``n``\ th derivative of ``P``. For ``n<0`` computes iterated primitives
970 vanishing at the origin.
971
972 The coefficients are not reduced to lowest terms.
973
974 **name and syntax UNSTABLE**
975
976 I am also considering reversing the order of the arguments.
977
978 ``antider(<pol. expr. P>)``
979 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
980
981 The primitive of ``P`` with no constant term. Same as ``diffn(P,-1)``.
982
983 ``intfrom(<pol. expr. P>, <pol. expr. c>)``
984 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
985
986 The primitive of ``P`` vanishing at ``c``, i.e. ``\int_c^x P(t)dt``.
987
988 Also ``c`` can be a polynomial... so if ``c`` is monomial ``x``
989 this will give zero!
990
991 **UNSTABLE**
992
993 Allowing general polynomial variable for ``c`` adds a bit of
994 overhead to the case of a pure scalar. So I am hesitating
995 maintaining this feature whose interest appears dubious.
996
997 .. attention::
998
999 As the two arguments are both allowed to be polynomials, if by
1000 inadvertance one exchanges the two, there is no error but the
1001 meaning of ``intfrom(c,P)`` is completely otherwise, as it
1002 produces ``c*(x - P)`` if ``c`` is a scalar::
1003
1004 >>> &pol
1005 pol mode (i.e. function definitions use \poldef)
1006 >>> P(x):=1+x^2;
1007 P = x^2+1
1008 --> &GenFloat(P) lets P become usable as function in fp mode
1009 --> &ROOTS(P) (resp. &ROOTS(P,N)) finds all rational roots exactly and
1010 all irrational roots with at least 10 (resp. N) fractional digits
1011 >>> intfrom(P,1);
1012 @_1 pol([-4/3, 1, 0, 1/3])
1013 >>> intfrom(1,P);
1014 @_2 pol([-1, 1, -1])
1015 >>> &bye
1016
1017
1018
1019 .. grosse hésitation ici
1020
1021 ``intto(<pol. expr. P>, <pol. expr. c>)``
1022 -----------------------------------------
1023
1024 ``\int_x^c P(t)dt``.
1025
1026 c'est l'opposé du précédent
1027
1028 mais le nom pourrait faire penser à \int_0^x plutôt
1029
1030 ``integral(<pol. expr. P>, [<pol. expr. a>, <pol. expr. b>])``
1031 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1032
1033 ``\int_a^b P(t)dt``.
1034
1035 .. warning::
1036
1037 The brackets here are not denoting an optional argument but a
1038 *mandatory* nutple argument ``[a, b]`` with *two items*. No real
1039 recoverable-from error check is done on the input syntax. The
1040 input can be an xintexpr_ variable which happens to be a nutple
1041 with two items, or any expression which evaluates to such a
1042 nutple.
1043
1044 ``a`` and ``b`` are not restricted to be scalars, they are allowed to
1045 be themselves polynomial variables or even polynomial expressions.
1046
1047 To compute ``\int_{x-1}^x P(t)dt`` it is more efficient to use
1048 ``intfrom(x-1)``.
1049
1050 Similary to compute ``\int_x^{x+1} P(t)dt``, use ``-intfrom(x+1)``.
1051
1052 **UNSTABLE**
1053
1054 Am I right to allow general polynomials ``a`` and ``b`` hence add
1055 overhead to the pure scalar case ?
1056
1057
1058
1059 Non-expandable macros
1060 ---------------------
1061
1062 .. note::
1063
1064 At ``0.8`` ``polexpr`` is usable with Plain TeX and not only with
1065 LaTeX. Some examples given in this section may be using LaTeX syntax
1066 such as ``\renewcommand``.
1067
1068 .. _poldef;:
1069
1070 ``\poldef polname(letter):= expression using the letter as indeterminate;``
1071 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1072
1073 This evaluates the *polynomial expression* and stores the
1074 coefficients in a private structure accessible later via other
1075 package macros, used with argument ``polname``. Of course the
1076 *expression* can make use of previously defined polynomials.
1077
1078 Polynomial names must start with a letter and are constituted of
1079 letters, digits, underscores, the ``@`` (see Technicalities_) and
1080 the right tick ``'``.
1081
1082 The whole xintexpr_ syntax is authorized, as long as the final
1083 result is of polynomial type::
1084
1085 \poldef polname(z) := add((-1)^i z^(2i+1)/(2i+1)!, i = 0..10);
1086
1087 With fractional coefficients, beware the `tacit multiplication issue
1088 <warningtacit_>`_.
1089
1090 Furthermore:
1091
1092 - a variable ``polname`` is defined which can be used in ``\poldef``
1093 as well as in ``\xinteval`` for algebraic computations or as
1094 argument to polynomial aware functions,
1095
1096 - a function ``polname()`` is defined which can be used in ``\poldef``
1097 as well as in ``\xinteval``. It accepts there as argument scalars
1098 and also other polynomials (via their names, thanks to previous
1099 item).
1100
1101 Any function defined via ``\xintdeffunc`` and only algebraic
1102 operations, as well as ople indexing or slicing operations, should
1103 work fine in ``\xintexpr/\xinteval`` with such polynomial names as
1104 argument.
1105
1106 In the case of a constant polynomial, the xintexpr_ *variable* (not
1107 the internal data structure on which the package macros operate)
1108 associated to it is indistinguishable from a scalar, it is actually
1109 a scalar and has lost all traces from its origins as a polynomial
1110 (so for example can be used as argument to the ``cos()`` function).
1111 The *function* on the other hand remains a one-argument function,
1112 which simply has a constant value.
1113
1114 .. attention::
1115
1116 The function ``polname()`` is defined **only** for
1117 ``\xintexpr/\xinteval``
1118 context. It will be unknown to ``\xintfloateval``.
1119
1120 Worse, a
1121 previously existing floating point function of the same name will
1122 be made undefined again, to avoid hard to debug mismatches between
1123 exact and floating point polynomials. This also applies when the
1124 polynomial is produced not via ``\poldef`` or ``\PolDef`` but
1125 as result of usage of the other package macros.
1126
1127 See :ref:`\\PolGenFloatVariant{\<polname\>} <PolGenFloatVariant>` to generate a **function**
1128 usable in ``\xintfloateval``.
1129
1130 .. attention::
1131
1132 Using the **variable** ``mypol`` inside ``\xintfloateval`` will
1133 generate low-level errors because the infix operators there are
1134 not polynomial-aware, and the polynomial specific functions such
1135 as ``deg()`` are only defined for usage inside ``\xintexpr``.
1136
1137 In short, currently polynomials defined via ``polexpr`` can
1138 be used in floating point context only for numerical evaluations,
1139 via **functions** obtained from :ref:`\\PolGenFloatVariant{\<polname\>} <PolGenFloatVariant>`
1140 usage.
1141
1142 Changes to the original polynomial via package macros are not
1143 automatically mapped to the numerical floating point evaluator
1144 which must be manually updated as necessary when the original
1145 rational coefficient polynomial is modified.
1146
1147 The original expression is lost after parsing, and in particular the
1148 package provides no way to typeset it (of course the package
1149 provides macros to typeset the computed polynomial). Typesetting
1150 the original expression has to be done manually, if needed.
1151
1152 .. _PolDef:
1153
1154 ``\PolDef[<letter>]{<polname>}{<expr. using the letter as indeterminate>}``
1155 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1156
1157 Does the same as `\\poldef <poldef;_>`_ in an undelimited macro
1158 format, the main interest is to avoid potential problems with the
1159 catcode of the semi-colon in presence of some packages. In absence
1160 of a ``[<letter>]`` optional argument, the variable is assumed to be
1161 ``x``.
1162
1163
1164 .. _PolGenFloatVariant:
1165
1166 ``\PolGenFloatVariant{}``
1167 ~~~~~~~~~~~~~~~~~~~~~~~~~
1168
1169 Syntax: ``\PolGenFloatVariant{<polname>}``
1170
1171 Makes the polynomial also usable in the
1172 ``\xintfloatexpr/\xintfloateval`` parser. It will therein evaluates
1173 via an Horner scheme using polynomial coefficients already
1174 pre-rounded to the float precision.
1175
1176 See also :ref:`\\PolToFloatExpr{\<pol. expr.\>} <PolToFloatExpr>`.
1177
1178 .. attention::
1179
1180 Any operation, for example generating the derivative polynomial,
1181 or dividing two polynomials or using the ``\PolLet``, must be
1182 followed by explicit usage of ``\PolGenFloatVariant{<polname>}`` if
1183 the new polynomial is to be used in ``\xintfloateval``.
1184
1185 .. _PolTypeset:
1186
1187 ``\PolTypeset[]{}``
1188 ~~~~~~~~~~~~~~~~~~~
1189
1190 Syntax: ``\PolTypeset[<letter>]{<pol. expr.>}``
1191
1192 Typesets in descending powers, switching to math mode if in text
1193 mode, after evaluating the polynomial expression::
1194
1195 \PolTypeset{mul(x-i,i=1..5)}% possible since polexpr 0.8
1196
1197 The letter used in the input is by default assumed to be ``x``,
1198 but can be modified by a redefinition of `\\PolToExprInVar`_.
1199
1200 The letter used in the output is also by default ``x``. This one
1201 can be changed on-the-fly via the optional ``<letter>``::
1202
1203 \PolTypeset[z]{polname or polynomial expression}
1204
1205 By default zero coefficients are skipped (use ``\poltypesetalltrue``
1206 to get all of them in output).
1207
1208 The following macros (whose meanings will be found in the package code)
1209 can be re-defined for customization. Their default definitions are
1210 expandable, but this is not a requirement.
1211
1212 .. _PolTypesetCmd:
1213
1214 ``\PolTypesetCmd{}``
1215 ^^^^^^^^^^^^^^^^^^^^
1216
1217 Syntax: ``\PolTypesetCmd{<raw_coeff>}``
1218
1219 Its package definition checks if the coefficient is ``1`` or ``-1``
1220 and then skips printing the ``1``, except for the coefficient of
1221 degree zero. Also it sets the conditional deciding behaviour of
1222 :ref:`\\PolIfCoeffIsPlusOrMinusOne{T}{F} <PolIfCoeffIsPlusOrMinusOne>`.
1223
1224 The actual printing of the coefficients, when not equal to plus or
1225 minus one, is handled by :ref:`\\PolTypesetOne{\<raw_coeff\>} <PolTypesetOne>`.
1226
1227 .. _PolIfCoeffIsPlusOrMinusOne:
1228
1229 ``\PolIfCoeffIsPlusOrMinusOne{}{}``
1230 ***********************************
1231
1232 Syntax: ``\PolIfCoeffIsPlusOrMinusOne{T}{F}``
1233
1234 This macro is a priori undefined.
1235
1236 It is defined via the default :ref:`\\PolTypesetCmd{\<raw_coeff\>} <PolTypesetCmd>` to be
1237 used if needed in the execution of `\\PolTypesetMonomialCmd`_,
1238 e.g. to insert a ``\cdot`` in front of ``\PolVar^{\PolIndex}`` if
1239 the coefficient is not plus or minus one.
1240
1241 The macro will execute ``T`` if the coefficient has been found to be
1242 plus or minus one, and ``F`` if not. It chooses expandably between
1243 ``T`` and ``F``.
1244
1245 .. _PolTypesetOne:
1246
1247 ``\PolTypesetOne{}``
1248 ^^^^^^^^^^^^^^^^^^^^
1249
1250 Syntax: ``\PolTypesetOne{<raw_coeff>}``
1251
1252 Defaults to ``\xintTeXsignedFrac`` (LaTeX) or ``\xintTeXsignedOver``
1253 (else). But these xintfrac_ old legacy macros are a bit
1254 annoying as they insist in exhibiting a power of ten rather than
1255 using simpler decimal notation.
1256
1257 As alternative, one can do definitions such as::
1258
1259 \def\PolTypesetOne#1{\xintDecToString{\xintREZ{#1}}}
1260 % or with LaTeX+siunitx for example
1261 \renewcommand\PolTypesetOne[1]{\num{\xintPFloat[5]{#1}}}
1262 % (as \num of siunitx understands floating point notation)
1263 \renewcommand\PolTypesetOne[1]{\num{\xintRound{4}{#1}}}
1264
1265 .. _PolTypesetMonomialCmd:
1266
1267 ``\PolTypesetMonomialCmd``
1268 ^^^^^^^^^^^^^^^^^^^^^^^^^^
1269
1270 This decides how a monomial (in variable ``\PolVar`` and with
1271 exponent ``\PolIndex``) is to be printed. The default does nothing
1272 for the constant term, ``\PolVar`` for the first degree and
1273 ``\PolVar^{\PolIndex}`` for higher degrees monomials. Beware that
1274 ``\PolIndex`` expands to digit tokens and needs termination in
1275 ``\ifnum`` tests.
1276
1277 .. _PolTypesetCmdPrefix:
1278
1279 ``\PolTypesetCmdPrefix{}``
1280 ^^^^^^^^^^^^^^^^^^^^^^^^^^
1281
1282 Syntax: ``\PolTypesetCmdPrefix{<raw_coeff>}``
1283
1284 Expands to a ``+`` if the ``raw_coeff`` is zero or positive, and to
1285 nothing if ``raw_coeff`` is negative, as in latter case the
1286 ``\xintTeXsignedFrac`` (or ``\xintTeXsignedOver``) used by
1287 :ref:`\\PolTypesetCmd{\<raw_coeff\>} <PolTypesetCmd>` will put the ``-`` sign in front of
1288 the fraction (if it is a fraction) and this will thus serve as
1289 separator in the typeset formula. Not used for the first term.
1290
1291
1292 .. _PolTypeset*:
1293
1294 ``\PolTypeset*[]{}``
1295 ~~~~~~~~~~~~~~~~~~~~
1296
1297 Syntax: ``\PolTypeset*[<letter>]{<pol. expr.>}``
1298
1299 Typesets in ascending powers. The ``<letter>`` optional argument
1300 (after the ``*``) declares the letter to use in the *output*.
1301 As for `\\PolTypeset <PolTypeset>`_, it defaults to ``x``.
1302
1303 To modify the expected ``x`` in the *input*, see `\\PolToExprInVar`_.
1304
1305 Extended at ``0.8`` to accept general expressions and not only
1306 polynomial names.
1307
1308
1309 .. _PolLet:
1310
1311 ``\PolLet{}={}``
1312 ~~~~~~~~~~~~~~~~
1313
1314 Syntax: ``\PolLet{<polname_2>}={<polname_1>}``
1315
1316 Makes a copy of the already defined polynomial ``polname_1`` to a
1317 new one ``polname_2``. This has the same effect as
1318 ``\PolDef{<polname_2>}{<polname_1>(x)}`` or (better)
1319 ``\PolDef{<polname_2>}{<polname_1>}`` but with less overhead. The
1320 ``=`` is optional.
1321
1322 .. _PolGlobalLet:
1323
1324 ``\PolGlobalLet{}={}``
1325 ~~~~~~~~~~~~~~~~~~~~~~
1326
1327 Syntax: ``\PolGlobalLet{<polname_2>}={<polname_1>}``
1328
1329 Acts globally.
1330
1331 .. _PolAssign:
1332
1333 ``\PolAssign{}\toarray{}``
1334 ~~~~~~~~~~~~~~~~~~~~~~~~~~
1335
1336 Syntax: ``\PolAssign{<polname>}\toarray{<\macro>}``
1337
1338 Defines a one-argument expandable macro ``\macro{#1}`` which expands
1339 to the (raw) #1th polynomial coefficient.
1340
1341 - Attention, coefficients here are indexed starting at 1. This is
1342 an unfortunate legacy situation related to the original indexing
1343 convention in xinttools_ arrays.
1344
1345 - With #1=-1, -2, ..., ``\macro{#1}`` returns leading coefficients.
1346
1347 - With #1=0, returns the number of coefficients, i.e. ``1 + deg f``
1348 for non-zero polynomials.
1349
1350 - Out-of-range #1's return ``0/1[0]``.
1351
1352 See also :ref:`\\PolNthCoeff{\<polname\>}{\<index\>} <PolNthCoeff>`.
1353
1354 .. _PolGet:
1355
1356 ``\PolGet{}\fromarray{}``
1357 ~~~~~~~~~~~~~~~~~~~~~~~~~
1358
1359 Syntax: ``\PolGet{<polname>}\fromarray{<\macro>}``
1360
1361 Does the converse operation to
1362 ``\PolAssign{<polname>}\toarray\macro``. Each individual
1363 ``\macro{<value>}`` gets expanded in an ``\edef`` and then normalized
1364 via xintfrac_\ 's macro ``\xintRaw``.
1365
1366 The leading zeros are removed from the polynomial.
1367
1368 (contrived) Example::
1369
1370 \xintAssignArray{1}{-2}{5}{-3}\to\foo
1371 \PolGet{f}\fromarray\foo
1372
1373 This will define ``f`` as would have ``\poldef f(x):=1-2x+5x^2-3x^3;``.
1374
1375 .. vieux commentaire
1376
1377 Prior to ``0.5``, coefficients were not normalized via
1378 ``\xintRaw`` for internal storage.
1379
1380 .. _PolFromCSV:
1381
1382 ``\PolFromCSV{}{}``
1383 ~~~~~~~~~~~~~~~~~~~
1384
1385 Syntax: ``\PolFromCSV{<polname>}{<csv>}``
1386
1387 Defines a polynomial directly from the comma separated list of values
1388 (or a macro expanding to such a list) of its coefficients, the *first
1389 item* gives the constant term, the *last item* gives the leading
1390 coefficient, except if zero, then it is dropped (iteratively). List
1391 items are each expanded in an ``\edef`` and then put into normalized
1392 form via xintfrac_\ 's macro ``\xintRaw``.
1393
1394 As leading zero coefficients are removed::
1395
1396 \PolFromCSV{f}{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
1397
1398 defines the zero polynomial, which holds only one coefficient.
1399
1400 See also expandable macro :ref:`\\PolToCSV{\<polname\>} <PolToCSV>`.
1401
1402 .. vieux commentaire
1403
1404 Prior to ``0.5``, coefficients were not normalized via
1405 ``\xintRaw`` for internal storage.
1406
1407
1408 .. _PolMapCoeffs:
1409
1410 ``\PolMapCoeffs{}{}``
1411 ~~~~~~~~~~~~~~~~~~~~~
1412
1413 Syntax: ``\PolMapCoeffs{\macro}{<polname>}``
1414
1415 It modifies ('in-place': original coefficients get lost) each
1416 coefficient of the defined polynomial via the *expandable* macro
1417 ``\macro``. The degree is adjusted as necessary if some leading
1418 coefficients vanish after the operation.
1419
1420 In the replacement text of ``\macro``, ``\index`` expands to the
1421 coefficient index (starting at zero for the constant term).
1422
1423 Notice that ``\macro`` will have to handle inputs in the xintfrac_
1424 internal format. This means that it probably will have to be
1425 expressed in terms of macros from the xintfrac_ package.
1426
1427 Example::
1428
1429 \def\foo#1{\xintMul{#1}{\the\numexpr\index*\index\relax}}
1430
1431 (or with ``\xintSqr{\index}``) to replace ``n``-th coefficient
1432 ``f_n`` by ``f_n*n^2``.
1433
1434 .. _PolReduceCoeffs:
1435
1436 ``\PolReduceCoeffs{}``
1437 ~~~~~~~~~~~~~~~~~~~~~~
1438
1439 Syntax: ``\PolReduceCoeffs{<polname>}``
1440
1441 Reduces the internal representations of the coefficients to
1442 their lowest terms.
1443
1444 .. _PolReduceCoeffs*:
1445
1446 ``\PolReduceCoeffs*{}``
1447 ~~~~~~~~~~~~~~~~~~~~~~~
1448
1449 Syntax: ``\PolReduceCoeffs*{<polname>}``
1450
1451 Reduces the internal representations of the coefficients to their
1452 lowest terms, but ignoring a possible separated "power of ten part".
1453
1454 For example, xintfrac_ stores an ``30e2/50`` input as ``30/50`` with
1455 a separate ``10^2`` part. This will thus get replaced by ``3e^2/5``
1456 (or rather whatever xintfrac_ uses for internal representation), and
1457 not by ``60`` as would result from complete reduction.
1458
1459 Evaluations with polynomials treated by this can be much faster than
1460 with those handled by the non-starred variant
1461 :ref:`\\PolReduceCoeffs{\<polname\>} <PolReduceCoeffs>`: as the numerators and denominators
1462 remain generally smaller.
1463
1464 .. _PolMakeMonic:
1465
1466 ``\PolMakeMonic{}``
1467 ~~~~~~~~~~~~~~~~~~~
1468
1469 Syntax: ``\PolMakeMonic{<polname>}``
1470
1471 Divides by the leading coefficient. It is recommended to execute
1472 :ref:`\\PolReduceCoeffs*{\<polname\>} <PolReduceCoeffs*>` immediately afterwards. This is not
1473 done automatically, in case the original polynomial had integer
1474 coefficients and the user wants to keep the leading one as common
1475 denominator for typesetting purposes.
1476
1477 .. _PolMakePrimitive:
1478
1479 ``\PolMakePrimitive{}``
1480 ~~~~~~~~~~~~~~~~~~~~~~~
1481
1482 Syntax: ``\PolMakePrimitive{<polname>}``
1483
1484 Divides by the integer content see (`\\PolIContent`_).
1485 This thus produces a polynomial with integer
1486 coefficients having no common factor. The sign of the leading
1487 coefficient is not modified.
1488
1489 .. _PolDiff:
1490
1491 ``\PolDiff{}{}``
1492 ~~~~~~~~~~~~~~~~
1493
1494 Syntax: ``\PolDiff{<polname_1>}{<polname_2>}``
1495
1496 This sets ``polname_2`` to the first derivative of ``polname_1``. It
1497 is allowed to issue ``\PolDiff{f}{f}``, effectively replacing ``f``
1498 by ``f'``.
1499
1500 Coefficients of the result ``polname_2`` are irreducible fractions
1501 (see `Technicalities`_ for the whole story.)
1502
1503 .. _PolDiff[]:
1504
1505 ``\PolDiff[]{}{}``
1506 ~~~~~~~~~~~~~~~~~~
1507
1508 Syntax: ``\PolDiff[N]{<polname_1>}{<polname_2>}``
1509
1510 This sets ``polname_2`` to the ``N``-th derivative of ``polname_1``.
1511 Identical arguments is allowed. With ``N=0``, same effect as
1512 ``\PolLet{<polname_2>}={<polname_1>}``. With negative ``N``, switches to
1513 using ``\PolAntiDiff``.
1514
1515 .. _PolAntiDiff:
1516
1517 ``\PolAntiDiff{}{}``
1518 ~~~~~~~~~~~~~~~~~~~~
1519
1520 Syntax: ``\PolAntiDiff{<polname_1>}{<polname_2>}``
1521
1522 This sets ``polname_2`` to the primitive of ``polname_1`` vanishing
1523 at zero.
1524
1525 Coefficients of the result ``polname_2`` are irreducible fractions
1526 (see `Technicalities`_ for the whole story.)
1527
1528 .. _PolAntiDiff[]:
1529
1530 ``\PolAntiDiff[]{}{}``
1531 ~~~~~~~~~~~~~~~~~~~~~~~
1532
1533 Syntax: ``\PolAntiDiff[N]{<polname_1>}{<polname_2>}``
1534
1535 This sets ``polname_2`` to the result of ``N`` successive integrations on
1536 ``polname_1``. With negative ``N``, it switches to using ``\PolDiff``.
1537
1538 .. _PolDivide:
1539
1540 ``\PolDivide{}{}{}{}``
1541 ~~~~~~~~~~~~~~~~~~~~~~
1542
1543 Syntax: ``\PolDivide{<polname_1>}{<polname_2>}{<polname_Q>}{<polname_R>}``
1544
1545 This sets ``polname_Q`` and ``polname_R`` to be the quotient and
1546 remainder in the Euclidean division of ``polname_1`` by
1547 ``polname_2``.
1548
1549 .. _PolQuo:
1550
1551 ``\PolQuo{}{}{}``
1552 ~~~~~~~~~~~~~~~~~
1553
1554 Syntax: ``\PolQuo{<polname_1>}{<polname_2>}{<polname_Q>}``
1555
1556 This sets ``polname_Q`` to be the quotient in the Euclidean division
1557 of ``polname_1`` by ``polname_2``.
1558
1559 .. _PolRem:
1560
1561 ``\PolRem{}{}{}``
1562 ~~~~~~~~~~~~~~~~~
1563
1564 Syntax: ``\PolRem{<polname_1>}{<polname_2>}{<polname_R>}``
1565
1566 This sets ``polname_R`` to be the remainder in the Euclidean division
1567 of ``polname_1`` by ``polname_2``.
1568
1569 .. _PolGCD:
1570
1571 ``\PolGCD{}{}{}``
1572 ~~~~~~~~~~~~~~~~~
1573
1574 Syntax: ``\PolGCD{<polname_1>}{<polname_2>}{<polname_GCD>}``
1575
1576 This sets ``polname_GCD`` to be the (monic) GCD of ``polname_1``
1577 and ``polname_2``. It is a unitary polynomial except if both
1578 ``polname_1`` and ``polname_2`` vanish, then ``polname_GCD`` is the
1579 zero polynomial.
1580
1581 .. ``\PolIGCD{<polname_1>}{<polname_2>}{polname_iGCD}``
1582 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1583
1584 **NOT YET**
1585
1586 This **assumes** that the two polynomials have integer coefficients.
1587 It then computes the greatest common divisor in the integer
1588 polynomial ring, normalized to have a positive leading coefficient
1589 (if the inputs are not both zero).
1590
1591
1592 Root localization routines via the `Sturm Theorem`_
1593 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1594
1595 As :ref:`\\PolToSturm{\<polname\>}{\<sturmname\>} <PolToSturm>` and
1596 :ref:`\\PolSturmIsolateZeros{\<sturmname\>} <PolSturmIsolateZeros>` and variants declare
1597 additional polynomial or scalar variables with names based on ``<sturmname>`` as
1598 prefix, it is advisable to keep the ``<sturmname>`` namespace separate from
1599 the one applying to ``\xintexpr`` variables generally, or to polynomials.
1600
1601 .. _PolToSturm:
1602
1603 ``\PolToSturm{}{}``
1604 ^^^^^^^^^^^^^^^^^^^
1605
1606 Syntax: ``\PolToSturm{<polname>}{<sturmname>}``
1607
1608 With ``<polname>`` being for example ``P``, and ``<sturmname>`` being
1609 for example ``S``, the macro starts by computing the derivative
1610 ``P'``, then computes the opposite of the remainder in the euclidean
1611 division of ``P`` by ``P'``, then the opposite of the remainder in
1612 the euclidean division of ``P'`` by the first obtained polynomial,
1613 etc... Up to signs following the ``--++--++...`` pattern, these are
1614 the same remainders as in the Euclide algorithm applied to the
1615 computation of the GCD of ``P`` and ``P'``.
1616
1617 The precise process differs from the above description: the
1618 algorithm first sets ``S_0_`` to be the *primitive part* of ``P``
1619 and ``S_1_`` to be the *primitive part* of ``P'`` (see
1620 :ref:`\\PolIContent{\<polname\>} <PolIContent>`), then at each step
1621 the remainder is made primitive and stored for internal reference as
1622 ``S_k_``, so only integer-coefficients polynomials are manipulated.
1623
1624 .. warning::
1625
1626 This exact procedure will perhaps in future be replaced by a
1627 *sub-resultant algorithm*, which may bring some speed gain in
1628 obtaining a pseudo-Sturm sequence, but some experimenting is
1629 needed, in the context of realistically realizable computations
1630 by the package; primitive polynomials although a bit costly
1631 have the smallest coefficients hence are the best for the kind of
1632 computations done for root localization, after having computed a
1633 Sturm sequence.
1634
1635 The last non-zero primitivized remainder ``S_N_`` is, up to sign,
1636 the primitive part of the GCD of ``P`` and ``P'``. Its roots (real
1637 and complex) are the multiple roots of the original ``P``. The
1638 original ``P`` was "square-free" (i\.e\. did not have multiple real
1639 or complex roots) if and only if ``S_N_`` is a constant, which is
1640 then ``+1`` or ``-1`` (its value before primitivization is lost).
1641
1642 The macro then divides each ``S_k_`` by ``S_N_`` and declares the
1643 quotients ``S_k`` as user polynomials for future use. By Gauss
1644 theorem about the contents of integer-coefficients polynomials,
1645 these ``S_k`` also are primitive integer-coefficients polynomials.
1646
1647 This step will be referred to as *normalization*, and in this
1648 documentation the obtained polynomials are said to constitute the
1649 "Sturm chain" (or "Sturm sequence"), i.e. by convention the "Sturm
1650 chain polynomials" are square-free and primitive. The possibly
1651 non-square-free ones are referred to as *non-normalized*.
1652
1653 As an exception to the rule, if the original ``P`` was "square-free"
1654 (i\.e\. did not have multiple real or complex roots) then
1655 normalization is skipped (in that case ``S_N_`` is either ``+1`` or
1656 ``-1``), so ``S_0_`` is exactly the primitive part of starting
1657 polynomial ``P``, in the "square-free" case.
1658
1659 The next logical step is to execute `\\PolSturmIsolateZeros{S}
1660 <PolSturmIsolateZeros_>`_ or one of its variants. Be careful not to
1661 use the names ``sturmname_0``, ``sturmname_1``, etc... for defining
1662 other polynomials after having done
1663 ``\PolToSturm{<polname>}{<sturmname>}`` and before executing
1664 ``\PolSturmIsolateZeros{<sturmname>}`` or its variants else the
1665 latter will behave erroneously.
1666
1667 .. note::
1668
1669 The declaration of the ``S_k``\ 's will overwrite with no warning
1670 previously declared polynomials with identical names ``S_k``,
1671 i.e. ``<sturmname>_k``. This is why the macro was designed
1672 to expect two names: ``<polname>`` and ``<sturmname>``.
1673
1674 It is allowed to use the polynomial name ``P`` as Sturm chain
1675 name ``S``: ``\PolToSturm{P}{P}``, but this is considered bad
1676 practice for the reason mentioned in the previous paragraph.
1677
1678 Furthermore, `\\PolSturmIsolateZeros <PolSturmIsolateZeros_>`_
1679 creates xintexpr_ variables whose names start with
1680 ``<sturmname>L_``, ``<sturmname>R_``, and ``<sturmname>Z_``, also
1681 ``<sturmname>M_`` for holding the multiplicities, and this may
1682 overwrite pre-existing user-defined xintexpr_ variables.
1683
1684 .. warning::
1685
1686 The reason why the ``S_k``\ 's are declared as polynomials is
1687 that the associated polynomial functions are needed to compute
1688 the sign changes in the Sturm sequence evaluated at a given
1689 location, as this is the basis mechanism of `\\PolSturmIsolateZeros
1690 <PolSturmIsolateZeros_>`_ (on the basis of the `Sturm theorem`_).
1691
1692 It is possible that in future the package will only internally
1693 construct such polynomial functions and only the starred variant
1694 will make the normalized (i.e. square-free) Sturm sequence public.
1695
1696 The integer ``N`` giving the length of the Sturm chain ``S_0``,
1697 ``S_1``, ..., ``S_N`` is available as
1698 :ref:`\\PolSturmChainLength{\<sturmname\>} <PolSturmChainLength>`. If all roots of original ``P``
1699 are real, then ``N`` is both the number of distinct real roots and
1700 the degree of ``S_0``. In the case of existence of complex roots,
1701 the number of distinct real roots is at most ``N`` and ``N`` is at
1702 most the degree of ``S_0``.
1703
1704 .. _PolToSturm*:
1705
1706 ``\PolToSturm*{}{}``
1707 ^^^^^^^^^^^^^^^^^^^^
1708
1709 Syntax: ``\PolToSturm*{<polname>}{<sturmname>}``
1710
1711 Does the same as `un-starred version <PolToSturm_>`_ and additionally it
1712 keeps for user usage the memory of the *un-normalized* (but still
1713 made primitive) Sturm chain
1714 polynomials ``sturmname_k_``, ``k=0,1, ..., N``, with
1715 ``N`` being :ref:`\\PolSturmChainLength{\<sturmname\>} <PolSturmChainLength>`.
1716
1717 .. comment
1718
1719 The square-free part of ``<polname>`` is ``sturmname_0``, and their
1720 quotient is the polynomial with name
1721 ``sturmname_\PolSturmChainLength{<sturmname>}_``. It thus easy to
1722 set-up a loop iteratively computing the latter until the last one
1723 is a constant, thus obtaining the decomposition of an ``f`` as
1724 a product ``c f_1 f_2 f_3 ...`` of a constant and square-free (primitive)
1725 polynomials, where each ``f_i`` divides its predecessor.
1726
1727 .. _PolSturmIsolateZeros:
1728
1729 ``\PolSturmIsolateZeros{}``
1730 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1731
1732 Syntax: ``\PolSturmIsolateZeros{<sturmname>}``
1733
1734 The macro locates, using the `Sturm Theorem`_, as many disjoint
1735 intervals as there are distinct real roots.
1736
1737 .. important::
1738
1739 The Sturm chain must have been produced by an earlier
1740 :ref:`\\PolToSturm{\<polname\>}{\<sturmname\>} <PolToSturm>`.
1741
1742 After its execution they are two types of such intervals (stored in
1743 memory and accessible via macros or xintexpr_ variables, see below):
1744
1745 - singleton ``{a}``: then ``a`` is a root, (necessarily a decimal
1746 number, but not all such decimal numbers are exactly identified yet).
1747
1748 - open intervals ``(a,b)``: then there is exactly one root ``z``
1749 such that ``a < z < b``, and the end points are guaranteed to not
1750 be roots.
1751
1752 The interval boundaries are decimal numbers, originating
1753 in iterated decimal subdivision from initial intervals
1754 ``(-10^E, 0)`` and ``(0, 10^E)`` with ``E`` chosen initially large
1755 enough so that all roots are enclosed; if zero is a root it is always
1756 identified as such. The non-singleton intervals are of the
1757 type ``(a/10^f, (a+1)/10^f)`` with ``a`` an integer, which is
1758 neither ``0`` nor ``-1``. Hence either ``a`` and ``a+1`` are both positive
1759 or they are both negative.
1760
1761 One does not *a priori* know what will be the lengths of these
1762 intervals (except that they are always powers of ten), they
1763 vary depending on how many digits two successive roots have in
1764 common in their respective decimal expansions.
1765
1766 .. important::
1767
1768 If some two consecutive intervals share an end-point, no
1769 information is yet gained about the separation between the two
1770 roots which could at this stage be arbitrarily small.
1771
1772 See :ref:`\\PolRefineInterval*{\<sturmname\>}{\<index\>} <PolRefineInterval*>` which addresses
1773 this issue.
1774
1775 .. This procedure is covariant
1776 with the independent variable ``x`` becoming ``-x``.
1777 Hmm, pas sûr et trop fatigué
1778
1779 Let us suppose ``<sturmname>`` is ``S``.
1780
1781 The interval boundaries (and exactly found roots) are made available
1782 for future computations in ``\xintexpr/xinteval`` or ``\poldef`` as
1783 variables ``SL_1``, ``SL_2``, etc..., for the left end-points and
1784 ``SR_1``, ``SR_2``, ..., for the right end-points.
1785
1786 Additionally, xintexpr_ variable ``SZ_1_isknown`` will have value
1787 ``1`` if the root in the first interval is known, and ``0``
1788 otherwise. And similarly for the other intervals.
1789
1790 .. important::
1791
1792 The variable declarations are done with no check of existence of
1793 previously existing variables with identical names.
1794
1795 Also, macros :ref:`\\PolSturmIsolatedZeroLeft{\<sturmname\>}{\<index\>} <PolSturmIsolatedZeroLeft>` and
1796 :ref:`\\PolSturmIsolatedZeroRight{\<sturmname\>}{\<index\>} <PolSturmIsolatedZeroRight>` are provided which
1797 expand to these same values, written in decimal notation (i.e.
1798 pre-processed by `\\PolDecToString <PolDecToString_>`_.) And there
1799 is also :ref:`\\PolSturmIfZeroExactlyKnown{\<sturmname\>}{\<index\>}{T}{F} <PolSturmIfZeroExactlyKnown>`.
1800
1801 .. important::
1802
1803 Trailing zeroes in the stored decimal numbers accessible via the
1804 macros are significant: they are also present in the decimal
1805 expansion of the exact root, so as to be able for example to
1806 print out bounds of real roots with as many digits as is
1807 significant, even if the digits are zeros.
1808
1809 The start of the decimal expansion of the ``<index>``-th root is given by
1810 `\\PolSturmIsolatedZeroLeft{<sturmname>}{<index>}
1811 <PolSturmIsolatedZeroLeft_>`_ if the root is positive, and by
1812 `\PolSturmIsolatedZeroRight{<sturmname>}{<index>}
1813 <PolSturmIsolatedZeroRight_>`_ if the root is neagtive. These two
1814 decimal numbers are either both zero or both of the same sign.
1815
1816 The number of distinct roots is obtainable expandably as
1817 :ref:`\\PolSturmNbOfIsolatedZeros{\<sturmname\>} <PolSturmNbOfIsolatedZeros>`.
1818
1819 Furthermore
1820 :ref:`\\PolSturmNbOfRootsOf{\<sturmname\>}\\LessThanOrEqualTo{\<value\>} <PolSturmNbOfRootsOfLessThanOrEqualTo>` and
1821 :ref:`\\PolSturmNbOfRootsOf{\<sturmname\>}\\LessThanOrEqualToExpr{\<num. expr.\>} <PolSturmNbOfRootsOfLessThanOrEqualToExpr>`.
1822 will expandably compute respectively the number of real roots at
1823 most equal to ``value`` or ``expression``, and the same but with
1824 multiplicities.
1825
1826 These variables and macros are automatically updated in case of
1827 subsequent usage of :ref:`\\PolRefineInterval*{\<sturmname\>}{\<index\>} <PolRefineInterval*>` or
1828 other localization improving macros.
1829
1830 .. note::
1831
1832 The current polexpr implementation defines the xintexpr_ variables
1833 and xinttools_ arrays as described above with global scope. On the
1834 other hand the Sturm sequence polynomials obey the current scope.
1835
1836 This is perhaps a bit inconsistent and may change in future.
1837
1838 .. note::
1839
1840 The results are exact
1841 bounds for the mathematically exact real roots.
1842
1843 Future releases will perhaps also provide macros based on Newton
1844 or Regula Falsi methods. Exact computations with such methods
1845 lead however quickly to very big fractions, and this forces usage
1846 of some rounding scheme for the abscissas if computation times
1847 are to remain reasonable. This raises issues of its own, which
1848 are studied in numerical mathematics.
1849
1850 .. _PolSturmIsolateZeros*:
1851
1852 ``\PolSturmIsolateZeros*{}``
1853 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1854
1855 Syntax: ``\PolSturmIsolateZeros*{<sturmname>}``
1856
1857 The macro does the same as :ref:`\\PolSturmIsolateZeros{\<sturmname\>} <PolSturmIsolateZeros>` and
1858 then in addition it does the extra work to determine all
1859 multiplicities of the real roots.
1860
1861 After execution,
1862 :ref:`\\PolSturmIsolatedZeroMultiplicity{\<sturmname\>}{\<index\>} <PolSturmIsolatedZeroMultiplicity>` expands
1863 to the multiplicity of the root located in the ``index``\ -th
1864 interval (intervals are enumerated from left to right, with index
1865 starting at ``1``).
1866
1867 Furthermore, if for example the ``<sturmname>`` is ``S``, xintexpr_
1868 variables ``SM_1``, ``SM_2``... hold the multiplicities thus
1869 computed.
1870
1871 .. note::
1872
1873 Somewhat counter-intuitively, it is not necessary to have
1874 executed the :ref:`\\PolToSturm* <PolToSturm*>`
1875 starred variant: during its
1876 execution, :ref:`\\PolToSturm <PolToSturm>`,
1877 even though it does not declare the
1878 non-square-free Sturm chain polynomials as user-level genuine
1879 polynomials, stores their data in private macros.
1880
1881 See ``The degree nine polynomial with 0.99, 0.999, 0.9999 as triple
1882 roots`` example in ``polexpr-examples.pdf``.
1883
1884 .. _PolSturmIsolateZerosAndGetMultiplicities:
1885
1886 ``\PolSturmIsolateZerosAndGetMultiplicities{}``
1887 ***********************************************
1888
1889 Syntax: ``\PolSturmIsolateZerosAndGetMultiplicities{<sturmname>}``
1890
1891 This is another name for :ref:`\\PolSturmIsolateZeros*{\<sturmname\>} <PolSturmIsolateZeros*>`.
1892
1893 .. _PolSturmIsolateZeros**:
1894
1895 ``\PolSturmIsolateZeros**{}``
1896 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1897
1898 Syntax: ``\PolSturmIsolateZeros**{<sturmname>}``
1899
1900 The macro does the same as :ref:`\\PolSturmIsolateZeros*{\<sturmname\>} <PolSturmIsolateZeros*>` and
1901 in addition it does the extra work to determine all the *rational*
1902 roots.
1903
1904 .. note::
1905
1906 After execution of this macro, a root is "known" if and only if
1907 it is rational.
1908
1909 Furthermore, primitive polynomial ``sturmname_sqf_norr`` is created
1910 to match the (square-free) ``sturmname_0`` from which all rational
1911 roots have been removed. The number of distinct rational roots is
1912 thus the difference between the degrees of these two polynomials
1913 (see also :ref:`\\PolSturmNbOfRationalRoots{\<sturmname\>}
1914 <PolSturmNbOfRationalRoots>`).
1915
1916 And ``sturmname_norr`` is ``sturmname_0_`` from which all rational
1917 roots have been removed, i.e. it contains the irrational roots of
1918 the original polynomial, with the same multiplicities.
1919
1920 See ``A degree five polynomial with three rational
1921 roots`` in ``polexpr-examples.pdf``.
1922
1923 .. _PolSturmIsolateZerosGetMultiplicitiesAndRationalRoots:
1924
1925 ``\PolSturmIsolateZerosGetMultiplicitiesAndRationalRoots``
1926 **********************************************************
1927
1928 Syntax: ``\PolSturmIsolateZerosGetMultiplicitiesAndRationalRoots``
1929
1930 This is another name for :ref:`\\PolSturmIsolateZeros**{\<sturmname\>} <PolSturmIsolateZeros**>`.
1931
1932 .. _PolSturmIsolateZerosAndFindRationalRoots:
1933
1934 ``\PolSturmIsolateZerosAndFindRationalRoots{}``
1935 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1936
1937 Syntax: ``\PolSturmIsolateZerosAndFindRationalRoots{<sturmname>}``
1938
1939 This works exactly like :ref:`\\PolSturmIsolateZeros**{\<sturmname\>} <PolSturmIsolateZeros**>`
1940 (inclusive of declaring the polynomials ``sturmname_sqf_norr`` and
1941 ``sturmname_norr`` with no rational roots) except that it does *not*
1942 compute the multiplicities of the *non-rational* roots.
1943
1944 .. note::
1945
1946 There is no macro to find the rational roots but not compute
1947 their multiplicities at the same time.
1948
1949 .. attention::
1950
1951 This macro does *not* define xintexpr_ variables
1952 ``sturmnameM_1``, ``sturmnameM_2``, ... holding the
1953 multiplicities and it leaves the multiplicity array (whose accessor
1954 is :ref:`\\PolSturmIsolatedZeroMultiplicity{\<sturmname\>}{\<index\>} <PolSturmIsolatedZeroMultiplicity>`) into
1955 a broken state, as all non-rational roots will supposedly have
1956 multiplicity one. This means that the output of
1957 `\\PolPrintIntervals* <PolPrintIntervals*_>`_ will be
1958 erroneous regarding the multiplicities of irrational roots.
1959
1960 I decided to document it because finding multiplicities of the
1961 non rational roots is somewhat costly, and one may be interested
1962 only into finding the rational roots (of course random
1963 polynomials with integer coefficients will not have *any*
1964 rational root anyhow).
1965
1966
1967 .. _PolRefineInterval*:
1968
1969 ``\PolRefineInterval*{}{}``
1970 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1971
1972 Syntax: ``\PolRefineInterval*{<sturmname>}{<index>}``
1973
1974 The ``index``\ -th interval (starting indexing at one) is further
1975 subdivided as many times as is necessary in order for the newer
1976 interval to have both its end-points distinct from the end-points of
1977 the original interval. As a consequence, the ``k``\ th root is then
1978 strictly separated from the other roots.
1979
1980 .. _PolRefineInterval[]:
1981
1982 ``\PolRefineInterval[]{}{}``
1983 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1984
1985 Syntax: ``\PolRefineInterval[N]{<sturmname>}{<index>}``
1986
1987 The ``index``\ -th interval (starting count at one) is further
1988 subdivided once, reducing its length by a factor of 10. This is done
1989 ``N`` times if the optional argument ``[N]`` is present.
1990
1991 .. _PolEnsureIntervalLength:
1992
1993 ``\PolEnsureIntervalLength{}{}{}``
1994 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1995
1996 Syntax: ``\PolEnsureIntervalLength{<sturmname>}{<index>}{<exponent>}``
1997
1998 The ``index``\ -th interval is subdivided until its length becomes at
1999 most ``10^E``. This means (for ``E<0``) that the first ``-E`` digits
2000 after decimal mark of the ``k``\ th root will then be known exactly.
2001
2002 .. _PolEnsureIntervalLengths:
2003
2004 ``\PolEnsureIntervalLengths{}{}``
2005 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2006
2007 Syntax: ``\PolEnsureIntervalLengths{<sturmname>}{<exponent>}``
2008
2009 The intervals as obtained from ``\PolSturmIsolateZeros`` are (if
2010 necessary) subdivided further by (base 10) dichotomy in order for
2011 each of them to have length at most ``10^E``.
2012
2013 This means that decimal expansions of all roots will be known with
2014 ``-E`` digits (for ``E<0``) after decimal mark.
2015
2016 .. _PolSetToSturmChainSignChangesAt:
2017
2018 ``\PolSetToSturmChainSignChangesAt{}{}{}``
2019 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020
2021 Syntax: ``\PolSetToSturmChainSignChangesAt{\foo}{<sturmname>}{<value>}``
2022
2023 Sets macro ``\foo`` to store the number of sign changes in the
2024 already computed normalized Sturm chain with name prefix
2025 ``<sturmname>``, at location ``<value>`` (which must be in format as
2026 acceptable by the xintfrac_ macros.)
2027
2028 The definition is made with global scope. For local scope, use
2029 ``[\empty]`` as extra optional argument.
2030
2031 One can use this immediately after creation of the Sturm chain.
2032
2033 .. _PolSetToNbOfZerosWithin:
2034
2035 ``\PolSetToNbOfZerosWithin{}{}{}{}``
2036 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2037
2038 Syntax: ``\PolSetToNbOfZerosWithin{\foo}{<sturmname>}{<value_left>}{<value_right>}``
2039
2040 Sets, assuming the normalized Sturm chain has been already computed,
2041 macro ``\foo`` to store the number of roots of ``sturmname_0`` in
2042 the interval ``(value_left, value_right]``. The macro first
2043 re-orders end-points if necessary for ``value_left <= value_right``
2044 to hold.
2045
2046 In accordance to `Sturm Theorem`_ this is computed as the difference
2047 between the number of sign changes of the Sturm chain at ``value_right``
2048 and the one at ``value_left``.
2049
2050 The definition is made with global scope. For local scope, use
2051 ``[\empty]`` as extra optional argument.
2052
2053 One can use this immediately after creation of a Sturm chain.
2054
2055 See also the expandable
2056 :ref:`\\PolSturmNbOfRootsOf{\<sturmname\>}\\LessThanOrEqualTo{value} <PolSturmNbOfRootsOfLessThanOrEqualTo>`,
2057 which however requires prior execution of `\\PolSturmIsolateZeros
2058 <PolSturmIsolateZeros_>`_.
2059
2060 See also the expandable
2061 :ref:`\\PolSturmNbWithMultOfRootsOf{\<sturmname\>}\\LessThanOrEqualTo{value} <PolSturmNbWithMultOfRootsOfLessThanOrEqualTo>`
2062 which requires prior execution of
2063 `\\PolSturmIsolateZeros* <PolSturmIsolateZeros*_>`_.
2064
2065 .. _PolPrintIntervals:
2066
2067 Displaying the found roots: ``\PolPrintIntervals[<varname>]{}``
2068 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2069
2070 Syntax: ``\PolPrintIntervals[<varname>]{<sturmname>}``
2071
2072 This is a convenience macro which prints the bounds for the roots
2073 ``Z_1``, ``Z_2``, ... (the optional argument ``varname`` allows to
2074 specify a replacement for the default ``Z``). This will be done (by
2075 default) in a
2076 math mode ``array``, one interval per row, and pattern ``rcccl``,
2077 where the second and fourth column hold the ``<`` sign, except when
2078 the interval reduces to a singleton, which means the root is known
2079 exactly.
2080
2081 .. note::
2082
2083 The explanations here and in this section are for LaTeX. With
2084 other TeX macro formats, the LaTeX syntax such as for example
2085 ``\begin{array}{rcccl}`` which appears in the documentation here
2086 is actually replaced with quasi-equivalent direct use of TeX
2087 primitives.
2088
2089 The next macros which govern its output.
2090
2091 .. _PolPrintIntervalsNoRealRoots:
2092
2093 ``\PolPrintIntervalsNoRealRoots``
2094 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2095
2096 Executed in place of an ``array`` environment, when there are no
2097 real roots. Default definition::
2098
2099 \newcommand\PolPrintIntervalsNoRealRoots{}
2100
2101 .. _PolPrintIntervalsBeginEnv:
2102
2103 ``\PolPrintIntervalsBeginEnv``
2104 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2105
2106 Default definition (given here for LaTeX, Plain has a variant)::
2107
2108 \newcommand\PolPrintIntervalsBeginEnv{\[\begin{array}{rcccl}}
2109
2110 A simpler ``center`` environment provides a straightforward way to
2111 obtain a display allowing pagebreaks. Of course redefinitions must
2112 at any rate be kept in sync with `\\PolPrintIntervalsKnownRoot`_ and
2113 `\\PolPrintIntervalsUnknownRoot`_.
2114
2115 Prior to ``0.8.6`` it was not possible to use here for example
2116 ``\begin{align}`` due to the latter executing twice in contents.
2117
2118
2119 .. _PolPrintIntervalsEndEnv:
2120
2121 ``\PolPrintIntervalsEndEnv``
2122 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2123
2124 Default definition::
2125
2126 \newcommand\PolPrintIntervalsEndEnv{\end{array}\]}
2127
2128 .. _PolPrintIntervalsRowSeparator:
2129
2130 ``\PolPrintIntervalsRowSeparator``
2131 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2132
2133 Expands by default to ``\\`` with LaTeX and to ``\cr`` with Plain
2134
2135 Added at ``0.8.6``.
2136
2137 .. _PolPrintIntervalsKnownRoot:
2138
2139 ``\PolPrintIntervalsKnownRoot``
2140 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2141
2142 Default definition::
2143
2144 \newcommand\PolPrintIntervalsKnownRoot{%
2145 &&\PolPrintIntervalsTheVar_{\PolPrintIntervalsTheIndex}%
2146 &=&\PolPrintIntervalsPrintExactZero
2147 }
2148
2149 .. _PolPrintIntervalsUnknownRoot:
2150
2151 ``\PolPrintIntervalsUnknownRoot``
2152 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2153
2154 Default definition::
2155
2156 \newcommand\PolPrintIntervalsUnknownRoot{%
2157 \PolPrintIntervalsPrintLeftEndPoint&<&%
2158 \PolPrintIntervalsTheVar_{\PolPrintIntervalsTheIndex}&<&%
2159 \PolPrintIntervalsPrintRightEndPoint
2160 }
2161
2162
2163 .. _PolPrintIntervalsPrintExactZero:
2164
2165 ``\PolPrintIntervalsPrintExactZero``
2166 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2167
2168 Default definition::
2169
2170 \newcommand\PolPrintIntervalsPrintExactZero{\PolPrintIntervalsTheLeftEndPoint}
2171
2172
2173 .. _PolPrintIntervalsPrintLeftEndPoint:
2174
2175 ``\PolPrintIntervalsPrintLeftEndPoint``
2176 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2177
2178 Default definition::
2179
2180 \newcommand\PolPrintIntervalsPrintLeftEndPoint{\PolPrintIntervalsTheLeftEndPoint}
2181
2182 .. _PolPrintIntervalsPrintRightEndPoint:
2183
2184 ``\PolPrintIntervalsPrintRightEndPoint``
2185 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2186
2187 Default definition is::
2188
2189 \newcommand\PolPrintIntervalsPrintRightEndPoint{\PolPrintIntervalsTheRightEndPoint}
2190
2191 .. _PolPrintIntervals*:
2192
2193 ``\PolPrintIntervals*[<varname>]{}``
2194 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2195
2196 Syntax: ``\PolPrintIntervals*[<varname>]{<sturmname>}``
2197
2198 This starred variant produces an alternative output (which
2199 displays the root multiplicity), and is provided as an
2200 example of customization.
2201
2202 As replacement for `\\PolPrintIntervalsKnownRoot`_,
2203 `\\PolPrintIntervalsPrintExactZero`_,
2204 `\\PolPrintIntervalsUnknownRoot`_ it uses its own
2205 ``\POL@@PrintIntervals...`` macros. We only reproduce here one
2206 definition::
2207
2208 \newcommand\POL@@PrintIntervalsPrintExactZero{%
2209 \displaystyle
2210 \xintTeXsignedFrac{\PolPrintIntervalsTheLeftEndPoint}%
2211 }%
2212
2213 Multiplicities are printed using this auxiliary macro:
2214
2215 .. _PolPrintIntervalsPrintMultiplicity:
2216
2217 ``\PolPrintIntervalsPrintMultiplicity``
2218 ***************************************
2219
2220 whose default definition is::
2221
2222 \newcommand\PolPrintIntervalsPrintMultiplicity{(\mbox{mult. }\PolPrintIntervalsTheMultiplicity)}
2223
2224
2225 Expandable macros
2226 -----------------
2227
2228 .. note::
2229
2230 At ``0.8`` ``polexpr`` is usable with Plain TeX and not only with
2231 LaTeX. Some examples given in this section may be using LaTeX syntax
2232 such as ``\renewcommand``. Convert to TeX primitives as appropriate
2233 if testing with a non LaTeX macro format.
2234
2235 These macros expand completely in two steps except ``\PolToExpr`` and
2236 ``\PolToFloatExpr`` which need a ``\write``, ``\edef`` or a
2237 ``\csname...\endcsname`` context.
2238
2239 .. _PolToExpr:
2240
2241 ``\PolToExpr{}``
2242 ~~~~~~~~~~~~~~~~
2243
2244 Syntax: ``\PolToExpr{<pol. expr.>}``
2245
2246 Produces expandably [#]_ the string ``coeff_N*x^N+...``, i.e. the
2247 polynomial is using descending powers.
2248
2249 .. [#] requires exhaustive expansion, for example as triggered by
2250 ``\write`` or ``\edef``.
2251
2252 Since ``0.8`` the input is not restricted to be a polynomial name but
2253 is allowed to be an arbitrary expression. Then ``x`` is expected as
2254 indeterminate but this can be customized via `\\PolToExprInVar`_.
2255
2256 The output uses the letter ``x`` by default, this is customizable
2257 via `\\PolToExprVar`_. The default output is compatible both with
2258
2259 - the Maple's input format,
2260
2261 - and the PSTricks ``\psplot[algebraic]`` input format.
2262
2263 Attention that it is not compatible with Python, see further
2264 `\\PolToExprCaret`_ in this context.
2265
2266 The following applies:
2267
2268 - vanishing coefficients are skipped (issue ``\poltoexpralltrue`` to
2269 override this and produce output such as ``x^3+0*x^2+0*x^1+0``),
2270
2271 - negative coefficients are not prefixed by a ``+`` sign (else,
2272 Maple would not be happy),
2273
2274 - coefficients numerically equal to ``1`` (or ``-1``) are present
2275 only via their sign,
2276
2277 - the letter ``x`` is used and the degree one monomial is output as
2278 ``x``, not as ``x^1``.
2279
2280 - (``0.8``) the caret ``^`` is of catcode 12. This means that one
2281 can for convenience typeset in regular text mode, for example
2282 using ``\texttt`` (in LaTeX). But TeX will not know how to break
2283 the expression across end-of-lines anyhow. Formerly ``^`` was
2284 suitable for math mode but as the exponent is not braced this
2285 worked only for polynomials of degrees at most 9. Anyhow this
2286 is not supposed to be a typesetting macro.
2287
2288 Complete customization is possible, see the next macros. Any user
2289 redefinition must maintain the expandability property.
2290
2291 .. _PolToExprVar:
2292
2293 ``\PolToExprVar``
2294 ^^^^^^^^^^^^^^^^^
2295
2296 Defaults to ``x``. The letter used in the macro output.
2297
2298
2299 .. _PolToExprInVar:
2300
2301 ``\PolToExprInVar``
2302 ^^^^^^^^^^^^^^^^^^^
2303
2304 Defaults to ``x``: the letter used as the polynomial indeterminate
2305 in the macro input::
2306
2307 \def\PolToExprInVar{x}% (default)
2308
2309 Recall that declared polynomials are more efficiently used in
2310 algebraic expressions without the ``(x)``, i.e. ``P*Q`` is better
2311 than ``P(x)*Q(x)``. Thus the input, even if an expression, does not
2312 have to contain any ``x``.
2313
2314 (new with ``0.8``)
2315
2316 .. _PolToExprTimes:
2317
2318 ``\PolToExprTimes``
2319 ^^^^^^^^^^^^^^^^^^^
2320
2321 Defaults to ``*``.
2322
2323 .. _PolToExprCaret:
2324
2325 ``\PolToExprCaret``
2326 ^^^^^^^^^^^^^^^^^^^
2327
2328 Defaults to ``^`` of catcode 12. Set it to
2329 expand to ``**`` for Python compatible output.
2330
2331 (new with ``0.8``)
2332
2333 .. _PolToExprCmd:
2334
2335 ``\PolToExprCmd{}``
2336 ^^^^^^^^^^^^^^^^^^^
2337
2338 Syntax: ``\PolToExprCmd{<raw_coeff>}``
2339
2340 Defaults to ``\xintPRaw{\xintRawWithZeros{#1}}``.
2341
2342 This means that the coefficient value is printed-out as a fraction
2343 ``a/b``, skipping the ``/b`` part if ``b`` turns out to be one.
2344
2345 Configure it to be ``\xintPRaw{\xintIrr{#1}}`` if the fractions
2346 must be in irreducible terms.
2347
2348 An alternative is ``\xintDecToString{\xintREZ{#1}}`` which uses
2349 integer or decimal fixed point format such as ``23.0071`` if the
2350 internal representation of the number only has a power of ten as
2351 denominator (the effect of ``\xintREZ`` here is to remove trailing
2352 decimal zeros). The behaviour of ``\xintDecToString`` is not yet
2353 stable for other cases, and for example at time of writing no
2354 attempt is made to identify inputs having a finite decimal expansion
2355 so for example ``23.007/2`` or ``23.007/25`` can appear in output
2356 and not their finite decimal expansion with no denominator.
2357
2358 .. _PolToExprOneTerm:
2359
2360 ``\PolToExprOneTerm{}{}``
2361 ^^^^^^^^^^^^^^^^^^^^^^^^^
2362
2363 Syntax: ``\PolToExprOneTerm{<raw_coeff>}{<exponent>}``
2364
2365 This is the macro which from the coefficient and the exponent
2366 produces the corresponding term in output, such as ``2/3*x^7``.
2367
2368 For its default definition, see the source code. It uses
2369 `\\PolToExprCmd <PolToExprCmd_>`_, `\\PolToExprTimes
2370 <PolToExprTimes_>`_, `\\PolToExprVar <PolToExprVar_>`_ and
2371 `\\PolToExprCaret`_.
2372
2373 .. _PolToExprOneTermStyleA:
2374
2375 ``\PolToExprOneTermStyleA{}{}``
2376 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2377
2378 Syntax: ``\PolToExprOneTermStyleA{<raw_coeff>}{<exponent>}``
2379
2380 This holds the default package meaning of ``\PolToExprOneTerm``.
2381
2382 .. _PolToExprOneTermStyleB:
2383
2384 ``\PolToExprOneTermStyleB{}{}``
2385 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2386
2387 Syntax: ``\PolToExprOneTermStyleB{<raw_coeff>}{<exponent>}``
2388
2389 This holds an alternative meaning, which puts the fractional part of
2390 a coefficient after the monomial, i.e. like this::
2391
2392 2*x^11/3+3*x^8/7-x^5-x^4/4-x^3-x^2/2-2*x+1
2393
2394 `\\PolToExprCmd <PolToExprCmd_>`_ isn't used at all in this style. But
2395 `\\PolToExprTimes <PolToExprTimes_>`_, `\\PolToExprVar
2396 <PolToExprVar_>`_ and `\\PolToExprCaret`_ are obeyed.
2397
2398 To activate it use ``\let\PolToExprOneTerm\PolToExprOneTermStyleB``.
2399 To revert to the package default behaviour, issue
2400 ``\let\PolToExprOneTerm\PolToExprOneTermStyleA``.
2401
2402 .. _PolToExprTermPrefix:
2403
2404 ``\PolToExprTermPrefix{}``
2405 ^^^^^^^^^^^^^^^^^^^^^^^^^^
2406
2407 Syntax: ``\PolToExprTermPrefix{<raw_coeff>}``
2408
2409 It receives as argument the coefficient. Its default behaviour is
2410 to produce a ``+`` if the coefficient is positive, which will thus
2411 serve to separate the monomials in the output. This is to match
2412 the default for :ref:`\\PolToExprCmd{\<raw_coeff\>} <PolToExprCmd>` which in case of a
2413 positive coefficient does not output an explicit ``+`` prefix.
2414
2415 .. _PolToFloatExpr:
2416
2417 ``\PolToFloatExpr{}``
2418 ~~~~~~~~~~~~~~~~~~~~~
2419
2420 Syntax: ``\PolToFloatExpr{<pol. expr.>}``
2421
2422 Similar to :ref:`\\PolToExpr{\<pol. expr.\>} <PolToExpr>` but using
2423 :ref:`\\PolToFloatExprCmd{\<raw_coeff\>} <PolToFloatExprCmd>` which by default rounds and
2424 converts the coefficients to floating point format.
2425
2426 .. note::
2427
2428 This is unrelated to :ref:`\\PolGenFloatVariant{\<polname\>} <PolGenFloatVariant>`:
2429 :ref:`\\PolToFloatExprCmd{\<raw_coeff\>} <PolToFloatExprCmd>` operates on the *exact*
2430 coefficients anew (and may thus produce something else than
2431 the coefficients of the polynomial function acting
2432 in ``\xintfloateval`` if the floating point precision was changed
2433 in between).
2434
2435 Extended at ``0.8`` to accept general expressions as input.
2436
2437 .. _PolToFloatExprOneTerm:
2438
2439 ``\PolToFloatExprOneTerm{}{}``
2440 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2441
2442 Syntax: ``\PolToFloatExprOneTerm{<raw_coeff>}{<exponent>}``
2443
2444 Similar to :ref:`\\PolToExprOneTerm{\<raw_coeff\>}{\<exponent\>} <PolToExprOneTerm>`. But does not treat
2445 especially coefficients equal to plus or minus one.
2446
2447 .. _PolToFloatExprCmd:
2448
2449 ``\PolToFloatExprCmd{}``
2450 ^^^^^^^^^^^^^^^^^^^^^^^^
2451
2452 Syntax: ``\PolToFloatExprCmd{<raw_coeff>}``
2453
2454 The one-argument macro used by ``\PolToFloatExprOneTerm``.
2455 It defaults to ``\xintPFloat{#1}``, which trims trailing
2456 zeroes.
2457
2458 *changed at 0.8.2* Formerly it was using ``\xintFloat``.
2459
2460 .. _PolToExpr*:
2461
2462 ``\PolToExpr*{}``
2463 ~~~~~~~~~~~~~~~~~
2464
2465 Syntax: ``\PolToExpr*{<pol. expr.>}``
2466
2467 Ascending powers: ``coeff_0+coeff_1*x+coeff_2*x^2+...``.
2468
2469 Extended at ``0.8`` to accept general expressions as input.
2470
2471 Customizable with the same macros as for
2472 :ref:`\\PolToExpr{\<pol. expr.\>} <PolToExpr>`.
2473
2474 .. _PolToFloatExpr*:
2475
2476 ``\PolToFloatExpr*{}``
2477 ~~~~~~~~~~~~~~~~~~~~~~
2478
2479 Syntax: ``\PolToFloatExpr*{<pol. expr.>}``
2480
2481 Ascending powers.
2482
2483 Extended at ``0.8`` to accept general expressions as input.
2484
2485 .. _PolNthCoeff:
2486
2487 ``\PolNthCoeff{}{}``
2488 ~~~~~~~~~~~~~~~~~~~~
2489
2490 Syntax: ``\PolNthCoeff{<polname>}{<index>}``
2491
2492 It expands to the raw ``N``-th coefficient (``N=0`` corresponds to
2493 the constant coefficient). If ``N`` is out of range, zero (in its
2494 default xintfrac_ format ``0/1[0]``) is returned.
2495
2496 Negative indices ``N=-1``, ``-2``, ... return the leading
2497 coefficient, sub-leading coefficient, ..., and finally ``0/1[0]``
2498 for ``N<-1-degree``.
2499
2500 .. _PolLeadingCoeff:
2501
2502 ``\PolLeadingCoeff{}``
2503 ~~~~~~~~~~~~~~~~~~~~~~
2504
2505 Syntax: ``\PolLeadingCoeff{<polname>}``
2506
2507 Expands to the leading coefficient.
2508
2509 .. _PolDegree:
2510
2511 ``\PolDegree{}``
2512 ~~~~~~~~~~~~~~~~
2513
2514 Syntax: ``\PolDegree{<polname>}``
2515
2516 It expands to the degree. This is ``-1`` if zero polynomial but this
2517 may change in future. Should it then expand to ``-\infty`` ?
2518
2519 .. _PolIContent:
2520
2521 ``\PolIContent{}``
2522 ~~~~~~~~~~~~~~~~~~
2523
2524 Syntax: ``\PolIContent{<polname>}``
2525
2526 It expands to the contents of the polynomial, i.e. to the positive
2527 fraction such that dividing by this fraction produces a polynomial
2528 with integer coefficients having no common prime divisor.
2529
2530 See `\\PolMakePrimitive <PolMakePrimitive_>`_.
2531
2532 .. _PolToList:
2533
2534 ``\PolToList{}``
2535 ~~~~~~~~~~~~~~~~
2536
2537 Syntax: ``\PolToList{<polname>}``
2538
2539 Expands to ``{coeff_0}{coeff_1}...{coeff_N}`` with ``N`` = degree, and
2540 ``coeff_N`` the leading coefficient
2541 (the zero polynomial does give ``{0/1[0]}`` and not an
2542 empty output.)
2543
2544 .. _PolToCSV:
2545
2546 ``\PolToCSV{}``
2547 ~~~~~~~~~~~~~~~
2548
2549 Syntax: ``\PolToCSV{<polname>}``
2550
2551 Expands to ``coeff_0, coeff_1, coeff_2, ....., coeff_N``, starting
2552 with constant term and ending with leading coefficient. Converse
2553 to :ref:`\\PolFromCSV{\<polname\>}{\<csv\>} <PolFromCSV>`.
2554
2555
2556 .. _PolEvalAtExpr:
2557
2558 ``\PolEval{}\AtExpr{}``
2559 ~~~~~~~~~~~~~~~~~~~~~~~
2560
2561 Syntax: ``\PolEval{<polname>}\AtExpr{<num. expr.>}``
2562
2563 Same output as
2564 ``\xinteval{polname(numerical expression)}``.
2565
2566 .. _PolEvalAt:
2567
2568 ``\PolEval{}\At{}``
2569 ~~~~~~~~~~~~~~~~~~~
2570
2571 Syntax: ``\PolEval{<polname>}\At{<value>}``
2572
2573 Evaluates the polynomial at the given value which must be in (or
2574 expand to) a format acceptable to the xintfrac_ macros.
2575
2576 .. _PolEvalReducedAtExpr:
2577
2578 ``\PolEvalReduced{}\AtExpr{}``
2579 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2580
2581 Syntax: ``\PolEvalReduced{<polname>}\AtExpr{<num. expr.>}``
2582
2583 Same output as ``\xinteval{reduce(polname(numerical expression))}``.
2584
2585 .. _PolEvalReducedAt:
2586
2587 ``\PolEvalReduced{}\At{}``
2588 ~~~~~~~~~~~~~~~~~~~~~~~~~~
2589
2590 Syntax: ``\PolEvalReduced{<polname>}\At{<value>}``
2591
2592 Evaluates the polynomial at the value which must be in (or expand
2593 to) a format acceptable to the xintfrac_ macros, and outputs an
2594 irreducible fraction.
2595
2596 .. _PolFloatEvalAtExpr:
2597
2598 ``\PolFloatEval{}\AtExpr{}``
2599 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2600
2601 Syntax: ``\PolFloatEval{<polname>}\AtExpr{<num. expr.>}``
2602
2603 Same output as ``\xintfloateval{polname(numerical expression)}``.
2604
2605 .. attention::
2606
2607 `\\PolGenFloatVariant <PolGenFloatVariant_>`_ must have
2608 been issued before.
2609
2610 To use the *exact coefficients* with *exactly executed* additions
2611 and multiplications and do the rounding only as the final last step,
2612 the following syntax can be used: [#]_
2613
2614 ::
2615
2616 \xintfloateval{3.27*\xintexpr f(2.53)\relax^2}
2617
2618
2619 .. [#] Cf. xintexpr_ documentation about nested expressions.
2620
2621 .. _PolFloatEvalAt:
2622
2623 ``\PolFloatEval{}\At{}``
2624 ~~~~~~~~~~~~~~~~~~~~~~~~
2625
2626 Syntax: ``\PolFloatEval{<polname>}\At{<value>}``
2627
2628 Evaluates the polynomial at the value which must be in (or expand
2629 to) a format acceptable to the xintfrac_ macros.
2630
2631
2632 Expandable macros in relation to root localization via `Sturm Theorem`_
2633 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2634
2635 .. _PolSturmChainLength:
2636
2637 ``\PolSturmChainLength{}``
2638 ^^^^^^^^^^^^^^^^^^^^^^^^^^
2639
2640 Syntax: ``\PolSturmChainLength{<sturmname>}``
2641
2642 Returns the integer ``N`` such that ``sturmname_N`` is the last one
2643 in the Sturm chain ``sturmname_0``, ``sturmname_1``, ...
2644
2645 See :ref:`\\PolToSturm{\<polname\>}{\<sturmname\>} <PolToSturm>`.
2646
2647 .. _PolSturmIfZeroExactlyKnown:
2648
2649 ``\PolSturmIfZeroExactlyKnown{}{}{}{}``
2650 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2651
2652 Syntax: ``\PolSturmIfZeroExactlyKnown{<sturmname>}{<index>}{T}{F}``
2653
2654 Executes ``T`` if the ``index``\ -th interval reduces to a singleton,
2655 i.e. the root is known exactly, else ``F``.
2656
2657 .. vieux commentaire
2658
2659 ``index`` is allowed to be something like ``1+2*3`` as it is fed
2660 to ``\the\numexpr...\relax``.
2661
2662 .. _PolSturmIsolatedZeroLeft:
2663
2664 ``\PolSturmIsolatedZeroLeft{}{}``
2665 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2666
2667 Syntax: ``\PolSturmIsolatedZeroLeft{<sturmname>}{<index>}``
2668
2669 Expands to the left end-point for the ``index``\ -th interval, as
2670 computed by some earlier :ref:`\\PolSturmIsolateZeros{\<sturmname\>} <PolSturmIsolateZeros>`.
2671
2672 .. note::
2673
2674 Execution of this macro after some
2675 `\\PolRefineInterval{<sturmname>}{<index>} <PolRefineInterval[]_>`_
2676 will take into account the now known tighter bounds.
2677
2678 The value is pre-formatted using `\\PolDecTostring
2679 <PolDecToString_>`_.
2680
2681 .. _PolSturmIsolatedZeroRight:
2682
2683 ``\PolSturmIsolatedZeroRight{}{}``
2684 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2685
2686 Syntax: ``\PolSturmIsolatedZeroRight{<sturmname>}{<index>}``
2687
2688 Expands to the right end-point for the ``index``\ -th interval as
2689 computed by some earlier :ref:`\\PolSturmIsolateZeros{\<sturmname\>} <PolSturmIsolateZeros>` and
2690 possibly refined afterwards.
2691
2692 The value is pre-formatted using `\\PolDecTostring
2693 <PolDecToString_>`_.
2694
2695 .. _PolSturmIsolatedZeroMultiplicity:
2696
2697 ``\PolSturmIsolatedZeroMultiplicity{}{}``
2698 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2699
2700 Syntax: ``\PolSturmIsolatedZeroMultiplicity{<sturmname>}{<index>}``
2701
2702 Expands to the multiplicity of the unique root contained in the
2703 ``index``\ -th interval.
2704
2705 .. attention::
2706
2707 A prior execution of :ref:`\\PolSturmIsolateZeros*{\<sturmname\>} <PolSturmIsolateZeros*>` is mandatory.
2708
2709 See ``The degree nine polynomial with 0.99, 0.999, 0.9999 as triple
2710 roots`` in ``polexpr-examples.pdf``.
2711
2712 .. _PolSturmNbOfIsolatedZeros:
2713
2714 ``\PolSturmNbOfIsolatedZeros{}``
2715 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2716
2717 Syntax: ``\PolSturmNbOfIsolatedZeros{<sturmname>}``
2718
2719 Expands to the number of real roots of the polynomial
2720 ``<sturmname>_0``, i.e. the number of distinct real roots of the
2721 polynomial originally used to create the Sturm chain via
2722 :ref:`\\PolToSturm{\<polname\>}{\<sturmname\>} <PolToSturm>`.
2723
2724 .. warning::
2725
2726 The next few macros counting roots, with or without multiplicities,
2727 less than or equal to some value, are under evaluation and may be
2728 removed from the package if their utility is judged to be not high
2729 enough. They can be re-coded at user level on the basis of the other
2730 documented package macros anyway.
2731
2732 .. _PolSturmNbOfRootsOfLessThanOrEqualTo:
2733
2734 ``\PolSturmNbOfRootsOf{}\LessThanOrEqualTo{}``
2735 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2736
2737 Syntax: ``\PolSturmNbOfRootsOf{<sturmname>}\LessThanOrEqualTo{<value>}``
2738
2739 Expands to the number of distinct roots (of the polynomial used to
2740 create the Sturm chain) less than or equal to the ``value`` (i.e. a
2741 number of fraction recognizable by the xintfrac_ macros).
2742
2743 .. attention::
2744
2745 :ref:`\\PolSturmIsolateZeros{\<sturmname\>} <PolSturmIsolateZeros>` must have been executed
2746 beforehand.
2747
2748 And the argument is a ``<sturmname>``, not a ``<polname>`` (this is
2749 why the macro contains Sturm in its name), simply to be reminded
2750 of the above constraint.
2751
2752 .. _PolSturmNbOfRootsOfLessThanOrEqualToExpr:
2753
2754 ``\PolSturmNbOfRootsOf{}\LessThanOrEqualToExpr{}``
2755 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2756
2757 Syntax: ``\PolSturmNbOfRootsOf{<sturmname>}\LessThanOrEqualToExpr{<num. expr.>}``
2758
2759 Expands to the number of distinct roots (of the polynomial
2760 used to create the Sturm chain) which are less than or equal to the
2761 given numerical expression.
2762
2763 .. attention::
2764
2765 :ref:`\\PolSturmIsolateZeros{\<sturmname\>} <PolSturmIsolateZeros>` must have been executed
2766 beforehand.
2767
2768 .. _PolSturmNbWithMultOfRootsOfLessThanOrEqualTo:
2769
2770 ``\PolSturmNbWithMultOfRootsOf{}\LessThanOrEqualTo{}``
2771 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2772
2773 Syntax: ``\PolSturmNbWithMultOfRootsOf{<sturmname>}\LessThanOrEqualTo{<value>}``
2774
2775 Expands to the number counted with multiplicities of the roots (of
2776 the polynomial used to create the Sturm chain) which are less than
2777 or equal to the given ``value``.
2778
2779 .. attention::
2780
2781 :ref:`\\PolSturmIsolateZeros*{\<sturmname\>} <PolSturmIsolateZeros*>` (or the double starred
2782 variant) must have been executed beforehand.
2783
2784 .. _PolSturmNbWithMultOfRootsOfLessThanOrEqualToExpr:
2785
2786 ``\PolSturmNbWithMultOfRootsOf{}\LessThanOrEqualToExpr{}``
2787 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2788
2789 Syntax: ``\PolSturmNbWithMultOfRootsOf{<sturmname>}\LessThanOrEqualToExpr{<num. expr.>}``
2790
2791 Expands to the total number of roots (counted with multiplicities)
2792 which are less than or equal to the given ``expression``.
2793
2794 .. attention::
2795
2796 :ref:`\\PolSturmIsolateZeros*{\<sturmname\>} <PolSturmIsolateZeros*>` (or the double starred
2797 variant) must have been executed beforehand.
2798
2799 .. _PolSturmNbOfRationalRoots:
2800
2801 ``\PolSturmNbOfRationalRoots{}``
2802 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2803
2804 Syntax: ``\PolSturmNbOfRationalRoots{<sturmname>}``
2805
2806 Expands to the number of rational roots (without multiplicities).
2807
2808 .. attention::
2809
2810 :ref:`\\PolSturmIsolateZeros**{\<sturmname\>} <PolSturmIsolateZeros**>` must have been executed
2811 beforehand.
2812
2813 .. _PolSturmNbOfRationalRootsWithMultiplicities:
2814
2815 ``\PolSturmNbOfRationalRootsWithMultiplicities{}``
2816 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2817
2818 Syntax: ``\PolSturmNbOfRationalRootsWithMultiplicities{<sturmname>}``
2819
2820 Expands to the number of rational roots (counted with multiplicities).
2821
2822 .. attention::
2823
2824 :ref:`\\PolSturmIsolateZeros**{\<sturmname\>} <PolSturmIsolateZeros**>` must have been executed
2825 beforehand.
2826
2827 .. _PolSturmRationalRoot:
2828
2829 ``\PolSturmRationalRoot{}{}``
2830 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2831
2832 Syntax: ``\PolSturmRationalRoot{<sturmname>}{<k>}``
2833
2834 Expands to the k-th rational root. They are enumerated from left to
2835 right starting at index value ``1``.
2836
2837 .. attention::
2838
2839 :ref:`\\PolSturmIsolateZeros**{\<sturmname\>} <PolSturmIsolateZeros**>` must have been executed
2840 beforehand.
2841
2842 .. _PolSturmRationalRootIndex:
2843
2844 ``\PolSturmRationalRootIndex{}{}``
2845 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2846
2847 Syntax: ``\PolSturmRationalRootIndex{<sturmname>}{<k>}``
2848
2849 Expands to the index of the ``k``\ th rational root as part of the
2850 ordered real roots (counted without multiplicities). So
2851 :ref:`\\PolSturmRationalRoot{\<sturmname\>}{\<k\>} <PolSturmRationalRoot>` is equivalent to
2852 this nested call::
2853
2854 \PolSturmIsolatedZeroLeft{<sturmname>}{\PolSturmRationalRootIndex{<sturmname>}{<k>}}
2855
2856 .. attention::
2857
2858 :ref:`\\PolSturmIsolateZeros**{\<sturmname\>} <PolSturmIsolateZeros**>` must have been executed
2859 beforehand.
2860
2861 .. _PolSturmRationalRootMultiplicity:
2862
2863 ``\PolSturmRationalRootMultiplicity{}{}``
2864 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2865
2866 Syntax: ``\PolSturmRationalRootMultiplicity{<sturmname>}{<k>}``
2867
2868 Expands to the multiplicity of the ``k``\ th rational root.
2869
2870 .. attention::
2871
2872 :ref:`\\PolSturmIsolateZeros**{\<sturmname\>} <PolSturmIsolateZeros**>` must have been executed
2873 beforehand.
2874
2875 .. _PolIntervalWidth:
2876
2877 ``\PolIntervalWidth{}{}``
2878 ^^^^^^^^^^^^^^^^^^^^^^^^^
2879
2880 Syntax: ``\PolIntervalWidth{<sturmname>}{<index>}``
2881
2882 The ``10^E`` width of the current ``index``\ -th root localization
2883 interval. Output is in xintfrac_ raw ``1/1[E]`` format (if not zero).
2884
2885 .. renommer cela en \PolSturmIntervalWidth ?
2886
2887 Expandable macros for use within execution of ``\PolPrintIntervals``
2888 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2889
2890 These macros are for usage within custom user redefinitions of
2891 `\\PolPrintIntervalsKnownRoot`_, `\\PolPrintIntervalsUnknownRoot`_, or
2892 in redefinitions of `\PolPrintIntervalsPrintExactZero`_ (used in the
2893 default for the former) and of `\\PolPrintIntervalsPrintLeftEndPoint`_,
2894 `\\PolPrintIntervalsPrintRightEndPoint`_ (used in the default for the
2895 latter).
2896
2897 .. vieux commentaire
2898
2899 Some macros formerly mentioned here got removed at 0.7:
2900 ``\PolPrintIntervalsTheEndPoint``,
2901 ``\PolIfEndPointIsPositive{T}{F}``,
2902 ``\PolIfEndPointIsNegative{T}{F}``,
2903 ``\PolIfEndPointIsZero{T}{F}``.
2904
2905 .. _PolPrintIntervalsTheVar:
2906
2907 ``\PolPrintIntervalsTheVar``
2908 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2909
2910 Expands to the name (default ``Z``) used for representing the roots,
2911 which was passed as optional argument ``varname`` to
2912 :ref:`\\PolPrintIntervals[varname]{\<sturmname\>} <PolPrintIntervals>`.
2913
2914 .. _PolPrintIntervalsTheIndex:
2915
2916 ``\PolPrintIntervalsTheIndex``
2917 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2918
2919 Expands to the index of the considered interval (indexing starting
2920 at 1 for the leftmost interval).
2921
2922 .. _PolPrintIntervalsTheSturmName:
2923
2924 ``\PolPrintIntervalsTheSturmName``
2925 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2926
2927 Expands to the argument which was passed as ``<sturmname>`` to
2928 :ref:`\\PolPrintIntervals[varname]{\<sturmname\>} <PolPrintIntervals>`.
2929
2930 .. _PolPrintIntervalsTheLeftEndPoint:
2931
2932 ``\PolPrintIntervalsTheLeftEndPoint``
2933 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2934
2935 The left end point of the interval, as would be produced by
2936 `\\PolSturmIsolatedZeroLeft <PolSturmIsolatedZeroLeft_>`_ if it was
2937 used with arguments the Sturm chain name and interval index returned
2938 by `\\PolPrintIntervalsTheSturmName`_ and
2939 `\\PolPrintIntervalsTheIndex`_.
2940
2941 .. _PolPrintIntervalsTheRightEndPoint:
2942
2943 ``\PolPrintIntervalsTheRightEndPoint``
2944 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2945
2946 The right end point of the interval, as would be produced by
2947 `\\\PolSturmIsolatedZeroRight <PolSturmIsolatedZeroRight_>`_ for
2948 this Sturm chain name and index.
2949
2950 .. _PolPrintIntervalsTheMultiplicity:
2951
2952 ``\PolPrintIntervalsTheMultiplicity``
2953 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2954
2955 The multiplicity of the unique root within the interval of index
2956 `\\PolPrintIntervalsTheIndex`_. Makes sense only if the starred (or
2957 double-starred) variant of `\\PolSturmIsolateZeros
2958 <PolSturmIsolateZeros_>`_ was used earlier.
2959
2960
2961 TeX Booleans (with names enacting their defaults)
2962 -------------------------------------------------
2963
2964 .. _xintverbosefalse:
2965
2966 ``\xintverbosefalse``
2967 ~~~~~~~~~~~~~~~~~~~~~
2968
2969 This is actually an xintexpr_ configuration. Setting it to
2970 ``true`` triggers the writing of information to the log when new
2971 polynomial or scalar variables are defined.
2972
2973 .. caution::
2974
2975 The macro and variable meanings as written to the log are to be
2976 considered unstable and undocumented internal structures.
2977
2978 .. _polnewpolverbosefalse:
2979
2980 ``\polnewpolverbosefalse``
2981 ~~~~~~~~~~~~~~~~~~~~~~~~~~
2982
2983 When ``\poldef`` is used, both a variable and a function are
2984 defined. The default ``\polnewpolverbosefalse`` setting suppresses
2985 the print-out to the log and terminal of the function macro meaning,
2986 as it only duplicates the information contained in the variable
2987 which is already printed out to the log and terminal.
2988
2989 However :ref:`\\PolGenFloatVariant{\<polname\>} <PolGenFloatVariant>`
2990 does still print out the information relative to the polynomial
2991 function it defines for use in ``\xintfloateval{}`` as there is no
2992 float polynomial variable, only the
2993
2994 function, and it is the only way to see its rounded coefficients
2995 (``\xintverbosefalse`` suppresses also that info).
2996
2997 If set to ``true``, it overrides in both cases
2998 ``\xintverbosefalse``. The setting only affects polynomial
2999 declarations. Scalar variables such as those holding information on
3000 roots obey only the ``\xintverbose...`` setting.
3001
3002 (new with ``0.8``)
3003
3004 .. _poltypesetallfalse:
3005
3006 ``\poltypesetallfalse``
3007 ~~~~~~~~~~~~~~~~~~~~~~~
3008
3009 If ``true``, `\\PolTypeset <PolTypeset_>`_ will also typeset the vanishing
3010 coefficients.
3011
3012
3013 .. _poltoexprallfalse:
3014
3015 ``\poltoexprallfalse``
3016 ~~~~~~~~~~~~~~~~~~~~~~
3017
3018 If ``true``, :ref:`\\PolToExpr{\<pol. expr.\>} <PolToExpr>` and
3019 :ref:`\\PolToFloatExpr{\<pol. expr.\>} <PolToFloatExpr>` will also
3020 include the vanishing coefficients in their outputs.
3021
3022
3023 Utilities
3024 ---------
3025
3026 .. _PolDecToString:
3027
3028 ``\PolDecToString{}``
3029 ~~~~~~~~~~~~~~~~~~~~~
3030
3031 Syntax: ``\PolDecToString{decimal number}``
3032
3033 This is a utility macro to print decimal numbers. It is an alias
3034 for ``\xintDecToString``.
3035
3036 .. vieux commentaire
3037
3038 It has been
3039 backported to xintfrac_ (release ``1.3`` of ``2018/03/01``) under
3040 the name ``\xintDecToString``, and the ``polexpr`` macro is simply
3041 now an alias to it.
3042
3043 ..
3044
3045 For example
3046 ``\PolDecToString{123.456e-8}`` will expand to ``0.00000123456``
3047 and ``\PolDecToString{123.450e-8}`` to ``0.00000123450`` which
3048 illustrates that trailing zeros are not trimmed.
3049
3050 To trim trailing zeroes, one can use
3051 ``\PolDecToString{\xintREZ{#1}}``.
3052
3053 Attention that a.t.t.o.w. if the argument is for example ``1/5``, the
3054 macro does not identify that this is in fact a number with a finite
3055 decimal expansion and it outputs ``1/5``. See current xintfrac_
3056 documentation.
3057
3058 .. vieux commentaire
3059
3060 The precise behaviour of this macro may evolve in future releases of
3061 xintexpr_.
3062
3063 ..
3064
3065
3066 .. _polexprsetup:
3067
3068 ``\polexprsetup{key=val,...}``
3069 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3070
3071 Serves to customize the package. Currently only two keys are
3072 recognized:
3073
3074 - ``norr``: the postfix that :ref:`\\PolSturmIsolateZeros**{\<sturmname\>} <PolSturmIsolateZeros**>`
3075 should append to ``<sturmname>`` to declare the primitive polynomial
3076 obtained from original one after removal of all rational roots.
3077 The default value is ``_norr`` (standing for “no rational roots”).
3078
3079 - ``sqfnorr``: the postfix that :ref:`\\PolSturmIsolateZeros**{\<sturmname\>} <PolSturmIsolateZeros**>`
3080 should append to ``<sturmname>`` to declare the primitive polynomial
3081 obtained from original one after removal of all rational roots and
3082 suppression of all multiplicities.
3083 The default value is ``_sqf_norr`` (standing for “square-free with
3084 no rational roots”).
3085
3086 The package executes ``\polexprsetup{norr=_norr,
3087 sqfnorr=_sqf_norr}`` as default.
3088
3089
3090 Technicalities
3091 --------------
3092
3093 - Do not use the underscore ``_`` as the *first character* of a
3094 polynomial name, even if of catcode letter. This may cause an
3095 infinite loop.
3096
3097 - The ``@`` is allowed in the names of polynomials, independently of
3098 whether it is of catcode letter or other. In defining macros which
3099 will use ``\poldef`` to create polynomials it seems reasonable to
3100 adopt the convention that ``@`` as *first* character in polynomial
3101 names is to be reserved to temporary auxiliary polynomials.
3102
3103 .. attention::
3104
3105 Do not use ``@_`` at start of polynomial names. This is reserved for
3106 internal usage by the package.
3107
3108 - Catcodes are set temporarily by `\\poldef <poldef;_>`_ macro to safe
3109 values prior to grab the polynomial expression up to the terminator
3110 ``;``, and also by `\\PolDef <PolDef_>`_ prior to grab the
3111 brace-enclosed polynomial expression. This gives a layer of
3112 protection in case some package (for example the ``babel-french`` module)
3113 has made some characters active. It will fail though if the whole
3114 thing is located inside some definition of a macro done at a time the
3115 characters are active.
3116
3117 - ..
3118
3119 .. attention::
3120
3121 Contrarily to ``\xintdefvar`` and ``\xintdeffunc`` from xintexpr_,
3122 ``\poldef`` uses a naive delimited macro to fetch up to the
3123 expression terminator ``";"``, hence it will be fooled if some
3124 ``;`` is used inside the expression (which is possible as it
3125 appears in some xintexpr_ constructs). Work-around is to use curly
3126 braces around the inner semi-colons, or simpler to use
3127 ``\PolDef``.
3128
3129 - As a consequence of xintfrac_ addition and subtraction always using
3130 least common multiples for the denominators, user-chosen common
3131 denominators (currently) survive additions and multiplications. For
3132 example, this::
3133
3134 \poldef P(x):= 1/2 + 2/2*x + 3/2*x^3 + 4/2*x^4;
3135 \poldef Q(x):= 1/3 + (2/3)x + (3/3)x^3 + (4/3)x^4;
3136 \poldef PQ(x):= P*Q;
3137
3138 gives internally the polynomial::
3139
3140 1/6+4/6*x^1+4/6*x^2+6/6*x^3+20/6*x^4+16/6*x^5+9/6*x^6+24/6*x^7+16/6*x^8
3141
3142 where all coefficients have the same denominator 6. Notice though that
3143 ``\PolToExpr{PQ}`` outputs the ``6/6*x^3`` as ``x^3`` because (by
3144 default) it recognizes and filters out coefficients equal to one or
3145 minus one. One can use for example
3146 ``\PolToCSV{PQ}`` to see the internally stored coefficients.
3147
3148 .. vieux commentaire
3149
3150 prior to ``0.4.1``, ``polexpr`` used to temporarily patch
3151 during the parsing of polynomials the xintfrac_ macros. This
3152 patch was backported to xintexpr_ at release ``1.3``.
3153
3154 - :ref:`\\PolDiff{\<polname_1\>}{\<polname_2\>} <PolDiff>` always applies ``\xintPIrr`` to the
3155 resulting coefficients, which means that fractions are reduced to
3156 lowest terms but ignoring an already separated *power of ten* part ``[N]``
3157 present in the internal representation. This is tentative and may change.
3158
3159 Same remark for :ref:`\\PolAntiDiff{\<polname_1\>}{\<polname_2\>} <PolAntiDiff>`.
3160
3161 - Currently, the package stores all coefficients from index ``0`` to
3162 index equal to the polynomial degree inside a single macro, as a list.
3163 This data structure is obviously very inefficient for polynomials of
3164 high degree and few coefficients (as an example with ``\poldef
3165 f(x):=x^1000 + x^500;`` the subsequent definition ``\poldef g(x):=
3166 f(x)^2;`` will do of the order of 1,000,000 multiplications and
3167 additions involvings only zeroes... which does take time). This
3168 may change in the future.
3169
3170 - As is to be expected internal structures of the package are barely
3171 documented and unstable. Don't use them.
3172
3173
3174 .. _xinttools:
3175 .. _xintfrac:
3176 .. _xint: https://www.ctan.org/pkg/xint
3177
3178 .. _xintexpr: https://www.ctan.org/pkg/xintexpr
3179
3180 .. _xintsession: https://www.ctan.org/pkg/xintsession
3181
3182 .. _Wilkinson polynomial: https://en.wikipedia.org/wiki/Wilkinson%27s_polynomial
3183
3184 .. _Sturm algorithm:
3185 .. _Sturm Theorem: https://en.wikipedia.org/wiki/Sturm%27s_theorem
3186
3187 .. _DocUtils: http://docutils.sourceforge.net/docs/index.html
3188
3189
3190 .. Local variables:
3191 .. sentence-end-double-space: t;
3192 .. End: