diff options
Diffstat (limited to 'Master/texmf-dist/source/generic/xint/xint.dtx')
-rw-r--r-- | Master/texmf-dist/source/generic/xint/xint.dtx | 833 |
1 files changed, 489 insertions, 344 deletions
diff --git a/Master/texmf-dist/source/generic/xint/xint.dtx b/Master/texmf-dist/source/generic/xint/xint.dtx index 96abc77b56a..7e8e6bb2c34 100644 --- a/Master/texmf-dist/source/generic/xint/xint.dtx +++ b/Master/texmf-dist/source/generic/xint/xint.dtx @@ -1,17 +1,20 @@ % -*- coding: iso-latin-1; -*- -% -% File: xint.dtx -% Source of the xint bundle -% Version: 1.01 of April 4, 2013 -% Copyright (C) 2013 by Jean-Francois Burnol -% -% Current style files in the bundle: +% This file: xint.dtx (1.02, 2013/04/05) +%% +%%---------------------------------------------------------------- +%% The xint bundle (version 1.02 of April 5, 2013) +%<xint>%% xint: Expandable operations on long numbers +%<xintgcd>%% xintgcd: Euclidean algorithm with xint package +%% Copyright (C) 2013 by Jean-Francois Burnol +%%---------------------------------------------------------------- +%% +% Style files in the bundle: % (base) xint.sty Expandable operations on long numbers % xintgcd.sty Euclidean algorithm with xint package -% -% This work consists of the source file xint.dtx and of its -% derived files xint.sty, xintgcd.sty, xint.ins and the -% documentation xint.pdf (or xint.dvi). +% +% This work consists of the source file xint.dtx and of its derived +% files xint.sty, xintgcd.sty, xint.ins and the documentation xint.pdf +% (or xint.dvi). % % This work may be distributed and/or modified under the % conditions of the LaTeX Project Public License, either @@ -55,9 +58,9 @@ % \input xintgcd.sty\relax % %<*none> -\def\pkgversion{1.01} -\def\pkgdate{2013/04/04} -\def\lasttimestamp{Time-stamp: <04-04-2013 17:36:58 CEST jfb>} +\def\pkgversion{1.02} +\def\pkgdate{2013/04/05} +\def\lasttimestamp{Time-stamp: <05-04-2013 16:49:16 CEST JF>} \def\striptimestamp #1 <#2 #3 #4 #5>{#2 at #3 #4} \def\getdocdate #1 <#2-#3-#4 #5>{#4/#3/#2} \edef\docdate{\expandafter\getdocdate\lasttimestamp} @@ -73,14 +76,6 @@ \endgroup \iffalse %</none> -%% -%%---------------------------------------------------------------- -%% Part of the xint bundle (version 1.01 of 2013/04/04) -%<xint>%% xint: Expandable operations on long numbers -%<xintgcd>%% xintgcd: Euclidean algorithm with xint package -%% Copyright (C) 2013 by Jean-Francois Burnol -%%---------------------------------------------------------------- -%% %<*ins> %----------- to .ins file ---------------------------------------- %% @@ -366,40 +361,6 @@ numbers (not digits!!!) will work thousands of times faster (or more, I don't know) than what can be achieved using \TeX{} to manipulate strings of ASCII representations of digits! -% \pdfresettimer -% \edef\x{\xintPow{1325798301}{137}} -% \the\pdfelapsedtime\ -% \xintLen{\x} - -% \pdfresettimer -% \edef\x{\xintFac{1000}} -% \edef\T{\the\pdfelapsedtime}\T= -% \xintQuo\T{65536} secondes\par -% \pdfresettimer -% \edef\y{\xintSqr{\x}} -% \edef\T{\the\pdfelapsedtime}\T= -% \xintQuo\T{65536} secondes\par -% \xintLen{\x}\par -% \xintLen{\y}\par - -% Sur l'iMac c'est un peu plus rapide: -% 55570 1250 -% 573033= 8 secondes -% 3382960= 51 secondes -% 2568 -% 5136 - -% This warning being issued, \xintname computes &1325798301^{137}& -% which has 1250 digits in less than 1 second (on my 2012 acquired -% laptop). It checks a Bezout identity involving two multiplications -% of 200 digits numbers (and a subtraction) in one 12th of a second. -% It computes 1000! (which has 2568 digits) in less than 10 seconds -% and its square in less than 60 seconds: of course this will be -% dwarfed by any specialized software. Communicating such -% computation times from runs on an unspecified machine is not very -% precise, but I guess my laptop is representative of the models of -% the last two years. - \section{Expansions} Except otherwise stated all macros are completely expandable. For @@ -433,7 +394,7 @@ of typesetting this documentation and not have big numbers extend into the margin and go beyond the page physical limits, I use this little macro (not provided by the package): \begin{verbatim} -\def\allownumbersplit #1 {\ifx #1\relax \else #1\hskip 0pt plus 1pt +\def\allownumbersplit #1{\ifx #1\relax \else #1\hskip 0pt plus 1pt \expandafter\allownumbersplit\fi}% \end{verbatim} To provoke the double expansion first, it is used as in: @@ -776,6 +737,7 @@ strings not containing these control sequence names. Anything within braces is treated as one unit: one level of exterior braces is removed and the contents are not reverted. +\clearpage \section{Loading and usage} \begin{verbatim} @@ -1042,8 +1004,33 @@ argument. \centeredline{% \subsection{\chb{xintMul}} -\csa{xintMul\n\m} returns the product of the two numbers. It is -more efficient to have the first one be the longer of the two. +\csa{xintMul\n\m} returns the product of the two numbers. The order of the +numbers influences the efficiency of the computation: +\begin{enumerate} +\item if the shortest number has at most 4 digits, then it is (always) more + efficient if it comes as the second argument, +\item if both numbers have at most 50 digits, then it is generally a bit + more efficient to have the longest one be the first argument and the shortest + one be the second argument, +\item if one of the number has more than 250 digits, it is always advantageous + if the shortest number is the first argument (except if it has only 4 digits + or less!). For example, 50 digits $\times$ 1000 digits is five times faster + than 1000 digits $\times$ 50 digits, +\item if both numbers have less than 250 digits, then it is advantageous to have + the shortest one be the first argument, as long as it is not too short. The + limit depends on the size of the longer number; roughly, when the longer + number has 100 digits, this limit on the shorter one is already of 12 digits, + and the longer the long number, the lower the limit for the shorter. +\end{enumerate} +So when both numbers have at most 50 digits, put the longer one first and the +shorter one second; when both numbers have at least 50 digits, put the shorter +one first and the longer one second. The gain will be substantial if the long +number is very long. + +When one of the number has at most 4 digits, always make it second. But if the +shortest has 5 digits or more, it is advantageous to have it in first +position when the longer number has 250 digits or more. + \subsection{\chb{xintSqr}} @@ -1064,8 +1051,18 @@ and returns 1: |\xintPrd {}=|\texttt{\xintPrd {}}. A product reduced to a single term returns this number: |\xintPrd {{-1234}}=|\texttt{\xintPrd {{-1234}}}. Attention that |\xintPrd {-1234}| is not legal input and will make the \TeX{} compilation -fail. On the other hand |\xintPrd {1234}=|\texttt{\xintPrd {1234}}. - +fail. On the other hand |\xintPrd {1234}=|\texttt{\xintPrd + {1234}}. +\centeredline{&2^{200}3^{100}7^{100}&} +\centeredline{=|\xintPrd {{\xintPow {2}{200}}{\xintPow + {3}{100}}{\xintPow {7}{100}}}|} +=\expandafter\expandafter\expandafter\allownumbersplit + \xintPrd {{\xintPow {2}{200}}{\xintPow {3}{100}}{\xintPow + {7}{100}}}\relax +\centeredline{=|\xintPow {\xintMul {\xintPow {42}{9}}{43008}}{10}|} + +% \expandafter\expandafter\expandafter\allownumbersplit +% \xintPow {\xintMul {\xintPow {42}{9}}{43008}}{10}\relax \subsection{\chb{xintProductExpr}} @@ -1080,7 +1077,15 @@ argument. \csa{xintFac\n} returns the factorial. It is an error if the argument is negative or at least &10^9&. It is not recommended to launch the computation of things such as &100000!&, if you need -your computer for other tasks. +your computer for other tasks. On my laptop &1000!& (2568 digits) +is computed in a little less than ten seconds, &2000!& (5736 +digits) is computed in a little less than one hundred seconds, and +&3000!& (which has 9131 digits) needs close to seven minutes\dots +I have no idea how much time &10000!& would need (do rather +&9999!& if you can, the algorithm has some overhead at the +transition from &N=9999& to &10000& and higher; &10000!& has 35660 +digits). Not to mention &100000!& which, from the Stirling formula, +should have 456574 digits. \subsection{\chb{xintPow}} @@ -1519,7 +1524,7 @@ and modify it to what is needed. \fi \expandafter\x\csname ver@xint.sty\endcsname \ProvidesPackage{xint}% - [2013/04/04 v1.01 Expandable operations on long numbers (jfB)]% + [2013/04/05 v1.02 Expandable operations on long numbers (jfB)]% % \end{macrocode} % \subsection{Token management macros} % \begin{macrocode} @@ -3070,7 +3075,20 @@ and modify it to what is needed. % \begin{verbatim} % MULTIPLICATION % Ici #1#2 = 2e input et #3#4 = 1er input -% Algorithme plus efficace pour #3#4 plus long que #1#2 +% Quelques précisions apportées à l'occasion de 1.02 (qui modifie le +% fonctionnement de \xintPrd pour tenir compte des règles ci-dessous, et aussi +% améliore au passage très légèrement la vitesse de calcul de la factorielle): +% La multiplication est plus rapide sous les conditions suivantes: +% - si le nombre le plus court a au plus 4 chiffres, il DOIT être en 2e +% - si les deux ont au plus 50 chiffres, le plus court en *second* +% - si les deux ont au moins 50 chiffres, le plus court en *premier* +% - si le plus long a au moins 250 chiffres, mettre ce plus long +% toujours en *second* (sauf si l'autre a au plus 4 chiffres) +% - si le plus long a au moins 100 chiffres, en second si le premier a au +% moins 12 chiffres. +% La règle générale est donc à peu près: pour les 'gros calculs' mettre le +% plus court en premier (SAUF pour multiplication par un nombre < 10000), et +% pour les 'petits calculs' le plus long en premier. % \end{verbatim} % \vspace*{-1.5\baselineskip} % \begin{macrocode} @@ -3124,8 +3142,7 @@ and modify it to what is needed. % \end{macrocode} % \vspace*{-.5\baselineskip} % \begin{verbatim} -% Ici #3#1 correspond au **2e input** celui censé être -% pyschologiquement plus petit +% Ici #3#1 correspond au **2e input** % \end{verbatim} % \vspace*{-1.5\baselineskip} % \begin{macrocode} @@ -3461,6 +3478,19 @@ and modify it to what is needed. % \begin{verbatim} % \xintPrd {{a}...{z}} % \xintProductExpr {a}...{z}\relax +% Release 1.02 modifies \XINT@posprod. The new version takes into account that +% multiplication on long numbers is more efficient with the shorter one first; +% the earlier version was on the premise that it was more efficient to give +% the longer number first and used a special version of multiplication to +% produce its output in reversed order to serve as next first number. This was +% optimal for numbers of at most 50 digits, but the bad choice for long +% numbers. As \xintPrd should be fast when it is used to produce long numbers +% (producing short numbers means few factors means computation does not take +% much time anyhow), I revert this choice here. On the other hand this was the +% correct choice (and tested so) for use in the \xintPow recursion which each +% times multiplies by something even bigger than what has been obtained so +% far. So the original version is renamed and moved to serve for \xintPow. +% The factorial receives separate special revision. % \end{verbatim} % \vspace*{-1.5\baselineskip} % \begin{macrocode} @@ -3471,13 +3501,12 @@ and modify it to what is needed. \def\XINT@pprod@checkifempty #1% {% \xint@relax #1\XINT@pprod@emptyproduct\relax - \XINT@pprod@RQfirst #1% + \XINT@pprod@first #1% }% \def\XINT@pprod@emptyproduct #1\Z { 1}% -\def\XINT@pprod@RQfirst #1\Z +\def\XINT@pprod@first #1\Z {% - \expandafter\XINT@pprod@getnext\expandafter - {\romannumeral0\XINT@RQ {}#1\R\R\R\R\R\R\R\R\Z}% + \XINT@pprod@getnext {#1}% }% \def\XINT@pprod@getnext #1#2% {% @@ -3486,21 +3515,22 @@ and modify it to what is needed. \def\XINT@pprod@checkiffinished #1% {% \xint@relax #1\XINT@pprod@end\relax - \XINT@pprod@compute #1% + \XINT@pprod@RQnew #1% }% -\def\XINT@pprod@compute #1\Z #2% +\def\XINT@pprod@RQnew #1\Z {% + \expandafter\XINT@pprod@compute \expandafter - \XINT@pprod@getnext - \expandafter - {\romannumeral0\XINT@prod@mul@enter #2\W\X\Y\Z #1\W\X\Y\Z}% + {\romannumeral0\XINT@RQ {}#1\R\R\R\R\R\R\R\R\Z }% }% -\def\XINT@pprod@end\relax\XINT@pprod@compute #1\Z #2% +\def\XINT@pprod@compute #1#2% {% \expandafter - \xint@cleanupzeros@andstop - \romannumeral0\XINT@rev {#2}% + \XINT@pprod@getnext + \expandafter + {\romannumeral0\XINT@mul@enter #1\W\X\Y\Z #2\W\X\Y\Z }% }% +\def\XINT@pprod@end\relax\XINT@pprod@RQnew #1\Z #2{ #2}% \def\xintProductExpr {\romannumeral0\xintproductexpr }% \def\xintPrd {\romannumeral0\xintprd }% \def\xintprd #1% @@ -3531,13 +3561,11 @@ and modify it to what is needed. \def\XINT@prod@returnzero #1\relax { 0}% \def\XINT@prod@firstisneg #1#2\Z {% - \expandafter\XINT@prod@xpxpnext\expandafter - 0\expandafter{\romannumeral0\XINT@RQ {}#2\R\R\R\R\R\R\R\R\Z}% + \XINT@prod@xpxpnext 0{#2}% }% \def\XINT@prod@firstispos #1\Z {% - \expandafter\XINT@prod@xpxpnext\expandafter - 1\expandafter{\romannumeral0\XINT@RQ {}#1\R\R\R\R\R\R\R\R\Z }% + \XINT@prod@xpxpnext 1{#1}% }% \def\XINT@prod@xpxpnext #1#2#3% {% @@ -3553,279 +3581,61 @@ and modify it to what is needed. {% \xint@zero #1\XINT@prod@returnzero0% \xint@UDsignfork - #1\dummy \XINT@prod@neg - -\dummy \XINT@prod@pos + #1\dummy \XINT@prod@neg@RQnew + -\dummy \XINT@prod@pos@RQnew \xint@UDkrof #1% }% -\def\XINT@prod@pos #1\Z #2#3% +\def\XINT@prod@pos@RQnew #1\Z +{% + \expandafter + \XINT@prod@pos + \expandafter + {\romannumeral0\XINT@RQ {}#1\R\R\R\R\R\R\R\R\Z }% +}% +\def\XINT@prod@pos #1#2#3% {% \expandafter \XINT@prod@xpxpnext \expandafter #3% \expandafter - {\romannumeral0\XINT@prod@mul@enter #2\W\X\Y\Z #1\W\X\Y\Z }% + {\romannumeral0\XINT@mul@enter #1\W\X\Y\Z #2\W\X\Y\Z }% }% -\def\XINT@prod@neg #1#2\Z #3#4% +\def\XINT@prod@neg@RQnew #1#2\Z +{% + \expandafter + \XINT@prod@neg + \expandafter + {\romannumeral0\XINT@RQ {}#2\R\R\R\R\R\R\R\R\Z }% +}% +\def\XINT@prod@neg #1#2#3% {% \expandafter \XINT@prod@xpxpnext \expandafter - {\the\numexpr 1-#4\expandafter}% + {\the\numexpr 1-#3\expandafter}% \expandafter - {\romannumeral0\XINT@prod@mul@enter #3\W\X\Y\Z #2\W\X\Y\Z }% + {\romannumeral0\XINT@mul@enter #1\W\X\Y\Z #2\W\X\Y\Z }% }% \def\XINT@prod@end\relax\XINT@prod@checksign #1\Z #2#3% {% - \expandafter - \xint@prod@cleanupzeros - \romannumeral0\XINT@rev {#2#3}% + \xint@prod@cleanupzeros #3#2% }% \def\xint@prod@cleanupzeros #1#2#3#4#5% {% \expandafter\space\the\numexpr (2*#1-1)*#2#3#4#5\relax }% % \end{macrocode} -% \vspace*{-.5\baselineskip} -% \begin{verbatim} -% MULTIPLICATION ET ADDITION POUR LES PRODUITS -% \end{verbatim} -% \vspace*{-1.5\baselineskip} -% \begin{macrocode} -\def\XINT@prod@add@A #1#2#3#4#5#6% -{% - \xint@w - #3\xint@prod@add@az - \W\XINT@prod@add@AB #1{#3#4#5#6}{#2}% -}% -\def\xint@prod@add@az\W\XINT@prod@add@AB #1#2% -{% - \XINT@prod@add@AC@checkcarry #1% -}% -\def\XINT@prod@add@AC@checkcarry #1% -{% - \xint@zero #1\xint@prod@add@AC@nocarry 0\XINT@prod@add@C -}% -\def\xint@prod@add@AC@nocarry 0\XINT@prod@add@C -{% - \XINT@prod@add@F -}% -\def\XINT@prod@add@AB #1#2#3#4\W\X\Y\Z #5#6#7#8% -{% - \XINT@prod@add@ABE #1#2{#8#7#6#5}{#3}#4\W\X\Y\Z -}% -\def\XINT@prod@add@ABE #1#2#3#4#5#6% -{\expandafter - \XINT@prod@add@ABEA\the\numexpr #1+10#5#4#3#2+#6\relax -}% -\def\XINT@prod@add@ABEA #1#2#3#4#5#6#7% -{% - \XINT@prod@add@A #2{#7#6#5#4#3}%<-- attention on met donc \`a droite -}% -\def\XINT@prod@add@C #1#2#3#4#5% -{% - \xint@w - #5\xint@prod@add@cw - #4\xint@prod@add@cx - #3\xint@prod@add@cy - #2\xint@prod@add@cz - \W\XINT@prod@add@CD {#5#4#3#2}{#1}% -}% -\def\XINT@prod@add@CD #1% -{\expandafter - \XINT@prod@add@CC\the\numexpr 1+10#1\relax -}% -\def\XINT@prod@add@CC #1#2#3#4#5#6#7% -{% - \XINT@prod@add@AC@checkcarry #2{#7#6#5#4#3}% -}% -\def\xint@prod@add@cw - #1\xint@prod@add@cx - #2\xint@prod@add@cy - #3\xint@prod@add@cz - \W\XINT@prod@add@CD -{\expandafter - \XINT@prod@add@CDw\the\numexpr 1+10#1#2#3\relax -}% -\def\XINT@prod@add@CDw #1#2#3#4#5#6% -{% - \xint@quatrezeros #2#3#4#5\XINT@prod@add@endDw@zeros - 0000\XINT@prod@add@endDw #2#3#4#5% -}% -\def\XINT@prod@add@endDw@zeros 0000\XINT@prod@add@endDw 0000#1\X\Y\Z{ #1}% -\def\XINT@prod@add@endDw #1#2#3#4#5\X\Y\Z{ #5#4#3#2#1}% -\def\xint@prod@add@cx - #1\xint@prod@add@cy - #2\xint@prod@add@cz - \W\XINT@prod@add@CD -{\expandafter - \XINT@prod@add@CDx\the\numexpr 1+100#1#2\relax -}% -\def\XINT@prod@add@CDx #1#2#3#4#5#6% -{% - \xint@quatrezeros #2#3#4#5\XINT@prod@add@endDx@zeros - 0000\XINT@prod@add@endDx #2#3#4#5% -}% -\def\XINT@prod@add@endDx@zeros 0000\XINT@prod@add@endDx 0000#1\Y\Z{ #1}% -\def\XINT@prod@add@endDx #1#2#3#4#5\Y\Z{ #5#4#3#2#1}% -\def\xint@prod@add@cy - #1\xint@prod@add@cz - \W\XINT@prod@add@CD -{\expandafter - \XINT@prod@add@CDy\the\numexpr 1+1000#1\relax -}% -\def\XINT@prod@add@CDy #1#2#3#4#5#6% -{% - \xint@quatrezeros #2#3#4#5\XINT@prod@add@endDy@zeros - 0000\XINT@prod@add@endDy #2#3#4#5% -}% -\def\XINT@prod@add@endDy@zeros 0000\XINT@prod@add@endDy 0000#1\Z{ #1}% -\def\XINT@prod@add@endDy #1#2#3#4#5\Z{ #5#4#3#2#1}% -\def\xint@prod@add@cz\W\XINT@prod@add@CD #1#2{ #21000}% -\def\XINT@prod@add@F #1#2#3#4#5% -{% - \xint@w - #5\xint@prod@add@Gw - #4\xint@prod@add@Gx - #3\xint@prod@add@Gy - #2\xint@prod@add@Gz - \W\XINT@prod@add@G {#2#3#4#5}{#1}% -}% -\def\XINT@prod@add@G #1#2% -{% - \XINT@prod@add@F {#2#1}% -}% -\def\xint@prod@add@Gw - #1\xint@prod@add@Gx - #2\xint@prod@add@Gy - #3\xint@prod@add@Gz - \W\XINT@prod@add@G #4% -{% - \xint@quatrezeros #3#2#10\XINT@prod@add@endGw@zeros - 0000\XINT@prod@add@endGw #3#2#10% -}% -\def\XINT@prod@add@endGw@zeros 0000\XINT@prod@add@endGw 0000#1\X\Y\Z{ #1}% -\def\XINT@prod@add@endGw #1#2#3#4#5\X\Y\Z{ #5#1#2#3#4}% -\def\xint@prod@add@Gx - #1\xint@prod@add@Gy - #2\xint@prod@add@Gz - \W\XINT@prod@add@G #3% -{% - \xint@quatrezeros #2#100\XINT@prod@add@endGx@zeros - 0000\XINT@prod@add@endGx #2#100% -}% -\def\XINT@prod@add@endGx@zeros 0000\XINT@prod@add@endGx 0000#1\Y\Z{ #1}% -\def\XINT@prod@add@endGx #1#2#3#4#5\Y\Z{ #5#1#2#3#4}% -\def\xint@prod@add@Gy - #1\xint@prod@add@Gz - \W\XINT@prod@add@G #2% -{% - \xint@quatrezeros #1000\XINT@prod@add@endGy@zeros - 0000\XINT@prod@add@endGy #1000% -}% -\def\XINT@prod@add@endGy@zeros 0000\XINT@prod@add@endGy 0000#1\Z{ #1}% -\def\XINT@prod@add@endGy #1#2#3#4#5\Z{ #5#1#2#3#4}% -\def\xint@prod@add@Gz\W\XINT@prod@add@G #1#2{ #2}% -% \end{macrocode} -% \vspace*{-.5\baselineskip} +% \subsection{\ch{xintFac}} % \begin{verbatim} -%--- multiplication spéciale +% Modified a bit with 1.02, following changes to \XINT@posprod +% I am tempted, here and elsewhere, to use \ifcase\XINT@Geq {#1}{1000000000} +% rather than \ifnum\XINT@Length {#1}>9 but for the time being I leave things +% as they stand. % \end{verbatim} % \vspace*{-1.5\baselineskip} % \begin{macrocode} -\def\XINT@prod@mul@enter #1\W\X\Y\Z #2#3#4#5% -{% - \xint@w - #5\xint@prod@mul@enterw - #4\xint@prod@mul@enterx - #3\xint@prod@mul@entery - #2\xint@prod@mul@enterz - \W\XINT@prod@mul@start {#2#3#4#5}#1\W\X\Y\Z -}% -\def\xint@prod@mul@enterw - #1\xint@prod@mul@enterx - #2\xint@prod@mul@entery - #3\xint@prod@mul@enterz - \W\XINT@prod@mul@start #4#5\W\X\Y\Z \X\Y\Z -{% - \XINT@mul@Mr {#3#2#1}#5\Z\Z\Z\Z -}% -\def\xint@prod@mul@enterx - #1\xint@prod@mul@entery - #2\xint@prod@mul@enterz - \W\XINT@prod@mul@start #3#4\W\X\Y\Z \Y\Z -{% - \XINT@mul@Mr {#2#1}#4\Z\Z\Z\Z -}% -\def\xint@prod@mul@entery - #1\xint@prod@mul@enterz - \W\XINT@prod@mul@start #2#3\W\X\Y\Z \Z -{% - \XINT@mul@Mr {#1}#3\Z\Z\Z\Z -}% -\def\XINT@prod@mul@start #1#2\W\X\Y\Z -{\expandafter - \XINT@prod@mul@main \expandafter - {\romannumeral0% - \XINT@mul@Mr {#1}#2\Z\Z\Z\Z - }#2\W\X\Y\Z -}% -\def\XINT@prod@mul@main #1#2\W\X\Y\Z #3#4#5#6% -{% - \xint@w - #6\xint@prod@mul@mainw - #5\xint@prod@mul@mainx - #4\xint@prod@mul@mainy - #3\xint@prod@mul@mainz - \W\XINT@prod@mul@compute {#1}{#3#4#5#6}#2\W\X\Y\Z -}% -\def\XINT@prod@mul@compute #1#2#3\W\X\Y\Z -{\expandafter - \XINT@prod@mul@main \expandafter - {\romannumeral0\expandafter - \XINT@mul@Ar \expandafter0\expandafter{\expandafter}% - \romannumeral0\XINT@mul@Mr {#2}#3\Z\Z\Z\Z \W\X\Y\Z 0000#1\W\X\Y\Z - }#3\W\X\Y\Z -}% -\def\xint@prod@mul@mainw - #1\xint@prod@mul@mainx - #2\xint@prod@mul@mainy - #3\xint@prod@mul@mainz - \W\XINT@prod@mul@compute #4#5#6\W\X\Y\Z \X\Y\Z -{% - \expandafter - \XINT@prod@add@A \expandafter0\expandafter{\expandafter}% - \romannumeral0% - \XINT@mul@Mr {#3#2#1}#6\Z\Z\Z\Z - \W\X\Y\Z 000#4\W\X\Y\Z -}% -\def\xint@prod@mul@mainx - #1\xint@prod@mul@mainy - #2\xint@prod@mul@mainz - \W\XINT@prod@mul@compute #3#4#5\W\X\Y\Z \Y\Z -{% - \expandafter - \XINT@prod@add@A \expandafter0\expandafter{\expandafter}% - \romannumeral0% - \XINT@mul@Mr {#2#1}#5\Z\Z\Z\Z - \W\X\Y\Z 00#3\W\X\Y\Z -}% -\def\xint@prod@mul@mainy - #1\xint@prod@mul@mainz - \W\XINT@prod@mul@compute #2#3#4\W\X\Y\Z \Z -{% - \expandafter - \XINT@prod@add@A \expandafter0\expandafter{\expandafter}% - \romannumeral0% - \XINT@mul@Mr {#1}#4\Z\Z\Z\Z - \W\X\Y\Z 0#2\W\X\Y\Z -}% -\def\xint@prod@mul@mainz\W\XINT@prod@mul@compute #1#2#3\W\X\Y\Z -{ #1}% -% \end{macrocode} -% \subsection{\ch{xintFac}} -% \begin{macrocode} \def\xintFac {\romannumeral0\xintfac }% \def\xintfac #1% {% @@ -3849,19 +3659,44 @@ and modify it to what is needed. }% \def\XINT@fac@checklength #1% {% - \ifnum\xintLen {#1} > 9 - \xint@afterfi{\xintError:FactorialOfTooBigNumber - \expandafter\space\expandafter 1\xint@gobble@three }% + \ifnum \XINT@Length {#1}> 9 + \xint@afterfi{\xintError:FactorialOfTooBigNumber + \expandafter\space\expandafter 1\xint@gobble }% + \else + \xint@afterfi{\ifnum #1>9999 + \expandafter\XINT@fac@big@loop + \else + \expandafter\XINT@fac@loop + \fi }% + \fi + {#1}% +}% +\def\XINT@fac@big@loop #1{\XINT@fac@big@loop@main {10000}{#1}{}}% +\def\XINT@fac@big@loop@main #1#2#3% +{% + \ifnum #1<#2 + \expandafter + \XINT@fac@big@loop@main + \expandafter + {\the\numexpr #1+1\expandafter }% \else - \expandafter\XINT@fac@loop + \expandafter\XINT@fac@big@docomputation \fi - {1}{#1}{}% + {#2}{#3{#1}}% +}% +\def\XINT@fac@big@docomputation #1#2% +{% + \expandafter + \XINT@pprod@getnext + \expandafter + {\romannumeral0\XINT@fac@loop {9999}}#2\relax }% -\def\XINT@fac@loop #1#2#3% +\def\XINT@fac@loop #1{\XINT@fac@loop@main 1{#1}{}}% +\def\XINT@fac@loop@main #1#2#3% {% \ifnum #1<#2 \expandafter - \XINT@fac@loop + \XINT@fac@loop@main \expandafter {\the\numexpr #1+1\expandafter }% \else @@ -3871,10 +3706,39 @@ and modify it to what is needed. }% \def\XINT@fac@docomputation #1#2% {% - \XINT@posprod #2\relax + \XINT@fprod@getnext {1000}#2\relax +}% +\def\XINT@fprod@getnext #1#2% +{% + \XINT@fprod@checkiffinished #2\Z {#1}% +}% +\def\XINT@fprod@checkiffinished #1% +{% + \xint@relax #1\XINT@fprod@end\relax + \XINT@fprod@compute #1% +}% +\def\XINT@fprod@compute #1\Z #2% +{% + \expandafter + \XINT@fprod@getnext + \expandafter + {\romannumeral0\XINT@mul@Mr {#1}#2\Z\Z\Z\Z }% +}% +\def\XINT@fprod@end\relax\XINT@fprod@compute #1\Z #2% +{% + \expandafter + \xint@cleanupzeros@andstop + \romannumeral0\XINT@rev {#2}% }% % \end{macrocode} % \subsection{\ch{xintPow}} +% \begin{verbatim} +% 1.02 this is the same as in earlier versions, but I had to move here the +% special routine of Product as it was previously done, with its accompanying +% special multiplication and addition (to maintain the intermediate results in a +% special reversed form), now that I have modified the \XINT@posprod routine. +% \end{verbatim} +% \vspace*{-1.5\baselineskip} % \begin{macrocode} \def\xintPow {\romannumeral0\xintpow }% \def\xintpow #1% @@ -4000,7 +3864,7 @@ and modify it to what is needed. \else \expandafter\XINT@pow@loop \fi - {#1}{#2}\XINT@posprod + {#1}{#2}\XINT@pow@posprod \xint@UNDEF \xint@undef\xint@undef\xint@undef\xint@undef \xint@undef\xint@undef\xint@undef\xint@undef @@ -4014,10 +3878,8 @@ and modify it to what is needed. \expandafter\XINT@pow@loop@end \else \xint@afterfi{\expandafter\XINT@pow@loop@a - \expandafter{\the\numexpr 2*(#1/2)-#1\expandafter }% - % b mod 2 - \expandafter{\the\numexpr #1-#1/2\expandafter }% - % [b/2] + \expandafter{\the\numexpr 2*(#1/2)-#1\expandafter }% b mod 2 + \expandafter{\the\numexpr #1-#1/2\expandafter }% [b/2] \expandafter{\romannumeral0\xintsqr{#2}}}% \fi {{#2}}% @@ -4036,6 +3898,289 @@ and modify it to what is needed. \XINT@pow@loop {#1}{#2}% }% % \end{macrocode} +% \vspace*{-.5\baselineskip} +% \begin{verbatim} +% Routine de produit servant pour le calcul des puissances. +% \end{verbatim} +% \vspace*{-1.5\baselineskip} +% \begin{macrocode} +\def\XINT@pow@posprod #1% +{% + \XINT@pow@pprod@checkifempty #1\Z +}% +\def\XINT@pow@pprod@checkifempty #1% +{% + \xint@relax #1\XINT@pow@pprod@emptyproduct\relax + \XINT@pow@pprod@RQfirst #1% +}% +\def\XINT@pow@pprod@emptyproduct #1\Z { 1}% +\def\XINT@pow@pprod@RQfirst #1\Z +{% + \expandafter\XINT@pow@pprod@getnext\expandafter + {\romannumeral0\XINT@RQ {}#1\R\R\R\R\R\R\R\R\Z}% +}% +\def\XINT@pow@pprod@getnext #1#2% +{% + \XINT@pow@pprod@checkiffinished #2\Z {#1}% +}% +\def\XINT@pow@pprod@checkiffinished #1% +{% + \xint@relax #1\XINT@pow@pprod@end\relax + \XINT@pow@pprod@compute #1% +}% +\def\XINT@pow@pprod@compute #1\Z #2% +{% + \expandafter + \XINT@pow@pprod@getnext + \expandafter + {\romannumeral0\XINT@pow@mul@enter #2\W\X\Y\Z #1\W\X\Y\Z}% +}% +\def\XINT@pow@pprod@end\relax\XINT@pow@pprod@compute #1\Z #2% +{% + \expandafter + \xint@cleanupzeros@andstop + \romannumeral0\XINT@rev {#2}% +}% +% \end{macrocode} +% \vspace*{-.5\baselineskip} +% \begin{verbatim} +% Multiplication spéciale pour emploi par le Produit servant pour le calcul +% des Puissances (sic) +% \end{verbatim} +% \vspace*{-1.5\baselineskip} +% \begin{macrocode} +\def\XINT@pow@mul@enter #1\W\X\Y\Z #2#3#4#5% +{% + \xint@w + #5\xint@pow@mul@enterw + #4\xint@pow@mul@enterx + #3\xint@pow@mul@entery + #2\xint@pow@mul@enterz + \W\XINT@pow@mul@start {#2#3#4#5}#1\W\X\Y\Z +}% +\def\xint@pow@mul@enterw + #1\xint@pow@mul@enterx + #2\xint@pow@mul@entery + #3\xint@pow@mul@enterz + \W\XINT@pow@mul@start #4#5\W\X\Y\Z \X\Y\Z +{% + \XINT@mul@Mr {#3#2#1}#5\Z\Z\Z\Z +}% +\def\xint@pow@mul@enterx + #1\xint@pow@mul@entery + #2\xint@pow@mul@enterz + \W\XINT@pow@mul@start #3#4\W\X\Y\Z \Y\Z +{% + \XINT@mul@Mr {#2#1}#4\Z\Z\Z\Z +}% +\def\xint@pow@mul@entery + #1\xint@pow@mul@enterz + \W\XINT@pow@mul@start #2#3\W\X\Y\Z \Z +{% + \XINT@mul@Mr {#1}#3\Z\Z\Z\Z +}% +\def\XINT@pow@mul@start #1#2\W\X\Y\Z +{\expandafter + \XINT@pow@mul@main \expandafter + {\romannumeral0% + \XINT@mul@Mr {#1}#2\Z\Z\Z\Z + }#2\W\X\Y\Z +}% +\def\XINT@pow@mul@main #1#2\W\X\Y\Z #3#4#5#6% +{% + \xint@w + #6\xint@pow@mul@mainw + #5\xint@pow@mul@mainx + #4\xint@pow@mul@mainy + #3\xint@pow@mul@mainz + \W\XINT@pow@mul@compute {#1}{#3#4#5#6}#2\W\X\Y\Z +}% +\def\XINT@pow@mul@compute #1#2#3\W\X\Y\Z +{\expandafter + \XINT@pow@mul@main \expandafter + {\romannumeral0\expandafter + \XINT@mul@Ar \expandafter0\expandafter{\expandafter}% + \romannumeral0\XINT@mul@Mr {#2}#3\Z\Z\Z\Z \W\X\Y\Z 0000#1\W\X\Y\Z + }#3\W\X\Y\Z +}% +\def\xint@pow@mul@mainw + #1\xint@pow@mul@mainx + #2\xint@pow@mul@mainy + #3\xint@pow@mul@mainz + \W\XINT@pow@mul@compute #4#5#6\W\X\Y\Z \X\Y\Z +{% + \expandafter + \XINT@pow@add@A \expandafter0\expandafter{\expandafter}% + \romannumeral0% + \XINT@mul@Mr {#3#2#1}#6\Z\Z\Z\Z + \W\X\Y\Z 000#4\W\X\Y\Z +}% +\def\xint@pow@mul@mainx + #1\xint@pow@mul@mainy + #2\xint@pow@mul@mainz + \W\XINT@pow@mul@compute #3#4#5\W\X\Y\Z \Y\Z +{% + \expandafter + \XINT@pow@add@A \expandafter0\expandafter{\expandafter}% + \romannumeral0% + \XINT@mul@Mr {#2#1}#5\Z\Z\Z\Z + \W\X\Y\Z 00#3\W\X\Y\Z +}% +\def\xint@pow@mul@mainy + #1\xint@pow@mul@mainz + \W\XINT@pow@mul@compute #2#3#4\W\X\Y\Z \Z +{% + \expandafter + \XINT@pow@add@A \expandafter0\expandafter{\expandafter}% + \romannumeral0% + \XINT@mul@Mr {#1}#4\Z\Z\Z\Z + \W\X\Y\Z 0#2\W\X\Y\Z +}% +\def\xint@pow@mul@mainz\W\XINT@pow@mul@compute #1#2#3\W\X\Y\Z +{ #1}% +% \end{macrocode} +% \vspace*{-.5\baselineskip} +% \begin{verbatim} +% ADDITION spéciale pour emploi dans la routine de Multiplication utilisée +% dans la routine de Produit servant pour le calcul des puissances (sic). +% \end{verbatim} +% \vspace*{-1.5\baselineskip} +% \begin{macrocode} +\def\XINT@pow@add@A #1#2#3#4#5#6% +{% + \xint@w + #3\xint@pow@add@az + \W\XINT@pow@add@AB #1{#3#4#5#6}{#2}% +}% +\def\xint@pow@add@az\W\XINT@pow@add@AB #1#2% +{% + \XINT@pow@add@AC@checkcarry #1% +}% +\def\XINT@pow@add@AC@checkcarry #1% +{% + \xint@zero #1\xint@pow@add@AC@nocarry 0\XINT@pow@add@C +}% +\def\xint@pow@add@AC@nocarry 0\XINT@pow@add@C +{% + \XINT@pow@add@F +}% +\def\XINT@pow@add@AB #1#2#3#4\W\X\Y\Z #5#6#7#8% +{% + \XINT@pow@add@ABE #1#2{#8#7#6#5}{#3}#4\W\X\Y\Z +}% +\def\XINT@pow@add@ABE #1#2#3#4#5#6% +{\expandafter + \XINT@pow@add@ABEA\the\numexpr #1+10#5#4#3#2+#6\relax +}% +\def\XINT@pow@add@ABEA #1#2#3#4#5#6#7% +{% + \XINT@pow@add@A #2{#7#6#5#4#3}%<-- attention on met donc \`a droite +}% +\def\XINT@pow@add@C #1#2#3#4#5% +{% + \xint@w + #5\xint@pow@add@cw + #4\xint@pow@add@cx + #3\xint@pow@add@cy + #2\xint@pow@add@cz + \W\XINT@pow@add@CD {#5#4#3#2}{#1}% +}% +\def\XINT@pow@add@CD #1% +{\expandafter + \XINT@pow@add@CC\the\numexpr 1+10#1\relax +}% +\def\XINT@pow@add@CC #1#2#3#4#5#6#7% +{% + \XINT@pow@add@AC@checkcarry #2{#7#6#5#4#3}% +}% +\def\xint@pow@add@cw + #1\xint@pow@add@cx + #2\xint@pow@add@cy + #3\xint@pow@add@cz + \W\XINT@pow@add@CD +{\expandafter + \XINT@pow@add@CDw\the\numexpr 1+10#1#2#3\relax +}% +\def\XINT@pow@add@CDw #1#2#3#4#5#6% +{% + \xint@quatrezeros #2#3#4#5\XINT@pow@add@endDw@zeros + 0000\XINT@pow@add@endDw #2#3#4#5% +}% +\def\XINT@pow@add@endDw@zeros 0000\XINT@pow@add@endDw 0000#1\X\Y\Z{ #1}% +\def\XINT@pow@add@endDw #1#2#3#4#5\X\Y\Z{ #5#4#3#2#1}% +\def\xint@pow@add@cx + #1\xint@pow@add@cy + #2\xint@pow@add@cz + \W\XINT@pow@add@CD +{\expandafter + \XINT@pow@add@CDx\the\numexpr 1+100#1#2\relax +}% +\def\XINT@pow@add@CDx #1#2#3#4#5#6% +{% + \xint@quatrezeros #2#3#4#5\XINT@pow@add@endDx@zeros + 0000\XINT@pow@add@endDx #2#3#4#5% +}% +\def\XINT@pow@add@endDx@zeros 0000\XINT@pow@add@endDx 0000#1\Y\Z{ #1}% +\def\XINT@pow@add@endDx #1#2#3#4#5\Y\Z{ #5#4#3#2#1}% +\def\xint@pow@add@cy + #1\xint@pow@add@cz + \W\XINT@pow@add@CD +{\expandafter + \XINT@pow@add@CDy\the\numexpr 1+1000#1\relax +}% +\def\XINT@pow@add@CDy #1#2#3#4#5#6% +{% + \xint@quatrezeros #2#3#4#5\XINT@pow@add@endDy@zeros + 0000\XINT@pow@add@endDy #2#3#4#5% +}% +\def\XINT@pow@add@endDy@zeros 0000\XINT@pow@add@endDy 0000#1\Z{ #1}% +\def\XINT@pow@add@endDy #1#2#3#4#5\Z{ #5#4#3#2#1}% +\def\xint@pow@add@cz\W\XINT@pow@add@CD #1#2{ #21000}% +\def\XINT@pow@add@F #1#2#3#4#5% +{% + \xint@w + #5\xint@pow@add@Gw + #4\xint@pow@add@Gx + #3\xint@pow@add@Gy + #2\xint@pow@add@Gz + \W\XINT@pow@add@G {#2#3#4#5}{#1}% +}% +\def\XINT@pow@add@G #1#2% +{% + \XINT@pow@add@F {#2#1}% +}% +\def\xint@pow@add@Gw + #1\xint@pow@add@Gx + #2\xint@pow@add@Gy + #3\xint@pow@add@Gz + \W\XINT@pow@add@G #4% +{% + \xint@quatrezeros #3#2#10\XINT@pow@add@endGw@zeros + 0000\XINT@pow@add@endGw #3#2#10% +}% +\def\XINT@pow@add@endGw@zeros 0000\XINT@pow@add@endGw 0000#1\X\Y\Z{ #1}% +\def\XINT@pow@add@endGw #1#2#3#4#5\X\Y\Z{ #5#1#2#3#4}% +\def\xint@pow@add@Gx + #1\xint@pow@add@Gy + #2\xint@pow@add@Gz + \W\XINT@pow@add@G #3% +{% + \xint@quatrezeros #2#100\XINT@pow@add@endGx@zeros + 0000\XINT@pow@add@endGx #2#100% +}% +\def\XINT@pow@add@endGx@zeros 0000\XINT@pow@add@endGx 0000#1\Y\Z{ #1}% +\def\XINT@pow@add@endGx #1#2#3#4#5\Y\Z{ #5#1#2#3#4}% +\def\xint@pow@add@Gy + #1\xint@pow@add@Gz + \W\XINT@pow@add@G #2% +{% + \xint@quatrezeros #1000\XINT@pow@add@endGy@zeros + 0000\XINT@pow@add@endGy #1000% +}% +\def\XINT@pow@add@endGy@zeros 0000\XINT@pow@add@endGy 0000#1\Z{ #1}% +\def\XINT@pow@add@endGy #1#2#3#4#5\Z{ #5#1#2#3#4}% +\def\xint@pow@add@Gz\W\XINT@pow@add@G #1#2{ #2}% +% \end{macrocode} % \subsection{\ch{xintDivision}, \ch{xintQuo}, \ch{xintRem}} % \begin{macrocode} \def\xintQuo {\romannumeral0\xintquo }% @@ -4583,7 +4728,7 @@ and modify it to what is needed. \expandafter \XINT@div@body@h \romannumeral0\XINT@div@sub@xpxp - {\romannumeral0\XINT@prod@mul@enter #3\W\X\Y\Z #1\W\X\Y\Z }% + {\romannumeral0\XINT@pow@mul@enter #3\W\X\Y\Z #1\W\X\Y\Z }% {#2}\Z {#3}{#1}% }% @@ -4628,7 +4773,7 @@ and modify it to what is needed. \expandafter \XINT@div@body@l \expandafter{\romannumeral0\XINT@div@sub@xpxp - {\romannumeral0\XINT@prod@mul@enter #3\W\X\Y\Z #1\W\X\Y\Z }% + {\romannumeral0\XINT@pow@mul@enter #3\W\X\Y\Z #1\W\X\Y\Z }% {\XINT@Rev{#2}}}% {#4+#1}% }% @@ -5632,7 +5777,7 @@ and modify it to what is needed. \fi \expandafter\x\csname ver@xintgcd.sty\endcsname \ProvidesPackage{xintgcd}% - [2013/04/04 v1.01 Euclide algorithm with xint package (jfB)]% + [2013/04/05 v1.02 Euclide algorithm with xint package (jfB)]% % \end{macrocode} % \subsection{\ch{xintGCD}} % \begin{macrocode} @@ -6340,7 +6485,7 @@ and modify it to what is needed. Grave accent \` Left brace \{ Vertical bar \| Right brace \} Tilde \~} -\CheckSum{6420} +\CheckSum{6549} \Finale %% |