.. comment: -*- fill-column: 72; mode: rst; -*- =============================== Package polexpr documentation =============================== 0.3.1 (2018/01/18) ================== .. contents:: First Examples -------------- The syntax is:: \poldef polname(x):= expression in variable x; where in place of ``x`` an arbitrary *dummy variable* is authorized (i.e. per default any of ``[a-z|A-Z]``; more letters can be declared under Unicode engines.) One can also issue:: \PolDef{polname}{expression in variable x} which admits an optional first argument to modify the variable letter from its default ``x``. ``\poldef f(x):= 1-x+x^2;`` defines polynomial ``f``. Polynomial names must start with a letter and may contain letters, digits, and underscores. The variable must be a single letter. The colon character is optional. The semi-colon at end of expression is mandatory. ``\PolDef{f}{1-x+x^2}`` does the same as ``\poldef f(x):= 1-x+x^2;`` To use another letter than ``x`` in the expression, one must pass it as an extra optional argument to ``\PolDef``. Useful if the semi-colon has been assigned some non-standard catcode by some package. ``\PolLet{g}={f}`` saves a copy of ``f`` under name ``g``. Also usable without ``=``. ``\poldef f(z):= f(z)^2;`` redefines ``f`` in terms of itself. ``\poldef f(T):= f(f(T));`` again redefines ``f`` in terms of its (new) self. ``\poldef k(z):= f(z)-g(g(z)^2)^2;`` should now define the zero polynomial... Let's check: ``\[ k(z) = \PolTypeset[z]{k} \]`` ``\PolDiff{f}{df_dx}`` sets ``df_dx`` to the derivative of ``f``. ``\PolDiff{df_dx}{f_xx}`` obtains second derivative. ``\PolDiff[3]{f}{d3f_dx3}`` computes directly the third derivative. Its name does not have to be chosen so complicated ``:)``, but the right quote ``'`` is not allowed in polynomial names (currently). :: $f(z) = \PolTypeset[z]{f} $\newline $f'(z) = \PolTypeset[z]{df_dx}$\newline $f''(z) = \PolTypeset[z]{f_xx}$\newline $f'''(z)= \PolTypeset[z]{d3f_dx3}$\par .. important:: The package does not currently know rational functions: ``/`` in a parsed polynomial expression does the Euclidean quotient:: (1-x^2)/(1-x) does give ``1+x`` but :: (1/(1-x))*(1-x^2) evaluates to zero. This will work as expected:: \poldef k(x):= (x-1)(x-2)(x-3)(x-4)/(x^2-5x+4); .. _warningtacit: .. attention:: ``1/2 x^2`` skips the space and is treated like ``1/(2*x^2)`` because of the tacit multiplication rules of \xintexpr. But this means 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 even 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: xint_ tacit multiplication always "ties more", hence this gets interpreted as ``1/(2*(x-1)*(x-2))`` which gives zero by polynomial division. Thus, use one of ``(1/2)(x-1)(x-2)``, ``1/2*(x-1)(x-2)`` or ``(x-1)(x-2)/2``. After:: \poldef f_1(x):= 25(x-1)(x^2-2)(x-3)(x-4)(x-5);% \poldef f_2(x):= 37(x-1)(x^2-2)(x-6)(x-7)(x-8);% the macro call ``\PolGCD{f_1}{f_2}{k}`` sets ``k`` to the (unitary) GCD of ``f_1`` and ``f_2`` (hence to the expansion of ``(x-1)(x^2-2)``.) ``\PolToExpr{k}`` will (expandably) give in this case ``x^3-x^2-2*x+2``. This is useful for console or file output (the syntax is Maple- and PSTricks-compatible; the letter used in output can be (non-expandably) changed via a redefinition of `\\PolToExprVar`_.) ``\PolToExpr*{k}`` gives ascending powers: ``2-2*x-x^2+x^3``. Non-expandable macros --------------------- .. _poldef;: ``\poldef polname(letter):= expression in letter;`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This evaluates the *polynomial expression* and stores the coefficients in a private structure accessible later via other package macros, under the user-chosen ``polname``. Of course the *expression* can use other previously defined polynomials. Names must start with a letter and are constituted of letters, digits and underscore characters. The whole xintexpr_ syntax is authorized:: \poldef sin(z) := add((-1)^i z^(2i+1)/(2i+1)!, i = 0..10); With fractional coefficients, beware the `tacit multiplication issue `_. As a side effect the function ``polname()`` is recognized as a genuine ``\xintexpr...\relax`` function for (exact) numerical evaluation (or within an ``\xintdefvar`` assignment.) It computes values not according to the original expression but via the Horner scheme corresponding to the polynomial coefficients. Also, a function with the same name is created for use within ``\xintfloatexpr`` (or ``\xintdeffloatvar``.) This is indispensible for numerical algorithms as exact computations very quickly lead to very big fractions. Addition and multiplication steps of the Horner scheme will be executed as floating-point operations. The coefficients have already been rounded at time of definition, according to the then prevailing ``\xinttheDigits`` value. .. important:: Package macros (such as derivatives or Euclidean division) operate with the "exact" polynomials; "floating point" polynomials are always obtained in a second step. To modifiy "in-place" the original coefficients of a polynomial and round them to float precision:: \PolMapCoeffs{\xintFloat}{polname} % or \xintFloat[P] for precision P digits See `\\PolMapCoeffs{\\macro}{polname}`_. The original expression is lost after parsing, and in particular the package provides no way to typeset it. This has to be done manually, if needed. .. _PolDef: ``\PolDef[letter]{polname}{expression in letter}`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Does the same in an undelimited macro format (thus avoiding potential problems with the catcode of the semi-colon in presence of some packages.) In absence of the ``[letter]`` optional argument, the variable is assumed to be ``x``. ``\PolLet{polname_2}={polname_1}`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Makes a copy of the already defined polynomial ``polname_1`` to a new one ``polname_2``. Same effect as ``\PolDef{polname_2}{polname_1(x)}`` but with less overhead. The ``=`` is optional. ``\PolAssign{polname}\toarray\macro`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Defines a one-argument expandable macro ``\macro{#1}`` which expands to the (raw) #1th polynomial coefficient. - Attention, coefficients here are indexed starting at 1. - 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}{number}`_. The main difference is that with ``\PolAssign``, ``\macro`` is made a prefix to ``1 + deg f`` already defined (hidden to user) macros holding individually the coefficients but `\\PolNthCoeff{polname}{number}`_ does each time the job to expandably recover the ``Nth`` coefficient, and due to expandability can not store it in a macro for future usage (of course, it can be an argument in an ``\edef``.) The other difference is the shift by one in indexing, mentioned above (negative indices act the same in both.) ``\PolGet{polname}\fromarray\macro`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Does the converse operation to ``\PolAssign{polname}\toarray\macro``. No error checks on validity of coefficients as numbers. Each ``\macro{number}`` is expanded in an ``\edef`` before being assigned to a coefficient. Leading zero coefficients are removed from the polynomial. (contrived) Example:: \xintAssignArray{1}{-2}{5}{-3}\to\foo \PolGet{f}\fromarray\foo This will define ``f`` as would have ``\poldef f(x):=1-2x+5x^2-3x^3;``. However the coefficients are still in their original form (i.e. they were not subjected to ``\xintRaw`` or similar xintfrac macro.) ``\PolFromCSV{polname}{}`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Defines a polynomial directly from the comma separated list of values (or a macro expanding to such a list) of its coefficients, the constant term being the first item. No validity checks. Spaces from the list argument are trimmed. List items are each expanded in an ``\edef``, but currently left in their original form like e.g. ``1.5e3`` which is not converted to ``15/1[2]`` *raw* xintfrac format (this may change). Leading zero coefficients are removed:: \PolFromCSV{f}{0, 0, 0, 0, 0, 0, 0, 0, 0, 0} defines the zero polynomial, which has only one (zero) coefficient. See also expandable macro `\\PolToCSV <\\PolToCSV{polname}_>`_. ``\PolTypeset{polname}`` ~~~~~~~~~~~~~~~~~~~~~~~~ Typesets in descending powers in math mode. It uses letter ``x`` but this can be changed via an optional argument:: \PolTypeset[z]{polname} By default zero coefficients are skipped (issue ``\poltypesetalltrue`` to get all of them in output). These commands (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. ``\PolTypesetCmd{raw_coeff}`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Basically will use ``\xintSignedFrac`` from xintfrac_, but checks if the coefficient is ``1`` or ``-1`` and then skips printing the ``1``, except for the constant term... One can do things such as for example: [#]_ :: \renewcommand\PolTypesetCmd[1]{\num{\xintPFloat[5]{#1}}} \renewcommand\PolTypesetCmd[1]{\num{\xintRound{4}{#1}}} where e.g. we used the ``\num`` macro of ``siunitx`` as it understands floating point notation. .. [#] the difference in the syntaxes of ``\xintPFloat`` and ``\xintRound`` is explained from the fact that ``\xintPFloat`` by default uses the prevailing precision hence the extra argument like here ``5`` is an optional one. ``\PolTypesetCmdPrefix{raw_coeff}`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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`` 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. ``\PolTypesetMonomialCmd`` ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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. ``\PolTypeset*{polname}`` ~~~~~~~~~~~~~~~~~~~~~~~~~ Typesets in ascending powers. Use e.g. ``[h]`` optional argument (after the ``*``) to use letter ``h`` rather than ``x``. ``\PolDiff{polname_1}{polname_2}`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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.) ``\PolDiff[N]{polname_1}{polname_2}`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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``. ``\PolAntiDiff{polname_1}{polname_2}`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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.) ``\PolAntiDiff[N]{polname_1}{polname_2}`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This sets ``polname_2`` to the result of ``N`` successive integrations on ``polname_1``. With negative ``N``, it switches to using ``\PolDiff``. ``\PolDivide{polname_1}{polname_2}{polname_Q}{polname_R}`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This sets ``polname_Q`` and ``polname_R`` to be the quotient and remainder in the Euclidean division of ``polname_1`` by ``polname_2``. ``\PolGCD{polname_1}{polname_2}{polname_GCD}`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This sets ``polname_GCD`` to be the G.C.D. It is a unitary polynomial except if both ``polname_1`` and ``polname_2`` vanish, then ``polname_GCD`` is the zero polynomial. ``\PolMapCoeffs{\macro}{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 replacement text of ``\macro``, ``\index`` expands to the coefficient index (which is defined to be zero for the constant term). Notice that ``\macro`` will have to handle inputs of the shape ``A/B[N]`` (xintfrac_ internal notation). This means that it probably will have to be expressed in terms of macros from 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``. ``\PolReduceCoeffs{polname}`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ About the same as ``\PolMapCoeffs{\xintIrr}{polname}`` (but maintaining a ``[0]`` postfix for speedier xintfrac_ parsing when polynomial function is used for computations.) This is a one-argument macro, working 'in-place'. Expandable macros ----------------- All these macros expand completely in two steps except ``\PolToExpr`` and ``\PolToFloatExpr`` (and their auxiliaries) which need a ``\write``, ``\edef`` or a ``\csname...\endcsname`` context. ``\PolEval{polname}\At{numerical expression}`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It boils down to ``\xinttheexpr polname(numerical expression)\relax``. .. note:: The ``0.2`` version stupidly tried to be clever and as a result of a misguided optimization choked if ``value`` was not a number but a numerical expression (a sum e.g.), but the more powerful behaviour has been reinstored at ``0.3`` release. The ``0.1`` and ``0.2`` version did a ``reduce`` which however is costly on big fractions and irrelevant if the output is served as argument of ``\xintRound`` or ``\xintFloat``. Thus ``reduce`` was removed, and former meaning is now available as `\\PolEvalReduced{polname}\\At{numerical expression}`_ ``\PolEvalReduced{polname}\At{numerical expression}`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Boils down to ``\xinttheexpr reduce(polname(numerical expression))\relax``. ``\PolFloatEval{polname}\At{numerical expression}`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Boils down to ``\xintthefloatexpr polname(numerical expression)\relax``. This is done via a Horner Scheme (see `\\poldef `_), with already rounded coefficients. [#]_ To use the *exact coefficients* (and *exact* additions and multiplications), just insert it in the float expression as in this example: [#]_ :: \xintthefloatexpr 3.27*\xintexpr f(2.53)\relax^2\relax The ``f(2.53)`` is exactly computed then rounded at the time of getting raised to the power ``2``. Moving the ``^2`` inside, that operation would also be treated exactly. .. [#] Anyway each floating point operation starts by rounding its operands to the floating point precision. .. [#] The ``\xintexpr`` could be ``\xinttheexpr`` but that would be less efficient. Cf. xintexpr_ documentation about nested expressions. ``\PolNthCoeff{polname}{number}`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It expands to the raw ``N``-th coefficient (``0/1[0]`` if the index number is out of range). With ``N=-1``, ``-2``, ... expands to the leading coefficients. ``\PolDegree{polname}`` ~~~~~~~~~~~~~~~~~~~~~~~ It expands to the degree. This is ``-1`` if zero polynomial but this may change in future. Should it then expand to ``-\infty`` ? ``\PolToExpr{polname}`` ~~~~~~~~~~~~~~~~~~~~~~~ Expands [#]_ to ``coeff_N*x^N+...`` (descending powers.) .. [#] in a ``\write``, ``\edef``, or ``\csname...\endcsname``, but not under ``\romannumeral-`0``. By default zero coefficients are skipped (issue ``\poltoexpralltrue`` to get all of them in output). By default, no ``+`` sign before negative coefficients, for compliance with Maple input format (but see `\\PolToExprTermPrefix{raw_coeff}`_.) Also, like the default behaviour of `\\PolTypeset{polname}`_, does not print (for the non constant terms) coefficients equal to plus or minus one. The degree one monomial is output as ``x``, not ``x^1``. Complete customization is possible, see next macros. Of course ``\PolToExpr{f}`` can be inserted in a ``\poldef``, as the latter expands token by token, hence will force complete expansion of ``\PolToExpr{f}``, but a simple ``f(x)`` is more efficient for the identical result. ``\PolToExprOneTerm{raw_coeff}{number}`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This two argument expandable command takes care of the monomial and its coefficient. The default definition is done in order for coefficients of absolute value ``1`` not be printed explicitely (except of course for the constant term). Also by default, the monomial of degree one is ``x`` not ``x^1``, and ``x^0`` is skipped. For compatibility with Maple input requirements, by default a ``*`` always precedes the ``x^number``, except if the coefficient is a one or a minus one. See `\\PolToExprTimes`_. ``\PolToExprOneTermStyleB{raw_coeff}{number}`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For output in this style:: 2*x^11/3+3*x^8/7-x^5−x^4/4−x^3−x^2/2−2*x+1 issue ``\let\PolToExprOneTerm\PolToExprOneTermStyleB`` before using ``\PolToExpr``. Note that then ``\PolToExprCmd`` isn't used at all. To suppress the ``*``'s, cf. `\\PolToExprTimes`_. ``\PolToExprCmd{raw_coeff}`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ It is the one-argument macro used by the package definition of ``\PolToExprOneTerm`` for the coefficients themselves (when not equal to plus or minus one), and it defaults to ``\xintPRaw{\xintRawWithZeros{#1}}``. One will have to redefine it to ``\xintIrr{#1}`` or to ``\xintPRaw{\xintIrr{#1}}`` to obtain in the output forcefully reduced coefficients. ``\PolToExprTermPrefix{raw_coeff}`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Defined identically as `\\PolTypesetCmdPrefix{raw_coeff}`_. It prefixes with a plus sign for non-negative coefficients, because they don't carry one by themselves. ``\PolToExprVar`` ^^^^^^^^^^^^^^^^^ This expands to the variable to use in output (it does not have to be a single letter, may be an expandable macro.) Initial definition is ``x``. ``\PolToExprTimes`` ^^^^^^^^^^^^^^^^^^^ This expands to the symbol used for multiplication of an ``x^{number}`` by the corresponding coefficient. The default is ``*``. Redefine the macro to expand to nothing to get rid of it (but this will give output incompatible with some professional computer algebra software). ``\PolToExpr*{polname}`` ~~~~~~~~~~~~~~~~~~~~~~~~ Expands to ``coeff_0+coeff_1*x+coeff_2*x^2+...`` (ascending powers). Customizable like `\\PolToExpr{polname}`_ via the same macros. ``\PolToFloatExpr{polname}`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Similar to `\\PolToExpr{polname}`_ but uses `\\PolToFloatExprCmd <\\PolToFloatExprCmd{raw_coeff}>`_ which by default rounds and converts the coefficients to floating point format. .. note:: The polynomial function for usage in ``\xintfloatexpr`` is already prepared with the rounded coefficients, but the latter are not easily recoverable (and especially not expandably) from this. Thus ``\PolToFloatExprCmd`` operates from the *exact* coefficients anew. This means though that if the prevailing float precision was changed with ``\xintDigits:=P;`` syntax, the output will obey this precision ``P``, but the polynomial function was defined earlier and operates on floating point numbers with coefficients which were rounded at time of definition. This may change in future, if the pre-rounded coefficients are stored in a more easily accessible data structure. ``\PolToFloatExprOneTerm{raw_coeff}{number}`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Similar to `\\PolToExprOneTerm <\\PolToExprOneTerm{raw_coeff}{number}>`_. But does not treat especially coefficients equal to plus or minus one. ``\PolToFloatExprCmd{raw_coeff}`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ It is the one-argument macro used by ``\PolToFloatExprOneTerm``. Its package definition is ``\xintFloat{#1}``. .. caution:: Currently (xint_ ``1.2p``) ``\xintFloat{0}`` outputs ``0.e0`` which is perfectly acceptable input for Python, but not for Maple. Thus, one should better leave the `\\poltoexprallfalse`_ toggle to its default ``\iffalse`` state, if one intends to use the output in a Maple worksheet. But even then the zero polynomial will cause a problem. Workaround:: \renewcommand\PolToFloatExprCmd[1]{\xintiiifZero{#1}{0.0}{\xintFloat{#1}}} Usage of ``\xintiiifZero`` and not ``\xintifZero`` is only for optimization (I can't help it) because ``#1`` is known to be in ``xintfrac`` raw format. ``\PolToFloatExpr*{polname}`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Typesets in ascending powers. ``\PolToList{polname}`` ~~~~~~~~~~~~~~~~~~~~~~~ Expands to ``{coeff_0}{coeff_1}...{coeff_N}`` with ``N`` = degree (except zero polynomial which does give ``{0/1[0]}`` and not an empty output.) ``\PolToCSV{polname}`` ~~~~~~~~~~~~~~~~~~~~~~ Expands to ``coeff_0, coeff_1, coeff_2, ....., coeff_N``. Converse to `\\PolFromCSV <\\PolFromCSV{polname}{\}_>`_. Booleans (with default setting as indicated) -------------------------------------------- ``\xintverbosefalse`` ~~~~~~~~~~~~~~~~~~~~~ This is actually an xintexpr_ configuration. Setting it to ``true`` triggers the writing of information to the log when new polynomials are defined. .. caution:: The macro meanings as written to the log are to be considered unstable and undocumented internal structures. ``\poltypesetallfalse`` ~~~~~~~~~~~~~~~~~~~~~~~ If ``true``, `\\PolTypeset{polname}`_ will also typeset the vanishing coefficients. ``\poltoexprallfalse`` ~~~~~~~~~~~~~~~~~~~~~~ If ``true``, `\\PolToExpr{polname}`_ and `\\PolToFloatExpr{polname}`_ will also include the vanishing coefficients in their outputs. Technicalities -------------- - 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{f}{P(x)} `_ rather. The colon in ``:=`` may be active with no consequences. - During execution of polynomial operations by ``\poldef`` (but not during the initial purely numerical parsing of the expression), the xintfrac_ macro ``\xintAdd`` is temporarily patched to always express ``a/b + c/d`` with ``l.c.m.(b,d)`` as denominator. Indeed the current (xint 1.2p) ``\xintAdd`` uses ``(ad+bc)/bd`` formula except if ``b`` divides ``d`` or ``d`` divides ``b``, which quickly leads in real life to big denominators. It is probable that this convention will be backported as default behaviour of xintfrac's ``\xintAdd`` in a future xint release. When this change is merged, there will be an impact on coefficients computed by ``\poldef`` because the change will apply even to the pure numerical evaluations arising during the initial stage of the parsing. Of course the coefficients are still the same rational numbers, only representation as fractions may change. - As a consequence of previous rule, user-chosen common denominators survive addition and multiplications:: \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(x)Q(x); gives 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 (which in this example is the ``l.c.m`` of the denominators of the reduced coefficients.) - `\\PolDiff{polname_1}{polname_2}`_ always applies ``\xintIrr`` to the resulting coefficients, except that the *power of ten* part ``[N]`` (for example an input in scientific notation such as ``1.23e5`` gives ``123/1[3]`` internally in xintfrac) is not taken into account in the reduction of the fraction. This is tentative and may change. Same remark for `\\PolAntiDiff{polname_1}{polname_2}`_. - If ``f`` was created from comma separated values by macro `\\PolFromCSV{polname}{\}`_, then the coefficients will be in the output of `\\PolToList{polname}`_ and `\\PolToCSV{polname}`_ in the same format as originally in input: a ``1.3e2`` will again be a ``1.3e2``. In contrast when such coefficients are used in a ``\poldef`` (or ``\PolDef``) expression, they get transformed during the parsing to the xintfrac *raw* format. This *raw* format speeds up expansion of xintfrac macros for numerical evaluations. - 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. - Tests have been made with Newton's iteration (for which computing exactly the derivative is precisely what this package is made for) or Regula Falsi method for locating roots: using exact computations leads quickly to gigantic fractions (but dichotomy method much less so). It is thus recommended to use ``\xintdeffloatvar`` or ``\xintthefloatexpr`` contexts for any kind of numerical mathematics. Of course, exact computations are invaluable for number theory or combinatorics... - As is to be expected internal structures of the package are barely documented and unstable. Don't use them. RELEASES -------- - 0.1 (2018/01/11) Initial release (files README, polexpr.sty). - 0.2 (2018/01/14) Documentation moved to polexpr.{txt,html}. - 0.3 (2018/01/17) Make polynomials known to ``\xintfloatexpr`` and improve documentation. - 0.3.1 (2018/01/18) Fix two typos in documentation. Files of 0.3.1 release: - README.md, - polexpr.sty (package file), - polexpr.txt (documentation), - polexpr.html (conversion via `DocUtils`__ rst2html.py) __ http://docutils.sourceforge.net/docs/index.html See README.md for the License and the change log (there were some breaking changes from 0.2 to 0.3). Acknowledgments --------------- Thanks to Jürgen Gilg whose question about xint_ 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. .. _xintfrac: .. _xintexpr: .. _xint: http://www.ctan.org/pkg/xint