summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2016-01-03 22:15:29 +0000
committerKarl Berry <karl@freefriends.org>2016-01-03 22:15:29 +0000
commit339b409afa91db4c85735e3320e9a7b0b362f052 (patch)
treee8fc129d431f3326b8cac4bf895f594f2e37be08
parentbdb7a6514bc9dd631b9c574425f7b376b3e3f9c9 (diff)
apnum (3jan16)
git-svn-id: svn://tug.org/texlive/trunk@39265 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/generic/apnum/README12
-rw-r--r--Master/texmf-dist/doc/generic/apnum/apnum.d289
-rw-r--r--Master/texmf-dist/doc/generic/apnum/apnum.pdfbin643161 -> 701961 bytes
-rw-r--r--Master/texmf-dist/tex/generic/apnum/apnum.tex89
4 files changed, 356 insertions, 34 deletions
diff --git a/Master/texmf-dist/doc/generic/apnum/README b/Master/texmf-dist/doc/generic/apnum/README
index ac417f8a284..155b8e5d8f8 100644
--- a/Master/texmf-dist/doc/generic/apnum/README
+++ b/Master/texmf-dist/doc/generic/apnum/README
@@ -18,8 +18,10 @@ Files: README ... this file
License: Public domain.
-Versions: 1.0 <Nov 2014> - released
- 1.1 <Jan 2015> - corrections
- 1.2 <May 2015> - .5+.5=.1 bug fixed
- 1.3 <Dec 2015> - many improvements, \SQRT, \LN, \EXP implemented
- 1.4 <Dec 2015> - \SIN, \COS, \TAN, \ASIN, \ACOS, \ATAN, \PI, \PIhalf added
+Versions:
+1.0 <Nov 2014> - released
+1.1 <Jan 2015> - corrections
+1.2 <May 2015> - .5+.5=.1 bug fixed
+1.3 <Dec 2015> - many improvements, \SQRT, \LN, \EXP implemented
+1.4 <Dec 2015> - \SIN, \COS, \TAN, \ASIN, \ACOS, \ATAN, \PI, \PIhalf added
+1.5 <Jan 2016> - \eprint for printing evaluated expressions added.
diff --git a/Master/texmf-dist/doc/generic/apnum/apnum.d b/Master/texmf-dist/doc/generic/apnum/apnum.d
index b612c363325..f22485e578b 100644
--- a/Master/texmf-dist/doc/generic/apnum/apnum.d
+++ b/Master/texmf-dist/doc/generic/apnum/apnum.d
@@ -10,7 +10,7 @@
\input utf8off \clearmubyte % use pdfcsplain
-\def\projectversion{1.4a Dec 2015}
+\def\projectversion{1.5 Jan 2016}
\def\headtitle{Arbitrary Precision Numbers}
\widowpenalty=10000
@@ -47,6 +47,7 @@
\medskip}
\def\nn#1 {\noactive{\nb#1}}
\def\inumref[#1]{\ilink[#1]{\numref[#1]}}
+\def\M{M\sb{\rm op}}
\def\cnvbookmark#1{\lowercase{\lowercase{#1}}}
{\obeyspaces\global\let =\ }
@@ -124,7 +125,7 @@ after decimal point are not calculated when this limit is reached.
The special value "\apTOT=0" means that the calculation is limited
only by "\apFRAC". Default values are "\apTOT=0" and "\apFRAC=20".
-The operator "^" means the powering, i.e "2^8" is "256". The exponent have
+The operator "^" means the powering, i.~e.\ "2^8" is "256". The exponent have
to be an integer (no decimal point is allowed) and a relatively small
integer is assumed.
@@ -155,8 +156,8 @@ allowed to use them as an operand in the "<expression>":
\item * \du{SGN}"\SGN {<value>}" returns sign of the "<value>",
\item * \du{iDIV}"\iDIV {<dividend>}{<divisor>}" for integer division,
\item * \du{iMOD}"\iMOD {<dividend>}{<divisor>}" for integer remainder,
-\item * \du{iROUND}"\iROUND {<value>}" for rounding the number to the integer,
-\item * \du{iFRAC}"\iFRAC {<value>}" for fraction part of the "\iROUND",
+\item * \du{iFLOOR}"\iFLOOR {<value>}" for rounding the number to the integer,
+\item * \du{iFRAC}"\iFRAC {<value>}" for fraction part of the "\iFLOOR",
\item * \du{FAC}"\FAC {<integer value>}" for factorial,
\item * \du{BINOM}"\BINOM {<integer above>}{<integer below>}" for binomial coefficient,
\item * \du{SQRT}"\SQRT {<value>}" for square root of the "<value>",
@@ -241,7 +242,7 @@ to operate with the numbers written in the notation:
<sign><digits>.<digits>E<sign><digits>
\endtt
%
-For example "1.234E9" means $1.234\cdot 10^9$, i.e.\ "1234000000" or
+For example "1.234E9" means $1.234\cdot 10^9$, i.~e.\ "1234000000" or
the text "1.234E-3" means ".001234". The decimal exponent (after the "E"
letter) have to be in the range $\pm\,2\,147\,483\,647$ because
we store this value in normal \TeX{} register.
@@ -279,7 +280,7 @@ There are another usable macros for operations with scientific numbers.
\begitems
\item * \du{apROLL}"\apROLL <sequence>{<shift>}" \dots the "<sequence>" is assumed to
be a macro with the number. The decimal point of this number is
- shifted right by "<shift>" parameter, i.e.\ the result is multiplied by
+ shifted right by "<shift>" parameter, i.~e.\ the result is multiplied by
"10^<shift>". The "<sequence>" is redefined by this result.
For example the "\apEnum\A" does "\apROLL\A{\apE}".
\item * \du{apNORM}"\apNORM <sequence>{<num>}"
@@ -477,6 +478,86 @@ Note that user cannot write "\usedimen\hsize{cm}" without braces because
this isn't the syntactically correct operand (see section~\inumref[eval]) and the
"<expression>" scanner is unable to read it.
+\subsec Printing expressions
+
+\TeX{} was designed for printing. The "apnum.tex" provides common syntax of
+"<expressions>" (given in section \inumref[eval]) which can be used for
+both: for {\it evaluating\/} or for {\it printing}. Printing can be done
+using \du{eprint}"\eprint{<expression>}{<declaration>}" macro. The
+"<declaration>" part declares locally what to do with ``variables'' or with
+your ``function-like'' macros. You can insert your local "\def"'s or
+"\let"'s here because the "<declaration>" is executed in the group before
+the "<expression>" is printed. The "\eprint" macro must be used in math mode
+only. Example:
+
+\begtt
+\def\printresult#1{$$\displaylines{
+ \eprint{#1}\vars = \cr = \eprint{#1}\nums = \cr
+ = \apFRAC=8 \evaldef\OUT{#1}\OUT, \cr
+ \nums x = \X, \quad y = \Y.
+}$$}
+
+\def\X{-.25} \def\Y{18.11}
+\def\vars{\def\X{x}\def\Y{y}\let\apMULop=\relax}
+\def\nums{\corrnum\X \corrnum\Y}
+\printresult
+{-(\X-\SQRT{\Y^2+1}) + -((\X*\Y+1)/2) + \SIN{\X+\PIhalf} + 2*\COS{\Y}}
+\endtt
+generates the result:
+$$
+ \displaylines{
+ - \left(x-\sqrt{y^2+1}\right) + - {xy+1\over 2}
+ + \sin\left( x+{\pi\over2}\right) + 2 \cos y = \cr
+ = - \left(-0.25-\sqrt{18.11^2+1}\right) + - {-0.25\cdot18.11+1\over 2}
+ + \sin\left( -0.25+{\pi\over2}\right) + 2\cdot \cos 18.11 = \cr
+ = 22.5977863, \cr
+ x = -0.25, \quad y = 18.11
+}
+$$
+This example prints the given "<expression>" in two forms: with
+``variables as variables'' first and with ``variables as constants'' second.
+The "<declaration>" is prepared in the "\vars" macro for the first
+form and in the "\nums" macro for the second.
+
+Note that "\eprint" macro re-calculates the occurrences of round brackets but
+keeps the meaning of the "<expression>".
+For example "(\A+\B)/\C" is printed as "{a+b\over c}" (without brackets) and
+"6*-(\A+\B)" is printed as "6\cdot(-(a+b))" (new brackets pair is added).
+Or "\SIN{\X}" is printed as "\sin x" (without brackets) but "\SIN{\X+1}"
+is printed as "\sin(x+1)" (with brackets). And "\SIN{X}^2" is printed as
+"\sin^2 x".
+
+You can do \du{apMULop}"\let\apMULop=\," or "\let\apMULop=\relax" in the
+"<declaration>" part if you need not to print any operator for multiplying.
+The default setting is "\let\apMULop=\cdot". Another possibility is to set
+"\let\apMULop=\times".
+
+The macro \du{corrnum}"\corrnum<token>" corrects the number saved in
+the "<token>" macro if it is in the form
+"[<minus>].<digits>" (i.~e.\ without digits before decimal point).
+Then zero is added before decimal point. Else nothing is changed.
+
+Warning. The first parameter of "\eprint" (i.~e.\ the "<expression>"), must
+be directly expression without any expansion steps. For example, you cannot
+define "\def\foo{<expression>}" and do "\eprint{\foo}{}" but you can do
+"\expandafter\eprint\expandafter{\foo}{}".
+
+The macro "\eprint" has its own intelligence about putting brackets. If you
+need to put or remove brackets somewhere where the intelligence of "\eprint"
+is different from your opinion, you can create your function-like macros
+"\BK{<expression>}" and "\noBK{<expression>}". They evaluate the
+"<expression>" when using "\evaldef".
+The "\BK" prints the "<expression>" with brackets and
+"\noBK" prints it without brackets when using "\eprint".
+
+\begtt
+\def\BK#1{\relax \evaldef\OUT{#1}}
+\let\noBK=\BK
+\def\BKprint#1{\left(\eprint{#1}{}\right)}
+\def\noBKprint#1{\eprint{#1}{}}
+\def\setBK{\let\BK=\BKprint \let\noBK=\noBKprint}
+Now $\eprint{3+\BK{\SIN{1}}^2}{\setBK}$ prints $3+(\sin 1)^2$.
+\endtt
\subsec [tests] Experiments
@@ -667,7 +748,7 @@ If there is a problem (level of brackets less than zero, level of brackets not
equal to zero at the end of the expression, unknown operator) we print an
error using "\apEVALerror" macro.
-The "\apNext" is set to "\apEVALb", i.e.\ scanner returns back to the state of
+The "\apNext" is set to "\apEVALb", i.~e.\ scanner returns back to the state of
reading the operand. But exceptions exist: if the ")" is found then
priority is decreased and the macro "\apEVALo" is executed again.
If the end of the "<expression>" is found then the loop is ended by
@@ -811,7 +892,7 @@ sign, then "\apnumG=-1". Else
"\apnumG=1". Finally the "<macro><expanded sequence>.@<sequence>"
is executed (but without the minus sign in the input stream).
If "#2" is zero then \db apPPu "<macro><rest>.@<sequence>" is executed. If
-the "<rest>" is empty, (i.e.\ the parameter is simply zero) then "<macro>"
+the "<rest>" is empty, (i.~e.\ the parameter is simply zero) then "<macro>"
isn't executed because there in nothing to do with zero number as a parameter of
"\apROLL", "\apROUND" or "\apNORM" macros.
@@ -829,7 +910,7 @@ base was chosen $10^4$ because the multiplication of such numbers gives
results less than $10^8$ and the maximal number in the \TeX{} register
is about $2\cdot10^9$. We'll use the word ``Digit'' (with capitalized D) in
this documentation if this means the digit in the numeral system with base
-10000, i.e.\ one Digit is four digits.
+10000, i.~e.\ one Digit is four digits.
Note that for addition we can use the numeral system with the base $10^8$
but we don't do it, because the auxiliary macros "\apIV*" for numeral system of the
base $10^4$ are already prepared.
@@ -934,7 +1015,7 @@ The macro \db apPLUSa does the following work:
prepared. Else the "\apPLUSp" for transmissions is prepared as the "\apNext" macro
(line~\cite[plus:next])
\item * The result of the first pass is expanded in the input stream and the
- "\apNext" (i.e.\ transmissions calculation) is activated at line~\cite[plus:X].
+ "\apNext" (i.~e.\ transmissions calculation) is activated at line~\cite[plus:X].
\item * if the result is in the form ".000123", then the decimal point and
the trailing zeros have to be inserted. Else the trailing zeros from the
left side of the result have to be removed by "\apPLUSy". This macro adds
@@ -972,7 +1053,7 @@ then "\apnumZ" will be set to this Digit in the "\apPLUSc" macro.
The macro \db apPLUSc is called repeatedly. It reads one Digit from input
stream and saves it to the "\apnumY". Then it calls the \db apPLUSe, which
-reads (if it is allowed, i.e.\ if "\apnumC"{\tt\char`<}"=0") one digit from
+reads (if it is allowed, i.~e.\ if "\apnumC"{\tt\char`<}"=0") one digit from
second operand "\tmpd" by the "\apIVread" macro.
Then it does the addition of these digits and saves the result
into the "\OUT" macro in reverse order.
@@ -1262,7 +1343,7 @@ There are several complications in the algorithm described above.
The macro \db apMULg "<special data format>@" removes the first dot
(it is the "#1" parameter) and prepares the "\OUT" to writing the result in
-reverse order, i.e. in human readable form. The next work is done by
+reverse order, i.~e. in human readable form. The next work is done by
"\apMULh" and "\apMULi" macros. The \db apMULh repeatedly reads the first part of the
special data format (Digits of the result are here) until the first "*"
is found. The output is stored by
@@ -1612,8 +1693,8 @@ calculation. The data "\apnumO", "\apnumL" and "\apOUTl" for this purpose
are initialized.
The "\apDIVq" is started and the tokens "0\apnumZ" are appended to the input
-stream (i.e to the expanded "\XOUT". This zero will be ignored and the
-"\apnumZ" will be used as a new $N_n$, i.e. the Digit from the ``rest of the
+stream (i.~e.\ to the expanded "\XOUT". This zero will be ignored and the
+"\apnumZ" will be used as a new $N_n$, i.~e.\ the Digit from the ``rest of the
dividend''.
\inext{apDIVp}{^^B\cbrace}{++}
@@ -1636,7 +1717,7 @@ the "\apDIVr" is invoked.
\inext{apDIVq}{^^B\cbrace}{++}
The \db apDIVr macro does the final work after the calculation of new
-remainder is done. It tests if the remainder is OK, i.e.\ the transmission
+remainder is done. It tests if the remainder is OK, i.~e.\ the transmission
from the $R_1$ calculation is equal to $R_0$. If it is true then new Digit
"\apnumA" is added to the "\OUT" macro else the "\apnumA" is decreased (the
correction) and the calculation of the remainder is run again.
@@ -1929,12 +2010,12 @@ decimal point of the number will be stored) is initialized to empty and the
from input stream repeatedly until the number of read tokens is equal to
"\apnumD" or the stop mark "@" is reached. All tokens are saved to "\tmpd".
Then the \db apROUNDd macro reads the rest of the "<param>", saves it to the
-"\XOUT" macro and defines "<sequence>" (i.e.\ "#2") as the rounded number.
+"\XOUT" macro and defines "<sequence>" (i.~e.\ "#2") as the rounded number.
\inext{apROUNDa}{\count=3 ^^B\cbrace}{++}
The macro \db apROUNDe solves the ``less standard'' problem when rounding to
-the negative digits after decimal point "\apnumD", i.e.\ we need to set
+the negative digits after decimal point "\apnumD", i.~e.\ we need to set
"-\apnumD" digits before decimal point to zero. The solution is to remove
the rest of the input stream, use "\apROLLa" to shift the decimal point left
by "-\apnumD" positions, use "\apROUNDa" to remove all digits after decimal
@@ -2012,7 +2093,7 @@ It internally expands "<sequence>", adds the "\apNL" marks and runs
The usage of the \db apNL as a stop-marks has the advantage: they act as
simply zero digits in the comparison but we can ask by "\ifx" if this
stop mark is reached. The "#5" parameter of "\apIVreadA" is separated by
-first occurrence of "\apNL", i.e.\ the rest of the macro "<sequence>" is
+first occurrence of "\apNL", i.~e.\ the rest of the macro "<sequence>" is
here.
\inext{apNL}{def\nb apIVreadA}{++}
@@ -2183,7 +2264,7 @@ allows the construction "\if...\else...\repeat".
\subsec [fce] Function-like Macros
The implementation of function-like macros \db ABS , \db SGN , \db iDIV ,
-\db iMOD , \db iROUND , \db iFRAC are simple.
+\db iMOD , \db iFLOOR , \db iFRAC are simple.
\inext{ABS}{\empty}{+-}
@@ -2236,7 +2317,7 @@ $$
If $|x_{n+1}-x_n|$ is sufficiently small we stop the processing. In
practice, we stop the processing, if the "\OUT" representation of $x_{n+1}$
rounded to the "\apFRAC" is the same as the previous representation of
-$x_n$, i.e "\ifx\Xn\OUT" in \TeX{} language. Amazingly, we need only about
+$x_n$, i.~e.\ "\ifx\Xn\OUT" in \TeX{} language. Amazingly, we need only about
four iterations for 20-digits precision and about seven iterations for 50-digits
precision, if the initial guess is good chosen.
@@ -2488,8 +2569,8 @@ The macro "\apSINCOSa" does the following steps:
The meaning of "\apSINCOSx" ("\apSINx" or "\apCOSx") is flipped in such case.
\item * If the $x'$ is zero then the result is set by "\apSINCOSo\apSINx"
and the rest of calculating is skipped.
-\item * Now $"\X"\in(0,\pi/4)$, i. e. $|"\X"|<1$ and we can use Taylor
- series. The "\apSINCOSx" (i.e. "\apSINx" or "\apCOSx") macro initializes
+\item * Now $"\X"\in(0,\pi/4)$, i.~e.\ $|"\X"|<1$ and we can use Taylor
+ series. The "\apSINCOSx" (i.~e.\ "\apSINx" or "\apCOSx") macro initializes
the computation of Taylor series mentioned above.
The $"\XX"="\X"^2$ is prepared. The Taylor series is processed in the loop
as usually.
@@ -2554,6 +2635,170 @@ $$
\inext{ASIN}{ACOS}{++}
+\subsec Printing expressions
+
+The \db eprint "{<expression>}{<declaration>}" macro
+works in the group "\bgroup...\egroup". This means that the result in math
+mode is math-Ord atom. The macro interprets the "<expression>"
+in the first step like "\evaldef". This is done by "\apEVALb#1\limits".
+The result is stored in the "\tmpb" macro in Polish notation.
+Then the internal initialization is processed in "\apEPi" and user-space
+initialization is added in "#2". Then "\tmpb" is processed. The \db apEPe can
+do something end-game play but typically it is "\relax".
+
+\inext{eprint}{^^B\cbrace}{++}
+
+The \db apEPi macro replaces the meaning of all macros typically used in
+Polish notation of the expression. The original meaning is ``to evaluate'',
+the new meaning is ``to print''. The macro "\apEPi" is set to "\relax" in the
+working group because nested "<expressions>" processed by nested "\eprint"s
+need not to be initialized again.
+
+There is second initialization macro \db apEPj (similar to the "\apEPi")
+which is empty by default.
+Users can define their own function-like functions and they can put the
+printing initialization of such macros here.
+
+\inext{apEPi}{def\nb apEPj}{++}
+
+All parameters are processed in new group. For example we have
+"\apPLUS{a}{\apDIV{b}{c}}" in the "\tmpb". Then the
+"{a}+{\apDIV{b}{c}}" is processed and thus "{a}+{{b}\over{c}}" is printed.
+The outer group is set by "\eprint" macro itself. So, the ``printing''
+meaning of "\apPLUS" prepared in \db apEPplus looks like:
+
+\inext{apEPplus}{}{++}
+
+When we process the "\tmpb" with the output of the "<expression>"
+interpreter then the original positions of the round brackets are lost. We
+must to print these brackets if it is required by usual math syntax. For
+example "\apMINUS{a}{\apPLUS{b}{c}}" must be printed as "a-(b+c)".
+But "\apMINUS{a}{\apMUL{b}{c}}" must be printed as "a-bc".
+
+The "\apEPp<parameter>\empty\end<a><b><c><d><e>" is used for this feature.
+The result of "\apEPp" is the "<parameter>" enclosed or not enclosed in
+round brackets. It depends on the main operator $\M$ in the "<parameter>" and
+on the given parameters "<a><b><c><d><e>". If $\M$ is "\apPLUS" and "<a>" isn't
+dot or $\M$ is "\apMINUS" and "<b>" isn't dot or $\M$ is (unary minus or
+"\apMUL") and "<c>" isn't dot or $\M$ is "\apDIV" and "<d>" isn't dot or $\M$
+is "\apPOWx" and "<e>" isn't dot then the "<parameter>" is enclosed in brackets
+using "\left(<parameter>\right)".
+Else the "<parameter>" is enclosed in invisible group-braces only. If $\M$ is
+nothing mentioned above (because single operand is here) then no brackets
+and no invisible braces are used and the "<parameter>" is printed ``as is''.
+This feature is used in the printing version of "\apMINUS", i.~e.\ in
+\db apEPminus macro (and in many others macros).
+The second parameter of "\apMINUS" is enclosed in brackets only if its main
+operator $\M$ is "+" or "-".
+
+\inext{apEPminus}{}{++}
+
+The unary minus in the cases like "-(a+b)" are transformed
+to "\apMUL{-1}{\apPLUS{a}{b}}"
+by the "<expression>" interpreter. But we don't need
+to print "-1\cdot(a+b)". So, the printing version of "\apMUL" stored in the
+macro \db apEPmul have an exception. First, we do the test, if "#1" is equal
+to "-1". If this is true, then we print the unary minus else we print the
+whole first parameter enclosed in braces if its $\M$ is "+" or "-".
+The second parameter is enclosed in braces if its $\M$ is "+" or "-" or "*".
+This needs more explanation: The multiplying chains as "a*b*c" are processed
+from left to right in the "<expression>" scanner and the result is
+"\apMUL{\apMUL{a}{b}}{c}". So, no brackets are printed. But the "a*-(b+c)"
+is converted to "\apMUL{a}{\apMUL{-1}{\apPLUS{b}{c}}}" and we need to print
+this as "a\cdot(-(b+c))". This is the reason why the second parameter of
+"\apMUL" will be in brackets when its $\M$ is "*".
+
+\inext{apEPmul}{!!!}{++}
+
+The \db apEPdiv macro used for printing "\apDIV" is very easy. We needn't to set
+the outer group here because each parameter is enclosed in the group. We
+need not to add any round brackets here because fraction generated by
+"\over" is self explanatory from priority point of view.
+If you need to redefine "\apEPdiv" with the operator "/" instead "\over"
+then you need to redefine "\apEPmul" too because you must enclose parameters with
+$\M="\apDIV"$ by brackets in such case.
+
+\inext{apEPdiv}{}{++}
+
+The \db apEPpow macro used for printing "^" includes another speciality.
+When the base (the first "<parameter>") is a function-like macro "\SIN", "\COS"
+etc. then we need to print "\SIN{X}^2" as "\sin^2 x".
+The test if the base is such special functions-like macro is
+performed by "\apEPpowa{<base>}\end{<exponent>}". If this is true then
+"\apEPpowa" saves the "<exponent>" to the temporary macro \db apEPy
+and only "<base>" is processed (the "\apEPy" is printed inside this
+processing) else "\apEPy" is empty and the "<base>" enclosed
+in brackets is followed by "^{<exponent>}". Note that the "<base>" isn't
+enclosed by brackets if its $\M$ is missing, i.~e.\ the "<base>" is single
+operand.
+
+\inext{apEPpow}{^^B\cbrace}{++}
+
+The \db apEPpowa macro detects the special function-like macro "\SIN", "\COS"
+etc. by performing one expansion step on the tested "<base>". If the first
+"<token>" is "\apEPf" then the special function-like macro is detected.
+Note that "\SIN", "\COS" etc. are defined as "\apEPf" in the "\apEPi" macro.
+
+\inext{}{\count=2 let\nb apEPy}{++}
+
+The functions like "\SIN{<expression>}" are printed by
+\db apEPf "{<name>}{<expression>}". First, the "\mathop{<name>}\nolimits" is
+printed. If "\apEPy" is non-empty then the exponent is printed by
+"^{\apEPy}". Finally, the nested "<expression>" is printed by the nested
+"\eprint".
+
+\inext{apEPf}{^^B\cbrace}{++}
+
+The code "\expandafter"\db apEPb in the "<declaration>" part of "\eprint"
+expands the following "\tmpb" (the result of the "<expression>" scanner) and
+checks the first token. By default the "<expression>" will be enclosed by
+brackets (see the default "\next" definition where closing brace is printed
+by "\apEPe" macro used after expanded "\tmpb"). But if the first token is
+"\apPPn" or "\apDIV" then no brackets are printed around the "<expression>".
+Note that the "<expression>" scanner generates "\apPPn{<operand>}" if and
+only if the whole "<expression>" is a single operand.
+
+\inext{apEPb}{^^B\cbrace}{++}
+
+The meaning of \db apEPp "<parameter>\empty\end<a><b><c><d><e>" is
+explained above, see the text where "\apEPminus" is introduced.
+Now, we focus to the implementation of this feature. The auxiliary macro
+\db apEPa "<first token>{<normal>}{<bracket>}<a><b><c><d><e>" is used twice:
+before processing the "<parameter>" "#1#2" and after processing. The "\apEPa"
+inserts the "<normal>" or "<bracket>" depending on the condition described
+above where $\M$ is equal to the "<first token>". Note the trick with
+"\empty" which is inserted at the end of "#2" parameter. The "<parameter>"
+should be in the form "\SIN{...}". If the "\empty" token isn't added then
+"#2" becomes the text without braces and this is not desired.
+
+\inext{apEPp}{^^B\cbrace}{++}
+
+The \db apMULop is used as an operation mark for multiplying.
+It is "\cdot" by default but user can change this.
+
+\inext{apMULop}{}{++}
+
+The single operand like "2.18" or "\X" or "\FAC{10}" is processed directly
+without any additional material. User can define ``variables'' as desired.
+The function-like macros provided by "apnum.tex" is initialized in "\apEPi"
+macro and the ``printing macros'' \db apEPabs, \db apEPfac, \db apEPbinom,
+\db apEPsqrt, \db apEPexp, \db apEPsgn, \db apEPdivmod, \db apEPidiv, \db
+apEPimod, \db apEPifloor, \db apEPifrac are defined here. The trick with
+"\expandafter\apEPb" in the declaration part of the nested "\eprint" was
+explained above. Users can re-define these macros if they want.
+
+\inext{apEPabs}{apEPifrac}{++}
+
+The \db corrnum "<token>" macro expects "<token>" as a macro with number.
+It adds zero before decimal point if the sequence of "<digits>" before
+decimal point is empty. It uses a macro \db apEPc which works at expansion
+level. First, the occurrence of the "-" is tested. If it is true then "-" is
+expanded and the "\apEPc" is called again. Else the zero is added if the
+first token is dot (this means if the "<digits>" before dot is empty).
+
+\inext{corrnum}{\empty}{+-}
+
+
\subsec Conclusion
This code is here only for backward compatibility with old versions of
diff --git a/Master/texmf-dist/doc/generic/apnum/apnum.pdf b/Master/texmf-dist/doc/generic/apnum/apnum.pdf
index 7be86bf0c01..c40bf2c2d0e 100644
--- a/Master/texmf-dist/doc/generic/apnum/apnum.pdf
+++ b/Master/texmf-dist/doc/generic/apnum/apnum.pdf
Binary files differ
diff --git a/Master/texmf-dist/tex/generic/apnum/apnum.tex b/Master/texmf-dist/tex/generic/apnum/apnum.tex
index 919c95fa0c9..e3a7bb53161 100644
--- a/Master/texmf-dist/tex/generic/apnum/apnum.tex
+++ b/Master/texmf-dist/tex/generic/apnum/apnum.tex
@@ -4,7 +4,7 @@
% See the documentation apnum.pdf or apnum.d for more information
-\def\apVERSION{1.4a <Dec 2015>}
+\def\apVERSION{1.5 <Jan 2016>}
\message{The Arbitrary Precision Numbers, \apVERSION}
%%%%%%%%%%%% Internal registers, sec. 2.1 in apnum.pdf
@@ -591,7 +591,7 @@
\def\apROUNDd#1.@#2{\def\XOUT{#1}\edef\XOUT{\apREMzerosR\XOUT}%
\ifnum\apnumX=0 \def\tmpd{}\fi
\ifx\tmpd\empty
- \ifx\tmpc\empty \def#2{0}%
+ \ifx\tmpc\empty \def#2{0}%
\else \edef#2{\ifnum\apnumG<0-\fi\tmpc}\fi
\else\edef#2{\ifnum\apnumG<0-\fi\tmpc.\tmpd}\fi
}
@@ -722,12 +722,17 @@
\let\OUT=\XOUT % remainder is the output
\apEND % end of group
}
-\def\iROUND#1{\relax \evaldef\OUT{#1}\apEnum\OUT \apROUND\OUT0}
+\def\iFLOOR#1{\relax \evaldef\OUT{#1}\apEnum\OUT \apROUND\OUT0%
+ \ifnum\apSIGN<0 \ifx\XOUT\empty \else \apPLUS\OUT{-1}\fi\fi
+ \def\tmp{0}\ifx\tmp\OUT \apSIGN=0 \fi
+}
\def\iFRAC#1{\relax
\evaldef\OUT{#1}\apEnum\OUT \apROUND\OUT0% % preparing the parameter
- \ifx\XOUT\empty \def\OUT{0}\apSIGN=0 % empty fraction part means zero
- \else \edef\OUT{.\XOUT}\apSIGN=1 % else OUT = dot+fraction part
- \fi
+ \ifx\XOUT\empty \def\OUT{0}\apSIGN=0 % empty fraction part means zero
+ \else \ifnum\apSIGN<0
+ \edef\XOUT{-.\XOUT}\apPLUS1\XOUT % OUT = 1 - .\XOUT
+ \else \edef\OUT{.\XOUT}\apSIGN=1 % else OUT = .\XOUT
+ \fi \fi
}
\def\FAC#1{\relax \apINIT % "function-like" in the group, FAC = factorial
@@ -999,6 +1004,7 @@
\ifnum\apTOT=0 \advance\apFRAC by-3 \else \apFRAC=\apTOT \fi
\ifnum\apFRAC<0 \apFRAC=-\apFRAC \fi
\apROUND\OUT\apFRAC
+ \def\X{0}\ifx\OUT\X \apSIGN=0 \fi
\ifnum\apSIGN<0 \edef\OUT{-\OUT}\fi
\apEND
}
@@ -1060,8 +1066,73 @@
}
\def\ACOS#1{\relax \apPIexec \apPLUS\apPIhalf{-\ASIN{#1}}}
+%%%%%%%%%%%% Printing expressions, sec 2.11 in apnum.pdf
+
+\def\eprint#1#2{\bgroup \apnumA=0 \apnumE=1 \apEVALb#1\limits
+ \let\apEPe=\relax \apEPi #2\tmpb \apEPe \egroup
+}
+\def\apEPi{\let\apPLUS=\apEPplus \let\apMINUS=\apEPminus
+ \let\apMUL=\apEPmul \let\apDIV=\apEPdiv \let\apPOWx=\apEPpow \def\apPPn##1{##1}%
+ \let\EXP=\apEPexp \def\LN{\apEPf{ln}}\let\SQRT=\apEPsqrt
+ \def\SIN{\apEPf{sin}}\def\COS{\apEPf{cos}}\def\TAN{\apEPf{tan}}%
+ \def\ASIN{\apEPf{arcsin}}\def\ACOS{\apEPf{arccos}}\def\ATAN{\apEPf{arctan}}%
+ \let\PI=\pi \def\PIhalf{{\pi\over2}}%
+ \let\ABS=\apEPabs \let\FAC=\apEPfac \let\BINOM=\apEPbinom
+ \let\SGN=\apEPsgn \let\iDIV=\apEPidiv \let\iMOD=\apEPimod
+ \let\iFLOOR=\apEPifloor \let\iFRAC=\apEPifrac
+ \let\apEPi=\relax \apEPj
+}
+\def\apEPj{}
+\def\apEPplus#1#2{{#1}+{#2}}
+\def\apEPminus#1#2{{#1}-\apEPp#2\empty\end!!...}
+\def\apEPmul#1#2{\def\tmpa{#1}\def\tmpb{-1}%
+ \ifx\tmpa\tmpb -\else \apEPp#1\empty\end!!...\apMULop\fi
+ \apEPp#2\empty\end!!!..}
+\def\apEPdiv#1#2{{#1}\over{#2}}
+\def\apEPpow#1#2{%
+ \let\apEPy=\empty \apEPpowa{#1}\end{#2}%
+ \ifx\apEPy\empty \apEPp#1\empty\end!!!!!^{#2}\else#1\fi
+}
+\def\apEPpowa#1{\expandafter\apEPpowb#1;}
+\def\apEPpowb#1#2;\end#3{\ifx#1\apEPf \def\apEPy{\let\apEPy=\empty #3}\fi}
+\let\apEPy=\empty
+\def\apEPf#1#2{\mathop{\rm#1}\nolimits
+ \ifx\apEPy\empty \else ^{\apEPy}\let\apEPy=\empty \fi
+ \eprint{#2}{\expandafter\apEPb}%
+}
+\def\apEPb#1{\def\next{\left(\def\apEPe{\right)}}%
+ \ifx\apPPn#1\let\next=\relax \fi
+ \ifx\apDIV#1\let\next=\relax \fi
+ \next#1%
+}
+\def\apEPp#1#2\end#3#4#5#6#7{%
+ \apEPa#1\bgroup{\left(}#3#4#5#6#7#1#2\apEPa#1\egroup{\right)}#3#4#5#6#7}
+\def\apEPa#1#2#3#4#5#6#7#8{%
+ \ifx#1\apEPplus \ifx#4.#2\else#3\fi\fi
+ \ifx#1\apEPminus \ifx#5.#2\else#3\fi\fi
+ \ifx#1\apEPmul \ifx#6.#2\else#3\fi\fi
+ \ifx#1\apEPdiv \ifx#7.#2\else#3\fi\fi
+ \ifx#1\apEPpow \ifx#8.#2\else#3\fi\fi
+ \ifx#1-\empty \ifx#6.#2\else#3\fi\fi
+}
+\let\apMULop=\cdot
+\def\apEPabs#1{\left|\eprint{#1}{}\right|}
+\def\apEPfac#1{\eprint{#1}{\expandafter\apEPb}\,!}
+\def\apEPbinom#1#2{{\eprint{#1}{}\choose\eprint{#2}{}}}
+\def\apEPsqrt#1{\sqrt{\eprint{#1}{}}}
+\def\apEPexp#1{{\rm e}^{\eprint{#1}{}}}
+\def\apEPsgn#1{\mathop{\rm sign}\eprint{#1}{\expandafter\apEPb}}
+\def\apEPdivmod#1#2#3{\left[\eprint{#2}{\expandafter\apEPb}%
+ \mathbin{\rm #1}\eprint{#3}{\expandafter\apEPb}\right]}
+\def\apEPidiv{\apEPdivmod{div}}
+\def\apEPimod{\apEPdivmod{mod}}
+\def\apEPifloor#1{\left\lfloor\eprint{#1}{}\right\rfloor}
+\def\apEPifrac#1{\left\{\eprint{#1}{}\right\}}
+
+\def\corrnum#1{\edef#1{\expandafter\apEPc#1\end}}
+\def\apEPc#1#2\end{\ifx#1-{-}\apEPc#2\end\else \ifx#1.0.#2\else #1#2\fi\fi}
-%%%%%%%%%%%% Conclusion, sec. 2.11 in apnum.pdf
+%%%%%%%%%%%% Conclusion, sec. 2.12 in apnum.pdf
\let\PLUS=\apPLUS \let\MINUS=\apMINUS \let\MUL=\apMUL \let\DIV=\apDIV \let\POW=\apPOW
\let\SIGN=\apSIGN \let\ROUND=\apROUND \let\NORM=\apNORM \let\ROLL=\apROLL
@@ -1097,3 +1168,7 @@
- \SIN, \COS, \TAN added
- \apTOT=0 by default
1.4a \end -> \limits, internal change in \ebvaldef because LaTeX redefines \end
+1.4b \apSINCOS: \ifx\OUT eq 0 added after \apROUND (bug fixed).
+1.5 <Jan 2015>
+ - \iROUND replaced by \iFLOOR, \iFRAC corrected (for negative numbers)
+ - \eprint introduced