summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-04-30 17:03:56 +0000
committerKarl Berry <karl@freefriends.org>2018-04-30 17:03:56 +0000
commitae8b34f2a6cf05f2d12a7a0d4bb28f5643b00e41 (patch)
treeb74f7fb27ad11452d721a0804f3d27ac726bcb3d /Master/texmf-dist/doc/generic
parentdacf576055f59aefcd2c687d90bc7145338738b9 (diff)
apnum (23apr18)
git-svn-id: svn://tug.org/texlive/trunk@47510 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/generic')
-rw-r--r--Master/texmf-dist/doc/generic/apnum/README1
-rw-r--r--Master/texmf-dist/doc/generic/apnum/apnum.d203
-rw-r--r--Master/texmf-dist/doc/generic/apnum/apnum.pdfbin712774 -> 720414 bytes
3 files changed, 129 insertions, 75 deletions
diff --git a/Master/texmf-dist/doc/generic/apnum/README b/Master/texmf-dist/doc/generic/apnum/README
index f926656cce0..b4abe62e1a4 100644
--- a/Master/texmf-dist/doc/generic/apnum/README
+++ b/Master/texmf-dist/doc/generic/apnum/README
@@ -26,3 +26,4 @@ Versions:
1.4 <Dec 2015> - \SIN, \COS, \TAN, \ASIN, \ACOS, \ATAN, \PI, \PIhalf added
1.5 <Jan 2016> - \eprint for printing evaluated expressions added.
1.6 <Feb 2016> - \evalmdef introduced, \EXP improved.
+1.7 <Apr 2018> - \eprint - round braces around an expression with unary minus
diff --git a/Master/texmf-dist/doc/generic/apnum/apnum.d b/Master/texmf-dist/doc/generic/apnum/apnum.d
index 5698936330a..b961d834345 100644
--- a/Master/texmf-dist/doc/generic/apnum/apnum.d
+++ b/Master/texmf-dist/doc/generic/apnum/apnum.d
@@ -1,6 +1,6 @@
% apnum.tex -- Arbitrary Precision Numbers
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% The documentation, Petr Olsak, 2014, 2015, 2016
+% The documentation, Petr Olsak, 2014, 2015, 2016, 2018
% You can create the pdf version of this documentation by the command
% pdfcsplain apnum.d
@@ -10,7 +10,7 @@
\input utf8off \clearmubyte % use pdfcsplain
-\def\projectversion{1.6 Feb 2016}
+\def\projectversion{1.7 Apr 2018}
\def\headtitle{Arbitrary Precision Numbers}
\widowpenalty=10000
@@ -520,15 +520,16 @@ only. Example:
\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}}
+{-(\X-\SQRT{\Y^2+1}) + -((\Y*\X+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
+ - \left(x-\sqrt{y^2+1}\right) + \left(- {yx+1\over 2}\right)
+ + \sin\!\left( x+{\pi\over2}\right) + 2 \cos y = \cr
+ = - \left(-0.25-\sqrt{18.11^2+1}\right) +
+ \left(- {18.11\cdot(-0.25)+1\over 2}\right)
+ + \sin\!\left( -0.25+{\pi\over2}\right) + 2\cdot \cos 18.11 = \cr
= 22.5977863, \cr
x = -0.25, \quad y = 18.11
}
@@ -540,10 +541,10 @@ 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
+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
@@ -570,14 +571,15 @@ 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$.
+\def\BK#1{\relax \evaldef\OUT{#1}} \let\noBK=\BK
+\def\apEPj{\def\BK##1{\left(\eprint{##1}{}\right)}%
+ \def\noBK##1{\eprint{##1}{}}}
+Now $\eprint{3+\BK{\SIN{1}}^2}{}$ prints $3+(\sin 1)^2$.
\endtt
+Note that "\apEPj" macro is an initial hook of "\eprint"
+(it is run inside group before processing of the second parameter of "\eprint").
+
\subsec [tests] Experiments
The following table shows the time needed for calculation of randomly
@@ -2687,7 +2689,7 @@ 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
+initialization is added in "\apEPj" and "#2". Then "\tmpb" is processed. The \db apEPe can
do something end-game play but typically it is "\relax".
\inext{eprint}{^^B\cbrace}{++}
@@ -2705,54 +2707,78 @@ printing initialization of such macros here.
\inext{apEPi}{def\nb apEPj}{++}
-All parameters are processed in new group. For example we have
+All parameters are processed in new group (excepts individual constants).
+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}{}{++}
+"a+{\apDIV{b}{c}}" is processed and thus "a+{b\over c}" is printed.
+As noted above, the outer group is set by "\eprint" macro itself.
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}{}{++}
+interpreter then the original positions of the round brackets are definitively
+lost. We must to print these brackets if it is required by usual math syntax.
+For example "\apPLUS{1}{-2}" must be printed as "1+(-2)".
+But "\apPLUS{1}{2}" must be printed as "1+2". So, we print
+all parameters using "\apEPp{<parameter>}{<a><b><c><d>}".
+This macro decides if the parameter will be surrounded by brackets or not.
+So, the ``printing'' meaning of "\apPLUS" (or "\apMINUS" respectively)
+and prepared in \db apEPplus (or \db apEPminus respectively) looks like:
+
+\inext{apEPplus}{apEPminus}{++}
+
+The usage of "\apEPp{<parameter>}{<a><b><c><d>}" has the
+following meaning:
+
+\begitems
+\item * if "<a>" is "!" and the "<parameter>" is a negative constant or
+ a "-<expression>" or
+\item * if "<b>" is "!" and main operator $\M$ of the "<parameter>" is "+" or "-" or
+\item * if "<c>" is "!" and main operator $\M$ of the "<parameter>" is "*" or
+\item * if "<d>" is "!" and main operator $\M$ of the "<parameter>" is "/" or "^"
+\enditems
+\noindent then "\apEPp" prints brackets around the "<parameter>" using
+"\left(<parameter>\right)".
+Else it doesn't use brackets around the "<parameter>" (but the "<parameter>"
+itself is printed in a group unless it is single element: constant, variable).
+
+The rule for the parameter "<a>" has the exception: if "<a>" is "?" and the
+"<parameter>" is a negative constant or a "-<expression>", then brackets are
+not used if and only if this is ``very first parameter'', it means that
+the "<parameter>" is first:
+\begitems
+\item * at beginning of the whole "<expression>" given as an argument
+ of "\eprint" or
+\item * immediately after an opening bracket or
+\item * at beginning of a numerator or a denominator in a fraction or
+\item * at beginning of an exponent.
+\enditems
+
+For example "-1+1" is preprocessed as "\apPLUS{-1}{1}" and printed as "-1+1"
+because first parameter has "<a>" equal to "?" and we are at beginning of
+the expression. But "1+-1" is preprocessed as
+"\apPLUS{1}{-1}" and printed as "1+(-1)" because second parameter has "<a>"
+equal to "!". The "2*(-1+5)" is printed as "2\cdot(-1+5)" because "-1" is
+``very first parameter'' after opening bracket.
+Another examples: "-1+-1+-1" is printed as "-1+(-1)+(-1)",
+"a+b*c" is printed as "a+b\cdot c" (without brackets), The "1-(2+3)" is
+printed ``as is'' but "1+(2+3)" is printed as "1+2+3".
+
+The question about to be ``very first parameter'' is controlled by the value of
+\db apEPx macro. It is started as "." and it is replaced by "!" whenever "<a>" is "!".
+It is reverted to "." when open bracket is printed.
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}{!!!}{++}
+to "-1". If this is true, then we print only the unary minus (no whole "-1\cdot").
+Else we print the whole first parameter (enclosed in braces if its $\M$ is "+" or "-").
+The first case has two sub-cases: if "\apEPx" is "!" (it means that it is not
+``very first parameter'' then brackets are used around "-<expression>".
+
+The second parameter is enclosed in brackets if its $\M$ is "+" or "-".
+
+\inext{apEPmul}{^^B\cbrace}{++}
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
@@ -2773,17 +2799,17 @@ performed by "\apEPpowa{<base>}\end{<exponent>}". If this is true then
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.
+enclosed by brackets only if the "<base>" is single and positive operand.
\inext{apEPpow}{^^B\cbrace}{++}
-The \db apEPpowa macro detects the special function-like macro "\SIN", "\COS"
+The \db apEPpowa and \db apEPpowb macros detect 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}{++}
+\inext{apEPpowa}{apEPy}{++}
The functions like "\SIN{<expression>}" are printed by
\db apEPf "{<name>}{<expression>}". First, the "\mathop{<name>}\nolimits" is
@@ -2793,30 +2819,57 @@ printed. If "\apEPy" is non-empty then the exponent is printed by
\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>".
+The space-correction macro \db apEPk is set to remove the "\thinmuskip"
+after "\mathop". This will be processed only if the "\left(" follows: we want
+to print "\sin\apEPk\left(<expression>\right)" because this gives the same result as
+"\sin(<expression>)". On the other hand we don't use "\apEPk" when simple "\sin x"
+is printed without brackets.
+
+By default the "<expression>" (this is an argument of common function-like
+macros "\SIN", "\COS", "\EXP" etc.) will be printed in brackets
+(see the default "\next" definition
+where closing bracket is printed by "\apEPe" macro used after expanded "\tmpb").
+But if
+\begitems
+\item * the "<expression>" is single non-negatie object
+ (a constant or a variable without unary minus) or
+\item * the "<expression>" is a fraction of the form "{<nominator>\over<denominator>}"
+\enditems
+
+\noindent then no brackets are printed around the "<expression>".
+
+This rule is implemented by the usage of
+"\expandafter"\db apEPb in the "<declaration>" part of "\eprint"
+(in the code of "\apEPf" above). It
+expands the following "\tmpb" (the result of the expression scanner) and
+checks the first token and the following parameter.
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.
+The meaning of \db apEPp "{<parameter>}{<a><b><c><d>}" is
+explained above, see the text where "\apEPplus" 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"
+\db apEPa "<first token><rest>\end{<normal>}{<bracket>}<a><b><c><d>"
+is used twice:
+before processing the "<parameter>" 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.
+above where $\M$ (or unary "-" when "<parameter>" is negative constant)
+is equal to the "<first token>".
\inext{apEPp}{^^B\cbrace}{++}
+If we have variables like "\def\X{-17}" and the expression looks like
+"1+\X" and the constants stored in the varaibales must to be printed
+then we have "\apPLUS{1}{\X}" after expression scanner and we need
+to print "1+(-17)".
+So we need to try to expand the "<paramter>" and to test if there is the
+unary "-" as a "<first-tok>". This is done by
+\db apEPd "<first-tok><rest>\end{<group-type>}{<else-part>}{<dot-or-exclam>}".
+
+\inext{apEPd}{}{++}
+
The \db apMULop is used as an operation mark for multiplying.
It is "\cdot" by default but user can change this.
diff --git a/Master/texmf-dist/doc/generic/apnum/apnum.pdf b/Master/texmf-dist/doc/generic/apnum/apnum.pdf
index e9ec9d35135..b7d4588d552 100644
--- a/Master/texmf-dist/doc/generic/apnum/apnum.pdf
+++ b/Master/texmf-dist/doc/generic/apnum/apnum.pdf
Binary files differ