diff options
author | Karl Berry <karl@freefriends.org> | 2018-01-18 23:25:24 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2018-01-18 23:25:24 +0000 |
commit | ab1f1f27607fc9dfce015d503843e67a46df1acd (patch) | |
tree | 638e43e6642516f42b16dc852d03a24f2b2251dc /Master/texmf-dist/tex | |
parent | 58626540c966a36cd7d83fc83a3aee629913ecec (diff) |
polexpr (18jan18)
git-svn-id: svn://tug.org/texlive/trunk@46377 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/polexpr/polexpr.sty | 202 |
1 files changed, 165 insertions, 37 deletions
diff --git a/Master/texmf-dist/tex/latex/polexpr/polexpr.sty b/Master/texmf-dist/tex/latex/polexpr/polexpr.sty index 9f2bd0c0ea5..752efa3fa77 100644 --- a/Master/texmf-dist/tex/latex/polexpr/polexpr.sty +++ b/Master/texmf-dist/tex/latex/polexpr/polexpr.sty @@ -1,7 +1,7 @@ % author: Jean-François Burnol % License: LPPL 1.3c (author-maintained) \ProvidesPackage{polexpr}% - [2018/01/14 v0.2 Polynomial expressions with rational coefficients (JFB)]% + [2018/01/18 v0.3.1 Polynomial expressions with rational coefficients (JFB)]% \RequirePackage{xintexpr}[2016/03/19]% xint 1.2g (or 1.2c 2015/11/16 at least) \edef\POL@restorecatcodes {\catcode`\noexpand\_ \the\catcode`\_ \catcode0 \the\catcode0\relax}% @@ -76,12 +76,16 @@ %% \def\POL@newpol#1{% \expandafter\POL@ifZero\csname POLuserpol@#1\endcsname - {\@namedef{XINT_expr_userfunc_#1}##1,{0/1[0]}}% + {\@namedef{XINT_expr_userfunc_#1}##1,{0/1[0]}% + \@namedef{XINT_flexpr_userfunc_#1}##1,{0[0]}}% {\POL@newpolhorner{#1}}% \unless\ifcsname XINT_expr_userfuncNE:#1\endcsname\POL@addtoextras{#1}\fi \expandafter\XINT_expr_defuserfunc \csname XINT_expr_func_#1\expandafter\endcsname \csname XINT_expr_userfunc_#1\endcsname + \expandafter\XINT_expr_defuserfunc + \csname XINT_flexpr_func_#1\expandafter\endcsname + \csname XINT_flexpr_userfunc_#1\endcsname \ifxintverbose\POL@info{#1}\fi }% \def\POL@info #1{% @@ -90,7 +94,11 @@ associated to \string\XINT_expr_userfunc_#1\space whose meaning uses Horner scheme: \expandafter\meaning - \csname XINT_expr_userfunc_#1\endcsname}% + \csname XINT_expr_userfunc_#1\endcsname^^J% + \@spaces And \string\XINT_flexpr_userfunc_#1\space for + the \string\xintfloatexpr\space parser has meaning + \expandafter\meaning + \csname XINT_flexpr_userfunc_#1\endcsname}% }% % \def\POL@newpolhorner#1{% @@ -102,17 +110,37 @@ \edef\POL@var@coeffs{\xintRevWithBraces{\POL@var@coeffs}}% \begingroup \expandafter\POL@newpol@horner\POL@var@coeffs\relax + \expandafter + \endgroup + \expandafter\def\csname XINT_expr_userfunc_#1\expandafter\endcsname + \expandafter##\expandafter1\expandafter,\expandafter{\POL@tmp{##1}}% + \begingroup + \expandafter\POL@newpol@floathorner\POL@var@coeffs\relax + \expandafter \endgroup - \expandafter\let\csname XINT_expr_userfunc_#1\endcsname\POL@tmp + \expandafter\def\csname XINT_flexpr_userfunc_#1\expandafter\endcsname + \expandafter##\expandafter1\expandafter,\expandafter{\POL@tmp{##1}}% }% \def\POL@newpol@horner#1{\let\xintAdd\relax\let\xintMul\relax - \gdef\POL@tmp##1,{#1}\POL@newpol@horner@loop.}% + \def\POL@tmp##1{#1}\POL@newpol@horner@loop.}% \def\POL@newpol@horner@loop.#1{% \if\relax#1\expandafter\xint_gob_til_dot\fi - \xdef\POL@tmp##1,{\xintiiifZero{#1}{\@firstofone}{\xintAdd{#1}}% - {\xintMul{##1}{\POL@tmp##1,}}}% + \edef\POL@tmp##1{\xintiiifZero{#1} + {\@firstofone}{\xintAdd{#1}}% + {\xintMul{##1}{\POL@tmp{##1}}}}% \POL@newpol@horner@loop.% }% +\def\POL@newpol@floathorner#1{\let\XINTinFloatAdd\relax\let\XINTinFloatMul\relax + \def\xintAdd{\XINTinFloatAdd}\def\xintMul{\XINTinFloatMul}% + \edef\POL@tmp##1{\XINTinFloatdigits{#1}}% + \POL@newpol@floathorner@loop.}% +\def\POL@newpol@floathorner@loop.#1{% + \if\relax#1\expandafter\xint_gob_til_dot\fi + \edef\POL@tmp##1{\xintiiifZero{#1} + {\@firstofone}{\xintAdd{\XINTinFloatdigits{#1}}}% + {\xintMul{##1}{\POL@tmp{##1}}}}% + \POL@newpol@floathorner@loop.% +}% %% Customizes xintexpr.sty's \XINT_NewExpr (\POL@addtoextras{name}) \begingroup \catcode`~ 12 @@ -150,15 +178,24 @@ \def\POL@redefinemacros{\POL@original_redefinemacros\POL@redefineextras}% \let\POL@redefineextras\@empty % -\newcommand\PolLet[2]{% +\newcommand\PolLet[2]{\if=\noexpand#2\expandafter\xint_firstoftwo + \else\expandafter\xint_secondoftwo\fi + \POL@@let\POL@let {#1}{#2}}% +\def\POL@@let#1#2#3{\POL@let{#1}{#3}}% +\def\POL@let#1#2{% \expandafter\let\csname POLuserpol@#1\expandafter\endcsname \csname POLuserpol@#2\endcsname \unless\ifcsname XINT_expr_userfuncNE:#1\endcsname\POL@addtoextras{#1}\fi \expandafter\let\csname XINT_expr_userfunc_#1\expandafter\endcsname \csname XINT_expr_userfunc_#2\endcsname + \expandafter\let\csname XINT_flexpr_userfunc_#1\expandafter\endcsname + \csname XINT_flexpr_userfunc_#2\endcsname \expandafter\XINT_expr_defuserfunc \csname XINT_expr_func_#1\expandafter\endcsname \csname XINT_expr_userfunc_#1\endcsname + \expandafter\XINT_expr_defuserfunc + \csname XINT_flexpr_func_#1\expandafter\endcsname + \csname XINT_flexpr_userfunc_#1\endcsname \ifxintverbose\POL@info{#1}\fi }% @@ -230,12 +267,12 @@ \newif\ifpoltypesetall -\newcommand\PolTypesetPlus[1]{\xintiiifSgn{#1}{}{+}{+}}% +\newcommand\PolTypesetCmdPrefix[1]{\xintiiifSgn{#1}{}{+}{+}}% \newcommand\PolTypesetCmd[1]{\xintifOne{\xintiiAbs{#1}}% {\ifnum\PolIndex=\z@\xintiiSgn{#1}\else \xintiiifSgn{#1}{-}{}{}\fi}% {\xintSignedFrac{#1}}}% -\newcommand\PolTypesetMonomial{% +\newcommand\PolTypesetMonomialCmd{% \ifcase\PolIndex\space % \or\PolVar @@ -262,12 +299,12 @@ \fi \def\PolVar{#1}% \ifnum\POL@var@deg<\z@ - \PolTypesetCmd{0/1[0]}% + \PolTypesetCmd{0/1[0]}\PolTypesetMonomialCmd \else \ifnum\POL@var@deg=\z@ - \expandafter\PolTypesetCmd\POL@var@coeffs + \expandafter\PolTypesetCmd\POL@var@coeffs\PolTypesetMonomialCmd \else - \def\POL@ts@plus##1{\let\POL@ts@plus\PolTypesetPlus}% + \def\POL@ts@prefix##1{\let\POL@ts@prefix\PolTypesetCmdPrefix}% \expandafter\POL@ts@loop \romannumeral-`0\POL@ts@reverse{\POL@var@coeffs}\relax \fi @@ -282,12 +319,12 @@ \if\relax#1\expandafter\xint_gob_til_dot\fi \xintiiifZero{#1}% {}% - {\POL@ts@plus{#1}\PolTypesetCmd{#1}\PolTypesetMonomial}% + {\POL@ts@prefix{#1}\PolTypesetCmd{#1}\PolTypesetMonomialCmd}% \edef\PolIndex{\the\numexpr\PolIndex+\POL@@ne@or@m@ne}\POL@ts@check.% }% \def\POL@ts@nocheck.#1{% \if\relax#1\expandafter\xint_gob_til_dot\fi - \POL@ts@plus{#1}\PolTypesetCmd{#1}\PolTypesetMonomial + \POL@ts@prefix{#1}\PolTypesetCmd{#1}\PolTypesetMonomialCmd \edef\PolIndex{\the\numexpr\PolIndex+\POL@@ne@or@m@ne}\POL@ts@nocheck.% }% @@ -495,7 +532,7 @@ \else\xint_afterfi{\POL@Iterate\POL@Diff@one}% \fi }% -\def\POL@Diff@no #1#2{\PolLet{#2}{#1}}% +\def\POL@Diff@no #1#2{\POL@let{#2}{#1}}% \def\POL@Diff@one #1#2{% \expandafter\expandafter\expandafter\POL@split \csname POLuserpol@#1\endcsname;\POL@var@deg\POL@var@coeffs @@ -920,11 +957,17 @@ %% EXPANDABLE MACROS \newcommand\PolEval{}% -\def\PolEval#1#2\At#3{% +\def\PolEval#1#2\At#3{\romannumeral`^^@\xinttheexpr #1(#3)\relax}% +% +\newcommand\PolEvalReduced{}% +\def\PolEvalReduced#1#2\At#3{% \romannumeral0\xintpraw % only serves to not print denominator if = 1 - {\xintIrr{\csname XINT_expr_userfunc_#1\endcsname {#3},}[0]}% + {\xintIrr{\romannumeral`^^@\xintthebareeval#1(#3)\relax}[0]}% }% % +\newcommand\PolFloatEval{}% +\def\PolFloatEval#1#2\At#3{\romannumeral`^^@\xintthefloatexpr #1(#3)\relax}% +% \newcommand\PolNthCoeff[2]{\romannumeral`^^@% \expandafter\POL@nthcoeff \romannumeral0\xintnthelt{\ifnum\numexpr#2<\z@#2\else(#2)+1\fi}% @@ -949,34 +992,119 @@ \newif\ifpoltoexprall \newcommand\PolToExprCmd[1]{\xintPRaw{\xintRawWithZeros{#1}}}% -\newcommand\PolToExprCmdWithSep[1]{\xintiiifSgn{#1}{}{+}{+}\PolToExprCmd{#1}}% -\newcommand\PolToExpr[1]{\expandafter\expandafter\expandafter - \POL@toexpr\csname POLuserpol@#1\endcsname\relax}% -% -\def\POL@toexpr#1.\empty{% - \ifnum#1<\z@ - \PolToExprCmd{0/1[0]}\expandafter\@gobbletwo +\newcommand\PolToFloatExprCmd[1]{\xintFloat{#1}}% +\let\PolToExprTermPrefix\PolTypesetCmdPrefix +\newcommand\PolToExprOneTerm[2]{% + \ifnum#2=\z@ + \PolToExprCmd{#1}% + \else + \xintifOne{\xintiiAbs{#1}} + {\xintiiifSgn{#1}{-}{}{}}% + from \PolToExprTermPrefix + {\PolToExprCmd{#1}\PolToExprTimes}% + \fi + \ifcase\xintiiAbs{#2} %<-- space here mandatory + \or\PolToExprVar + \else\PolToExprVar^\xintiiAbs{#2}% + \fi +}% +\newcommand\PolToExprOneTermStyleB[2]{% + \ifnum#2=\z@ + \xintNumerator{#1}% \else - \expandafter\POL@toexpr@a - \fi}% + \xintifOne{\xintiiAbs{\xintNumerator{#1}}} + {\xintiiifSgn{#1}{-}{}{}}% + from \PolToExprTermPrefix + {\xintNumerator{#1}\PolToExprTimes}% + \fi + \ifcase\xintiiAbs{#2} %<-- space here mandatory + \or\PolToExprVar + \else\PolToExprVar^\xintiiAbs{#2}% + \fi + \xintiiifOne{\xintDenominator{#1}}{}{/\xintDenominator{#1}}% +}% +\newcommand\PolToFloatExprOneTerm[2]{% + \ifnum#2=\z@ + \PolToFloatExprCmd{#1}% + \else + \PolToFloatExprCmd{#1}\PolToExprTimes + \fi + \ifcase\xintiiAbs{#2} %<-- space here mandatory + \or\PolToExprVar + \else\PolToExprVar^\xintiiAbs{#2}% + \fi +}% +\newcommand\PolToExprTimes{*}% +\newcommand\PolToExprVar{x}% +\newcommand\PolToExpr[1]{% + \if*\noexpand#1\expandafter\xint_firstoftwo\else + \expandafter\xint_secondoftwo\fi + \PolToExprAscending\PolToExprDescending{#1}}% +\newcommand\PolToFloatExpr[1]{% + \if*\noexpand#1\expandafter\xint_firstoftwo\else + \expandafter\xint_secondoftwo\fi + \PolToFloatExprAscending\PolToFloatExprDescending{#1}}% +\newcommand\PolToExprAscending[2]{% + \expandafter\POL@toexpr\csname POLuserpol@#2\endcsname + \PolToExprOneTerm\POL@toexprA}% +\newcommand\PolToFloatExprAscending[2]{% + \expandafter\POL@toexpr\csname POLuserpol@#2\endcsname + \PolToFloatExprOneTerm\POL@toexprA}% +\newcommand\PolToExprDescending[1]{% + \expandafter\POL@toexpr\csname POLuserpol@#1\endcsname + \PolToExprOneTerm\POL@toexprD}% +\newcommand\PolToFloatExprDescending[1]{% + \expandafter\POL@toexpr\csname POLuserpol@#1\endcsname + \PolToFloatExprOneTerm\POL@toexprD}% % -\def\POL@toexpr@a #1{\ifpoltoexprall\expandafter\POL@toexprall@b - \else\expandafter\POL@toexpr@b - \fi{#1}{}\PolToExprCmd0.}% +\def\POL@toexpr#1#2#3{\expandafter\POL@toexpr@ + \expandafter#3\expandafter#2#1\relax}% +\def\POL@toexpr@#1#2#3.{% + \ifnum#3<\z@ + #2{0/1[0]}{0}\expandafter\xint_gobble_v + \else + \expandafter#1% + \fi {#3}#2}% % +\def\POL@toexprA #1#2\empty#3{% + \ifpoltoexprall\expandafter\POL@toexprall@b + \else\expandafter\POL@toexpr@b + \fi {#3}#2{0}1.% +}% +\def\POL@toexprD #1#2#3\relax{% #3 has \empty to prevent brace removal + \expandafter\POL@toexprD@a\expandafter#2% + \the\numexpr #1\expandafter.\romannumeral0\xintrevwithbraces{#3}\relax +}% +\def\POL@toexprD@a #1#2.#3{% + \ifpoltoexprall\expandafter\POL@toexprall@b + \else\expandafter\POL@toexpr@b + \fi{#3}#1{-#2}\the\numexpr\@ne+-#2.% +}% \def\POL@toexpr@b #1#2#3{% \xintiiifZero{#1}% - {\expandafter\POL@toexpr@loop\expandafter#3}% - {#3{#1}#2\expandafter\POL@toexpr@loop\expandafter\PolToExprCmdWithSep}% - \expandafter\POL@toexpr@b\the\numexpr\@ne+% + {\expandafter\POL@toexpr@loop\expandafter\POL@toexpr@b}% + {#2{#1}{#3}% + \expandafter\POL@toexpr@loop\expandafter\POL@toexpr@c}% + \expandafter#2% +}% +\def\POL@toexpr@c #1#2#3{% + \xintiiifZero{#1}% + {}% + {\PolToExprTermPrefix{#1}#2{#1}{#3}}% + \expandafter\POL@toexpr@loop\expandafter\POL@toexpr@c + \expandafter#2% }% \def\POL@toexprall@b #1#2#3{% - #3{#1}#2% - \expandafter\POL@toexpr@loop\expandafter\PolToExprCmdWithSep - \expandafter\POL@toexprall@b\the\numexpr\@ne+% + #2{#1}{#3}% + \expandafter\POL@toexpr@loop\expandafter\POL@toexprall@c + \expandafter#2% +}% +\def\POL@toexprall@c #1#2#3{% + \PolToExprTermPrefix{#1}#2{#1}{#3}% + \expandafter\POL@toexpr@loop\expandafter\POL@toexprall@c + \expandafter#2% }% \def\POL@toexpr@loop#1#2#3.#4{% - \if\relax#4\expandafter\xint_gob_til_dot\fi #2{#4}{*x^#3}#1#3.% + \if\relax#4\expandafter\xint_gob_til_dot\fi + #1{#4}#2{#3}\the\numexpr\@ne+#3.% }% |