0.8.4 (2021/11/01)
Contents
The polexpr 0.8 extensions to the \xintexpr syntax
\poldef polname(letter):= expression using the letter as indeterminate;
\PolDef[<letter>]{<polname>}{<expr. using the letter as indeterminate>}
Non-expandable macros related to the root localization routines
\PolDivide{<polname_1>}{<polname_2>}{<polname_Q>}{<polname_R>}
Expandable macros related to the root localization routines
\PolSturmNbOfRootsOf{<sturmname>}\LessThanOrEqualTo{<value>}
\PolSturmNbOfRootsOf{<sturmname>}\LessThanOrEqualToExpr{<num. expr.>}
\PolSturmNbWithMultOfRootsOf{<sturmname>}\LessThanOrEqualTo{<value>}
\PolSturmNbWithMultOfRootsOf{<sturmname>}\LessThanOrEqualToExpr{<num. expr.>}
Expandable macros for use within execution of \PolPrintIntervals
The package can be used with TeX based formats incorporating the e-TeX primitives. The \expanded primitive available generally since TeXLive 2019 is required.
\input polexpr.sty
with Plain or other non-LaTeX macro formats, or:
\usepackage{polexpr}
with the LaTeX macro format.
The package requires xintexpr 1.4d or later.
Note
Until 0.8 the package only had a LaTeX interface. As a result, parts of this documentation may still give examples using LaTeX syntax such as \newcommand. Please convert to the syntax appropriate to the TeX macro format used if needed.
The package provides a parser \poldef of algebraic polynomial expressions. As it is based on xintexpr the coefficients are allowed to be arbitrary rational numbers.
Once defined, a polynomial is usable by its name either as a numerical function in \xintexpr/\xinteval, or for additional polynomial definitions, or as argument to the package macros. The localization of real roots to arbitrary precision as well as the determination of all rational roots is implemented via such macros.
Since release 0.8, polexpr extends the xintexpr syntax to recognize polynomials as a new variable type (and not only as functions). Functionality which previously was implemented via macros such as the computation of a greatest common divisor is now available directly in \xintexpr, \xinteval or \poldef via infix or functional syntax.
The user must have some understanding of TeX as a macro-expansion based programming interface, and in particular of how \edef differs from \def: functionalities of the package as described in the Expandable macros section are suitable for usage in \edef, \write or \xinteval context. At 0.8 some of these macros have an even more convenient functional interface inside \xinteval, as is described in a dedicated section.
Despite its name \poldef is more to be seen as an \edef although it does not define a TeX macro (at user level); and of course \edef would do usually nothing on the typical input parsed by \poldef which generally has no backslash in it: but if this input does contain macros, they will then be expanded fully and are supposed to produce recognizable syntax elements in this expansion only context.
Note that the def in \poldef reminds us that the macro does some assignments hence is not usable in expandable only context. Its whole point is rather to define entities which, them, can then be used in the expandable only \xinteval (or \poldef) context.
The user must have some familiarity with xintexpr and in particular must know what \xintexpr, \xinttheexpr, \xinteval and \xintfloatexpr, \xintthefloatexpr, \xintfloateval mean and what are the good practices with them.
The user will become quickly aware that exact computations with fractions easily lead to very big ones in very few steps; see \PolReduceCoeffs{<polname>} in this context.
Finally, it is mandatory to read the entire documentation before starting to use the package.
The syntax to define a new polynomial is:
\poldef polname(x):= expression in variable x;
The package is focused on exact computations, so this expression will be parsed by the services of xintexpr and accept arbitrarily big integers or fractions.
If you are interested into numerical evaluations, for example for plotting, it is advisable to use the \xintfloatexpr/\xintfloateval context, as exact evaluations will quickly lead to manipulating numbers with dozens of digits (when the number of digits exceeds five hundreds, computation with xintexpr will become noticeably too slow, if many evaluations need to be done). For the polynomial to be usable as a function in floating point context, an extra step beyond \poldef is required: see \PolGenFloatVariant.
As a rule, the functionalities such as getting the degree, or getting one coefficient, or taking derivatives, etc..., i.e. anything which handles the polynomial as an entity and not only as a numerical function, are only available in the \poldef/\xintexpr/\xinteval context. The \PolGenFloatVariant must be used each time the polynomial gets modified or a new polynomial created out of it, if continuing computations in \xintfloatexpr are to follow. But (see xintexpr documentation) one can always use a sub-expression such as \xintexpr deg(P)\relax as sub-component inside a \xintfloatexpr/\xintfloateval.
Conversely if perhaps the coefficients of your polynomial have become too gigantic and you would like to replace them with some approximation to keep on working in \xinteval, not necessarily \xintfloateval, see \PolMapCoeffs which can be used for example with \xintFloat macro to make the float-rounding applied to the exact coefficients.
In place of x an arbitrary dummy variable is authorized, i.e. per default one a, .., z, A, .., Z (more letters can be declared under Unicode engines).
polname consists of letters, digits, and the _ and ' characters. It must start with a letter: do not use the underscore _ as first character of a polynomial name (even if of catcode letter). No warning is emitted but dire consequences will result.
Hint
The @ is usable too, independently of whether it is of catcode letter or other. This has always been the case, but was not documented by polexpr prior to 0.8, as the author has never found the time to provide some official guidelines on how to name temporary variables and the @ is used already as such internally to package; time has still not yet been found for 0.8 to review the situation but it seems reasonable to recommend at any rate to restrict usage of @ to scratch variables of defined macros and to avoid using it to name document variable.
The colon before the equality sign is optional and its (reasonable) catcode does not matter.
The semi-colon at the end of the expression is mandatory. Some contexts (such as (pdf)LaTeX with babel+frenchb) modify its catcode. If at top level, \poldef resets temporarily the semi-colon catcode before fetching the expression, so is immune to this. There is also naturally no problem either if \poldef is used in the replacement text of some other macro which is defined at a time the ; has its standard catcode, as is the case in LaTeX in the document preamble, even with babel+french loaded.
The semi-colon intervenes in certain xintexpr syntax elements, within parentheses. This (except if the inner semi-colons are hidden within braces: {;}) will break \poldef which, contrarily to xintexpr's \xintdefvar, does not balance parentheses when fetching the semi-colon delimited polynomial expression.
Problems with the semi-colon are avoided via an alternative syntax:
\PolDef[optional letter]{<polname>}{<expr. using letter as indeterminate>}
The \PolDef optional first argument defaults to x and must be used as the indeterminate in the expression.
\poldef f(x):= 1 - x + quo(x^5,1 - x + x^2);
Both parse the polynomial expression, and convert it internally (currently) to the list of its coefficients from the constant term to the highest degree term.
The polynomial can then be used in further polynomial definitions or serve as argument to package macros, or as a variable in various functions which will be described later.
Important
Euclidean quotient is mapped to the function quo() (as shown in the example above), but for backwards compatibility one can currently still use the / infix operator:
\poldef f(x):= 1 - x + x^5/(1 - x + x^2);
Due to precedence rules the first operand is x^5, not of course 1-x+x^5.
Note that (1-x^2)/(1-x) produces 1+x but (1/(1-x))*(1-x^2) produces zero! One also has to be aware of some precedence rules, for example:
\poldef k(x):= (x-1)(x-2)(x-3)(x-4)/(x^2-5x+4);
does compute a degree 2 polynomial because the tacit multiplication ties more than the division operator.
In short, it is safer to use the quo() function which avoids surprises.
Attention!
Tacit multiplication means that 1/2 x^2 skips the space and is treated like 1/(2*x^2). But then it gives zero!
Thus one must use (1/2)x^2 or 1/2*x^2 or (1/2)*x^2 for disambiguation: x - 1/2*x^2 + 1/3*x^3.... It is simpler to move the denominator to the right: x - x^2/2 + x^3/3 - ....
It is worth noting that 1/2(x-1)(x-2) suffers the same issue: xintexpr's tacit multiplication always "ties more", hence this gets interpreted as 1/(2*(x-1)*(x-2)) which gives zero by polynomial division. Thus, use in such cases one of (1/2)(x-1)(x-2), 1/2*(x-1)(x-2) or (x-1)(x-2)/2.
Warning
The package does not currently know rational functions, but in order to leave open this as a future possibility, the usage of / to stand for the euclidean quotient is deprecated.
Please start using rather the quo() function. It is possible that in a future major release A/B with B a non-scalar will raise an error. Or, who knows, rational functions will be implemented sometime during the next decades, and then A/B will naturally be the rational function.
Important
\poldef P(x):=...; defines P both as a function, to be used as:
P(..numeric or even polynomial expression..)
and as a variable which can used inside polynomial expressions or as argument to some polynomial specific functions such as deg() or polgcd() 1.
Functional syntax accepts expressions as arguments; but the TeX macros described in the documentation, even the expandable ones, work only (there are a few exceptions to the general rule) with arguments being names of declared polynomials.
One needs to have a clear understanding of the difference between P used a function and P used as a variable: if P and Q are both declared polynomials then:
(P+Q)(3)% <--- attention!
is currently evaluated as (P+Q)*3, because P+Q is not known as a function, but only as a variable of polynomial type. Even worse:
(P)(3)% <--- attention!
will compute P*3, because one can not in current xintexpr syntax enclose a function name in parentheses: consequently it is the variable which is used here. There is a meager possibility that in future some internal changes to xintexpr would let (P)(3) actually compute P(3) and (P+Q)(3) compute P(3) + Q(3), but note that (P)(P) will then do P(P) and not P*P, the latter, current interpretation, looking more intuitive. Anyway, do not rely too extensively on tacit * and use explicit (P+Q)*(1+2) if this is what is intended.
As an alternative to explicit P(3)+Q(3) there is evalp(P+Q,3).
saves a copy of f under name g. Also usable without =.
Has exactly the same effect as \poldef g(x):=f; or \poldef g(w):=f(w);.
redefines f in terms of itself. Prior to 0.8 one needed the right hand side to be f(z)^2. Also, now sqr(f) is possible (also sqr(f(x)) but not sqr(f)(x)).
It may look strange that an indeterminate variable is used on left-hand-side even though it may be absent of right-hand-side, as it seems to define f always as a polynomial function.
This is a legacy of pre-0.8 context.
Important
Note that f^2(z) or sqr(f)(z) will give a logical but perhaps unexpected result: first f^2 is computed, then the opening parenthesis is seen which inserts a tacit multiplication *, so in the end it is as if the input had been f^2 * z. Although f is both a variable and a function, f^2 is computed as a polynomial variable and ceases being a function.
again modifies f. Here it is used both as variable and as a function. Prior to 0.8 it needed to be f(f(T)).
if everybody followed, this should now define the zero polynomial... And f-sqr(g(sqr(g))) computes the same thing.
We can check this in a typeset document like this:
\poldef f(x):= 1 - x + quo(x^5,1 - x + x^2);% \PolLet{g}={f}% \poldef f(z):= f^2;% \poldef f(T):= f(f);% \poldef k(w):= f-sqr(g(sqr(g)));% $$f(x) = \vcenter{\hsize10cm \PolTypeset{f}} $$ $$g(z) = \PolTypeset{g} $$ $$k(z) = \PolTypeset{k} $$ \immediate\write128{f(x)=\PolToExpr{f}}% ah, here we see it also
(new at 0.8)
Both set f' (or any other chosen name) to the derivative of f.
Important
This is not done automatically. If some new definition needs to use the derivative of some available polynomial, that derivative polynomial must have been previously defined: something such as f'(3)^2 will not work without a prior definition of f'.
But one can now use diff1(f) for on-the-spot construction with no permanent declaration, so here evalp(diff1(f),3)^2. And diff1(f)^2 is same as f'^2, assuming here f' was declared to be the derived polynomial.
Notice that the name diff1() is experimental and may change. Use \PolDiff{f}{f'} as the stable interface.
Typesets (switching to math mode if in text mode):
\poldef f(x):=(3+x)^5;% \PolDiff{f}{f'}\PolDiff{f'}{f''}\PolDiff{f''}{f'''}% $$f(z) = \PolTypeset[z]{f} $$ $$f'(z) = \PolTypeset[z]{f'} $$ $$f''(z) = \PolTypeset[z]{f''} $$ $$f'''(z)= \PolTypeset[z]{f'''} $$
See the documentation for the configurability via macros.
Since 0.8 \PolTypeset accepts directly an expression, it does not have to be a pre-declared polynomial name:
\PolTypeset{mul(x-i,i=1..5)}
Expandably (contrarily to \PolTypeset) produces c_n*x^n + ... + c_0 starting from the leading coefficient. The + signs are omitted if followed by negative coefficients.
This is useful for console or file output. This syntax is Maple and PSTricks \psplot[algebraic] compatible; and also it is compatible with \poldef input syntax, of course. See \PolToExprCaret for configuration of the ^, for example to use rather ** for Python syntax compliance.
Changed at 0.8: the ^ in output is by default of catcode 12 so in a draft document one can use \PolToExpr{P} inside the typesetting flow (without requiring math mode, where the * would be funny and ^12 would only put the 1 as exponent anyhow; but arguably in text mode the + and - are not satisfactory for math, except sometimes in monospace typeface, and anyhow TeX is unable to break the expression across lines, barring special help).
See \PolToExpr{<pol. expr.>} and related macros for customization.
Extended at 0.8 to accept as argument not only the name of a polynomial variable but more generally any polynomial expression.
All the syntax elements described in this section can be used in the \xintexpr/\xinteval context (where polynomials can be obtained from the pol([]) constructor, once polexpr is loaded): their usage is not limited to only \poldef context.
Note
If a variable myPol defined via \xintdefvar turns out to be a polynomial, the difference with those declared via \poldef will be:
myPol is not usable as function, but only as a variable. Attention that f(x) if f is only a variable (even a polynomial one) will actually compute f * x.
myPol is not known to the polexpr package, hence for example the macros to achieve localization of its roots are unavailable.
In a parallel universe I perhaps have implemented this expandably which means it could then be accessible with syntax such as rightmostroot(pol([42,1,34,2,-8,1])) but...
Warning
Consider the entirety of this section as UNSTABLE and EXPERIMENTAL (except perhaps regarding +, - and *).
And this applies even to items not explicitly flagged with one of unstable, Unstable, or UNSTABLE which only reflect that documentation was written over a period of time exceeding one minute, enough for the author mood changes to kick in.
It is hard to find good names at the start of a life-long extension program of functionalities, and perhaps in future it will be preferred to rename everything or give to some functions other meanings. Such quasi-complete renamings happened already a few times during the week devoted to development.
As has been explained in the Quick syntax overview these infix operators have been made polynomial aware, not only in the \poldef context, but generally in any \xintexpr/\xinteval context, inclusive of \xintdeffunc.
Conversely functions declared via \xintdeffunc and making use of these operators will automatically be able to accept polynomials declared from \poldef as variables.
Usage of / for euclidean division of polynomials is deprecated. Only in case of a scalar denominator is it to be considered stable. Please use rather quo().
Here is the tentative behaviour of A//B according to types:
A non scalar and B non scalar: euclidean quotient,
A scalar and B scalar: floored division,
A scalar and B non scalar: produces zero,
A non scalar and B scalar: coefficient per coefficient floored division.
This is an experimental overloading of the // and /: from \xintexpr.
The behaviour in the last case, but not only, is to be considerd unstable. The alternative would be for A//B with B scalar to act as quo(A,B). But, we have currently chosen to let //B for a scalar B act coefficient-wise on the numerator. Beware that it thus means it can be employed with the idea of doing euclidean division only by checking that B is non-scalar.
The /: operator provides the associated remainder so always A is reconstructed from (A//B)*B + A/:B.
If : is active character use /\string: (it is safer to use /\string : if it is not known if : has catcode other, letter, or is active, but note that /: is fine and needs no precaution if : has catcode letter, it is only an active : which is problematic, like for all other characters possibly used in an expression).
UNSTABLE
As explained above, there are (among other things) hesitations about behaviour with pol2 a scalar.
NOT YET IMPLEMENTED
As the internal representation by xintfrac and xintexpr of fractions does not currently require them to be in reduced terms, such operations would be a bit costly as they could not benefit from the \pdfstrcmp engine primitive. In fact xintexpr does not use it yet anywhere, even for normalized pure integers, although it could speed up signifcantly certain aspects of core arithmetic.
Equality of polynomials can currently be tested by computing the difference, which is a bit costly. And of course the deg() function allows comparing degrees. In this context note the following syntax:
(deg(Q)) ?? { zero } { non-zero scalar } { non-scalar }for branching.
This converts a nutple [c0,c1,...,cN] into the polynomial variable having these coefficients. Attention that the square brackets are mandatory, except of course if the argument is actually an expression producing such a "nutple".
Currently, this process will not normalize the coefficients (such as reducing to lowest terms), it only trims out the leading zero coefficients.
Inside \xintexpr, this is the only (allowed) way to create ex nihilo a polynomial variable; inside \poldef it is an alternative input syntax which is more efficient than typing c0 + c1 * x + c2 * x^2 + ....
Important
Whenever an expression with polynomials collapses to a constant, it becomes a scalar. There is currently no distinction during the parsing of expressions by \poldef or \xintexpr between constant polynomial variables and scalar variables.
Naturally, \poldef can be used to declare a constant polynomial P, then P can also be used as function having a value independent of argument, but as a variable, it is non-distinguishable from a scalar (of course functions such as deg() tacitly consider scalars to be constant polynomials).
Notice that we tend to use the vocable "variable" to refer to arbitrary expressions used as function arguments, without implying that we are actually referring to pre-declared variables in the sense of \xintdefvar.
This converts a nutple [cN,...,c1,c0] into the polynomial variable having these coefficients, with leading coefficients coming first in the input. Attention that the square brackets are mandatory, except of course if the argument is actually an expression producing such a "nutple".
Currently, this process will not normalize the coefficients (such as reducing to lowest terms), it only trims out the leading zero coefficients.
NAME UNSTABLE
It can be used in \poldef as an alternative input syntax, which is more efficient than using the algebraic notation with monomials.
(new with 0.8.1, an empty nutple will cause breakage)
This is documented here for lack of a better place: it evaluates the polynomial expression then outputs the "string" pol([c0, c1, ..., cN]) if the degree N is at least one (and the usual scalar output else).
The "pol" word uses letter catcodes, which is actually mandatory for this output to be usable as input, but it does not make sense to use this inside \poldef or \xintexpr at it means basically executing pol(coeffs(..expression..)) which is but a convoluted way to obtain the same result as (..expression..) (the parentheses delimiting the polynomial expression).
For example, \xinteval{(1+pol([0,1]))^10} expands (in two steps) to:
pol([1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1])You do need loading polexpr for this, else of course pol([]) remains unknown to \xinteval{} as well as the polynomial algebra ! This example can also be done as \xinteval{subs((1+x)^10,x=pol([0,1]))}.
I hesitated using as output the polynomial notation as produced by \PolToExpr{}, but finally opted for this.
Evaluates the first argument as a polynomial function of the second. Usually the second argument will be scalar, but this is not required:
\poldef K(x):= evalp(-3x^3-5x+1,-27x^4+5x-2);If the first argument is an already declared polynomial P, use rather the functional form P() (which can accept a numerical as well as polynomial argument) as it is more efficient.
One can also use subs() syntax 2 (see xintexpr documentation):
\poldef K(x):= subs(-3y^3-5y+1, y = -27x^4+5x-2);but the evalp() will use a Horner evaluation scheme which is usually more efficient.
- 2
by the way Maple uses the opposite, hence wrong, order subs(x=..., P) but was written before computer science reached the xintexpr heights. However it makes validating Maple results by polexpr sometimes cumbersome, but perhaps they will update it at some point.
name unstable
poleval? evalpol? peval? evalp? value? eval? evalat? eval1at2? evalat2nd?
Life is so complicated when one asks questions. Not everybody does, though, as is amply demonstrated these days.
syntax unstable
I am hesitating about permuting the order of the arguments.
Computes the degree.
Important
As \xintexpr does not yet support infinities, the degree of the zero polynomial is -1. Beware that this breaks additivity of degrees, but deg(P)<0 correctly detects the zero polynomial, and deg(P)<=0 detects scalars.
Produces the nutple [c0,c1,...,cN] of coefficients. The highest degree coefficient is always non zero (except for the zero polynomial...).
name unstable
I am considering in particular using polcoeffs() to avoid having to overload coeffs() in future when matrix type will be added to xintexpr.
Produces the nutple [cN,....,c1,c0] of coefficients, starting with the highest degree coefficient.
(new with 0.8.1)
As expected. Produces zero if the numerical index is negative or higher than the degree.
name, syntax and output unstable
I am hesitating with coeff(n,pol) syntax and also perhaps using polcoeff() in order to avoid having to overload coeff() when matrix type will be added to xintexpr.
The current behaviour is at odds with legacy \PolNthCoeff{<polname>}{<index>} regarding negative indices. Accessing leading or sub-leading coefficients can be done with other syntax, see lc(<pol. expr.>), and in some contexts it is useful to be able to rely on the fact that coefficients with negative indices do vanish, so I am for time being maintaining this.
The leading coefficient. The same result can be obtained from coeffs(pol)[-1], which shows also how to generalize to access sub-leading coefficients. See the xintexpr documentation for Python-like indexing syntax.
Divides by the leading coefficient, except that monicpart(0)==0.
unstable
Currently the coefficients are reduced to lowest terms (contrarily to legacy behaviour of \PolMakeMonic), and additionally the xintfrac \xintREZ macro is applied which extracts powers of ten from numerator or denominator and stores them internally separately. This is generally beneficial to efficiency of multiplication.
The (fractional) greatest common divisor of the polynomial coefficients. It is always produced as an irreducible (non-negative) fraction. According to Gauss theorem the content of a product is the product of the contents.
name and syntax unstable
At 0.8 it was created as icontent() to match the legacy macro \PolIContent, whose name in 2018 was chosen in relation to Maple's function icontent(), possibly because at that time I had not seen that Maple also had a content() function. Name changed at 0.8.1.
It will change syntax if in future multivariate polynomials are supported, and icontent() will then make a come-back.
The quotient (except for the zero polynomial) by cont(<pol. expr.>). This is thus a polynomial with integer coefficients having 1 as greatest common divisor. The sign of the leading coefficient is the same as in the original.
And primpart(0)==0.
The trailing zeros of the integer coefficients are extracted into a power of ten exponent part, in the internal representation.
Produces a nutple [Q,R] with Q the euclidean quotient and R the remainder.
name unstable
poldiv()?
The euclidean quotient.
The deprecated pol1/pol2 syntax computes the same polynomial.
The euclidean remainder. If pol2 is a (non-zero) scalar, this is zero.
There is no infix operator associated to this, for lack of evident notation. Please advise.
/: can be used if one is certain that pol2 is of degree at least one. But read the warning about it being unstable even in that case.
Produces a nutple [m, spR] where spR is the (special) pseudo Euclidean remainder. Its description is:
the standard euclidean remainder R is spR/m
m = b^f with b equal to the absolute value of the leading coefficient of pol2,
f is the number of non-zero coefficients in the euclidean quotient, if deg(pol2)>0 (even if the remainder vanishes).
If pol2 is a scalar however, the function outputs [1,0].
With these definitions one can show that if both pol1 and pol2 have integer coefficients, then this is also the case of spR, which makes its interest (and also m*Q has integer coefficients, with Q the euclidean quotient, if deg(pol2)>0). Also, prem() is computed faster than rem() for such integer coefficients polynomials.
Hint
If you want the euclidean quotient R evaluated via spR/m (which may be faster, even with non integer coefficients) use subs(last(x)/first(x),x=prem(P,Q)) syntax as it avoids computing prem(P,Q) twice. This does the trick both in \poldef or in \xintdefvar.
However, as is explained in the xintexpr documentation, using such syntax in an \xintdeffunc is (a.t.t.o.w) illusory, due to technicalities of how subs() gets converted into nested expandable macros. One needs an auxiliary function like this:
\xintdeffunc lastoverfirst(x):=last(x)/first(x); \xintdeffunc myR(x)=lastoverfirst(prem(x));Then, myR(pol1,pol2) will evaluate prem(pol1,pol2) only once and compute a polynomial identical to the euclidean remainder (internal representations of coefficients may differ).
In this case of integer coefficients polynomials, the polexpr internal representation of the integer coefficients in the pseudo remainder will be with unit denominators only if that was already the case for those of pol1 and pol2 (no automatic reduction to lowest terms is made prior or after computation).
Pay attention here that b is the absolute value of the leading coefficient of pol2. Thus the coefficients of the pseudo-remainder have the same signs as those of the standard remainder. This diverges from Maple's function with the same name.
Overloads the scalar divmod() and associates it with the experimental // and /: as extended to the polynomial type.
In particular when both pol1 and pol2 are scalars, this is the usual divmod() (as in Python) and for pol1 and pol2 non constant polynomials, this is the same as quorem().
Highly unstable overloading of \xinteval's divmod().
The R of the divmod() output. Same as R of quorem() when the second argument pol2 is of degree at least one.
Highly unstable overloading of \xinteval's mod().
Evaluates to the greatest common polynomial divisor of all the polynomial inputs. The output is a primitive (in particular, with integer coefficients) polynomial. It is zero if and only if all inputs vanish.
Attention, there must be either at least two polynomial variables, or alternatively, only one argument which then must be a bracketed list or some expression or variable evaluating to such a "nutple" whose items are polynomials (see the documentation of the scalar gcd() in xintexpr).
The two variable case could (and was, during development) have been defined at user level like this:
\xintdeffunc polgcd_(P,Q):= (deg(Q))??{P}{1}{polgcd_(Q,primpart(last(prem(P,Q))))}; \xintdeffunc polgcd(P,Q):=polgcd_(primpart(P),primpart(Q));%This is basically what is done internally for two polynomials, up to some internal optimizations.
UNSTABLE
I hesitate between returning a primitive or a monic polynomial. Maple returns a primitive polynomial if all inputs 3 have integer coefficients, else it returns a monic polynomial, but this is complicated technically for us to add such a check and would add serious overhead.
Internally, computations are done using primitive integer-coefficients polynomials (as can be seen in the function template above). So I decided finally to output a primitive polynomial, as one can always apply monicpart() to it.
Attention that this is at odds with behaviour of the legacy \PolGCD (non expandable) macro.
- 3
actually, only two polynomial arguments are allowed by Maple's gcd() as far as I know.
The resultant.
NOT YET IMPLEMENTED
The discriminant.
NOT YET IMPLEMENTED
Modular exponentiation: mod(pol1^N, pol2) in a more efficient manner than first computing pol1^N then reducing modulo pol2.
Attention that this is using the mod() operation, whose current experimental status is as follows:
if deg(pol2)>0, the euclidean remainder operation,
if pol2 is a scalar, coefficient-wise reduction modulo pol2.
UNSTABLE
This is currently implemented at high level via \xintdeffunc and recursive definitions, which were copied over from a scalar example in the xintexpr manual:
\xintdeffunc polpowmod_(P, m, Q) := isone(m)? % m=1: return P modulo Q { mod(P,Q) } % m > 1: test if odd or even and do recursive call { odd(m)? { mod(P*sqr(polpowmod_(P, m//2, Q)), Q) } { mod( sqr(polpowmod_(P, m//2, Q)), Q) } } ;% \xintdeffunc polpowmod(P, m, Q) := (m)?{polpowmod_(P, m, Q)}{1};%Negative exponents are not currently implemented.
For example:
\xinteval{subs(polpowmod(1+x,100,x^7),x=pol([0,1]))} \xinteval{subs(polpowmod(1+x,20,10), x=pol([0,1]))}produce respectively:
pol([1, 100, 4950, 161700, 3921225, 75287520, 1192052400]) pol([1, 0, 0, 0, 5, 4, 0, 0, 0, 0, 6, 0, 0, 0, 0, 4, 5, 0, 0, 0, 1])
This operates on the internal representation of the coefficients, reducing them to lowest terms.
name HIGHLY undecided
This operates on the internal representation of the coefficients, reducing them to lowest terms then extracting from numerator or denominator the maximal power of ten to store as a decimal exponent.
This is sometimes favourable to more efficient polynomial algebra computations.
name HIGHLY undecided
The first derivative.
name UNSTABLE
This name may be used in future to be the partial derivative with respect to a first variable.
The second derivative.
name UNSTABLE
This name may be used in future to be the partial derivative with respect to a second variable.
The nth derivative of P. For n<0 computes iterated primitives vanishing at the origin.
The coefficients are not reduced to lowest terms.
name and syntax UNSTABLE
I am also considering reversing the order of the arguments.
The primitive of P with no constant term. Same as diffn(P,-1).
The primitive of P vanishing at c, i.e. \int_c^x P(t)dt.
Also c can be a polynomial... so if c is monomial x this will give zero!
UNSTABLE
Allowing general polynomial variable for c adds a bit of overhead to the case of a pure scalar. So I am hesitating maintaining this feature whose interest appears dubious.
\int_a^b P(t)dt.
The brackets here are not denoting an optional argument but a mandatory nutple argument [a, b] with two items.
a and b are not restricted to be scalars, they can be polynomials.
To compute \int_{x-1}^x P(t)dt it is more efficient to use intfrom(x-1).
Similary to compute \int_x^{x+1} P(t)dt, use -intfrom(x+1).
UNSTABLE
Am I right to allow general polynomials a and b hence add overhead to the pure scalar case ?
Note
As of 0.8, polexpr is usable with Plain TeX and not only with LaTeX, the examples of this section have been converted to use a syntax which (at least at time of writing, March 2021) works in both.
This is done in order for the examples to be easy to copy-paste to documents using either macro format.
This (slightly over-extended) section gives various examples of usage of the package macros such as \PolToSturm, \PolSturmIsolateZeros and \PolPrintIntervals for root localization, which exist since release 0.4 (2018/02/16). The capacity to find all rational roots exactly was added at 0.7.2 (2018/12/09).
The examples demonstrate that the package can find all real roots to arbitrary precision, find the multiplicities of real roots, and find exactly all rational roots.
Perhaps future releases will implement other approaches, which are known to be generically computationally more efficient, at least in high degrees, than the Sturm theorem based approach. This is not immediate priority though (perhaps support of multivariate polynomials would be more important feature; or localization of complex roots).
To make printed decimal numbers more enjoyable than via \xintSignedFrac (or \xintSignedFwOver with Plain):
\def\PolTypesetOne#1{\PolDecToString{\xintREZ{#1}}}%
\PolDecToString will use decimal notation to incorporate the power of ten part; and the \xintREZ will have the effect to suppress trailing zeros if present in raw numerator (if those digits end up after decimal mark.) Notice that the above are expandable macros and that one can also do:
\def\PolToExprCmd#1{\PolDecToString{\xintREZ{#1}}}%
to modify output of \PolToExpr{<pol. expr.>}.
For extra info in log file use \xintverbosetrue.
Warning
Package macros related to root localization create (user-level) new polynomials, or numeric variables, via a naming scheme which postfixes a root name <sturmname> in various ways (see \PolToSturm{<polname>}{<sturmname>} and \PolSturmIsolateZeros{<sturmname>}). It is thus advisable to keep the <sturmname> name-space separate from the one used to name polynomial or scalar variables.
Regrettably all examples here use the condemnable \PolToSturm{f}{f} practice which fuses the name-spaces. This can lead to problems if one is not aware of the consequances.
In this example the polynomial is square-free.
\poldef f(x) := x^7 - x^6 - 2x + 1; \PolToSturm{f}{f} \PolSturmIsolateZeros{f} The \PolTypeset{f} polynomial has \PolSturmNbOfIsolatedZeros{f} distinct real roots which are located in the following intervals: \PolPrintIntervals{f} Here is the second root with ten more decimal digits: \PolRefineInterval[10]{f}{2} $$\PolSturmIsolatedZeroLeft{f}{2}<Z_2<\PolSturmIsolatedZeroRight{f}{2}$$ And here is the first root with twenty digits after decimal mark: \PolEnsureIntervalLength{f}{1}{-20} $$\PolSturmIsolatedZeroLeft{f}{1}<Z_1<\PolSturmIsolatedZeroRight{f}{1}$$ The first element of the Sturm chain has degree $\PolDegree{f_0}$. As this is the original degreee $\PolDegree{f}$ we know that $f$ is square free. Its derivative is up to a constant \PolTypeset{f_1} (in this example it is identical with it). \PolToSturm{f_1}{f_1}\PolSturmIsolateZeros{f_1}% The derivative has \PolSturmNbOfIsolatedZeros{f_1} distinct real roots: \PolPrintIntervals[W]{f_1} \PolEnsureIntervalLengths{f_1}{-10}% Here they are with ten digits after decimal mark: \PolPrintIntervals[W]{f_1} \PolDiff{f_1}{f''} \PolToSturm{f''}{f''} \PolSturmIsolateZeros{f''} The second derivative is \PolTypeset{f''}. It has \PolSturmNbOfIsolatedZeros{f''} distinct real roots: \PolPrintIntervals[X]{f''} Here is the positive one with 20 digits after decimal mark: \PolEnsureIntervalLength{f''}{2}{-20}% $$X_2 = \PolSturmIsolatedZeroLeft{f''}{2}\dots$$ The more mathematically advanced among our dear readers will be able to give the exact value for $X_2$!
Notice that this example is a bit outdated as 0.7 release has added \PolSturmIsolateZeros**{<sturmname>} which would find exactly the roots. The steps here retain their interest when one is interested in finding isolating intervals for example to prepare some demonstration of dichotomy method.
\PolDef{Q}{(x-1.050001)(x-1.105001)(x-1.110501)(x-1.111051)} \PolTypeset{Q} \PolToSturm{Q}{Q} % it is allowed to use same prefix for Sturm chain \PolSturmIsolateZeros{Q} \PolPrintIntervals{Q} % reports 1.0 < Z_1 < 1.1, 1.10 < Z_2 < 1.11, 1.110 < Z_3 < 1.111, and 1.111 < Z_4 < 1.112 % but the above bounds do not allow minimizing separation between roots % so we refine: \PolRefineInterval*{Q}{1} \PolRefineInterval*{Q}{2} \PolRefineInterval*{Q}{3} \PolRefineInterval*{Q}{4} \PolPrintIntervals{Q} % reports 1.05 < Z_1 < 1.06, 1.105 < Z_2 < 1.106, 1.1105 < Z_3 < 1.1106, % and 1.11105 < Z_4 < 1.11106. \PolEnsureIntervalLengths{Q}{-6} \PolPrintIntervals{Q} % of course finds here all roots exactly
% define a user command (xinttools is loaded automatically by polexpr) \def\showmultiplicities#1{% #1 = "sturmname" \xintFor* ##1 in {\xintSeq{1}{\PolSturmNbOfIsolatedZeros{#1}}}\do{% The multiplicity is \PolSturmIsolatedZeroMultiplicity{#1}{##1} \PolSturmIfZeroExactlyKnown{#1}{##1}% {at the root $x=\PolSturmIsolatedZeroLeft{#1}{##1}$} {for the root such that $\PolSturmIsolatedZeroLeft{#1}{##1}<x<\PolSturmIsolatedZeroRight{#1}{##1}$} \par }}% \PolDef{f}{(x-0.99)^3(x-0.999)^3(x-0.9999)^3} \def\PolTypesetOne#1{\PolDecToString{\xintREZ{#1}}} \PolTypeset{f}\par \PolToSturm{f}{f}% it is allowed to use "polname" as "sturmname" too \PolSturmIsolateZerosAndGetMultiplicities{f}% use the "sturmname" here % or \PolSturmIsolateZeros*{f} which is exactly the same, but shorter.. \showmultiplicities{f}
In this example, the output will look like this (but using math mode):
x^9 - 8.9667x^8 + 35.73400293x^7 - 83.070418400109x^6 + 124.143648875193123x^5 - 123.683070924326075877x^4 + 82.149260397553075617891x^3 - 35.07602992699900159127007x^2 + 8.7364078733314648368671733x - 0.967100824643585986488103299 The multiplicity is 3 at the root x = 0.99 The multiplicity is 3 at the root x = 0.999 The multiplicity is 3 at the root x = 0.9999
On first pass, these rational roots were found (due to their relative magnitudes, using \PolSturmIsolateZeros** was not needed here). But multiplicity computation works also with (decimal) roots not yet identified or with non-decimal or irrational roots.
It is fun to modify only a tiny bit the polynomial and see if polexpr survives:
\PolDef{g}{f(x)+1e-27} \PolTypeset{g}\par \PolToSturm{g}{g} \PolSturmIsolateZeros*{g} \showmultiplicities{g}
This produces:
x^9 - 8.9667x^8 + 35.73400293x^7 - 83.070418400109x^6 + 124.143648875193123x^5 - 123.683070924326075877x^4 + 82.149260397553075617891x^3 - 35.07602992699900159127007x^2 + 8.7364078733314648368671733x - 0.967100824643585986488103298 The multiplicity is 1 for the root such that 0.98 < x < 0.99 The multiplicity is 1 for the root such that 0.9991 < x < 0.9992 The multiplicity is 1 for the root such that 0.9997 < x < 0.9998
Which means that the multiplicity-3 roots each became a real and a pair of complex ones. Let's see them better:
\PolEnsureIntervalLengths{g}{-10} \showmultiplicities{g}
which produces:
The multiplicity is 1 for the root such that 0.9899888032 < x < 0.9899888033 The multiplicity is 1 for the root such that 0.9991447980 < x < 0.9991447981 The multiplicity is 1 for the root such that 0.9997663986 < x < 0.9997663987
\poldef Q(x) := 1581755751184441 x^5 -14907697165025339 x^4 +48415668972339336 x^3 -63952057791306264 x^2 +46833913221154895 x -49044360626280925; \PolToSturm{Q}{Q} \def\PolTypesetCmdPrefix#1{\allowbreak\xintiiifSgn{#1}{}{+}{+}}% $Q_0(x) = \PolTypeset{Q_0}$ \PolSturmIsolateZeros**{Q} \PolPrintIntervals{Q} $Q_{norr}(x) = \PolTypeset{Q_norr}$
Here, all real roots are rational:
Z_1 = 833719/265381 Z_2 = 165707065/52746197 Z_3 = 355/113 Q_norr(x) = x^2 + 1
And let's get their decimal expansion too:
% print decimal expansion of the found roots \def\PolPrintIntervalsPrintExactZero {\xintTrunc{20}{\PolPrintIntervalsTheLeftEndPoint}\dots} \PolPrintIntervals{Q} Z_1 = 3.14159265358107777120... Z_2 = 3.14159265358979340254... Z_3 = 3.14159292035398230088...
\PolDef{P}{x^10 - (10x-1)^2}% \PolTypeset{P} % prints it in expanded form \PolToSturm{P}{P} % we can use same prefix for Sturm chain \PolSturmIsolateZeros{P} % finds 4 real roots This polynomial has \PolSturmNbOfIsolatedZeros{P} distinct real roots: \PolPrintIntervals{P}% % reports -2 < Z_1 < -1, 0.09 < Z_2 < 0.10, 0.1 < Z_3 < 0.2, 1 < Z_4 < 2 Let us refine the second and third intervals to separate the corresponding roots: \PolRefineInterval*{P}{2}% will refine to 0.0999990 < Z_2 < 0.0999991 \PolRefineInterval*{P}{3}% will refine to 0.100001 < Z_3 < 0.100002 \PolPrintIntervals{P}% Let us now get to know all roots with 10 digits after decimal mark: \PolEnsureIntervalLengths{P}{-10}% \PolPrintIntervals{P}% now all roots are known 10 decimal digits after mark Finally, we display 20 digits of the second root: \PolEnsureIntervalLength{P}{2}{-20}% makes Z_2 known with 20 digits after mark $$\PolSturmIsolatedZeroLeft{P}{2}<Z_2<\PolSturmIsolatedZeroRight{P}{2}$$
The last line produces:
0.09999900004999650028 < Z_2 < 0.09999900004999650029
See Wilkinson polynomial.
%\xintverbosetrue % for the curious... \poldef f(x) := mul((x - i), i = 1..20); \def\PolTypesetCmdPrefix#1{\allowbreak\xintiiifSgn{#1}{}{+}{+}}% \def\PolTypesetOne#1{\xintDecToString{#1}}% \noindent\PolTypeset{f} \PolToSturm{f}{f} \PolSturmIsolateZeros{f} \PolPrintIntervals{f} % \vfill\eject % This page is commented out because it takes about 30s on a 2GHz CPU % \poldef g(x) := f(x) - 2**{-23} x**19; % \PolToSturm{g}{g} % \noindent\PolTypeset{g_0}% integer coefficient primitive polynomial % \PolSturmIsolateZeros{g} % \PolEnsureIntervalLengths{g}{-10} % \let\PolPrintIntervalsPrintMultiplicity\empty % \PolPrintIntervals*{g}
The first polynomial:
f(x) = x**20 - 210 x**19 + 20615 x**18 - 1256850 x**17 + 53327946 x**16 - 1672280820 x**15 + 40171771630 x**14 - 756111184500 x**13 + 11310276995381 x**12 - 135585182899530 x**11 + 1307535010540395 x**10 - 10142299865511450 x**9 + 63030812099294896 x**8 - 311333643161390640 x**7 + 1206647803780373360 x**6 - 3599979517947607200 x**5 + 8037811822645051776 x**4 - 12870931245150988800 x**3 + 13803759753640704000 x**2 - 8752948036761600000 x + 2432902008176640000
is handled fast enough, but the modified one f(x) - 2**-23 x**19 takes about 20x longer.
The Sturm chain polynomials have integer coefficients with up to 321 digits, whereas (surprisingly perhaps) those of the Sturm chain polynomials derived from f never have more than 21 digits ...
Once the Sturm chain is computed and the zeros isolated, obtaining their decimal digits is relatively faster. Here is for the ten real roots of f(x) - 2**-23 x**19 as computed by the code above:
Z_1 = 0.9999999999... Z_2 = 2.0000000000... Z_3 = 2.9999999999... Z_4 = 4.0000000002... Z_5 = 4.9999999275... Z_6 = 6.0000069439... Z_7 = 6.9996972339... Z_8 = 8.0072676034... Z_9 = 8.9172502485... Z_10 = 20.8469081014...
\poldef f(x) := mul(x - 2^-i, i = 1..20); %\PolTypeset{f} \PolToSturm{f}{f} \PolSturmIsolateZeros**{f} \PolPrintIntervals{f}
This takes more time than the polynomial with 1, 2, .., 20 as roots but less than the latter modified by the 2**-23 tiny change to one of its coefficient.
Here is the output (with release 0.7.2):
Z_1 = 0.00000095367431640625 Z_2 = 0.0000019073486328125 Z_3 = 0.000003814697265625 Z_4 = 0.00000762939453125 Z_5 = 0.0000152587890625 Z_6 = 0.000030517578125 Z_7 = 0.00006103515625 Z_8 = 0.0001220703125 Z_9 = 1/4096 Z_10 = 1/2048 Z_11 = 1/1024 Z_12 = 1/512 Z_13 = 1/256 Z_14 = 1/128 Z_15 = 0.015625 Z_16 = 0.03125 Z_17 = 0.0625 Z_18 = 0.125 Z_19 = 0.25 Z_20 = 0.5
There is some incoherence in output format which has its source in the fact that some roots are found in branches which can only find decimal roots, whereas some are found in branches which could find general fractions and they use \xintIrr before storage of the found root. This may evolve in future.
\PolDef{P}{mul((x-i*1e-1), i=-20..20)}% i/10 is same but less efficient
In the defining expression we could have used i/10 but this gives less efficient internal form for the coefficients (the 10's end up in denominators).
Using \PolToExpr{P} after having done
\def\PolToExprCmd#1{\PolDecToString{\xintREZ{#1}}}
we get this expanded form:
x^41 -28.7*x^39 +375.7117*x^37 -2975.11006*x^35 +15935.28150578*x^33 -61167.527674162*x^31 +173944.259366417394*x^29 -373686.963560544648*x^27 +613012.0665016658846445*x^25 -771182.31133138163125495*x^23 +743263.86672885754888959569*x^21 -545609.076599482896371978698*x^19 +301748.325708943677229642930528*x^17 -123655.8987669450434698869844544*x^15 +36666.1782054884005855608205864192*x^13 -7607.85821367459445649518380016128*x^11 +1053.15135918687298508885950223794176*x^9 -90.6380005918141132650786081964032*x^7 +4.33701563847327366842552218288128*x^5 -0.0944770968420804735498178265088*x^3 +0.00059190121813899276854174416896*x
which shows coefficients with up to 36 significant digits...
Stress test: not a hard challenge to xint + polexpr, but be a bit patient!
\PolDef{P}{mul((x-i*1e-1), i=-20..20)}% \PolToSturm{P}{S} % dutifully computes S_0, ..., S_{41} % the [1] optional argument limits the search to interval (-10,10) \PolSturmIsolateZeros[1]{S} % finds *exactly* (but a bit slowly) all 41 roots! \PolPrintIntervals{S} % nice, isn't it?
Note
Release 0.5 has experimental addition of optional argument E to \PolSturmIsolateZeros. It instructs to search roots only in interval (-10^E, 10^E). Important: the extremities are assumed to not be roots. In this example, the [1] in \PolSturmIsolateZeros[1]{S} gives some speed gain; without it, it turns out in this case that polexpr would have started with (-10^6, 10^6) interval.
Please note that this will probably get replaced in future by the specification of a general interval. Do not rely on meaning of this optional argument keeping the same.
\poldef T_0(x) := 1; \poldef T_1(x) := x; \catcode`@ 11 \count@ 2 \xintloop \poldef T_\the\count@(x) := 2x*T_\the\numexpr\count@-1\relax - T_\the\numexpr\count@-2\relax; \ifnum\count@<15 \advance\count@ 1 \repeat \catcode`@ 12 $$T_{15} = \PolTypeset[X]{T_15}$$ \PolToSturm{T_15}{T_15} \PolSturmIsolateZeros{T_15} \PolEnsureIntervalLengths{T_15}{-10} \PolPrintIntervals{T_15}
Note
At 0.8 polexpr is usable with Plain TeX and not only with LaTeX. Some examples given in this section may be using LaTeX syntax such as \renewcommand. Convert to TeX primitives as appropriate if testing with a non LaTeX macro format.
This evaluates the polynomial expression and stores the coefficients in a private structure accessible later via other package macros, used with argument polname. Of course the expression can make use of previously defined polynomials.
Polynomial names must start with a letter and are constituted of letters, digits, underscores and the right tick '.
The whole xintexpr syntax is authorized, as long as the final result is of polynomial type:
\poldef polname(z) := add((-1)^i z^(2i+1)/(2i+1)!, i = 0..10);With fractional coefficients, beware the tacit multiplication issue.
Furthermore:
a variable polname is defined which can be used in \poldef as well as in \xinteval for algebraic computations or as argument to polynomial aware functions,
a function polname() is defined which can be used in \poldef as well as in \xinteval. It accepts there as argument scalars and also other polynomials (via their names, thanks to previous item).
Notice that any function defined via \xintdeffunc and using only algebraic operations (and ople indexing or slicing operations) should work fine in \xintexpr/\xinteval with such polynomial names as argument.
In the case of a constant polynomial, the xintexpr variable (not the internal data structure on which the package macros operate) associated to it is indistinguishable from a scalar, it is actually a scalar and has lost all traces from its origins as a polynomial (so for example can be used as argument to the cos() function).
The function on the other hand remains a one-argument function, which simply has a constant value.
Attention!
The function polname() is defined only for \xintexpr/\xinteval context. It will be unknown to \xintfloateval.
Worse, a previously existing floating point function of the same name will be let undefined again, to avoid hard to debug mismatches between exact and floating point polynomials. This also applies when the polynomial is produced not via \poldef or \PolDef but as result of usage of the other package macros.
See \PolGenFloatVariant{<polname>} to generate a function usable in \xintfloateval.
Attention!
Using the variable mypol inside \xintfloateval will generate low-level errors because the infix operators there are not polynomial-aware, and the polynomial specific functions such as deg() are only defined for usage inside \xintexpr.
In short, currently polynomials defined via polexpr can be used in floating point context only for numerical evaluations, via functions obtained from \PolGenFloatVariant{<polname>} usage.
Changes to the original polynomial via package macros are not automatically mapped to the numerical floating point evaluator which must be manually updated as necessary when the original rational coefficient polynomial is modified.
The original expression is lost after parsing, and in particular the package provides no way to typeset it (of course the package provides macros to typeset the computed polynomial). Typesetting the original expression has to be done manually, if needed.
Does the same as \poldef in an undelimited macro format, the main interest is to avoid potential problems with the catcode of the semi-colon in presence of some packages. In absence of a [<letter>] optional argument, the variable is assumed to be x.
Makes the polynomial also usable in the \xintfloatexpr/\xintfloateval parser. It will therein evaluates via an Horner scheme using polynomial coefficients already pre-rounded to the float precision.
See also \PolToFloatExpr{<pol. expr.>}.
Attention!
Any operation, for example generating the derivative polynomial, or dividing two polynomials or using the \PolLet, must be followed by explicit usage of \PolGenFloatVariant{<polname>} if the new polynomial is to be used in \xintfloateval.
Typesets in descending powers, switching to math mode if in text mode, after evaluating the polynomial expression:
\PolTypeset{mul(x-i,i=1..5)}% possible since polexpr 0.8The letter used in the input expression is by default x, but can be modified by a redefinition of \PolToExprInVar.
It uses also by default the letter x on output but this one can be changed via an optional argument:
\PolTypeset[z]{polname or polynomial expression}By default zero coefficients are skipped (use \poltypesetalltrue to get all of them in output).
The following macros (whose meanings will be found in the package code) can be re-defined for customization. Their default definitions are expandable, but this is not a requirement.
Its package definition checks if the coefficient is 1 or -1 and then skips printing the 1, except for the coefficient of degree zero. Also it sets the conditional deciding behaviour of \PolIfCoeffIsPlusOrMinusOne{T}{F}.
The actual printing of the coefficients, when not equal to plus or minus one, is handled by \PolTypesetOne{<raw_coeff>}.
This macro is a priori undefined.
It is defined via the default \PolTypesetCmd{<raw_coeff>} to be used if needed in the execution of \PolTypesetMonomialCmd, e.g. to insert a \cdot in front of \PolVar^{\PolIndex} if the coefficient is not plus or minus one.
The macro will execute T if the coefficient has been found to be plus or minus one, and F if not. It chooses expandably between T and F.
Defaults to \xintSignedFrac (LaTeX) or \xintSignedFwOver (else). But these xintfrac old legacy macros are a bit annoying as they insist in exhibiting a power of ten rather than using simpler decimal notation.
As alternative, one can do definitions such as:
\def\PolTypesetOne#1{\xintDecToString{\xintREZ{#1}}} % or with LaTeX+siunitx for example \renewcommand\PolTypesetOne[1]{\num{\xintPFloat[5]{#1}}} % (as \num of siunitx understands floating point notation) \renewcommand\PolTypesetOne[1]{\num{\xintRound{4}{#1}}}
This decides how a monomial (in variable \PolVar and with exponent \PolIndex) is to be printed. The default does nothing for the constant term, \PolVar for the first degree and \PolVar^{\PolIndex} for higher degrees monomials. Beware that \PolIndex expands to digit tokens and needs termination in \ifnum tests.
Expands to a + if the raw_coeff is zero or positive, and to nothing if raw_coeff is negative, as in latter case the \xintSignedFrac (or \xintSignedFwOver) used by \PolTypesetCmd{<raw_coeff>} will put the - sign in front of the fraction (if it is a fraction) and this will thus serve as separator in the typeset formula. Not used for the first term.
Typesets in ascending powers. Use [<letter>] optional argument (after the *) to use another letter than x.
Extended at 0.8 to accept general expressions and not only polynomial names. Redefine \PolToExprInVar to use in the expression another letter than default x.
Makes a copy of the already defined polynomial polname_1 to a new one polname_2. This has the same effect as \PolDef{<polname_2>}{<polname_1>(x)} or (better) \PolDef{<polname_2>}{<polname_1>} but with less overhead. The = is optional.
Acts globally.
Defines a one-argument expandable macro \macro{#1} which expands to the (raw) #1th polynomial coefficient.
Attention, coefficients here are indexed starting at 1. This is an unfortunate legacy situation related to the original indexing convention in xinttools arrays.
With #1=-1, -2, ..., \macro{#1} returns leading coefficients.
With #1=0, returns the number of coefficients, i.e. 1 + deg f for non-zero polynomials.
Out-of-range #1's return 0/1[0].
See also \PolNthCoeff{<polname>}{<index>}.
Does the converse operation to \PolAssign{<polname>}\toarray\macro. Each individual \macro{<value>} gets expanded in an \edef and then normalized via xintfrac's macro \xintRaw.
The leading zeros are removed from the polynomial.
(contrived) Example:
\xintAssignArray{1}{-2}{5}{-3}\to\foo \PolGet{f}\fromarray\fooThis will define f as would have \poldef f(x):=1-2x+5x^2-3x^3;.
Defines a polynomial directly from the comma separated list of values (or a macro expanding to such a list) of its coefficients, the first item gives the constant term, the last item gives the leading coefficient, except if zero, then it is dropped (iteratively). List items are each expanded in an \edef and then put into normalized form via xintfrac's macro \xintRaw.
As leading zero coefficients are removed:
\PolFromCSV{f}{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}defines the zero polynomial, which holds only one coefficient.
See also expandable macro \PolToCSV{<polname>}.
It modifies ('in-place': original coefficients get lost) each coefficient of the defined polynomial via the expandable macro \macro. The degree is adjusted as necessary if some leading coefficients vanish after the operation.
In the replacement text of \macro, \index expands to the coefficient index (starting at zero for the constant term).
Notice that \macro will have to handle inputs in the xintfrac internal format. This means that it probably will have to be expressed in terms of macros from the xintfrac package.
Example:
\def\foo#1{\xintMul{#1}{\the\numexpr\index*\index\relax}}(or with \xintSqr{\index}) to replace n-th coefficient f_n by f_n*n^2.
Reduces the internal representations of the coefficients to their lowest terms.
Reduces the internal representations of the coefficients to their lowest terms, but ignoring a possible separated "power of ten part".
For example, xintfrac stores an 30e2/50 input as 30/50 with a separate 10^2 part. This will thus get replaced by 3e^2/5 (or rather whatever xintfrac uses for internal representation), and not by 60 as would result from complete reduction.
Evaluations with polynomials treated by this can be much faster than with those handled by the non-starred variant \PolReduceCoeffs{<polname>}: as the numerators and denominators remain generally smaller.
Divides by the leading coefficient. It is recommended to execute \PolReduceCoeffs*{<polname>} immediately afterwards. This is not done automatically, in case the original polynomial had integer coefficients and the user wants to keep the leading one as common denominator for typesetting purposes.
Divides by the integer content see (\PolIContent). This thus produces a polynomial with integer coefficients having no common factor. The sign of the leading coefficient is not modified.
This sets polname_2 to the first derivative of polname_1. It is allowed to issue \PolDiff{f}{f}, effectively replacing f by f'.
Coefficients of the result polname_2 are irreducible fractions (see Technicalities for the whole story.)
This sets polname_2 to the N-th derivative of polname_1. Identical arguments is allowed. With N=0, same effect as \PolLet{<polname_2>}={<polname_1>}. With negative N, switches to using \PolAntiDiff.
This sets polname_2 to the primitive of polname_1 vanishing at zero.
Coefficients of the result polname_2 are irreducible fractions (see Technicalities for the whole story.)
This sets polname_2 to the result of N successive integrations on polname_1. With negative N, it switches to using \PolDiff.
This sets polname_Q and polname_R to be the quotient and remainder in the Euclidean division of polname_1 by polname_2.
This sets polname_Q to be the quotient in the Euclidean division of polname_1 by polname_2.
This sets polname_R to be the remainder in the Euclidean division of polname_1 by polname_2.
This sets polname_GCD to be the (monic) GCD of polname_1 and polname_2. It is a unitary polynomial except if both polname_1 and polname_2 vanish, then polname_GCD is the zero polynomial.
Note
At 0.8 polexpr is usable with Plain TeX and not only with LaTeX. Some examples given in this section may be using LaTeX syntax such as \renewcommand. Convert to TeX primitives as appropriate if testing with a non LaTeX macro format.
These macros expand completely in two steps except \PolToExpr and \PolToFloatExpr which need a \write, \edef or a \csname...\endcsname context.
Produces expandably 4 the string coeff_N*x^N+..., i.e. the polynomial is using descending powers.
- 4
requires exhaustive expansion, for example as triggered by \write or \edef.
Since 0.8 the input is not restricted to be a polynomial name but is allowed to be an arbitrary expression (where by default the letter x is recognized as the indeterminate; see \PolToExprInVar).
The default output (which also by default uses the letter x and is completely configurable, see in particular \PolToExprVar) is compatible with both
the Maple's input format,
and the PSTricks \psplot[algebraic] input format.
Attention that it is not compatible with Python, but see \PolToExprCaret in this regard.
It has the following characteristics:
vanishing coefficients are skipped (issue \poltoexpralltrue to override this and produce output such as x^3+0*x^2+0*x^1+0),
negative coefficients are not prefixed by a + sign (else, Maple would not be happy),
coefficients numerically equal to 1 (or -1) are present only via their sign,
the letter x is used and the degree one monomial is output as x, not as x^1.
(0.8) the caret ^ is of catcode 12. This means that one can for convenience typeset in regular text mode, for example using \texttt (in LaTeX). But TeX will not know how to break the expression across end-of-lines anyhow. Formerly ^ was suitable for math mode but as the exponent is not braced this worked only for polynomials of degrees at most 9. Anyhow this is not supposed to be a typesetting macro.
Complete customization is possible, see the next macros. Any user redefinition must maintain the expandability property.
Defaults to x. The letter used in input.
Defaults to x: the letter used as the polynomial indeterminate.
Recall that declared polynomials are more efficiently used in algebraic expressions without the (x), i.e. P*Q is better than P(x)*Q(x). Thus the input, even if an expression, does not have to contain any x.
(new with 0.8)
Defaults to *.
Defaults to ^ of catcode 12. Set it to expand to ** for Python compatible output.
(new with 0.8)
Defaults to \xintPRaw{\xintRawWithZeros{#1}}.
This means that the coefficient value is printed-out as a fraction a/b, skipping the /b part if b turns out to be one.
Configure it to be \xintPRaw{\xintIrr{#1}} if the fractions must be in irreducible terms.
An alternative is \xintDecToString{\xintREZ{#1}} which uses integer or decimal fixed point format such as 23.0071 if the internal representation of the number only has a power of ten as denominator (the effect of \xintREZ here is to remove trailing decimal zeros). The behaviour of \xintDecToString is not yet stable for other cases, and for example at time of writing no attempt is made to identify inputs having a finite decimal expansion so for example 23.007/2 or 23.007/25 can appear in output and not their finite decimal expansion with no denominator.
This is the macro which from the coefficient and the exponent produces the corresponding term in output, such as 2/3*x^7.
For its default definition, see the source code. It uses \PolToExprCmd, \PolToExprTimes, \PolToExprVar and \PolToExprCaret.
This holds the default package meaning of \PolToExprOneTerm.
This holds an alternative meaning, which puts the fractional part of a coefficient after the monomial, i.e. like this:
2*x^11/3+3*x^8/7-x^5-x^4/4-x^3-x^2/2-2*x+1\PolToExprCmd isn't used at all in this style. But \PolToExprTimes, \PolToExprVar and \PolToExprCaret are obeyed.
To activate it use \let\PolToExprOneTerm\PolToExprOneTermStyleB. To revert to the package default behaviour, issue \let\PolToExprOneTerm\PolToExprOneTermStyleA.
It receives as argument the coefficient. Its default behaviour is to produce a + if the coefficient is positive, which will thus serve to separate the monomials in the output. This is to match the default for \PolToExprCmd{<raw_coeff>} which in case of a positive coefficient does not output an explicit + prefix.
Similar to \PolToExpr{<pol. expr.>} but using \PolToFloatExprCmd{<raw_coeff>} which by default rounds and converts the coefficients to floating point format.
Note
This is unrelated to \PolGenFloatVariant{<polname>}: \PolToFloatExprCmd{<raw_coeff>} operates on the exact coefficients anew (and may thus produce something else than the coefficients of the polynomial function acting in \xintfloateval if the floating point precision was changed in between).
Extended at 0.8 to accept general expressions as input.
Similar to \PolToExprOneTerm{<raw_coeff>}{<exponent>}. But does not treat especially coefficients equal to plus or minus one.
The one-argument macro used by \PolToFloatExprOneTerm. It defaults to \xintPFloat{#1}, which trims trailing zeroes.
changed at 0.8.2 Formerly it was using \xintFloat.
Ascending powers: coeff_0+coeff_1*x+coeff_2*x^2+....
Extended at 0.8 to accept general expressions as input.
Customizable with the same macros as for \PolToExpr{<pol. expr.>}.
Ascending powers.
Extended at 0.8 to accept general expressions as input.
It expands to the raw N-th coefficient (N=0 corresponds to the constant coefficient). If N is out of range, zero (in its default xintfrac format 0/1[0]) is returned.
Negative indices N=-1, -2, ... return the leading coefficient, sub-leading coefficient, ..., and finally 0/1[0] for N<-1-degree.
Expands to the leading coefficient.
It expands to the degree. This is -1 if zero polynomial but this may change in future. Should it then expand to -\infty ?
It expands to the contents of the polynomial, i.e. to the positive fraction such that dividing by this fraction produces a polynomial with integer coefficients having no common prime divisor.
See \PolMakePrimitive.
Expands to {coeff_0}{coeff_1}...{coeff_N} with N = degree, and coeff_N the leading coefficient (the zero polynomial does give {0/1[0]} and not an empty output.)
Expands to coeff_0, coeff_1, coeff_2, ....., coeff_N, starting with constant term and ending with leading coefficient. Converse to \PolFromCSV{<polname>}{<csv>}.
Same output as \xinteval{polname(numerical expression)}.
Evaluates the polynomial at the given value which must be in (or expand to) a format acceptable to the xintfrac macros.
Same output as \xinteval{reduce(polname(numerical expression))}.
Evaluates the polynomial at the value which must be in (or expand to) a format acceptable to the xintfrac macros, and outputs an irreducible fraction.
Same output as \xintfloateval{polname(numerical expression)}.
Attention!
\PolGenFloatVariant must have been issued before.
To use the exact coefficients with exactly executed additions and multiplications and do the rounding only as the final last step, the following syntax can be used: 5
\xintfloateval{3.27*\xintexpr f(2.53)\relax^2}
Evaluates the polynomial at the value which must be in (or expand to) a format acceptable to the xintfrac macros.
This is actually an xintexpr configuration. Setting it to true triggers the writing of information to the log when new polynomial or scalar variables are defined.
Caution!
The macro and variable meanings as written to the log are to be considered unstable and undocumented internal structures.
When \poldef is used, both a variable and a function are defined. The default \polnewpolverbosefalse setting suppresses the print-out to the log and terminal of the function macro meaning, as it only duplicates the information contained in the variable which is already printed out to the log and terminal.
However \PolGenFloatVariant{<polname>} does still print out the information relative to the polynomial function it defines for use in \xintfloateval{} as there is no float polynomial variable, only the function, and it is the only way to see its rounded coefficients (\xintverbosefalse suppresses also that info).
If set to true, it overrides in both cases \xintverbosefalse. The setting only affects polynomial declarations. Scalar variables such as those holding information on roots obey only the \xintverbose... setting.
(new with 0.8)
If true, \PolTypeset will also typeset the vanishing coefficients.
If true, \PolToExpr{<pol. expr.>} and \PolToFloatExpr{<pol. expr.>} will also include the vanishing coefficients in their outputs.
This is a utility macro to print decimal numbers. It is an alias for \xintDecToString.
For example \PolDecToString{123.456e-8} will expand to 0.00000123456 and \PolDecToString{123.450e-8} to 0.00000123450 which illustrates that trailing zeros are not trimmed.
To trim trailing zeroes, one can use \PolDecToString{\xintREZ{#1}}.
Attention that a.t.t.o.w. if the argument is for example 1/5, the macro does not identify that this is in fact a number with a finite decimal expansion and it outputs 1/5. See current xintfrac documentation.
Serves to customize the package. Currently only two keys are recognized:
norr: the postfix that \PolSturmIsolateZeros**{<sturmname>} should append to <sturmname> to declare the primitive polynomial obtained from original one after removal of all rational roots. The default value is _norr (standing for “no rational roots”).
sqfnorr: the postfix that \PolSturmIsolateZeros**{<sturmname>} should append to <sturmname> to declare the primitive polynomial obtained from original one after removal of all rational roots and suppression of all multiplicities. The default value is _sqf_norr (standing for “square-free with no rational roots”).
The package executes \polexprsetup{norr=_norr, sqfnorr=_sqf_norr} as default.
The catcode of the semi-colon is reset temporarily by \poldef macro in case some other package (for example the French babel module) may have made it active. This will fail though if the whole thing was already part of a macro argument, in such cases one can use \PolDef rather. The colon in := may be active with no consequences.
As a consequence of xintfrac addition and subtraction always using least common multiples for the denominators, user-chosen common denominators survive additions and multiplications. For example, this:
\poldef P(x):= 1/2 + 2/2*x + 3/2*x^3 + 4/2*x^4; \poldef Q(x):= 1/3 + (2/3)x + (3/3)x^3 + (4/3)x^4; \poldef PQ(x):= P*Q;
gives internally the polynomial:
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
where all coefficients have the same denominator 6. Notice though that \PolToExpr{PQ} outputs the 6/6*x^3 as x^3 because (by default) it recognizes and filters out coefficients equal to one or minus one. One can use for example \PolToCSV{PQ} to see the internally stored coefficients.
\PolDiff{<polname_1>}{<polname_2>} always applies \xintPIrr to the resulting coefficients, which means that fractions are reduced to lowest terms but ignoring an already separated power of ten part [N] present in the internal representation. This is tentative and may change.
Same remark for \PolAntiDiff{<polname_1>}{<polname_2>}.
Currently, the package stores all coefficients from index 0 to index equal to the polynomial degree inside a single macro, as a list. This data structure is obviously very inefficient for polynomials of high degree and few coefficients (as an example with \poldef f(x):=x^1000 + x^500; the subsequent definition \poldef g(x):= f(x)^2; will do of the order of 1,000,000 multiplications and additions involvings only zeroes... which does take time). This may change in the future.
As is to be expected internal structures of the package are barely documented and unstable. Don't use them.
v0.1 (2018/01/11): initial release. Features:
The \poldef parser itself,
Differentiation and anti-differentiation,
Euclidean division and GCDs,
Various utilities such as \PolFromCSV, \PolMapCoeffs, \PolToCSV, \PolToExpr, ...
Only one-variable polynomials so far.
v0.2 (2018/01/14)
Fix: "README thinks \numexpr recognizes ^ operator".
Convert README to reStructuredText markup.
Move main documentation from README to separate polexpr.txt file.
Provide polexpr.html as obtained via DocUtils rst2html.py.
Convert README to (CTAN compatible) Markdown markup.
Due to lack of available time the test suite might not be extensive enough. Bug reports are very welcome!
v0.3 (2018/01/17)
bug fixes:
the 0.1 \PolEval accepted expressions for its second argument, but this was removed by mistake at 0.2. Restored.
Attention: at 0.4 this has been reverted again, and \PolEval{P}\AtExpr{foo} syntax is needed for using expressions in the second argument.
incompatible or breaking changes:
\PolToExpr now by default uses descending powers (it also treats differently coefficients equal to 1 or -1.) Use \PolToExpr* for ascending powers.
\PolEval reduced the output to smallest terms, but as this is costly with big fractions and not needed if e.g. wrapped in an \xintRound or \xintFloat, this step has been removed; the former meaning is available as \PolEvalReduced.
new (or newly documented) macros:
improvements:
documentation has a table of contents, internal hyperlinks, standardized signature notations and added explanations.
one can do \PolLet{g}={f} or \PolLet{g}{f}.
\PolToExpr{f} is highly customizable.
\poldef and other defining macros prepare the polynomial functions for usage within \xintthefloatexpr (or \xintdeffloatvar). Coefficients are pre-rounded to the floating point precision. Indispensible for numerical algorithms, as exact fractions, even reduced, quickly become very big. See the documentation about how to use the exact polynomials also in floating point context.
Attention: this has been reverted at 0.4. The macro \PolGenFloatVariant must be used for generation floating point polynomial functions.
v0.3.1 (2018/01/18)
Fixes two typos in example code included in the documentation.
v0.4 (2018/02/16)
bug fixes:
when Euclidean division gave a zero remainder, the internal representation of this zero polynomial could be faulty; this could cause mysterious bugs in conjunction with other package macros such as \PolMapCoeffs.
\PolGCD was buggy in case of first polynomial being of lesser degree than the second one.
breaking changes:
formerly \PolEval{P}\At{foo} allowed foo to be an expression, which was transparently handled via \xinttheexpr. Now, foo must be a fraction (or a macro expanding to such) in the format acceptable by xintfrac.sty macros. Use \PolEval{P}\AtExpr{foo} for more general arguments using expression syntax. E.g., if foo is the name of a variable known to \xintexpr.
The same holds for \PolEvalReduced and \PolFloatEval.
the 3.0 automatic generation of floating point variants has been reverted. Not only do not the package macros automatically generate floating point variants of newly created polynomials, they actually make pre-existing such variant undefined.
See \PolGenFloatVariant.
new non-expandable macros:
new expandable macros:
\PolPrintIntervalsTheEndPoint (removed at 0.7)
\PolIfEndPointIsPositive (removed at 0.7)
\PolIfEndPointIsNegative (removed at 0.7)
\PolIfEndPointIsZero (removed at 0.7)
improvements:
The main new feature is implementation of the Sturm algorithm for localization of the real roots of polynomials.
v0.4.1 (2018/03/01)
Synced with xint 1.3.
v0.4.2 (2018/03/03)
Documentation fix.
v0.5 (2018/04/08)
bug fixes:
\PolGet{<polname>}\fromarray\macro crashed when \macro was an xinttools array macro with no items. It now produces the zero polynomial.
breaking changes:
\PolToSturm creates primitive integer coefficients polynomials. This speeds up localization of roots via \PolSturmIsolateZeros. In case of user protests the author will make available again the code producing the bona fide Sturm polynomials as used formerly.
polynomials created from \PolFromCSV or \PolGet get their coefficients normalized via xintfrac's \xintRaw.
experimental change:
optional argument to \PolSturmIsolateZeros (see The degree 41 polynomial with -2, -1.9, -1.8, ..., 0, 0.1, ..., 1.9, 2 as roots for usage). It will presumably be replaced in future by an interval specification.
new non-expandable macro:
new expandable macro:
v0.5.1 (2018/04/22)
new feature:
the character ' can be used in polynomial names.
v0.6 (2018/11/20)
bugfix:
the starred variant \PolToSturm*{<polname>}{<sturmname>} was broken. On the occasion of the fix, its meaning has been modified, see its documentation.
using \PolToSturm with a constant polynomial caused a division by zero error.
new macro:
\PolSturmIsolateZeros* acts like the non-starred variant then computes all the multiplicities.
new expandable macros:
v0.7 (2018/12/08), v0.7.1 (bugfix), v0.7.2 (2nd bugfix) (2018/12/09)
breaking changes:
although \PolPrintIntervals[<varname>]{<sturmname>} default output remains the same, some auxiliary macros for user-customization have been removed: \PolPrintIntervalsTheEndPoint, \PolIfEndPointIsPositive{T}{F}, \PolIfEndPointIsNegative{T}{F}, and \PolIfEndPointIsZero{T}{F}.
bugfix:
it could happen that, contrarily to documentation, an interval computed by \PolSturmIsolateZeros{<sturmname>} had zero as an endpoint,
\PolEnsureIntervalLength{<sturmname>}{<index>}{<exponent>} could under certain circumstances erroneously replace a non-zero root by zero,
\PolEnsureIntervalLengths{<sturmname>}{<exponent>} crashed when used with a polynomial with no real roots, hence for which no isolation intervals existed (thanks to Thomas Söll for report).
new macros:
new expandable macros:
v0.7.3 (2019/02/04)
bugfix:
Debugging information not destined to user showed in log if root finding was done under \xintverbosetrue regime.
\PolPrintIntervalsTheVar remained defined after \PolPrintIntervals but was left undefined after \PolPrintIntervals* (reported by Jürgen Gilg). Now remains defined in both cases, and \PolPrintIntervalsTheSturmName also.
Polynomial names ending in digits caused errors (reported by Thomas Söll).
v0.7.4 (2019/02/12)
bugfix:
20000000000 is too big for \numexpr, shouldn't I know that? Thanks to Jürgen Gilg for report.
v0.7.5 (2020/01/31)
Synced with xintexpr 1.4. Requires it.
v0.8 (2021/03/29)
Synced with xintexpr 1.4d. Requires it.
breaking changes:
As the usability of character ' in names has been extended from \poldef to also generally \xintexpr, \xintdefvar, and \xintdeffunc, it means that the infix operators 'and', 'or', and 'mod' must be replaced by &&, ||, and /: if they follow immediately a variable name (similarly 'xor' must be replaced by the xor() function in such case).
\PolToExpr by default uses a catcode 12 ^. See its documentation and the new configuration \PolToExprCaret.
deprecated:
Usage of P/Q for the euclidean quotient of two polynomials is deprecated. Start using quo(P,Q) in its place.
bugfix:
The \xintglobaldefstrue setting was obeyed only partially by the polexpr macros defining polynomials.
The \xintexpr variables storing the values of the extremities of the intervals as found by \PolSturmIsolateZeros were not updated at 0.7.5 to the xintexpr 1.4 format and thus caused low-level TeX errors if used.
Attempting to use in \poldef a function previously declared via \xintdeffunc which made usage of the indexing or slicing "ople" syntax typically caused TeX capacity exceeded error. Indeed 0.7.5 only partially made polexpr able to cope with the extended possibilities for xintexpr 1.4 user-declared functions. Hopefully 0.8 achieves full functionality in this context.
new macros:
alongside the major new functionalities described in the next item \PolTypeset and \PolToExpr have been enhanced to accept as argument a general expression and not only a pre-declared polynomial name.
new features:
The package is usable under Plain and probably most any TeX format, and not only under LaTeX.
The core of the package has been rewritten entirely in order to start letting \xintexpr recognize a polynomial type as a genuine variable. This has allowed:
to solve the reduced inter-operability problems between polexpr and xintexpr which arose as consequences to the deep xintexpr 1.4 evolution,
to make available most of the functionality associated to expandable macros directly in the \xinteval syntax as operators or functions,
to provide (expandable) functional interface in \xinteval to features previously available only via (for some, non-expandable) macro interface such as gcd computations.
See the updated Quick syntax overview and then the extended syntax description.
v0.8.1 (2021/04/12)
breaking changes:
bugfix:
Sadly, diff1(), diff2(), diffn() were broken for polynomials of degrees 8 or more, due to a typo and insufficient testing.
The package should have (as documented) required xintexpr 1.4d but in practice it accepted to work with xintexpr 1.4c, whose \xinteval does not know how to "output" a polynomial.
The definition of one of the two variants of \PolSturmNbOfRootsOf was broken by an end-of-line space, left-over from mass conversion from LaTeX to TeX syntax.
added:
v0.8.2 (2021/05/05)
breaking change:
usage of \xintPFloat in place of \xintFloat for \PolToFloatExprCmd.
improved:
Some xintexpr functions such as rseq() use the semi-colon, and it was mentioned in the documentation that \poldef will be confused by this and that inner semi-colons could be set within braces {;} as a work-around. It was not clear from this documentation that also \PolDef required this work-around. With this relase only \poldef but not \PolDef needs the work-around.
track xintexpr 1.4e changes relative to powers.
v0.8.3 (2021/05/27)
small internal update to track an xintexpr 1.4h change regarding handling of exceptions. Will require this version at least on loading.
v0.8.4 (2021/11/01)
bugfix: \PolSturmIsolateZeros**{<sturmname>} did not declare the <sturmname>_norr and <sturmname>_sqf_norr polynomials if original polynomial had no real root!
Thanks to Jürgen Gilg whose question about xintexpr usage for differentiating polynomials was the initial trigger leading to this package, and to Jürgen Gilg and Thomas Söll for testing it on some concrete problems.
Renewed thanks to them on occasion of the 0.6, 0.7, and 0.8 releases for their continued interest.
See README.md for the License.