| 1 |
%% LyX 2.4.0-beta3-devel created this file. For more info, see https://www.lyx.org/. |
| 2 |
%% Do not edit unless you really know what you are doing. |
| 3 |
\documentclass[english,tableposition=top]{report} |
| 4 |
\usepackage{lmodern} |
| 5 |
\renewcommand{\sfdefault}{lmss} |
| 6 |
\renewcommand{\ttdefault}{lmtt} |
| 7 |
\usepackage[T1]{fontenc} |
| 8 |
\usepackage{textcomp} |
| 9 |
\usepackage[utf8]{inputenc} |
| 10 |
\setcounter{secnumdepth}{3} |
| 11 |
\usepackage{color} |
| 12 |
\definecolor{shadecolor}{rgb}{0.667969, 1, 1} |
| 13 |
\usepackage{babel} |
| 14 |
\usepackage{array} |
| 15 |
\usepackage{cprotect} |
| 16 |
\usepackage{wrapfig} |
| 17 |
\usepackage{booktabs} |
| 18 |
\usepackage{framed} |
| 19 |
\usepackage{url} |
| 20 |
\usepackage{multirow} |
| 21 |
\usepackage{varwidth} |
| 22 |
\usepackage{amsmath} |
| 23 |
\usepackage{amssymb} |
| 24 |
\usepackage[pdfusetitle, |
| 25 |
bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=2, |
| 26 |
breaklinks=true,pdfborder={0 0 1},backref=section,colorlinks=true] |
| 27 |
{hyperref} |
| 28 |
|
| 29 |
\makeatletter |
| 30 |
|
| 31 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands. |
| 32 |
\providecommand{\LyX}{\texorpdfstring{\ensureascii{% |
| 33 |
L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX\@}}{LyX}} |
| 34 |
\newcommand{\noun}[1]{\textsc{#1}} |
| 35 |
\DeclareRobustCommand*{\lyxarrow}{% |
| 36 |
\@ifstar |
| 37 |
{\leavevmode\,$\triangleleft$\,\allowbreak} |
| 38 |
{\leavevmode\,$\triangleright$\,\allowbreak}} |
| 39 |
%% Because html converters don't know tabularnewline |
| 40 |
\providecommand{\tabularnewline}{\\} |
| 41 |
%% Variable width box for table cells |
| 42 |
\newenvironment{cellvarwidth}[1][t] |
| 43 |
{\begin{varwidth}[#1]{\linewidth}} |
| 44 |
{\@finalstrut\@arstrutbox\end{varwidth}} |
| 45 |
|
| 46 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands. |
| 47 |
\newenvironment{centred}% |
| 48 |
{\begin{center}}{\end{center}} |
| 49 |
|
| 50 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands. |
| 51 |
\usepackage{numerica} |
| 52 |
\usepackage{mleftright} |
| 53 |
\usepackage{upquote} |
| 54 |
\usepackage{xfrac} |
| 55 |
\usepackage{xurl} |
| 56 |
|
| 57 |
\newcommand\rel{\,\varrho\;} |
| 58 |
\DeclareMathOperator{\erf}{erf} |
| 59 |
\DeclareMathOperator{\gd}{gd} |
| 60 |
|
| 61 |
\reuse{} |
| 62 |
\newcommand\vsp{\vphantom{I^{I^I}}} |
| 63 |
\newcommand\dsp{\vphantom{I_{I_I}}} |
| 64 |
|
| 65 |
\makeatother |
| 66 |
|
| 67 |
\begin{document} |
| 68 |
\title{\texttt{numerica}~\\ |
| 69 |
{\large version 3.0.0}} |
| 70 |
\author{Andrew Parsloe\\ |
| 71 |
(\url{[email protected]})} |
| 72 |
\maketitle |
| 73 |
\begin{abstract} |
| 74 |
The \texttt{numerica} package defines a command \verb`\nmcEvaluate` |
| 75 |
(short-name form \verb`\eval`) to wrap around mathematical expressions |
| 76 |
in the LaTeX form in which they are typeset and numerically evaluate |
| 77 |
them. For programs (like \LyX ) with a preview facility, or for compile-as-you-go |
| 78 |
systems, interactive back-of-envelope calculations and numerical exploration |
| 79 |
are possible within the document being worked on. |
| 80 |
\end{abstract} |
| 81 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 82 |
\begin{shaded}% |
| 83 |
\begin{itemize} |
| 84 |
\item This document applies to version 3.0.0 of \texttt{numerica}. |
| 85 |
\item \texttt{numerica} requires a \LaTeXe{} system from October 2020 or |
| 86 |
later (when \texttt{xparse} became available in \LaTeXe{} systems). |
| 87 |
\item The package requires \texttt{amsmath} and \texttt{mathtools}, is compatible |
| 88 |
with the \texttt{mleftright} and \texttt{xfrac} packages, and `knows |
| 89 |
about' some symbols from \texttt{amssymb}. |
| 90 |
\item I refer many times in this document to \emph{Handbook of Mathematical |
| 91 |
Functions}, edited by Milton Abramowitz and Irene A. Stegun, Dover, |
| 92 |
1965, abbreviated to \emph{HMF}, and often followed by a number like |
| 93 |
1.2.3 to locate the actual expression referenced. |
| 94 |
\item Version 3.0.0 of \texttt{numerica} |
| 95 |
\begin{itemize} |
| 96 |
\item dispenses with a configuration file (\verb`numerica.cfg`) but adds |
| 97 |
three package options: |
| 98 |
\begin{itemize} |
| 99 |
\item \verb`comma` sets the comma as the decimal point; items in the variable=value |
| 100 |
list must then be separated by semicolons; |
| 101 |
\item \verb`rounding`=$n$ sets the default rounding value to the integer |
| 102 |
$n$; |
| 103 |
\item \verb`approx` replaces the default \verb`=` between formula and |
| 104 |
result in displays with \verb`\approx` ($\approx$); |
| 105 |
\end{itemize} |
| 106 |
\item enables outputting results as (approximate) fractions with integer |
| 107 |
numerators and denominators in both slash and \verb`\frac` forms; |
| 108 |
\item allows use of \LaTeX{} braces for delimiting arguments to functions |
| 109 |
like \verb`\sin` and \verb`\cos` to handle complicated arguments |
| 110 |
in (e.g.) Fourier series; the previous \texttt{()=0}, \texttt{1}, |
| 111 |
\texttt{2} setting for this is removed; |
| 112 |
\item enables multiple formulas to be evaluated within the one \verb`\eval` |
| 113 |
command; and |
| 114 |
\item provides enhanced treatment of mathematical environments for the presentation |
| 115 |
of results, especially for such multiple evaluations, with the \verb`env` |
| 116 |
key in the settings option (which makes the \verb`*` key obsolete); |
| 117 |
\item defines a \verb`\degree` command and uses it as an alternative to |
| 118 |
the \verb`o` setting for specifying angles in degrees; |
| 119 |
\item allows nested commands to be evaluated to a specified rounding value |
| 120 |
(rather than insisting that they be evaluated to maximum precision); |
| 121 |
\item accepts the use of spaces to group blocks of digits in numbers in |
| 122 |
the variable=value list and formula (with the setting \verb`1s2=1`); |
| 123 |
\item resolves the `leading space' issue with the \verb`\macros` command |
| 124 |
when a user-defined macro begins with an expandable token; |
| 125 |
\item \emph{continues \ldots} |
| 126 |
\end{itemize} |
| 127 |
\end{itemize} |
| 128 |
\end{shaded}% |
| 129 |
\end{minipage} |
| 130 |
|
| 131 |
\noindent{}% |
| 132 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 133 |
\begin{shaded}% |
| 134 |
\begin{itemize} |
| 135 |
\item Version 3.0.0 of \texttt{numerica}~\emph{(continued)} |
| 136 |
\begin{itemize} |
| 137 |
\item reworks (again!) the \verb`\reuse` command to simplify its use, and |
| 138 |
\item removes the \verb`reuse` \emph{setting} of \verb`\eval` (not the |
| 139 |
command); now \emph{only} the numerical result is saved, either as |
| 140 |
a decimal or in scientific notation or in fraction form (but without |
| 141 |
math delimiters or variable=value list); |
| 142 |
\item adds the \LaTeX{} form of a result to the debug display (\verb`dbg=11`); |
| 143 |
\item adds warnings with line numbers to the \LaTeX{} log file for \texttt{numerica} |
| 144 |
errors (which continue to be displayed in the pdf); |
| 145 |
\item accepts the use of \verb`a-`, \verb`ar-` or \verb`arc-` prefixes |
| 146 |
for the inverses of all six hyperbolic functions so that, for instance, |
| 147 |
\verb`\asinh`, \verb`\arsinh`, and \verb`\arcsinh`, displaying |
| 148 |
as $\asinh$, $\arsinh$ and $\arcsinh$, can be used (rather than |
| 149 |
only \verb`\asinh` as before); |
| 150 |
\item accepts the \verb`\sfrac` command from the \texttt{xfrac} package, |
| 151 |
producing elegant slash fractions like $\sfrac{355}{113}$; |
| 152 |
\item accepts commands of the \texttt{mleftright} package; |
| 153 |
\item accepts \verb`\mkern` and \verb`\mskip` commands in formulas; |
| 154 |
\item defines the commands \verb`\comma` and \verb`\equals` (expanding |
| 155 |
to \verb`,` and \verb`=`) for use in the settings option, as distinct |
| 156 |
from the `bare' marks used in formulas; |
| 157 |
\item fixes bugs that could occur: (i) when raising an $n$-th root to a |
| 158 |
power; (ii) when using a dot with \verb`\left`, \verb`\right`; and |
| 159 |
(iii) when using a non-integer in the first argument of \verb`\binom`; |
| 160 |
\item amends and adds to documentation. |
| 161 |
\end{itemize} |
| 162 |
\end{itemize} |
| 163 |
\end{shaded}% |
| 164 |
\end{minipage} |
| 165 |
|
| 166 |
\tableofcontents{} |
| 167 |
|
| 168 |
\chapter{Introduction} |
| 169 |
|
| 170 |
\label{chap:Introduction}\texttt{numerica} is a \LaTeX{} package offering |
| 171 |
the ability to numerically evaluate mathematical expressions in the |
| 172 |
\LaTeX{} form in which they are typeset. |
| 173 |
|
| 174 |
There are a number of packages which can do calculations in \LaTeX ,\footnote{A simple search finds the venerable \texttt{calc} in the \LaTeX{} base, |
| 175 |
\texttt{calculator }(including an associated \texttt{calculus} package), |
| 176 |
\texttt{fltpoint}, \texttt{fp} (\emph{fixed} rather than floating |
| 177 |
point), \texttt{spreadtab} (using either \texttt{fp} or \texttt{l3fp} |
| 178 |
as its calculational engine) if you want simple spreadsheeting with |
| 179 |
your calculations, the elaborate \texttt{xint}, \texttt{pst-calculate} |
| 180 |
(a limited interface to \texttt{l3fp}), \texttt{l3fp} in the \LaTeX 3 |
| 181 |
kernel, and \texttt{xfp}, the \LaTeX 3 interface to \texttt{l3fp}. |
| 182 |
Other packages include a calculational element but are restricted |
| 183 |
in their scope. (\texttt{longdivision} for instance is elegant, but |
| 184 |
limited only to long division.)} but those I am aware of all require the mathematical expressions |
| 185 |
they operate on to be changed to an appropriate syntax. Of these packages |
| 186 |
\texttt{xfp} comes closest to my objective with \texttt{numerica}. |
| 187 |
For instance, given a formula |
| 188 |
\begin{centred} |
| 189 |
\verb`\frac{\sin (3.5)}{2} + 2\cdot 10^{-3}` |
| 190 |
\end{centred} |
| 191 |
(in a math environment), this can be evaluated using \texttt{xfp} |
| 192 |
by transforming the expression to \verb`sin(3.5)/2 + 2e-3` and wrapping |
| 193 |
this in the command \verb`\fpeval`. In \texttt{numerica} you don't |
| 194 |
need to transform the formula, just wrap it in an \verb`\eval` command: |
| 195 |
\begin{centred} |
| 196 |
\verb`\eval{ \frac{\sin (3.5)}{2} + 2\cdot 10^{-3} }`. |
| 197 |
\end{centred} |
| 198 |
(For the actual calculation see §\ref{subsec:introBasicProcedure}.)\texttt{ } |
| 199 |
|
| 200 |
\texttt{numerica}, like \texttt{xfp} and a number of other packages, |
| 201 |
uses \texttt{l3fp} (the \LaTeX 3 floating point module in \texttt{l3kernel} |
| 202 |
and since February 2020 available in \LaTeXe{} distributions) as its |
| 203 |
calculational engine. The main command of the package, \verb`\nmcEvaluate`, |
| 204 |
short-name form \verb`\eval`, in many ways acts as a pre-processor |
| 205 |
to \texttt{l3fp}, converting mathematical expressions written in the |
| 206 |
\LaTeX\texttt{ }form in which they will be typeset into an `fp-ified' |
| 207 |
form that is digestible by \texttt{l3fp}. The aim is for the command |
| 208 |
to act as a wrapper around \LaTeX{} formulas, processing them into |
| 209 |
a form that is digestible by \texttt{l3fp} and allows compilation |
| 210 |
to \texttt{pdf} to take place. Ideally, one should not have to make |
| 211 |
\emph{any} adjustment to a formula, although any text on Fourier series |
| 212 |
suggests that hope in full generality is delusional. Surprisingly |
| 213 |
often however it \emph{is} possible. We shall see shortly that even |
| 214 |
complicated formulas like |
| 215 |
|
| 216 |
\[ |
| 217 |
\cos\tfrac{m}{n}\pi-(1-4\sin^{2}\tfrac{m}{3n}\pi)\frac{\sin\tfrac{1}{n}\pi\sin\tfrac{m-1}{n}\pi}{2\sin^{2}\tfrac{m}{3n}\pi}, |
| 218 |
\] |
| 219 |
and |
| 220 |
\[ |
| 221 |
\left(\frac{1-4\sin^{2}\tfrac{m}{3n}\pi}{2\sin^{2}\tfrac{m}{3n}\pi}\right)\sin\tfrac{2m-3}{3n}\pi\sin\tfrac{m-3}{3n}\pi, |
| 222 |
\] |
| 223 |
|
| 224 |
\noindent can be evaluated `as is' (see below, §\ref{subsec:introReassurance}). |
| 225 |
There is no need to shift the position of the superscript $2$ on |
| 226 |
the sines, no need to parenthesize the arguments of \verb`\sin` and |
| 227 |
\verb`\cos`, no need to insert asterisks to indicate multiplication, |
| 228 |
no need to change the \verb`\frac` and \verb`\tfrac`-s to slashes, |
| 229 |
\texttt{/}, and in the second expression no need to delete the \verb`\left` |
| 230 |
and \verb`\right` that qualify the big parentheses (in the underlying |
| 231 |
\LaTeX ). Of course, if there are variables in an expression, as in |
| 232 |
these examples, they will need to be assigned values; that is unavoidable. |
| 233 |
And how the result of the evaluation is displayed also requires specifying, |
| 234 |
but the aim is always: to evaluate mathematical expressions in \LaTeX{} |
| 235 |
with as little adjustment as possible to the form in which they are |
| 236 |
typeset. |
| 237 |
|
| 238 |
\texttt{numerica} is written in \texttt{expl3}, the programming language |
| 239 |
of the \LaTeX 3 project, now incorporated into the \LaTeX{} kernel. |
| 240 |
It uses the \LaTeX 3 module \texttt{l3fp} (since early 2020 part of |
| 241 |
a standard \LaTeXe{} distribution) as its calculational engine. This |
| 242 |
enables floating point operations to 16 significant figures, with |
| 243 |
exponents ranging between $-10000$ and $+10000$. Many functions |
| 244 |
and operations are built into \texttt{l3fp} – arithmetic operations, |
| 245 |
trigonometric, exponential and logarithm functions, factorials, absolute |
| 246 |
value, max and min. Others have been constructed for \texttt{numerica |
| 247 |
}from \texttt{l3fp} ingredients – binomial coefficients, hyperbolic |
| 248 |
functions, sums and products – but to the user there should be no |
| 249 |
discernible difference. |
| 250 |
|
| 251 |
Associated packages provide for additional operations: iteration of |
| 252 |
functions, finding zeros of functions, recurrence relations, mathematical |
| 253 |
table building. |
| 254 |
|
| 255 |
\section{How to use \texttt{numerica}} |
| 256 |
|
| 257 |
The package is invoked in the usual way: put |
| 258 |
\begin{verbatim} |
| 259 |
\usepackage[<options>]{numerica} |
| 260 |
\end{verbatim} |
| 261 |
\noindent in the \LaTeX{} preamble. \texttt{numerica} requires the |
| 262 |
\texttt{amsmath} and \texttt{mathtools} packages and loads these automatically. |
| 263 |
\texttt{numerica} will also accept use of some relation symbols from |
| 264 |
the \texttt{amssymb} package (see §\ref{subsec:evalBoolean-output}), |
| 265 |
all commands from the \texttt{mleftright} package, and the \verb`\sfrac` |
| 266 |
command from \texttt{xfrac} (part of the \texttt{l3packages} bundle), |
| 267 |
provided these last three packages have been loaded by the user. |
| 268 |
|
| 269 |
\subsection{Package options} |
| 270 |
|
| 271 |
\label{subsec:introPackagesOptions}Version 2 of \texttt{numerica} |
| 272 |
had no package options. The options available in version 1 that gave |
| 273 |
access to commands for iteration, finding zeros, math-table making, |
| 274 |
etc., were discontinued. That functionality became available in associated |
| 275 |
but separate \LaTeX{} packages (see below §\ref{subsec:introAssociated-packages}). |
| 276 |
With version 3.0.0 some package options have been added and the possible |
| 277 |
use of a configuration file dispensed with. The current options available |
| 278 |
with version 3.0.0 are: |
| 279 |
\begin{itemize} |
| 280 |
\item \verb`comma` If present, a decimal point is denoted by a comma (more |
| 281 |
exactly, an unspaced comma). If absent, a decimal point is denoted |
| 282 |
by a dot (period, full stop, also unspaced). The choice – \verb`comma` |
| 283 |
present, \verb`comma` absent – has consequences for the item separator |
| 284 |
in the variable=value list and $n$-ary functions (see §\ref{subsec:introDecPtItemSeps}), |
| 285 |
and the item separator in the main argument of the \verb`\eval`, |
| 286 |
\verb`\macros` and \verb`\constants` commands; see below §\ref{subsec:introDecPtItemSeps}. |
| 287 |
\begin{itemize} |
| 288 |
\item `Out of the box' the \verb`comma` option is not used and the decimal |
| 289 |
point is a dot. |
| 290 |
\end{itemize} |
| 291 |
\item \verb`rounding=<integer>` The rounding value. The value of \verb`<integer>` |
| 292 |
determines how many digits after the decimal point are displayed in |
| 293 |
numerical results (see §\ref{subsec:evalRounding-value}). `Out of |
| 294 |
the box' the value is set to $6$. |
| 295 |
\item \verb`approx` sets the default relation linking \emph{formula} and |
| 296 |
\emph{result} in displays from \verb`=` to \verb`\approx` (displaying |
| 297 |
as $\approx$). (The \verb`eq` setting (§\ref{subsec:settingsRelationSymbol}) |
| 298 |
is available to change the relation for individual calculations.) |
| 299 |
\end{itemize} |
| 300 |
Thus a possible invocation of \texttt{numerica} might be |
| 301 |
\begin{verbatim} |
| 302 |
\usepackage[comma,rounding=4,approx]{numerica} |
| 303 |
\end{verbatim} |
| 304 |
meaning that the decimal point is an unspaced comma, the default rounding |
| 305 |
value is $4$, and \verb`\approx` is inserted between formula and |
| 306 |
numerical result in (some) displays. Alternatively, |
| 307 |
\begin{verbatim} |
| 308 |
\usepackage{numerica} |
| 309 |
\end{verbatim} |
| 310 |
means the decimal point is an unspaced dot, the rounding value is |
| 311 |
$6$, and the display of (some) results is in the form \emph{formula=result}. |
| 312 |
\textbf{This is how} \texttt{\textbf{numerica}} \textbf{is invoked |
| 313 |
for the present document.} |
| 314 |
|
| 315 |
\subsubsection{\texttt{numerica.cfg}} |
| 316 |
|
| 317 |
Previous versions of \texttt{numerica} supported use of a configuration |
| 318 |
file for setting various default values. With version 3.0.0, this |
| 319 |
has been dispensed with. Now, \texttt{numerica} supports (currently) |
| 320 |
the three package options mentioned. On review, most of the \texttt{.cfg} |
| 321 |
settings did not feel like ones that realistically qualified as package-level |
| 322 |
settings. For calculation-level default values, see Chapter~\ref{chap:settingsSettings}. |
| 323 |
|
| 324 |
\subsubsection{Associated packages} |
| 325 |
|
| 326 |
\label{subsec:introAssociated-packages}Currently there are two of |
| 327 |
these, \texttt{numerica-plus} and \texttt{numerica-tables}. They are |
| 328 |
loaded with the familiar \verb`\usepackage` command in the document |
| 329 |
preamble and require \texttt{numerica} to be loaded. This is different |
| 330 |
from version 2 where calling \texttt{numerica-plus} or \texttt{numerica-tables} |
| 331 |
automatically loaded \texttt{numerica}.\texttt{ }I think it is clearer |
| 332 |
to do this in two explicit steps. Neither package will function without |
| 333 |
\texttt{numerica} loaded. Thus putting |
| 334 |
\begin{verbatim} |
| 335 |
\usepackage[<options>]{numerica} |
| 336 |
\usepackage{numerica-plus} |
| 337 |
\end{verbatim} |
| 338 |
in the preamble of your document gives access to the commands \verb`\nmcIterate`, |
| 339 |
\verb`\nmcSolve`, and \verb`\nmcRecur` of \texttt{numerica-plus} |
| 340 |
and of course also to the commands in \texttt{numerica}. \verb`\nmcIterate` |
| 341 |
enables the iteration of functions of a single variable, including |
| 342 |
finding fixed points and, by means of Newton-Raphson iteration, finding |
| 343 |
zeros. \verb`\nmcSolve` enables the solving of equations of the form |
| 344 |
$f(x)=0$ (i.e.\ finding zeros) by bisection, or the finding of local |
| 345 |
maxima or minima of a function of one variable. \verb`\nmcRecur` |
| 346 |
enables the calculation of terms in recurrence relations, like the |
| 347 |
terms of the Fibonacci series, or othogonal polynomials defined recurrently. |
| 348 |
In all three cases, see the associated document \verb`numerica-plus.pdf` |
| 349 |
for details. |
| 350 |
|
| 351 |
If you enter |
| 352 |
\begin{verbatim} |
| 353 |
\usepackage[<options>]{numerica} |
| 354 |
\usepackage{numerica-tables} |
| 355 |
\end{verbatim} |
| 356 |
in the preamble of your document you gain access to the command \verb`\nmcTabulate`, |
| 357 |
which enables the creation of (possibly multi-column) tables of function |
| 358 |
values and makes available most of the table formats used in \emph{HMF} |
| 359 |
(and also to the commands in \texttt{numerica}). See the associated |
| 360 |
document \verb`numerica-tables.pdf` for details. |
| 361 |
|
| 362 |
\subsection{Decimal point and item separators} |
| 363 |
|
| 364 |
\label{subsec:introDecPtItemSeps}From version 3.0.0 of \texttt{numerica} |
| 365 |
the trio of marks {\ttfamily\verb`.,;`} have different |
| 366 |
functions depending as the package is called without or with the \verb`comma` |
| 367 |
option. Without the comma option, the decimal point is a dot (period, |
| 368 |
full stop) and the variable=value list (§\ref{sec:evalVv-list}) is |
| 369 |
punctuated with commas. There is no ambiguity in a list like \verb`[g=9.81,u=1,t=0.5]` |
| 370 |
nor in the arguments of $n$-ary functions (§\ref{sec:calc-n-ary-functions}) |
| 371 |
like \verb`\max`, \verb`\min`, \verb`\gcd`, e.g.\ \verb`\gcd(63,231)`, |
| 372 |
although the presence of such functions in the vv-list needs protective |
| 373 |
braces, e.g.\ \verb`[x={\min(\pi,e,\phi,\gamma)},y=2]`. |
| 374 |
|
| 375 |
But if the decimal point is a comma, then its use as a separator in |
| 376 |
these lists is problematic. For that reason, with the \verb`comma` |
| 377 |
package option, \texttt{numerica} uses a \emph{semicolon} to punctuate |
| 378 |
the variable=value list and the argument lists of $n$-ary functions: |
| 379 |
\verb`[g=9,81;u=1;t=0,5]`, \verb`\max(6,1;2e;\gamma\pi^2)`. This |
| 380 |
is in line with ISO 80000 Part 2, section 3 which reads: `A comma, |
| 381 |
semicolon or other appropriate symbol can be used as a separator between |
| 382 |
numbers or expressions. The comma is generally preferred, except when |
| 383 |
numbers with a decimal comma are used.' However, rather than the |
| 384 |
gently permissive language of the standard, \texttt{numerica} \emph{insists} |
| 385 |
on semicolons for separating items when the \verb`comma` package |
| 386 |
option is used. |
| 387 |
|
| 388 |
In summary, the trio of punctuation marks \verb`.,;` are used in |
| 389 |
\texttt{numerica} like this: when the \verb`comma` package option |
| 390 |
is \emph{not} used, the marks function as |
| 391 |
\begin{itemize} |
| 392 |
\item \verb`.` = decimal point |
| 393 |
\begin{itemize} |
| 394 |
\item also \LaTeX{} dot signifying `no delimiter' when used with \verb`\left`, |
| 395 |
\verb`\right` etc. |
| 396 |
\end{itemize} |
| 397 |
\item \verb`,` = item separator in the variable=value list |
| 398 |
\begin{itemize} |
| 399 |
\item also argument separator in $n$-ary functions (\verb`\max`, \verb`\min`, |
| 400 |
\verb`\gcd`) |
| 401 |
\item also formula separator in the main argument of \verb`\nmcEvaluate` |
| 402 |
for multi-formula calculations |
| 403 |
\end{itemize} |
| 404 |
\end{itemize} |
| 405 |
or, when the \verb`comma` package option \emph{is} used, as |
| 406 |
\begin{itemize} |
| 407 |
\item \verb`.` = \LaTeX{} dot signifying `no delimiter' when used with |
| 408 |
\verb`\left`, \verb`\right` etc. |
| 409 |
\item \verb`,` = decimal point |
| 410 |
\item \verb`;` = item separator in the variable=value list |
| 411 |
\begin{itemize} |
| 412 |
\item also argument separator in $n$-ary functions (\verb`\max`, \verb`\min`, |
| 413 |
\verb`\gcd`), |
| 414 |
\item also formula separator in the main argument of \verb`\nmcEvaluate` |
| 415 |
for multi-formula calculations |
| 416 |
\end{itemize} |
| 417 |
\end{itemize} |
| 418 |
Note, in both cases, that if a formula involves an $n$-ary function |
| 419 |
(at present only \verb`\max`, \verb`\min`, or \verb`\gcd`) then |
| 420 |
it's argument will need to be hidden in braces to avoid being interpreted |
| 421 |
as containing multi-formula separators. Alternatively (and better) |
| 422 |
there is a setting that allows a different character to be used as |
| 423 |
the multi-formula separator for a calculation, e.g. \verb`ff=|` ; |
| 424 |
see §\ref{subsec:introMult-formula-calculations} and §\ref{subsec:settingsMulti-formula-separator}. |
| 425 |
|
| 426 |
\subsection{Basic procedure} |
| 427 |
|
| 428 |
\label{subsec:introBasicProcedure}A simple example of how \texttt{numerica} |
| 429 |
is used is provided by the document |
| 430 |
\begin{verbatim} |
| 431 |
\documentclass{article} |
| 432 |
\usepackage{numerica} |
| 433 |
\begin{document} |
| 434 |
\eval{$ mc^2 $}[m=70,c=299792458][8x] |
| 435 |
\end{document} |
| 436 |
\end{verbatim} |
| 437 |
\noindent There is a formula, \verb`mc^2`, between math delimiters: |
| 438 |
\verb`$ $`. A command \verb`\eval{ }` is wrapped around these, |
| 439 |
and two square-bracketed optional arguments have been appended. In |
| 440 |
the first option numerical values are assigned to the quantities \verb`m` |
| 441 |
and \verb`c` occurring in the formula. The assignments are separated |
| 442 |
by a comma since the dot is being used as the decimal point in this |
| 443 |
document. The second option contains a cryptic specification of the |
| 444 |
format of the numerical result – to $8$ places of decimals, and in |
| 445 |
(proper) scientific notation – the \verb`x`. Running \texttt{pdflatex} |
| 446 |
on this document generates a pdf displaying |
| 447 |
\begin{centred} |
| 448 |
\eval{$ mc^2$}[m=70,c=299792458][8x] |
| 449 |
\end{centred} |
| 450 |
\noindent where the formula ($mc^{2})$ is equated to the numerical |
| 451 |
value resulting from substituting the given values of $m$ and $c$. |
| 452 |
Those values are displayed in a list following the result. As specified, |
| 453 |
the result of the calculation is presented to $8$ decimal places |
| 454 |
in scientific notation. (According to Einstein's famous equation $E=mc^{2}$ |
| 455 |
this is the enormous energy content, in joules, of what was once considered |
| 456 |
an average adult Caucasian male.)\footnote{\noindent In earlier versions of \texttt{numerica} this calculation |
| 457 |
evaluated incorrectly because spaces were used to make \texttt{c=299792458} |
| 458 |
more `eye friendly'. Although numbers with spaces can now be read |
| 459 |
by \texttt{numerica}, this ability needs to be turned on by the user. |
| 460 |
`Out of the box' it is off; see §\ref{subsec:evalNumbers}.} |
| 461 |
|
| 462 |
A second example is provided by the formula in earlier remarks: |
| 463 |
\begin{verbatim} |
| 464 |
\documentclass{article} |
| 465 |
\usepackage{numerica} |
| 466 |
\begin{document} |
| 467 |
\begin{quote} |
| 468 |
First, evaluate the expression when it sits between |
| 469 |
textstyle delimiters, |
| 470 |
\eval{\( \frac{\sin(3.5)}{2} + 2\cdot 10^{-3} \)}, |
| 471 |
and then, second, when it sits between |
| 472 |
displaystyle delimiters: |
| 473 |
\eval{\[ \frac{\sin(3.5)}{2} + 2\cdot 10^{-3} \]} |
| 474 |
\end{quote} |
| 475 |
\end{document} |
| 476 |
|
| 477 |
\end{verbatim} |
| 478 |
Running \texttt{pdflatex} on this document produces the result: |
| 479 |
\begin{quote} |
| 480 |
First, evaluate the expression when it sits between |
| 481 |
textstyle delimiters, |
| 482 |
\eval{\( \frac{\sin(3.5)}{2} + 2\cdot 10^{-3} \)}, |
| 483 |
and then, second, when it sits between |
| 484 |
displaystyle delimiters: |
| 485 |
\eval{\[ \frac{\sin(3.5)}{2} + 2\cdot 10^{-3} \]} |
| 486 |
\end{quote} |
| 487 |
(For a quick mental check of the result, note that $\sin(3.5)\approx-0.35$.) |
| 488 |
The \verb`\eval` command used in these examples is the main command |
| 489 |
of the \texttt{numerica} package and is discussed fully in the next |
| 490 |
two chapters, but I first discuss different ways to display the results |
| 491 |
of calculations. |
| 492 |
|
| 493 |
\subsection{Display of the result} |
| 494 |
|
| 495 |
\label{subsec:introResultDisplay}In what follows I shall write things |
| 496 |
like (but generally more complicated than) |
| 497 |
\begin{centred} |
| 498 |
\verb`$ \eval{ 1+1 } $` $\Longrightarrow \eval{ 1 + 1 } $ |
| 499 |
\end{centred} |
| 500 |
to mean: run \texttt{pdflatex} on a document containing \verb`$ \eval{ 1+1 } $` |
| 501 |
in the document body to generate a pdf containing the calculated result |
| 502 |
– $2$ in this instance, as indicated by the arrow. The reader will |
| 503 |
note that I have used dollar signs to delimit the math environment. |
| 504 |
I could (and perhaps should) have used the more \LaTeX -pure \verb`\( \)`, |
| 505 |
but habit has won out. |
| 506 |
|
| 507 |
In the example the \verb`\eval` command is used \emph{within} a math |
| 508 |
environment (delimited by the dollar signs). |
| 509 |
\begin{itemize} |
| 510 |
\item When the \verb`\eval` command is used\emph{ within} a math environment, |
| 511 |
only the \emph{numerical result,} followed possibly by the \emph{variable=value |
| 512 |
list}, is displayed (within the given math environment). |
| 513 |
\end{itemize} |
| 514 |
For the \emph{variable=value list} see the $mc^{2}$ example earlier |
| 515 |
where values were assigned to $m$ and $c$ in a trailing optional |
| 516 |
argument; this is discussed more fully in §\ref{sec:evalVv-list}. |
| 517 |
As a simple example, I repeat the previous addition with variables |
| 518 |
$x$ and $y$: |
| 519 |
\begin{centred} |
| 520 |
\verb`$ \eval{ x+y }[x=1,y=1] $` $\Longrightarrow$ $ \eval{ x+y }[x=1,y=1]$ |
| 521 |
\end{centred} |
| 522 |
(If the package option \verb`comma` were being used, setting the |
| 523 |
comma as the decimal point, then the example would look like \verb`$ \eval{ x+y }[x=1;y=1] $` |
| 524 |
with a semicolon separating the variable assignments.) |
| 525 |
|
| 526 |
To my eye, display of the variable=value list in this example looks |
| 527 |
silly. It needs context, some prior commentary or statement of the |
| 528 |
formula like |
| 529 |
\begin{centred} |
| 530 |
\verb`$ x+y=\eval{ x+y }[x=1,y=1] $` $\Longrightarrow$ $ x+y=\eval{ x+y }[x=1,y=1] $ |
| 531 |
\end{centred} |
| 532 |
Otherwise display of the variable=value list can be suppressed, most |
| 533 |
simply by appending a star (asterisk) to the \verb`\eval` command; |
| 534 |
see §\ref{subsec:evalVvSuppresList} or later in this section. Environments |
| 535 |
may include the standard \LaTeX{} inline (\verb`$ $` or \verb`\( \)` |
| 536 |
or \verb`math`) environments, the \verb`displaymath`, \verb`\[ \]` |
| 537 |
and \verb`equation` environments, the \verb`eqnarray` environment, |
| 538 |
as well as the AMS environments which come into their own when multi-formula |
| 539 |
calculations are performed, or when long formulas with many variables |
| 540 |
are involved (\verb`multline`). Examples will recur throughout this |
| 541 |
document. |
| 542 |
|
| 543 |
\verb`\eval` is not limited to use within a math environment. As |
| 544 |
we have already seen with the $mc^{2}$ example, it can also wrap |
| 545 |
\emph{around} math delimiters: |
| 546 |
\begin{centred} |
| 547 |
\verb`\eval{$ x+y $}[x=1,y=1]` $\Longrightarrow$ \eval{$ x+y $}[x=1,y=1] |
| 548 |
\end{centred} |
| 549 |
When it does, the display that results is different, as you can see. |
| 550 |
The formula is \emph{automatically} included in the display; it does |
| 551 |
not need to be written in `by hand' as I did in the previous example. |
| 552 |
\begin{itemize} |
| 553 |
\item When the \verb`\eval` command is wrapped\emph{ around} a math environment, |
| 554 |
the result is displayed within that environment in the form, \emph{formula=numerical |
| 555 |
result}, followed possibly by the \emph{variable=value list}. |
| 556 |
\begin{itemize} |
| 557 |
\item If the formula is long or contains many variables then it may be desirable |
| 558 |
to split the display over two lines; see the \verb`multline*` example |
| 559 |
below, and §\ref{subsec:evalChanging-display-format}. |
| 560 |
\end{itemize} |
| 561 |
\item An alternative to explicitly wrapping \verb`\eval` around math delimiters |
| 562 |
is to use the \emph{settings} option, an optional argument before |
| 563 |
the main (mandatory) argument, and enter \verb`env=<environment>` |
| 564 |
there, for example like this: |
| 565 |
\end{itemize} |
| 566 |
\begin{centred} |
| 567 |
\verb`\eval[env=$]{x+y}[x=1,y=1]` $\Longrightarrow$ \eval[env=$]{x+y}[x=1,y=1] |
| 568 |
\end{centred} |
| 569 |
which reproduces the previous display. Doing this is more convenient |
| 570 |
when more `verbose' environment names than the brief \verb`$ $`, |
| 571 |
\verb`\( \)` or \verb`\[ \]` are used (although you can write, say, |
| 572 |
\verb`\eval{\begin{multline*}...\end{multline*}}` if so inclined). |
| 573 |
Here is an example of a \verb`multline*` environment being used to |
| 574 |
`tame' the display of a long unwieldy formula (the phantom is there |
| 575 |
so that the hanging $+$ sign spaces correctly): |
| 576 |
\begin{verbatim} |
| 577 |
\eval[env=multline*] |
| 578 |
{ 1+2+3+4+5+6+7+8+9+10+\phantom{0}\\ |
| 579 |
11+12+13+14+15+16+17+18+19 } |
| 580 |
\end{verbatim} |
| 581 |
$\Longrightarrow$ \eval[env=multline*] |
| 582 |
{ 1+2+3+4+5+6+7+8+9+10+\phantom{0} \\ |
| 583 |
11+12+13+14+15+16+17+18+19 } |
| 584 |
|
| 585 |
\noindent Note how the phantom and the new line command \verb`\\` |
| 586 |
are swallowed by \verb`\eval` without complaint. |
| 587 |
\begin{itemize} |
| 588 |
\item It is also possible to dispense with math delimiters entirely, neither |
| 589 |
wrapped within the \verb`\eval` command nor wrapped around it nor |
| 590 |
invoked with the \verb`env` setting, in which case \texttt{numerica} |
| 591 |
displays the \emph{numerical result} between \verb`$` delimiters. |
| 592 |
\end{itemize} |
| 593 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 594 |
\begin{shaded}% |
| 595 |
This is different from the behaviour in earlier versions of \texttt{numerica} |
| 596 |
when no math delimiters were involved. Then, \verb`\[ \]` delimiters |
| 597 |
were wrapped around the \emph{numerical result}, possibly followed |
| 598 |
by the \emph{variable=value} list. Now only the \emph{numerical result} |
| 599 |
is displayed and, since the absence of the variable=value list means |
| 600 |
no mathematical constructs like \verb`\frac`-tions are present, inline |
| 601 |
delimiters seem more appropriate than the previously used \verb`\[ \]`.\end{shaded}% |
| 602 |
\end{minipage} |
| 603 |
\begin{verbatim} |
| 604 |
\begin{quote} |
| 605 |
The result of subtracting $e^\pi$ from $\pi^e$ is |
| 606 |
\eval{ \pi^e-e^\pi } |
| 607 |
which is negative; hence $e^\pi>\pi^e$. |
| 608 |
\end{quote} |
| 609 |
\end{verbatim} |
| 610 |
is an example of \verb`\eval` used in the absence of delimiters and |
| 611 |
produces the result: |
| 612 |
\begin{quote} |
| 613 |
The result of subtracting $e^\pi$ from $\pi^e$ is |
| 614 |
\eval{ \pi^e-e^\pi} |
| 615 |
which is negative; hence $e^\pi>\pi^e$. |
| 616 |
\end{quote} |
| 617 |
Note that the minus sign displays correctly because of the \verb`$` |
| 618 |
delimiters automatically inserted by \texttt{numerica}. |
| 619 |
\begin{itemize} |
| 620 |
\item What is displayed can be pared to the minimum by appending an asterisk |
| 621 |
to the \verb`\eval` command. Then, only the \emph{numerical result} |
| 622 |
is displayed, with no math delimters added; if \verb`\eval*` is used |
| 623 |
within a math environment, the numerical result will be displayed |
| 624 |
accordingly, but otherwise the result will be displayed as text, a |
| 625 |
negative sign displaying as a hyphen. |
| 626 |
\end{itemize} |
| 627 |
Compare \verb`\eval*{ \pi^e-e^\pi }` $\Longrightarrow$ \eval*{ \pi^e-e^\pi } |
| 628 |
with the previous example. In the present example only the numerical |
| 629 |
result is displayed – as text, with a hyphen depicting the minus sign. |
| 630 |
It is up to you, the user, to provide the surrounding math environment |
| 631 |
if you want a proper minus. |
| 632 |
|
| 633 |
\subsubsection{Punctuation: the \texttt{p} setting} |
| 634 |
|
| 635 |
\label{subsec:introPunctuation}To complete a display you may wish |
| 636 |
to add a punctuation mark – usually a comma or full stop – after the |
| 637 |
displayed expression. For inline use punctuation is easy: add the |
| 638 |
punctuation mark after the \verb`\eval` command and its arguments: |
| 639 |
\verb`\eval{$ 2\pi $},` $\Longrightarrow$ \eval{$ 2\pi $}, and |
| 640 |
\verb`$\eval{ 1+x+y }[x=2,y=3]$.` $\Longrightarrow$ $\eval{ 1+x+y }[x=2,y=3]$. |
| 641 |
The mark appears in the right place. |
| 642 |
|
| 643 |
For displaystyle environments punctuation is not so straightforward. |
| 644 |
When \verb`\eval` is used \emph{within} a displaystyle environment, |
| 645 |
say between \verb`\[` \verb`\]` delimiters, it is easy to add a |
| 646 |
comma or full stop after the \verb`\eval` command and its arguments |
| 647 |
but before the closing delimiter, \verb`\[ x+1=\eval{ x+1 }[x=1],\]` |
| 648 |
and the punctuation mark will appear in the right place. But when |
| 649 |
the \verb`\eval` command wraps \emph{around} \verb`\[ \]` delimiters |
| 650 |
or the \verb`env=\[` option is used, a problem arises: a fullstop |
| 651 |
or comma after the \verb`\eval` command and its arguments – \verb`\eval{\[ 1+1 \]}.` |
| 652 |
– lies \emph{beyond} the closing delimiter and will slide off to the |
| 653 |
start of the next line, \emph{after} the displayed result. We want |
| 654 |
it to display as if it were the last element \emph{before} the closing |
| 655 |
delimiter. |
| 656 |
|
| 657 |
Explicitly putting it there, like \verb`\eval{\[ 1+1.\]}`, means |
| 658 |
the punctuation mark becomes part of the formula. Potentially \texttt{numerica} |
| 659 |
then needs to check not just for a fullstop but also other punctuation |
| 660 |
marks like comma, semicolon, perhaps even exclamation and question |
| 661 |
marks. All these marks have roles in mathematics or \texttt{l3fp} |
| 662 |
or \texttt{numerica}, and the program\texttt{ }responds to them accordingly. |
| 663 |
For instance a full stop is also the decimal point mark and is treated |
| 664 |
as such (giving the rather cryptic result \verb`\eval{$ . $}` $\Longrightarrow$ |
| 665 |
\eval{$ .$} since the solitary dot is interpreted as the number $0.0$). |
| 666 |
An exclamation mark is the factorial sign; \texttt{numerica} recognizes |
| 667 |
it as such: \verb`\eval{$ 4! $}` $\Longrightarrow$ \eval{$ 4!$}. |
| 668 |
A comma is used to separate the arguments of $n$-ary functions like |
| 669 |
\verb`\max` and \verb`\min`: \verb`$\eval{\min(\pi,e,\phi,\gamma)}$` |
| 670 |
$\Longrightarrow$ $\eval{\min(\pi,e,\phi,\gamma)}$. And as we will |
| 671 |
see below, a semicolon is used by \texttt{numerica} to separate expressions |
| 672 |
in a multi-formula calculation. Distinguishing the punctuation role |
| 673 |
from the mathematical role of these marks would only complicate the |
| 674 |
code and slow evaluation. |
| 675 |
|
| 676 |
Instead, \texttt{numerica} uses a key in the settings option to add |
| 677 |
punctuation. As already noted, the settings option is an optional |
| 678 |
argument preceding the main argument, already met in relation to the |
| 679 |
\verb`env`-ironment key. A second setting is the punctuation key |
| 680 |
\verb`p`. Indeed, simply entering \verb`p`, as here, |
| 681 |
\begin{verbatim} |
| 682 |
\eval[p]{\[ 1+x+y+z+xy+yz+zx+xyz \]}[x=2,y=3,z=4] |
| 683 |
\end{verbatim} |
| 684 |
$\Longrightarrow$ \eval[p]{\[ 1+x+y+z+xy+yz+zx+xyz \]}[x=2,y=3,z=4]puts |
| 685 |
a comma in the correct place, after the closing parenthesis of the |
| 686 |
variable=value list. If a full stop is wanted use \verb`p=.`: |
| 687 |
\begin{verbatim} |
| 688 |
\eval[env=\[,p=.]{ (1+x)(1+y)(1+z) }[x=2,y=3,z=4] |
| 689 |
\end{verbatim} |
| 690 |
$\Longrightarrow$ \eval[p=.,env=\[ ]{ (1+x)(1+y)(1+z) }[x=2,y=3,z=4]Again |
| 691 |
the mark appears in the right place. As you can see, the settings |
| 692 |
option is a comma-separated list of \emph{key=value} pairs.\emph{ |
| 693 |
}This remains true of the settings option even when the \verb`comma` |
| 694 |
package option is used, since the only numbers appearing in the settings |
| 695 |
are integers – ambiguity does not arise. That entering \verb`p` alone |
| 696 |
sufficed is because the punctuation key \verb`p` defaults to a comma. |
| 697 |
If you want some other mark – a semicolon or exclamation mark perhaps |
| 698 |
– equate \verb`p` to that mark in the optional argument. The default |
| 699 |
value for \verb`p` does not change if the \verb`comma` package option |
| 700 |
is used. |
| 701 |
|
| 702 |
\noindent{}% |
| 703 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 704 |
\begin{shaded}% |
| 705 |
The comma is chosen as the default not only because it is a commonly |
| 706 |
used mark at the end of equations but because the settings option |
| 707 |
is a comma-separated list. By making the default the comma, it suffices |
| 708 |
to write \verb`p` when you want a comma – rather than the more awkward |
| 709 |
\verb`p={,}` which would otherwise be required.\end{shaded}% |
| 710 |
\end{minipage} |
| 711 |
|
| 712 |
\subsection{Multi-formula calculations} |
| 713 |
|
| 714 |
\label{subsec:introMult-formula-calculations}It is possible to evaluate |
| 715 |
more than one expression at a time in the one \verb`\eval` command |
| 716 |
by means of a further setting \verb`ff`, or \verb`ff=<char>`. The |
| 717 |
default separator of one formula from the next is the same as that |
| 718 |
used in the variable=value list. If the decimal point is a dot, then |
| 719 |
the default separator is a comma; if the decimal point is a comma |
| 720 |
(with the \verb`comma` package option) then the default separator |
| 721 |
is a semicolon. In both cases this will generally be fine except when |
| 722 |
$n$-ary functions are involved since their arguments are delimited |
| 723 |
in the same way. Either one can wrap the arguments of these functions |
| 724 |
in braces or, better, choose a different separator by means of the |
| 725 |
setting \verb`ff=<char>`. I give an example shortly below; also see |
| 726 |
§\ref{subsec:settingsMulti-formula-separator}. For this document |
| 727 |
the decimal point is a dot and the comma generally suffices. |
| 728 |
|
| 729 |
Suppose we want the values of the main trigonometric functions at, |
| 730 |
say, $\pi/6$. In the example, I have entered the functions separated |
| 731 |
by commas, assigned the value $\pi/6$ to the variable $x$ in the |
| 732 |
trailing optional argument and concluded the display with a full stop |
| 733 |
by means of the \verb`p=.` setting. The point to note is the \verb`ff` |
| 734 |
in the settings option, signalling a multi-formula calculation: |
| 735 |
\begin{verbatim} |
| 736 |
\eval[ff,p=.]{\[ \sin x, \cos x, \tan x \]}[x=\pi/6] |
| 737 |
\end{verbatim} |
| 738 |
$\Longrightarrow$ \eval[ff,p=.]{ \[ \sin x, \cos x, \tan x \] }[x=\pi/6]To |
| 739 |
understand these values we might add |
| 740 |
\begin{centred} |
| 741 |
\verb`\eval[ff,p=.]{\[ \surd3/2, 1/\surd3 \]}` $\Longrightarrow$ |
| 742 |
\eval[ff,p=.]{ \[\surd3/2, 1/\surd3 \]} |
| 743 |
\end{centred} |
| 744 |
The displays in both instances follow the default format for a multi-formula |
| 745 |
calculation in the \verb`equation*` (\verb`\[`) environment. |
| 746 |
|
| 747 |
There are irritants: the failure of the equals signs to line up, the |
| 748 |
repetition of the variable=value list, the different numbers of digits |
| 749 |
displayed in the answers and, if you are a `punctuator', you might |
| 750 |
like commas to terminate the intermediate rows. For back-of-envelope |
| 751 |
calculations, who cares? But for inclusion in more formal documents |
| 752 |
such things matter. All can be remedied: see §\ref{subsec:evalPadding-with-zeros} |
| 753 |
(and below) about padding numbers with zeros to a given number of |
| 754 |
decimal places; see §\ref{subsec:settingsEnvironmentSettings} about |
| 755 |
use of AMS environments to guarantee alignment; see §\ref{subsec:settingsEnvironments-=00005C=00007D} |
| 756 |
about suppressing repetition of the variable=value list. Punctuating |
| 757 |
the intermediate rows I discuss next. |
| 758 |
|
| 759 |
\subsubsection{Punctuation: the \texttt{pp} } |
| 760 |
|
| 761 |
\label{subsec:intoMultiFormulaPunctuation}Like the \verb`p` setting, |
| 762 |
there is a \verb`pp` setting also entered in the settings argument |
| 763 |
of the \verb`\eval` command that enables the insertion of punctuation |
| 764 |
at the end of intermediate results in a multi-formula calculation; |
| 765 |
the \verb`p` setting still determines the terminating punctuation |
| 766 |
mark. Like \verb`p`, \verb`pp` defaults to a comma, which means |
| 767 |
that you need enter only \verb`pp` to insert commas. This remains |
| 768 |
true if the \verb`comma` package option is used. For any other mark |
| 769 |
you need to equate \verb`pp` to that mark – e.g. \verb`pp=;`. Thus, |
| 770 |
repeating the first of the examples above, I've added \verb`pp` to |
| 771 |
the settings option, and also added a star (asterisk) in a second |
| 772 |
trailing argument on the right. This triggers padding the numerical |
| 773 |
result with zeros, should it not display the default six decimal places |
| 774 |
– as happens with both $\sin x$ and $\tan x$ (because they round |
| 775 |
to five or fewer figures). |
| 776 |
\begin{verbatim} |
| 777 |
\eval[ff,pp,p=.]{\[ \sin x, \cos x, \tan x \]}[x=\pi/6][*] |
| 778 |
\end{verbatim} |
| 779 |
$\Longrightarrow$ \eval[ff,pp,p=.]{\[ \sin x, \cos x, \tan x \]}[x=\pi/6][*] |
| 780 |
|
| 781 |
\noindent The display is improved: commas terminate intermediate rows, |
| 782 |
a full stop is at the end, and by padding with zeros, all three results |
| 783 |
display six decimal places and now align vertically. |
| 784 |
|
| 785 |
\subsubsection{Multi-formula separator: the \texttt{ff} setting} |
| 786 |
|
| 787 |
\noindent\label{subsec:introMultiFormulaSeparator}That the last |
| 788 |
example displays as desired depends on all three results being positive. |
| 789 |
If $x=5\pi/6$, $\cos x$ and $\tan x$ will be negative and minus |
| 790 |
signs will destroy the alignment. The secret then is to use an \verb`alignat*` |
| 791 |
environment. Also, just to show how it's done, I've changed the multi-formula |
| 792 |
separator with the setting \verb`ff=|`. (Even if a formula contained |
| 793 |
an absolute value it should not contain the \verb`|` character but |
| 794 |
rather \verb`\abs` or \verb`\lvert`, \verb`\rvert`; see §\ref{sec:calcAbsValueEtc}.) |
| 795 |
\begin{verbatim} |
| 796 |
\eval[pp,p=.,env=alignat*,ff=|] |
| 797 |
{\[ \sin x | \cos x | \tan x \]}[x=5\pi/6][*] |
| 798 |
\end{verbatim} |
| 799 |
$\Longrightarrow$ \eval[pp,p=.,env=alignat*,ff=|] |
| 800 |
{\[ \sin x | \cos x | \tan x \]}[x=5\pi/6][*] |
| 801 |
|
| 802 |
\noindent Padding wit zeros and the \verb`alignat*` environment have |
| 803 |
ensured alignment of the numerical results. |
| 804 |
|
| 805 |
Multi-formula calculations can also be performed in an inline context. |
| 806 |
In the following example, the \verb`p` setting has been dispensed |
| 807 |
with since a full stop can be inserted at the end `by hand' without |
| 808 |
problem. Again, just to show how, I have used the \verb`ff=<char>` |
| 809 |
setting (although \verb`&` is a confusing character to use for anyone |
| 810 |
familiar with \LaTeX ): |
| 811 |
\begin{centred} |
| 812 |
\verb`$\eval[pp,ff=&]{ \pi & \pi/2 & 1/\pi & \surd\pi }$` $\Longrightarrow$ |
| 813 |
$\vsp\eval[pp,ff=&]{ \pi & \pi/2 & 1/\pi & \surd\pi }$. |
| 814 |
\end{centred} |
| 815 |
By default, a quad of space is inserted between results of a multi-formula |
| 816 |
calculation in an inline (\verb`$ $`, \verb`\( \)` or \verb`math`) |
| 817 |
context, as evident here. This can be changed by means of the \verb`sep` |
| 818 |
(for separator) setting (§\ref{subsec:settingsEnvironments-sep}). |
| 819 |
For more on environments and their tweaks, see §\ref{subsec:settingsEnvironmentSettings}. |
| 820 |
|
| 821 |
\subsection{Examples of use} |
| 822 |
|
| 823 |
To give a sense of how \texttt{numerica} can be used, I include some |
| 824 |
examples of actual use of the program. (The \texttt{numerica-plus} |
| 825 |
and \texttt{numerica-tables} packages contain others.) |
| 826 |
|
| 827 |
\subsubsection{Checking} |
| 828 |
|
| 829 |
Occasionally, just to reassure myself that age hasn't completely rotted |
| 830 |
my brain I like to tackle short mathematical problems I come across |
| 831 |
on the internet. One that caught my attention was to simplify $\sqrt{220-30\sqrt{35}}$. |
| 832 |
After some bumbling and fumbling, I let |
| 833 |
\[ |
| 834 |
x=\sqrt{220-30\sqrt{35}},\qquad y=\sqrt{220+30\sqrt{35}}, |
| 835 |
\] |
| 836 |
(which seems an obvious thing to do) so that |
| 837 |
\[ |
| 838 |
xy=10\sqrt{484-315}=10\sqrt{169}=10\sqrt{13^{2}}=130. |
| 839 |
\] |
| 840 |
Since $x^{2}+y^{2}=440$ it was easy to form both $(x+y)^{2}$ and |
| 841 |
$(x-y)^{2}$, and by separating the resulting numbers into their prime |
| 842 |
factors, to find $y+x$ and $y-x$ and work out that $x=5\sqrt{7}-3\sqrt{5}$. |
| 843 |
Was I right, or had I made a mistake? Since |
| 844 |
\begin{verbatim} |
| 845 |
\eval[p,pp,ff]{\[\sqrt{220-30\sqrt{35}}, |
| 846 |
5\sqrt{7}-3\sqrt{5}\]} |
| 847 |
\end{verbatim} |
| 848 |
$\Longrightarrow$ \eval[p=.,pp,ff]{\[ \sqrt{220-30\sqrt{35}}, 5\sqrt{7}-3\sqrt{5} \]} |
| 849 |
|
| 850 |
\noindent the simplification was correct. Indeed $y=5\sqrt{7}+3\sqrt{5}$: |
| 851 |
\begin{verbatim} |
| 852 |
\eval[p=.,pp,ff]{\[\sqrt{220+30\sqrt{35}}, |
| 853 |
5\sqrt{7}+3\sqrt{5}\]} |
| 854 |
\end{verbatim} |
| 855 |
$\Longrightarrow$ \eval[p=.,pp,ff]{\[ \sqrt{220+30\sqrt{35}}, 5\sqrt{7}+3\sqrt{5} \]} |
| 856 |
|
| 857 |
\noindent As a final flourish, |
| 858 |
\begin{verbatim} |
| 859 |
\eval{$xy$}[x=5\sqrt{7}-3\sqrt{5}, |
| 860 |
y=5\sqrt{7}+3\sqrt{5}] |
| 861 |
\end{verbatim} |
| 862 |
$\Longrightarrow$ \eval{$ xy $} |
| 863 |
[x=5\sqrt{7}-3\sqrt{5}, |
| 864 |
y=5\sqrt{7}+3\sqrt{5}]. |
| 865 |
|
| 866 |
\subsubsection{Exploring } |
| 867 |
|
| 868 |
\label{subsec:introExploring}When working on \texttt{numerica}'s |
| 869 |
predecessor package, I constantly tested it against known results |
| 870 |
to check for coding errors. One test was to ensure that |
| 871 |
\[ |
| 872 |
\left(1+\frac{1}{n}\right)^{n} |
| 873 |
\] |
| 874 |
did indeed converge to the number $e$ as $n$ increased.\texttt{ }Let's |
| 875 |
do that here. Try first $n=10$: |
| 876 |
\begin{center} |
| 877 |
\verb`\eval{$ e-(1+1/n)^n $}[n=10][x]` $\Longrightarrow$ \eval{$ e-(1+1/n)^n $}[n=10][x]. |
| 878 |
\par\end{center} |
| 879 |
|
| 880 |
\noindent (The default number of decimal places displayed is $6$.) |
| 881 |
The difference between $e$ and $(1+1/n)^{n}$ is about an eighth |
| 882 |
($0.125$) when $n=10$, which is encouraging but hardly decisive. |
| 883 |
The obvious thing to do is increase the value of $n$. I'll use an |
| 884 |
\verb`align*` environment to `prettify' the presentation of the |
| 885 |
results. Although looking like a solid block of typing, most of the |
| 886 |
following was done by copy-and-paste; I only had to change the exponent |
| 887 |
on the \verb`10`: |
| 888 |
\begin{verbatim} |
| 889 |
\begin{align*} |
| 890 |
e-(1+1/n)^{n} &= \eval{e-(1+1/n)^n}[n=1\times10^5][*x],\\ |
| 891 |
e-(1+1/n)^{n} &= \eval{e-(1+1/n)^n}[n=1\times10^6][*x],\\ |
| 892 |
e-(1+1/n)^{n} &= \eval{e-(1+1/n)^n}[n=1\times10^7][*x],\\ |
| 893 |
e-(1+1/n)^{n} &= \eval{e-(1+1/n)^n}[n=1\times10^8][*x]. |
| 894 |
\end{align*} |
| 895 |
\end{verbatim} |
| 896 |
This gave the result |
| 897 |
\begin{align*} |
| 898 |
e-(1+1/n)^{n} & =\eval{e-(1+1/n)^{n}}[n=1\times10^{5}][x],\\ |
| 899 |
e-(1+1/n)^{n} & =\eval{e-(1+1/n)^{n}}[n=1\times10^{6}][*x],\\ |
| 900 |
e-(1+1/n)^{n} & =\eval{e-(1+1/n)^{n}}[n=1\times10^{7}][x],\\ |
| 901 |
e-(1+1/n)^{n} & =\eval{e-(1+1/n)^{n}}[n=1\times10^{8}][x]. |
| 902 |
\end{align*} |
| 903 |
Clearly $(1+1/n)^{n}$ converges to $e$, the difference between them |
| 904 |
being of order $1/n$, but that is not what catches the eye. There |
| 905 |
is an unanticipated regularity here. 1.35914? Double the number: \verb`\eval{2\times 1.35914}[5]` |
| 906 |
$\Longrightarrow$ \eval{2\times 1.35914}[5] which looked like $e$ |
| 907 |
to me and suggested a relationship, namely, |
| 908 |
\[ |
| 909 |
\lim_{n\to\infty}n\left(e-\left(1+\frac{1}{n}\right)^{n}\right)=\tfrac{1}{2}e. |
| 910 |
\] |
| 911 |
|
| 912 |
\noindent I hadn't seen this before. Is it true? Since |
| 913 |
\[ |
| 914 |
\ln\left(1+\frac{1}{n}\right)^{n}=n\ln\left(1+\frac{1}{n}\right), |
| 915 |
\] |
| 916 |
it followed from the familiar expansion of the logarithm that |
| 917 |
\begin{align*} |
| 918 |
\ln\left(1+\frac{1}{n}\right)^{n} & =n\left(\frac{1}{n}-\frac{1}{2}\frac{1}{n^{2}}+\frac{1}{3}\frac{1}{n^{3}}-\ldots\right)\\ |
| 919 |
& =1-\frac{1}{2n}\left(1-\frac{2}{3}\frac{1}{n}+\frac{2}{4}\frac{1}{n^{2}}-\right). |
| 920 |
\end{align*} |
| 921 |
Write $E_{n}$ for the bracketed series on the right. $E_{n}$ is |
| 922 |
an alternating series and the magnitudes of the terms of the series |
| 923 |
tend to $0$ monotonically. Hence $1>E_{n}>1-2/3n$ and $E_{n}\to1$ |
| 924 |
as $n\to\infty$. Now exponentiate: |
| 925 |
\[ |
| 926 |
\left(1+\frac{1}{n}\right)^{n}=e\times e^{-E_{n}/2n}, |
| 927 |
\] |
| 928 |
so that |
| 929 |
\[ |
| 930 |
n\left(e-\left(1+\frac{1}{n}\right)^{n}\right)=ne\Big(1-e^{-E_{n}/2n}\Bigr). |
| 931 |
\] |
| 932 |
The proposed limit, new to me, now followed from the standard inequality |
| 933 |
(see \emph{HMF }2.3.32), $x/(1+x)<1-e^{-x}<x$ when $x>-1$. |
| 934 |
|
| 935 |
\subsubsection{Reassuring} |
| 936 |
|
| 937 |
\label{subsec:introReassurance}In the course of some hobbyist investigations |
| 938 |
in plane hyperbolic geometry I derived the formula |
| 939 |
\[ |
| 940 |
\Phi_{1}(m,n)=\cos\tfrac{m}{n}\pi-(1-4\sin^{2}\tfrac{m}{3n}\pi)\frac{\sin\tfrac{1}{n}\pi\sin\tfrac{m-1}{n}\pi}{2\sin^{2}\tfrac{m}{3n}\pi}, |
| 941 |
\] |
| 942 |
for $m=2,3,\ldots$ and integral $n\ge2m+1$. A key concern was: when |
| 943 |
is $\Phi_{1}$ positive? $\Phi_{1}$ itself was opaque; could I work |
| 944 |
it into an equivalent but more enlightening form? After an embarrassingly |
| 945 |
laborious struggle, I derived the expression |
| 946 |
\[ |
| 947 |
\Phi_{2}(m,n)=\left(\frac{1-4\sin^{2}\tfrac{m}{3n}\pi}{2\sin^{2}\tfrac{m}{3n}\pi}\right)\sin\tfrac{2m-3}{3n}\pi\sin\tfrac{m-3}{3n}\pi, |
| 948 |
\] |
| 949 |
in which the conditions for positivity were now clear: with $n\ge2m+1$, |
| 950 |
so that $m\pi/3n<\pi/6$, the first parenthesized factor is always |
| 951 |
positive; the second is positive for $m\ge2$, and the third is positive |
| 952 |
for $m\ge4$. All well and good, but given the struggle to derive |
| 953 |
$\Phi_{2}$, was I confident that $\Phi_{1}$ and $\Phi_{2}$ really\emph{ |
| 954 |
}are equal? It felt all too likely that I had made a mistake. |
| 955 |
|
| 956 |
The simplest way to check was to see if the two expressions gave the |
| 957 |
same numerical answers for a number of $m,\thinspace n$ values. First |
| 958 |
I checked for $m=2,n=5$: I wrote \verb`\eval{\[ \]}[m=2,n=5]` twice |
| 959 |
and between the delimiters pasted the already composed expressions |
| 960 |
for $\Phi_{1}$ and $\Phi_{2}$, namely: |
| 961 |
\begin{verbatim} |
| 962 |
\eval{\[ |
| 963 |
\cos\tfrac{m}{n}\pi-(1-4\sin^{2}\tfrac{m}{3n}\pi) |
| 964 |
\frac{\sin\tfrac{1}{n}\pi\sin\tfrac{m-1}{n}\pi} |
| 965 |
{2\sin^{2}\tfrac{m}{3n}\pi} |
| 966 |
\]}[m=2,n=5] |
| 967 |
\eval{\[ \left( |
| 968 |
\frac{1-4\sin^{2}\tfrac{m}{3n}\pi} |
| 969 |
{2\sin^{2}\tfrac{m}{3n}\pi} |
| 970 |
\right) |
| 971 |
\sin\tfrac{2m-3}{3n}\pi\sin\tfrac{m-3}{3n}\pi |
| 972 |
\]}[m=2,n=5] |
| 973 |
\end{verbatim} |
| 974 |
I have added some formatting – indenting, line breaks – to make the |
| 975 |
formulas more readable but otherwise left them unaltered. The \verb`\eval` |
| 976 |
command can be used for even quite complicated expressions without |
| 977 |
needing to tinker with their \LaTeX{} form, but you may wish – as here |
| 978 |
– to adjust white space to clarify their component parts. Running |
| 979 |
\texttt{pdflatex} on these expressions, the results were |
| 980 |
|
| 981 |
\eval{\[ |
| 982 |
\cos\tfrac{m}{n}\pi-(1-4\sin^{2}\tfrac{m}{3n}\pi) |
| 983 |
\frac{\sin\tfrac{1}{n}\pi\sin\tfrac{m-1}{n}\pi} |
| 984 |
{2\sin^{2}\tfrac{m}{3n}\pi} |
| 985 |
\]}[m=2,n=5] |
| 986 |
|
| 987 |
\eval{\[ |
| 988 |
\left( |
| 989 |
\frac{1-4\sin^{2}\tfrac{m}{3n}\pi} |
| 990 |
{2\sin^{2}\tfrac{m}{3n}\pi} |
| 991 |
\right) |
| 992 |
\sin\tfrac{2m-3}{3n}\pi\sin\tfrac{m-3}{3n}\pi |
| 993 |
\]}[m=2,n=5] |
| 994 |
|
| 995 |
\noindent which was reassuring. (The result is negative since $m-3<0$.) |
| 996 |
|
| 997 |
I could have avoided the double writing of \verb`\eval` and \verb`[m=2,n=5]` |
| 998 |
by putting a comma between the expressions and performing a multi-formula |
| 999 |
calculation. This time I've checked equality for \verb`m=5` and \verb`n=13`, |
| 1000 |
which should give a positive result, and I've taken the opportunity |
| 1001 |
to \verb`align*` the results with the \verb`env` setting: |
| 1002 |
\begin{verbatim} |
| 1003 |
\eval[p=.,pp,env=align*,ff] |
| 1004 |
{ \cos\tfrac{m}{n}\pi-(1-4\sin^{2}\tfrac{m}{3n}\pi) |
| 1005 |
\frac{\sin\tfrac{1}{n}\pi\sin\tfrac{m-1}{n}\pi} |
| 1006 |
{2\sin^{2}\tfrac{m}{3n}\pi} |
| 1007 |
, \left( |
| 1008 |
\frac{1-4\sin^{2}\tfrac{m}{3n}\pi} |
| 1009 |
{2\sin^{2}\tfrac{m}{3n}\pi} |
| 1010 |
\right) |
| 1011 |
\sin\tfrac{2m-3}{3n}\pi\sin\tfrac{m-3}{3n}\pi |
| 1012 |
}[m=5,n=13] |
| 1013 |
\end{verbatim} |
| 1014 |
which evaluates to |
| 1015 |
|
| 1016 |
\eval[p=.,pp,env=align*,ff]{ |
| 1017 |
\cos\tfrac{m}{n}\pi-(1-4\sin^{2}\tfrac{m}{3n}\pi) |
| 1018 |
\frac{\sin\tfrac{1}{n}\pi\sin\tfrac{m-1}{n}\pi} |
| 1019 |
{2\sin^{2}\tfrac{m}{3n}\pi} |
| 1020 |
, |
| 1021 |
\left( |
| 1022 |
\frac{1-4\sin^{2}\tfrac{m}{3n}\pi} |
| 1023 |
{2\sin^{2}\tfrac{m}{3n}\pi} |
| 1024 |
\right) |
| 1025 |
\sin\tfrac{2m-3}{3n}\pi\sin\tfrac{m-3}{3n}\pi |
| 1026 |
}[m=5,n=13] |
| 1027 |
|
| 1028 |
\noindent Thus reassured that there was \emph{not }an error in my |
| 1029 |
laborious derivation of $\Phi_{2}$ from $\Phi_{1}$, it was not difficult |
| 1030 |
to work back from $\Phi_{2}$ to $\Phi_{1}$ then reverse the argument |
| 1031 |
to find a straightforward derivation. |
| 1032 |
|
| 1033 |
\chapter{\texttt{\textbackslash nmcEvaluate} (\texttt{\textbackslash eval)}} |
| 1034 |
|
| 1035 |
\label{chap:evalEvaluate}The main calculational command in \texttt{numerica} |
| 1036 |
is \verb`\nmcEvaluate`. Because this would be tiresome to write too |
| 1037 |
frequently,\texttt{ }particularly for back-of-envelope calculations, |
| 1038 |
there is an equivalent short-name form, \verb`\eval`, used almost |
| 1039 |
exclusively in this document. But wherever you see \verb`\eval` you |
| 1040 |
can substitute \verb`\nmcEvaluate` and obtain the same result. \verb`\eval` |
| 1041 |
is defined using \verb`\ProvideDocumentCommand` from the \texttt{xparse} |
| 1042 |
package. Hence if already defined in some other package already loaded, |
| 1043 |
it will not be redefined by \texttt{numerica}. It will retain its |
| 1044 |
meaning in the other package. Its consequent absence from \texttt{numerica} |
| 1045 |
may be an irritant, but only that. \verb`\nmcEvaluate` is unlikely |
| 1046 |
to be defined elsewhere and should still be available. |
| 1047 |
|
| 1048 |
\section{Syntax of \texttt{\textbackslash nmcEvaluate (\textbackslash eval)}} |
| 1049 |
|
| 1050 |
\verb`\nmcEvaluate` (or \verb`\eval`) takes five arguments of which |
| 1051 |
only the third is mandatory. All others are optional. If all are deployed |
| 1052 |
the command looks like |
| 1053 |
\begin{centred} |
| 1054 |
\noindent\verb`\nmcEvaluate*[settings]{expr.}[vv-list][num. format]` |
| 1055 |
\end{centred} |
| 1056 |
I discuss the various arguments in the referenced sections. |
| 1057 |
\begin{enumerate} |
| 1058 |
\item \verb`*` optional \emph{number-only} switch; if present ensures display |
| 1059 |
of only the numerical result, as text with no formatting; see §\ref{subsec:evalVvSuppresList}; |
| 1060 |
\item \verb`[settings]` optional comma-list of \emph{key=value settings} |
| 1061 |
of the calculational environment for this particular calculation; |
| 1062 |
see §\ref{chap:settingsSettings}; |
| 1063 |
\item \verb`{expr.}` mandatory main argument, the mathematical \emph{expression} |
| 1064 |
in \LaTeX{} form that is to be evaluated, or a list of such expressions; |
| 1065 |
see §\ref{subsec:evalExpressions}; |
| 1066 |
\item \verb`[vv-list]` optional list of \emph{variable=value }entries; |
| 1067 |
see §\ref{sec:evalVv-list}; |
| 1068 |
\item \verb`[num. format]` optional \emph{number-format} specification |
| 1069 |
for the numerical result (rounding, padding with zeros, scientific |
| 1070 |
notation, boolean or fraction-form output); see~§\ref{sec:evalRoundingEtc}. |
| 1071 |
\end{enumerate} |
| 1072 |
Note that arguments 4 and 5 are both square-bracket delimited optional |
| 1073 |
arguments. Should only one such argument be used, \texttt{numerica} |
| 1074 |
determines which is intended by looking for an equals sign within |
| 1075 |
the argument. Its presence indicates the argument is the vv-list; |
| 1076 |
its absence indicates the argument is the number-format specification. |
| 1077 |
|
| 1078 |
The vv-list and number-format specification are trailing optional |
| 1079 |
arguments but do not need to be hard against their preceding arguments; |
| 1080 |
intervening spaces are allowed. This means there is a possibility |
| 1081 |
that should the \verb`\eval` command be followed by a square-bracketed |
| 1082 |
mathematical expression that expression might be interpreted as a |
| 1083 |
trailing argument. Experience using \texttt{numerica} suggests that |
| 1084 |
this will be a (very) rare occurrence and is easily prevented by inserting |
| 1085 |
an intervening empty brace pair (\verb`{}`). By allowing spaces between |
| 1086 |
the arguments complicated expressions and large vv-lists can be formatted, |
| 1087 |
in the interests of clarity, with new lines and white space without |
| 1088 |
requiring the insertion of line-ending comment characters (\verb`%`). |
| 1089 |
|
| 1090 |
Recommended practice is to minimise the number of optional arguments |
| 1091 |
used in \LaTeX{} commands by consolidating them into a single \emph{key=value} |
| 1092 |
list. Although \texttt{numerica} uses such an argument (the settings |
| 1093 |
optional argument), the vv-list does not fit naturally into that scheme. |
| 1094 |
And practice suggests that separating out the elements of the number-format |
| 1095 |
specification of the result and placing them in a trailing argument |
| 1096 |
is both convenient and intuitive for the kind of back-of-envelope |
| 1097 |
calculations envisaged for \texttt{numerica}. |
| 1098 |
|
| 1099 |
\subsection{Expressions} |
| 1100 |
|
| 1101 |
\label{subsec:evalExpressions}What kind of formula or expression |
| 1102 |
can be `digested' by \verb`\nmcEvaluate`? As seen above (§\ref{subsec:introBasicProcedure}), |
| 1103 |
a formula can be complicated, including components like $2\sin^{2}\tfrac{m}{3n}\pi$ |
| 1104 |
or |
| 1105 |
\[ |
| 1106 |
\left(\frac{1-4\sin^{2}\tfrac{m}{3n}\pi}{2\sin^{2}\tfrac{m}{3n}\pi}\right), |
| 1107 |
\] |
| 1108 |
but the underlying aim is always: if the meaning of a formula in the |
| 1109 |
\texttt{pdf} is clear to a human reader, it ought to be clear to \texttt{numerica}. |
| 1110 |
In a perhaps surprising number of cases this aim can be met. Mathematicians |
| 1111 |
understand an expression like $\sin2\pi x$ to mean the sine of the |
| 1112 |
triple product $2\pi x$; so does \texttt{numerica}. Mathematicians |
| 1113 |
casually use and understand logically wrong but customary notations |
| 1114 |
like $\sin^{2}x$, the square of the sine of $x$; \texttt{numerica} |
| 1115 |
digests this without fuss. Mathematicians use a wide variety of formatting |
| 1116 |
commands to clarify their intent: \verb`\left` and \verb`\right`, |
| 1117 |
\verb`\phantom`-s, spaces and new lines (\verb`\quad`, \verb`\\`), |
| 1118 |
structural commands like \verb`\mathstrut`, or environments like |
| 1119 |
\verb`align` or \verb`multline`; all are grist to \texttt{numerica}'s |
| 1120 |
mill. |
| 1121 |
|
| 1122 |
\subsubsection{Multi-formula expressions} |
| 1123 |
|
| 1124 |
\label{subsec:evalMulti-formula-expressions}From version 3.0.0 of |
| 1125 |
\texttt{numerica} the main (and only mandatory) argument of the \verb`\eval` |
| 1126 |
command may contain more than one formula to be evaluated. `Expression' |
| 1127 |
can now mean a (generally short) list of formulas. The default punctuation |
| 1128 |
mark separating one formula from the next in the list is the same |
| 1129 |
as that used in the vv-list – a comma if the decimal point is a dot, |
| 1130 |
a semicolon if the decimal point is a comma. The only potential conflict |
| 1131 |
is if a formula contains an $n$-ary function (\verb`\max` or \verb`\min` |
| 1132 |
or \verb`\gcd`), since their arguments are separated by the same |
| 1133 |
separators in the two cases. There are two responses. One is to wrap |
| 1134 |
the $n$-ary function in braces. The other is to specify a different |
| 1135 |
multi-formula delimiter in the settings option. This is done by entering |
| 1136 |
\verb`ff=<char>` there (see §\ref{subsec:settingsMulti-formula-separator}), |
| 1137 |
where \verb`<char>` is some suitably `neutral' character not otherwise |
| 1138 |
present in any of the formulas to be evaluated – perhaps \verb`@`, |
| 1139 |
or \verb`|`. |
| 1140 |
|
| 1141 |
Examples of multi-formula expressions being evaluated within the one |
| 1142 |
\verb`\eval` command were seen earlier in the Introduction, especially |
| 1143 |
at §\ref{subsec:introMult-formula-calculations}, and §\ref{subsec:introReassurance}. |
| 1144 |
A multi-formula calculation is a natural way to check identities – |
| 1145 |
see for example the test of $\sinh3x=3\sinh x+4\sinh^{3}x$ in §\ref{subsec:calcSquaring-etc-unary}. |
| 1146 |
Numerous other examples occur throughout this document. |
| 1147 |
|
| 1148 |
\subsubsection{\protect\LaTeX{} braces and mathematical arguments} |
| 1149 |
|
| 1150 |
\label{subsec:evalBraced-groups}There are mathematical braces, \verb`\{ \}`, |
| 1151 |
which display in the \texttt{pdf} and are used to delimit (generally |
| 1152 |
larger) parts of mathematical expressions, and there are \LaTeX{} braces, |
| 1153 |
\verb`{ }`, which do not display in the \texttt{pdf} and are used |
| 1154 |
to delimit \LaTeX{} arguments or groupings. This discussion is about |
| 1155 |
\LaTeX{} braces. |
| 1156 |
|
| 1157 |
Generally, the \LaTeX{} braces \verb`\eval` encounters should be `announced' |
| 1158 |
by a preceding \LaTeX{} command. Thus the braced argument in \verb`\sqrt{x^2+1}`, |
| 1159 |
displaying in a math environment as $\sqrt{x^{2}+1}$, is `announced' |
| 1160 |
by the square root command. Similarly, \verb`\frac` and \verb`\binom` |
| 1161 |
each announce two braced arguments. The superscripting \verb`^` or |
| 1162 |
subscripting \verb`_` also announce a braced argument (in general). |
| 1163 |
In these cases \verb`\eval` knows what to do with the braced argument |
| 1164 |
because it is prepared by the preceding command. |
| 1165 |
|
| 1166 |
Although there is no \LaTeX{} requirement for them, braced arguments |
| 1167 |
can also be used after unary functions like \verb`\sin` or \verb`\ln` |
| 1168 |
or \verb`\tanh`. Given the presence of the unary function, \verb`\eval` |
| 1169 |
knows what to do with an immediately following braced argument and |
| 1170 |
will happily digest it – it has been announced by the unary function. |
| 1171 |
Indeed, from version 3.0.0 of \texttt{numerica} this is the recommended |
| 1172 |
way of handling (for instance) the more complicated arguments that |
| 1173 |
frequently occur following \verb`\sin` and \verb`\cos` in the study |
| 1174 |
of Fourier series; see §\ref{subsec:calcComplicated-arguments}. |
| 1175 |
|
| 1176 |
Even \emph{without} braces, \verb`\eval` will happily digest an argument |
| 1177 |
to a unary function that is the product of a number, a variable, a |
| 1178 |
constant, a \verb`\tfrac` (or an \verb`\sfrac` if \texttt{xfrac} |
| 1179 |
is loaded) or some subset thereof: |
| 1180 |
\begin{centred} |
| 1181 |
\verb`\eval{$ \cos \tfrac1{12}2n\pi $}[n=2]` $\Longrightarrow$ \eval{$ \cos \tfrac1{12}2n\pi $}[n=2]. |
| 1182 |
\end{centred} |
| 1183 |
\LaTeX{} braces are for those situations where the reader sees the |
| 1184 |
function's argument extending \emph{beyond} the point where a programming |
| 1185 |
rule would end the argument. For example, a reader knows that the |
| 1186 |
argument of the sine in $\sin\tfrac{1}{2}(A+B)$ does not end with |
| 1187 |
the $\tfrac{1}{2}$, nor with the right parenthesis in $\sin(n+\tfrac{1}{2})\pi$ |
| 1188 |
nor with the first factor in $\sin(n+\tfrac{1}{2})(x-t)$. It is for |
| 1189 |
situations like this that em-bracing the argument is recommended. |
| 1190 |
It makes no difference to the visual appearance, hence does not interfere |
| 1191 |
with the reader's comprehension, but informs \texttt{numerica} of |
| 1192 |
exactly where the argument ends. |
| 1193 |
|
| 1194 |
Because they are invisible in the \texttt{pdf}, \LaTeX{} braces should |
| 1195 |
never be used to shorten what the reader sees as the argument of a |
| 1196 |
function. \verb`\eval` assumes that the braced part is the \emph{whole} |
| 1197 |
argument but the reader doesn't read that. For example, presented |
| 1198 |
with \verb`\sin{2n}\pi`, \verb`\eval` assumes the sine's argument |
| 1199 |
is $2n$ and does not extend to \verb`\pi`. This is not what a human |
| 1200 |
reads in the \texttt{pdf}. The compiled expression, $\sin2n\pi$, |
| 1201 |
is read as `the sine of $2n\pi$'. If the intention really is to |
| 1202 |
multiply $\pi$ by $\sin2n$ then the reader needs to \emph{see }that |
| 1203 |
this is so: $(\sin2n)\pi$ perhaps or $\sin2n\times\pi$ or, best, |
| 1204 |
$\pi\sin2n$, but \emph{not} by means of \LaTeX{} braces which leave |
| 1205 |
no visual trace in the \texttt{pdf}. |
| 1206 |
|
| 1207 |
\subsubsection{Unannounced braces} |
| 1208 |
|
| 1209 |
\emph{Unannounced} braced expressions should be used with care. When |
| 1210 |
\verb`\eval` meets an unnanounced brace group it is `flying blind'. |
| 1211 |
\LaTeX{} braces are `punctuation marks' for \LaTeX{} code, not for |
| 1212 |
mathematical formulas. How could they be, since they do not display |
| 1213 |
in the \texttt{pdf}? For \texttt{numerica} it is \emph{how things |
| 1214 |
look in the }\texttt{\emph{pdf}} that is the guide. |
| 1215 |
|
| 1216 |
\verb`\eval` converts an unannounced braced expression into its corresponding |
| 1217 |
\texttt{l3fp} form and appends that to the overall expression that |
| 1218 |
is to be evaluated. It does not do anything further. Note in particular |
| 1219 |
that it does not first evaluate the braced expression and append the |
| 1220 |
result to the overall expression, nor does it parenthesize the \texttt{l3fp} |
| 1221 |
form of the braced expression, nor does it check to see if a multiplying |
| 1222 |
asterisk \verb`*` should be appended or prepended to the \texttt{l3fp} |
| 1223 |
form. It simply converts the braced expression into its \texttt{l3fp} |
| 1224 |
form and appends. |
| 1225 |
|
| 1226 |
This works fine if, as suggested above, the braces surround a function |
| 1227 |
like \verb`\max(x,y,z)` so it can be included in a multi-formula |
| 1228 |
calculation, but it can give unexpected results in other contexts. |
| 1229 |
Thus (math braces; \LaTeX{} braces), |
| 1230 |
\begin{centred} |
| 1231 |
\verb`\eval[ff]{\[ \{ 1+2 \}^2, { 1+2 }^2 \]}` $\Longrightarrow$ |
| 1232 |
\eval[ff]{\[ \{ 1+2 \}^2, { 1+2 }^2 \]} |
| 1233 |
\end{centred} |
| 1234 |
In the first of these \verb`eval` reads the math-braced expression, |
| 1235 |
converts it into its \texttt{l3fp} form and appends that, which \emph{includes |
| 1236 |
the math braces}, to the (empty at this stage) overall expression\emph{. |
| 1237 |
}In the second of these, \verb`\eval` reads the braced expression, |
| 1238 |
converts that to its \texttt{l3fp} form and appends the result to |
| 1239 |
the (empty at this stage) overall expression. In both cases, \verb`\eval` |
| 1240 |
proceeds to read and append \verb`^2` to the overall expression so |
| 1241 |
that the superscript acts on a bracketed expression in the first case |
| 1242 |
and on $2$ alone in the second. |
| 1243 |
|
| 1244 |
A second example is |
| 1245 |
\begin{centred} |
| 1246 |
\verb`\eval[ff]{\[ 3\{ 2+1 \}, 3{ 2+1 } \]}` $\Longrightarrow$ \eval[ff]{\[ 3\{ 2+1 \} , 3{ 2+1 } \]} |
| 1247 |
\end{centred} |
| 1248 |
Similarly \verb`{ 2+1 }\tfrac13` displays like $2+1\tfrac{1}{3}$ |
| 1249 |
which one might naively expect to evaluate to $3.333333$ but in fact |
| 1250 |
it evaluates to $2.333333$ since \texttt{l3fp} uses juxtaposition |
| 1251 |
to mean \emph{multiply}. Because \LaTeX{} braces do not visibly display, |
| 1252 |
this kind of result is all too likely. Unless there is some compelling |
| 1253 |
reason to do otherwise avoid \emph{unannounced} brace groups in expressions |
| 1254 |
except to `hide' functions containing problematic characters (like |
| 1255 |
the argument separator in $n$-ary functions in some contexts). |
| 1256 |
|
| 1257 |
\noindent{}% |
| 1258 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 1259 |
\begin{shaded}% |
| 1260 |
There is also a quirk (or feature) of \texttt{l3fp} that could catch |
| 1261 |
one out. An expression of the form \verb`(1)1` produces a \LaTeX{} |
| 1262 |
error when \texttt{l3fp} tries to evaluate it. In \texttt{l3fp} a |
| 1263 |
number can be placed directly \emph{before} a parenthesized expression |
| 1264 |
but not after; \verb`1(1)` and \verb`(1)1` are read very differently |
| 1265 |
by the program. In normal use, `behind the scenes' \texttt{numerica} |
| 1266 |
takes care of this quirk; a user should never have to worry about |
| 1267 |
it. But this internal coping mechanism is not activated when the \texttt{l3fp} |
| 1268 |
form of a braced group is appended to the overall expression.\end{shaded}% |
| 1269 |
\end{minipage} |
| 1270 |
|
| 1271 |
\subsection{Numbers} |
| 1272 |
|
| 1273 |
\label{subsec:evalNumbers}In the present document the numerous examples |
| 1274 |
presented mainly use ordinary decimal notation for numbers, but scientific |
| 1275 |
notation is also available, both for input (see §\ref{subsec:settingsInputtingSciNotation}) |
| 1276 |
and output (see §\ref{subsec:evalScientificNotation}). |
| 1277 |
|
| 1278 |
\subsubsection{Decimal point} |
| 1279 |
|
| 1280 |
Prior to version 3.0.0 the only decimal marker accepted was the dot |
| 1281 |
(period, full stop). Now, by means of the \verb`comma` package option, |
| 1282 |
the comma can also be used as the decimal point. This means using |
| 1283 |
semicolons in the variable=value list (see below §\ref{sec:evalVv-list}) |
| 1284 |
and for separating the arguments of $n$-ary functions (§\ref{sec:calc-n-ary-functions}) |
| 1285 |
in line with ISO 80000 Part 2, section 3 which reads: `A comma, semicolon |
| 1286 |
or other appropriate symbol can be used as a separator between numbers |
| 1287 |
or expressions. The comma is generally preferred, except when numbers |
| 1288 |
with a decimal comma are used.' When the \verb`comma` package option |
| 1289 |
is used, \texttt{numerica} \emph{insists} on semicolons for separating |
| 1290 |
items in the two contexts mentioned. |
| 1291 |
|
| 1292 |
\subsubsection{Grouping blocks of digits} |
| 1293 |
|
| 1294 |
Sometimes, to make numbers more readable, blocks of digits are grouped |
| 1295 |
together, separated perhaps by spaces or by an explicit mark like |
| 1296 |
a comma. \texttt{numerica} can digest numbers in which the grouping |
| 1297 |
is by \emph{spaces}, but not a mark. `Out of the box', however, |
| 1298 |
the package does not expect spaces in numbers. This needs to be turned |
| 1299 |
on by the user by entering \verb`1s2` (or \verb`1s2=1`; \verb`1s2` |
| 1300 |
indicating a space `s' between digits) in the settings option: |
| 1301 |
\begin{centred} |
| 1302 |
\verb`\eval[1s2]{ 12 345.678 901 }` $\Longrightarrow$ \eval[1s2]{ 12 345.678 901} |
| 1303 |
\end{centred} |
| 1304 |
\texttt{l3fp} works to $16$ significant figures; so does \texttt{numerica}. |
| 1305 |
But experience suggests that in `everyday' use significantly fewer |
| 1306 |
digits are generally used, both as input and output. The cases in |
| 1307 |
which grouping digits aids readability will be rare. For this reason, |
| 1308 |
`out of the box', \verb`1s2=0`. |
| 1309 |
|
| 1310 |
Note that \verb`1s2=0` should not cause a \LaTeX{} error nor raise |
| 1311 |
a message in \texttt{numerica} if a number containing spaces\emph{ |
| 1312 |
}is fed to \verb`\eval`, but the result may be disconcerting: |
| 1313 |
\begin{centred} |
| 1314 |
\verb`\eval[1s2=0]{ 12 34 }` $\Longrightarrow$ \eval[1s2=0]{ 12 34 } |
| 1315 |
\end{centred} |
| 1316 |
What has happened in the example is that $12$ and $34$ have been |
| 1317 |
read separately as distinct numbers, an asterisk inserted between |
| 1318 |
them, and multiplied. Sometimes the product may lead to a result |
| 1319 |
sufficiently close to the expected one as to pass unnoticed. For this |
| 1320 |
reason it is recommended that spaces in numbers be avoided as a matter |
| 1321 |
of habit except in rare special circumstances (e.g.\ when entering |
| 1322 |
a number like \verb`0.7777 7777 7777 7777`). |
| 1323 |
|
| 1324 |
Grouping blocks of digits with spaces is available through the \verb`1s2` |
| 1325 |
setting solely for \emph{inputting} numbers in the variable=value |
| 1326 |
list or formula. The \verb`\eval` command does not \emph{output} |
| 1327 |
numbers in this form. |
| 1328 |
|
| 1329 |
\subsection{Variable names} |
| 1330 |
|
| 1331 |
\label{subsec:evalVariableNames}In mathematical practice, variable |
| 1332 |
names are generally single letters of the Roman or Greek alphabets, |
| 1333 |
or occasionally from other alphabets, in a variety of fonts, and often |
| 1334 |
with subscripts or primes or other decorations: $x,\,\boldsymbol{x},\,\mu,\,x',\,\alpha'',$ |
| 1335 |
$\,T^{iv},\,\Theta_{n},\,\boldsymbol{a}'_{n},\,\beta''_{mn},\,\vec{v},\,k^{+},\,k_{-}$ |
| 1336 |
are examples. \texttt{numerica} does not attempt to characterize variables |
| 1337 |
by their `internals'(alphabet, font, decoration, etc.). Rather, |
| 1338 |
the program accepts as a variable \emph{whatever lies to the left |
| 1339 |
of the equals sign }in an item of the variable=value list (for which |
| 1340 |
see §\ref{sec:evalVv-list} immediately below). |
| 1341 |
|
| 1342 |
What lies to the left is a \emph{\LaTeX{} expression}. Different \LaTeX{} |
| 1343 |
almost always means different variable. For instance $x$ and x are |
| 1344 |
\emph{different} variables since, in the underlying \LaTeX , one is |
| 1345 |
\verb`x` and the other \verb`\mathrm{x}`. I write `\emph{almost} |
| 1346 |
always' because there are exceptions. Since braces do not display |
| 1347 |
in the \texttt{pdf}, names that look identical in the \texttt{pdf} |
| 1348 |
may well be distinct in \LaTeX . This is true particularly of superscripts |
| 1349 |
and subscripts: \verb`x_0` and \verb`x_{0}` appear identical in |
| 1350 |
the \texttt{pdf} but in the underlying \LaTeX{} they are distinct, |
| 1351 |
and will be treated as distinct variables by \texttt{numerica}. The |
| 1352 |
user needs to be aware of this. Also, because equals signs and commas |
| 1353 |
give structure to the variable=value list, a variable name should |
| 1354 |
not contain a \emph{naked} equals sign or a \emph{naked} comma. Instead |
| 1355 |
they should be decently wrapped in braces, like \verb`R_{=}` displaying |
| 1356 |
as $R_{=}$. These provisos aside, variables can be single- or multi-token, |
| 1357 |
can be in different fonts, can be decorated with primes and indices |
| 1358 |
– and may even contain spaces. (But please don’t; such names are not |
| 1359 |
part of mathematical practice.) If a variable is natural to the mathematical |
| 1360 |
context, it will almost certainly be accepted as a variable in \texttt{numerica}. |
| 1361 |
For the kind of back-of-envelope calculations envisaged for the package, |
| 1362 |
most variables will be single letters from the Roman or Greek alphabets. |
| 1363 |
|
| 1364 |
\subsubsection{Multi-token variable handling} |
| 1365 |
|
| 1366 |
Although multi-token variables are perfectly acceptable, \emph{internally} |
| 1367 |
\texttt{numerica} works with single tokens. Variable names can be |
| 1368 |
so different in structure, one from another, that to ease the parsing |
| 1369 |
of formulas, all \emph{internal} variable names are assumed to be |
| 1370 |
single tokens. Hence a necessary initial step for the package is to |
| 1371 |
map all multi-token variable names in the vv-list and the formula |
| 1372 |
to single tokens. \texttt{numerica} does this by turning the multi-token |
| 1373 |
variable names into control sequences with names in the sequence \verb`\nmc_a`, |
| 1374 |
\verb`\nmc_b`, \verb`\nmc_c`, etc., then searches through the vv-list |
| 1375 |
and the formula for every occurrence of the multi-token names and |
| 1376 |
replaces them with the relevant control sequences. It does this in |
| 1377 |
order of decreasing size of name, working from the names that contain |
| 1378 |
most tokens down to names containing only two tokens. (Doing the replacing |
| 1379 |
in this order prevents \emph{parts} of longer names possibly being |
| 1380 |
mistaken for shorter variable names.) |
| 1381 |
|
| 1382 |
The conversion process uses computer resources. Even if there are |
| 1383 |
no multi-token variables present, \texttt{numerica} still needs to |
| 1384 |
check that this is so – unless the user alerts the program to the |
| 1385 |
fact with the setting \verb`xx=0`; see §\ref{subsec:settingsMultitokSwitch}. |
| 1386 |
|
| 1387 |
\section{The variable=value list} |
| 1388 |
|
| 1389 |
\label{sec:evalVv-list}To evaluate algebraic, trigonometric and other |
| 1390 |
formulas that involve variables we need to give those variables values. |
| 1391 |
This is done in the \emph{variable=value list} – or \emph{vv-list} |
| 1392 |
for short. This is the fourth argument of the \texttt{\textbackslash nmcEvaluate} |
| 1393 |
command and is a square-bracket delimited optional argument (optional |
| 1394 |
because an expression may depend only on constants and numbers). |
| 1395 |
|
| 1396 |
A vv-list is a comma-separated list (or, if the \verb`comma` package |
| 1397 |
option is used, semicolon-separated list) where each item is of the |
| 1398 |
form \emph{variable=value}. It might be something simple like \verb`[g=9.81,t=2]` |
| 1399 |
or something more complicated like |
| 1400 |
\begin{verbatim} |
| 1401 |
[V_S=\tfrac43\pi r^3,V_C=2\pi r^2h,h=3/2,r=2]. |
| 1402 |
\end{verbatim} |
| 1403 |
Spaces around the equals signs or the commas (resp., semicolons) are |
| 1404 |
stripped away during processing so that \verb`[g=9.81,t=2]` and \verb`[ g = 9.81 , t = 2 ]` |
| 1405 |
are the \emph{same} variable=value list. |
| 1406 |
|
| 1407 |
\emph{Math delimiters should never be used in the vv-list. }If they |
| 1408 |
are present they will cause errors. Math delimiters have a part to |
| 1409 |
play only in the main argument, where their presence or absence can |
| 1410 |
determine the form of display of the result, as discussed above in |
| 1411 |
§\ref{subsec:introResultDisplay}. |
| 1412 |
|
| 1413 |
\subsection{Evaluation from right to left} |
| 1414 |
|
| 1415 |
In these examples, with variables depending on other variables, there |
| 1416 |
is an implication: that the list is evaluated \emph{from the right}. |
| 1417 |
Recall how a function of a function is evaluated, say\emph{ }$y=f(g(h(x)))$. |
| 1418 |
To evaluate $y$, first $x$ is assigned a value then $h(x)$ is calculated, |
| 1419 |
then $g(h(x))$ then $f(g(h(x)))=y$. We work from right to left, |
| 1420 |
from the innermost to the outermost element. Or consider an example |
| 1421 |
like calculating the area of a triangle by means of the formula |
| 1422 |
\[ |
| 1423 |
A=\sqrt{s(s-a)(s-b)(s-c)}. |
| 1424 |
\] |
| 1425 |
First we write the formula; then we state how $s$ depends on $a,b,c$, |
| 1426 |
namely $s=\frac{1}{2}(a+b+c)$, then we give values to $a,b,c$. In |
| 1427 |
\texttt{numerica} this is mirrored in the layout of the \verb`\eval` |
| 1428 |
command: |
| 1429 |
\begin{verbatim} |
| 1430 |
\eval{$ \sqrt{s(s-a)(s-b)(s-c)} $} |
| 1431 |
[s=\tfrac12(a+b+c),a=3,b=4,c=5] |
| 1432 |
\end{verbatim} |
| 1433 |
The formula in a sense is the leftmost extension of the vv-list. The |
| 1434 |
entire evaluation occurs from right to left. This means that the rightmost |
| 1435 |
variable in the vv-list can depend only on constants and numbers – |
| 1436 |
although it may be a complicated expression of those elements. Other |
| 1437 |
variables in the vv-list can depend on variables \emph{to their right} |
| 1438 |
but not to their left. |
| 1439 |
|
| 1440 |
\subsection{Constants} |
| 1441 |
|
| 1442 |
\label{subsec:evalBuilt-in-Constants}\texttt{numerica} has five built-in |
| 1443 |
constants and can also accept user-defined constants. For the latter, |
| 1444 |
see §\ref{sec:supplConstants}. The five built-in constants known |
| 1445 |
to \texttt{numerica} are \verb`\pi`, the ratio of circumference to |
| 1446 |
diameter of a circle; \verb`e`, the base of natural logarithms; Euler's |
| 1447 |
constant \verb`\gamma`, the limit of $\left(\sum_{1}^{N}1/n\right)-\ln N$ |
| 1448 |
as $N\to\infty$; the golden ratio \verb`\phi`, equal to $\tfrac{1}{2}(1+\surd5)$; |
| 1449 |
and the utilitarian constant \verb`\deg`, the size of a degree in |
| 1450 |
radians. Using a comma list for a multi-formula calculation and an |
| 1451 |
\verb`align*` environment, |
| 1452 |
\begin{centred} |
| 1453 |
\verb`\eval[env=align*,pp,p,ff]{ \pi, e, \gamma, \phi, \deg }` $\Longrightarrow$ |
| 1454 |
\eval[env=align*,pp,p,ff]{ \pi, e, \gamma, \phi, \deg } |
| 1455 |
\end{centred} |
| 1456 |
\noindent so that \verb`\eval{$ 180\deg $}` $\Longrightarrow$ \eval{$ 180\deg $} |
| 1457 |
(as it should). |
| 1458 |
|
| 1459 |
In some contexts it may feel natural to use any or all of \verb`\pi`, |
| 1460 |
\verb`e`, \verb`\gamma` and \verb`\phi` as variables by assigning |
| 1461 |
values to them in the vv-list. \texttt{numerica} does not object. |
| 1462 |
The values assigned in this way override the built-in constant values. |
| 1463 |
|
| 1464 |
For example, if instead of the usual ABC we label a triangle EFG with |
| 1465 |
sides (note!) $e=3,f=4$ and $g=5$, its area is\medskip{} |
| 1466 |
\begin{verbatim} |
| 1467 |
\eval{$ \sqrt{s(s-e)(s-f)(s-g)} $} |
| 1468 |
[s=\tfrac12(e+f+g),e=3,f=4,g=5] |
| 1469 |
\end{verbatim} |
| 1470 |
$\Longrightarrow$ |
| 1471 |
|
| 1472 |
\eval{$ \sqrt{s(s-e)(s-f)(s-g)} $} |
| 1473 |
[s=\tfrac12(e+f+g),e=3,f=4,g=5].\medskip{} |
| 1474 |
|
| 1475 |
\noindent Clearly the value $3$ assigned to \verb`e` in the vv-list |
| 1476 |
has been used in the calculation, not the value of the constant. But |
| 1477 |
if \verb`e` (or \verb`\pi` or \verb`\gamma` or \verb`\phi`) is |
| 1478 |
not assigned a value in the vv-list then it has, by default, the value |
| 1479 |
of the constant. In the case of \verb`e`, if you wish to use it as |
| 1480 |
a variable, the constant is always available as \verb`\exp(1)`. No |
| 1481 |
similar alternative is available for \verb`\pi`, \verb`\gamma` or |
| 1482 |
\verb`\phi`. |
| 1483 |
|
| 1484 |
\subsection{Expressions in the variable=value list} |
| 1485 |
|
| 1486 |
Suppose our expression is $\tfrac{4}{3}\pi r^{3}$, the volume $V_{S}$ |
| 1487 |
of a sphere in terms of its radius $r$, and we want to calculate |
| 1488 |
the volume for different values of $r$ to get a sense of how rapidly |
| 1489 |
volume increases with radius. |
| 1490 |
\begin{centred} |
| 1491 |
\verb`$ V_S=\eval{ \tfrac43\pi r^3 }[r=1] $` $\Longrightarrow$ $ V_S=\eval{ \tfrac43\pi r^3 }[r=1] $. |
| 1492 |
\end{centred} |
| 1493 |
Having set up this calculation it is now an easy matter to change |
| 1494 |
the value of $r$ in the vv-list: |
| 1495 |
\begin{centred} |
| 1496 |
\verb`$ V_S=\eval{ \tfrac43\pi r^3 }[r=1.5] $` $\Longrightarrow$ |
| 1497 |
$\vsp V_S= \eval{ \tfrac43\pi r^3 }[r=1.5] $. |
| 1498 |
\end{centred} |
| 1499 |
Or we could `rephrase' the calculation like this: |
| 1500 |
\begin{centred} |
| 1501 |
\verb`\eval{$ V_S $}[V_S=\tfrac43\pi r^3,r=2]` $\Longrightarrow$ |
| 1502 |
$\vsp$\eval{$ V_S $}[V_S=\tfrac43\pi r^3,r=2]. |
| 1503 |
\end{centred} |
| 1504 |
As you can see, values in the vv-list are not limited to numbers. |
| 1505 |
They can be expressions depending on constants, numbers or other variables |
| 1506 |
to their right in the list. This calculation also shows a multi-token |
| 1507 |
variable (\verb`V_S`) being used. |
| 1508 |
|
| 1509 |
Another example: to compute the volume $V_{C}=\pi r^{2}h$ of a cylinder, |
| 1510 |
we have two variables to assign values to: |
| 1511 |
\begin{centred} |
| 1512 |
\verb`$ V_C=\eval{ \pi r^2h }[h=4/3,r=1] $` $\Longrightarrow$ $\vsp V_C=\eval{ \pi r^2h }[h=4/3,r=1] $. |
| 1513 |
\end{centred} |
| 1514 |
Or we can divide the calculation up like this, |
| 1515 |
\begin{centred} |
| 1516 |
\verb`$ V_C=\eval{ hA_C }[A_C=\pi r^2,h=4/3,r=1] $` $\Longrightarrow$ |
| 1517 |
$\vsp V_C=\eval{ hA_C }[A_C=\pi r^2,h=4/3,r=1] $, |
| 1518 |
\end{centred} |
| 1519 |
which emphasizes that the volume is `base $\times$ height' (and |
| 1520 |
again uses a multi-token variable). |
| 1521 |
|
| 1522 |
A third instance is provided by the example above in which we calculated |
| 1523 |
the area of a triangle by means of Brahmagupta's formula. |
| 1524 |
|
| 1525 |
\subsection{Display of the vv-list} |
| 1526 |
|
| 1527 |
By default, the vv-list is displayed with the numerical result. That |
| 1528 |
and the format of the display can both be changed. |
| 1529 |
|
| 1530 |
\subsubsection{Changing the display format} |
| 1531 |
|
| 1532 |
\label{subsec:evalChanging-display-format}In the example above where |
| 1533 |
the area of a triangle is calculated using Brahmagupta's formula, |
| 1534 |
display of the result is crowded. One remedy is to force display of |
| 1535 |
the vv-list to a new line. In the default set-up, this happens automatically |
| 1536 |
if the \verb`env` setting is equated to \verb`multline` or \verb`multline*`. |
| 1537 |
Let's do this when Brahmagupta's formula is used not for a triangle |
| 1538 |
but in the more challenging case of a cyclic quadrilateral. |
| 1539 |
|
| 1540 |
The cyclic quadrilateral in question is formed by a 45-45-90 triangle |
| 1541 |
of hypotenuse 2 joined to a 30-60-90 triangle along its hypotenuse |
| 1542 |
of the same length. Two triangles, six vertices but the two along |
| 1543 |
the hypotenuses are shared, hence four vertices in all, lying on a |
| 1544 |
circle. The sides of the cyclic quadrilateral are therefore $\surd2,\surd2,\surd3,1$. |
| 1545 |
Adding the areas of the two triangles, the area of the quadrilateral |
| 1546 |
is $A=1+\tfrac{1}{2}\surd3$, or in decimal form, \verb`$\eval{1+\tfrac12\surd3}$` |
| 1547 |
$\Longrightarrow$ $\eval{1+\tfrac12\surd3}$. Let's check with Brahmagupta's |
| 1548 |
formula: |
| 1549 |
\begin{verbatim} |
| 1550 |
\eval[env=multline*]{\sqrt{(s-a)(s-b)(s-c)(s-d)}} |
| 1551 |
[s=\tfrac12(a+b+c+d), |
| 1552 |
a=\surd2,b=\surd2,c=\surd3,d=1] |
| 1553 |
\end{verbatim} |
| 1554 |
$\Longrightarrow$ \eval[env=multline*]{ |
| 1555 |
\sqrt{(s-a)(s-b)(s-c)(s-d)} |
| 1556 |
}[s=\tfrac12(a+b+c+d), |
| 1557 |
a=\surd2,b=\surd2,c=\surd3,d=1] |
| 1558 |
|
| 1559 |
\subsubsection{Suppressing display of the vv-list} |
| 1560 |
|
| 1561 |
\label{subsec:evalVvSuppresList} |
| 1562 |
|
| 1563 |
\paragraph{Star (\texttt{{*}}) option} |
| 1564 |
|
| 1565 |
If display of the vv-list is not wanted at all, only the numerical |
| 1566 |
result, it suffices to attach an asterisk (star) to the \verb`\eval` |
| 1567 |
command, giving a `naked' result: |
| 1568 |
\begin{centred} |
| 1569 |
\verb`\eval*{ hA_C }[A_C=\pi r^2,h=4/3,r=1]` $\Longrightarrow$ \eval*{ hA_C }[A_C=\pi r^2,h=4/3,r=1]. |
| 1570 |
\end{centred} |
| 1571 |
The star option for a multi-formula calculation evaluates each formula |
| 1572 |
and presents the numerical result of each calculation with a space |
| 1573 |
between; it is minimal and inelegant: |
| 1574 |
\begin{centred} |
| 1575 |
\verb`\eval*[ff]{ \surd x, x, x^2 }[x=\pi]` $\Longrightarrow$ \eval*[ff]{ \surd x, x, x^2 }[x=\pi] |
| 1576 |
\end{centred} |
| 1577 |
However, the \verb`pp` setting is available to add a comma (for instance) |
| 1578 |
and the \verb`sep` setting can change the space – perhaps \verb`sep=\quad`. |
| 1579 |
|
| 1580 |
Note that with the star option a negative result will display with |
| 1581 |
a hyphen for the minus sign. |
| 1582 |
\begin{centred} |
| 1583 |
\verb`\eval*{ y }[y=ax+b,x=2,a=-2,b=2]` $\Longrightarrow$ \eval*{ y }[y=ax+b,x=2,a=-2,b=2], |
| 1584 |
\end{centred} |
| 1585 |
In a math environment, the hyphen will display as a minus sign. Wrapping |
| 1586 |
\verb`\eval*` around math delimiters or using the \verb`env` option |
| 1587 |
has no effect – the \verb`*` dominates. |
| 1588 |
|
| 1589 |
\paragraph{No math environment:} |
| 1590 |
|
| 1591 |
In the absence of a math environment, recall from §\ref{subsec:introResultDisplay}, |
| 1592 |
\verb`\eval` (no star!) automatically presents the numerical result |
| 1593 |
\emph{without vv-list} between \verb`$` delimiters, (so that negative |
| 1594 |
values display with a proper minus sign): |
| 1595 |
\begin{centred} |
| 1596 |
\verb`\eval{ y }[y=ax+b,x=2,a=-2,b=2]` $\Longrightarrow$ \eval{ y }[y=ax+b,x=2,a=-2,b=2]. |
| 1597 |
\end{centred} |
| 1598 |
|
| 1599 |
\paragraph{Settings option:} |
| 1600 |
|
| 1601 |
Display of the vv-list can also be suppressed through the settings |
| 1602 |
option, by writing \verb`vv= ` there – i.e.\ by giving the key \verb`vv` |
| 1603 |
an empty value. If the example above is too bare, then perhaps |
| 1604 |
\begin{centred} |
| 1605 |
\verb`\eval[vv=]{$ V_C $}[V_C=h\pi r^2,h=4/3,r=1]` $\Longrightarrow$ |
| 1606 |
\eval[vv=]{$ V_C $}[V_C=h\pi r^2,h=4/3,r=1] |
| 1607 |
\end{centred} |
| 1608 |
is more acceptable? See §\ref{subsec:settingsVvDisplayChangeLocal} |
| 1609 |
for a fuller discussion of the \verb`vv` setting. |
| 1610 |
|
| 1611 |
\paragraph{Scriptstyle contexts: } |
| 1612 |
|
| 1613 |
In versions of \texttt{numerica} before version 3, display of the |
| 1614 |
vv-list was automatically suppressed in scriptstyle (and scriptscriptstyle) |
| 1615 |
contexts. This occurred by means of \TeX 's \verb`\mathchoice` command. |
| 1616 |
Version 3.0.0 of \texttt{numerica} has dispensed with\texttt{ }\verb`\mathchoice` |
| 1617 |
and requires the user to suppress display in these contexts (if so |
| 1618 |
wished), by starring the \verb`\eval` command: |
| 1619 |
\begin{centred} |
| 1620 |
\verb`$e^{\eval*{xy}[x=\pi,y=1/e]}$` $\Longrightarrow$ $e^{ \eval*{xy}[x=\pi,y=1/e]}$ |
| 1621 |
\end{centred} |
| 1622 |
|
| 1623 |
\paragraph{Empty vv-list suppressed:} |
| 1624 |
|
| 1625 |
Should the vv-list be empty, or display of \emph{all} variables be |
| 1626 |
suppressed by wrapping each in braces (see next, §\ref{subsec:evalVvSuppressVars}), |
| 1627 |
then \emph{nothing} is displayed where the vv-list would normally |
| 1628 |
be: |
| 1629 |
\begin{centred} |
| 1630 |
\verb`$ V_C=\eval{ hA_C }[{A_C}=\pi r^2,{h}=4/3,{r}=1] $.` $\Longrightarrow$ |
| 1631 |
$ V_C=\eval{ hA_C }[{A_C}=\pi r^2,{h}=4/3,{r}=1]. $ |
| 1632 |
\end{centred} |
| 1633 |
|
| 1634 |
\subsubsection{Suppressing display of items} |
| 1635 |
|
| 1636 |
\label{subsec:evalVvSuppressVars}You may wish to retain some variables |
| 1637 |
in the vv-list display, but not all. For those variables you wish |
| 1638 |
omitted from the display, wrap each variable (but not the equals sign |
| 1639 |
or value) in braces. When calculating the volume of a cylinder in |
| 1640 |
a previous example, the base area $A_{C}$ has a different status |
| 1641 |
from the `fundamental' variables $r$ and $h$. It is an intermediate |
| 1642 |
value, one that we pass through on the way to the final result. To |
| 1643 |
suppress it from display enclose the variable in braces: |
| 1644 |
\begin{centred} |
| 1645 |
\verb`$ V_C=\eval{ hA_C }[{A_C}=\pi r^2,h=4/3,r=1] $` $\Longrightarrow$ |
| 1646 |
$ V_C=\eval{ hA_C }[{A_C}=\pi r^2,h=4/3,r=1] $. |
| 1647 |
\end{centred} |
| 1648 |
As you can see, $A_{C}$ no longer appears in the displayed vv-list. |
| 1649 |
Of course the name and its value are still recorded `behind the scenes' |
| 1650 |
and can still be used in calculations. Note that the braces enclose |
| 1651 |
only the variable name, not the equals sign or the value. |
| 1652 |
|
| 1653 |
\noindent{}% |
| 1654 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 1655 |
\begin{shaded}% |
| 1656 |
|
| 1657 |
\subsection{Abusing multi-token variable names} |
| 1658 |
|
| 1659 |
\label{subsec:evalDon't-do-this!}A variable name is what lies to |
| 1660 |
the left of the equals sign of an item in the vv-list. Since multi-token |
| 1661 |
variables are converted to single tokens before any calculating is |
| 1662 |
done, it is possible to sin. We can, for instance, make $\sin\pi$ |
| 1663 |
a variable name and produce an absurdity: |
| 1664 |
\begin{centred} |
| 1665 |
\verb`\eval{$ \sin\pi $}[{\sin\pi}=1]` $\Longrightarrow$ \eval{$ \sin\pi $}[{\sin\pi}=1]; |
| 1666 |
\end{centred} |
| 1667 |
or similarly treat a number as a variable name and produce another: |
| 1668 |
\begin{centred} |
| 1669 |
\verb`\eval{$ -1 $}[{-1}=1]` $\Longrightarrow$ \eval{$ -1 $}[{-1}=1]. |
| 1670 |
\end{centred} |
| 1671 |
What is happening here is that the multi-token `variables' \verb`\sin\pi` |
| 1672 |
and \verb`-1` are converted, right at the start of proceedings, to |
| 1673 |
single tokens like \verb`\nmc_a`, \verb`\nmc_b`. These \TeX{} macros |
| 1674 |
expand to their respective multi-token variable names when \emph{displayed}, |
| 1675 |
but for calculating within \texttt{numerica} the single token is used. |
| 1676 |
By this means it is easy to construct whatever grotesqueries you like. |
| 1677 |
\medskip{} |
| 1678 |
|
| 1679 |
Should \texttt{numerica} try to check variable names to avoid consequences |
| 1680 |
like this? I see no reasonable way of doing so. Digits, and symbols |
| 1681 |
like \verb`(` and \verb`+`, can easily be part of valid variable |
| 1682 |
names – $k^{+}$, $x_{1}$, $C_{n}^{(0)}$ and so on. It is left to |
| 1683 |
the user, in any \emph{public} document, to avoid such sins (which |
| 1684 |
can easily be constructed in \LaTeX{} without recourse to \verb`\eval` |
| 1685 |
at all, should the user so wish). See also §\ref{subsec:supplMacrosDisplay} |
| 1686 |
where a similar issue arises with user-defined macros.\end{shaded}% |
| 1687 |
\end{minipage} |
| 1688 |
|
| 1689 |
\section{Formatting the numerical result} |
| 1690 |
|
| 1691 |
\label{sec:evalRoundingEtc}Internally, values are stored to $16$ |
| 1692 |
significant figures (if available), calculations are carried out to |
| 1693 |
$16$ significant figures, but only rarely are results displayed to |
| 1694 |
$16$ figures. Generally, they are rounded to some smaller number |
| 1695 |
of figures. The default `out of the box' rounding value is $6$, |
| 1696 |
meaning at most $6$ decimal places are shown. (It can of course be |
| 1697 |
reset with the \verb`rounding` package option, e.g. \verb`rounding=4`; |
| 1698 |
see §§\ref{subsec:introPackagesOptions}, \ref{subsec:evalRounding-value}.) |
| 1699 |
So far, nearly all results have been rounded to the default figure, |
| 1700 |
although not all digits are always displayed – for instance if the |
| 1701 |
sixth one is $0$, or the result is an integer. |
| 1702 |
|
| 1703 |
But \texttt{numerica} is not limited to the decimal presentation of |
| 1704 |
results. Scientific notation is also available, as is fraction-form |
| 1705 |
output with numerator and denominator both integers, and boolean output |
| 1706 |
when the formula being evaluated is a comparison, treated by the \verb`\eval` |
| 1707 |
command not as a statement like \emph{`A is less than B'} but rather |
| 1708 |
as a question: \emph{`Is A less than B?'}. |
| 1709 |
|
| 1710 |
The appearance of the result in any of these various formats can be |
| 1711 |
chosen and customized by means of a square-bracketed optional argument |
| 1712 |
following the vv-list – or the formula if there is no vv-list. This |
| 1713 |
optional argument may contain a number of juxtaposed items from these |
| 1714 |
possibilities: |
| 1715 |
\begin{itemize} |
| 1716 |
\item a question mark \verb`?` which gives boolean output, $1$ for true, |
| 1717 |
$0$ for false; see §\ref{subsec:evalBoolean-output}; |
| 1718 |
\begin{itemize} |
| 1719 |
\item a second question mark, \verb`??`, which gives boolean output $T$ |
| 1720 |
for true, $F$ for false; |
| 1721 |
\item a third question mark, \verb`???`, which gives boolean output \verb`T` |
| 1722 |
for true, \verb`F` for false; |
| 1723 |
\end{itemize} |
| 1724 |
\item a slash \verb`/` which gives output in slash-fraction form with integers |
| 1725 |
for both numerator and denominator; see §\ref{subsec:evalFraction-form-output}; |
| 1726 |
if followed by \verb`s` the fraction will be formed with the \verb`\sfrac` |
| 1727 |
command from the \verb`xfrac` package if loaded, or in scriptstyle |
| 1728 |
slash fraction form if not; |
| 1729 |
\begin{itemize} |
| 1730 |
\item a second slash, \verb`//`, which gives output in fraction form using |
| 1731 |
\verb`\frac` with integers for both numerator and denominator; if |
| 1732 |
followed by \verb`t` or \verb`d` the fraction will be formed with, |
| 1733 |
respectively, the \verb`\tfrac` or \verb`\dfrac` commands from \verb`amsmath`; |
| 1734 |
\end{itemize} |
| 1735 |
\item an integer, the \emph{rounding value}, positive, negative or zero, |
| 1736 |
specifying how many decimal places to display the result to, or to |
| 1737 |
how many zeros after the decimal point fraction-form output approximates |
| 1738 |
the result; see §\ref{subsec:evalRounding-value} and §\ref{subsec:evalFraction-form-output}; |
| 1739 |
\item an asterisk, {*}, which pads the result with zeros should it not display |
| 1740 |
as many decimal places as the rounding value specifies; see §\ref{subsec:evalPadding-with-zeros}; |
| 1741 |
\item the character \verb`x` (lower case!) which presents the result in |
| 1742 |
`proper' scientific notation (a form like $1.2345\times10^{5}$ |
| 1743 |
for 123450) except for numbers in the interval \verb`[1,10)`; see |
| 1744 |
§\ref{subsec:evalSciNotation1to10}; |
| 1745 |
\begin{itemize} |
| 1746 |
\item the character \verb`x` repeated, \verb`xx`, which extends the notation |
| 1747 |
to numbers in the interval \verb`[1,10)`; |
| 1748 |
\end{itemize} |
| 1749 |
\item the character \verb`t` (lower case!) which presents the result in |
| 1750 |
a style of scientific notation useful in tables (a form like $(5)1.2345$ |
| 1751 |
for 123450) except for numbers in the interval \verb`[1,10)`; see |
| 1752 |
§\ref{subsec:evalSciNotation1to10}; |
| 1753 |
\begin{itemize} |
| 1754 |
\item the character \verb`t` repeated, \verb`tt`, which extends the notation |
| 1755 |
to numbers in the interval \verb`[1,10)`; |
| 1756 |
\end{itemize} |
| 1757 |
\item a letter other than \verb`x` or \verb`t`, usually one of the letters\texttt{ |
| 1758 |
}\verb`e`, \verb`d`, \verb`E`, \verb`D`, which presents the result |
| 1759 |
in scientific notation with that letter as the exponent mark (a form |
| 1760 |
like $1.2345\text{e}5$ for $123450$); see §\ref{subsec:evalSciNotation1to10}; |
| 1761 |
\begin{itemize} |
| 1762 |
\item the letter repeated – say \verb`dd` – which extends the notation |
| 1763 |
to numbers in the interval \verb`[1,10)`. |
| 1764 |
\end{itemize} |
| 1765 |
\end{itemize} |
| 1766 |
If you use \verb`?` in the same specification as some other character, |
| 1767 |
the \verb`?` prevails; if you use \verb`/` in the same specification |
| 1768 |
as some other character except for \verb`?`, the \verb`/` prevails; |
| 1769 |
if you use \verb`x` in the same specification as some other character |
| 1770 |
except for \verb`?` or \verb`/`, the \verb`x` prevails; if you |
| 1771 |
use \verb`t` in the same specification as some other character except |
| 1772 |
for \verb`?`, \verb`/` or \verb`x`, the \verb`t` prevails: \verb`?`$\succ$\verb`/`$\succ$\verb`x`$\succ$\verb`t`$\succ$\ldots{} |
| 1773 |
(where $\succ$ means `prevails over'). |
| 1774 |
|
| 1775 |
\subsection{Rounding value } |
| 1776 |
|
| 1777 |
\label{subsec:evalRounding-value}If the number is displayed as a |
| 1778 |
decimal, the rounding value specifies the number of decimal places |
| 1779 |
displayed. If a number is displayed in scientific notation (see below |
| 1780 |
§\ref{subsec:evalScientificNotation}) that is still true, but it |
| 1781 |
can mean differences in the overall number of digits displayed. For |
| 1782 |
the moment, I show the effect of rounding in a purely decimal display: |
| 1783 |
\begin{centred} |
| 1784 |
\verb`\eval{ 1/3 }[4],\qquad \eval{ 1/3 }` $\Longrightarrow$ \eval{ 1/3 }[4],\qquad\eval{ 1/3 }. |
| 1785 |
\end{centred} |
| 1786 |
In the first case \verb`4` was entered in the number-format option |
| 1787 |
and the result is displayed to four decimal places; in the second, |
| 1788 |
the default rounding value of $6$ takes effect. |
| 1789 |
|
| 1790 |
Following the default behaviour in \texttt{l3fp}, which is the calculational |
| 1791 |
engine used by \texttt{numerica}, `ties' are rounded to the nearest |
| 1792 |
\emph{even} digit. Thus a number ending $55$ with a `choice' of |
| 1793 |
rounding to $5$ or $6$ rounds up to the even digit $6$, and a number |
| 1794 |
ending $65$ with a `choice' of rounding to $6$ or $7$ rounds |
| 1795 |
down to the even digit $6$: |
| 1796 |
\begin{centred} |
| 1797 |
\verb`\eval[pp,ff]{ 0.1234555, 0.1234565 }` $\Longrightarrow$ \eval[pp,ff]{0.1234555,0.1234565}. |
| 1798 |
\end{centred} |
| 1799 |
\texttt{l3fp} works to 16 significant figures and never displays more |
| 1800 |
than that number (and often fewer). |
| 1801 |
\begin{itemize} |
| 1802 |
\item In the following, although I have specified a rounding value of $19$, |
| 1803 |
only $16$ decimal places are displayed (with the final digits rounded |
| 1804 |
up): |
| 1805 |
\end{itemize} |
| 1806 |
\begin{centred} |
| 1807 |
\verb`\eval{ 0.12345678912345678912 }[19]` $\Longrightarrow$ \eval{ 0.12345678912345678912 }[19]\medskip{} |
| 1808 |
|
| 1809 |
\verb`\eval{ 1.12345678912345678912 }[19]` $\Longrightarrow$ \eval{ 1.12345678912345678912 }[19] |
| 1810 |
\end{centred} |
| 1811 |
\begin{itemize} |
| 1812 |
\item Now I add ten zeros after the decimal point, meaning that all $19$ |
| 1813 |
decimal places specified by the rounding value can be displayed in |
| 1814 |
the first since the ten zeros do not contribute to the significant |
| 1815 |
figures, but in the second, by changing the figure before the decimal |
| 1816 |
point to $1$, the ten zeros added \emph{do} contribute to the significant |
| 1817 |
figures: |
| 1818 |
\end{itemize} |
| 1819 |
\begin{centred} |
| 1820 |
\verb`\eval{ 0.0000000000123456789 }[19]` $\Longrightarrow$ \eval{ 0.0000000000123456789 }[19]\medskip{} |
| 1821 |
|
| 1822 |
\verb`\eval{ 1.0000000000123456789 }[19]` $\Longrightarrow$ \eval{ 1.0000000000123456789 }[20] |
| 1823 |
\end{centred} |
| 1824 |
\begin{itemize} |
| 1825 |
\item Lastly, I have added $9$ digits before the decimal point: |
| 1826 |
\end{itemize} |
| 1827 |
\begin{centred} |
| 1828 |
\verb`\eval{ 987654321.123456789 }[19]` $\Longrightarrow$ \eval{ 987654321.123456789 }[19] |
| 1829 |
\end{centred} |
| 1830 |
In all cases, no more than $16$ \emph{significant} figures are displayed, |
| 1831 |
although the number of decimal places displayed may exceed $16$. |
| 1832 |
|
| 1833 |
It is possible to use \emph{negative} rounding values. Such a value |
| 1834 |
replaces the specified number of digits \emph{before} the decimal |
| 1835 |
point with zeros. |
| 1836 |
\begin{centred} |
| 1837 |
\verb`\eval{ 987654321.123456789 }[-4]` $\Longrightarrow$ \eval{ 987654321.123456789 }[-4] |
| 1838 |
\end{centred} |
| 1839 |
A rounding value of $0$ rounds to the nearest integer: |
| 1840 |
\begin{centred} |
| 1841 |
\verb`\eval{ 987654321.123456789 }[0]` $\Longrightarrow$ \eval{ 987654321.123456789 }[0] |
| 1842 |
\end{centred} |
| 1843 |
If you wish to change the \emph{default} rounding value from $6$ |
| 1844 |
to some other value, this can be done by means of the package option |
| 1845 |
\verb`rounding`. For example, calling \texttt{numerica} like this, |
| 1846 |
\begin{verbatim} |
| 1847 |
\usepackage[rounding=4]{numerica} |
| 1848 |
\end{verbatim} |
| 1849 |
will make $4$ the new default rounding value. |
| 1850 |
|
| 1851 |
The rounding value also plays a part in how closely fraction-form |
| 1852 |
output approximates the calculated result (§\ref{subsec:evalFraction-form-output}), |
| 1853 |
and how many terms are used to evaluate `infinite' sums (§\ref{tab:calcStoppingCriterionSettings}). |
| 1854 |
|
| 1855 |
\subsection{Padding with zeros } |
| 1856 |
|
| 1857 |
\label{subsec:evalPadding-with-zeros}A result may contain fewer decimal |
| 1858 |
places than the rounding value specifies, the trailing zeros being |
| 1859 |
suppressed by default (this is how \texttt{l3fp} does it). Sometimes, |
| 1860 |
perhaps for reasons of presentation like aligning columns of figures, |
| 1861 |
it may be desirable to pad results with zeros – we have already met |
| 1862 |
an example at §\ref{subsec:intoMultiFormulaPunctuation}. Padding |
| 1863 |
is achieved by inserting an asterisk into the final optional argument |
| 1864 |
of the \verb`\eval` command: |
| 1865 |
\begin{centred} |
| 1866 |
\verb`\eval{ 1/4 }[4]` $\Longrightarrow$ \eval{ 1/4 }[4],\medskip{} |
| 1867 |
|
| 1868 |
\verb`\eval{ 1/4 }[4*],\quad \eval{ 1/4 }[*4]` $\Longrightarrow$ |
| 1869 |
\eval{ 1/4 }[4*],\quad\eval{ 1/4 }[*4]. |
| 1870 |
\end{centred} |
| 1871 |
As you can see, it doesn't matter if there is a rounding value also |
| 1872 |
present (the example at §\ref{subsec:intoMultiFormulaPunctuation}, |
| 1873 |
using the default rounding value, had none), nor the order in which |
| 1874 |
the asterisk and rounding value are entered. |
| 1875 |
|
| 1876 |
\subsection{Scientific notation } |
| 1877 |
|
| 1878 |
\label{subsec:evalScientificNotation} \texttt{numerica} can output |
| 1879 |
numbers in various scientific notations. Entering \verb`x` (lower |
| 1880 |
case) in the number-format option produces the `pure' form: |
| 1881 |
\begin{centred} |
| 1882 |
\verb`\eval[pp,ff]{ 2^{256}, 2^{-256} }[x]` $\Longrightarrow$ $\vsp$\eval[pp,ff]{ 2^{256}, 2^{-256} }[x]. |
| 1883 |
\end{centred} |
| 1884 |
With the default rounding value, as here, one digit is shown before |
| 1885 |
the decimal point and $6$ digits after. Alternatively, you can enter |
| 1886 |
some other letter in the number-format option, generally \verb`e`, |
| 1887 |
to generate a less elegant, more utilitarian output: |
| 1888 |
\begin{centred} |
| 1889 |
\verb`\eval[pp,ff]{ 3^{81}, e^{-81} }[e]` $\Longrightarrow$ \eval[pp,ff]{ 3^{81}, 3^{-81} }[e]. |
| 1890 |
\end{centred} |
| 1891 |
Other letters sometimes used for this purpose are \verb`E`, \verb`d` |
| 1892 |
and \verb`D`, but \texttt{numerica} will accept \emph{any} letter |
| 1893 |
(although \verb`x` and \verb`t` produce distinctive output). The |
| 1894 |
`e' in the output is the \emph{exponent mark}, separating the \emph{significand} |
| 1895 |
($1.234$) from the \emph{exponent} ($3$). In scientific notation, |
| 1896 |
the significand always has one \emph{non-zero} digit before the decimal |
| 1897 |
point (except for $0$ itself). |
| 1898 |
|
| 1899 |
For scientific notation the rounding value still means the number |
| 1900 |
of decimal places displayed – by default, $6$. This can mean different |
| 1901 |
numbers of digits being shown from those displayed in `ordinary' |
| 1902 |
decimal form. Compare \verb`\eval{ 123.456789 }` $\Longrightarrow$ |
| 1903 |
\eval{ 123.456789 }, where nine significant figures are displayed, |
| 1904 |
with \verb`\eval{ 123.456789 }[e]` $\Longrightarrow$ \eval{ 123.456789 }[e] |
| 1905 |
where only seven are, one before the decimal point and six after. |
| 1906 |
In the other direction, only five significant figures are shown in |
| 1907 |
the `ordinary' decimal form \verb`\eval{ 0.0123456789 }` $\Longrightarrow$ |
| 1908 |
\eval{ 0.0123456789 }, whereas in scientific notation \verb`\eval{ 0.0123456789 }[e]` |
| 1909 |
$\Longrightarrow$ \eval{ 0.0123456789 }[e] once again seven are |
| 1910 |
on display. |
| 1911 |
|
| 1912 |
Negative rounding values are pointless for scientific notation. |
| 1913 |
|
| 1914 |
Sometimes letters other than `e' are used for the exponent mark, |
| 1915 |
particularly `E' or `d' or `D'. |
| 1916 |
\begin{centred} |
| 1917 |
\verb`\eval{$ 1/123456789 $}[4d]`\texttt{ $\Longrightarrow$} \eval{$ 1/123456789 $}[4d]. |
| 1918 |
\end{centred} |
| 1919 |
But when \verb`x` is inserted in the trailing optional argument, |
| 1920 |
the output is in the form $d_{0}.d_{1}\ldots d_{m}\times10^{n}$ (except |
| 1921 |
when $n=0$), where each $d_{i}$ denotes a digit. |
| 1922 |
\begin{centred} |
| 1923 |
\verb`\eval{$ 1/123456789 $}[4x*]`\texttt{ $\Longrightarrow$ }\eval{$ 1/123456789 $}[4x*] . |
| 1924 |
\end{centred} |
| 1925 |
As you can see, padding with zeros still applies in scientific notation |
| 1926 |
and is activated, as before, with an asterisk in the number-format |
| 1927 |
option. |
| 1928 |
|
| 1929 |
The requirements of tables leads to another form of scientific notation. |
| 1930 |
Placing \verb`t` in the trailing argument turns on this table-ready |
| 1931 |
form: |
| 1932 |
\begin{centred} |
| 1933 |
\verb`\eval{$ 1/123456789 $}[4t*]`\texttt{ $\Longrightarrow$ }\eval{$ 1/123456789 $}[4t*]. |
| 1934 |
\end{centred} |
| 1935 |
This is discussed more fully in the documentation for the \texttt{numerica-tables} |
| 1936 |
package. |
| 1937 |
|
| 1938 |
The order in which items are entered in the number-format option doesn't |
| 1939 |
matter: |
| 1940 |
\begin{centred} |
| 1941 |
\verb`\eval{$ 1/125 $}[*e4]` $\Longrightarrow$ \eval{$ 1/125 $}[*e4],\medskip{} |
| 1942 |
|
| 1943 |
\verb`\eval{$ 1/125 $}[4e*]` $\Longrightarrow$ \eval{$ 1/125 $}[4e*]. |
| 1944 |
\end{centred} |
| 1945 |
|
| 1946 |
\subsubsection{Numbers in the interval \texttt{{[}1,10)}} |
| 1947 |
|
| 1948 |
\label{subsec:evalSciNotation1to10}Usually when scientific notation |
| 1949 |
is being used, numbers with magnitude in the interval $[1,10)$ are |
| 1950 |
rendered in their normal decimal form, $3.14159$ and the like. Occasionally |
| 1951 |
it may be desired to present numbers in this range in scientific notation |
| 1952 |
(this can be the case in tables where the alignment of a column of |
| 1953 |
figures might be affected). \texttt{numerica} offers a means of extending |
| 1954 |
scientific notation to numbers in this range by repeating the letter |
| 1955 |
chosen as the exponent mark in the trailing optional argument. |
| 1956 |
\begin{centred} |
| 1957 |
\verb`\eval{$ \pi $}[4xx]` $\Longrightarrow$ \eval{$ \pi $}[4xx] |
| 1958 |
\end{centred} |
| 1959 |
|
| 1960 |
\subsubsection{\textbackslash eval{*} and scientific notation} |
| 1961 |
|
| 1962 |
Starring the \verb`\eval` command gives a number-only result which |
| 1963 |
can be presented in scientific notation: |
| 1964 |
\begin{centred} |
| 1965 |
\verb`\eval*{ \pi^\pi }[e]` $\Longrightarrow$ \eval*{ \pi^\pi }[e] |
| 1966 |
\end{centred} |
| 1967 |
There is one catch: if you substitute \verb`x` for \verb`e` here, |
| 1968 |
compilation will halt and \LaTeX{} will state \verb`Missing $ inserted.` |
| 1969 |
This is because an \verb`x` in the number-format option means a \verb`\times` |
| 1970 |
in the output and that requires a math environment to display. It |
| 1971 |
is up to you, as the user, to provide the necessary delimiters \emph{outside} |
| 1972 |
the \verb`\eval*` command. (Alternatively, use \verb`\eval` without |
| 1973 |
the star and without any delimiters whatever. Dollar signs are automatically |
| 1974 |
placed around the result.) |
| 1975 |
|
| 1976 |
\subsection{Fraction-form output} |
| 1977 |
|
| 1978 |
\label{subsec:evalFraction-form-output}The \verb`\eval` command |
| 1979 |
can output numbers in fraction form by including in the number-format |
| 1980 |
specification either one or two slashes: |
| 1981 |
\begin{centred} |
| 1982 |
\verb`\eval[pp,ff]{0.333333, 1.875}[4/]` $\Longrightarrow$ \eval[pp,ff]{0.333333,1.875}[4/];\medskip{} |
| 1983 |
|
| 1984 |
\verb`\eval[pp,ff]{\pi, e}[2//]` $\Longrightarrow$ \eval[pp,ff]{\pi, e}[2//]. |
| 1985 |
\end{centred} |
| 1986 |
A single slash results in a textstyle slash fraction; two slashes |
| 1987 |
produce a \verb`\frac`-tion. Always, numerator and denominator are |
| 1988 |
integers. The rounding value determines how close the fraction is |
| 1989 |
to the calculated result. Consider |
| 1990 |
\begin{verbatim} |
| 1991 |
\eval{\pi}[1//],\quad \eval{\pi}[2//], |
| 1992 |
\eval{\pi}[3//],\quad \eval{\pi}[6//]. |
| 1993 |
\end{verbatim} |
| 1994 |
$\Longrightarrow$ \eval{\pi}[1//],\quad\eval{\pi}[2//],\quad |
| 1995 |
\eval{\pi}[3//],\quad\eval{\pi}[6//], \medskip{} |
| 1996 |
|
| 1997 |
\noindent and compare these results against $\pi$: |
| 1998 |
\begin{verbatim} |
| 1999 |
\eval[env=alignat*,pp,p=.,ff]{ \pi-\tfrac{19}6, |
| 2000 |
\pi-\tfrac{22}7, \pi-\tfrac{267}{85}, |
| 2001 |
\pi-\tfrac{355}{113} }[8*] |
| 2002 |
\end{verbatim} |
| 2003 |
$\Longrightarrow$ \eval[env=alignat*,pp,p=.,ff]{ \pi-\tfrac{19}6, |
| 2004 |
\pi-\tfrac{22}7, \pi-\tfrac{267}{85}, |
| 2005 |
\pi-\tfrac{355}{113} }[8*]In each case the fraction approximates the correct result to at least |
| 2006 |
as many decimal places as specified in the rounding value – the difference |
| 2007 |
between pi and the fraction is zero to that rounding value. Sometimes, |
| 2008 |
as evident with the familiar approximations $22/7$ and $355/113$, |
| 2009 |
the difference is zero to twice the number of digits in the denominator |
| 2010 |
– these are exceptionally good approximations. |
| 2011 |
|
| 2012 |
The example illustrates the use of an \verb`alignat*` environment |
| 2013 |
to ensure the results line up, including taking account of the minus |
| 2014 |
signs. |
| 2015 |
|
| 2016 |
What happens if I seek a still more accurate approximation – say to |
| 2017 |
(at least) seven places of decimals? The result is a message: |
| 2018 |
\begin{centred} |
| 2019 |
\verb`\eval{\pi}[7//]` $\Longrightarrow$ \eval{ \pi}[7//] |
| 2020 |
\end{centred} |
| 2021 |
By default \texttt{numerica} searches denominators from 1 to $200$ |
| 2022 |
before halting the search and producing the message. The program offers |
| 2023 |
two settings that may assist here. The first is the \verb`/max` setting |
| 2024 |
which allows the user to specify the maximum denominator tried, e.g.\ putting |
| 2025 |
\verb`/max = 1000` in the settings option of the \verb`\eval` command |
| 2026 |
would allow the search to continue up to a denominator of $1000$. |
| 2027 |
But perhaps that means waiting too long? The user can also specify |
| 2028 |
an initial value to start searching from with the \verb`/min` setting, |
| 2029 |
by entering in the settings option, say, \verb`/min = 500`, which |
| 2030 |
would mean searching from an initial denominator of $500$. By default |
| 2031 |
\verb`/min = 1` and \verb`/max = 200`. |
| 2032 |
|
| 2033 |
To test the settings equate both to $113$: |
| 2034 |
\begin{centred} |
| 2035 |
\verb`\eval[/min=113,/max=113]{\pi}[6//]` $\Longrightarrow$ \eval[/min=113,/max=113]{\pi}[6//]. |
| 2036 |
\end{centred} |
| 2037 |
Performing a similar exercise with other irrational numbers like $e$, |
| 2038 |
$\phi$ and $\surd2$, one realizes just how good this particular |
| 2039 |
approximation is. |
| 2040 |
|
| 2041 |
\subsubsection{Refining the form of fraction} |
| 2042 |
|
| 2043 |
The form of the fraction output can be refined by adding a qualifying |
| 2044 |
letter to the single or double slash in the number format option. |
| 2045 |
|
| 2046 |
By adding an \verb`s` after a single slash, \verb`/s`, it is possible |
| 2047 |
to get scriptstyle numbers in a slash fraction. If the \texttt{xfrac} |
| 2048 |
package\footnote{\texttt{xfrac} is included in the \texttt{l3packages} bundle.} |
| 2049 |
has been loaded (as it has been for the present document), then the |
| 2050 |
fraction takes this form: |
| 2051 |
\begin{centred} |
| 2052 |
\verb`\eval{$ \pi $}[2/s]` $\Longrightarrow$ \eval{$ \pi $}[2/s]. |
| 2053 |
\end{centred} |
| 2054 |
This is the result of the \verb`\sfrac` command from the \texttt{xfrac} |
| 2055 |
package. If that package had not been loaded then the fraction would |
| 2056 |
have been presented in the form $\scriptstyle 22/7$. |
| 2057 |
|
| 2058 |
By adding a \verb`t` or \verb`d` after two slashes, \verb`//t` |
| 2059 |
or \verb`//d`, it is possible to force textstyle or displaystyle |
| 2060 |
output by means of \texttt{amsmath}'s \verb`\tfrac` or \verb`\dfrac` |
| 2061 |
commands (in place of \verb`\frac`). For example, even in a displaystyle |
| 2062 |
environment, |
| 2063 |
\begin{centred} |
| 2064 |
\verb`\eval[p]{\[ \pi \]}[6//t]` $\Longrightarrow$ \eval[p]{\[ \pi \]}[6//t] |
| 2065 |
\end{centred} |
| 2066 |
with the \verb`//t` specification, and similarly, in a textstyle |
| 2067 |
environment you can force a displaystyle fraction with the \verb`//d` |
| 2068 |
specification. |
| 2069 |
|
| 2070 |
\subsection{Boolean output} |
| 2071 |
|
| 2072 |
\label{subsec:evalBoolean-output}\texttt{l3fp} can evaluate comparisons, |
| 2073 |
outputting $0$ if the comparison is false, $1$ if it is true. By |
| 2074 |
entering a question mark, \verb`?`, in the trailing optional argument, |
| 2075 |
you can force \texttt{numerica} to do the same depending as the result |
| 2076 |
of a calculation is zero or not. (The expression being evaluated does |
| 2077 |
not need to be a comparison, \verb`\eval{\pi}[?]` $\Longrightarrow$ |
| 2078 |
\eval{\pi}[?], but comparisons are what this is designed for.) |
| 2079 |
|
| 2080 |
Possible comparison relations are \verb`=`, \verb`<`, \verb`>`, |
| 2081 |
\verb`\ne`, \verb`\neq`, \verb`\ge`, \verb`\geq`, \verb`\le`, |
| 2082 |
\verb`\leq`. Although programming languages use combinations like |
| 2083 |
\verb`<=` or \verb`>=` and, from version 3.0.0 \verb`\eval` will |
| 2084 |
accept these without raising an error, this is not part of mathematical |
| 2085 |
practice. |
| 2086 |
|
| 2087 |
An example of boolean output where the relation is equality exhibits |
| 2088 |
a numerological curiosity: |
| 2089 |
\begin{centred} |
| 2090 |
\verb`\eval[p=.]{\[ \frac1{0.0123456789}=81 \]}[5?]` $\Longrightarrow$ |
| 2091 |
\eval[p=.]{\[ \frac1{0.0123456789}=81 \]}[5?] |
| 2092 |
\end{centred} |
| 2093 |
The expression on the left is to be read as a \emph{question}: `Is |
| 2094 |
$1/0.0123456789$ equal to $81$?', not as a statement; the arrow |
| 2095 |
points to the answer, in this instance $1$, meaning \emph{true}. |
| 2096 |
But notice the $5$ alongside the question mark in the trailing argument. |
| 2097 |
That is critical. Change it to $6$ (or omit it since the default |
| 2098 |
rounding value is $6$) and the outcome is different: |
| 2099 |
\begin{centred} |
| 2100 |
\verb`\eval[p=.]{\[ \frac1{0.0123456789}=81 \]}[6?]` $\Longrightarrow$ |
| 2101 |
\eval[p=.]{\[ \frac1{0.0123456789}=81 \]}[6?] |
| 2102 |
\end{centred} |
| 2103 |
Now the relation is \emph{false}. Evaluating the fraction to more |
| 2104 |
than $6$ places, say to $9$, we can see what is going on: |
| 2105 |
\begin{centred} |
| 2106 |
\verb`\eval{$ 1/0.0123456789 $}[9]` $\Longrightarrow$ \eval{$ 1/0.0123456789 $}[9]. |
| 2107 |
\end{centred} |
| 2108 |
In other words, the question posed by the \verb`?` specification |
| 2109 |
is not `Is $1/0.0123456789$ equal to $81$?' but `Is $1/0.0123456789$ |
| 2110 |
equal to $81$ \emph{to the specified number of decimal places}?' |
| 2111 |
To $5$ decimal places it is; to $6$ decimal places it is not. |
| 2112 |
|
| 2113 |
\subsubsection{Outputting \texttt{T} or \texttt{F}} |
| 2114 |
|
| 2115 |
To my eye, outputting $0$ or $1$ in response to a question like |
| 2116 |
$1/0.0123456789=81$ is confusing. It is easy to change the boolean |
| 2117 |
output from $0,1$ to a more appropriate $F,T$, or \texttt{$\texttt{F,\texttt{T}}$} |
| 2118 |
by duplicating ($F,T$) or triplicating (\texttt{$\texttt{F,\texttt{T}}$}) |
| 2119 |
the question mark in the number-format option. |
| 2120 |
\begin{centred} |
| 2121 |
\verb`\eval[p=.]{\[ \frac1{0.0123456789}=81 \]}[6???]` $\Longrightarrow$ |
| 2122 |
\eval[p=.]{\[ \frac1{0.0123456789}=81 \]}[6???] |
| 2123 |
\end{centred} |
| 2124 |
The default boolean output format is chosen to be $0,1$ in case an |
| 2125 |
\verb`\eval` command is used within another \verb`\eval` command |
| 2126 |
(`nesting'– see Chapter~\ref{sec:miscNesting}~). The inner command |
| 2127 |
needs to output a \emph{numerical} answer. |
| 2128 |
|
| 2129 |
\subsubsection{Rounding error tolerance} |
| 2130 |
|
| 2131 |
\label{subsec:evalToleranceRounding}If at least one of the terms |
| 2132 |
in a comparison is the result of a calculation, then it's value is |
| 2133 |
likely to contain rounding errors. What level of rounding error can |
| 2134 |
we tolerate before such errors interfere with the comparison being |
| 2135 |
made? \texttt{l3fp} tolerates none. It decides the truth or falsity |
| 2136 |
of a comparison to all $16$ significant figures: 1.000 0000 0000 |
| 2137 |
0000 and 1.000 0000 0000 0001 are \emph{not }equal in \texttt{l3fp}. |
| 2138 |
But for most purposes this will be far too severe a criterion. |
| 2139 |
|
| 2140 |
Suppose our comparison relation is $\varrho$, denoting one of =, |
| 2141 |
<, >, \verb`\le`, etc. If $X\rel Y$ then $X-Y\rel Y-Y$, i.e.\ $X-Y\rel0$. |
| 2142 |
This is what \texttt{numerica} does. It takes the right-hand side |
| 2143 |
of the relation from the left-hand side and then compares the \emph{rounded} |
| 2144 |
difference under $\varrho$ to $0$. The rounding value used is the |
| 2145 |
number specified with the question mark in the trailing argument of |
| 2146 |
the \verb`\eval` command or, if no number is present, the default |
| 2147 |
rounding value (`out of the box' this is $6$). Thus, in a recent |
| 2148 |
example, $1/0.0123456789-81$ when rounded to $5$ decimal places |
| 2149 |
is $0.00000$, indistinguishable from zero at this rounding value; |
| 2150 |
hence the equality $1/0.0123456789=81$ is true. But when rounded |
| 2151 |
to $6$ places it is $0.000001$ which \emph{is} distinguishable from |
| 2152 |
zero and so the equality is false. Truth or falsity depends on the |
| 2153 |
rounding value. |
| 2154 |
|
| 2155 |
When dealing with numbers generated purely mathematically, rounding |
| 2156 |
values of $5$ or $6$ are likely to be too small. More useful would |
| 2157 |
be rounding values closer to \texttt{l3fp}'s $16$ – perhaps $14$? |
| 2158 |
– depending on how severe the calculations are that generate the numbers. |
| 2159 |
However if the numbers we are dealing with come from outside mathematics, |
| 2160 |
from practical experiments perhaps, then even a rounding value of |
| 2161 |
$5$ or $6$ may be too large. |
| 2162 |
|
| 2163 |
\noindent{}% |
| 2164 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 2165 |
\begin{shaded}% |
| 2166 |
Mathematically, the claim that $X=Y$ at a rounding value $n$ is |
| 2167 |
the claim that |
| 2168 |
\[ |
| 2169 |
\abs{X-Y}\le5\times10^{-(n+1)}. |
| 2170 |
\] |
| 2171 |
since this rounds \emph{down} to zero at $n$ places of decimals. |
| 2172 |
This gives a more accurate test of equality than doing things in the |
| 2173 |
opposite order – rounding each number first and then taking the difference. |
| 2174 |
One might, for instance, have numbers like $X=0.12345$, $Y=0.12335$. |
| 2175 |
Rounding to $n=4$ places, both round to $0.1234$ and yet the difference |
| 2176 |
between them is $0.0001$ – they are distinguishable numbers to $4$ |
| 2177 |
places of decimals. This is why \texttt{numerica} forms the difference |
| 2178 |
\emph{before }doing the rounding.\end{shaded}% |
| 2179 |
\end{minipage} |
| 2180 |
|
| 2181 |
\subsubsection{And, Or, Not} |
| 2182 |
|
| 2183 |
For logical And \LaTeX{} provides the symbols \verb`\wedge` and \verb`\land`, |
| 2184 |
both displaying as $\land$, but \texttt{numerica} adds thin spaces |
| 2185 |
( \verb`\,` ) around the symbol for \verb`\land` (copying the package |
| 2186 |
\texttt{gn-logic14.sty}). For logical Or \LaTeX{} provides the symbols |
| 2187 |
\verb`\vee` and \verb`\lor`, both displaying as $\lor$, but again |
| 2188 |
\texttt{numerica} adds thin spaces around the symbol for \verb`\lor`. |
| 2189 |
\begin{centred} |
| 2190 |
\verb`\eval{$ 1<2 \wedge 2<3 $}[??]` $\Longrightarrow$ \eval{$ 1<2 \wedge 2<3 $}[??], |
| 2191 |
|
| 2192 |
\verb`\eval{$ 1<2 \land 2<3 $}[???]` $\Longrightarrow$ \eval{$ 1<2 \land 2<3 $}[???]. |
| 2193 |
\end{centred} |
| 2194 |
To my eye the second of these with its increased space around the |
| 2195 |
wedge symbol displays the meaning of the overall expression better |
| 2196 |
than the first. Both And and Or have equal precedence; in cases of |
| 2197 |
ambiguity the user needs to parenthesize as necessary to clarify what |
| 2198 |
is intended. |
| 2199 |
|
| 2200 |
\LaTeX{} provides two commands for logical Not, \verb`\neg` and \verb`\lnot`, |
| 2201 |
both displaying as $\lnot$ . Not binds tightly to its argument: |
| 2202 |
\begin{centred} |
| 2203 |
\verb`\eval{$ \lnot A \land B $}[A=0,B=0]` $\Longrightarrow$ \eval{$ \lnot A \land B $}[A=0,B=0]. |
| 2204 |
\end{centred} |
| 2205 |
Here \verb`\lnot` acts only on the $A$; if it had acted on $A\land B$ |
| 2206 |
as a whole the result would have been different: |
| 2207 |
\begin{centred} |
| 2208 |
\verb`\eval{$ \lnot(A \land B) $}[A=0,B=0]` $\Longrightarrow$ \eval{$ \lnot(A \land B) $}[A=0,B=0]. |
| 2209 |
\end{centred} |
| 2210 |
For a little flourish, I evaluate a more complicated logical statement:\footnote{Quoting from an article in \emph{Quanta Magazine} (August 2020) by |
| 2211 |
Kevin Hartnett: `Let’s say you and two friends are planning a party. |
| 2212 |
The three of you are trying to put together the guest list, but you |
| 2213 |
have somewhat competing interests. Maybe you want to either invite |
| 2214 |
Avery or exclude Kemba. One of your co-planners wants to invite Kemba |
| 2215 |
or Brad or both of them. Your other co-planner, with an ax to grind, |
| 2216 |
wants to leave off Avery or Brad or both of them. Given these constraints, |
| 2217 |
you could ask: Is there a guest list that satisfies all three party |
| 2218 |
planners?' I have written $C$ for Kemba, $A$ and $B$ for Avery |
| 2219 |
and Brad.} |
| 2220 |
\begin{verbatim} |
| 2221 |
\eval{$(A\lor\lnot C)\land(C\lor B)\land |
| 2222 |
(\lnot A\lor\lnot B)$}[A=1,B=0,C=1][???] |
| 2223 |
\end{verbatim} |
| 2224 |
$\Longrightarrow$ \eval{$(A\lor\lnot C)\land(C\lor B)\land |
| 2225 |
(\lnot A\lor\lnot B)$}[A=1,B=0,C=1][???]. |
| 2226 |
|
| 2227 |
\subsubsection{Chains of comparisons} |
| 2228 |
|
| 2229 |
\texttt{numerica} can handle chains of comparisons like $1<2<1+2<5-1$. |
| 2230 |
`Behind the scenes' it inserts logical And-s into the chain, $1<2\land2<1+2\land1+2<5-1$, |
| 2231 |
and evaluates the modified expression: |
| 2232 |
\begin{centred} |
| 2233 |
\verb`\eval{$ 1<2<1+2<5-1 $}[???]` $\Longrightarrow$ \eval{$ 1<2<1+2<5-1 $}[???]. |
| 2234 |
\end{centred} |
| 2235 |
|
| 2236 |
\subsubsection{\texttt{amssymb} comparison symbols} |
| 2237 |
|
| 2238 |
\label{subsec:evalAmssymb-comparisons}\texttt{numerica} accepts some |
| 2239 |
alternative symbols for the basic comparison relations from the \texttt{amssymb} |
| 2240 |
package provided that package is loaded, i.e.\ the preamble of your |
| 2241 |
document includes the statement |
| 2242 |
\begin{verbatim} |
| 2243 |
\usepackage{amssymb} |
| 2244 |
\end{verbatim} |
| 2245 |
The variants from this package are: \verb`\leqq` ( $\leqq$ ), \verb`\leqslant` |
| 2246 |
( $\leqslant$ ), \verb`\geqq` (~$\geqq$~), and \verb`\geqslant` |
| 2247 |
( $\geqslant$ ).\footnote{No, that is not \texttt{eggplant}.} There |
| 2248 |
are also negations: \verb`\nless` ( $\nless$ ), \verb`\nleq` (~$\nleq$~), |
| 2249 |
\verb`\nleqq` ( $\nleqq$ ), \verb`\nleqslant` ( $\nleqslant$ ), |
| 2250 |
\verb`\ngtr` ( $\ngtr$ ), \verb`\ngeq` ( $\ngeq$ ), \verb`\ngeqq` |
| 2251 |
( $\ngeqq$ ), \verb`\ngeqslant` ( $\ngeqslant$ ). |
| 2252 |
|
| 2253 |
\chapter{Calculational details} |
| 2254 |
|
| 2255 |
\section{Arithmetic} |
| 2256 |
|
| 2257 |
\label{sec:calcArithmetic}Addition, subtraction, multiplication, |
| 2258 |
division, square roots, \emph{$n$}-th roots, and exponentiating (raising |
| 2259 |
to a power) are all available. |
| 2260 |
|
| 2261 |
Multiplication can be rendered explicitly with an asterisk, |
| 2262 |
\begin{centred} |
| 2263 |
\verb`\eval{$ 9*9 $}` $\Longrightarrow$ \eval{$ 9*9 $}, |
| 2264 |
\end{centred} |
| 2265 |
but that's ugly. More elegant is to use \verb`\times`: |
| 2266 |
\begin{centred} |
| 2267 |
\verb`\eval{$ 9\times9 $}` $\Longrightarrow$ \eval{$ 9\times9 $}. |
| 2268 |
\end{centred} |
| 2269 |
\verb`\cdot` is also available and in many cases juxtaposition alone |
| 2270 |
suffices: |
| 2271 |
\begin{centred} |
| 2272 |
\verb`\eval{$ \surd2\surd2 $}` $\Longrightarrow$ \eval{$ \surd2\surd2 $}, |
| 2273 |
|
| 2274 |
\verb`\eval{$ ab $}[a=123,b=1/123]` $\Longrightarrow$ \eval{$ ab $}[a=123,b=1/123]. |
| 2275 |
\end{centred} |
| 2276 |
Division can be rendered in multiple ways too. Using a comma list |
| 2277 |
for a multi-formula evaluation (and the \verb`ff` setting), |
| 2278 |
\begin{centred} |
| 2279 |
\verb`\eval[p=.,ff]{\[ 42/6, 42\div6, \frac{42}6 \]}` $\Longrightarrow$ |
| 2280 |
\eval[p=.,ff]{\[ 42/6, 42\div6, \frac{42}6 \]} |
| 2281 |
\end{centred} |
| 2282 |
In a displaystyle environment, \verb`\frac` displays as shown. In |
| 2283 |
a textstyle environment it displays as $\frac{42}{6}$. If you want |
| 2284 |
to force a textstyle display, even in a displaystyle environment, |
| 2285 |
use \verb`\tfrac` (from \texttt{amsmath}) and, conversely, if you |
| 2286 |
want to force a displaystyle display, even in a textstyle environment, |
| 2287 |
use \verb`\dfrac`. If the package \texttt{xfrac} is loaded, then |
| 2288 |
slash fractions are rendered with scriptstyle numbers, \verb`\eval[p]{\[ \sfrac{42}{6} \]}` |
| 2289 |
$\Longrightarrow$ \eval[p]{\[ \sfrac{42}{6} \]} even in a displaystyle |
| 2290 |
environment. If \verb`xfrac` is not loaded, then \texttt{numerica} |
| 2291 |
defines \verb`\sfrac` to expand to a scriptstyle slash fraction, |
| 2292 |
e.g. ${\scriptstyle 42/6}$. |
| 2293 |
|
| 2294 |
Note that since juxtaposition means multiplication, a combination |
| 2295 |
like $42\tfrac{1}{6}$\texttt{ }also evaluates to $7$ within an \verb`\eval` |
| 2296 |
command; it does not mean `forty two and a sixth'. Such fractions |
| 2297 |
need to be entered as improper fractions to evaluate correctly – for |
| 2298 |
instance, `two and a half' entered as $\tfrac{5}{2}$ (as one does |
| 2299 |
anyway in mathematical expressions because of the ambiguity in a form |
| 2300 |
like $2\tfrac{1}{2}$). |
| 2301 |
|
| 2302 |
Powers are indicated with the superscript symbol \verb`^`. It is |
| 2303 |
clear from the braced \LaTeX{} grouping that a `tower' of superscripts |
| 2304 |
is evaluated from the top down. Thus $3^{2^{3}}$is $3^{8}$ $(=9^{4})$, |
| 2305 |
not $9^{3}=\eval{9^{3}}$: |
| 2306 |
\begin{centred} |
| 2307 |
\verb` \eval{$ 3^{2^3} $}` $\Longrightarrow$ \eval{$ 3^{2^3} $} . |
| 2308 |
\end{centred} |
| 2309 |
|
| 2310 |
\section{Square roots and $n$-th roots} |
| 2311 |
|
| 2312 |
\label{sec:calcSquareRootsEtc}Let us check that 3, 4, 5 and 5, 12, |
| 2313 |
13 really are Pythagorean triples (I use \verb`\sqrt` in the first, |
| 2314 |
\verb`\surd` in the second): |
| 2315 |
\begin{centred} |
| 2316 |
\verb`\eval[ff]{\[ \sqrt{3^2+4^2}, \surd(5^2+12^2) \]}` $\Longrightarrow$ |
| 2317 |
\eval[ff]{\[\sqrt{3^{2}+4^{2}}, \surd(5^2+12^2)\]} |
| 2318 |
\end{centred} |
| 2319 |
The \verb`\sqrt` command has an optional argument which can be used |
| 2320 |
for extracting $n$-th roots of a number. In \texttt{numerica}, when |
| 2321 |
used with the \verb`\sqrt` command, $n$ is assumed to be a \emph{positive |
| 2322 |
integer}, in practice generally a \emph{small} positive integer like |
| 2323 |
$3$ or $4$. |
| 2324 |
\begin{centred} |
| 2325 |
\verb`\eval{$ \sqrt[4]{81} $}` $\Longrightarrow$ \eval{$ \sqrt[4]{81} $},\medskip{} |
| 2326 |
|
| 2327 |
\verb`\eval{$ \sqrt[n]{125} $}[n=\floor{\pi}]` $\Longrightarrow$ |
| 2328 |
\eval{$ \sqrt[n]{125} $}[n=\floor{\pi}]. |
| 2329 |
\end{centred} |
| 2330 |
For displaystyle expressions, the \verb`\sqrt` sign grows to accommodate |
| 2331 |
the extra vertical height; the \verb`\surd` sign doesn't. Here is |
| 2332 |
an example which uses the \verb`\mleft`, \verb`\middle`, \verb`\mright` |
| 2333 |
commands from the package \texttt{mleftright} (requiring \verb`\usepackage{mleftright}` |
| 2334 |
in the preamble of the present document). In the formula I have enlarged |
| 2335 |
the $3$ of the cube root from the default \verb`\scriptscriptstyle` |
| 2336 |
visible in the examples above to a more appropriately sized \verb`\scriptstyle`. |
| 2337 |
\begin{verbatim} |
| 2338 |
\eval[p=.]{\[ \sqrt[\scriptstyle3]{\! |
| 2339 |
\mleft(\frac AD\middle/\frac BC\mright)} |
| 2340 |
\]}[A=729,B=81,C=9,D=3] |
| 2341 |
\end{verbatim} |
| 2342 |
$\Longrightarrow$ \eval[p=.]{\[ \sqrt[\scriptstyle3]{\! |
| 2343 |
\mleft(\frac AD\middle/\frac BC\mright)} |
| 2344 |
\]}[A=729,B=81,C=9,D=3] |
| 2345 |
|
| 2346 |
As implemented in \texttt{numerica}, $n$-th roots found using \verb`\sqrt[n]` |
| 2347 |
are restricted to positive integral \verb`n`. This raises an interesting |
| 2348 |
question: if the `$n$' of an $n$-th root is the result of a calculation, |
| 2349 |
what happens with rounding errors? The calculation may not produce |
| 2350 |
an \emph{exact} integer. (This problem also arises with factorials; |
| 2351 |
see §\ref{sec:calcFactorialsBinom}.) The solution employed in version |
| 2352 |
3.0.0 of \texttt{numerica} is simply to round to the nearest integer. |
| 2353 |
This is simpler than in previous versions where an error could be |
| 2354 |
raised in some rare situations. But it does mean that, e.g.\ \eval{$\sqrt[\pi]{27}$}, |
| 2355 |
since $\pi$ rounds to $3$. In such cases, for the sake of the reader, |
| 2356 |
a user should make the rounding explicit – as I did in an example |
| 2357 |
above, wrapping $\pi$ in the \verb`\floor` command. |
| 2358 |
|
| 2359 |
\subsection{$n$-th roots of negative numbers} |
| 2360 |
|
| 2361 |
Odd (in the sense of `not even') positive integral roots of \emph{negative} |
| 2362 |
numbers are available with \verb`\sqrt`, |
| 2363 |
\begin{centred} |
| 2364 |
\verb`\eval[p=.,ff]{\[ \sqrt[3]{-125}, \sqrt[3]{-3.375} \]}` $\Longrightarrow$\eval[p=.,ff]{\[ \sqrt[3]{-125}, \sqrt[3]{-3.375} \]} |
| 2365 |
\end{centred} |
| 2366 |
|
| 2367 |
\subsection{Powers of $n$-th roots} |
| 2368 |
|
| 2369 |
In previous versions of \texttt{numerica}, raising an $n$-th root |
| 2370 |
to a power when $n\ne2$ gave a false answer unless the $n$-th root |
| 2371 |
was parenthesized before raising to the power. From version 3.0.0, |
| 2372 |
the parentheses are unnecessary (but notice the thin space inserted |
| 2373 |
before the $3$ in the second example to improve the visual appearance): |
| 2374 |
\begin{centred} |
| 2375 |
\verb`\eval[p=.,ff]{\[ \bigl(\sqrt[3]{-8}\,\bigr)^3, \sqrt[3]{-8}^{\,3} \]}` |
| 2376 |
$\Longrightarrow$ \eval[p=.,ff]{\[ \bigl(\sqrt[3]{-8}\,\bigr)^3, \sqrt[3]{-8}^{\,3} \]} |
| 2377 |
\end{centred} |
| 2378 |
|
| 2379 |
\subsection{Inverse integer powers } |
| 2380 |
|
| 2381 |
Of course to find an $n$-th root we can also raise to the inverse |
| 2382 |
power, |
| 2383 |
\begin{centred} |
| 2384 |
\verb`\eval{$ 81^{1/4} $}` $\Longrightarrow$ \eval{$ 81^{1/4} $}. |
| 2385 |
\end{centred} |
| 2386 |
However, raising a \emph{negative} number to an inverse power generates |
| 2387 |
an error even when, mathematically, it should not. This matter, which |
| 2388 |
is a product of floating point representation of numbers, is discussed |
| 2389 |
below in §\ref{subsec:errorsInverse-powers}. |
| 2390 |
|
| 2391 |
\section{Precedence and parentheses} |
| 2392 |
|
| 2393 |
The usual precedence rules apply: multiplication and division bind |
| 2394 |
equally strongly and more strongly than addition and subtraction which |
| 2395 |
bind equally stongly. Exponentiating binds most strongly. Evaluation |
| 2396 |
occurs from the left. |
| 2397 |
\begin{centred} |
| 2398 |
\verb`\eval{$ 4+5\times6+3 $}` $\Longrightarrow$ \eval{$ 4+5\times6+3 $},\medskip{} |
| 2399 |
|
| 2400 |
\verb`\eval{$ 6\times10^3/2\times10^2 $}` $\Longrightarrow$ \eval{$ 6\times10^3/2\times10^2 $}, |
| 2401 |
\end{centred} |
| 2402 |
which may not be what was intended. Parentheses (or brackets or braces) |
| 2403 |
retrieve the situation: |
| 2404 |
\begin{centred} |
| 2405 |
\verb`\eval{$ (4+5)(6+3) $}` $\Longrightarrow$ \eval{$ (4+5)(6+3) $},\medskip{} |
| 2406 |
|
| 2407 |
\verb`\eval{$ (6\times10^3)/(2\times10^2) $}` $\Longrightarrow$ |
| 2408 |
\eval{$ (6\times10^3)/(2\times10^2) $}. |
| 2409 |
\end{centred} |
| 2410 |
When one writes $-4^{2}$ it is not clear what is intended: is it |
| 2411 |
$-(4^{2})$ or $(-4)^{2}$? In \texttt{numerica} exponentiating binds |
| 2412 |
most strongly; negative values must therefore be parenthesized when |
| 2413 |
raised to a power. Thus |
| 2414 |
\begin{centred} |
| 2415 |
\verb`\eval[pp,ff]{$ -4^2, (-4)^2 $}` $\Longrightarrow$ \eval[pp,ff]{$ -4^2, (-4)^2 $}. |
| 2416 |
\end{centred} |
| 2417 |
|
| 2418 |
\subsection{Command-form brackets} |
| 2419 |
|
| 2420 |
\label{subsec:calcCommandBrackets}Note that brackets of all three |
| 2421 |
kinds are available also in command form: \verb`\lparen \rparen` |
| 2422 |
(from \texttt{mathtools}) for \verb`( )`, \verb`\lbrack \rbrack` |
| 2423 |
for \verb`[ ]`, and \verb`\lbrace \rbrace` for \verb`\{ \}`. |
| 2424 |
|
| 2425 |
\subsection{Modifiers\texttt{ (\textbackslash left}, \texttt{\textbackslash right}, |
| 2426 |
\texttt{\textbackslash big}, etc.)} |
| 2427 |
|
| 2428 |
The \verb`\left` and \verb`\right` modifiers and also the series |
| 2429 |
of \verb`\big...` modifiers\texttt{ }(\texttt{\textbackslash}\verb`bigl \bigr`; |
| 2430 |
\verb`\Bigl \Bigr`; \verb`\biggl \biggr`; \verb`\Biggl \Biggr`) |
| 2431 |
are available for use with all brackets (parentheses, square brackets, |
| 2432 |
braces). If you feel \verb`\left`, \verb`\right` give too much space |
| 2433 |
around your formulas, you can use \verb`\mleft`, \verb`\mright` |
| 2434 |
from the \texttt{mleftright} package. |
| 2435 |
\begin{verbatim} |
| 2436 |
\eval[p=.,ff]{\[ \exp\left( |
| 2437 |
\dfrac{\ln2}{4}+\dfrac{\ln8}{4} |
| 2438 |
\right), |
| 2439 |
\exp\mleft( |
| 2440 |
\dfrac{\ln2}{4}+\dfrac{\ln8}{4} |
| 2441 |
\mright)\]} |
| 2442 |
\end{verbatim} |
| 2443 |
$\Longrightarrow$ \eval[p=.,ff]{\[ \exp\left( |
| 2444 |
\dfrac{\ln2}{4}+\dfrac{\ln8}{4} |
| 2445 |
\right), |
| 2446 |
\exp\mleft( |
| 2447 |
\dfrac{\ln2}{4}+\dfrac{\ln8}{4} |
| 2448 |
\mright) |
| 2449 |
\]}\texttt{numerica} also accepts the use of left-right modifiers with |
| 2450 |
\verb`.` (dot) and with \verb`/`, but if parentheses are not wanted |
| 2451 |
it can be simpler just to use a \verb`\big` command: |
| 2452 |
\begin{centred} |
| 2453 |
\verb`\eval[p=.]{\[ \dfrac{3+4}{2+1}\bigg/\dfrac{1+2}{4+5} \]}` $\Longrightarrow$ |
| 2454 |
\eval[p=.]{\[ \dfrac{3+4}{2+1}\bigg/\dfrac{1+2}{4+5} \]} |
| 2455 |
\end{centred} |
| 2456 |
Modifiers with their accompanying brackets etc.\,can be nested. |
| 2457 |
|
| 2458 |
\section{Unary functions} |
| 2459 |
|
| 2460 |
The unary functions catered for in \texttt{numerica} (at present) |
| 2461 |
are the trigonometric and hyperbolic functions, the various logarithms, |
| 2462 |
the exponential function, and the signum function. Mathematicians |
| 2463 |
delimit the arguments of these functions not only with parentheses, |
| 2464 |
but also with square brackets and (mathematical) braces (\verb`\{ \}`). |
| 2465 |
In \LaTeX{} these are available both in explicit character form and |
| 2466 |
also in the command form of §\ref{subsec:calcCommandBrackets}. Of |
| 2467 |
whatever kind, brackets can be qualified with \verb`\left \right`, |
| 2468 |
\verb`\bigl \bigr`, etc., and \verb`\mleft` and \verb`\mright` |
| 2469 |
from the \texttt{mleftright} package. |
| 2470 |
|
| 2471 |
\subsection{Trigonometric functions} |
| 2472 |
|
| 2473 |
\label{subsec:calcTrigonometricFunctions}\LaTeX{} provides all six |
| 2474 |
trignometric functions, \verb`\sin`, \verb`\cos`, \verb`\tan`, |
| 2475 |
\verb`\csc`, \verb`\sec`, \verb`\cot`. Their arguments are assumed |
| 2476 |
to be in radians unless degrees are explicitly ordered, either by |
| 2477 |
entering \verb`o` (lowercase letter `o', reminiscent of a degree |
| 2478 |
symbol) in the settings option, or by appending \verb`\degree` to |
| 2479 |
a number. The command \verb`\degree` is defined in \texttt{numerica} |
| 2480 |
(using \verb`\ProvideDocumentCommand`) and expands to $\degree$ |
| 2481 |
in both text and math modes.) |
| 2482 |
\begin{centred} |
| 2483 |
\verb`\eval{$ \sin(\pi/3) $}` $\Longrightarrow$ \eval{$ \sin(\pi/3) $}, |
| 2484 |
|
| 2485 |
\verb`\eval[o]{$ \sin 60 $}` $\Longrightarrow$ \eval[o]{$ \sin 60 $}, |
| 2486 |
|
| 2487 |
\verb`\eval{$ \sin 60\degree $}` $\Longrightarrow$ \eval{$ \sin 60\degree $}. |
| 2488 |
\end{centred} |
| 2489 |
\noindent\LaTeX{} also provides the three main trigonometric inverses: |
| 2490 |
\verb`\arcsin`, \verb`\arccos`, \verb`\arctan`. The three missing |
| 2491 |
inverses – \verb`\arccsc`, \verb`\arcsec`, \verb`\arccot` – are |
| 2492 |
provided by \texttt{numerica}. In the example, the \verb`p` setting |
| 2493 |
has been used to attach a degree symbol to the answer: |
| 2494 |
\begin{centred} |
| 2495 |
\verb`\eval[p=\degree]{$ (\arccot 1)/1\deg $}` $\Longrightarrow$ |
| 2496 |
\eval[p=\degree]{$ (\arccot 1)/1\deg $}. |
| 2497 |
\end{centred} |
| 2498 |
Alternatively, you can manually append a \verb`\degree` command after |
| 2499 |
the \verb`\eval` command. Repeating the last example, everything |
| 2500 |
is clearer if the \verb`o` option is used: |
| 2501 |
\begin{centred} |
| 2502 |
\verb`\eval[o]{$ \arccot 1 $}\degree` $\Longrightarrow$ \eval[o]{$\arccot1 $}\degree. |
| 2503 |
\end{centred} |
| 2504 |
Inverses can also be constructed using the `$-1$' superscript notation. |
| 2505 |
Thus |
| 2506 |
\begin{centred} |
| 2507 |
\verb`\eval[p=\degree,o]{$ \sin^{-1}(1/\surd2) $}` $\Longrightarrow$ |
| 2508 |
\eval[p=\degree,o]{$ \sin^{-1}(1/\surd2) $}. |
| 2509 |
\end{centred} |
| 2510 |
|
| 2511 |
\subsubsection{Complicated arguments} |
| 2512 |
|
| 2513 |
\label{subsec:calcComplicated-arguments}A general function $f$ of |
| 2514 |
$x$ is usually written $f(x)$: the argument of the function is delimited |
| 2515 |
by parentheses. In practice, with familiar functions, mathematicians |
| 2516 |
often don't bother with the parentheses, even when the argument includes |
| 2517 |
more than one factor: $\sin\tfrac{1}{2}\pi$, $\cos2\pi t$, $\ln xy$ |
| 2518 |
($=\ln x+\ln y$), and so on. So long as the argument is composed |
| 2519 |
of numbers, constants, variables or \verb`\tfrac`-s or \verb`\sfrac`-s, |
| 2520 |
\texttt{numerica} parses the argument without difficulty and without |
| 2521 |
requiring parentheses to be inserted. As function arguments become |
| 2522 |
more complicated, parentheses can become necessary to clarify just |
| 2523 |
what expression the function is acting on. But trigonometric identities |
| 2524 |
like |
| 2525 |
\[ |
| 2526 |
\sin A+\sin B=2\sin\tfrac{1}{2}(A+B)\cos\tfrac{1}{2}(A-B) |
| 2527 |
\] |
| 2528 |
and especially Fourier series where expressions like |
| 2529 |
\[ |
| 2530 |
\cos\frac{2\pi}{T}nt,\quad\cos\frac{2\pi}{T}n(t+\tfrac{1}{2}T),\quad\text{\ensuremath{\sin(N+\tfrac{1}{2})\frac{2\pi\tau}{T}}, } |
| 2531 |
\] |
| 2532 |
\[ |
| 2533 |
\sin2\pi\left(\frac{x}{\lambda}-\frac{t}{T}\right),\quad\sin(n+\tfrac{1}{2})(x-t), |
| 2534 |
\] |
| 2535 |
are a common occurrence, show that in practice parentheses that enclose |
| 2536 |
the whole argument, even for complicated expressions, are often omitted. |
| 2537 |
Context makes clear where the function argument ends and mathematicians |
| 2538 |
read the expressions accordingly. |
| 2539 |
|
| 2540 |
What should \texttt{numerica} do? Insist that the whole argument be |
| 2541 |
parenthesized? But that results in expressions that are generally |
| 2542 |
less pleasing to the eye and require more concentration to read, to |
| 2543 |
disentangle the enclosing from the enclosed parentheses: |
| 2544 |
\[ |
| 2545 |
\sin\left(\tfrac{1}{2}(A+B)\right),\quad\sin\left(2\pi\left(\frac{x}{\lambda}-\frac{t}{T}\right)\right),\quad\sin\left((n+\tfrac{1}{2})(x-t)\right). |
| 2546 |
\] |
| 2547 |
Admittedly square brackets and mathematical braces can help here, |
| 2548 |
but mathematicians don't (generally) do this. The examples above are |
| 2549 |
culled from a number of different texts that I had to hand – I didn't |
| 2550 |
need to go searching for them. To insist that formulas be written |
| 2551 |
in a `forced' or pedantic way, goes against the underlying idea |
| 2552 |
behind \texttt{numerica}: to evaluate expressions in the form in which |
| 2553 |
they are typeset.\texttt{ } |
| 2554 |
|
| 2555 |
Rather, from version 3.0.0 the recommended way of handling such expressions |
| 2556 |
is to put the \emph{whole} argument of the function between \LaTeX{} |
| 2557 |
braces. (This applies not only to the trigonometric functions but |
| 2558 |
also to \emph{any} unary function.) Yes, inserting \LaTeX{} braces |
| 2559 |
does involve modifying the formula, but it fits naturally within \LaTeX{} |
| 2560 |
practice and, crucially, it makes \emph{no change} to the \texttt{pdf} |
| 2561 |
display. The formula retains its `natural' appearance at the same |
| 2562 |
time as the full argument is delimited so that \texttt{numerica} knows |
| 2563 |
what to operate on. Thus |
| 2564 |
\begin{centred} |
| 2565 |
\verb`\eval{$ \sin{\tfrac16(m+n)\pi} $}[m=1,n=2]`, $\Longrightarrow$ |
| 2566 |
\eval{$ \sin{\tfrac16(m+n)\pi} $}[m=1,n=2], |
| 2567 |
\end{centred} |
| 2568 |
which is $\sin\tfrac{1}{2}\pi$, and |
| 2569 |
\begin{verbatim} |
| 2570 |
\eval{\[ |
| 2571 |
\sin{2\pi\mleft(\frac{x}{\lambda} |
| 2572 |
-\frac{t}{T}\mright)} |
| 2573 |
\]}[x=1,\lambda=2,t=3,T=4] |
| 2574 |
\end{verbatim} |
| 2575 |
$\Longrightarrow$ \eval{\[ |
| 2576 |
\sin{2\pi\mleft(\frac{x}{\lambda} |
| 2577 |
-\frac{t}{T}\mright)} |
| 2578 |
\]}[x=1,\lambda=2,t=3,T=4] |
| 2579 |
|
| 2580 |
\noindent which is the sine of $-\tfrac{1}{2}\pi=2\pi\times(-\tfrac{1}{4})$. |
| 2581 |
|
| 2582 |
\noindent{}% |
| 2583 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 2584 |
\begin{shaded}% |
| 2585 |
In earlier versions of \texttt{numerica} there was a setting \texttt{()=0}, |
| 2586 |
\texttt{1}, \texttt{2} (see Chapter~\ref{chap:settingsSettings} |
| 2587 |
for a discussion of settings) which changed the way parentheses were |
| 2588 |
parsed and allowed (most of) these usages. But it was difficult to |
| 2589 |
document and remember exactly what was and was not allowed at each |
| 2590 |
setting value, meaning the result of a calculation might not reflect |
| 2591 |
what a user intended. Besides, dealing with the different setting |
| 2592 |
values complicated the code. From version 3.0.0, with the use of braces |
| 2593 |
to delimit such arguments, this setting has been withdrawn and now |
| 2594 |
produces a \texttt{numerica} error message. The use of \LaTeX{} braces |
| 2595 |
to delimit the arguments of \emph{mathematical} functions\emph{ }is |
| 2596 |
more generally discussed at §\ref{subsec:evalBraced-groups}.\end{shaded}% |
| 2597 |
\end{minipage} |
| 2598 |
|
| 2599 |
\subsection{Hyperbolic functions} |
| 2600 |
|
| 2601 |
Four of the six hyperbolic functions: \verb`\sinh`, \verb`\cosh`, |
| 2602 |
\verb`\tanh`, and \verb`\coth` are provided by \LaTeX , and \emph{no} |
| 2603 |
inverses. \texttt{numerica} fills the gaps, providing the missing |
| 2604 |
hyperbolic functions, \verb`\csch` and \verb`\sech`, and all missing |
| 2605 |
inverses. There is no agreed notation in common use for the hyperbolic |
| 2606 |
inverses. \emph{HMF} writes arcsinh, arccosh, \ldots , ISO recommends |
| 2607 |
arsinh, arcosh, \ldots , \texttt{l3fp} uses asinh, acosh, \ldots{} |
| 2608 |
as do the computer algebra system \texttt{maxima} and the spreadsheet |
| 2609 |
\texttt{LibreOffice Calc}. \texttt{numerica} makes no attempt to decide |
| 2610 |
the issue. From version 3.0.0, it accepts all\emph{ }three forms for |
| 2611 |
all six functions. All can be used within an \verb`\eval` command: |
| 2612 |
\begin{verbatim} |
| 2613 |
\eval[pp,p=.,ff]{\[ \atanh\tanh 3, \sinh\arsinh 3, |
| 2614 |
\arcsech\sech 3 \]} |
| 2615 |
\end{verbatim} |
| 2616 |
$\Longrightarrow$ \eval[pp,p=.,ff]{\[ \atanh\tanh 3, \sinh\arsinh 3, \arcsech\sech 3 \]}As |
| 2617 |
for the trig.\ inverses, hyperbolic inverses can also be constructed |
| 2618 |
using the `$-1$' superscript notation. Thus |
| 2619 |
\begin{centred} |
| 2620 |
\verb`\eval{$ \coth\coth^{-1}1.5 $}` $\Longrightarrow$ \eval{$ \coth\coth^{-1}1.5 $}. |
| 2621 |
\end{centred} |
| 2622 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 2623 |
\begin{shaded}% |
| 2624 |
|
| 2625 |
\subsubsection{Absence from \texttt{l3fp}} |
| 2626 |
|
| 2627 |
Please note that \texttt{l3fp} does not (as yet) provide \emph{any} |
| 2628 |
hyperbolic functions natively. The values \texttt{numerica} provides |
| 2629 |
for these functions are \emph{calculated} values using familiar formulas |
| 2630 |
involving exponentials (for the direct functions) and natural logarithms |
| 2631 |
and square roots for the inverses. Rounding errors mean the values |
| 2632 |
calculated may not have $16$-figure accuracy. The worst `offenders' |
| 2633 |
are likely to be the least used, \verb`\acsch` and \verb`\asech`. |
| 2634 |
For instance, |
| 2635 |
\[ |
| 2636 |
\acsch x=\ln\left[\frac{1}{x}+\left(\frac{1}{x^{2}}+1\right)^{\mkern-6mu 1/2}\right], |
| 2637 |
\] |
| 2638 |
|
| 2639 |
\begin{centred} |
| 2640 |
\verb`\eval{$ \csch \acsch 7 $}[15]` $\Longrightarrow$ \eval{$ \csch \acsch 7 $}[15]. |
| 2641 |
\end{centred} |
| 2642 |
\end{shaded}% |
| 2643 |
\end{minipage} |
| 2644 |
|
| 2645 |
\subsection{Logarithms} |
| 2646 |
|
| 2647 |
The natural logarithm \verb`\ln`, base $10$ logarithm \verb`\lg`, |
| 2648 |
and binary or base $2$ logarithm \verb`\lb` are all recognized, |
| 2649 |
as is \verb`\log`, preferably with a subscripted base: |
| 2650 |
\begin{centred} |
| 2651 |
\verb`\eval{$ \log_{12}1728 $}` $\Longrightarrow$ \eval{$ \log_{12}1728 $} |
| 2652 |
\end{centred} |
| 2653 |
If there is no base indicated, base $10$ is assumed. (The notations |
| 2654 |
\verb`\ln`, \verb`\lg`, and \verb`\lb` follow ISO 80000-2 recommendation, |
| 2655 |
which frowns upon the use of the unsubscripted \verb`\log` although |
| 2656 |
only \verb`\ln` appears to be widely used.) The base need not be |
| 2657 |
explicitly entered as a number. It could be entered as an expression |
| 2658 |
or be specified in the vv-list: |
| 2659 |
\begin{centred} |
| 2660 |
\verb`\eval*{$ \log_b c $}[b=2,c=1024]` $\Longrightarrow$ \eval*{$ \log_b c $}[b=2,c=1024], |
| 2661 |
\end{centred} |
| 2662 |
the log to base $2$ in this case. It is possible to use the unadorned |
| 2663 |
\verb`\log` with a base different from $10$; see §\ref{subsec:settingsLogBase}. |
| 2664 |
|
| 2665 |
\subsection{Other unary functions} |
| 2666 |
|
| 2667 |
Other unary functions supported are the exponential function \verb`\exp`, |
| 2668 |
and signum function \verb`\sgn`, equal to $1$, $-1$, or $0$, depending |
| 2669 |
as its argument is positive, negative or zero. |
| 2670 |
\begin{verbatim} |
| 2671 |
\eval{$ \sgn(\exp(x)-e^x) $}[x=1],\quad |
| 2672 |
\eval{$ \sgn(e^x-\exp(x)) $}[x=2]. |
| 2673 |
\end{verbatim} |
| 2674 |
$\Longrightarrow$ \eval{$ \sgn(\exp(x)-e^x) $}[x=1],\quad |
| 2675 |
\eval{$ \sgn(e^x-\exp(x)) $}[x=2]. |
| 2676 |
|
| 2677 |
The first of these is expected, the second probably not. $\exp x$ |
| 2678 |
is provided by \texttt{l3fp}, a built-in function; $e^{x}$ is calculated |
| 2679 |
by \texttt{numerica}, a number ($e$) raised to a power. They differ |
| 2680 |
by $1$ in the $15$-th decimal place: |
| 2681 |
\begin{centred} |
| 2682 |
\verb`\eval[ff]{$ \exp 2, e^2 $}[15*]` $\Longrightarrow$ \eval[ff]{$ \exp 2, e^2 $}[15*]. |
| 2683 |
\end{centred} |
| 2684 |
|
| 2685 |
\subsection{Squaring, cubing, \ldots{} unary functions} |
| 2686 |
|
| 2687 |
\label{subsec:calcSquaring-etc-unary}\verb`\eval` happily digests |
| 2688 |
a familiar but `incorrectly formed' expression like |
| 2689 |
\[ |
| 2690 |
\sin^{2}1.234+\cos^{2}1.234. |
| 2691 |
\] |
| 2692 |
You do not have to parenthesize like $(\sin1.234)^{2}+(\cos1.234)^{2}$ |
| 2693 |
or (heaven forbid) $(\sin(1.234))^{2}+(\cos(1.234))^{2}$; the everyday |
| 2694 |
usage is fine: |
| 2695 |
\begin{centred} |
| 2696 |
\verb`\eval{$ \sin^2\theta+\cos^2\theta $}[\theta=1.234]` $\Longrightarrow$ |
| 2697 |
\eval{$ \sin^2\theta+\cos^2\theta $}[\theta=1.234] . |
| 2698 |
\end{centred} |
| 2699 |
Equally \verb`\eval` has no difficulty reading the `correct' pedantic |
| 2700 |
form |
| 2701 |
\begin{centred} |
| 2702 |
\verb`\eval{$ (\sin(\theta))^2+(\cos(\theta))^2 $}[\theta=1.234]` |
| 2703 |
$\Longrightarrow$ \eval{$ (\sin(\theta))^2+(\cos(\theta))^2 $}[\theta=1.234] . |
| 2704 |
\end{centred} |
| 2705 |
A hyperbolic identity is corroborated in this example: |
| 2706 |
\begin{centred} |
| 2707 |
\verb`\eval[ff]{\[ \sinh 3x, 3\sinh x+4\sinh^3x \]}[x=1]` $\Longrightarrow$ |
| 2708 |
\eval[ff]{\[ \sinh 3x, 3\sinh x+4\sinh^3x \]}[x=1] |
| 2709 |
\end{centred} |
| 2710 |
In fact all named unary functions in \texttt{numerica} can be squared, |
| 2711 |
cubed, etc., in this `incorrect' but familiar way, although the |
| 2712 |
practice outside the trigonometric and hyperbolic contexts seems rare. |
| 2713 |
|
| 2714 |
When the argument of the function is parenthesized and raised to a |
| 2715 |
power – like $\sin(\pi)^{2}$ – it is read by \verb`\eval` as the |
| 2716 |
`sine of the square of pi', $\sin(\pi^{2})$, and \emph{not }as |
| 2717 |
the `square of the sine of pi', $(\sin\pi)^{2}$: |
| 2718 |
\begin{centred} |
| 2719 |
\verb`\eval{$ \sin(\pi)^2 $}` $\Longrightarrow$ \eval{$ \sin(\pi)^2 $} . |
| 2720 |
\end{centred} |
| 2721 |
Things are done like this in \texttt{numerica} above all to handle |
| 2722 |
the logarithm in a natural way. Surely (see \emph{HMF} 4.1.11) $\ln x^{n}=n\ln x$? |
| 2723 |
I.e.\ $\ln x^{n}=\ln(x^{n})$ rather than $(\ln x)^{n}$. And if |
| 2724 |
we wish to write (as we do) $\ln(1+1/n)^{n}=n\ln(1+1/n)=1-1/2n+1/3n^{2}-\ldots$ |
| 2725 |
to study the limiting behaviour of $(1+1/n)^{n}$, then we are committed |
| 2726 |
to $\ln(x)^{n}=n\ln(x)=\ln(x^{n})$ too. |
| 2727 |
|
| 2728 |
\section{\emph{n}-ary functions} |
| 2729 |
|
| 2730 |
\label{sec:calc-n-ary-functions}The functions of more than one variable |
| 2731 |
($n$-ary functions) that \texttt{numerica} supports are \verb`\max`, |
| 2732 |
\verb`\min` and \verb`\gcd`, greatest common divisor. The comma |
| 2733 |
list of arguments (semicolon list if the \verb`comma` package option |
| 2734 |
has been used) to \verb`\max`, \verb`\min` or \verb`\gcd` can be |
| 2735 |
of arbitrary length. The arguments themselves can be expressions or |
| 2736 |
numbers. |
| 2737 |
|
| 2738 |
As implemented in \texttt{numerica}, for \verb`\gcd` non-integer |
| 2739 |
arguments are\emph{ }rounded to integers. Hence both $y$ and $3y$ |
| 2740 |
are independently rounded in the following example – to $81$ and |
| 2741 |
$243$ respectively: |
| 2742 |
\begin{centred} |
| 2743 |
\verb`\eval{$ \gcd(12,10x^2,3y,y,63) $}[y=1/0.0123456789,x=3]` $\Longrightarrow$ |
| 2744 |
$\vsp$\eval{$ \gcd(12,10x^2,3y,y,63) $}[y=1/0.0123456789,x=3]. |
| 2745 |
\end{centred} |
| 2746 |
The rounding occurs within the greatest common divisor routine, not |
| 2747 |
in the vv-list; the variable retains its original value. Modifying |
| 2748 |
the example, this becomes evident in the sixth decimal place of the |
| 2749 |
new result: |
| 2750 |
\begin{centred} |
| 2751 |
\verb`\eval{$ \gcd(12,10x^2,3y,y,63) + y $}[y=1/0.0123456789,x=3]` |
| 2752 |
$\Longrightarrow$ $\vsp$\eval{$ \gcd(12,10x^2,3y,y,63) + y $}[y=1/0.0123456789,x=3]. |
| 2753 |
\end{centred} |
| 2754 |
For $n$-ary functions, squaring, cubing, etc. follow a different |
| 2755 |
pattern from that for unary functions. The argument of these functions |
| 2756 |
is a comma list. Squaring it makes no sense and we understand the |
| 2757 |
superscript as applying to the function as a whole. (Consistency is |
| 2758 |
not the point here; it is how a person reads the expression that \texttt{numerica} |
| 2759 |
tries to accommodate.) |
| 2760 |
\begin{centred} |
| 2761 |
\verb`\eval{$ \gcd(3x,x,\arcsin 1/\deg)^2 $}[x=24]` $\Longrightarrow$ |
| 2762 |
$\vsp$\eval{$ \gcd(3x,x,\arcsin 1/\deg)^2$}[x=24] . |
| 2763 |
\end{centred} |
| 2764 |
|
| 2765 |
\section{Absolute value, floor \& ceiling functions} |
| 2766 |
|
| 2767 |
\label{sec:calcAbsValueEtc}It is tempting to use the \textsf{|} key |
| 2768 |
on the keyboard for inserting an absolute value sign. \texttt{numerica} |
| 2769 |
accepts this usage, but it is strongly deprecated. The spacing is |
| 2770 |
incorrect – compare $|-l|$ using \textsf{|}, against $\lvert-l\rvert$ |
| 2771 |
using \verb`\lvert \rvert`. Also, with\textsf{ |}, the identity of |
| 2772 |
the left and right delimiters makes parsing nested absolute values |
| 2773 |
difficult. \texttt{numerica} does not attempt to do so. \verb`\lvert \rvert` |
| 2774 |
are better in every way except ease of writing.\texttt{ }To aid such |
| 2775 |
ease \texttt{numerica }provides the \verb`\abs` function (using the |
| 2776 |
\texttt{\textbackslash DeclarePairedDelimiter} command of the \texttt{mathtools} |
| 2777 |
package). This takes a mutually exclusive star (asterisk) or square |
| 2778 |
bracketed optional argument, and a mandatory braced argument. The |
| 2779 |
starred form wraps \verb`\left\lvert`, \verb`\right\rvert` around |
| 2780 |
the mandatory argument: |
| 2781 |
\begin{centred} |
| 2782 |
\verb`\eval[p=.]{\[ 3\abs*{\frac{\abs{n}}{21}-1} \]}[n=-7]` $\Longrightarrow$ |
| 2783 |
\eval[p=.]{\[ 3\abs*{\frac{\abs{n}}{21}-1} \]}[n=-7] |
| 2784 |
\end{centred} |
| 2785 |
The optional argument provides access to the \verb`\big...` modifiers: |
| 2786 |
\begin{verbatim} |
| 2787 |
\eval[p=.]{\[ |
| 2788 |
\abs[\Big]{\abs{a-c}-\abs[\big]{A-C}} |
| 2789 |
\]}[A=12,a=-10,C=7,c=-5] |
| 2790 |
\end{verbatim} |
| 2791 |
$\Longrightarrow$ \eval[p=.]{\[ |
| 2792 |
\abs[\Big]{\abs{a-c}-\abs[\big]{A-C}} |
| 2793 |
\]}[A=12,a=-10,C=7,c=-5] |
| 2794 |
|
| 2795 |
\noindent The form without either option dispenses with modifiers |
| 2796 |
altogether: |
| 2797 |
\begin{centred} |
| 2798 |
\verb`\eval{$ \tfrac12(x+y)+\tfrac12\abs{x-y} $}[x=-3,y=7].` $\Longrightarrow$ |
| 2799 |
\eval{$ \tfrac12(x+y)+\tfrac12\abs{x-y} $}[x=-3,y=7]. |
| 2800 |
\end{centred} |
| 2801 |
As noted, the star and square bracket options are mutually exclusive. |
| 2802 |
|
| 2803 |
\texttt{numerica} also provides the functions \verb`\floor` and \verb`\ceil`, |
| 2804 |
defined in the same way, taking a mutually exclusive star or square |
| 2805 |
bracketed optional argument, the starred forms wrapping \verb`\left\lfloor`, |
| 2806 |
\verb`\right\rfloor` or \verb`\left\lceil`, \verb`\right\rceil` |
| 2807 |
around the mandatory argument, and the square bracket option forms |
| 2808 |
replacing the \verb`\left` and \verb`\right` with the corresponding |
| 2809 |
\verb`\big` commands (see the \verb`\abs` example above). The form |
| 2810 |
without star or square-bracket option dispenses with any modifier |
| 2811 |
at all. |
| 2812 |
\begin{centred} |
| 2813 |
\verb`\eval[pp,ff]{$ \floor{-\pi}, \ceil{\pi} $}` $\Longrightarrow$ |
| 2814 |
\eval[pp,ff]{$ \floor{-\pi}, \ceil{\pi} $}. |
| 2815 |
\end{centred} |
| 2816 |
The floor function, $\lfloor x\rfloor$, is the greatest integer $\le x$; |
| 2817 |
the ceiling function, $\lceil x\rceil$ is the smallest integer $\ge x$. |
| 2818 |
Like the absolute value, the floor and ceiling functions, can be nested: |
| 2819 |
\begin{centred} |
| 2820 |
\verb`\eval{$ \floor{-\pi+\ceil{e}} $}` $\Longrightarrow$ \eval{$ \floor{-\pi+\ceil{e}} $}. |
| 2821 |
\end{centred} |
| 2822 |
|
| 2823 |
\subsection{Squaring, cubing, \ldots{} absolute values, etc.} |
| 2824 |
|
| 2825 |
These three functions can be raised to a power \emph{without} extra |
| 2826 |
parentheses: |
| 2827 |
\begin{centred} |
| 2828 |
\verb`\eval[pp,ff]{$ \ceil{e}^2, \floor{e}^2 $}` $\Longrightarrow$ |
| 2829 |
\eval[pp,ff]{$ \ceil{e}^2, \floor{e}^2 $},\medskip{} |
| 2830 |
|
| 2831 |
\verb`\eval{$ \abs{-4}^2 $}` $\Longrightarrow$ \eval{$ \abs{-4}^2 $}. |
| 2832 |
\end{centred} |
| 2833 |
|
| 2834 |
\section{Factorials, binomial coefficients} |
| 2835 |
|
| 2836 |
\label{sec:calcFactorialsBinom}Factorials use the familiar trailing |
| 2837 |
\texttt{!} notation: |
| 2838 |
\begin{centred} |
| 2839 |
\verb`\eval{$ 7! $}` $\Longrightarrow$ \eval{$ 7! $}, |
| 2840 |
|
| 2841 |
\verb`\eval{$ (\alpha+\beta)!-\alpha!-\beta! $}[\alpha=2,\beta=3]` |
| 2842 |
$\Longrightarrow$ \eval{$ (\alpha+\beta)!-\alpha!-\beta! $}[\alpha=2,\beta=3]. |
| 2843 |
\end{centred} |
| 2844 |
The examples illustrate how \texttt{numerica} interprets the argument |
| 2845 |
of the factorial symbol: it `digests' |
| 2846 |
\begin{itemize} |
| 2847 |
\item a preceding (possibly multi-digit) integer, or |
| 2848 |
\item a preceding variable, or |
| 2849 |
\item a bracketed expression, or |
| 2850 |
\item a bracket-like expression. |
| 2851 |
\end{itemize} |
| 2852 |
A bracket-like expression is an absolute value, floor or ceiling function, |
| 2853 |
since they delimit arguments in a bracket-like way: |
| 2854 |
\begin{centred} |
| 2855 |
\verb`\eval{$ \abs{-4}!+\floor{\pi}!+\ceil{e}! $}` $\Longrightarrow$ |
| 2856 |
\eval{$ \abs{-4}!+\floor{\pi}!+\ceil{e}! $}. |
| 2857 |
\end{centred} |
| 2858 |
The result of feeding the factorial an expression different in kind |
| 2859 |
from one of these four cases may give an error message or an unexpected |
| 2860 |
result. Use parentheses around such an expression; for example write |
| 2861 |
$(3^{2})!$, rather than $3^{2}!$. |
| 2862 |
|
| 2863 |
Nesting of brackets for factorials is accepted: |
| 2864 |
\begin{centred} |
| 2865 |
\verb`\eval{$ ((5-2)!+1)! $}` $\Longrightarrow$ \eval{$ ((5-2)!+1)! $}. |
| 2866 |
\end{centred} |
| 2867 |
The factorials of negative integers are not defined and raise a \texttt{numerica} |
| 2868 |
error. It simplifies the code to treat the factorial of a positive |
| 2869 |
non-integer as the factorial of the integer it rounds to, rather than |
| 2870 |
raising an error. For the sake of the reader, in such circumstances, |
| 2871 |
an author should make the rounding explicit: |
| 2872 |
\begin{centred} |
| 2873 |
\verb`\eval{$ \floor{\pi}! $}` $\Longrightarrow$\eval{$ \floor{\pi}! $}. |
| 2874 |
\end{centred} |
| 2875 |
This rounding to an integer is different from the behaviour in earlier |
| 2876 |
versions of \texttt{numerica} but should make no noticeable difference. |
| 2877 |
|
| 2878 |
\subsection{Double factorials} |
| 2879 |
|
| 2880 |
The double factorial, written $n!!,$ is the product $n(n-2)(n-4)\ldots\times4\times2$ |
| 2881 |
when $n$ is even, and the product $n(n-2)(n-4)\ldots\times3\times1$ |
| 2882 |
when $n$ is odd: |
| 2883 |
\begin{centred} |
| 2884 |
\verb`$\eval[pp,ff]{6!!, 5!!}$` $\Longrightarrow$ $\eval[pp,ff]{6!!, 5!!}$. |
| 2885 |
\end{centred} |
| 2886 |
As with factorials, the double factorial sign can be appended to a |
| 2887 |
(possibly multi-digit) number, a variable, a bracketed expression |
| 2888 |
or a bracket-like expression. |
| 2889 |
\begin{centred} |
| 2890 |
\verb`\eval[env=\[,ff]{ n!!, (n-1)!!, \abs{2-n}!! }[n=\sqrt{49}]` |
| 2891 |
$\Longrightarrow$ \eval[env=\[,ff]{ n!!, (n-1)!!, \abs{2-n}!! }[n=\sqrt{49}] |
| 2892 |
\end{centred} |
| 2893 |
Since $n!=n!!(n-1)!!$, |
| 2894 |
\[ |
| 2895 |
n!!=\frac{n!}{(n-1)!!}=\frac{(n+1)!}{(n+1)!!}, |
| 2896 |
\] |
| 2897 |
on multiplying top and bottom by $n+1$. Putting $n=0$ in the left |
| 2898 |
and right expressions shows that $0!!=1$. Now put $n=0$ in the left |
| 2899 |
and middle expressions. We deduce that $(-1)!!=1$. It follows that |
| 2900 |
double factorials are defined for integers $\ge-1$. |
| 2901 |
|
| 2902 |
\subsection{Binomial coefficients} |
| 2903 |
|
| 2904 |
Binomial coefficients are entered in \LaTeX{} with the \verb`\binom`\textbf{ |
| 2905 |
}command. It takes two arguments, \verb`\binom{a}{b}` and scales |
| 2906 |
like \verb`\frac`: inline it displays as $\binom{a}{b}$, and in |
| 2907 |
displaystyle as |
| 2908 |
\[ |
| 2909 |
\binom{a}{b}. |
| 2910 |
\] |
| 2911 |
One can force textstyle with \verb`\tbinom` and force displaystyle |
| 2912 |
with \verb`\dbinom`. As implemented in \texttt{numerica}, these are |
| 2913 |
\emph{generalised} binomial coefficients: |
| 2914 |
\[ |
| 2915 |
\binom{x}{k}=\frac{x(x-1)\dots(x-k+1)}{k(k-1)\dots1},\quad(x\in\mathbb{R},~k\in\mathbb{N}), |
| 2916 |
\] |
| 2917 |
where $x$ need not be a positive or zero integer, and where $\binom{x}{0}=1$ |
| 2918 |
by definition. |
| 2919 |
\begin{centred} |
| 2920 |
\verb`\eval[pp,p=.,ff]{$ \tbinom53, \tbinom70 $}` $\Longrightarrow$ |
| 2921 |
\eval[pp,p=.,ff]{$ \tbinom53, \tbinom70 $} |
| 2922 |
\end{centred} |
| 2923 |
The first (or upper) argument can be any real number; it does not |
| 2924 |
need to be an integer or positive: recalling that \eval[eq=\approx]{$\pi^2$}[3], |
| 2925 |
\begin{centred} |
| 2926 |
\verb`\eval[pp,p=.,ff]{$ \tbinom94, \tbinom{\pi^2}4, \tbinom{10}4 $}[3]`$\Longrightarrow$ |
| 2927 |
\eval[pp,p=.,ff]{$ \tbinom94, \tbinom{\pi^2}4, \tbinom{10}4 $}[3] |
| 2928 |
\end{centred} |
| 2929 |
If the second (or lower) argument of \verb`\binom` is negative, \texttt{numerica} |
| 2930 |
responds with a message: |
| 2931 |
\begin{centred} |
| 2932 |
\verb`\eval{$ \binom 5{-3} $}` $\Longrightarrow$ \eval{$ \binom 5{-3} $}. |
| 2933 |
\end{centred} |
| 2934 |
If the second argument is positive but not an integer, \texttt{numerica} |
| 2935 |
rounds it to the nearest integer before calculating the binomial coefficient: |
| 2936 |
\begin{centred} |
| 2937 |
\verb`\eval[pp,ff]{$ \binom 5e, \binom 53 $}` $\Longrightarrow$ |
| 2938 |
\eval[pp,ff]{$ \binom 5e, \binom 53 $}. |
| 2939 |
\end{centred} |
| 2940 |
This differs from previous versions of \texttt{numerica} which would |
| 2941 |
raise an error in this case. Although positive non-integers are now |
| 2942 |
rounded to the nearest integer, out of consideration for the reader, |
| 2943 |
an author should make explicit the fact that an integer has been used. |
| 2944 |
In the example I should have written \verb`\ceil{e}` rather than |
| 2945 |
\verb`e`. |
| 2946 |
|
| 2947 |
\section{Sums and products} |
| 2948 |
|
| 2949 |
\texttt{numerica} recognizes \verb`\sum`, displaying as $\sum$, |
| 2950 |
and \verb`\prod`, displaying as $\prod$, and expects both symbols |
| 2951 |
to have lower and upper summation or product limits specified. The |
| 2952 |
lower limit must be given in the form\emph{ variable=initial value} |
| 2953 |
where \emph{variable} is the summation or product variable; the upper |
| 2954 |
limit requires only the final value to be specified (although it can |
| 2955 |
also be given in the form \emph{variable=final value}). The values |
| 2956 |
may be expressions depending on other variables and values, and are |
| 2957 |
rounded to integers. This differs from earlier versions of \texttt{numerica} |
| 2958 |
where, if the result of a calculation differed too much from an integer, |
| 2959 |
it prompted an error message. Now the rounding happens automatically, |
| 2960 |
whatever the value. As in other similar contexts, for the sake of |
| 2961 |
the reader an author should ensure that the integer value is explicit: |
| 2962 |
\begin{centred} |
| 2963 |
\verb`\eval[p]{\[ \sum_{n=\floor{\pi/e}}^{\ceil{\pi e}}n \]}` $\Longrightarrow$\eval[p]{\[ \sum_{n=\floor{\pi/e}}^{\ceil{\pi e}}n \]} |
| 2964 |
\end{centred} |
| 2965 |
\noindent (which is $\sum_{n=1}^{9}n$).\emph{ }If the upper limit |
| 2966 |
is less than the lower limit the result is zero. Notice that there |
| 2967 |
is no vv-list. The summation variable does not need to be included |
| 2968 |
there unless there are other variables that depend on it. However, |
| 2969 |
in the case |
| 2970 |
\begin{centred} |
| 2971 |
\verb`\eval[p]{\[ \sum_{k=1}^N\frac1{k^3} \]}[N=100][4]` $\Longrightarrow$ |
| 2972 |
\eval[p]{\[ \sum_{k=1}^N\frac1{k^3} \]}[N=100][4] |
| 2973 |
\end{centred} |
| 2974 |
the upper limit $N$ is necessarily assigned a value in the vv-list. |
| 2975 |
|
| 2976 |
To the author it seems natural to enter the lower limit first, immediately |
| 2977 |
after the \verb`\sum` command (the sum is \emph{from }something \emph{to} |
| 2978 |
something), but no problem will accrue if the upper limit is placed |
| 2979 |
first (after all, the appearance of the formula in the \texttt{pdf} |
| 2980 |
is the same): |
| 2981 |
\begin{centred} |
| 2982 |
\verb`\eval[p=.]{\[ \sum^N_{k=1}\frac1{k^3} \]}[N=100][4]` $\Longrightarrow$ |
| 2983 |
\eval[p=.]{\[ \sum^N_{k=1}\frac1{k^3} \]}[N=100][4] |
| 2984 |
\end{centred} |
| 2985 |
Another example of a sum, using binomial coefficients this time, is |
| 2986 |
\begin{centred} |
| 2987 |
\verb`\eval[p]{\[ \sum_{m=0}^5\binom{5}{m}x^m y^{5-m} \]}[x=0.75,y=2.25]` |
| 2988 |
$\Longrightarrow$ \eval[p]{\[ \sum_{m=0}^5\binom{5}{m}x^m y^{5-m} \]}[x=0.75,y=2.25] |
| 2989 |
\end{centred} |
| 2990 |
which is just |
| 2991 |
\begin{centred} |
| 2992 |
\verb`\eval{$(x+y)^5$}[x=0.75,y=2.25]` $\Longrightarrow$ \eval{$ (x+y)^5 $}[x=0.75,y=2.25], |
| 2993 |
\end{centred} |
| 2994 |
or $3^{5}$. Now let's calculate a product: |
| 2995 |
\begin{verbatim} |
| 2996 |
\eval[p]{\[ |
| 2997 |
\prod_{k=1}^{100} |
| 2998 |
\biggl(\frac{x^2}{k^2\pi^2} +1\biggr) |
| 2999 |
\]}[x=1][3] |
| 3000 |
\end{verbatim} |
| 3001 |
$\Longrightarrow$ \eval[p]{\[\prod_{k=1}^{100} \biggl(\frac{x^2}{k^2\pi^2} +1\biggr)\]}[x=1][3] |
| 3002 |
|
| 3003 |
\noindent to be compared with \verb`\eval{$ \sinh 1 $}[3]` $\Longrightarrow$ |
| 3004 |
\eval{$ \sinh1 $}[3]. Obviously more terms than $100$ are required |
| 3005 |
in the product to achieve 3-figure accuracy. |
| 3006 |
|
| 3007 |
\subsection{Infinite sums and products} |
| 3008 |
|
| 3009 |
How many more? Let's `go the whole hog' and put $\infty$ in the |
| 3010 |
upper limit of this product: |
| 3011 |
\begin{verbatim} |
| 3012 |
\eval[p=.]{\[ |
| 3013 |
\prod_{k=1}^{\infty} |
| 3014 |
\biggl(\frac{x^2}{k^2\pi^2} +1\biggr) |
| 3015 |
\]}[x=1][3] |
| 3016 |
\end{verbatim} |
| 3017 |
$\Longrightarrow$ \eval[p=.] |
| 3018 |
{\[ |
| 3019 |
\prod_{k=1}^{\infty} |
| 3020 |
\biggl(\frac{x^2}{k^2\pi^2} +1\biggr) |
| 3021 |
\]}[x=1][3] |
| 3022 |
|
| 3023 |
\noindent Disappointingly, we still get the same result, deficient |
| 3024 |
by $1$ in the third decimal place. Obviously \texttt{numerica} has |
| 3025 |
not multiplied an infinite number of terms and, just as obviously, |
| 3026 |
the finite number of terms it \emph{has} multiplied are too few. How |
| 3027 |
\texttt{numerica} decides when to stop evaluating additional terms |
| 3028 |
in an infinite sum or product is discussed below in §\ref{sec:calcStoppingCriterion}. |
| 3029 |
|
| 3030 |
For this particular product the problem is that it converges slowly. |
| 3031 |
Any criterion for when to stop multiplying terms or, for an infinite |
| 3032 |
sum adding terms, seems bound to fail whenever convergence is sufficiently |
| 3033 |
slow. Presumably any stopping criterion must measure smallness in |
| 3034 |
some way. But terms of the divergent harmonic series $\sum(1/n)$, |
| 3035 |
for example, can always be found smaller than any value we care to |
| 3036 |
specify. It is not surprising that a stopping criterion will fail |
| 3037 |
when convergence is slow enough. However, the default criterion can |
| 3038 |
be changed: again, see below in §\ref{sec:calcStoppingCriterion}. |
| 3039 |
|
| 3040 |
Other infinite sums converge more rapidly, and the default settings |
| 3041 |
work admirably for them. For example |
| 3042 |
\begin{centred} |
| 3043 |
\verb`\eval{$ (1+0.1234)^{4.321} $}` $\Longrightarrow$ \eval{$ (1+0.1234)^{4.321} $}. |
| 3044 |
\end{centred} |
| 3045 |
Using binomial coefficients we can express this as an infinite sum:\medskip{} |
| 3046 |
\begin{verbatim} |
| 3047 |
\eval[p=.]{\[ |
| 3048 |
\sum_{n=0}^{\infty}\binom{\alpha}{n}x^{n} |
| 3049 |
\]}[\alpha=4.321,x=0.1234] |
| 3050 |
\end{verbatim} |
| 3051 |
$\Longrightarrow$ \eval[p=.] |
| 3052 |
{\[ |
| 3053 |
\sum_{n=0}^{\infty}\binom{\alpha}{n}x^{n} |
| 3054 |
\]}[\alpha=4.321,x=0.1234] |
| 3055 |
|
| 3056 |
\subsection{The stopping criterion} |
| 3057 |
|
| 3058 |
\label{sec:calcStoppingCriterion}There are ways of tweaking various |
| 3059 |
parameters to nudge infinite sums and products to a correct limit. |
| 3060 |
These tweaks are applied via the settings option of the \verb`\eval` |
| 3061 |
command. |
| 3062 |
|
| 3063 |
The normal convergence criterion used by \texttt{numerica} to determine |
| 3064 |
when to stop adding/multiplying terms in an infinite sum/product is |
| 3065 |
\emph{when the next term added/multiplied leaves the total unaltered |
| 3066 |
when rounded to 2 more digits than the specified rounding value.} |
| 3067 |
Suppose $L_{k}$ is the partial sum/product after $k$ terms, and |
| 3068 |
$r$ is the rounding value.\footnote{E.g.\ if $T(n)$ is the $n$-th term then the partial sum $L_{k}=\sum_{n=1}^{k}T(n)$.} |
| 3069 |
Let $\left(L_{k}\right)_{r}$ denote $L_{k}$ rounded to $r$ figures. |
| 3070 |
\emph{The infinite sum or product stops at the $(k+1)$-th term (and |
| 3071 |
the value is attained at the $k$-th term) when }$\left(L_{k+1}\right)_{r+2}=\left(L_{k}\right)_{r+2}$. |
| 3072 |
The hope is that if this is true at rounding value $r+2$ then at |
| 3073 |
rounding value $r$ the series or product will have attained a stable |
| 3074 |
value at that smaller rounding value. |
| 3075 |
|
| 3076 |
For a series of monotonic terms converging quickly to a limit, this |
| 3077 |
stopping criterion works well, less so if convergence is slower, as |
| 3078 |
seen earlier with the infinite product for $\sinh1$. The criterion |
| 3079 |
can fail completely when terms behave in a non-monotonic manner. Terms |
| 3080 |
of a Fourier series, for example, may take zero values so that $L_{k+1}=L_{k}$ |
| 3081 |
and, \emph{a fortiori}, $\left(L_{k+1}\right)_{r+2}=\left(L_{k}\right)_{r+2}$; |
| 3082 |
the criterion is necessarily satisfied but the series may still be |
| 3083 |
far from its limit. In a product the equivalent would be a term taking |
| 3084 |
unit value. Sometimes the initial terms of series or products are |
| 3085 |
`irregular' and take these `stopping' values meaning sum or product |
| 3086 |
would stop after only one or two additions/multiplications and far |
| 3087 |
from any limit. |
| 3088 |
|
| 3089 |
\begin{table}[t] |
| 3090 |
\centering |
| 3091 |
\centering{}\caption{Stopping criterion settings}\label{tab:calcStoppingCriterionSettings} |
| 3092 |
\begin{center} |
| 3093 |
{\small{}% |
| 3094 |
\begin{tabular}{ll>{\raggedright}p{6cm}l} |
| 3095 |
\toprule |
| 3096 |
{\small key} & {\small type} & {\small meaning} & {\small default}\tabularnewline |
| 3097 |
\midrule |
| 3098 |
{\small\texttt{S+}} & {\small int} & {\small extra rounding for sums} & {\small\texttt{2}}\tabularnewline |
| 3099 |
{\small\texttt{S?}} & {\small$\text{int}\ge0$} & {\small number of query terms for sums} & {\small\texttt{0}}\tabularnewline |
| 3100 |
{\small\texttt{P+}} & {\small int} & {\small extra rounding for products} & {\small\texttt{2}}\tabularnewline |
| 3101 |
{\small\texttt{P?}} & {\small$\text{int}\ge0$} & {\small number of query terms for products} & {\small\texttt{0}}\tabularnewline |
| 3102 |
\bottomrule |
| 3103 |
\end{tabular}} |
| 3104 |
\par\end{center} |
| 3105 |
\end{table} |
| 3106 |
To cope with these possibilities, \texttt{numerica} offers two settings |
| 3107 |
for sums, two for products, summarized in Table~\ref{tab:calcStoppingCriterionSettings}. |
| 3108 |
These are entered in the settings option of the \verb`\eval` command. |
| 3109 |
\begin{itemize} |
| 3110 |
\item \texttt{S+=<integer>} \texttt{(P+=<integer>)\quad{}} \emph{additional} |
| 3111 |
rounding on top of the specified (or default) rounding for the calculation; |
| 3112 |
the larger \texttt{<integer>} is, the more likely that sum or product |
| 3113 |
has attained a stable value at the specified rounding value $r$; |
| 3114 |
default = $2$ |
| 3115 |
\item \texttt{S?=<integer> $\ge0$ (P?=<integer> $\ge0$)\quad{}}the number |
| 3116 |
of terms to \emph{query} after the stopping criterion has been achieved |
| 3117 |
to confirm that it is not an `accident' of particular values; default |
| 3118 |
= $0$ |
| 3119 |
\begin{itemize} |
| 3120 |
\item once the stopping criterion has been met, we add/multiply these next |
| 3121 |
few terms to the result and check at each step whether the result |
| 3122 |
is unchanged at the specified rounding value. Suppose the additional |
| 3123 |
rounding (\texttt{S+} or \texttt{P+}) is $\delta r$ on top of the |
| 3124 |
specified rounding $r$ and let the number of query terms be $q$. |
| 3125 |
(By default $\delta r=2$ and $q=0$.) Suppose $L_{k_{0}}$ is the |
| 3126 |
first term at which the stopping criterion is achieved. That means |
| 3127 |
$\left(L_{k_{0}}\right)_{r+\delta r}=\left(L_{k_{0}+1}\right)_{r+\delta r}$. |
| 3128 |
What we require of the query terms is that $\left(L_{k_{0}}\right)_{r+\delta r}=\left(L_{k_{0}+1+j}\right)_{r+\delta r}$ |
| 3129 |
for $j=0,1,\ldots,q$. |
| 3130 |
\end{itemize} |
| 3131 |
\end{itemize} |
| 3132 |
Earlier we found that the infinite product for $\sinh1$ with the |
| 3133 |
default settings gave the wrong value, $0.174$, deficient by $1$ |
| 3134 |
in the last digit. We now have the means to tweak the stopping criterion |
| 3135 |
by increasing the additional rounding: |
| 3136 |
\begin{verbatim} |
| 3137 |
\eval[p,P+=3]{\[ |
| 3138 |
\prod_{k=1}^{\infty} |
| 3139 |
\biggl(\frac{x^2}{k^2\pi^2} +1\biggr) |
| 3140 |
\]}[x=1][3]\nmcInfo{prod}. |
| 3141 |
\end{verbatim} |
| 3142 |
\noindent$\Longrightarrow$ \noindent\eval[p,P+=3]{\[ |
| 3143 |
\prod_{k=1}^{\infty} |
| 3144 |
\biggl(\frac{x^2}{k^2\pi^2} +1\biggr) |
| 3145 |
\]}[x=1][3]\nmcInfo{prod}. To obtain that last item of information (350 factors), I've anticipated |
| 3146 |
a little and used the command \verb`\nmcInfo` with the argument \verb`prod` |
| 3147 |
(see §\ref{sec:supplInfo}). The product now produces the correct |
| 3148 |
three-figure value, but it takes $350$ factors to do so. |
| 3149 |
|
| 3150 |
Knowing how many terms or factors have been needed helps assess how |
| 3151 |
trustworthy the result from an infinite sum or product is. For example, |
| 3152 |
for the exponential series, |
| 3153 |
\begin{verbatim} |
| 3154 |
\eval[p]{\[ |
| 3155 |
\sum_{k=0}^\infty \frac1{k!} |
| 3156 |
\]}[9]\nmcInfo{sum}. |
| 3157 |
\end{verbatim} |
| 3158 |
$\Longrightarrow$ \eval[p]{\[\sum_{k=0}^\infty \frac1{k!} \]}[9]%\nmcInfo{sum}. |
| 3159 |
To $9$ places of decimals, using the default value \texttt{S+=2}, |
| 3160 |
the exponential series arrives at the right sum after only $15$ terms. |
| 3161 |
Convergence is rapid. We can trust this result (and it is in fact |
| 3162 |
the correct nine-figure value). By contrast, if we didn't know the |
| 3163 |
value of $\sinh1$ beforehand, noting the number of factors required |
| 3164 |
would make us justly cautious about accepting the result of the infinite |
| 3165 |
product calculation. |
| 3166 |
|
| 3167 |
\noindent{}% |
| 3168 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 3169 |
\begin{shaded}% |
| 3170 |
One way to gain confidence in a result is to choose a possibly unrealistic |
| 3171 |
rounding value $r$ – say the default $6$ for the infinite product |
| 3172 |
– then use \emph{negative} values for the additional rounding, \texttt{S+=-5}, |
| 3173 |
\texttt{S+=-4}, \ldots{} , so that the stopping criterion applies at |
| 3174 |
rounding values $s=r+S_{+}$ of $6+(-5)=1$ decimal place, $6+(-4)=2$ |
| 3175 |
decimal places, and so on, but the result is always presented to $6$ |
| 3176 |
decimal places. You can then see how the $6$-figure results behave |
| 3177 |
relative to the number of terms it takes to meet the stopping criterion. |
| 3178 |
A little experimenting shows that for the infinite product for $\sinh1$ |
| 3179 |
the number of factors $N_{s}$ required at a stopping rounding value |
| 3180 |
$s$ increases in geometric proportion with a scale factor of about |
| 3181 |
$3$: $N_{s}\approx\text{const}\times3^{s}$. This rapidly becomes |
| 3182 |
large ($3^{4}=81,3^{5}=243\dots$). For the exponential series on |
| 3183 |
the other hand $N_{s}=4+s$, the number of terms increases only slowly, |
| 3184 |
in direct proportion to the stopping rounding value. |
| 3185 |
|
| 3186 |
~ |
| 3187 |
|
| 3188 |
Similar experiments with the sums of inverse fourth, third and second |
| 3189 |
powers of the integers, using \verb`\nmcInfo` to find how many terms |
| 3190 |
are required at each stopping rounding value, show that at least over |
| 3191 |
the rounding value range $1$ to $8$, for inverse fourth powers $N_{s}\approx\text{const}\times1.7^{s}$, |
| 3192 |
for inverse third powers $N_{s}\approx\text{const}\times2^{s}$ and |
| 3193 |
for inverse squares $N_{s}\approx\text{const}\times3^{s}$. All are |
| 3194 |
geometric rather than arithmetic progressions, but for inverse fourth |
| 3195 |
powers the scale factor ($\approx1.7$) is sufficiently small that |
| 3196 |
for these low values of $s$ the number of terms required does not |
| 3197 |
grow too quickly (e.g.\ $1.7^6\approx\eval{1.7^6}[0]$). |
| 3198 |
|
| 3199 |
~ |
| 3200 |
|
| 3201 |
It is a standard result (Euler) that the inverse fourth power series |
| 3202 |
sums to $\pi^{4}/90$: \verb`$ \eval{ \pi^4/90 } $` $\Longrightarrow$ |
| 3203 |
$ \eval{ \pi^4/90 } $ to six places, and indeed, with the default |
| 3204 |
rounding value $6$ and default extra rounding \texttt{S+=2}, |
| 3205 |
\begin{centred} |
| 3206 |
\verb`\eval[p]{\[ \sum_{k=1}^\infty \frac1{k^4} \]}` $\Longrightarrow$ |
| 3207 |
\eval[p=.]{\[ \sum_{k=1}^\infty \frac1{k^4} \]} |
| 3208 |
\end{centred} |
| 3209 |
\end{shaded}% |
| 3210 |
\end{minipage} |
| 3211 |
|
| 3212 |
\subsubsection{Premature ending of infinite sums} |
| 3213 |
|
| 3214 |
All the series considered so far have been monotonic. Trigonometric |
| 3215 |
series will generally not be so, nor even single-signed. |
| 3216 |
|
| 3217 |
Trigonometric sums are computationally intensive and so, for the following |
| 3218 |
example, I have specified a rounding value of 2. The series |
| 3219 |
\[ |
| 3220 |
\sum_{n=1}^{\infty}\frac{4}{n^{2}\pi^{2}}(1-\cos n\pi)\cos2\pi nt |
| 3221 |
\] |
| 3222 |
is the Fourier series for the triangular wave function \textbackslash\!/\!\textbackslash\!/\!\textbackslash\!/\!\textbackslash{} |
| 3223 |
\ldots{} of period 1, symmetric about the origin where it takes its |
| 3224 |
maximum value 1, crossing the $t$-axis at $t=0.25$ and descending |
| 3225 |
to its minimum $-1$ at $t=0.5$, before ascending to a second maximum |
| 3226 |
at $t=1$ (and so on). In the interval $[0,0.5)$ the series should |
| 3227 |
sum to $1-4t$. The problem is that the summand $\frac{4}{n^{2}\pi^{2}}(1-\cos n\pi)\cos2\pi nt$ |
| 3228 |
vanishes both when $n$ is even and when $4nt$ is an odd integer. |
| 3229 |
If $t=0.1$ then $4nt$ is never an odd integer so the summand vanishes |
| 3230 |
only for $n$ even, every second term. We expect the result to be |
| 3231 |
$1-4\times0.1=0.6$. |
| 3232 |
\begin{verbatim} |
| 3233 |
\eval[p]{\[ |
| 3234 |
\sum_{n=1}^{\infty} |
| 3235 |
\frac{4}{n^{2}\pi^{2}} |
| 3236 |
(1-\cos n\pi)\cos2\pi nt |
| 3237 |
\]}[t=0.1][2]\nmcInfo{sum}. |
| 3238 |
\end{verbatim} |
| 3239 |
$\Longrightarrow$ \eval[p]{\[ |
| 3240 |
\sum_{n=1}^{\infty} |
| 3241 |
\frac{4}{n^{2}\pi^{2}} |
| 3242 |
(1-\cos n\pi)\cos2\pi nt |
| 3243 |
\]}[t=0.1][2]\info{sum}. Only one term? Of course – in the second term $n=2$ is even so the |
| 3244 |
term vanishes and the stopping criterion is satisfied. The way around |
| 3245 |
this problem is to query terms \emph{beyond} the one where the stopping |
| 3246 |
criterion is achieved, i.e.\ to set \texttt{S?} to a nonzero value. |
| 3247 |
We try \texttt{S?=1}: |
| 3248 |
\begin{verbatim} |
| 3249 |
\eval[p,S?=1]{\[ |
| 3250 |
\sum_{n=1}^{\infty} |
| 3251 |
\frac{4}{n^{2}\pi^{2}} |
| 3252 |
(1-\cos n\pi)\cos2\pi nt |
| 3253 |
\]}[t=0.1][2]\nmcInfo{sum}. |
| 3254 |
\end{verbatim} |
| 3255 |
$\Longrightarrow$ \eval[p,S?=1]{\[ |
| 3256 |
\sum_{n=1}^{\infty} |
| 3257 |
\frac{4}{n^{2}\pi^{2}} |
| 3258 |
(1-\cos n\pi)\cos2\pi nt |
| 3259 |
\]}[t=0.1][2]\info{sum}. |
| 3260 |
|
| 3261 |
\noindent{}% |
| 3262 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 3263 |
\begin{shaded}% |
| 3264 |
\begin{wraptable}{o}{0.35\columnwidth}% |
| 3265 |
\centering{}\vspace{-5ex} |
| 3266 |
\caption{Partial sums}\label{tab:calcPartialSums} |
| 3267 |
\abovetopsep=2ex % |
| 3268 |
\begin{tabular}{cc} |
| 3269 |
\toprule |
| 3270 |
$N$ & $\Sigma$\tabularnewline |
| 3271 |
\midrule |
| 3272 |
$63$ & $0.6001$\tabularnewline |
| 3273 |
$64$ & $0.6001$\tabularnewline |
| 3274 |
$65$ & $0.5999$\tabularnewline |
| 3275 |
$66$ & $0.5999$\tabularnewline |
| 3276 |
$67$ & $0.5999$\tabularnewline |
| 3277 |
\bottomrule |
| 3278 |
\end{tabular}\end{wraptable}% |
| 3279 |
Table~\ref{tab:calcPartialSums} lists the results of evaluating |
| 3280 |
the partial\emph{ }sums from $n=1$ to $n=N$ for values of $N$ around |
| 3281 |
$65$. Since the specified rounding value is $2$ for the calculation, |
| 3282 |
the stopping criterion\emph{ }applies at a rounding value of $2+2=4$. |
| 3283 |
Since $N=64$ is even, the $64$th term is zero and the sum takes |
| 3284 |
the same value as for $N=63$. The $65$th term is the query term |
| 3285 |
and the sum differs, so the summation continues. The $66$th term |
| 3286 |
vanishes, so the stopping criterion is met. This time for the query |
| 3287 |
term, the $67$th, the sum retains the same $4$-figure value, and |
| 3288 |
the summation \end{shaded}% |
| 3289 |
\end{minipage} |
| 3290 |
|
| 3291 |
\noindent{}% |
| 3292 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 3293 |
\begin{shaded}% |
| 3294 |
stops. The result was attained at the $65$th term. Should we be confident |
| 3295 |
in the result? Increase the number of query terms to $3$ (there is |
| 3296 |
no point in increasing \texttt{S?} to $2$ because of the vanishing |
| 3297 |
of the even terms); the sum stops after $113$ terms, with the same |
| 3298 |
$0.6$ result.\end{shaded}% |
| 3299 |
\end{minipage}\medskip{} |
| 3300 |
For a final example, consider the error function |
| 3301 |
\[ |
| 3302 |
\erf z=\dfrac{2}{\sqrt{\pi}}\int_{0}^{z}e^{-t^{2}}dt |
| 3303 |
\] |
| 3304 |
which can also be rendered as an infinite sum (\emph{HMF }7.1.5): |
| 3305 |
\[ |
| 3306 |
\erf z=\sum_{n=0}^{\infty}(-1)^{n}\frac{z^{2n+1}}{n!\,(2n+1)}. |
| 3307 |
\] |
| 3308 |
(\verb`\erf` expanding to \verb`erf` has been defined in the preamble |
| 3309 |
to this document using \verb`\DeclareMathOperator`.) We calculate |
| 3310 |
this sum when $z=2$ to $10$ places of decimals. Although this is |
| 3311 |
an alternating series, it is obvious that the summand never vanishes |
| 3312 |
when $z\ne0$ as here. Hence there seems no need to change the default |
| 3313 |
value \texttt{S?=0}. |
| 3314 |
\begin{verbatim} |
| 3315 |
\eval[p]{\[ |
| 3316 |
\frac2{\sqrt{\pi}} |
| 3317 |
\sum_{n=0}^\infty(-1)^n |
| 3318 |
\frac{z^{2n+1}}{n!\,(2n+1)} |
| 3319 |
\]}[z=2][10*]\nmcInfo{sum}. |
| 3320 |
\end{verbatim} |
| 3321 |
$\Longrightarrow$ \eval[p]{\[ |
| 3322 |
\frac2{\sqrt{\pi}} |
| 3323 |
\sum_{n=0}^\infty(-1)^n |
| 3324 |
\frac{z^{2n+1}}{n!\,(2n+1)} |
| 3325 |
\]}[z=2][10*]\nmcInfo{sum}. According to \emph{HMF }Table 7.1, this calculated value of $\erf2$ |
| 3326 |
is correct to all $10$ places. But beyond $z=2$ errors will begin |
| 3327 |
to interfere with the result. Note that $26$ terms means $n=26$ |
| 3328 |
was the last value of $n$ for which the summand was evaluated. (The |
| 3329 |
sum stops at the $26$th term, $n=25$, but the next term $n=26$ |
| 3330 |
needs to be calculated for the stopping criterion.) Fortuitously, |
| 3331 |
$2^{2\times26+1}=2^{53}$ is the greatest power of $2$ that can be |
| 3332 |
\emph{exactly} rendered to the $16$ significant figures that \texttt{l3fp} |
| 3333 |
uses. But $n!$ exceeds the $16$-significant figure limit of \texttt{l3fp} |
| 3334 |
when $n>21$, so despite the 10-figure result, errors have already |
| 3335 |
begun to occur in the denominator of the summand and accrue in the |
| 3336 |
sum when $z=2$. For larger $z$ values the errors can only get worse |
| 3337 |
and at some point will render the calculated value worthless at any |
| 3338 |
meaningful rounding value. For example, when $z=7$ the sum apparently |
| 3339 |
`evaluates' to over $929$ whereas we know that |
| 3340 |
\[ |
| 3341 |
\erf z<\dfrac{2}{\sqrt{\pi}}\int_{0}^{\infty}e^{-t^{2}}dt=1. |
| 3342 |
\] |
| 3343 |
|
| 3344 |
|
| 3345 |
\subsubsection{Double sums or products} |
| 3346 |
|
| 3347 |
\label{subsec:settinsDouble-sums-prods}Sums or products can be iterated. |
| 3348 |
For instance, the exponential function can be calculated this way: |
| 3349 |
\begin{verbatim} |
| 3350 |
\eval[p] |
| 3351 |
{\[ \sum_{k=0}^{\infty} |
| 3352 |
\prod_{m=1}^{k}\frac{x}{m} \]}[x=2] |
| 3353 |
\end{verbatim} |
| 3354 |
$\Longrightarrow$ \eval[p] |
| 3355 |
{\[ \sum_{k=0}^{\infty} |
| 3356 |
\prod_{m=1}^{k}\frac{x}{m} \]}[x=2] |
| 3357 |
|
| 3358 |
\noindent which is \verb`\eval{$ e^2 $}` $\Longrightarrow\eval{\ensuremath{e^{2}}}$. |
| 3359 |
|
| 3360 |
A second example is afforded by Euler's transformation of series (\emph{HMF~}3.6.27). |
| 3361 |
To calculate $e^{-1}$ we use |
| 3362 |
\begin{verbatim} |
| 3363 |
\eval[p] |
| 3364 |
{\[ \sum_{n=0}^{\infty} |
| 3365 |
\frac{(-1)^{n}}{n!} \]}[3]\info{sum}. |
| 3366 |
\end{verbatim} |
| 3367 |
$\Longrightarrow$ \eval[p]{\[ \sum_{n=0}^{\infty}\frac{(-1)^{n}}{n!} \]}[3]\info{sum}. |
| 3368 |
Following Euler, this series can be transformed to the form |
| 3369 |
\begin{verbatim} |
| 3370 |
\eval[p,S?=1]{\[ |
| 3371 |
\sum_{k=0}^\infty \frac{(-1)^k}{2^{k+1}} |
| 3372 |
\sum_{n=0}^k(-1)^n\binom kn \frac1{(k-n)!} |
| 3373 |
\]}[3]\nmcInfo{sum}. |
| 3374 |
\end{verbatim} |
| 3375 |
$\Longrightarrow$ \eval[p,S?=1]{\[ \sum_{k=0}^\infty \frac{(-1)^k}{2^{k+1}}\sum_{n=0}^k(-1)^n\binom kn \frac1{(k-n)!} \]}[3]\nmcInfo{sum}. |
| 3376 |
Note the setting \verb`S?=1`. Without it, the summation stops after |
| 3377 |
$1$ term, the $k=0$ term, because the $k=1$ term vanishes. With |
| 3378 |
\verb`S?=1` it takes $16$ terms of the \emph{outer }sum to reach |
| 3379 |
the stopping criterion. Since that sum starts at $0$, that means |
| 3380 |
that changing the upper limit from $\infty$ to $15$ should give |
| 3381 |
the same result – which it does, taking $\tfrac{1}{2}\times16\times17=136$ |
| 3382 |
terms in total to get there, to be compared with the $9$ terms of |
| 3383 |
the earlier simpler sum, and the terms are more complicated. Obviously |
| 3384 |
such double sums are computationally intensive. |
| 3385 |
|
| 3386 |
\section{Formatting commands} |
| 3387 |
|
| 3388 |
\label{sec:calcFormatting-commands}There are many formatting commands |
| 3389 |
which change the layout of a formula on the page but do not alter |
| 3390 |
its calculational content. \texttt{numerica} copes with a great many |
| 3391 |
of these, although there will surely be some that have been overlooked\footnote{Please contact the author in that case: [email protected]} |
| 3392 |
and which will trigger an `Unknown token' message; see §\ref{chap:errorsErrors}. |
| 3393 |
|
| 3394 |
\subsection{Spaces, phantoms, struts} |
| 3395 |
|
| 3396 |
These include cryptic forms like \verb`\,` \verb`\:` and \verb`\>`, |
| 3397 |
\verb`\;` and the corresponding `verbose' forms, \verb`\thinspace`, |
| 3398 |
\verb`\medspace` and \verb`\thickspace` and their negative equivalents |
| 3399 |
\verb`\!` or \verb`\negthinspace`, \verb`\negmedspace` and \verb`\negthickspace`: |
| 3400 |
\begin{centred} |
| 3401 |
\verb`\eval{$ 1\negthickspace+\negthickspace 1 $}` $\Longrightarrow$ |
| 3402 |
\eval{$ 1\negthickspace+\negthickspace 1 $} |
| 3403 |
\end{centred} |
| 3404 |
which is a tiny bit tighter than the text spacing, 1+1, and much tighter |
| 3405 |
than the usual math spacing $1+1$ – but it doesn't affect the result |
| 3406 |
of the calculation. |
| 3407 |
|
| 3408 |
Other spacing commands are \verb`\quad` and \verb`\qquad`, and \verb`\hspace{arg}` |
| 3409 |
and \verb`\mspace{arg}`. For \verb`\hspace` there is also a starred |
| 3410 |
form, \verb`\hspace*{arg}`. Phantoms similarly take an argument: |
| 3411 |
\verb`\phantom{arg}`, \verb`\hphantom{arg}` and \verb`\vphantom{arg}`. |
| 3412 |
\begin{centred} |
| 3413 |
\verb`\eval{$ 1\hphantom{mmm}+\hphantom{mmm}1 $}` $\Longrightarrow$ |
| 3414 |
\eval{$ 1\hphantom{mmm}+ \hphantom{mmm}1 $}. |
| 3415 |
\end{centred} |
| 3416 |
Like \verb`\vphantom`, struts allow vertical spacing adjustments. |
| 3417 |
\texttt{numerica} should digest both \verb`\xmathstrut[optarg]{arg}` |
| 3418 |
from \texttt{mathtools} and its `baby cousin' \verb`\mathstrut` |
| 3419 |
from \TeX . An example from \emph{The \TeX{} book} demonstrating the |
| 3420 |
use of \verb`\mathstrut` is |
| 3421 |
\begin{verbatim} |
| 3422 |
\eval{$\sqrt{\mathstrut a}+\sqrt{\mathstrut d}+ |
| 3423 |
\sqrt{\mathstrut y}$}[a=4,d=9,y=16] |
| 3424 |
\end{verbatim} |
| 3425 |
$\Longrightarrow$ \eval{$\sqrt{\mathstrut a}+\sqrt{\mathstrut d}+ |
| 3426 |
\sqrt{\mathstrut y}$}[a=4,d=9,y=16] . \medskip{} |
| 3427 |
|
| 3428 |
And here is an evaluation of a somewhat ridiculous expression modified |
| 3429 |
from the \texttt{mathtools} documentation that uses \verb`\xmathstrut`: |
| 3430 |
\begin{verbatim} |
| 3431 |
\eval{\[ \frac{ \frac{\xmathstrut{0.1} 2\ceil x-1} |
| 3432 |
{ \xmathstrut{0.25} \ceil x-\sin x } } |
| 3433 |
{\xmathstrut{0.4} \sqrt{10-\ceil x} } \]} |
| 3434 |
[x=\pi/6] |
| 3435 |
\end{verbatim} |
| 3436 |
$\Longrightarrow$ \eval{\[ \frac{ \frac{\xmathstrut{0.1} 2\ceil x-1} |
| 3437 |
{ \xmathstrut{0.25} \ceil x-\sin x } } |
| 3438 |
{\xmathstrut{0.4} \sqrt{10-\ceil x} } \]} |
| 3439 |
[x=\pi/6] |
| 3440 |
|
| 3441 |
\subsubsection{\texttt{\textbackslash mkern}, \texttt{\textbackslash mskip}} |
| 3442 |
|
| 3443 |
From version 3.0.0, both \verb`\mkern` and \verb`\mskip` are recognized |
| 3444 |
by \texttt{numerica}. \verb`\mkern` should be followed either by |
| 3445 |
an explicit space specification in \verb`mu` (math units), like \verb`3 mu` |
| 3446 |
(or \verb`3mu`), or a control sequence containing such a specification; |
| 3447 |
\verb`\mkern` should be followed by an explicit `glue' specification |
| 3448 |
or a control sequence containing such a specification. A glue spec. |
| 3449 |
is a distance in \verb`mu` possibly followed by some stretch and |
| 3450 |
shrink, e.g.\ \verb`3 mu plus 1 mu minus 2 mu` (or \verb`3muplus1muminus2mu`) |
| 3451 |
with or without the \verb`plus` and \verb`minus` parts. A silly |
| 3452 |
example of the use of \verb`\mkern` and \verb`\mskip` is the following: |
| 3453 |
\begin{verbatim} |
| 3454 |
\def\negvmu{-5mu} |
| 3455 |
\eval[env=$]{ 1 \mkern \negvmu + |
| 3456 |
\mskip 18mu plus 6mu minus 9mu 1 } |
| 3457 |
\end{verbatim} |
| 3458 |
$\Longrightarrow$ \def\negvmu{-5mu} |
| 3459 |
\eval[env=$]{ 1 \mkern \negvmu + |
| 3460 |
\mskip 18mu plus 6mu minus 9mu 1 }. |
| 3461 |
|
| 3462 |
\subsection{\texttt{\textbackslash splitfrac}, \texttt{\textbackslash splitdfrac}} |
| 3463 |
|
| 3464 |
The \texttt{mathtools} package provides \verb`\splitfrac` and \verb`\splitdfrac` |
| 3465 |
to aid handling of clumsy fractions. I've mangled the example in the |
| 3466 |
\texttt{mathtools} documentation illustrating this command to produce |
| 3467 |
an even more ridiculous illustration, adding to the mess an enormous |
| 3468 |
square root, \verb`\left` and \verb`\right` modifiers, and command-form |
| 3469 |
parentheses; also the use of \verb`\dfrac`. In the other direction, |
| 3470 |
the \verb`vv=` in the settings option suppresses the vv-list (see |
| 3471 |
§\ref{subsec:settingsVvDisplayChangeLocal}). A little mental arithmetic |
| 3472 |
will convince that we are evaluating the square root of $(9\times7)^{2}$ |
| 3473 |
which indeed is what we get: |
| 3474 |
\begin{verbatim} |
| 3475 |
\eval[p=.,vv=] |
| 3476 |
{\[ \sqrt{ \left\lparen |
| 3477 |
\frac{ \splitfrac{xy + xy + xy + xy + xy} |
| 3478 |
{+ xy + xy + xy + xy} |
| 3479 |
} |
| 3480 |
{ \dfrac z7} |
| 3481 |
\right\rparen \left\lparen |
| 3482 |
\frac{ \splitdfrac{xy + xy + xy + xy + xy} |
| 3483 |
{+ xy + xy + xy + xy} |
| 3484 |
} |
| 3485 |
{\dfrac z7}\right\rparen} |
| 3486 |
\]}[x=2,y=5,z=10] |
| 3487 |
\end{verbatim} |
| 3488 |
$\Longrightarrow$ \eval[p=.,vv=]{\[ |
| 3489 |
\sqrt{\left\lparen |
| 3490 |
\frac{ \splitfrac{xy + xy + xy + xy + xy} |
| 3491 |
{+ xy + xy + xy + xy} |
| 3492 |
} |
| 3493 |
{ \dfrac z7} |
| 3494 |
\right\rparen \left\lparen |
| 3495 |
\frac{ \splitdfrac{xy + xy + xy + xy + xy} |
| 3496 |
{+ xy + xy + xy + xy} |
| 3497 |
} |
| 3498 |
{\dfrac z7}\right\rparen} |
| 3499 |
\]}[x=2,y=5,z=10] |
| 3500 |
|
| 3501 |
\subsection{Colour} |
| 3502 |
|
| 3503 |
\label{subsec:calcColour}(Anglicised spelling at least for the heading!) |
| 3504 |
If you add to the preamble of your document the line |
| 3505 |
\begin{verbatim} |
| 3506 |
\usepackage{color} |
| 3507 |
\end{verbatim} |
| 3508 |
two commands become available, \verb`\textcolor[optarg]{arg1}{arg2}` |
| 3509 |
and the declaration form of command, \verb`\color[optarg]{arg}`. |
| 3510 |
\texttt{numerica} readily accepts the former in a formula to be evaluated: |
| 3511 |
\begin{centred} |
| 3512 |
\verb`\eval{$ \sin \tfrac\pi6n\textcolor{red}{T}+1 $}[T=9,n=3]` $\Longrightarrow$ |
| 3513 |
\eval{$ \sin \tfrac\pi6n\textcolor{red}{T}+1 $}[T=9,n=3] |
| 3514 |
\end{centred} |
| 3515 |
(assuming you had some wish to highlight the time $T$). You can even |
| 3516 |
colour the $T$ in the vv-list too, but it adds a lot of typing for |
| 3517 |
a small gain: |
| 3518 |
\begin{centred} |
| 3519 |
\verb`\eval{$ \sin \tfrac\pi6n\textcolor{red}{T}+1 $}[\textcolor{red}{T}=9,n=3]` |
| 3520 |
$\Longrightarrow$ \eval{$ \sin \tfrac\pi6n\textcolor{red}{T}+1 $}[\textcolor{red}{T}=9,n=3]. |
| 3521 |
\end{centred} |
| 3522 |
However \verb`\color` is a \emph{declaration} form of command. It |
| 3523 |
has effect until the end of the current group or environment. If you |
| 3524 |
want to restrict it to only part of that group you need to em-brace |
| 3525 |
the command and what it is to apply to, |
| 3526 |
\begin{verbatim} |
| 3527 |
<pre-stuff>{\color{red}<red-stuff>}<post-stuff} |
| 3528 |
\end{verbatim} |
| 3529 |
but that is where the problem arises. `Unannounced' brace groups |
| 3530 |
(see §\ref{subsec:evalBraced-groups}) can easily result in unexpected |
| 3531 |
results or \LaTeX{} errors. Writing |
| 3532 |
\begin{centred} |
| 3533 |
\verb`\eval{$ \color{red} \sin \tfrac\pi6nT+1 $}[T=9,n=3]`$\Longrightarrow$ |
| 3534 |
\eval{$ \color{red} \sin \tfrac\pi6nT+1 $}[T=9,n=3] |
| 3535 |
\end{centred} |
| 3536 |
is fine. So too, because the \verb`\color` command is `trapped' |
| 3537 |
within the braces defining the first argument of the \verb`\frac`, |
| 3538 |
is |
| 3539 |
\begin{centred} |
| 3540 |
\verb`\eval{$ \frac{\color[gray]{0.5}A}B $}[A=12,b=4]` $\Longrightarrow$\eval{$ \frac{\color[gray]{0.5}A}B $}[A=12,B=4]. |
| 3541 |
\end{centred} |
| 3542 |
(Both arguments of the \verb`\color` command have been used for grayscale |
| 3543 |
output.) Also fine is |
| 3544 |
\begin{centred} |
| 3545 |
\verb`\eval{$ 3{\color{red}x}+1 $}[x=2]` $\Longrightarrow$ \eval{$ 3{\color{red}x}+1 $}[x=2] |
| 3546 |
\end{centred} |
| 3547 |
because juxtaposition in this case means multiplication, but substituting |
| 3548 |
the actual value \verb`2` for \verb`x` produces |
| 3549 |
\begin{centred} |
| 3550 |
\verb`\eval{$ 3{\color{red}2}+1 $}` $\Longrightarrow$ \eval{$ 3{\color{red}2}+1 $}. |
| 3551 |
\end{centred} |
| 3552 |
Recall the discussion at §\ref{subsec:evalBraced-groups}. An \emph{unannounced} |
| 3553 |
brace group is simply appended to what has gone before. The resulting |
| 3554 |
juxtaposition of $3$ and $x$ means multiply which was what was intended, |
| 3555 |
but the juxtaposition of $3$ and $2$ has quite a different meaning. |
| 3556 |
|
| 3557 |
\subsection{\texttt{\textbackslash text}, \texttt{\textbackslash mbox} and |
| 3558 |
font commands} |
| 3559 |
|
| 3560 |
\label{subsec:calcText-mbox-fonts}The content of a \verb`\text` |
| 3561 |
or \verb`\mbox` command is \emph{invisible} to the \verb`\eval` |
| 3562 |
command and is ignored in calculations, |
| 3563 |
\begin{centred} |
| 3564 |
\verb`\eval*{ 1/0.0123456789 \mbox{approx.\ 81} }[5]` $\Longrightarrow$ |
| 3565 |
\eval*{ 1/0.0123456789 \mbox{approx.}}[5], |
| 3566 |
\end{centred} |
| 3567 |
even when the \verb`\text` or \verb`\mbox` contains mathematical |
| 3568 |
content. The author's view is that these commands are likely to be |
| 3569 |
used for comments, annotations, or remarks, rather than to modify |
| 3570 |
symbols of calculational significance. |
| 3571 |
|
| 3572 |
Conversely, \emph{specific }font commands, like \verb`\mathbf` or |
| 3573 |
\verb`\textrm`, may well apply to such symbols and so there content |
| 3574 |
should be \emph{visible} to \verb`\eval`. This becomes useful should |
| 3575 |
numbers be input in scientific notation (see §\ref{subsec:settingsInputtingSciNotation}) |
| 3576 |
where \verb`\textrm` or \verb`\texttt` may be useful so that a number |
| 3577 |
in scientific notation like \verb`2e-1` appearing in a formula or |
| 3578 |
the vv-list can display correctly rather than inappropriately as the |
| 3579 |
algebraic expression $2e-1$. |
| 3580 |
|
| 3581 |
The complete list of font commands where the content is visible to |
| 3582 |
\verb`\eval` is |
| 3583 |
\begin{enumerate} |
| 3584 |
\item \verb`\mathrm{}`, \verb`\mathit{}`, \verb`\mathtt{}`, \verb`\mathbf{}`, |
| 3585 |
\verb`\mathsf{}`, \verb`\mathcal{}`, \verb`\mathbb{}`, \verb`\mathfrak{}`, |
| 3586 |
\verb`\mathscr{}` |
| 3587 |
\item \verb`\textrm{}`, \verb`\textsf{}`, \verb`\texttt{}`, \verb`\textit{}`, |
| 3588 |
\verb`\textsl{}`, \verb`\textbf{}`, \verb`\textsc{}` |
| 3589 |
\end{enumerate} |
| 3590 |
The commands \verb`\mathbb{}` and \verb`\mathfrak{}` require the |
| 3591 |
\texttt{amsfonts} package to be loaded; \verb`\mathscr` requires |
| 3592 |
the \texttt{euscript} package to be loaded with the \verb`mathscr` |
| 3593 |
package option. |
| 3594 |
|
| 3595 |
\section{Environment precedence} |
| 3596 |
|
| 3597 |
\label{sec:calcEnvironment-precedence}Math environments are relevant |
| 3598 |
particularly for multi-formula calculations. For a single formula |
| 3599 |
evaluation, either an inline (\verb`$`) or \verb`equation*` (\verb`\[`) |
| 3600 |
environment is probably all that is needed. |
| 3601 |
|
| 3602 |
The environment of a calculation is determined in one or two of three |
| 3603 |
ways: first, \verb`\eval` may sit within an environment, |
| 3604 |
\begin{verbatim} |
| 3605 |
\begin{env} |
| 3606 |
\eval{...} |
| 3607 |
\end{env} |
| 3608 |
\end{verbatim} |
| 3609 |
Second, the \verb`env` setting may be used, \verb`\eval[env=...]{...}`. |
| 3610 |
And third, \verb`\eval` may wrap around an environment, e.g. \verb`\eval{\[...\]}`. |
| 3611 |
Should a user, inadvertently or otherwise, specify `extra' environments |
| 3612 |
in a calculation, the environment wrapping around \verb`\eval` takes |
| 3613 |
precedence over the \verb`env`-setting environment which takes precedence |
| 3614 |
over the environment wrapped within \verb`\eval`: |
| 3615 |
\begin{centred} |
| 3616 |
\verb`$\eval[env=align,pp,ff]{\[ \pi,e,\phi,\gamma \]}[3]$` $\Longrightarrow$ |
| 3617 |
$\eval[env=align,pp,ff]{\[ \pi,e,\phi,\gamma \]}[3]$. |
| 3618 |
\end{centred} |
| 3619 |
As you can see, the inline \verb`$` delimiters have prevails over |
| 3620 |
the \verb`align` environment and \verb`\[` \verb`\]` delimiters. |
| 3621 |
|
| 3622 |
Of course for the \verb`-ed` environments of \texttt{amsmath} a surrounding |
| 3623 |
math environment is necessary – as it is for \verb`cases`, \verb`dcases` |
| 3624 |
and \verb`array` environments. If \verb`\eval` wraps around an \verb`-ed` |
| 3625 |
or like environment, the surrounding environment may either be \verb`env`-specified |
| 3626 |
or wrap around \verb`\eval` (and if both are used, inadvertently |
| 3627 |
or otherwise, the latter takes precedence). |
| 3628 |
|
| 3629 |
\noindent{}% |
| 3630 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 3631 |
\begin{shaded}% |
| 3632 |
Having these three different ways of specifying the environment may |
| 3633 |
seem like overkill, but they are likely to arise in different contexts. |
| 3634 |
The author envisaged a user writing an expression within an environment |
| 3635 |
and then wondering what it evaluates to. Surely it is natural in this |
| 3636 |
case just to wrap \verb`\eval` around the lot, environment and expression, |
| 3637 |
and let \emph{it}, \verb`\eval`, do the \emph{formula=result} typesetting. |
| 3638 |
Or, one may enter an expression into \verb`\eval` \emph{before} deciding |
| 3639 |
on the environment. How much easier just to write \verb`env=align*` |
| 3640 |
(or whatever the environment chosen is) in the settings option than |
| 3641 |
to insert \verb`\begin{align*}` before the expression and \verb`\end{align*}` |
| 3642 |
after. Finally, \verb`\eval` can find itself within a surrounding |
| 3643 |
environment in many ways. It may be necessary in order to use an AMS |
| 3644 |
\verb`-ed` environment, or it may occur in a context like that in |
| 3645 |
§\ref{subsec:introExploring}. The upshot is that all three ways of |
| 3646 |
specifying environments should be – and are – catered for as of version |
| 3647 |
3.0.0.\end{shaded}% |
| 3648 |
\end{minipage} |
| 3649 |
|
| 3650 |
\chapter{Error messages } |
| 3651 |
|
| 3652 |
\label{chap:errorsErrors}There are two kinds of error in \texttt{numerica}: |
| 3653 |
those in the underlying \LaTeX{} which are reported in the \LaTeX{} |
| 3654 |
log and shown on the terminal, and generally halt compilation, and |
| 3655 |
specifically \texttt{numerica}-related errors which do not halt compilation |
| 3656 |
and produce messages displayed in the pdf where one would expect the |
| 3657 |
result of the calculation to be. The original reason for doing things |
| 3658 |
this way was to enable \texttt{numerica} to be used effectively with |
| 3659 |
the instant preview facility of the document processor \LyX . More |
| 3660 |
philosophically, one might view such errors as similar to errors of |
| 3661 |
grammar or spelling mistakes in text. It is not clear that they should |
| 3662 |
halt compilation. |
| 3663 |
|
| 3664 |
Hence strictly \texttt{numerica}-related errors leave brief messages |
| 3665 |
in the pdf at the offending places. From version 3.0.0 of \texttt{numerica} |
| 3666 |
they also leave messages in the \LaTeX{} log like |
| 3667 |
\begin{centred} |
| 3668 |
\verb`numerica error on line <n> in <location>` |
| 3669 |
\end{centred} |
| 3670 |
where \verb`<location>` will usually be \verb`formula` or \verb`variable=value list` |
| 3671 |
or possibly some more specific location like \verb`sum` or \verb`product`. |
| 3672 |
\verb`<n>` is the line number in the \verb`.tex` file where the |
| 3673 |
error occurs. These messages in the log do not halt compilation. They |
| 3674 |
allow the user to pinpoint – especially helpful in a long document |
| 3675 |
– the actual line in the \verb`.tex` file where the \texttt{numerica} |
| 3676 |
error occurs. |
| 3677 |
|
| 3678 |
Before discussing specific error messages, note that there is a debug |
| 3679 |
facility (of a sort) discussed below in §\ref{sec:settingsDebug}. |
| 3680 |
|
| 3681 |
\section{Specific messages} |
| 3682 |
|
| 3683 |
\texttt{numerica} error messages that appear in the \texttt{pdf} in |
| 3684 |
place of the expected result are in two parts: a \emph{what} part |
| 3685 |
and a \emph{where} part. |
| 3686 |
|
| 3687 |
\subsection{Mismatched brackets} |
| 3688 |
|
| 3689 |
\label{subsec:errorsMismatched-brackets}An unmatched left parenthesis |
| 3690 |
or other left bracket (in this case a missing right parenthesis) usually |
| 3691 |
results in a \texttt{numerica} error: |
| 3692 |
\begin{centred} |
| 3693 |
\verb`$\eval{\sin(\pi/(1+x)}[x=1]$` $\Longrightarrow$ $\eval{\sin(\pi/(1+x)}[x=1]$ |
| 3694 |
\end{centred} |
| 3695 |
For the same error in the vv-list, the \emph{what}-part remains unchanged |
| 3696 |
but the \emph{where}-part is altered: |
| 3697 |
\begin{centred} |
| 3698 |
\verb`$\eval{ 1+y }[x=1,y=\sin(\pi/(1+x)]$` $\Longrightarrow$ $\eval{ 1+y }[y=\sin(\pi/(1+x),x=1]$ |
| 3699 |
\end{centred} |
| 3700 |
An unmatched right parenthesis or other right bracket (in this case |
| 3701 |
a missing \emph{left} parenthesis) usually results in a similar \texttt{numerica} |
| 3702 |
error: |
| 3703 |
\begin{centred} |
| 3704 |
\verb`$\eval{2((x+y)/(y+z)))^2}[x=1,y=2,z=3]$` $\Longrightarrow$ |
| 3705 |
$\eval{2((x+y)/(y+z)))^{2}}[x=1,y=2,z=3]$ |
| 3706 |
\end{centred} |
| 3707 |
But note that an unmatched modifier like \verb`\left` or \verb`\right` |
| 3708 |
is a \LaTeX{} error and is caught by \LaTeX{} before \texttt{numerica} |
| 3709 |
can respond and so results in a terminal and logfile message. |
| 3710 |
|
| 3711 |
\subsection{Unknown tokens} |
| 3712 |
|
| 3713 |
An `Unknown token' message can arise in a number of ways. If an |
| 3714 |
expression involves a number of variables, some of which depend on |
| 3715 |
others, their order in the vv-list matters: |
| 3716 |
\begin{center} |
| 3717 |
\verb`$\eval{\tfrac12 vt}[t=2,v=gt,g=9.8]$` $\Longrightarrow$ \eval{\tfrac{1}{2}vt}[t=2,v=gt,g=9.8] |
| 3718 |
\par\end{center} |
| 3719 |
|
| 3720 |
\noindent The vv-list is evaluated from the \emph{right} so that in |
| 3721 |
this example the variable \verb`v` depends on a quantity \verb`t` |
| 3722 |
that is not yet defined. Hence the message. The remedy is to move |
| 3723 |
\verb`t` to the right of \verb`v` in the vv-list. |
| 3724 |
|
| 3725 |
Similarly, if we use a variable in the formula that has not been assigned |
| 3726 |
a value in the vv-list, we again get the `Unknown token' message, |
| 3727 |
but this time the location is the formula: |
| 3728 |
\begin{centred} |
| 3729 |
\verb`$\eval{\pi r^2h}[r=3]$` $\Longrightarrow$ \eval{\pi r^{2}h}[r=3] |
| 3730 |
\end{centred} |
| 3731 |
The remedy obviously is to assign a value to \verb`h` in the vv-list\texttt{.} |
| 3732 |
|
| 3733 |
The same message will result if a mathematical operation or function |
| 3734 |
is used that has not been implemented in \texttt{numerica}: |
| 3735 |
\begin{centred} |
| 3736 |
\verb`$\eval{u \bmod v }[v=7,u=3]$` $\Longrightarrow$ \eval{u\bmod v}[v=7,u=3] |
| 3737 |
\end{centred} |
| 3738 |
A missing comma in the vv-list will generally result in an unknown |
| 3739 |
token message: |
| 3740 |
\begin{centred} |
| 3741 |
\verb`$\eval{axy}[a=3 y=2,x=1]$` $\Longrightarrow$ \eval{axy}[a=3y=2,x=1] |
| 3742 |
\end{centred} |
| 3743 |
Because of the missing comma, \texttt{numerica} sees only two variables |
| 3744 |
in the vv-list, \verb`x` and \verb`a` and assumes \verb`a` has |
| 3745 |
the `value' \verb`3y=2`, an expression which it then tries to evaluate, |
| 3746 |
but \verb`y` has not been assigned a value. Parenthetically, if you |
| 3747 |
give \verb`y` a value, say \verb`y=2/3`, the expression evaluates, |
| 3748 |
treating the combination \verb`3 y=2` as a comparison evaluating |
| 3749 |
to true for this value of \verb`y`, meaning \verb`a=1` and |
| 3750 |
\begin{centred} |
| 3751 |
\verb`$\eval{axy}[a=3 y=2,y=2/3,x=1]$` $\Longrightarrow$ $\vsp\eval{axy}[a=3 y=2,y=2/3,x=1]$. |
| 3752 |
\end{centred} |
| 3753 |
\emph{Extra} commas in the vv-list should cause no problems: |
| 3754 |
\begin{centred} |
| 3755 |
\verb`$\eval{axy}[,a=3,,y=2,x=1,]$` $\Longrightarrow$ $\eval{axy}[,a=3,,y=2,x=1,]$ |
| 3756 |
. |
| 3757 |
\end{centred} |
| 3758 |
The presence of multi-token variables can also cause an unknown token |
| 3759 |
message if the check for such variables is turned off; see §\ref{subsec:settingsMultitokSwitch}. |
| 3760 |
|
| 3761 |
\subsection{Overlooked value assignments} |
| 3762 |
|
| 3763 |
Perhaps if one is evaluating a long formula with a number of variables |
| 3764 |
and assigning different experimental values to them to see the effect, |
| 3765 |
a variable might be overlooked (I have done this). The example is |
| 3766 |
too simple to be a likely candidate for this error but shows the message: |
| 3767 |
\begin{centred} |
| 3768 |
\verb`$\eval{axy}[a=3,y=,x=1]$` $\Longrightarrow$ \eval{axy}[a=3,y=,x=1] |
| 3769 |
\end{centred} |
| 3770 |
In the example the variable \verb`y` has been overlooked. The remedy |
| 3771 |
is obvious. |
| 3772 |
|
| 3773 |
\subsection{Negative integers in the wrong place} |
| 3774 |
|
| 3775 |
Factorials (apart from the double factorial \eval{$(-1)!!$}), binomial |
| 3776 |
coefficients, and $n$-th roots, require positive or at least non-negative |
| 3777 |
integers. |
| 3778 |
\begin{centred} |
| 3779 |
\verb`\eval{$ \sqrt[-1]{2} $}` $\Longrightarrow$ \eval{$ \sqrt[-1]{2} $}\medskip{} |
| 3780 |
|
| 3781 |
\verb`\eval{$ (-3)! $}` $\Longrightarrow$ \eval{$ (-3)! $}\medskip{} |
| 3782 |
|
| 3783 |
\verb`\eval{$ \binom{7}{-3} $}` $\Longrightarrow$ \eval{$ \binom{7}{-3} $} |
| 3784 |
\end{centred} |
| 3785 |
|
| 3786 |
\subsection{Invalid base for \texttt{\textbackslash log}} |
| 3787 |
|
| 3788 |
ISO recommends using \verb`\log` only with a subscripted base specified, |
| 3789 |
a recommendation honoured in the breach rather than the observance. |
| 3790 |
\texttt{numerica} assumes that when \verb`\log` is used unsubscripted, |
| 3791 |
the base is 10 and that \verb`\ln` is used for base \verb`e`. Suppose |
| 3792 |
you want to make $12$ the base, but forget to put braces around the |
| 3793 |
$12$: |
| 3794 |
\begin{centred} |
| 3795 |
\verb`$\eval{ \log_12 1728 }$` $\Longrightarrow$ $\eval{ \log_12 1728 } $ |
| 3796 |
\end{centred} |
| 3797 |
Here, \texttt{numerica} has taken \texttt{1} as the base (and $2$ |
| 3798 |
as the argument) of the logarithm and responds accordingly. |
| 3799 |
|
| 3800 |
\subsection{Environment errors} |
| 3801 |
|
| 3802 |
Errors can arise from environments wrongly used, although environmental |
| 3803 |
precedence (§\ref{sec:calcEnvironment-precedence}) sidesteps a number |
| 3804 |
of apparent problems. Some environments – \verb`aligned`, \verb`alignedat`, |
| 3805 |
\verb`gathered`, \verb`cases`, \verb`dcases` and \verb`array` |
| 3806 |
– can be used only within another math environment. Thus |
| 3807 |
\begin{centred} |
| 3808 |
\verb`\eval[env=aligned,ff]{ \sin x, \cos x, \tan x }[x=\pi/6]` $\Longrightarrow$ |
| 3809 |
\eval[env=aligned,ff]{\sin x, \cos x, \tan x}[x=\pi/6] |
| 3810 |
\end{centred} |
| 3811 |
The remedy, obviously, is to put the \verb`\eval` command between, |
| 3812 |
say, \verb`\[`, \verb`\]` delimiters. In the other direction, because |
| 3813 |
of environment precedence, forgetting the \verb`ed` at the end of |
| 3814 |
the \verb`env`-ironment does not result in an error but displays |
| 3815 |
the result in the outer, wrapping environment: |
| 3816 |
\begin{verbatim} |
| 3817 |
\[ \eval[env=align,p=.,ff] |
| 3818 |
{ \sin x, \cos x, \tan x}[x=\pi/6] \] |
| 3819 |
\end{verbatim} |
| 3820 |
$\Longrightarrow$ \[ \eval[env=align,p=.,ff] |
| 3821 |
{ \sin x, \cos x, \tan x}[x=\pi/6] \] |
| 3822 |
|
| 3823 |
An unknown environment produces a message: |
| 3824 |
\begin{verbatim} |
| 3825 |
\eval[env=foo]{ \pi }\par |
| 3826 |
\eval{\begin{foo} \pi \end{foo}} |
| 3827 |
\end{verbatim} |
| 3828 |
$\Longrightarrow$ \eval[env=foo]{ \pi }\par |
| 3829 |
\eval{\begin{foo} \pi \end{foo}} |
| 3830 |
|
| 3831 |
\subsection{\texttt{l3fp} errors} |
| 3832 |
|
| 3833 |
Some errors arising at the \texttt{l3fp} level are trapped and a message |
| 3834 |
displayed. |
| 3835 |
|
| 3836 |
\subsubsection{Dividing by zero} |
| 3837 |
\begin{centred} |
| 3838 |
\verb`$\eval{1/\sin x}[x=0]$` $\Longrightarrow$ \eval{1/\sin x}[x=0] |
| 3839 |
\end{centred} |
| 3840 |
Note however that |
| 3841 |
\begin{centred} |
| 3842 |
\verb`$\eval{1/\sin x}[x=\pi]$` $\Longrightarrow\,\eval{1/\sin x}[x=\pi]$, |
| 3843 |
\end{centred} |
| 3844 |
because of rounding errors in distant decimal places. No doubt this |
| 3845 |
is true for other functions as well. |
| 3846 |
|
| 3847 |
\subsubsection{Invalid operation} |
| 3848 |
|
| 3849 |
\label{subsec:errorsInverse-powers}Finding inverse integer powers |
| 3850 |
of \emph{positive} numbers should always be possible, but raising |
| 3851 |
a \emph{negative} number to an inverse power generates an error even |
| 3852 |
when – mathematically – it should not: |
| 3853 |
\begin{centred} |
| 3854 |
\verb`\eval{$ (-125)^{1/3} $}` $\Longrightarrow$ \eval{$ (-125)^{1/3} $} |
| 3855 |
\end{centred} |
| 3856 |
This is a feature of floating point arithmetic. When a number is raised |
| 3857 |
to a rational power, say $p/q$ where $p$ and $q$ are non-zero integers, |
| 3858 |
then the result is the $p$th power of the $q$-th root of the number. |
| 3859 |
Can a $q$-th root be taken? If our floating point system used (for |
| 3860 |
ease of illustration) only $4$ significant digits, $p/q=1/3$ would |
| 3861 |
be the fraction $3333/10^{4}$, an odd numerator over an even denominator. |
| 3862 |
But a negative number does not possess an even ($10^{4}$th) root. |
| 3863 |
The user needs to take care of the minus sign, in this case simply |
| 3864 |
by omitting the parentheses. |
| 3865 |
|
| 3866 |
Trying to evaluate a function like a factorial or square root or inverse |
| 3867 |
trig. function outside its domain of definition also produces this |
| 3868 |
error: |
| 3869 |
\begin{centred} |
| 3870 |
\verb`$\eval{\arccos x}[x=2]$` $\Longrightarrow$ $\eval{\arccos x}[x=2]$ |
| 3871 |
\end{centred} |
| 3872 |
In this case the inverse cosine, which is defined only on the interval |
| 3873 |
$[-1,1]$, has been fed the value $2$. |
| 3874 |
|
| 3875 |
Trying to evaluate an expression that resolves to $0/0$ also produces |
| 3876 |
this message: |
| 3877 |
\begin{centred} |
| 3878 |
\verb`$\eval{\frac{1-y}{x-2}}[x=2,y=1]$` $\Longrightarrow$ \eval{\frac{1-y}{x-2}}[x=2,y=1] |
| 3879 |
\end{centred} |
| 3880 |
|
| 3881 |
\subsubsection{Overflow/underflow} |
| 3882 |
|
| 3883 |
The factorial (discussed in §\ref{sec:calcFactorialsBinom}) provides |
| 3884 |
an example of overflow: |
| 3885 |
\begin{centred} |
| 3886 |
\verb`$\eval{3249!}$`\texttt{ }$\Longrightarrow$ \eval{3249! } |
| 3887 |
\end{centred} |
| 3888 |
This is hardly surprising since |
| 3889 |
\begin{centred} |
| 3890 |
\verb`$\eval{3248!}[x]$` $\Longrightarrow$ $\eval{3248!}[x]$. |
| 3891 |
\end{centred} |
| 3892 |
There is a limit on the size of exponents that \texttt{l3fp} can handle. |
| 3893 |
A number in the form $a\times10^{b}$ must have $-10001\le b<10000$. |
| 3894 |
If this is not the case an overflow or underflow condition occurs. |
| 3895 |
As the examples show, an overflow condition generates a \texttt{numerica} |
| 3896 |
error. |
| 3897 |
|
| 3898 |
For underflow, where the number is closer to $0$ than $10^{-10001}$, |
| 3899 |
\texttt{l3fp} assigns a zero value to the quantity. \texttt{numerica} |
| 3900 |
accepts the zero value and the error is ignored. |
| 3901 |
|
| 3902 |
\subsection{Obsolete settings} |
| 3903 |
|
| 3904 |
(For settings, see the next chapter.) Some settings in earlier versions |
| 3905 |
of \texttt{numerica} may be superseded by later developments and rendered |
| 3906 |
obsolete. With version 3.0.0 there are two of these obsolete settings, |
| 3907 |
and some deprecations. The superseded settings are these: |
| 3908 |
\begin{itemize} |
| 3909 |
\item \verb`()` \quad{}previously a setting for handling complicated arguments |
| 3910 |
to trigonometric functions. Now \LaTeX{} braces are recommended; see |
| 3911 |
§\ref{subsec:evalBraced-groups} and §\ref{subsec:calcComplicated-arguments}. |
| 3912 |
\item \verb`reuse` \quad{}previously a setting determining what is saved |
| 3913 |
with the \verb`\nmcReuse` command (§\ref{sec:supplReuse}). Now only |
| 3914 |
the numerical result is saved – although it can be saved in a variety |
| 3915 |
of forms, depending on the result-format specification in the \verb`\eval` |
| 3916 |
command. |
| 3917 |
\end{itemize} |
| 3918 |
Use of either setting generates a similar message, changing only the |
| 3919 |
content between the quote marks in the following: |
| 3920 |
\begin{centred} |
| 3921 |
\verb`\eval[()=2]{$ \sin\frac12\bigl(A+B\bigr) $}[A=\pi/5,B=\pi/7]` |
| 3922 |
$\Longrightarrow$ \eval[()=2] {$ \sin\frac12\bigl(A+B\bigr) $}[A=\pi/5,B=\pi/7] |
| 3923 |
\end{centred} |
| 3924 |
|
| 3925 |
\chapter{Settings} |
| 3926 |
|
| 3927 |
\label{chap:settingsSettings}The first square-bracketed optional |
| 3928 |
argument (and second argument overall) of the \verb`\nmcEvaluate` |
| 3929 |
command (see Chapter~\ref{chap:evalEvaluate}) is the settings option |
| 3930 |
preceding the main argument that contain the expression or expressions |
| 3931 |
to be evaluated. The settings option is a comma-separated\footnote{Including when the \texttt{comma} package option is used. No \emph{decimal} |
| 3932 |
number is required in the settings, only integers.} \emph{key=value} list. Such\emph{ }lists tend to be wordy. For back-of-envelope |
| 3933 |
calculations one wants to be able to `dash off' the calculation; |
| 3934 |
hence short, cryptically named keys have been used. Many settings |
| 3935 |
are generic, applicable not only to \verb`\nmcEvaluate` but also |
| 3936 |
to other commands that are available in \texttt{numerica} (see Chapter~\ref{chap:Supplementary-commands}) |
| 3937 |
and the packages \texttt{numerica-plus} and \texttt{numerica-tables} |
| 3938 |
– briefly described in §\ref{subsec:introPackagesOptions}. |
| 3939 |
|
| 3940 |
A calculation is effected against a background of assigned values |
| 3941 |
for various quantities – the calculational environment. For a particular |
| 3942 |
calculation, these values may not be appropriate; or you may have |
| 3943 |
different preferences. The complete list of such settings available |
| 3944 |
for \verb`\nmcEvaluate` (or \verb`\eval`) is shown in Tables~\ref{tab:settingsFunctionalSettingsParams} |
| 3945 |
and \ref{tab:settingsDisplaySettingsParams}, separated into \emph{functional} |
| 3946 |
settings (which affect the calculation) and \emph{display} settings |
| 3947 |
(which don't). |
| 3948 |
\begin{itemize} |
| 3949 |
\item The \emph{initial} values listed are the values assigned to the settings |
| 3950 |
initially at each use of the \verb`\eval` (and other) commands. |
| 3951 |
\item A \emph{default} value is the value assigned to the setting if you |
| 3952 |
simply enter its name (without assigning a value to it) in the settings |
| 3953 |
option. |
| 3954 |
\item $0/1$ alternatives are interpreted as $1$ meaning ON and $0$ meaning |
| 3955 |
OFF. |
| 3956 |
\end{itemize} |
| 3957 |
For example, entering \verb`o` in the settings option is equivalent |
| 3958 |
to entering \verb`o=1`, meaning angles are assumed to be in degrees, |
| 3959 |
but unless \verb`o` is entered, \verb`\eval` uses \verb`o=0`, the |
| 3960 |
initial value, meaning angles are assumed to be in radians. |
| 3961 |
|
| 3962 |
\begin{table} |
| 3963 |
\centering |
| 3964 |
\centering{}\caption{Functional settings parameters}\label{tab:settingsFunctionalSettingsParams} |
| 3965 |
\begin{center} |
| 3966 |
\begin{tabular}{>{\raggedright}p{1.5cm}>{\raggedright}p{1.5cm}>{\raggedright}p{3cm}>{\raggedright}p{1.5cm}>{\raggedright}p{1.5cm}} |
| 3967 |
\toprule |
| 3968 |
{\small key} & {\small type} & {\small meaning} & {\small default} & {\small initial}\tabularnewline |
| 3969 |
\midrule |
| 3970 |
{\small\texttt{dbg}} & {\small int} & {\small debug data} & & {\small\texttt{0}}\tabularnewline |
| 3971 |
{\small\texttt{view}} & & {\small\texttt{dbg=1}} & {\small\texttt{dbg=1}} & \tabularnewline |
| 3972 |
{\small\texttt{\textasciicircum}} & {\small char} & {\small exp. mark for sci. notation input} & {\small\texttt{e}} & \tabularnewline |
| 3973 |
{\small\texttt{xx}} & {\small int (0/1)} & {\small accept multi-token variables} & & {\small\texttt{1}}\tabularnewline |
| 3974 |
\multirow{2}{1.5cm}{\texttt{ff}} & \multirow{2}{1.5cm}{{\small char}} & \multirow{2}{3cm}{{\small main arg. multi- formula delimiter}} & \multicolumn{2}{l}{{\small\texttt{, }}{\small (if decimal dot)}}\tabularnewline |
| 3975 |
& & & \multicolumn{2}{l}{{\small\texttt{; }}{\small (if decimal comma)}}\tabularnewline |
| 3976 |
{\small\texttt{1s2}} & {\small int (0/1)} & {\small allow spaced digit groups in numbers} & {\small\texttt{1}} & {\small\texttt{0}}\tabularnewline |
| 3977 |
{\small\texttt{/min}} & {\small$\text{int}\ge1$} & {\small fraction form denom- inator search start} & & {\small\texttt{1}}\tabularnewline |
| 3978 |
{\small\texttt{/max}} & {\small$\text{int}\ge1$} & {\small fraction form denom- inator search end} & & {\small\texttt{200}}\tabularnewline |
| 3979 |
{\small\texttt{vv@}} & \multirow{3}{1.5cm}{{\small int (0/1)}} & \multirow{3}{3cm}{{\small vv-list calculation mode}} & \multirow{3}{1.5cm}{} & \multirow{3}{1.5cm}{{\small\texttt{0}}}\tabularnewline |
| 3980 |
\multirow{2}{1.5cm}{{\small\texttt{vvmode}}} & & & & \tabularnewline |
| 3981 |
& & & & \tabularnewline |
| 3982 |
{\small\texttt{o}} & {\small int (0/1)} & {\small trig. function args in degrees} & {\small\texttt{1}} & {\small\texttt{0}}\tabularnewline |
| 3983 |
{\small\texttt{log}} & {\small num} & {\small base of logs for }{\small{\small\verb`\log`}} & & {\small\texttt{10}}\tabularnewline |
| 3984 |
{\small\texttt{S+}} & {\small int} & {\small extra rounding, sums} & & {\small\texttt{2}}\tabularnewline |
| 3985 |
{\small\texttt{S?}} & {\small$\text{int}\ge0$} & {\small number of query terms, sums} & & {\small\texttt{0}}\tabularnewline |
| 3986 |
{\small\texttt{P+}} & {\small int} & {\small extra rounding, products } & & {\small\texttt{2}}\tabularnewline |
| 3987 |
{\small\texttt{P?}} & {\small$\text{int}\ge0$} & {\small number of query terms, products} & & {\small\texttt{0}}\tabularnewline |
| 3988 |
\cmidrule{1-1} |
| 3989 |
{\small\texttt{()}} & \multicolumn{4}{l}{{\small obsolete; see §\ref{sec:settinsDeprecatedObsoleteOptions}}}\tabularnewline |
| 3990 |
{\small\texttt{reuse}} & \multicolumn{4}{l}{{\small obsolete; see §\ref{sec:settinsDeprecatedObsoleteOptions}}}\tabularnewline |
| 3991 |
{\small\texttt{{*}}} & \multicolumn{4}{l}{{\small obsolete; see §\ref{sec:settinsDeprecatedObsoleteOptions}}}\tabularnewline |
| 3992 |
\bottomrule |
| 3993 |
\end{tabular} |
| 3994 |
\par\end{center} |
| 3995 |
\end{table} |
| 3996 |
|
| 3997 |
\begin{table} |
| 3998 |
\centering |
| 3999 |
\caption{Display settings parameters}\label{tab:settingsDisplaySettingsParams} |
| 4000 |
\medskip{} |
| 4001 |
|
| 4002 |
\begin{tabular}{>{\raggedright}p{1cm}>{\raggedright}p{1.5cm}>{\raggedright}p{3.5cm}>{\centering}p{1.5cm}>{\centering}p{1.5cm}} |
| 4003 |
\toprule |
| 4004 |
{\small key} & {\small type} & {\small meaning} & {\small default} & {\small initial}\tabularnewline |
| 4005 |
\texttt{f} & {\small int (0/1)} & {\small show/hide formula} & & \tabularnewline |
| 4006 |
{\small\texttt{p}} & {\small token(s)} & {\small concluding punctuation } & {\small\texttt{,}} & \tabularnewline |
| 4007 |
{\small\texttt{pp}} & {\small token(s)} & {\small multi-formula inter- result punctuation} & {\small\texttt{,}} & \tabularnewline |
| 4008 |
\cmidrule{1-1} |
| 4009 |
{\small\texttt{env}} & {\small token(s)} & {\small math environment} & \multicolumn{2}{c}{{\small see Table~\ref{tab:settingsEnvironment-defaults}}}\tabularnewline |
| 4010 |
{\small\texttt{arg}} & {\small token(s)} & {\small arg. for }{\small\texttt{-at}}{\small , }{\small\texttt{array}}{\small{} |
| 4011 |
envs} & \multicolumn{2}{c}{{\small see Table~\ref{tab:settingsEnvironment-defaults}}}\tabularnewline |
| 4012 |
{\small\texttt{eq}} & {\small token(s)} & {\small relation symbol} & \multicolumn{2}{c}{{\small see Table~\ref{tab:settingsEnvironment-defaults}}}\tabularnewline |
| 4013 |
{\small\texttt{vv}} & {\small token(s)} & {\small vv-list specification} & \multicolumn{2}{c}{{\small see Table~\ref{tab:settingsEnvironment-defaults}}}\tabularnewline |
| 4014 |
{\small\texttt{sep}} & {\small token(s)} & {\small separator between multi-formula results} & \multicolumn{2}{c}{{\small see Table~\ref{tab:settingsEnvironment-defaults}}}\tabularnewline |
| 4015 |
{\small\texttt{\textbackslash\}}} & {\small token(s)} & {\small right bracket for inner math environments} & {\small\textbackslash{} }{\small\texttt{\textbackslash\}}} & \tabularnewline |
| 4016 |
\cmidrule{1-1} |
| 4017 |
{\small\texttt{vvi}} & \multicolumn{4}{l}{{\small deprecated; use }{\small\texttt{vv }}}\tabularnewline |
| 4018 |
{\small\texttt{vvd}} & \multicolumn{4}{l}{{\small deprecated; use }{\small\texttt{vv}}}\tabularnewline |
| 4019 |
\bottomrule |
| 4020 |
\end{tabular} |
| 4021 |
|
| 4022 |
\end{table} |
| 4023 |
|
| 4024 |
|
| 4025 |
\section{\textquoteleft Debug\textquoteright{} facility} |
| 4026 |
|
| 4027 |
\label{sec:settingsDebug}It is rather grandiose to call this a debug |
| 4028 |
facility, but if a calculation goes wrong or produces a surprising |
| 4029 |
result, \texttt{numerica} offers a means of examining various quantities |
| 4030 |
at some intermediate stages on the way to the final result. To use |
| 4031 |
the facility, enter |
| 4032 |
\begin{verbatim} |
| 4033 |
dbg = <integer> |
| 4034 |
\end{verbatim} |
| 4035 |
into the settings option. (White space around the equals sign is optional.) |
| 4036 |
\begin{itemize} |
| 4037 |
\item \verb`dbg=0`\texttt{ }turns off the debug function, displays the |
| 4038 |
result or error message (this is the initial setting); |
| 4039 |
\item \verb`dbg=1`\texttt{ }equivalent to \verb`dbg=2*3*5*7*11` for \verb`\eval`; |
| 4040 |
\end{itemize} |
| 4041 |
The `magic' integers are the first few prime numbers and their products |
| 4042 |
\begin{itemize} |
| 4043 |
\item \verb`dbg=2` displays the formula after multi-token variables have |
| 4044 |
been converted to their single token form, \verb`\nmc_a`, \verb`\nmc_b`, |
| 4045 |
etc.; |
| 4046 |
\item \verb`dbg=3` displays the vv-list after multi-token variables have |
| 4047 |
been converted to their single token form; |
| 4048 |
\item \verb`dbg=5` displays the stored variables and their values \emph{after} |
| 4049 |
evaluation (\verb`dbg=3` lists the values as expressions); |
| 4050 |
\item \verb`dbg=7` displays the formula after it has been fp-ified but |
| 4051 |
before it has been fed to \texttt{l3fp} to evaluate; |
| 4052 |
\begin{itemize} |
| 4053 |
\item When interpreting the fp-form, be aware that differences in the ways |
| 4054 |
\texttt{numerica} and \texttt{l3fp} read formulas can lead to more |
| 4055 |
or fewer parentheses than seem strictly necessary. In particular be |
| 4056 |
aware that in \texttt{l3fp} function calls bind most tightly so that, |
| 4057 |
for example, \verb`sin 2pi` evaluates not to zero but to $(\sin2)\times\pi$, |
| 4058 |
and \verb`sin x^2` evaluates to $(\sin x)^{2}$. \texttt{numerica} |
| 4059 |
takes care of the former by inserting extra parentheses and exploits |
| 4060 |
the latter by not inserting parentheses. |
| 4061 |
\end{itemize} |
| 4062 |
\item \verb`dbg=11` displays the \LaTeX{} form of the final display; it |
| 4063 |
will contain, \emph{inter alia}, the numerical result. |
| 4064 |
\end{itemize} |
| 4065 |
To display two or more of the debug elements simultaneously, use the |
| 4066 |
product of their debug numbers for the magic integer. This can be |
| 4067 |
entered either as the multiplied-out product, or as the `waiting |
| 4068 |
to be evaluated' product with asterisks (stars) between the factors. |
| 4069 |
Thus \verb`dbg=6` and \verb`dbg=2*3` each display both the vv-list |
| 4070 |
and formula after multi-token variables have been converted to single |
| 4071 |
token form; \verb`dbg=77` or \verb`dbg=7*11` each display both the |
| 4072 |
form of the expression that is fed to \texttt{l3fp} (the `fp-ified' |
| 4073 |
form) and the \LaTeX{} form of the final display (including the numerical |
| 4074 |
result). And generally, if an integer is divisible by $2$, $3$, |
| 4075 |
$5$, $7$, or $11$ the corresponding element of the debug display |
| 4076 |
will be shown. Both \verb`dbg=2310` and \verb`dbg=2*3*5*7*11` display |
| 4077 |
all five elements, but rather than remembering this product or typing |
| 4078 |
all those digits and asterisks, it suffices to enter \verb`dbg=1`. |
| 4079 |
This is equivalent and displays all elements. |
| 4080 |
|
| 4081 |
The debug option uses an \verb`aligned`\texttt{ }or \verb`align*` |
| 4082 |
environment to display its wares, depending on whether \verb`\eval` |
| 4083 |
lies within or around a math environment. The following uses \verb`align*` |
| 4084 |
and shows how multi-token variables are handled and how a chain of |
| 4085 |
comparisons is evaluated (§\ref{subsec:evalBoolean-output}): |
| 4086 |
\begin{verbatim} |
| 4087 |
\eval[dbg=1]{ a < 2a' < 3a'' } |
| 4088 |
[a=\pi,a'=\phi,a''=e\gamma][4???] |
| 4089 |
\end{verbatim} |
| 4090 |
$\Longrightarrow$ \eval[dbg=1]{ a < 2a' < 3a'' } |
| 4091 |
[a=\pi,a'=\phi,a''=e\gamma][4???] |
| 4092 |
|
| 4093 |
\noindent The various items are displayed in chronological order. |
| 4094 |
First comes the formula after conversion of multi-token to single-token |
| 4095 |
variables, then the vv-list in those single-token variables; these |
| 4096 |
are created essentially at the same time. Next the stored values of |
| 4097 |
the variables are displayed. These are the values \emph{after }vv-list |
| 4098 |
evaluation. (Even if the \verb`comma` package option is being used |
| 4099 |
and the decimal point is a comma, the stored values will display with |
| 4100 |
a decimal dot because this is what \texttt{l3fp} uses.) The fourth |
| 4101 |
element both in the display and chronologically is the fp-ified formula. |
| 4102 |
Often this can be a thicket of parentheses, especially if unary functions |
| 4103 |
or fractions are involved. The final element of both the display and |
| 4104 |
chronologically is the \LaTeX{} form of the display. In the example |
| 4105 |
it is skimpy, because no environment was specified. Putting, say, |
| 4106 |
\verb`env=$` in the settings option results in a much fuller final |
| 4107 |
line: |
| 4108 |
\begin{verbatim} |
| 4109 |
\eval[dbg=11,env=$]{ a < 2a' < 3a'' } |
| 4110 |
[a=\pi,a'=\phi,a''=e\gamma][4???] |
| 4111 |
\end{verbatim} |
| 4112 |
$\Longrightarrow$ \eval[dbg=11,env=$]{ a < 2a' < 3a'' } |
| 4113 |
[a=\pi,a'=\phi,a''=e\gamma][4???]By using \verb`dbg=11` in the settings option I have limited the |
| 4114 |
display to the \LaTeX{} form, since the other elements are unchanged. |
| 4115 |
|
| 4116 |
Mathematical operations that have no direct counterpart in \texttt{l3fp} |
| 4117 |
contribute only their numerical value to the fp-form. This applies |
| 4118 |
to sums and products, double factorials, partly to binomial coefficients, |
| 4119 |
and also to \verb`\eval` and other commands when nested one within |
| 4120 |
another (see Chapter~\ref{sec:miscNesting}). The following (ridiculous) |
| 4121 |
example illustrates the matter: |
| 4122 |
\begin{verbatim} |
| 4123 |
\eval[dbg=1]{\[ |
| 4124 |
\sum_{n=1}^k n + \binom{2k}{m} - \frac1{4k} + |
| 4125 |
\prod_{n=2}^k (1-1/n) + m!! \]}[m=6,k=5] |
| 4126 |
\end{verbatim} |
| 4127 |
$\Longrightarrow$ \eval[dbg=1]{\[ |
| 4128 |
\sum_{n=1}^k n + \binom{2k}{m} - \frac1{4k} + |
| 4129 |
\prod_{n=2}^k (1-1/n) + m!! \]}[m=6,k=5]($0$\textdegree{}~C in kelvin!) In the \verb`fp-form` line, the |
| 4130 |
various contributions to the overall result are displayed simply as |
| 4131 |
numbers because \texttt{l3fp} does not (at least as yet) handle these |
| 4132 |
elements natively. |
| 4133 |
|
| 4134 |
\subsection{Multi-formula calculations} |
| 4135 |
|
| 4136 |
Using \verb`dbg=1` on a multi-formula calculation displays the formula |
| 4137 |
and fp-form of the last formula `digested' by \verb`\eval`. Other |
| 4138 |
elements of the debug display are not limited in this way. If all |
| 4139 |
formulas are successfully evaluated then this will be the final formula |
| 4140 |
entered in the multi-formula calculation. But should there be an error |
| 4141 |
when evaluating one of the component formulas, \emph{that} will be |
| 4142 |
the last formula evaluated; the debug information will pertain to |
| 4143 |
that formula. For example, |
| 4144 |
\begin{verbatim} |
| 4145 |
\eval[dbg=1,ff]{$ \sin x, \arccos x, \tan x $}[x=\pi/3] |
| 4146 |
\end{verbatim} |
| 4147 |
$\Longrightarrow$ \eval[dbg=1,ff]{$ \sin x, \arccos x, \tan x $}[x=\pi/3]Both |
| 4148 |
error message and debug information are present, the debug information |
| 4149 |
pertaining to the formula, \verb`\arccos x`, where the error occurred. |
| 4150 |
|
| 4151 |
\subsection{Negative \texttt{dbg} values} |
| 4152 |
|
| 4153 |
Had the \verb`$` delimiters been placed around rather than within |
| 4154 |
the \verb`\eval` command in the last example, both error message |
| 4155 |
and debug display would have been crowded onto the one line and would |
| 4156 |
generally exceed the dimensions of the paper. The remedy is to turn |
| 4157 |
off the error message by using a \emph{negative} debug number of the |
| 4158 |
same numerical value, in this case \verb`dbg=-1` (note that this |
| 4159 |
use of \emph{negative} debug numbers differs from their use in previous |
| 4160 |
versions of \texttt{numerica}): |
| 4161 |
\begin{verbatim} |
| 4162 |
$\eval[dbg=-1,ff]{ \sin x, \arccos x, \tan x }[x=\pi/3]$ |
| 4163 |
\end{verbatim} |
| 4164 |
$\Longrightarrow$ $\eval[dbg=-1,ff]{ \sin x, \arccos x, \tan x}[x=\pi/3]$ |
| 4165 |
|
| 4166 |
\subsection{\texttt{view} setting} |
| 4167 |
|
| 4168 |
Putting \verb`dbg=1` in the settings option may seem somewhat obscure |
| 4169 |
in order to view internal values of \texttt{numerica}. Writing \verb`view` |
| 4170 |
instead (it does not need to be equated to anything) is equivalent |
| 4171 |
and should be easier to remember. |
| 4172 |
|
| 4173 |
\section{Other functional settings} |
| 4174 |
|
| 4175 |
\subsection{Inputting numbers in scientific notation} |
| 4176 |
|
| 4177 |
\label{subsec:settingsInputtingSciNotation}Outputting numbers in |
| 4178 |
scientific notation is controlled by the final trailing argument of |
| 4179 |
the \verb`\eval` command. Such output is turned off by default and |
| 4180 |
needs to be explicitly ordered. Similarly, \emph{inputting} numbers |
| 4181 |
in scientific notation is turned off by default and needs to be explicitly |
| 4182 |
ordered. To turn it on, write |
| 4183 |
\begin{verbatim} |
| 4184 |
^ = <char> |
| 4185 |
\end{verbatim} |
| 4186 |
\noindent in the settings option, where \verb`<char>` is any single |
| 4187 |
character, usually \verb`e` or \verb`d` or their upper-casings, |
| 4188 |
but not restricted to them: \verb`^=@` for instance is perfectly |
| 4189 |
possible, and has the advantage over \verb`e` or \verb`d` that it |
| 4190 |
doesn't conflict with the use of the character as a variable or constant. |
| 4191 |
\begin{centred} |
| 4192 |
\verb`$ \eval[^=@]{ 0.123 + 1.23@-1 } $` $\Longrightarrow$ $ \eval[^=@]{ 0.123 + 1.23@-1 } $. |
| 4193 |
\end{centred} |
| 4194 |
The example shows that numbers can still be input in ordinary decimal |
| 4195 |
form at the same time as scientific notation is used. |
| 4196 |
|
| 4197 |
The default exponent mark is \verb`e` so that entering \verb`^` |
| 4198 |
in the settings option is equivalent to entering \verb`^=e` and will |
| 4199 |
suffice to turn on the inputting of numbers in scientific notation |
| 4200 |
using this mark: |
| 4201 |
\begin{centred} |
| 4202 |
\verb`$ \eval[^]{ 0.123 + 1.23e-1 } $` $\Longrightarrow$ $ \eval[^]{ 0.123 + 1.23e-1 } $. |
| 4203 |
\end{centred} |
| 4204 |
With letters for the exponent mark – say \verb`d` or \verb`e` – |
| 4205 |
there is a problem in interpreting forms like \verb`8d-3` or \verb`2e-1`. |
| 4206 |
Does such a form denote a number in scientific notation or an algebraic |
| 4207 |
expression? In \texttt{numerica}, if the settings option shows \verb`^=d`, |
| 4208 |
then a form like \verb`8d-3` is treated as a number in scientific |
| 4209 |
notation. Similarly for \verb`e` or any other letter used as the |
| 4210 |
exponent mark for the input of scientific numbers. (But only one character |
| 4211 |
can be so used at a time.) Note that the number \emph{must start with |
| 4212 |
a digit}: \verb`e-1` for instance does not and will be treated as |
| 4213 |
an algebraic expression involving the exponential constant: |
| 4214 |
\begin{centred} |
| 4215 |
\verb`$ \eval[^]{ x+e-1 }[x=1] $` $\Longrightarrow$ $ \eval[^]{ x+e-1 }[x=1] $ |
| 4216 |
\end{centred} |
| 4217 |
but |
| 4218 |
\begin{centred} |
| 4219 |
\verb`$ \eval[^]{ x+1e-1 }[x=1] $` $\Longrightarrow$ $ \eval[^]{ x+1e-1 }[x=1] $. |
| 4220 |
\end{centred} |
| 4221 |
A problem of appearance arises if scientific numbers appear in the |
| 4222 |
vv-list or formula and either is displayed in the result. A number |
| 4223 |
like \verb`2e-1` will display as $2e-1$, as if it were an algebraic |
| 4224 |
expression. In version 1 of \texttt{numerica} the cure was to wrap |
| 4225 |
\verb`2e-1` in a \verb`\text` or \verb`\mbox` command. In version |
| 4226 |
2 of \texttt{numerica} the behaviour of \verb`\text` and \verb`\mbox` |
| 4227 |
was re-thought; see §\ref{subsec:calcText-mbox-fonts}. Their contents |
| 4228 |
are invisible to the \verb`\eval` command. The solution is to wrap |
| 4229 |
\verb`2e-1` in a \verb`\textrm` or \verb`\textsf` or \verb`\texttt` |
| 4230 |
command. These commands were not recognized by \verb`\eval` in version |
| 4231 |
1 but in versions from 2.0.0: |
| 4232 |
\begin{centred} |
| 4233 |
\verb`\eval[^=e]{$ 5x $ }[x=\texttt{2e-1}]` $\Longrightarrow$ \eval[^=e]{$ 5x $ }[x=\texttt{2e-1}] |
| 4234 |
, |
| 4235 |
|
| 4236 |
\verb`\eval[^=e]{$ 5\texttt{2e-1} $ }` $\Longrightarrow$ \eval[^=e]{$ 5(\texttt{2e-1}) $ } |
| 4237 |
. |
| 4238 |
\end{centred} |
| 4239 |
If you use a particular character as the exponent marker for inputting |
| 4240 |
numbers in scientific notation, it is good practice \emph{not} to |
| 4241 |
use that character as a variable, not because it will cause an error |
| 4242 |
but because it makes expressions harder to read. |
| 4243 |
|
| 4244 |
\subsection{Multi-token variables} |
| 4245 |
|
| 4246 |
\label{subsec:settingsMultitokSwitch}Variables need not consist of |
| 4247 |
a single character or token (like $x$ or $\alpha$). Multi-token |
| 4248 |
symbols like $x'$ or $t_{i}$ or $var$ are perfectly acceptable. |
| 4249 |
For its internal operations, \texttt{numerica} converts such multi-token |
| 4250 |
names to single tokens (as discussed in §\ref{subsec:evalVariableNames}). |
| 4251 |
This conversion takes time. Even if there are no multi-token variables |
| 4252 |
used at all, \texttt{numerica} still needs to check that that is so. |
| 4253 |
There is a setting that allows a user to turn off or turn on the check |
| 4254 |
for such variables by entering |
| 4255 |
\begin{verbatim} |
| 4256 |
xx = <integer> |
| 4257 |
\end{verbatim} |
| 4258 |
into the settings option. If \verb`<integer>` is \verb`0`, the check |
| 4259 |
for (and conversion of) multi-token variables is turned off; if \verb`<integer>` |
| 4260 |
is \verb`1` (or any other\emph{ non-zero} integer), the check, and |
| 4261 |
conversion if needed, goes ahead. \texttt{numerica} assumes multi-token |
| 4262 |
variables may be used (primed or subscripted variables are common) |
| 4263 |
so \verb`xx=1` is assumed initially. (The name for the key, \verb`xx`, |
| 4264 |
is chosen because \verb`x` is the most familiar variable of all, |
| 4265 |
introduced in elementary algebra, and doubling it like this suggests |
| 4266 |
multi-token-ness.) |
| 4267 |
|
| 4268 |
If checking is turned off when a multi-token variable is present, |
| 4269 |
an error results. We don't need to turn on the check in the first |
| 4270 |
of the following examples because that is the initial pre-set state. |
| 4271 |
Explicitly turning it off in the second produces an error. |
| 4272 |
\begin{centred} |
| 4273 |
\verb`\eval{$ x_0^{\,2} $}[x_0=5]` $\Longrightarrow$ \eval{$ x_0^{\,2} $}[x_0=5],\medskip{} |
| 4274 |
\verb`\eval[xx=0]{$ x_0^{\,2} $}[x_0=5]` $\Longrightarrow$\\ |
| 4275 |
\eval[xx=0]{$ x_0^{\,2} $}[x_0=5] |
| 4276 |
\end{centred} |
| 4277 |
|
| 4278 |
\subsection{Multi-formula separator} |
| 4279 |
|
| 4280 |
\label{subsec:settingsMulti-formula-separator}The \verb`\eval` command |
| 4281 |
can evaluate more than one formula at a time. This is activated with |
| 4282 |
the \verb`ff` setting. Entering |
| 4283 |
\begin{verbatim} |
| 4284 |
ff = <char> |
| 4285 |
\end{verbatim} |
| 4286 |
in the settings option means multiple formulas separated by \verb`<char>` |
| 4287 |
in the main argument of \verb`\eval` will be evaluated. For example, |
| 4288 |
using \verb`ff=|`: |
| 4289 |
\begin{centred} |
| 4290 |
\verb`\eval[ff=|,pp]{ \pi^e | e^\pi | 2\phi^{\phi\pi} }` $\Longrightarrow$ |
| 4291 |
\eval[ff=|,pp]{ \pi^e | e^\pi | 2\phi^{\phi\pi} }. |
| 4292 |
\end{centred} |
| 4293 |
When \verb`ff` is used without the \verb`= <char>` part, it defaults |
| 4294 |
to the vv-list separator – a comma if the decimal point is a dot (period, |
| 4295 |
full stop), a semicolon if the decimal point is a comma (i.e.\ if |
| 4296 |
the \verb`comma` package option is used). If \verb`ff=` is used, |
| 4297 |
with nothing on the right of the equals sign, to prevent a \LaTeX{} |
| 4298 |
error being raised, the vv-list separator is retained as the multi-formula |
| 4299 |
separator. |
| 4300 |
|
| 4301 |
\subsection{Spaced digit grouping} |
| 4302 |
|
| 4303 |
\label{subsec:settingsDigitGroupingSpaces}Numbers containing many |
| 4304 |
digits can be easier to read if the digits are grouped into blocks. |
| 4305 |
\texttt{numerica} accepts \emph{as input} numbers with such grouped |
| 4306 |
digits provided the intervening character is a space. This needs to |
| 4307 |
be explicitly turned on with the setting \verb`1s2`: |
| 4308 |
\begin{centred} |
| 4309 |
\verb`\eval[1s2]{ 12 3456.7890 1234 }` $\Longrightarrow$ \eval[1s2=1]{ 12 3456.7890 1234 }. |
| 4310 |
\end{centred} |
| 4311 |
Without the \verb`1s2` setting, the separate blocks of digits are |
| 4312 |
multiplied together: |
| 4313 |
\begin{verbatim} |
| 4314 |
\eval[dbg=77]{ 12 3456.7890 1234 } |
| 4315 |
\end{verbatim} |
| 4316 |
$\Longrightarrow$\eval[dbg=77]{$ 12 3456.7890 1234 $} |
| 4317 |
|
| 4318 |
\subsection{Fraction-form denominator limits} |
| 4319 |
|
| 4320 |
\label{subsec:settingsFractionOutput}To restrict the size of the |
| 4321 |
denominator in fraction-form ouput \verb`\eval` has two settings |
| 4322 |
\begin{verbatim} |
| 4323 |
/min = <integer1> |
| 4324 |
/max = <integer2> |
| 4325 |
\end{verbatim} |
| 4326 |
(Those are \emph{not} backslashes!) \verb`<integer1>` is the value |
| 4327 |
to start searching from for a denominator for the fraction; \verb`integer2` |
| 4328 |
is the value to search to and then stop the search if none has been |
| 4329 |
found (to the requested accuracy). The initial values are \verb`/min=1` |
| 4330 |
and \verb`/max=200`. See the discussion at §\ref{subsec:evalFraction-form-output}. |
| 4331 |
|
| 4332 |
\subsection{Calculation mode} |
| 4333 |
|
| 4334 |
\label{subsec:settingsRecalcMode}A variable may change in the course |
| 4335 |
of a calculation. This is certainly true of sums and products. If |
| 4336 |
a parameter in the vv-list depends on the variable then that parameter |
| 4337 |
will need to be recalculated, perhaps repeatedly, in the course of |
| 4338 |
a calculation. By entering either |
| 4339 |
\begin{verbatim} |
| 4340 |
vv@ = <integer> |
| 4341 |
\end{verbatim} |
| 4342 |
or (as in version 1 of \texttt{numerica}), |
| 4343 |
\begin{verbatim} |
| 4344 |
vvmode = <integer> |
| 4345 |
\end{verbatim} |
| 4346 |
in the settings option it is possible to turn on or off the ability |
| 4347 |
to repeatedly evaluate the vv-list; \verb`<integer>` here takes two |
| 4348 |
possible values, \verb`0` or \verb`1`. \verb`vv@=0` (or \verb`vvmode=0`) |
| 4349 |
means the vv-list is evaluated once at the start of the calculation; |
| 4350 |
\verb`vv@=1` (or\texttt{ }\verb`vvmode=1`) means the vv-list is |
| 4351 |
recalculated every time the relevant variable changes.\footnote{In version 1 of \texttt{numerica} only the \texttt{vvmode} name for |
| 4352 |
this setting was available. To the author's eye, the \texttt{@} sign |
| 4353 |
seems suggestively close to a symbol like $\circlearrowleft$ to mean |
| 4354 |
`redo' (and is generally available on keyboards). } |
| 4355 |
|
| 4356 |
For example, in a sum it may be desirable to place the summand, or |
| 4357 |
some part of it, in the vv-list. Since the summation variable obviously |
| 4358 |
changes during the course of the calculation, we need to enter \verb`vv@=1` |
| 4359 |
in the settings option. Repeating an earlier sum, \medskip{} |
| 4360 |
\begin{verbatim} |
| 4361 |
\eval[p=.,vv@=1]{\[ \sum_{k=1}^N f(k) \]} |
| 4362 |
[N=100,f(k)=1/k^3,{k}=1][4] |
| 4363 |
\end{verbatim} |
| 4364 |
$\Longrightarrow$ \eval[p=.,vv@=1]{\[ \sum_{k=1}^N f(k) \]} |
| 4365 |
[N=100,f(k)=1/k^3,{k}=1][4] |
| 4366 |
|
| 4367 |
As you can see, the summand \verb`f(k)` has been given explicit form |
| 4368 |
in the vv-list – equated to \verb`1/k^3`. That means we need to give |
| 4369 |
a preceding value to \verb`k` in the vv-list to avoid an unknown |
| 4370 |
token message, hence the rightmost entry. But we don't want \verb`k=1` |
| 4371 |
appearing in the final display, so we wrap \verb`k` in braces (see |
| 4372 |
§\ref{subsec:evalVvSuppressVars}). Since the value \verb`k=1` applies |
| 4373 |
only to the first term in the sum, to ensure it is not used for all |
| 4374 |
terms, we enter \verb`vv@=1` in the settings option. This turns vv-recalculation |
| 4375 |
mode on and ensures \verb`k=1` is overwritten by \verb`k=2`, \verb`k=3` |
| 4376 |
and so on, and the vv-list recalculated each time. The final result |
| 4377 |
is the same as before, although recalculating the vv-list at each |
| 4378 |
step is a more resource-hungry process. The difference may not be |
| 4379 |
marked for this example; with more complicated expressions it noticeably |
| 4380 |
takes longer. |
| 4381 |
|
| 4382 |
Because it is necessary to activate this switch when using \emph{implicit} |
| 4383 |
notations – like $f(k)$ in the example – rather than the explicit |
| 4384 |
form of the function in the main argument, it seems natural to call |
| 4385 |
\verb`vv@=1` \emph{implicit }mode and \verb`vv@=0` (the default) |
| 4386 |
\emph{explicit }mode. Most calculations are explicit mode – the vv-list |
| 4387 |
is evaluated only once.\emph{ } |
| 4388 |
|
| 4389 |
\subsection{Using degrees rather than radians} |
| 4390 |
|
| 4391 |
\label{subsec:settingsDegrees}You may find it more convenient to |
| 4392 |
use degrees rather than radians with trigonometric functions. This |
| 4393 |
can be switched on simply by entering a lowercase \verb`o` in the |
| 4394 |
settings option. (The author hopes the charitable eye sees a degree |
| 4395 |
symbol in the \verb`o`.) Thus |
| 4396 |
\begin{centred} |
| 4397 |
\verb`\eval[o]{$ \sin 30 $}` $\Longrightarrow$ \eval[o]{$ \sin 30 $}, |
| 4398 |
|
| 4399 |
\verb`\eval[o]{$ \arcsin 0.5 $}` $\Longrightarrow$ \eval[o]{$ \arcsin 0.5 $}. |
| 4400 |
\end{centred} |
| 4401 |
This is a \verb`0/1` switch, \verb`0` signifying \verb`off` or |
| 4402 |
`don't use degrees', \verb`1` signifying \verb`on` or `do use |
| 4403 |
degrees'. Out-of-the-box \texttt{numerica} assumes radians are being |
| 4404 |
used, \verb`o=0`. As noted in §\ref{subsec:calcTrigonometricFunctions}, |
| 4405 |
one can also append \verb`\degree` to a number (or a variable), making |
| 4406 |
the \verb`o` switch unnecessary for the \emph{direct} functions (but |
| 4407 |
always necessary if you want the \emph{inverse} functions to produce |
| 4408 |
an answer in degrees). |
| 4409 |
|
| 4410 |
\subsection{Specifying a logarithm base} |
| 4411 |
|
| 4412 |
\label{subsec:settingsLogBase}If you wish to use \verb`\log` without |
| 4413 |
a subscripted base in a particular calculation, then add an entry |
| 4414 |
like |
| 4415 |
\begin{verbatim} |
| 4416 |
log = <positive number> |
| 4417 |
\end{verbatim} |
| 4418 |
where \verb`<positive number>`~$\ne1$ to the settings option of |
| 4419 |
the \verb`\eval` command. The \verb`<positive number>` does not |
| 4420 |
need to be an integer. It could be \verb`e` (if you object to writing |
| 4421 |
\verb`\ln`) but is more likely to be $2$ or another small integer. |
| 4422 |
If no value is specified, \texttt{numerica} assumes \verb`log=10`. |
| 4423 |
|
| 4424 |
\subsection{\textquoteleft Infinite\textquoteright{} sum and product settings} |
| 4425 |
|
| 4426 |
These settings, \verb`S+=<integer>`, \verb`P+=<integer>`, \verb`S?=<integer>`, |
| 4427 |
\verb`P?=<integer>`, where the latter two are non-negative, determine |
| 4428 |
when the stopping criterion for `infinite' sums and products applies. |
| 4429 |
They are discussed in §\ref{sec:calcStoppingCriterion}. |
| 4430 |
|
| 4431 |
\section{Display-related settings} |
| 4432 |
|
| 4433 |
The following settings have no effect on the calculation but do change |
| 4434 |
how the result is displayed. |
| 4435 |
|
| 4436 |
\subsection{Show/hide formula, \texttt{f}} |
| 4437 |
|
| 4438 |
\verb`\eval` automatically shows the formula in the result display |
| 4439 |
if the \verb`env` setting is used to define the environment or \verb`\eval` |
| 4440 |
wraps around the environment, but if the environment wraps around |
| 4441 |
\verb`\eval`, display of the formula is suppressed. Either circumstance |
| 4442 |
can be changed by entering \verb`f=0` to suppress display of the |
| 4443 |
formula or \verb`f=1` to display the formula. |
| 4444 |
|
| 4445 |
\subsection{Environment settings, \texttt{env} etc.} |
| 4446 |
|
| 4447 |
\label{subsec:settingsEnvironmentSettings}The math environment in |
| 4448 |
which a calculation is presented can be specified in three different |
| 4449 |
ways: externally, with \verb`\eval` lying within the environment, |
| 4450 |
or internally, either through the \verb`env` setting |
| 4451 |
\begin{verbatim} |
| 4452 |
env=<environment> |
| 4453 |
\end{verbatim} |
| 4454 |
or by explicitly writing the environment into the main argument containing |
| 4455 |
the formula, although this last method is clumsy for anything other |
| 4456 |
than \verb`$...$` or \verb`\(...\)` or \verb`\[...\]`. If multiple |
| 4457 |
environments are – inadvertently or otherwise – specified, the outer |
| 4458 |
environment takes precedence over the \verb`env` setting which takes |
| 4459 |
precedence over the main-argument environment; this matter was discussed |
| 4460 |
with examples in §\ref{sec:calcEnvironment-precedence}. |
| 4461 |
|
| 4462 |
\begin{table} |
| 4463 |
\centering |
| 4464 |
\caption{Initial values for environments}\label{tab:settingsEnvironment-defaults} |
| 4465 |
\medskip{} |
| 4466 |
\begin{tabular}{lccV{\linewidth}l} |
| 4467 |
\toprule |
| 4468 |
{\small\texttt{env}} & {\small rem/}{\small\texttt{arg}} & {\small\texttt{eq}} & {\small\texttt{vv}} & {\small\texttt{sep}}\tabularnewline |
| 4469 |
\midrule |
| 4470 |
{\small\texttt{\$}} & \multirow{3}{*}{} & \multirow{3}{*}{{\small\texttt{=}}} & \multirow{3}{*}{\begin{cellvarwidth}[t] |
| 4471 |
{\small\texttt{,\textbackslash mskip 12muplus}}~\linebreak{} |
| 4472 |
{\small\texttt{6muminus9mu(vv)}} |
| 4473 |
\end{cellvarwidth}} & \multirow{3}{*}{{\small\texttt{\textbackslash quad}}}\tabularnewline |
| 4474 |
{\small\texttt{\textbackslash (}} & & & & \tabularnewline |
| 4475 |
{\small\texttt{math}} & & & & \tabularnewline |
| 4476 |
\cmidrule{1-1} |
| 4477 |
{\small\texttt{\textbackslash{[}}} & & {\small\texttt{=}} & \begin{cellvarwidth}[t] |
| 4478 |
{\small\texttt{,\textbackslash mskip 36mu}}~\linebreak{} |
| 4479 |
{\small\texttt{minus24mu(vv)}} |
| 4480 |
\end{cellvarwidth} & {\small\texttt{\textbackslash{]}\textbackslash{[}}}\tabularnewline |
| 4481 |
\cmidrule{1-1} |
| 4482 |
{\small\texttt{displaymath}} & \multirow{3}{*}{} & \multirow{3}{*}{{\small\texttt{=}}} & \multirow{3}{*}{\begin{cellvarwidth}[t] |
| 4483 |
{\small\texttt{,\textbackslash mskip 36mu}}~\linebreak{} |
| 4484 |
{\small\texttt{minus24mu(vv)}} |
| 4485 |
\end{cellvarwidth}} & \multirow{3}{*}{\begin{cellvarwidth}[t] |
| 4486 |
{\small\texttt{\textbackslash end\{}}{\small\texttt{\emph{env}}}{\small\texttt{\}}}~\linebreak{} |
| 4487 |
{\small\texttt{\textbackslash begin\{}}{\small\texttt{\emph{env}}}{\small\texttt{\}}} |
| 4488 |
\end{cellvarwidth}}\tabularnewline |
| 4489 |
{\small\texttt{equation}} & & & & \tabularnewline |
| 4490 |
{\small\texttt{equation{*}}} & & & & \tabularnewline |
| 4491 |
\cmidrule{1-1} |
| 4492 |
{\small\texttt{multline}} & \multirow{2}{*}{\begin{cellvarwidth}[t] |
| 4493 |
\centering |
| 4494 |
{\small\texttt{\textbackslash eval}}{\small{} in }\linebreak{} |
| 4495 |
{\small{} }{\small\texttt{m'line}} |
| 4496 |
\end{cellvarwidth}} & \multirow{2}{*}{{\small\texttt{=}}} & \multirow{2}{*}{\begin{cellvarwidth}[t] |
| 4497 |
{\small\texttt{,\textbackslash mskip 36mu}}~\linebreak{} |
| 4498 |
{\small\texttt{minus24mu(vv)}} |
| 4499 |
\end{cellvarwidth}} & \multirow{2}{*}{{\small\texttt{\textbackslash hfill\textbackslash\textbackslash}}}\tabularnewline |
| 4500 |
{\small\texttt{multline{*}}} & & & & \tabularnewline |
| 4501 |
\cmidrule{1-1} |
| 4502 |
{\small\texttt{multline}} & \multirow{2}{*}{\begin{cellvarwidth}[t] |
| 4503 |
\centering |
| 4504 |
{\small\texttt{m'line}}~\linebreak{} |
| 4505 |
{\small in }{\small\texttt{\textbackslash eval}} |
| 4506 |
\end{cellvarwidth}} & \multirow{2}{*}{{\small\texttt{=}}} & \multirow{2}{*}{{\small\texttt{,\textbackslash\textbackslash (vv)}}} & \multirow{2}{*}{\begin{cellvarwidth}[t] |
| 4507 |
{\small\texttt{\textbackslash end\{}}{\small\texttt{\emph{env}}}{\small\texttt{\}}}~\linebreak{} |
| 4508 |
{\small\texttt{\textbackslash begin\{}}{\small\texttt{\emph{env}}}{\small\texttt{\}}} |
| 4509 |
\end{cellvarwidth}}\tabularnewline |
| 4510 |
{\small\texttt{multline{*}}} & & & & \tabularnewline |
| 4511 |
\cmidrule{1-1} |
| 4512 |
{\small\texttt{eqnarray}} & \multirow{2}{*}{} & \multirow{2}{*}{{\small\texttt{\&=\&}}} & \multirow{2}{*}{\begin{cellvarwidth}[t] |
| 4513 |
{\small\texttt{,\textbackslash mskip 36mu}}~\linebreak{} |
| 4514 |
{\small\texttt{minus24mu(vv)}} |
| 4515 |
\end{cellvarwidth}} & \multirow{2}{*}{{\small\texttt{\textbackslash\textbackslash}}}\tabularnewline |
| 4516 |
{\small\texttt{eqnarray{*}}} & & & & \tabularnewline |
| 4517 |
\cmidrule{1-1} |
| 4518 |
{\small\texttt{align}} & \multirow{3}{*}{} & \multirow{3}{*}{{\small\texttt{\&=}}} & \multirow{3}{*}{\begin{cellvarwidth}[t] |
| 4519 |
{\small\texttt{,\textbackslash mskip 36mu}}~\linebreak{} |
| 4520 |
{\small\texttt{minus24mu(vv)}} |
| 4521 |
\end{cellvarwidth}} & \multirow{3}{*}{{\small\texttt{\textbackslash\textbackslash}}}\tabularnewline |
| 4522 |
{\small\texttt{align{*}}} & & & & \tabularnewline |
| 4523 |
{\small\texttt{aligned}} & & & & \tabularnewline |
| 4524 |
\cmidrule{1-1} |
| 4525 |
{\small\texttt{flalign}} & \multirow{2}{*}{} & \multirow{2}{*}{{\small\texttt{\&=}}} & \multirow{2}{*}{{\small\texttt{,\&(vv)}}} & \multirow{2}{*}{{\small\texttt{\textbackslash\textbackslash}}}\tabularnewline |
| 4526 |
{\small\texttt{flalign{*}}} & & & & \tabularnewline |
| 4527 |
\cmidrule{1-1} |
| 4528 |
{\small\texttt{gather}} & \multirow{3}{*}{} & \multirow{3}{*}{{\small\texttt{\&=\&}}} & \multirow{3}{*}{\begin{cellvarwidth}[t] |
| 4529 |
{\small\texttt{,\textbackslash mskip 12muplus}}~\linebreak{} |
| 4530 |
{\small\texttt{6muminus9mu(vv)}} |
| 4531 |
\end{cellvarwidth}} & \multirow{3}{*}{{\small\texttt{\textbackslash\textbackslash}}}\tabularnewline |
| 4532 |
{\small\texttt{gather{*}}} & & & & \tabularnewline |
| 4533 |
{\small\texttt{gathered}} & & & & \tabularnewline |
| 4534 |
\cmidrule{1-1} |
| 4535 |
{\small\texttt{alignat}} & \multirow{3}{*}{{\small\texttt{2}}} & \multirow{3}{*}{{\small\texttt{\&=\textbackslash ;\&}}} & \multirow{3}{*}{{\small\texttt{,\textbackslash qquad\&(vv)}}} & \multirow{3}{*}{{\small\texttt{\textbackslash\textbackslash}}}\tabularnewline |
| 4536 |
{\small\texttt{alignat{*}}} & & & & \tabularnewline |
| 4537 |
{\small\texttt{alignedat}} & & & & \tabularnewline |
| 4538 |
\cmidrule{1-1} |
| 4539 |
{\small\texttt{array}} & {\small\texttt{rcrl}} & {\small\texttt{\&=\&}} & {\small\texttt{,\&(vv)}} & {\small\texttt{\textbackslash\textbackslash}}\tabularnewline |
| 4540 |
\cmidrule{1-1} |
| 4541 |
{\small\texttt{cases}} & \multirow{2}{*}{} & \multirow{2}{*}{{\small\texttt{=}}} & \multirow{2}{*}{{\small\texttt{,\textbackslash quad\textbackslash hfill(vv)}}} & \multirow{2}{*}{{\small\texttt{\textbackslash\textbackslash}}}\tabularnewline |
| 4542 |
{\small\texttt{dcases}} & & & & \tabularnewline |
| 4543 |
\bottomrule |
| 4544 |
\end{tabular} |
| 4545 |
\end{table} |
| 4546 |
Table~\ref{tab:settingsEnvironment-defaults} lists the environments |
| 4547 |
that \verb`env` can be set to and that \verb`\eval` recognizes. |
| 4548 |
It also lists the initial values of the settings \verb`arg`, \verb`eq`, |
| 4549 |
\verb`vv` and \verb`sep`, designed to give sensible displays, without |
| 4550 |
further intervention by the user, in many circumstances. (When the |
| 4551 |
\verb`comma` package option is used, the comma leading the entries |
| 4552 |
in the \verb`vv` column is replaced by a semicolon.) If you are using |
| 4553 |
the \verb`env` setting, and want to change a value for one or more |
| 4554 |
of these settings, then the changed value must be entered \emph{after} |
| 4555 |
the \verb`env` setting to have any effect. |
| 4556 |
|
| 4557 |
There are other settings which inter-play with these environment settings |
| 4558 |
but are not given initial values by the \verb`env` setting as \verb`arg`, |
| 4559 |
\verb`eq`, \verb`vv` and \verb`sep` are, and so do not need to |
| 4560 |
follow it in the settings option, but it is clearer and therefore |
| 4561 |
good practice if they do. These are the punctuation settings \verb`p` |
| 4562 |
and \verb`pp`, and the \verb`\}` setting applying only to \verb`aligned`, |
| 4563 |
\verb`alignedat`, \verb`gathered`, \verb`cases`, \verb`dcases`, |
| 4564 |
and \verb`array` environments – ones that require an enclosing math |
| 4565 |
environment. The \verb`\}` setting gathers the results of a multi-formula |
| 4566 |
display within a large right delimiter (right brace by default); it |
| 4567 |
is usually followed by the vv-list and allows the results of a multi-formula |
| 4568 |
calculation to be collectively numbered rather than individually. |
| 4569 |
|
| 4570 |
\subsubsection{\texttt{arg}} |
| 4571 |
|
| 4572 |
The \verb`array` and \verb`alignat` group of environments require |
| 4573 |
an argument, as in \verb`\begin{array}{arg}...` and \verb`\begin{alignat}{arg}...`. |
| 4574 |
For recognized environments the pre-set value of \verb`arg` is shown |
| 4575 |
in the second column of Table~\ref{tab:settingsEnvironment-defaults}. |
| 4576 |
Note that the use of \verb`arg` environments is possible with \verb`\eval` |
| 4577 |
\emph{only} when used with the \verb`env` setting; otherwise the |
| 4578 |
\verb`{arg}` is misinterpreted and will generally cause an error, |
| 4579 |
as in the following, with its peculiar error message |
| 4580 |
\begin{verbatim} |
| 4581 |
\[ |
| 4582 |
\eval[ff]{ \begin{array}{rcll} |
| 4583 |
\sin x, \cos x, \tan x |
| 4584 |
\end{array}}[x=\pi/6] |
| 4585 |
\] |
| 4586 |
\end{verbatim} |
| 4587 |
$\Longrightarrow$ \[ |
| 4588 |
\eval[ff]{ \begin{array}{rclr} |
| 4589 |
\sin x, \cos x, \tan x |
| 4590 |
\end{array}}[x=\pi/6] |
| 4591 |
\] |
| 4592 |
|
| 4593 |
\noindent The problem does not arise when the \verb`env` setting |
| 4594 |
is used: |
| 4595 |
\begin{verbatim} |
| 4596 |
\[ |
| 4597 |
\eval[env=array,ff]{ |
| 4598 |
\sin x, \cos x, \tan x }[x=\pi/6][*] |
| 4599 |
\] |
| 4600 |
\end{verbatim} |
| 4601 |
$\Longrightarrow$ \[ |
| 4602 |
\eval[env=array,ff]{ |
| 4603 |
\sin x, \cos x, \tan x }[x=\pi/6][*] |
| 4604 |
\] |
| 4605 |
|
| 4606 |
\noindent In this case, with the pre-set \verb`arg=rcrl`, the formulas |
| 4607 |
are right-aligned, the equality signs are centred, the numerical results |
| 4608 |
are right-aligned and the vv-lists are left-aligned. These alignments |
| 4609 |
can be changed with the \verb`arg` setting, but this must \emph{follow} |
| 4610 |
the \verb`env` setting for the changes to have any effect. |
| 4611 |
|
| 4612 |
\subsubsection{\texttt{eq}} |
| 4613 |
|
| 4614 |
\label{subsec:settingsRelationSymbol}Throughout this document, \emph{formula=result} |
| 4615 |
displays have used the equality sign between the two sides. Most of |
| 4616 |
the results however have been approximate. If you want a different |
| 4617 |
relation symbol in the display, enter |
| 4618 |
\begin{verbatim} |
| 4619 |
eq=<char(s)> |
| 4620 |
\end{verbatim} |
| 4621 |
in the settings option. For example, |
| 4622 |
\begin{centred} |
| 4623 |
\verb`\eval[eq=\approx]{$ \pi $}[4]` $\Longrightarrow$ \eval[eq=\approx]{$ \pi $}[4]. |
| 4624 |
\end{centred} |
| 4625 |
If the \verb`approx` package option is being used, note that \verb`eq` |
| 4626 |
defaults to \verb`=` , so that – say – for a calculation with an |
| 4627 |
integer answer for which $\approx$ would be inappropriate it suffices |
| 4628 |
just to enter \verb`eq` to obtain $=$ between formula and result. |
| 4629 |
|
| 4630 |
A main use of this setting is with environments with alignment where |
| 4631 |
\verb`&=` and \verb`&=&` are natural values for \verb`eq`; see |
| 4632 |
below, §\ref{subsec:settingsEnvironmentSettings}. If the \verb`env` |
| 4633 |
setting is being used then the \verb`eq` setting must \emph{follow} |
| 4634 |
it to have any effect. |
| 4635 |
|
| 4636 |
\subsubsection{\texttt{vv}} |
| 4637 |
|
| 4638 |
\label{subsec:settingsVvDisplayChangeLocal}In many of the examples |
| 4639 |
in this document the vv-list has been displayed following the result. |
| 4640 |
It is wrapped in parentheses following a comma and a space. (A semicolon |
| 4641 |
replaces the comma if the \verb`comma` package option is used.) These |
| 4642 |
elements – comma, space, parentheses – can all be changed by entering |
| 4643 |
\begin{verbatim} |
| 4644 |
vv=<tokens> |
| 4645 |
\end{verbatim} |
| 4646 |
in the settings option. For example |
| 4647 |
\begin{verbatim} |
| 4648 |
vv=;\mskip 12mu plus 6mu minus 9mu(vv) |
| 4649 |
\end{verbatim} |
| 4650 |
will result in a semicolon immediately following the numerical result |
| 4651 |
followed by an elastic space followed by the actual vv-list – replacing |
| 4652 |
the placeholder \verb`vv` – enclosed in parentheses. No full stop |
| 4653 |
is inserted after the closing parenthesis because the \verb`\eval` |
| 4654 |
command may occur in the middle of a sentence (and the \verb`p` setting |
| 4655 |
is available for such punctuation in displaystyle contexts). For inline |
| 4656 |
use, the elasticity of the space becomes relevant when \TeX{} is adjusting |
| 4657 |
individual lines to fit sentences into paragraphs and paragraphs into |
| 4658 |
pages. If a comma were to replace the semicolon in the suggested vv-list |
| 4659 |
spec., it would need to be entered in braces or as \verb`\comma`, |
| 4660 |
since the settings option is a comma-separated list. In displaystyle |
| 4661 |
settings, some shrink in the space is a good idea to accommodate a |
| 4662 |
long formula or many variables in the vv-list. |
| 4663 |
|
| 4664 |
For a particular calculation with a surprising result, one might specify |
| 4665 |
\verb`vv=?!` with no vv-list shown (since the \verb`vv` placeholder |
| 4666 |
is not used on the right): |
| 4667 |
\begin{centred} |
| 4668 |
\verb`\eval[vv=?!]{$ \pi $}[\pi=3]` $\Longrightarrow$ \eval[vvi=?!]{$ \pi $}[\pi=3] |
| 4669 |
\end{centred} |
| 4670 |
Different formats for vv-list display are appropriate for different |
| 4671 |
environments. Those with alignment, like the AMS environments, may |
| 4672 |
have an alignment token \verb`&` following a comma (or semicolon) |
| 4673 |
before display of the vv-list proper; see below, §\ref{subsec:settingsEnvironmentSettings} |
| 4674 |
and Table~\ref{tab:settingsEnvironment-defaults}. If the \verb`env` |
| 4675 |
setting is being used then the \verb`vv` setting must \emph{follow} |
| 4676 |
it to have any effect. |
| 4677 |
|
| 4678 |
\subsubsection{\texttt{sep}} |
| 4679 |
|
| 4680 |
\label{subsec:settingsEnvironments-sep}Displaying the results of |
| 4681 |
a multi-formula calculation means separating the displays for each |
| 4682 |
result. The \verb`sep` setting specifies the tokens inserted between |
| 4683 |
each display: |
| 4684 |
\begin{verbatim} |
| 4685 |
sep = <tokens> |
| 4686 |
\end{verbatim} |
| 4687 |
where \verb`<tokens>` may be something like \verb`\quad` for an |
| 4688 |
inline environment or \verb`\\` in a multi-line environment, see |
| 4689 |
Table~\ref{tab:settingsEnvironment-defaults}. For \verb`multline` |
| 4690 |
and \verb`multline*` different values are assigned depending as \verb`\eval` |
| 4691 |
is wrapped by or wraps the environment. The function of the \verb`sep` |
| 4692 |
setting overlaps that of the \verb`pp` setting, but it proves more |
| 4693 |
flexible to keep them separate. Since \verb`env`-ironments come with |
| 4694 |
pre-set values of \verb`sep`, if both settings are being used, the |
| 4695 |
\verb`sep` setting must \emph{follow} \verb`env` for it to have |
| 4696 |
any effect. |
| 4697 |
|
| 4698 |
\subsubsection{\texttt{p}, \texttt{pp}} |
| 4699 |
|
| 4700 |
\label{subsec:settingsPunctuation}As noted in the discussion at §\ref{subsec:introPunctuation}, |
| 4701 |
punctuation of the display of a result is straightforward when the |
| 4702 |
\verb`\eval` command is used in inline contexts but requires use |
| 4703 |
of a setting in displaystyle environments. The setting |
| 4704 |
\begin{verbatim} |
| 4705 |
p = <char(s)> |
| 4706 |
\end{verbatim} |
| 4707 |
places {\ttfamily\verb`<char(s)>`} after the display of |
| 4708 |
everything else but within the environment delimiters. The default |
| 4709 |
punctuation mark is the comma so that entering \verb`p` alone will |
| 4710 |
produce a comma in the appropriate place. Since the settings option |
| 4711 |
is a comma-separated list, this saves having to write \verb`p={,}`. |
| 4712 |
Note that {\ttfamily\verb`<char(s)>`} need not be a single-character |
| 4713 |
punctuation mark: |
| 4714 |
\begin{centred} |
| 4715 |
\verb`\eval[p=\ \text{(but no 8!)}]{\[ \frac{1}{81} \]}[9]` $\Longrightarrow$ |
| 4716 |
\eval[p=\ \text{(but no 8!)}]{\[ \frac{1}{81} \]}[9] |
| 4717 |
\end{centred} |
| 4718 |
For multi-formula commands punctuation may be desired not just after |
| 4719 |
the final result (the \verb`p` setting) but also after the intermediate |
| 4720 |
results. For these, use the setting |
| 4721 |
\begin{verbatim} |
| 4722 |
pp = <char(s)> |
| 4723 |
\end{verbatim} |
| 4724 |
Like \verb`p`, the \verb`pp` setting defaults to a comma to avoid |
| 4725 |
having to write \verb`pp={,}`. See the examples at §\ref{subsec:intoMultiFormulaPunctuation} |
| 4726 |
and throughout this document. |
| 4727 |
|
| 4728 |
\subsubsection{\texttt{\textbackslash\}}} |
| 4729 |
|
| 4730 |
\label{subsec:settingsEnvironments-=00005C=00007D}Some environments |
| 4731 |
must lie within another math environment to be used. These environments |
| 4732 |
– the AMS \verb`-ed` environments, the \verb`cases` and \verb`dcases` |
| 4733 |
environments, and the \verb`array` environment – allow one to `collect' |
| 4734 |
results of a multi-formula calculation within a large right delimiter |
| 4735 |
– usually a right brace – and follow that with the vv-list. The setting |
| 4736 |
for this is \verb`\}`: |
| 4737 |
\begin{verbatim} |
| 4738 |
\} = <space-spec><right-delimiter> |
| 4739 |
\end{verbatim} |
| 4740 |
Here \verb`<space-spec>` is either a single token or a brace group |
| 4741 |
defining a space between the numerical results and the right delimiter. |
| 4742 |
\verb`<right-delimiter>` is any right delimiter that responds to |
| 4743 |
the command \verb`\right` of a \verb`\left` \verb`\right` pair; |
| 4744 |
that includes a dot, \verb`.` , if you want no delimiter. The default |
| 4745 |
specification is \verb`\}=\ \}`. In the following example an \verb`alignedat` |
| 4746 |
environment is used to align numerical results containing a minus |
| 4747 |
sign. The \verb`pp` and \verb`p` settings place commas after the |
| 4748 |
results, not after the vv-list. The full stop there is manually inserted |
| 4749 |
after the number-format option (and before the \verb`\]`). The example |
| 4750 |
shows how to suppress the needless repetition of the vv-list that |
| 4751 |
otherwise accompanies display of a multi-formula result. If so wished, |
| 4752 |
the three calculations could be collectively numbered by a single |
| 4753 |
equation number. |
| 4754 |
\begin{verbatim} |
| 4755 |
\[ |
| 4756 |
\eval[env=alignedat,pp,p,\}=.,vv=\qquad(vv),ff] |
| 4757 |
{ \sin nx, \cos (n+1)x, \tan x } |
| 4758 |
[n=2,x=\pi/6][*]. |
| 4759 |
\] |
| 4760 |
\end{verbatim} |
| 4761 |
$\Longrightarrow$ \[ |
| 4762 |
\eval[env=alignedat,pp,p,\}=.,vv=\qquad(vv),ff] |
| 4763 |
{ \sin nx, \cos (n+1)x, \tan x } |
| 4764 |
[n=2,x=\pi/6][*]. |
| 4765 |
\] |
| 4766 |
|
| 4767 |
\section{Deprecated and obsolete settings} |
| 4768 |
|
| 4769 |
\label{sec:settinsDeprecatedObsoleteOptions} |
| 4770 |
\begin{description} |
| 4771 |
\item [{\texttt{vvi,~vvd}}] These settings have been superseded by the |
| 4772 |
\verb`vv` setting as a result of the enhanced treatment of environments |
| 4773 |
in version 3.0.0 of \texttt{numerica}; see immediately above. Both |
| 4774 |
\verb`vvi` and \verb`vvd` settings are now treated as alternative |
| 4775 |
(but deprecated) names for \verb`vv`. |
| 4776 |
\item [{\texttt{{*}}}] In version $2$ of \texttt{numerica} this key was |
| 4777 |
used to suppress equation numbering when the \verb`vvd` specification |
| 4778 |
contained a newline character. If \verb`\\` was present in \verb`vvd`, |
| 4779 |
it triggered replacement of whatever math delimiters were enclosed |
| 4780 |
by the \verb`\eval` command with a \verb`multline` environment. |
| 4781 |
The star {*} then converted the \verb`multline` into a \verb`multline*`. |
| 4782 |
This is all now superseded by the enhanced treatment of environments. |
| 4783 |
\item [{\texttt{()}}] Earlier versions of \texttt{numerica} used this setting |
| 4784 |
to adjust how `expansively' the arguments of trigonometric functions |
| 4785 |
were read, with the arguments of such functions in Fourier series |
| 4786 |
in mind. Version 3.0.0 of \texttt{numerica} has dispensed with the |
| 4787 |
setting and now recommends using \LaTeX{} braces to delimit such arguments. |
| 4788 |
See the general discussion at §\ref{subsec:evalBraced-groups}, and |
| 4789 |
more specific discussion at §\ref{subsec:calcComplicated-arguments}. |
| 4790 |
\item [{\texttt{reuse}}] In earlier versions of \texttt{numerica} this |
| 4791 |
setting determined exactly what was saved with the next \verb`\reuse` |
| 4792 |
command. Now only the `naked' numerical result is saved, although |
| 4793 |
it may be in scientific notation or fraction form; see §\ref{subsec:supplReuseEvalSetting}. |
| 4794 |
\end{description} |
| 4795 |
|
| 4796 |
\chapter{Supplementary commands} |
| 4797 |
|
| 4798 |
\label{chap:Supplementary-commands}This chapter introduces four commands, |
| 4799 |
\verb`\nmcInfo` (met already in relation to infinite sums), \verb`\nmcMacros`, |
| 4800 |
\verb`\nmcConstants` and \verb`\nmcReuse`, supplementary to the |
| 4801 |
principal command \verb`\nmcEvaluate`. They use the same machinery |
| 4802 |
as \verb`\nmcEvaluate` and so have the same syntax. If all arguments |
| 4803 |
are present it is |
| 4804 |
\begin{centred} |
| 4805 |
\noindent\verb`\nmc<cmd>*[settings]{main arg}[vv-list][rounding]` |
| 4806 |
\end{centred} |
| 4807 |
where \verb`<cmd>` is one of \verb`Info`, \verb`Macros`, \verb`Constants` |
| 4808 |
and \verb`Reuse`. All four commands have short-name forms: \verb`\info`, |
| 4809 |
\verb`\macros`, \verb`\constants`, \verb`\reuse`. |
| 4810 |
|
| 4811 |
Generally the final two optional arguments will not be used. The user |
| 4812 |
should be aware of this if following a command with a square bracketed |
| 4813 |
expression – the expression will be absorbed without trace unless |
| 4814 |
it is preceded by, for example, an empty brace pair. Because the commands |
| 4815 |
share the machinery of \verb`\nmcEvaluate`, the \verb`dbg`, \verb`view` |
| 4816 |
and functional settings discussed in the previous chapter (Chapter~\ref{chap:settingsSettings}) |
| 4817 |
for the \verb`\eval` command are also available for these commands, |
| 4818 |
although many will be without effect. |
| 4819 |
|
| 4820 |
The starred form of command is available in all four cases and in |
| 4821 |
all cases produces a pure number. If both star ( \verb`*` ) and \verb`view` |
| 4822 |
are used at the same time, the \verb`view` setting prevails over |
| 4823 |
starring. |
| 4824 |
|
| 4825 |
\section{Feedback on \textquoteleft infinite\textquoteright{} processes:\texttt{ \textbackslash nmcInfo}} |
| 4826 |
|
| 4827 |
\label{sec:supplInfo}Used after the evaluation of an `infinite' |
| 4828 |
process, the \verb`\nmcInfo` command, or its short-name form \verb`\info`, |
| 4829 |
will tell you how many terms or factors or other operations\footnote{It also applies to the commands \texttt{\textbackslash nmcIterate |
| 4830 |
}and \texttt{\textbackslash nmcSolve} from the \texttt{numerica-plus |
| 4831 |
}package.} were needed to arrive at the result.The main argument contains an |
| 4832 |
identifier for the `infinite' process: |
| 4833 |
\begin{verbatim} |
| 4834 |
\nmcInfo{<arg>} |
| 4835 |
\end{verbatim} |
| 4836 |
(or, using the short-name form, \verb`\info{<arg>}`) where, at this |
| 4837 |
stage, \verb`<arg>` is either \verb`sum` or \verb`prod`. The display, |
| 4838 |
as we have seen in earlier examples, is a number followed by a space |
| 4839 |
then a descriptor. For \verb`sum` and \verb`prod` the descriptors |
| 4840 |
are \verb`terms` and \verb`factors` respectively. Starring \verb`\nmcInfo` |
| 4841 |
– \verb`\nmcInfo*{arg}` or \verb`\info*{arg}` – suppresses the descriptor |
| 4842 |
and leaves only the number. |
| 4843 |
|
| 4844 |
As an example, let's test `the hard way' a standard identity, $\cosh^{2}x-\sinh^{2}x=1$. |
| 4845 |
We know that $\cosh x=\sum_{n=0}^{\infty}\frac{x^{2n}}{(2n)!}$ and |
| 4846 |
$\sinh x=x\prod_{k=1}^{\infty}\left(1+\frac{x^{2}}{k^{2}\pi^{2}}\right)$. |
| 4847 |
The difference of their squares should be $1$: |
| 4848 |
\begin{verbatim} |
| 4849 |
\eval{\[ |
| 4850 |
\left[\sum_{n=0}^{\infty} |
| 4851 |
\frac{x^{2n}}{(2n)!} |
| 4852 |
\right]^2- |
| 4853 |
\left[x\prod_{k=1}^{\infty} |
| 4854 |
\left(1+\frac{x^{2}}{k^{2}\pi^{2}}\right) |
| 4855 |
\right]^2 |
| 4856 |
\]}[x=1][3] \info{sum},\quad \info{prod}. |
| 4857 |
\end{verbatim} |
| 4858 |
$\Longrightarrow$ \eval{\[ |
| 4859 |
\left[\sum_{n=0}^{\infty} |
| 4860 |
\frac{x^{2n}}{(2n)!}\right]^2- |
| 4861 |
\left[x\prod_{k=1}^{\infty} |
| 4862 |
\left(1+\frac{x^{2}}{k^{2}\pi^{2}}\right) |
| 4863 |
\right]^2 |
| 4864 |
\]}[x=1][3] \info{sum},\quad\info{prod}. |
| 4865 |
|
| 4866 |
Nearly right. Obviously the product converges only slowly which is |
| 4867 |
where the error comes from (see the discussion in §\ref{sec:calcStoppingCriterion}, |
| 4868 |
where we needed the extra rounding setting \texttt{P+=3} and $350$ |
| 4869 |
factors to get a correct 3-figure value). The point of the example |
| 4870 |
is to show the information command being used for both sum and product |
| 4871 |
in the one evaluation. One does not exclude the other. |
| 4872 |
|
| 4873 |
The starred form of the \verb`\info` command suppresses the descriptor |
| 4874 |
(`terms' or `factors') and gives a purely numerical result: |
| 4875 |
\begin{verbatim} |
| 4876 |
\eval{$ |
| 4877 |
\sum_{k=0}^{\infty}\binom \alpha k x^k |
| 4878 |
$}[x=1/2,\alpha=3],\\ \\ |
| 4879 |
requiring \eval{$ \info*{sum}-1 $}\ additions. |
| 4880 |
\end{verbatim} |
| 4881 |
$\Longrightarrow$ \eval{$ |
| 4882 |
\sum_{k=0}^{\infty}\binom \alpha k x^k |
| 4883 |
$}[x=1/2,\alpha=3],\\ \\ |
| 4884 |
requiring \eval{$ \info*{sum}-1 $}\ additions. In fact the starring is unnecessary in this example since all nested |
| 4885 |
commands are now treated as if they were starred. |
| 4886 |
|
| 4887 |
\subsection{Errors} |
| 4888 |
|
| 4889 |
Should the \emph{wrong} argument be used in the \verb`\nmcInfo` command, |
| 4890 |
no harm is done: |
| 4891 |
\begin{verbatim} |
| 4892 |
\eval{$ \sum_{k=0}^{\infty}\binom \alpha k x^k $} |
| 4893 |
[x=1/2,\alpha=3], \ \info{prod} |
| 4894 |
\end{verbatim} |
| 4895 |
$\Longrightarrow$ \eval{$ \sum_{k=0}^{\infty}\binom \alpha k x^k $}[x=1/2,\alpha=3],\ \info{prod}.\medskip{} |
| 4896 |
|
| 4897 |
$119$ \emph{factors}? We were evaluating a sum but used \verb`prod` |
| 4898 |
as the argument of the \verb`\info` command which remembers a previous |
| 4899 |
result, the last time \verb`prod` was used as its argument. Changing |
| 4900 |
the argument from \verb`prod` to \verb`sum` reveals the correct |
| 4901 |
number of \emph{terms}. |
| 4902 |
|
| 4903 |
Should a non-existent argument be used, an error message is generated: |
| 4904 |
\begin{verbatim} |
| 4905 |
\eval{$ |
| 4906 |
\sum_{k=0}^{\infty}\binom \alpha k x^k |
| 4907 |
$}[x=1/2,\alpha=3], \\ \info{Fred} |
| 4908 |
\end{verbatim} |
| 4909 |
$\Longrightarrow$ \eval{$ \sum_{k=0}^{\infty}\binom \alpha k x^k $}[x=1/2,\alpha=3],\\ \\ \info{Fred} |
| 4910 |
|
| 4911 |
\subsection{\texttt{view} setting} |
| 4912 |
|
| 4913 |
Only two settings seem relevant for \verb`\info`: the \verb`dbg` |
| 4914 |
and \verb`view` settings. Rather than use the obscure \verb`dbg=<integer>` |
| 4915 |
(which is possible), it suffices to enter \verb`view` in the settings |
| 4916 |
option: |
| 4917 |
\begin{centred} |
| 4918 |
\verb`\info[view]{}` $\Longrightarrow$ \info[view] {} |
| 4919 |
\end{centred} |
| 4920 |
The result is a display of all the current values of all the `infinite' |
| 4921 |
processes available. (Further processes become available if the \texttt{numerica-plus} |
| 4922 |
package is used.) The mandatory but empty braces can be filled with |
| 4923 |
\verb`sum`, \verb`prod` or even \verb`Fred` but it makes no difference; |
| 4924 |
the display is always of the current values of all `infinite' processes |
| 4925 |
\texttt{numerica} knows about. If there has been no sum or product |
| 4926 |
evaluated, the displayed value is conventionally shown as zero. |
| 4927 |
|
| 4928 |
\section{User-defined macros: \texttt{\textbackslash nmcMacros}} |
| 4929 |
|
| 4930 |
\label{sec:supplMacros}The \verb`\nmcMacros` command was prompted |
| 4931 |
by a question on \TeX{} Stack Exchange.\cprotect\footnote{See \url{https://tex.stackexchange.com/questions/602993/use-macros-in-numerica-vv-list/602998#602998}} |
| 4932 |
Some time later the maintainer of the \verb`mandi` package approached |
| 4933 |
me with a similar problem. Suppose one has defined a macro to contain |
| 4934 |
a value, say |
| 4935 |
\begin{itemize} |
| 4936 |
\item \verb`\def\myvalue{0.35}`, or |
| 4937 |
\item \verb`\newcommand\myvalue{0.35}`, or |
| 4938 |
\item \verb`\NewDocumentCommand\myvalue{}{ 0.35 }`. |
| 4939 |
\end{itemize} |
| 4940 |
(If you're using the document processor \LyX{} then there is good reason |
| 4941 |
to prefer \verb`\gdef` to define your macro, \verb`\gdef\myvalue{0.35}`; |
| 4942 |
see Chapter~\ref{sec:miscLyX}). After one of these commands, \verb`\myvalue` |
| 4943 |
is now known to \LaTeX , but it is not known to \texttt{numerica}. |
| 4944 |
The quantities \texttt{numerica} \emph{does }know about are variables |
| 4945 |
in the vv-list of an \verb`\eval` command, and those \LaTeX{} (and |
| 4946 |
\texttt{amsmath} and \texttt{mathtools}) commands used for writing |
| 4947 |
mathematical expressions. These quantities are stored in \texttt{numerica} |
| 4948 |
in structures called property lists. Since \verb`\myvalue` is not |
| 4949 |
– yet – recorded in these lists putting \verb`x=\myvalue` in the |
| 4950 |
formula or vv-list of an \verb`\eval` command will produce an `Unknown |
| 4951 |
token' error message: |
| 4952 |
\begin{verbatim} |
| 4953 |
\NewDocumentCommand \myvalue {} { 0.35 } |
| 4954 |
\eval{ \myvalue } |
| 4955 |
\end{verbatim} |
| 4956 |
$\Longrightarrow$ \NewDocumentCommand \myvalue {} {0.35} |
| 4957 |
\eval{ \myvalue } |
| 4958 |
|
| 4959 |
From version 2 of \texttt{numerica}, a command \verb`\nmcMacros` |
| 4960 |
is available to register macros and their values with the property |
| 4961 |
lists used internally by \texttt{numerica}. The macro must have been |
| 4962 |
defined earlier in the document or in a supporting package. Using |
| 4963 |
\verb`\nmcMacros` (or \verb`\macros` in its short-name form) is |
| 4964 |
simple. |
| 4965 |
|
| 4966 |
If you have a list of macros you wish to use in \texttt{numerica}, |
| 4967 |
enter them in a comma (or a semicolon list if the decimal comma is |
| 4968 |
being used) in the mandatory argument of the command. The \verb`ff` |
| 4969 |
setting necessary for a multi-formula calculation in \verb`\eval` |
| 4970 |
is implicit for \verb`\nmcMacros` – it does not need to be added: |
| 4971 |
\begin{verbatim} |
| 4972 |
\nmcMacros{ \macro1, \macro2, … } |
| 4973 |
\nmcMacros{ \macro1; \macro2; … } |
| 4974 |
\end{verbatim} |
| 4975 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 4976 |
\begin{shaded}% |
| 4977 |
Since no decimal numbers are involved, no ambiguity would arise from |
| 4978 |
using a comma separator even when the \verb`comma` package option |
| 4979 |
is used but consistency with multi-formula calculations in \verb`\eval` |
| 4980 |
suggests that a semicolon should be – and is – insisted upon unless |
| 4981 |
explicitly countermanded by entering \verb`ff=<char>` in the settings |
| 4982 |
option of the \verb`\macros` command.\end{shaded}% |
| 4983 |
\end{minipage}\medskip{} |
| 4984 |
|
| 4985 |
\noindent Multiple \verb`\macros` commands can be used in a document. |
| 4986 |
If the command is placed in the preamble (\emph{after} the definition |
| 4987 |
of the macros)\emph{ }then the user-defined macros and their values |
| 4988 |
are available throughout the document, otherwise they are available |
| 4989 |
from the position of the \verb`\macros` statement. However, it is |
| 4990 |
not necessary for macros to be defined in the \emph{current} document |
| 4991 |
provided they are defined and accessible from some other loaded \LaTeX{} |
| 4992 |
package. But always an \verb`\nmcMacros` (or \verb`\macros`) command |
| 4993 |
is required to register them with \texttt{numerica} for use in \verb`\eval`. |
| 4994 |
|
| 4995 |
\subsection{What can be stored in a macro?} |
| 4996 |
|
| 4997 |
Generally a user-defined macro will store a number. This macro might |
| 4998 |
well be defined in an external package – for example the \verb`mandi` |
| 4999 |
package defines a large number of macros containing the values of |
| 5000 |
physical constants, some fundamental like the speed of light, others |
| 5001 |
contingent like the earth–moon distance. If the \verb`mandi` package |
| 5002 |
is loaded\footnote{Maintainer Joe Heafner explains that `mandi' abbreviates `matter |
| 5003 |
and interactions' after a physics textbook of that name.} then writing, for instance, |
| 5004 |
\begin{verbatim} |
| 5005 |
\macros{ \electronmassprecisevalue, |
| 5006 |
\protonmassprecisevalue } |
| 5007 |
\end{verbatim} |
| 5008 |
will make these two macros available for use in \texttt{numerica}. |
| 5009 |
One could then write in the vv-list of an \verb`\eval` command |
| 5010 |
\begin{verbatim} |
| 5011 |
m_e=\electronmassprecisevalue, |
| 5012 |
m_p=\protonmassprecisevalue |
| 5013 |
\end{verbatim} |
| 5014 |
which would allow (among other things) calculation of the mass ratio |
| 5015 |
$m_{p}/m_{e}$ of proton to electron. (The length of name of some |
| 5016 |
of the macros in the \verb`mandi` package has a pedagogical purpose, |
| 5017 |
but makes them unwieldy for direct use in mathematical calculations.) |
| 5018 |
|
| 5019 |
\noindent{}% |
| 5020 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 5021 |
\begin{shaded}% |
| 5022 |
\noindent In version 2 of \texttt{numerica}, where the \verb`\macros` |
| 5023 |
command was introduced, if the first token in a macro definition was |
| 5024 |
expandable (like \verb`\sin` expanding to $\sin$ or \verb`\sum` |
| 5025 |
expanding to $\sum$) it was necessary to ensure there was a preceding |
| 5026 |
space. If the first token was a digit, there was no problem. From |
| 5027 |
version 3.0.0 this is no longer the case. A leading space may or may |
| 5028 |
not be included; it doesn't matter. I thank \noun{David Carlisle} |
| 5029 |
for the routine that solved this irritant.\footnote{\url{https://tex.stackexchange.com/questions/683578/storing-the-unknown-contents-of-a-macro-in-a-clist}}\end{shaded}% |
| 5030 |
\end{minipage} |
| 5031 |
|
| 5032 |
\subsubsection{Macros containing formulas } |
| 5033 |
|
| 5034 |
Numbers are not the only quantities that can be stored in a macro |
| 5035 |
for use in \texttt{numerica}. In fact any mathematical expression |
| 5036 |
that can be \verb`\eval`-uated can be stored in a macro: |
| 5037 |
\begin{verbatim} |
| 5038 |
\NewDocumentCommand \mysumC {} |
| 5039 |
{ \sum_{n=1}^{100}1/n - \ln 100 } |
| 5040 |
\macros{ \mysumC } |
| 5041 |
\eval{$ \mysumC $}[4] |
| 5042 |
\end{verbatim} |
| 5043 |
$\Longrightarrow$ \NewDocumentCommand \mysumC {} |
| 5044 |
{ \sum_{n=1}^{100}1/n - \ln 100 } |
| 5045 |
\macros{ \mysumC } |
| 5046 |
\eval{$ \mysumC $}[4], \medskip{} |
| 5047 |
|
| 5048 |
\noindent (to be compared with Euler's constant \eval{$ \gamma $}[4] |
| 5049 |
– obviously many more terms are needed). The \verb`\eval` command |
| 5050 |
wraps around math delimiters in the example. Hence the result is presented |
| 5051 |
in the form \emph{formula=result}. In that presentation, note how |
| 5052 |
\verb`\mysumC` displays as the formula it contains. |
| 5053 |
|
| 5054 |
\subsubsection{vv-list} |
| 5055 |
|
| 5056 |
In the example it would be nice to be able to vary the number of terms |
| 5057 |
summed. This is easily done by using a vv-list in the \verb`\macros` |
| 5058 |
statement: |
| 5059 |
\begin{verbatim} |
| 5060 |
\NewDocumentCommand \mysumN {} |
| 5061 |
{ \sum_{n=1}^{N}1/n - \ln N } |
| 5062 |
\macros{ \mysumN }[N=150] |
| 5063 |
\eval{$ \mysumN $} |
| 5064 |
\end{verbatim} |
| 5065 |
$\Longrightarrow$ \NewDocumentCommand \mysumN {} |
| 5066 |
{ \sum_{n=1}^{N}1/n - \ln N } |
| 5067 |
\macros{ \mysumN }[N=150] |
| 5068 |
\eval{$ \mysumN $}.\medskip{} |
| 5069 |
|
| 5070 |
\noindent\texttt{numerica} needs a definite value to store; it does |
| 5071 |
not store the formula as such. To give \verb`\mysumN` a definite |
| 5072 |
value, give the variable \verb`N` a value. This is done in the vv-list |
| 5073 |
added to the \verb`\macros` statement: \verb`N=150`. In this way |
| 5074 |
a definite value is stored in \texttt{numerica} against the macro |
| 5075 |
\verb`\mysumN`. The definition of the macro is unaffected. If a new |
| 5076 |
value is given to \verb`N` in the \verb`\macros` statement (which |
| 5077 |
is the point of using a variable), the old value is overwritten and |
| 5078 |
the new value is used in subsequent calculations. |
| 5079 |
|
| 5080 |
\subsection{Seeing what macros are available} |
| 5081 |
|
| 5082 |
Perhaps your document has a number of \verb`\nmcMacros` statements |
| 5083 |
scattered through it and you want to remind yourself of what exactly |
| 5084 |
has been stored. \verb`\nmcMacros` has the \verb`view` setting for |
| 5085 |
this purpose. Writing |
| 5086 |
\begin{centred} |
| 5087 |
\verb`\macros[view]{}` $\Longrightarrow$ \macros[view]{} |
| 5088 |
\end{centred} |
| 5089 |
produces a list of all macros registered with \texttt{numerica} and |
| 5090 |
their values, as you can see. |
| 5091 |
|
| 5092 |
If the braced argument is not empty, the display is slightly modified: |
| 5093 |
\begin{verbatim} |
| 5094 |
\def\mydef{ \sin(m\pi/n) } |
| 5095 |
\newcommand\mynewcmd{ \cos(m\pi/n) } |
| 5096 |
\macros[view]{ \mydef,\mynewcmd }[m=3,n=18] |
| 5097 |
\end{verbatim} |
| 5098 |
$\Longrightarrow$ \def\mydef{ \sin(m\pi/n) } |
| 5099 |
\newcommand\mynewcmd{ \cos(m\pi/n)} |
| 5100 |
\macros[view]{ \mydef,\mynewcmd }[m=3,n=18] |
| 5101 |
|
| 5102 |
\noindent\verb`\mydef` and \verb`\mynewcmd` have been added to |
| 5103 |
those available for use in \texttt{numerica}. |
| 5104 |
|
| 5105 |
\subsection{Freeing macros from storage} |
| 5106 |
|
| 5107 |
Rather than cluttering \texttt{numerica}'s property lists with no-longer-needed |
| 5108 |
macros, it is possible to remove them from there with the \verb`free` |
| 5109 |
setting. This has no effect on the \LaTeX{} definition of the macro. |
| 5110 |
It merely `de-registers' the macro with \texttt{numerica}. |
| 5111 |
\begin{centred} |
| 5112 |
\verb`\macros[free,view]{ \mysumC }` $\Longrightarrow$ \macros[free,view]{ \mysumC } |
| 5113 |
\end{centred} |
| 5114 |
If you want to free \emph{all} macros registered with \texttt{numerica} |
| 5115 |
use an empty main argument with the \verb`free` setting. For an example, |
| 5116 |
see just below. |
| 5117 |
|
| 5118 |
\subsection{Counting how many macros are available} |
| 5119 |
|
| 5120 |
You can count how many macros are currently registered with \texttt{numerica} |
| 5121 |
by starring the \verb`\nmcMacros`~command: |
| 5122 |
\begin{centred} |
| 5123 |
\verb`\macros*{}` $\Longrightarrow$ \macros*{}. |
| 5124 |
\end{centred} |
| 5125 |
If the braced argument is not empty, the list of macros it contains |
| 5126 |
will be added to those registered with \texttt{numerica} and included |
| 5127 |
in the overall count. |
| 5128 |
|
| 5129 |
Note that the \verb`view` setting prevails over starring if both |
| 5130 |
are used. |
| 5131 |
|
| 5132 |
The star can also be used with the \verb`free` setting. As mentioned |
| 5133 |
above, if the main argument is empty, then \emph{all} macros are freed: |
| 5134 |
\begin{centred} |
| 5135 |
\verb`\macros*[free]{}` $\Longrightarrow$ \macros* [free]{}. |
| 5136 |
\end{centred} |
| 5137 |
|
| 5138 |
\subsection{Errors} |
| 5139 |
|
| 5140 |
\label{subsec:supplMacrosErrors}If a macro is used in a \verb`\macros` |
| 5141 |
statement but has not been defined earlier in the document or a supporting |
| 5142 |
package it will cause an error: |
| 5143 |
\begin{centred} |
| 5144 |
\verb`\macros{ \mymacro }` $\Longrightarrow$ \macros{\mymacro } |
| 5145 |
\end{centred} |
| 5146 |
\noindent An undefined macro used in an \verb`\eval`-uation will |
| 5147 |
cause an `Unknown token' message in \texttt{numerica}. The solution |
| 5148 |
in both these cases is (obviously) to define the macro. |
| 5149 |
|
| 5150 |
If a macro is defined but the \verb`\macros` statement overlooked |
| 5151 |
and the macro used in an \verb`\eval`-uation, it will generate an |
| 5152 |
`Unknown token' message. If your macro stores a formula with variables, |
| 5153 |
and you forget to give those variables values in the \verb`\macros` |
| 5154 |
statement that will produce a message, for instance: |
| 5155 |
\begin{verbatim} |
| 5156 |
\def\mysumk{ \sum_{n=1}^k n } |
| 5157 |
\macros{ \mysumk } |
| 5158 |
\end{verbatim} |
| 5159 |
$\Longrightarrow$ \def\mysumk{ \sum_{n=1}^k n } |
| 5160 |
\macros{ \mysumk } |
| 5161 |
|
| 5162 |
\noindent In this case the `where' part of the message is specific, |
| 5163 |
but more usually will be \verb`macros command`. And of course there |
| 5164 |
can be `all the usual suspects' discussed in Chapter~\ref{chap:errorsErrors}. |
| 5165 |
|
| 5166 |
\noindent{}% |
| 5167 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 5168 |
\begin{shaded}% |
| 5169 |
|
| 5170 |
\subsubsection{Display of macros} |
| 5171 |
|
| 5172 |
\label{subsec:supplMacrosDisplay}Once a macro is known to \LaTeX{} |
| 5173 |
it can be used as a variable name. If it is entered as such on the |
| 5174 |
left of an equals sign in the vv-list, \verb`\eval` will treat it |
| 5175 |
as a variable name. As with multi-token variables (§\ref{subsec:evalDon't-do-this!}), |
| 5176 |
this fact can be abused. In the following example the macro is defined |
| 5177 |
in \LaTeX{} but there is no \verb`\macros` statement. |
| 5178 |
\begin{verbatim} |
| 5179 |
\def\mymac{1} |
| 5180 |
\eval[vv=\,???]{$ \mymac+\mymac $}[\mymac=2] |
| 5181 |
\end{verbatim} |
| 5182 |
$\Longrightarrow$ \def\mymac{1} |
| 5183 |
\eval[vv=\,???]{$ \mymac+\mymac $}[\mymac=2] |
| 5184 |
|
| 5185 |
Do not define a macro containing some value and then use it as a variable |
| 5186 |
name for a different value. Macros display as their content. The value |
| 5187 |
($2$) assigned to a variable name (\verb`\mymac`) for calculational |
| 5188 |
purposes in \verb`\eval` and how that variable name displays in \LaTeX{} |
| 5189 |
are separate things. It is up to the user not to abuse this fact.\end{shaded}% |
| 5190 |
\end{minipage} |
| 5191 |
|
| 5192 |
\subsection{Rounding value} |
| 5193 |
|
| 5194 |
\label{subsec:supplMacrosRounding}Values are stored to $16$ significant |
| 5195 |
figures (if available). In most cases appending a rounding value to |
| 5196 |
a \verb`\macros` statement has no effect on the value stored. In |
| 5197 |
the following example note the \verb`o` setting, meaning the sine |
| 5198 |
reads angles in degrees: |
| 5199 |
\begin{verbatim} |
| 5200 |
\NewDocumentCommand\testi{}{ \sin 60 } |
| 5201 |
\NewDocumentCommand\testii{}{ \sin 60 } |
| 5202 |
\macros[o]{ \testi }[10] |
| 5203 |
\macros[o]{ \testii }[3] |
| 5204 |
\macros[view]{} |
| 5205 |
\end{verbatim} |
| 5206 |
$\Longrightarrow$ \NewDocumentCommand\testi{}{ \sin 60 } |
| 5207 |
\NewDocumentCommand\testii{}{ \sin 60 } |
| 5208 |
\macros[o]{ \testi }[10] |
| 5209 |
\macros[o]{ \testii }[3] |
| 5210 |
\macros[view]{} |
| 5211 |
|
| 5212 |
\noindent Despite the different rounding values in the \verb`\macros` |
| 5213 |
statements the same $16$ figures are stored in both \verb`\testi` |
| 5214 |
and \verb`\testii`. |
| 5215 |
|
| 5216 |
For the \verb`\eval` command, rounding values specify how results |
| 5217 |
are \emph{displayed}. In general the rounding value matters \emph{after}, |
| 5218 |
not during, the calculation. Only for infinite sums or products is |
| 5219 |
this otherwise. (Although fraction-form output from \verb`\eval` |
| 5220 |
also depends on the rounding value, that is not relevant here.) For |
| 5221 |
infinite sums or products the rounding value is used to determine |
| 5222 |
when to stop adding further terms or factors. The same is true of |
| 5223 |
the \verb`\macros` command. Only if a macro contains an infinite |
| 5224 |
sum or product does the rounding value become relevant. Sixteen figures |
| 5225 |
are still stored, but most of them will be `wrong' since the infinite |
| 5226 |
sum or product has stopped early, after only a finite number of terms |
| 5227 |
or factors. Exactly how many of the first few figures are correct |
| 5228 |
depends on the rounding value. An example may clarify the matter. |
| 5229 |
\begin{verbatim} |
| 5230 |
\macros[free]{} |
| 5231 |
\def\zetaiii{ \sum_{n=1}^\infty 1/n^3 } |
| 5232 |
\macros[view]{ \zetaiii }[3] |
| 5233 |
\info{sum} |
| 5234 |
\macros[view]{ \zetaiii }[6] |
| 5235 |
\info{sum} |
| 5236 |
\end{verbatim} |
| 5237 |
$\Longrightarrow$ \macros[free]{} |
| 5238 |
\def\zetaiii{ \sum_{n=1}^\infty 1/n^3 } |
| 5239 |
\macros[view]{ \zetaiii }[3] |
| 5240 |
\info{sum} |
| 5241 |
\macros[view]{ \zetaiii }[6] |
| 5242 |
\info{sum} |
| 5243 |
|
| 5244 |
\emph{HMF }Table 23.3 tells me that $\zeta(3)=1.202056903159594\dots$ |
| 5245 |
The different rounding numbers have restricted the infinite sums to |
| 5246 |
the very finite $47$ and $468$ terms respectively. Although $16$ |
| 5247 |
figures are stored, only the first few are correct, three more for |
| 5248 |
rounding value $6$ than for rounding value $3$. |
| 5249 |
|
| 5250 |
\section{User-defined constants:\texttt{ \textbackslash nmcConstants}} |
| 5251 |
|
| 5252 |
\label{sec:supplConstants}As noted much earlier in this document |
| 5253 |
(§\ref{subsec:evalBuilt-in-Constants}), there are five built-in constants: |
| 5254 |
\verb`\pi`, \verb`e`, \verb`\phi`, \verb`\gamma` and \verb`\deg`, |
| 5255 |
but a user may well want to define their own constant or constants. |
| 5256 |
There are contexts where it would make sense to permanently record |
| 5257 |
fundamental constants like the speed of light or Planck's constant, |
| 5258 |
or more down-to-earth constants like the acceleration due to gravity |
| 5259 |
or the viscosity of water, rather than having to enter them in the |
| 5260 |
vv-list for each calculation. Or a parameter might be held constant |
| 5261 |
for a particular problem or class of problems where other variables |
| 5262 |
change – for example triangles of constant perimeter but varying sides. |
| 5263 |
This is the purpose of the \verb`\nmcConstants` command. |
| 5264 |
|
| 5265 |
The symbols used to denote constants are subject to exactly the same |
| 5266 |
constraints and freedoms as the symbols used to denote variables. |
| 5267 |
They might be single latin letters like \verb`c` (e.g.\ $c=3\times10^{8}$), |
| 5268 |
or greek letters like \verb`\alpha` (e.g.\ $\alpha=1/137)$, or |
| 5269 |
multi-token combinations like the Rydberg constants \verb`R_\infty` |
| 5270 |
or \verb`R_{\mathrm{H}}` from atomic physics, or \verb`\mu_0` and |
| 5271 |
\verb`\epsilon_0` used to denote the permeability and permitivity |
| 5272 |
of free space, or personal constants like \verb`total` of no wider |
| 5273 |
significance. \texttt{numerica} handles all these different forms |
| 5274 |
of constant with the command \verb`\nmcConstants`, where the main |
| 5275 |
argument is a comma-list of \emph{const=value} statements: |
| 5276 |
\begin{verbatim} |
| 5277 |
\nmcConstants{ const1=value1, const2=value2, ... , |
| 5278 |
const-n=value-n } |
| 5279 |
\end{verbatim} |
| 5280 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 5281 |
\begin{shaded}% |
| 5282 |
When the \verb`comma` package option is used and the decimal point |
| 5283 |
is a comma, the default item separator in \verb`\nmcConstants` is |
| 5284 |
the semicolon. Alternatively and irrespective of the choice of decimal |
| 5285 |
point, a user can specify a separator with the setting \verb`ff=<char>`, |
| 5286 |
e.g. \verb`ff=|`, and use that.\end{shaded}% |
| 5287 |
\end{minipage}\medskip{} |
| 5288 |
|
| 5289 |
This is the simplest use – each constant is assigned a numerical value. |
| 5290 |
But it is easy to envisage situations where it would be convenient |
| 5291 |
to have a constant with value $1/\sqrt{2\pi}$ say, or another with |
| 5292 |
value $e^{\tfrac{\pi}{2}}$, and so on. That is easy: simply put the |
| 5293 |
expession for the value on the right: |
| 5294 |
\begin{verbatim} |
| 5295 |
\constants{ a=1/\sqrt{2\pi},b=e^{\tfrac\pi2} } |
| 5296 |
\end{verbatim} |
| 5297 |
where the short(er)-name form \verb`\constants` has been used. Or |
| 5298 |
the values could be expressions depending on parameters: |
| 5299 |
\begin{verbatim} |
| 5300 |
\constants{ s=\tfrac12(a+b+c) }[a=3,b=5,c=7] |
| 5301 |
\end{verbatim} |
| 5302 |
Some constants might depend on earlier constants in the list: |
| 5303 |
\begin{verbatim} |
| 5304 |
\constants{ A=\sqrt{s(s-a)(s-b)(s-c)}, |
| 5305 |
s=\tfrac12(a+b+c) }[a=3,b=5,c=7] |
| 5306 |
\end{verbatim} |
| 5307 |
Or the values could involve an `infinite' process, requiring a rounding |
| 5308 |
value: |
| 5309 |
\begin{verbatim} |
| 5310 |
\constants{ \zeta=\sum_{n=1}^\infty(1/n^k) }[k=4][5] |
| 5311 |
\end{verbatim} |
| 5312 |
In this, although $16$ figures will be stored, only the first few |
| 5313 |
will be accurate, the precise number depending on the value of \verb`k` |
| 5314 |
and the rounding value (\verb`5` in the example); see the discussion |
| 5315 |
on this issue for user-defined macros above. |
| 5316 |
|
| 5317 |
\subsection{New list \emph{replaces} old} |
| 5318 |
|
| 5319 |
A particular group of constants may be relevant only to a particular |
| 5320 |
part of a document. Another part of the document may use other constants. |
| 5321 |
By default, a second list of constants \emph{replaces }the first list. |
| 5322 |
Thus each of the \verb`\constants` statements above would replace |
| 5323 |
the previous one. |
| 5324 |
|
| 5325 |
\noindent{}% |
| 5326 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 5327 |
\begin{shaded}% |
| 5328 |
There is a technical reason for this. For each calculation all \emph{multi-token} |
| 5329 |
constants are added internally to the start of the vv-list of the |
| 5330 |
\verb`\eval` command. Even if the vv-list is empty, this is still |
| 5331 |
the case since the formula might well use constants. As for multi-token |
| 5332 |
variables (see §\ref{subsec:evalVariableNames}), multi-token constants |
| 5333 |
are mapped internally to single tokens. This occurs afresh for each |
| 5334 |
calculation which will require not only this mapping from multi- to |
| 5335 |
single tokens but the evaluation of a vv-list that includes the multi-token |
| 5336 |
constants. It seems safer to make the default behaviour replacement |
| 5337 |
of one constant list by another, rather than cumulating them. \end{shaded}% |
| 5338 |
\end{minipage} |
| 5339 |
|
| 5340 |
\subsection{Adding constants to a list} |
| 5341 |
|
| 5342 |
Despite which there will be occasions when adding new constants to |
| 5343 |
an existing list is desired. This is easily done with the \verb`add` |
| 5344 |
setting. For instance, |
| 5345 |
\begin{verbatim} |
| 5346 |
\nmcConstants[add]{ \sigma=5.67\times10^{-8}, |
| 5347 |
k_B = 1.381\times10^{-23} } |
| 5348 |
\end{verbatim} |
| 5349 |
would add \verb`\sigma` and \verb`k_B` to the current list. The |
| 5350 |
presence of the \verb`add` setting triggers appending rather than |
| 5351 |
replacement. |
| 5352 |
|
| 5353 |
\subsection{Examples of use} |
| 5354 |
|
| 5355 |
\subsubsection{Example 1: atomic constants} |
| 5356 |
|
| 5357 |
In the following example, the values of various atomic constants are |
| 5358 |
taken from the \verb`mandi` package. I use two \verb`\constants` |
| 5359 |
statements in order to show the use of the \verb`add` setting. I've |
| 5360 |
also included a \verb`view` setting in the second \verb`\constants` |
| 5361 |
statement. |
| 5362 |
|
| 5363 |
The constants are used to calculate the fine-structure constant \verb`\alpha` |
| 5364 |
in the vv-list of the \verb`\eval` command, and its well-known reciprocal |
| 5365 |
(close to $137)$ in the main argument. Note that the constants do |
| 5366 |
not need to be entered in the vv-list of the \verb`\eval` command. |
| 5367 |
Their values are available from the \verb`\constants` statements. |
| 5368 |
\begin{verbatim} |
| 5369 |
\constants{ c=2.99792458\times10^{8}, |
| 5370 |
h=6.62607015\times10^{-34}, |
| 5371 |
e=1.602176634\times10^{-19} } |
| 5372 |
\constants[view,add] |
| 5373 |
{ \epsilon_0=8.854187817\times10^{-12} } |
| 5374 |
\eval{$ 1/\alpha $}[\alpha=e^2/2\epsilon_0hc] |
| 5375 |
\end{verbatim} |
| 5376 |
$\Longrightarrow$ \constants{ c=2.99792458\times10^{8}, |
| 5377 |
h=6.62607015\times10^{-34}, |
| 5378 |
e=1.602176634\times10^{-19} } |
| 5379 |
\constants[view,add] |
| 5380 |
{\epsilon_0=8.854187817\times10^{-12} } |
| 5381 |
\eval{$ 1/\alpha $}[\alpha=e^2/2\epsilon_0hc]. |
| 5382 |
|
| 5383 |
The \verb`view` setting produces a now familiar kind of display. |
| 5384 |
It shows that the three-token \verb`\epsilon_0` (the control sequence |
| 5385 |
\verb`\epsilon`, the underscore \verb`_` and the digit \verb`0`) |
| 5386 |
has been replaced by \verb`\nmc_p` – which may look as if it is also |
| 5387 |
three tokens but is in fact a single control sequence. |
| 5388 |
|
| 5389 |
\subsubsection{Example 2: local constants} |
| 5390 |
|
| 5391 |
Long ago, when there were such creatures as reference librarians, |
| 5392 |
I was asked about a school physics project along these lines. |
| 5393 |
|
| 5394 |
A\emph{ car is travelling at 50 km/hr when it hits a lamppost. The |
| 5395 |
bonnet crumples 1 metre and the car comes to an immediate halt. Although |
| 5396 |
she herself is wearing a seat-belt, a woman in the passenger cabin |
| 5397 |
is holding her 5 kg baby. Does the baby survive?} |
| 5398 |
|
| 5399 |
The enquirer was familiar with the equations describing constant acceleration, |
| 5400 |
\[ |
| 5401 |
x=ut+\tfrac{1}{2}at^{2},\quad\text{and}\quad v^{2}-u^{2}=2ax, |
| 5402 |
\] |
| 5403 |
and Newton's second law, $F=ma$, force equals mass times acceleration. |
| 5404 |
The question was really about understanding these laws and how to |
| 5405 |
think with them. Here, $s$ is the distance travelled in time $t,$ |
| 5406 |
with initial speed $u$ at $t=0$, speed $v$ at time $t$, and constant |
| 5407 |
acceleration $a$ – a deceleration in this case. |
| 5408 |
|
| 5409 |
The given data provide our constants: distance $x=1$ metre, initial |
| 5410 |
speed $u=1000*50/(60*60)=(10/36)*50$ metres per second, final speed |
| 5411 |
$v=0$. To estimate whether the woman can hold on to her baby, we |
| 5412 |
will need to make a comparison with forces we have personally experienced. |
| 5413 |
Most of us have tried lifting someone else, so let's use a characteristic |
| 5414 |
human weight as our test mass. Thus, we have the (baby's) mass $m=5$ |
| 5415 |
kilograms, and a test mass, $M$ say, which we will leave as a variable. |
| 5416 |
But dealing with weight, we will need the acceleration due to gravity. |
| 5417 |
For the kind of rough estimating we are doing, $g=10$ metres per |
| 5418 |
second per second will be an adequate approximation. |
| 5419 |
\begin{verbatim} |
| 5420 |
\constants{ x=1,v=0,u=(10/36)50,m=5,g=10 } |
| 5421 |
\end{verbatim} |
| 5422 |
The deceleration experienced by the woman is found from the second |
| 5423 |
equation of constant acceleration, $a=(v^{2}-u^{2})/2x$. Even if |
| 5424 |
the deceleration isn't constant this will give an estimate of its |
| 5425 |
magnitude. (If some of the deceleration is less than this $a$, some |
| 5426 |
must be greater.) This is also the deceleration experienced by the |
| 5427 |
baby as long as the woman holds onto her. Hence the magnitude of the |
| 5428 |
force exerted by the baby on the woman's arms is $ma=m(v^{2}-u^{2})/2x=-mu^{2}/2x$ |
| 5429 |
which we want to compare with our test force, say that required to |
| 5430 |
lift $M=70$ kilograms, which was once considered the mass of an average |
| 5431 |
western adult male (but is doubtless a considerable underestimate |
| 5432 |
now). Hence the test force is $Mg$. Let's do the calculations. (I |
| 5433 |
have altered the \verb`\constants` statement to allow for a later |
| 5434 |
comparison with the effect of a small increase in speed.) |
| 5435 |
\begin{verbatim} |
| 5436 |
\constants{ x=1,u=(10/36)U,m=5,g=10 }[U=50] |
| 5437 |
\eval{$ mu^2/2x $}[0], \par |
| 5438 |
\eval{$ Mg $}[M=70]. |
| 5439 |
\end{verbatim} |
| 5440 |
$\Longrightarrow$ \constants{ x=1,u=(10/36)U,m=5,g=10 }[U=50] |
| 5441 |
\eval{$ mu^2/2x $}[0], \par |
| 5442 |
\eval{$ Mg $}[M=70]. |
| 5443 |
|
| 5444 |
The force required to hold on to the baby is noticeably less than |
| 5445 |
that required to lift a $70$~kg person – in fact about the same |
| 5446 |
as that needed to lift a $50$~kg person. But we have ignored the |
| 5447 |
force experienced by the mothers forearms – perhaps doubling $m$ |
| 5448 |
(baby plus forearms) would give a better estimate of the force she |
| 5449 |
experiences. In that case $mu^{2}/2x$ obviously doubles and the total |
| 5450 |
force required by the woman to retain her baby – now $964$ newtons |
| 5451 |
– is significantly more than that required to lift a $70$~kg person. |
| 5452 |
I think it almost certain that the baby is torn from her arms. |
| 5453 |
|
| 5454 |
What difference does increasing the speed to 60 km/hr make? |
| 5455 |
\begin{verbatim} |
| 5456 |
\constants{ x=1,u=(10/36)U,m=5,g=10 }[U=60] |
| 5457 |
\eval{$ mu^2/2x $}[1], \par |
| 5458 |
\eval{$ Mg $}[M=70]. |
| 5459 |
\end{verbatim} |
| 5460 |
$\Longrightarrow$ \constants{ x=1,u=(10/36)U,m=5,g=10 }[U=60] |
| 5461 |
\eval{$ mu^2/2x $}[0], \par |
| 5462 |
\eval{$ Mg $}[M=70]. |
| 5463 |
|
| 5464 |
Now the force of baby alone is comparable to that required to lift |
| 5465 |
a $70$ kg person. Including the woman's forearms in $m$, doubling |
| 5466 |
$m$ say, will result in a force twice as great – like that required |
| 5467 |
to lift two $70$~kg people or one $140$~kg person. There is no |
| 5468 |
chance of the woman holding on to her baby. The force is too great. |
| 5469 |
|
| 5470 |
\subsubsection{Example 3: macros and constants} |
| 5471 |
|
| 5472 |
Constants can depend on previously defined and registered user macros. |
| 5473 |
Suppose I have defined two macros |
| 5474 |
\begin{verbatim} |
| 5475 |
\NewDocumentCommand\electronmassprecisevalue {} |
| 5476 |
{9.1093837015\times10^{-31}} |
| 5477 |
\NewDocumentCommand\protonmassprecisevalue {} |
| 5478 |
{1.672621898\times10^{-27}} |
| 5479 |
\end{verbatim} |
| 5480 |
(I have taken both the names and the values from the \verb`mandi` |
| 5481 |
package.) The long explicit names of the macros has a pedagogic purpose, |
| 5482 |
but they are too cumbersome to use in calculations. For that purpose |
| 5483 |
we need, first, a \verb`\macros` statement registering the two macros |
| 5484 |
with \texttt{numerica}, and then a \verb`\constants` statement like |
| 5485 |
\begin{verbatim} |
| 5486 |
\nmcConstants{ m_e=\electronmassprecisevalue, |
| 5487 |
m_p=\protonmassprecisevalue } |
| 5488 |
\end{verbatim} |
| 5489 |
With that \verb`m_e` and \verb`m_p` could be entered in formulas, |
| 5490 |
taking the values contained in the macros. Let's do it: |
| 5491 |
\begin{verbatim} |
| 5492 |
\NewDocumentCommand\electronmassprecisevalue {} |
| 5493 |
{9.1093837015\times10^{-31}} |
| 5494 |
\NewDocumentCommand\protonmassprecisevalue {} |
| 5495 |
{1.672621898\times10^{-27}} |
| 5496 |
\nmcMacros{ \electronmassprecisevalue, |
| 5497 |
\protonmassprecisevalue } |
| 5498 |
\nmcConstants{ m_e=\electronmassprecisevalue, |
| 5499 |
m_p=\protonmassprecisevalue } |
| 5500 |
\eval{$ m_p/m_e $} |
| 5501 |
\end{verbatim} |
| 5502 |
$\Longrightarrow$ \NewDocumentCommand\electronmassprecisevalue {} |
| 5503 |
{9.1093837015\times10^{-31}} |
| 5504 |
\NewDocumentCommand\protonmassprecisevalue {} |
| 5505 |
{1.672621898\times10^{-27}} |
| 5506 |
\nmcMacros{ \electronmassprecisevalue, |
| 5507 |
\protonmassprecisevalue } |
| 5508 |
\nmcConstants{ m_e=\electronmassprecisevalue, |
| 5509 |
m_p=\protonmassprecisevalue } |
| 5510 |
\eval{$ m_p/m_e $}, |
| 5511 |
|
| 5512 |
\noindent the familiar mass ratio of proton and electron. |
| 5513 |
|
| 5514 |
\subsection{Viewing, counting constants} |
| 5515 |
|
| 5516 |
To see all constants currently `in play', use the \verb`view` setting |
| 5517 |
in the \verb`\constants` command. The main argument can be empty, |
| 5518 |
\begin{centred} |
| 5519 |
\verb`\constants[view]{}` $\Longrightarrow$ \constants[view]{} |
| 5520 |
\end{centred} |
| 5521 |
or contain a list of constants. In the latter case, the display is |
| 5522 |
of the above form but featuring the constants of the new list or, |
| 5523 |
if the \verb`add` setting is used, featuring the joined lists, old |
| 5524 |
and new: |
| 5525 |
\begin{centred} |
| 5526 |
\verb`\constants[view,add]{X=42}` $\Longrightarrow$ \constants[view,add]{X=42} |
| 5527 |
\end{centred} |
| 5528 |
To count how many constants are currently in play, star the \verb`\constants` |
| 5529 |
command. The number will depend on whether the main argument is empty |
| 5530 |
or not, and whether the \verb`add` setting is active: |
| 5531 |
\begin{centred} |
| 5532 |
\verb`\constants*{}` $\Longrightarrow$ \constants*{}. |
| 5533 |
\end{centred} |
| 5534 |
If the \verb`view` setting is being used at the same time as the |
| 5535 |
star, the \verb`view` prevails. |
| 5536 |
|
| 5537 |
\subsection{Errors} |
| 5538 |
|
| 5539 |
When contemplating error messages from \texttt{numerica} it needs |
| 5540 |
to be remembered that \emph{multi-token} constants are added to the |
| 5541 |
vv-list for every calculation. Hence an error may not be in the vv-list |
| 5542 |
as indicated in the message but in the \verb`\constants` statement, |
| 5543 |
specifically, the multi-token constants. |
| 5544 |
|
| 5545 |
\section{Saving and reusing results: \texttt{\textbackslash nmcReuse}} |
| 5546 |
|
| 5547 |
\label{sec:supplReuse}You may want to use at some place in a document |
| 5548 |
a result calculated earlier. It would be good to be able to do so |
| 5549 |
without having to do the calculation again at the new location. \texttt{numerica} |
| 5550 |
offers a command \verb`\nmcReuse` (short-name form, \verb`\reuse`) |
| 5551 |
which saves the numerical result of the most recent \verb`\eval`-uation |
| 5552 |
to a control sequence (a macro) that can then be used elsewhere in |
| 5553 |
the document, expanding to the saved result. The control sequence |
| 5554 |
and its content are also saved to file, allowing the possibility of |
| 5555 |
using the result in other documents. |
| 5556 |
|
| 5557 |
\noindent{}% |
| 5558 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 5559 |
\begin{shaded}% |
| 5560 |
For those familiar with earlier usage, in version 2 of \texttt{numerica |
| 5561 |
}the \verb`\nmcReuse` command was completely rewritten and was no |
| 5562 |
longer compatible with how the command was used in version 1. In version |
| 5563 |
3 of \texttt{numerica} the command has, again, been reworked with |
| 5564 |
an eye to greater consistency in its use (and simplifying the code). |
| 5565 |
The command created difficulties for itself by mixing two functions: |
| 5566 |
(i) saving and retrieving a result, and (ii) making the retrieved |
| 5567 |
result usable within another calculation (an \verb`\eval`-uation). |
| 5568 |
That latter function is the purpose of the \verb`\macros` command |
| 5569 |
and in version 3 of \texttt{numerica} has been removed from \verb`\recur`. |
| 5570 |
For a saved result to be used within an \verb`\eval` command it must |
| 5571 |
first be `registered' by means of the \verb`\macros` command – |
| 5572 |
like any other \LaTeX{} macro. Further, \emph{only the numerical result} |
| 5573 |
is now saved, although that can be saved as a decimal or in scientific |
| 5574 |
notation or fraction form, but saving associated elements like the |
| 5575 |
vv-list or math delimiters with the numerical result has been discontinued.\end{shaded}% |
| 5576 |
\end{minipage} |
| 5577 |
|
| 5578 |
\subsection{Use of \texttt{\textbackslash nmcReuse}} |
| 5579 |
|
| 5580 |
As noted, all the supplementary commands share the syntax of the \verb`\eval` |
| 5581 |
command, so that \verb`\nmcReuse` has an optional settings argument |
| 5582 |
preceding a mandatory main argument, followed by two trailing optional |
| 5583 |
arguments. \verb`\nmcReuse` does not use the last two. The command |
| 5584 |
is used to save the numerical result of the last \verb`\eval` command |
| 5585 |
to file and to load saved results from file. The results are saved |
| 5586 |
as pairs, \verb`\foo {<result>}`, where \verb`foo` is a control |
| 5587 |
sequence name (or macro name) chosen by the user. When loaded from |
| 5588 |
file, \verb`\foo` is globally defined to expand to \verb`<result>`. |
| 5589 |
The file that is used to store control sequences and their values |
| 5590 |
is named \verb`<\jobname>.nmc` where \verb`\jobname` is the \LaTeX{} |
| 5591 |
macro that expands to the filename of the current document. The file |
| 5592 |
is organized as a comma list. |
| 5593 |
|
| 5594 |
Because of past practice, |
| 5595 |
\begin{itemize} |
| 5596 |
\item \verb`\nmcReuse{}`, or \verb`\reuse{}`, loads all saved macros and |
| 5597 |
globally defines them to expand to their saved values; |
| 5598 |
\item \verb`\nmcReuse{foo}`, or \verb`\reuse{foo}`, saves the numerical |
| 5599 |
result from the most recent \verb`\eval`-uation to file in the form |
| 5600 |
\verb`\foo {<result>}` and globally defines \verb`\foo` to expand |
| 5601 |
to \verb`<result>`. |
| 5602 |
\end{itemize} |
| 5603 |
In light of the first of these you may want to put \verb`\reuse{}` |
| 5604 |
in the preamble of your document (\emph{after} \verb`\usepackage{numerica}` |
| 5605 |
of course). In that way, saved control sequences are available from |
| 5606 |
the start. |
| 5607 |
|
| 5608 |
But these are somewhat inconsistent default behaviours. Version 3 |
| 5609 |
of \texttt{numerica} offers options to make more explicit what is |
| 5610 |
being done: |
| 5611 |
\begin{itemize} |
| 5612 |
\item \verb`save` |
| 5613 |
\begin{itemize} |
| 5614 |
\item \verb`\reuse[save]{foo}` saves the numerical result from the latest |
| 5615 |
\verb`\eval` command to file \verb`<\jobname>.nmc` as the pair \verb`\foo {<result>}`;\verb`\foo` |
| 5616 |
is globally defined to expand to \verb`<result>`; if \verb`\foo` |
| 5617 |
is defined elsewhere in \LaTeX{} or already exists in \verb`<\jobname>.nmc` |
| 5618 |
with a \emph{different} value then the save fails and a message is |
| 5619 |
generated; |
| 5620 |
\item \verb`\reuse[save]{}` is equivalent to \verb`\reuse{}`, see above; |
| 5621 |
\end{itemize} |
| 5622 |
\item \verb`renew` |
| 5623 |
\begin{itemize} |
| 5624 |
\item \verb`\reuse[renew]{foo}` saves the numerical result from the latest |
| 5625 |
\verb`\eval` command to file \verb`<\jobname>.nmc` as the pair \verb`\foo {<result>}`, |
| 5626 |
if necessary overwriting any previously saved value for \verb`\foo`; |
| 5627 |
\verb`\foo` is globally defined to expand to \verb`<result>`; if |
| 5628 |
\verb`\foo` already exists elsewhere in \LaTeX{} then the save fails |
| 5629 |
and a message is generated; |
| 5630 |
\item \verb`\reuse[renew]{}` is equivalent to \verb`\reuse{}`, see above; |
| 5631 |
\end{itemize} |
| 5632 |
\item \verb`load` |
| 5633 |
\begin{itemize} |
| 5634 |
\item \verb`\reuse[load]{foo}` loads \verb`\foo` from file \verb`<\jobname>.nmc` |
| 5635 |
and defines it globally to expand to its saved value; if \verb`\foo` |
| 5636 |
is defined elsewhere in \LaTeX{} or if it does not exist in file \verb`<\jobname>.nmc` |
| 5637 |
nothing happens; |
| 5638 |
\item \verb`\reuse[load]{}` is equivalent to \verb`\reuse{}`, see above; |
| 5639 |
\end{itemize} |
| 5640 |
\item \verb`delete` |
| 5641 |
\begin{itemize} |
| 5642 |
\item \verb`\reuse[delete]{foo}` undefines \verb`\foo` in the current |
| 5643 |
\LaTeX{} session and deletes \verb`\foo` and its value from file \verb`<\jobname>.nmc` |
| 5644 |
should it be there; |
| 5645 |
\item \verb`\reuse[delete]{}` deletes all contents from the file \verb`<\jobname>.nmc` |
| 5646 |
and undefines all macros previously saved there from the current \LaTeX{} |
| 5647 |
session; |
| 5648 |
\end{itemize} |
| 5649 |
\end{itemize} |
| 5650 |
Only one of the options should be used at a time; if more than one |
| 5651 |
is, it is the rightmost (in the settings option of the \verb`\reuse` |
| 5652 |
command) which prevails. |
| 5653 |
|
| 5654 |
As examples of use, the following illustrate first the default behaviour |
| 5655 |
and then the explicit use of the \verb`save` option. |
| 5656 |
\begin{verbatim} |
| 5657 |
\eval{$ x+y $}[x=-1,y=3] \par |
| 5658 |
\reuse{two} >> \two \ << |
| 5659 |
\end{verbatim} |
| 5660 |
$\Longrightarrow$ \eval{$ x+y $}[x=-1,y=3] \par |
| 5661 |
\reuse{two} >> \two \ << |
| 5662 |
|
| 5663 |
\noindent Only the numerical result is saved, not the math environment, |
| 5664 |
so that if you want a minus sign to display correctly (rather than |
| 5665 |
as a hyphen) when you use a saved control sequence you will need to |
| 5666 |
ensure it is used in a math environment: |
| 5667 |
\begin{verbatim} |
| 5668 |
\eval{$ -1-1 $}. \reuse[save]{negtwo} |
| 5669 |
Now use the control sequence: $\negtwo$. |
| 5670 |
\end{verbatim} |
| 5671 |
$\Longrightarrow$ \eval{$ -1-1 $}.\reuse{negtwo} |
| 5672 |
Now use the control sequence: $\negtwo$. |
| 5673 |
|
| 5674 |
There may be occasions when you wish to change a previously saved |
| 5675 |
value and yet, irritatingly, the control sequence name will now be |
| 5676 |
known to \LaTeX{} and so will generate an `already defined' message. |
| 5677 |
And if you choose a different name for the control sequence to save |
| 5678 |
the new value to, do you want the old name cluttering the \verb`.nmc` |
| 5679 |
file? The settings \verb`delete` and \verb`renew` provide for such |
| 5680 |
situations. |
| 5681 |
|
| 5682 |
The following example shows the use of these options. In the example |
| 5683 |
a control sequence \verb`\testing` is defined in the first line. |
| 5684 |
Being unable to recall what is in the \verb`.nmc` file, I try deleting |
| 5685 |
it from there in the second line. In the third line the sum of the |
| 5686 |
first ten integers is evaluated. In the fourth line I try to save |
| 5687 |
the sum to the control sequence \verb`\testing`. That generates a |
| 5688 |
message: \verb`\testing` is defined elsewhere (in \LaTeX ) and therefore |
| 5689 |
was \emph{not} deleted. Okay, I resort to a new control sequence \verb`\test`. |
| 5690 |
In the fifth line, in case it is present in the \texttt{.nmc} file, |
| 5691 |
I try deleting \verb`\test` from there. The lack of a message means |
| 5692 |
that either it was successfully deleted or was not present in the |
| 5693 |
\texttt{.nmc} file in the first place. In the following lines, I calculate |
| 5694 |
the sum of the first 20 integers and save the result to \verb`\test`. |
| 5695 |
The final line shows that this was successful. |
| 5696 |
\begin{verbatim} |
| 5697 |
\NewDocumentCommand\testing{}{1} |
| 5698 |
\reuse[delete]{testing} |
| 5699 |
\eval[env=\[ ]{\sum_{n=1}^{10}n} |
| 5700 |
\reuse{testing}\par |
| 5701 |
\reuse[delete]{test}\par |
| 5702 |
\eval[env=\[ ]{\sum_{n=1}^{20}n} |
| 5703 |
\reuse{test} Now testing |
| 5704 |
\textbackslash test: \test. |
| 5705 |
\end{verbatim} |
| 5706 |
$\Longrightarrow$ \NewDocumentCommand\testing{}{1} |
| 5707 |
\reuse[delete]{testing} |
| 5708 |
\eval[env=\[ ]{\sum_{n=1}^{10}n} |
| 5709 |
\reuse{testing}\par |
| 5710 |
\reuse[delete]{test}\par |
| 5711 |
\eval[env=\[ ]{\sum_{n=1}^{20}n} |
| 5712 |
\reuse[renew]{ test} Now testing \textbackslash test: \test. |
| 5713 |
|
| 5714 |
If a control sequence \verb`\foo` is already known to \LaTeX{} from |
| 5715 |
elsewhere (perhaps it is a \LaTeX{} command) then writing \verb`\reuse{foo}` |
| 5716 |
or \verb`\reuse[save]{foo}` or even \verb`\reuse[renew]{foo}` will |
| 5717 |
produce a message and the result of the latest \verb`\eval`-uation |
| 5718 |
will \emph{not} be saved : |
| 5719 |
\begin{verbatim} |
| 5720 |
\eval*{\sum_{n=1}^{10}n}\par |
| 5721 |
\reuse[renew]{sigma} \par |
| 5722 |
>> $\sigma$ << |
| 5723 |
\end{verbatim} |
| 5724 |
$\Longrightarrow$ \eval*{\sum_{n=1}^{10}n} \par |
| 5725 |
\reuse[renew]{sigma}\par |
| 5726 |
>> $\sigma$ << |
| 5727 |
|
| 5728 |
\noindent As you can see, \verb`\sigma` is unchanged. |
| 5729 |
|
| 5730 |
If a control sequence is already saved to file from a previous \verb`\reuse` |
| 5731 |
command trying to save a different value to it produces a message: |
| 5732 |
\begin{verbatim} |
| 5733 |
\eval{$-1-1-1$} \par \reuse{negtwo} |
| 5734 |
\end{verbatim} |
| 5735 |
$\Longrightarrow$ \eval{$-1-1-1$} \par \reuse{negtwo}\medskip{} |
| 5736 |
|
| 5737 |
\noindent If you really do want to change the stored value, use the |
| 5738 |
\verb`renew` option. |
| 5739 |
|
| 5740 |
Empty results (from an \verb`\eval`-uation) are \emph{not} saved. |
| 5741 |
A following \verb`\reuse` command which attempts to do so generates |
| 5742 |
another message: |
| 5743 |
\begin{verbatim} |
| 5744 |
\eval{1/0} \par \reuse{oops} |
| 5745 |
\end{verbatim} |
| 5746 |
$\Longrightarrow$ \reuse[delete]{oops}\eval{1/0}\par\reuse{oops}\medskip{} |
| 5747 |
|
| 5748 |
\noindent The \verb`\eval`-uative error has produced an error message |
| 5749 |
and an empty result which generates the \verb`\reuse` message.\emph{ |
| 5750 |
}However, if \verb`\oops` had already existed in \verb`<\jobname>.nmc` |
| 5751 |
the stored macro and its value would have been loaded to prevent \LaTeX{} |
| 5752 |
later complaining about an undefined control sequence, should \verb`\oops` |
| 5753 |
have been used later in the document, and halting compilation. |
| 5754 |
|
| 5755 |
\subsubsection{Seeing what is saved} |
| 5756 |
|
| 5757 |
The \verb`view` setting is available for \verb`\reuse`, as for other |
| 5758 |
commands. |
| 5759 |
\begin{itemize} |
| 5760 |
\item \verb`\reuse[view]{}` displays all saved commands and their values; |
| 5761 |
\item \verb`\reuse[view]{foo}` displays only \verb`\foo` and its contents. |
| 5762 |
\end{itemize} |
| 5763 |
\verb`view` is independent of the other \verb`\reuse` options and |
| 5764 |
can be used freely with them: they do their thing, and \verb`view` |
| 5765 |
shows what results. For instance, the option combination \verb`[view,delete]` |
| 5766 |
results \emph{first} in the deletion and only after in the viewing. |
| 5767 |
Note that because \verb`\reuse{foo}` is equivalent to \verb`\reuse[save]{foo}`, |
| 5768 |
so \verb`\reuse[view]{foo}` is equivalent to \verb`\reuse[save,view]{foo}`. |
| 5769 |
|
| 5770 |
\subsubsection{Saving in other number formats} |
| 5771 |
|
| 5772 |
\label{subsec:reuseOtherFormats}\texttt{numerica} can output numbers |
| 5773 |
in scientific notation and in fraction form and save them in that |
| 5774 |
form. In the example, to check that both results have indeed been |
| 5775 |
saved, I use the \verb`view` option: |
| 5776 |
\begin{verbatim} |
| 5777 |
\eval{ \pi }[//t6], \reuse[renew]{fracpi} \quad |
| 5778 |
\eval{ \pi }[xx]. \reuse[renew]{scipi} |
| 5779 |
\reuse[view]{} |
| 5780 |
\end{verbatim} |
| 5781 |
$\Longrightarrow$ \eval{ \pi }[//t6], \reuse[renew]{fracpi} |
| 5782 |
\quad \eval{ \pi }[xx]. \reuse[renew,view]{scipi} |
| 5783 |
|
| 5784 |
\subsection{Using saved macros in calculations} |
| 5785 |
|
| 5786 |
To use a saved value in an \verb`\eval`-uation requires first `registering' |
| 5787 |
the control sequence (the macro) containing the value with \texttt{numerica}. |
| 5788 |
This is hardly surprising: saved control sequences are macros and |
| 5789 |
\texttt{numerica} needs to be alerted to their presence as with other |
| 5790 |
macros. The macros \verb`\two` and \verb`\negtwo` are active in |
| 5791 |
the current document but, in the following example, the initial attempt |
| 5792 |
to use them in an \verb`\eval` command fails; the second time, after |
| 5793 |
registering with the \verb`\macros` command, it succeeds: |
| 5794 |
\begin{verbatim} |
| 5795 |
\eval{ \two \times \negtwo }\par |
| 5796 |
\macros{ \two, \negtwo } |
| 5797 |
\eval{ \two \times \negtwo } |
| 5798 |
\end{verbatim} |
| 5799 |
$\Longrightarrow$ \eval{ \two \times \negtwo }\par |
| 5800 |
\macros{ \two, \negtwo } |
| 5801 |
\eval{$ \two \times \negtwo $} |
| 5802 |
|
| 5803 |
\subsection{The \texttt{.nmc} file} |
| 5804 |
|
| 5805 |
\label{subsec:suppleReuse.nmc-file}The file that control sequences |
| 5806 |
are saved to has a filename composed of the document name with the |
| 5807 |
extension \texttt{.nmc}. If your document is \texttt{mydoc.tex} (so |
| 5808 |
that the \LaTeX{} command {\small\verb`\jobname`} expands to |
| 5809 |
\texttt{mydoc}) then the file to which results are saved is \texttt{mydoc.nmc}, |
| 5810 |
located in the document directory. |
| 5811 |
|
| 5812 |
The \texttt{.nmc} file is a comma list of pairs of the form \verb`\csname {value}`. |
| 5813 |
Thus, the contents of \verb`mydoc.nmc` might be \verb`\csname1` |
| 5814 |
{\ttfamily\verb`{value1}`},\verb`\csname2` {\ttfamily\verb`{value2}`},..., |
| 5815 |
\verb`\csname-n` \verb`{value-n}`. If \texttt{mydoc.nmc} does not |
| 5816 |
already exist then \verb`\reuse{csname}` will create it in the document |
| 5817 |
directory, and \verb`\csname {value}` will becomes its first element. |
| 5818 |
|
| 5819 |
\subsubsection{Editing the \texttt{.nmc} file externally} |
| 5820 |
|
| 5821 |
\label{subsec:supplEditing-the-.nmc}The \texttt{.nmc} file is a text |
| 5822 |
file and can be edited in a text editor. Thus it is possible to externally |
| 5823 |
add control sequences and values to it provided the (simple) structure |
| 5824 |
of the file is strictly adhered to: pairs like \verb`\csname {value}` |
| 5825 |
separated by commas. It is also possible to delete items from it or |
| 5826 |
rename control sequences or edit values by the same mechanism. Editing |
| 5827 |
the file externally like this, or renaming it, or transferring items |
| 5828 |
from one \texttt{.nmc} file to another, provides a way of using saved |
| 5829 |
values in multiple documents. |
| 5830 |
|
| 5831 |
\subsection{Counting, viewing all saved control sequences} |
| 5832 |
|
| 5833 |
The \verb`\reuse` command has a starred form, \verb`\reuse*` (or |
| 5834 |
\verb`\nmcReuse*`) which, like other starred commands, produces a |
| 5835 |
purely numerical result. The number is the count of how many control |
| 5836 |
sequences have been saved: |
| 5837 |
\begin{centred} |
| 5838 |
\verb`\reuse*{}` $\Longrightarrow$ \reuse*{ } |
| 5839 |
\end{centred} |
| 5840 |
The star does not interfere with the other functions of \verb`\reuse`; |
| 5841 |
the main argument does not need to be empty. |
| 5842 |
|
| 5843 |
\subsection{Obsolete \texttt{reuse} setting of \texttt{\textbackslash eval} |
| 5844 |
command} |
| 5845 |
|
| 5846 |
\noindent\label{subsec:supplReuseEvalSetting}In version 2 of \texttt{numerica |
| 5847 |
}the \verb`\eval` command had a setting \verb`reuse` that gave some |
| 5848 |
choice as to what was saved. That has been discontinued. \texttt{numerica} |
| 5849 |
evaluates mathematical expressions; the numerical result is what is |
| 5850 |
important; the rest is cosmetics. Adding the extra capability was |
| 5851 |
confusing both as to what was saved and where and how it could be |
| 5852 |
used – and complicated the code. For the added complexity there was |
| 5853 |
little gain. |
| 5854 |
|
| 5855 |
\chapter{Miscellaneous matters} |
| 5856 |
|
| 5857 |
In this chapter I consider the nesting of commands, the parsing of |
| 5858 |
mathematical arguments, the use of different mathematical environments |
| 5859 |
and the use of \texttt{numerica} in the document processor \LyX . |
| 5860 |
|
| 5861 |
\section{Nesting commands} |
| 5862 |
|
| 5863 |
\label{sec:miscNesting} The \verb`\eval` command and the supplementary |
| 5864 |
commands of the previous chapter can be \emph{nested} –\emph{ }used |
| 5865 |
within other \verb`\eval` or supplementary commands. Nesting may |
| 5866 |
occur in the main argument, or the vv-list, or the settings option, |
| 5867 |
or some combination of all three. With the commands currently introduced, |
| 5868 |
nesting is unlikely to be a major concern, but it becomes significant |
| 5869 |
for the commands defined in the associated package \texttt{numerica-plus} |
| 5870 |
(see §\ref{subsec:introPackagesOptions}). Since those additional |
| 5871 |
commands are not available for this document, the examples below use |
| 5872 |
the commands introduced earlier: \verb`\eval`, \verb`\info`, \verb`\macros`, |
| 5873 |
\verb`\constants` and \verb`\reuse`. |
| 5874 |
|
| 5875 |
\subsection{In the formula} |
| 5876 |
|
| 5877 |
Consider a statement like \verb`\eval{...\eval...}`. There is an |
| 5878 |
inner \verb`\eval` and an outer \verb`\eval`. The inner \verb`\eval` |
| 5879 |
`digests' \emph{its} \LaTeX{} formula to produce an \texttt{l3fp}-readable |
| 5880 |
expression which is fed to \texttt{l3fp} to evaluate. The result is |
| 5881 |
then fed to the outer \verb`\eval` to be inserted into the outer |
| 5882 |
formula to be evaluated and then displayed. In version 1 of \texttt{numerica} |
| 5883 |
that meant the inner command \emph{had} to be starred, \verb`\eval*`, |
| 5884 |
so that no display formatting was fed to the outer command to try |
| 5885 |
to digest (and cause an error).\emph{ }From version 2 of \texttt{numerica} |
| 5886 |
this is no longer the case. \texttt{numerica} detects whether a command |
| 5887 |
is inner or outer, and if inner, suppresses all display formatting, |
| 5888 |
producing only a number, as if the command had been starred: |
| 5889 |
\begin{centred} |
| 5890 |
\verb`\eval{$ \sin(\eval{\sin x}[x=\pi/6]\pi) + 1 $}` $\Longrightarrow$ |
| 5891 |
\eval{ $\sin(\eval{\sin x}[x=\pi/6]\pi) + 1 $}. |
| 5892 |
\end{centred} |
| 5893 |
In the presentation of the overall result, the inner \verb`\eval` |
| 5894 |
command is evaluated, displaying as a number. |
| 5895 |
|
| 5896 |
In the example, the inner vv-list could be attached to the outer \verb`\eval` |
| 5897 |
\verb`x=\pi/6` since outer variables are available to the inner command |
| 5898 |
– and it aids clarity: |
| 5899 |
\begin{centred} |
| 5900 |
\verb`\eval{$ \sin(\eval{\sin x}\pi) + 1 $}[x=\pi/6]` $\Longrightarrow$ |
| 5901 |
\eval{$ \sin(\eval{\sin x}\pi)+ 1$}[x=\pi/6]. |
| 5902 |
\end{centred} |
| 5903 |
Or both inner and outer commands could have their own vv-lists – indeed, |
| 5904 |
the same variable could appear in both and be assigned different values |
| 5905 |
in each, without conflict: |
| 5906 |
\begin{centred} |
| 5907 |
\verb`\eval{$ \sin(\eval{\sin x}[x=\pi/6]\pi) + x $}[x=1]` $\Longrightarrow$ |
| 5908 |
\eval{$ \sin(\eval{\sin x}[x=\pi/6]\pi) + x $}[x=1]. |
| 5909 |
\end{centred} |
| 5910 |
Just to show that it is possible, the next example shows \verb`\eval` |
| 5911 |
being used in a \verb`\constants` command. The \verb`o` setting |
| 5912 |
in the \verb`\constants` command pervades its argument; hence it |
| 5913 |
needs to be explicitly turned off for the \verb`\eval` if \verb`\sin(\pi/6)` |
| 5914 |
is to evaluate as expected. |
| 5915 |
\begin{verbatim} |
| 5916 |
\constants[o]{ y=\sin 30, x=\eval[o=0]{\sin(\pi/6)} } |
| 5917 |
\eval{$ x+y $} |
| 5918 |
\end{verbatim} |
| 5919 |
$\Longrightarrow$ \constants[o]{ y=\sin 30, x=\eval[o=0]{\sin(\pi/6)}} |
| 5920 |
\eval{$ x+y $}. |
| 5921 |
|
| 5922 |
\subsubsection{Math delimiters and double evaluations} |
| 5923 |
|
| 5924 |
Any math delimiters in the inner \verb`\eval` are ignored. (This |
| 5925 |
also differs from version 1 of \texttt{numerica} where they caused |
| 5926 |
an error.) Obviously it is simpler to omit them as I have done in |
| 5927 |
the examples. |
| 5928 |
|
| 5929 |
However, math delimiters in the outer \verb`\eval` command still |
| 5930 |
have their normal effect and produce a \emph{formula = result, (vv-list)} |
| 5931 |
display. One consequence of such a display is that the formula in |
| 5932 |
the inner \verb`\eval` command is evaluated \emph{twice} – once when |
| 5933 |
the overall result is being calculated (i.e.\ the formula of the |
| 5934 |
outer \verb`\eval`) and later when the overall display of the result |
| 5935 |
is created. In the \emph{formula} part of the \emph{formula = result, |
| 5936 |
{[}vv-list{]}} display, the tokens in the \emph{formula} are expanded |
| 5937 |
to their display form. For example, \verb`\sin` is expanded to $\sin$, |
| 5938 |
\verb`\pi` is expanded to $\pi$ – and the inner \verb`\eval` is |
| 5939 |
expanded to the numerical result of its evaluation – which means a |
| 5940 |
second evaluation. If the inner formula is simple, this will be of |
| 5941 |
little moment, but should the inner formula contain, say, a slowly |
| 5942 |
converging infinite series, then evaluating it twice is a bad idea |
| 5943 |
and it would be better to remove the delimiters from the outer \verb`\eval`. |
| 5944 |
That prevents the second evaluation. |
| 5945 |
|
| 5946 |
The problem does not arise if the outer \verb`\eval` lies within |
| 5947 |
a math environment (e.g.\ \verb`$ \eval{...} $`) since that produces |
| 5948 |
a display of the form \emph{result, (vv-list).} The formula is not |
| 5949 |
displayed and so the second evaluation does not occur. The inner \verb`\eval` |
| 5950 |
is evaluated once only to calculate the result. |
| 5951 |
|
| 5952 |
\subsection{In the vv-list} |
| 5953 |
|
| 5954 |
The inner \verb`\eval` can be placed in the vv-list of the outer |
| 5955 |
command. If the vv-list of the inner \verb`\eval` contains a comma |
| 5956 |
then the entire inner \verb`\eval` and its \LaTeX{} arguments needs |
| 5957 |
to be wrapped in braces to hide \emph{its} comma from the vv-list |
| 5958 |
of the outer \verb`\eval`. To show the effect of not doing so, I |
| 5959 |
have slightly complicated a previous example by adding a second (unnecessary) |
| 5960 |
variable. The first example is with braces, the second without: |
| 5961 |
\begin{centred} |
| 5962 |
\verb`\eval{$ \sin k\pi + 1 $}[k={\eval{y\sin x}[x=\pi/6,y=1]}]` |
| 5963 |
$\Longrightarrow$ \eval{$ \sin k\pi + 1 $} [k={\eval{y\sin x}[x=\pi/6,y=1]}]. |
| 5964 |
|
| 5965 |
\verb`\eval{$ \sin k\pi + 1 $}[k=\eval{y\sin x}[x=\pi/6,y=1]]` $\Longrightarrow$ |
| 5966 |
\eval{$ \sin k\pi +1 $}[k=\eval{y\sin x}[x=\pi/6,y=1]]. |
| 5967 |
\end{centred} |
| 5968 |
The vv-list of the outer \verb`\eval` is parsed as containing two |
| 5969 |
entries, first \verb`k=\eval` \verb`{y\sin x}[x=\pi/6` and second |
| 5970 |
\verb`y=1]` (containing the right bracket). Both will cause errors |
| 5971 |
but since the vv-list is evaluated from the right, it is \verb`y=1]` |
| 5972 |
which actually does so. |
| 5973 |
|
| 5974 |
\subsection{In the settings option} |
| 5975 |
|
| 5976 |
This will be rare, but commands can occur in the settings option of |
| 5977 |
the outer command. The \verb`\info` command provides a good example. |
| 5978 |
I have included it in the punctuation setting of an \verb`\eval`-uation. |
| 5979 |
\begin{verbatim} |
| 5980 |
\eval[p=\mbox{,\qquad\info{sum} terms.}] |
| 5981 |
{\[ \sum_{n=0}^{\infty}\frac{(-1)^{n}}{n!} \]}[3] |
| 5982 |
\end{verbatim} |
| 5983 |
$\Longrightarrow$ \eval[p=\mbox{,\qquad\info{sum} terms.}]{\[ \sum_{n=0}^{\infty}\frac{(-1)^{n}}{n!}\]}[3] |
| 5984 |
|
| 5985 |
Because of the \verb`\[ \]` math delimiters, if the \verb`\info` |
| 5986 |
command had been placed \emph{after} the \texttt{\textbackslash eval} |
| 5987 |
command, it would have slid down to the next line. Used in the settings, |
| 5988 |
as here, the display is \emph{inside} the \verb`\[ \]` delimiters, |
| 5989 |
on the same line as the expression. This may be significant for adjusting |
| 5990 |
vertical spacing of later parts of the document – widow and orphan |
| 5991 |
control for instance. |
| 5992 |
|
| 5993 |
A point to note is the explicit writing of the `terms' descriptor. |
| 5994 |
Normally \verb`\info{sum}` would automatically supply the descriptor, |
| 5995 |
but as noted earlier, nesting of one command in another suppresses |
| 5996 |
all elements of display of the inner command beyond the numerical |
| 5997 |
result. It is as if the inner command is starred. Because the \verb`\info` |
| 5998 |
command is nested in the \verb`\eval` command, the `terms' descriptor |
| 5999 |
is suppressed and has had to be explicitly supplied by hand. |
| 6000 |
|
| 6001 |
\subsection{Rounding and display} |
| 6002 |
|
| 6003 |
In the display of the overall result, it is the numerical outcome |
| 6004 |
of the inner command which is shown, not the formula that the inner |
| 6005 |
command acts on. In previous versions of \texttt{numerica} that result |
| 6006 |
was \emph{always} evaluated to $16$ figures which were then fed into |
| 6007 |
the formula of the outer command. From version 3.0.0, the number-format |
| 6008 |
option of the inner command is heeded, \emph{if it is present}, and |
| 6009 |
only the specified number of decimal digits of the floating point |
| 6010 |
result are fed to the the outer command. In its absence, the inner |
| 6011 |
command feeds $16$ significant figures to the the outer command. |
| 6012 |
For example, |
| 6013 |
\begin{verbatim} |
| 6014 |
\eval[env=alignat*,ff]{ \pi - \eval{ \pi }, |
| 6015 |
\pi - \eval{ \pi }[4] }[15*] |
| 6016 |
\end{verbatim} |
| 6017 |
$\Longrightarrow$ \eval[env=alignat*,ff]{ \pi - \eval{ \pi }, |
| 6018 |
\pi - \eval{ \pi }[4] }[15*] |
| 6019 |
|
| 6020 |
\noindent In the first instance, with no explicit number-format specification |
| 6021 |
for the inner \verb`\eval`, the outer result is zero because all |
| 6022 |
$16$ significant figures of the inner result have been passed to |
| 6023 |
the outer \verb`\eval`; in the second instance, with an explicit |
| 6024 |
rounding number specified, only $4$ decimal digits have been passed |
| 6025 |
to the outer \verb`\eval` and as a consequence the overall result |
| 6026 |
does not vanish. |
| 6027 |
|
| 6028 |
\subsubsection{\textquoteleft\texttt{-ed}\textquoteright{} environments} |
| 6029 |
|
| 6030 |
With `inner' environments like \verb`cases` and \verb`dcases`, |
| 6031 |
\verb`array` and the AMS `\verb`-ed`' environments which are used |
| 6032 |
\emph{within} a math environment, there can be a conflict between |
| 6033 |
display and result when commands are nested. Consider the example |
| 6034 |
\begin{verbatim} |
| 6035 |
\[ \eval[env=array,pp,p=.,ff]{ \pi - \eval{ \pi }, |
| 6036 |
\pi - \eval{ \pi }[15] }[15*] \] |
| 6037 |
\end{verbatim} |
| 6038 |
$\Longrightarrow$ \[ \eval[env=array,pp,p=.,ff]{\pi - \eval{ \pi }, |
| 6039 |
\pi - \eval{ \pi }[15] }[15*] \]In both instances the result is zero to all $16$ significant figures, |
| 6040 |
but only the second instance, where an explicit rounding number is |
| 6041 |
specified, displays correctly. The \emph{implicit} rounding number |
| 6042 |
in the first instance is used in the display but not in the calculation. |
| 6043 |
|
| 6044 |
To see what is going on in this case, put \verb`dbg=7*11` in the |
| 6045 |
settings option. This will display both the fp-form and the \LaTeX{} |
| 6046 |
form of the result: |
| 6047 |
\begin{verbatim} |
| 6048 |
\[ \eval[env=array,dbg=7*11]{ \pi - \eval{ \pi } }[15*] \] |
| 6049 |
\end{verbatim} |
| 6050 |
$\Longrightarrow$ \[ \eval[env=array,dbg=7*11]{ \pi - \eval{ \pi } }[15*] \] |
| 6051 |
|
| 6052 |
\noindent In the \emph{formula} part of the \emph{formula=result} |
| 6053 |
display, the \emph{formula} contains the unevaluated \verb`\eval{ \pi }`, |
| 6054 |
whereas the \emph{result} has long since been evaluated. When \LaTeX{} |
| 6055 |
comes to display the whole thing, the \verb`\eval` in the \emph{formula |
| 6056 |
}is finally expanded, which means evaluated. The rounding value is |
| 6057 |
the implicitly specified $6$ decimal places of \emph{this} \verb`\eval`, |
| 6058 |
not the explicitly specified $15$ of the outer \verb`\eval`. This |
| 6059 |
is a problem for this group of `inner' environments. The solution |
| 6060 |
is to explicitly specify rounding numbers for inner \verb`\eval` |
| 6061 |
commands. |
| 6062 |
|
| 6063 |
\subsection{Error messages} |
| 6064 |
|
| 6065 |
Errors in an inner command create a small change in error message |
| 6066 |
display. |
| 6067 |
\begin{centred} |
| 6068 |
\verb`\eval{ 1 + \eval{ 1 + \eval{ k } } }` $\Longrightarrow$\\ |
| 6069 |
\eval{ 1 + \eval{ 1 + \eval{ k } } } |
| 6070 |
|
| 6071 |
\verb`\eval{ x + \eval{ k }[k=\arcsin 2] }[x=1]` $\Longrightarrow$\\ |
| 6072 |
\eval{ x + \eval{ k }[k=\arcsin 2] }[x=1] |
| 6073 |
\end{centred} |
| 6074 |
An integer is added to the `where' part of the error message. The |
| 6075 |
integer indicates the \emph{depth} (or \emph{level}) where the error |
| 6076 |
occurs. |
| 6077 |
|
| 6078 |
For an error at the top level the integer is suppressed, even though |
| 6079 |
there may be nesting elsewhere in the overall expression. This is |
| 6080 |
in the interests of straightforwardness when nesting is absent, which |
| 6081 |
will be overwhelmingly the most common situation. |
| 6082 |
\begin{centred} |
| 6083 |
\verb`\eval{ k + \eval{ x }[x=1] }[k=\arcsin 2]` $\Longrightarrow$\\ |
| 6084 |
\eval{ k + \eval{ x }[x=1] }[k=\arcsin 2] |
| 6085 |
\end{centred} |
| 6086 |
|
| 6087 |
\subsection{Debugging} |
| 6088 |
|
| 6089 |
\label{subsec:miscNestingDebugging}It is worth looking at the debug |
| 6090 |
display when \verb`\eval` commands are nested. For the outer \verb`\eval` |
| 6091 |
command: |
| 6092 |
\begin{centred} |
| 6093 |
\verb`\eval[dbg=1]{$ \sin \eval{\sin x}[x=\pi/6]\pi + 1 $}` $\Longrightarrow$ |
| 6094 |
\eval[dbg=210]{$ \sin \eval{\sin x}[x=\pi/6]\pi + 1$} |
| 6095 |
\end{centred} |
| 6096 |
There is no vv-list for the outer command whence the two empty slots |
| 6097 |
in the display but when the inner \verb`\eval` is in the vv-list, |
| 6098 |
they are filled: |
| 6099 |
\begin{centred} |
| 6100 |
\verb`\eval[dbg=1]{$ \sin k\pi + 1 $}[k={\eval{\sin x}[x=\pi/6]}]` |
| 6101 |
$\Longrightarrow$ \eval[dbg=1]{$ \sin k\pi + 1$} [k={\eval{\sin x}[x=\pi/6]}] |
| 6102 |
\end{centred} |
| 6103 |
Contrary to their behaviour (which was accidental) in earlier versions |
| 6104 |
of \texttt{numerica} debug numbers have no effect when used with an |
| 6105 |
inner \verb`\eval` command: |
| 6106 |
\begin{verbatim} |
| 6107 |
\eval{$ \sin{\left( |
| 6108 |
\eval[dbg=1]{ \sin x }[x=\pi/6] |
| 6109 |
\right)\pi} + 1 $} |
| 6110 |
\end{verbatim} |
| 6111 |
$\Longrightarrow$ \eval{$ |
| 6112 |
\sin{\left( |
| 6113 |
\eval[dbg=-1]{ \sin x }[x=\pi/6] |
| 6114 |
\right)\pi} + 1 $} |
| 6115 |
|
| 6116 |
In the example, note the use of braces to define the argument of the |
| 6117 |
outer \verb`\sin` function; see §§\ref{subsec:evalBraced-groups}, |
| 6118 |
\ref{subsec:calcComplicated-arguments}. |
| 6119 |
|
| 6120 |
\section{Parsing mathematical arguments} |
| 6121 |
|
| 6122 |
\label{sec:miscArgument-parsing} A main aim of the \texttt{numerica} |
| 6123 |
package is to require minimal, preferably no, adjustment to the \LaTeX{} |
| 6124 |
form in which an expression is typeset in order to evaluate it. But |
| 6125 |
when writing formulas mathematicians do not follow codified rules |
| 6126 |
of the kind programming languages insist on – like parenthesizing |
| 6127 |
the arguments of functions, or inserting explicit multiplication signs |
| 6128 |
({*}) between juxtaposed terms. For the package to attain its aim, |
| 6129 |
the question of where the arguments of mathematical functions end |
| 6130 |
is acute. |
| 6131 |
|
| 6132 |
Before discussing the rules \texttt{numerica} uses to answer this |
| 6133 |
question, I discuss the tools the package provides to handle exceptions |
| 6134 |
to those rules, when an author \emph{does} need to make some adjustment |
| 6135 |
to a formula for it to be evaluated correctly. |
| 6136 |
|
| 6137 |
\subsection{\protect\LaTeX{} braces} |
| 6138 |
|
| 6139 |
\label{subsec:settingsBraces}So, one has a complicated argument to |
| 6140 |
a mathematical function. It is clear to a person reading the compiled |
| 6141 |
expression in the \texttt{pdf} where the argument ends. The simplest |
| 6142 |
way to make it clear to \texttt{numerica} also is by enclosing the |
| 6143 |
argument in \LaTeX{} braces. This is the recommended practice from |
| 6144 |
version 3.0.0 of \texttt{numerica}, both because braces do not alter |
| 6145 |
the visual appearance of the formula in the \texttt{pdf} and because |
| 6146 |
it is consonant with general \LaTeX{} practice. |
| 6147 |
|
| 6148 |
The following expression, $\sin(n+\tfrac{1}{2})(x-t)$, or one like |
| 6149 |
it, occurs in multiple texts on Fourier series. The human reader understands |
| 6150 |
that the argument of the sine includes \emph{both} parenthesized factors. |
| 6151 |
But asking \texttt{numerica} to evaluate it `as is' produces |
| 6152 |
\begin{centred} |
| 6153 |
\verb`\eval{$ \sin(n+\tfrac12)(x-t) $}[n=3,x=t+\pi,t=1.234]` $\Longrightarrow$ |
| 6154 |
\eval{$ \sin(n+\tfrac12)(x-t) $}[n=3,x=t+\pi,t=1.234], |
| 6155 |
\end{centred} |
| 6156 |
which is $(\sin\tfrac{7}{2})\times\pi$ and not what was intended. |
| 6157 |
Enclosing the whole argument – both factors – in braces rescues the |
| 6158 |
situation, |
| 6159 |
\begin{centred} |
| 6160 |
\verb`\eval{$ \sin{(n+\tfrac12)(x-t)} $}[n=3,x=t+\pi,t=1.234]` $\Longrightarrow$ |
| 6161 |
\eval{$ \sin{(n+\tfrac12)(x-t)} $}[n=3,x=t+\pi,t=1.234], |
| 6162 |
\end{centred} |
| 6163 |
which is $\sin(\tfrac{7}{2}\pi)$, as intended. Another example is |
| 6164 |
\begin{centred} |
| 6165 |
\verb`\eval{\[\cos{\frac{2\pi}T n(t+\tfrac12T)}\]}[T=2,t=1,n=3]` |
| 6166 |
|
| 6167 |
$\Longrightarrow$ \eval{\[ \cos{\frac{2\pi}{T}n(t+\tfrac12T)} |
| 6168 |
\]}[T=2,t=1,n=3] |
| 6169 |
\end{centred} |
| 6170 |
which otherwise evaluates to $-6$. |
| 6171 |
|
| 6172 |
See §\ref{subsec:calcComplicated-arguments} for further examples. |
| 6173 |
The point is that the braces do not alter the visual appearance in |
| 6174 |
the \texttt{pdf} but do delimit the whole argument for the \verb`\eval` |
| 6175 |
command. |
| 6176 |
|
| 6177 |
\subsection{The cleave commands \texttt{\textbackslash q} and \texttt{\textbackslash Q}} |
| 6178 |
|
| 6179 |
\label{subsec:miscCleave}An alternative to using braces is to use |
| 6180 |
\texttt{numerica}'s `cleave' commands. The word \emph{cleave} has |
| 6181 |
two opposed meanings: to adhere or cling to, and to split apart or |
| 6182 |
separate. \texttt{numerica} defines two commands, \verb`\q` and \verb`\Q` |
| 6183 |
to achieve these opposite effects. When a mathematical argument is |
| 6184 |
being parsed, the \verb`\q` command joins the next token to the argument |
| 6185 |
(cleaves\emph{ to}); the \verb`\Q` command severs the next token |
| 6186 |
from the argument (cleaves\emph{ apart}). Neither command leaves a |
| 6187 |
visible trace in the output or has any other effect on the calculation |
| 6188 |
beyond joining or severing the tokens on either side. |
| 6189 |
|
| 6190 |
Repeating the penultimate example with \verb`\q` between the bracketed |
| 6191 |
factors rather than enclosing all in braces, |
| 6192 |
\begin{centred} |
| 6193 |
\verb`\eval{$ \sin(n+\tfrac12)\q(x-t) $}[n=3,x=t+\pi,t=1.234]` $\Longrightarrow$ |
| 6194 |
\eval{$ \sin(n+\tfrac12)\q(x-t) $}[n=3,x=t+\pi,t=1.234]. |
| 6195 |
\end{centred} |
| 6196 |
which again is $\sin(\tfrac{7}{2}\pi)$. |
| 6197 |
|
| 6198 |
The \verb`\Q` command splits an argument. Without it, we have |
| 6199 |
\begin{centred} |
| 6200 |
\verb`\eval{$ \ln n\,X $}[n=2,X=e^2]` $\Longrightarrow$ \eval{$ \ln n\,X $}[n=2,X=e^2]; |
| 6201 |
\end{centred} |
| 6202 |
with \verb`\Q` inserted before the fraction, |
| 6203 |
\begin{centred} |
| 6204 |
\verb`\eval{$ \ln n\Q\,X $}[n=2,X=e^2]` $\Longrightarrow$ \eval{$ \ln n\Q\,X $}[n=2,X=e^2]. |
| 6205 |
\end{centred} |
| 6206 |
However, an author could be kinder to the reader by not using a thin |
| 6207 |
space (\verb`\,`) to indicate separation of the terms but rather |
| 6208 |
parentheses, ($(\ln n)X$, or rearrangement, $X\ln n$, and avoid |
| 6209 |
the need for \verb`\Q` entirely. |
| 6210 |
|
| 6211 |
\subsubsection{Mnemonic} |
| 6212 |
|
| 6213 |
As mnemonic, best seen in sans serif for the Latin Modern fonts used |
| 6214 |
in this document, think of the letter \textsf{q} as a circle cleaving\emph{ |
| 6215 |
to} a vertical descender; think of the letter \textsf{Q} as a circle |
| 6216 |
cleaved\emph{ asunder} by the diagonal stroke. |
| 6217 |
|
| 6218 |
\subsection{Parsing groups} |
| 6219 |
|
| 6220 |
A formula is a sequence of tokens and brace groups. When evaluating |
| 6221 |
a formula, \verb`\eval` digests the formula from the left, \LaTeX{} |
| 6222 |
argument by \LaTeX{} argument, where \emph{argument} here means either |
| 6223 |
a token (an N-type argument in \verb`expl3`-speak) or a brace group |
| 6224 |
(an n-type argument). Some mathematical functions have arguments which |
| 6225 |
correspond to \LaTeX{} arguments – think \verb`\sqrt`, \verb`\frac`, |
| 6226 |
\verb`\binom`; also \verb`^`. But for mathematical functions like |
| 6227 |
\verb`\surd` or \verb`\sin` or \verb`\ln`, this is not so; nor |
| 6228 |
is it for sums and products, nor for comparisons. There need be no |
| 6229 |
direct translation of \LaTeX{} argument (an `L-arg') to mathematical |
| 6230 |
argument (an `M-arg'). |
| 6231 |
|
| 6232 |
\begin{wraptable}{o}{0.5\columnwidth}% |
| 6233 |
\caption{ Parsing groups}\label{tab:miscShadingGroups} |
| 6234 |
|
| 6235 |
\begin{centering} |
| 6236 |
\begin{center} |
| 6237 |
\begin{tabular}{ll} |
| 6238 |
\toprule |
| 6239 |
group & function/operation\tabularnewline |
| 6240 |
\midrule |
| 6241 |
I & surd, \verb`Not`\tabularnewline |
| 6242 |
II & unary functions, \verb`/`\tabularnewline |
| 6243 |
III & sums, products\tabularnewline |
| 6244 |
IV & comparisons\tabularnewline |
| 6245 |
V & \verb`And`, \verb`Or`\tabularnewline |
| 6246 |
\bottomrule |
| 6247 |
\end{tabular} |
| 6248 |
\par\end{center} |
| 6249 |
\par\end{centering} |
| 6250 |
\end{wraptable}% |
| 6251 |
Different mathematical functions, operations, relations – for convenience |
| 6252 |
call them collectively \emph{functions} – have different reaches when |
| 6253 |
it comes to how we read subsequent tokens. We might think of a function |
| 6254 |
as casting a shadow over subsequent tokens; what lies in the shadow |
| 6255 |
is part of its argument; what lies beyond the shadow is not. Table |
| 6256 |
§\ref{tab:miscShadingGroups} lists the different \emph{parsing groups |
| 6257 |
}(alternatively \emph{shading groups}) that \texttt{numerica} takes |
| 6258 |
account of. Those functions with the lowest group number have the |
| 6259 |
shortest reach, cast the shortest shadows which progressively lengthen |
| 6260 |
as the group number increases. |
| 6261 |
|
| 6262 |
To justify the groupings in Table~\ref{tab:miscShadingGroups}, I |
| 6263 |
look at examples, particularly from \emph{HMF} but also from G. H. |
| 6264 |
Hardy, \emph{A course of pure mathematics}, and other sources and |
| 6265 |
use the following terminology. A mathematical argument may end \emph{at} |
| 6266 |
an L-arg, meaning immediately before the L-arg, or end \emph{with} |
| 6267 |
the L-arg, meaning immediately after the L-arg. Ending or not will |
| 6268 |
in general depend on whether the argument is in \emph{first position} |
| 6269 |
– the position immediately following a function token like \verb`\sin` |
| 6270 |
or \verb`\surd` – or in \emph{general position} – any later position. |
| 6271 |
Formatting elements do not change the position count. This applies |
| 6272 |
to things like spaces or phantoms (and their arguments) or modifiers |
| 6273 |
like \verb`\left` or \verb`\biggl`. Multi-token numbers (in decimal |
| 6274 |
or scientific formats) are treated as single items; they advance the |
| 6275 |
position count by exactly one. Finally, a \emph{naked} sign (like |
| 6276 |
a plus or minus sign) is one that is \emph{not} enclosed in brackets |
| 6277 |
lying wholly to the right of the function whose argument is being |
| 6278 |
determined. |
| 6279 |
|
| 6280 |
\subsubsection{Parsing group I} |
| 6281 |
|
| 6282 |
The only functions in this category are the surd and logical \verb`Not`. |
| 6283 |
|
| 6284 |
Why distinguish the surd from other unary functions? Hardy writes |
| 6285 |
(§13) $\surd(pq)$ but (§206) $\log xy=\log x+\log y$ – the surd |
| 6286 |
does not have the reach of the logarithm. The logarithm extends to |
| 6287 |
both members of a product; the surd does not and the factors need |
| 6288 |
to be parenthesized if the surd is to apply to both.\emph{ }Surely |
| 6289 |
we all agree that \verb`\sin2\pi`, displaying as $\sin2\pi$, vanishes? |
| 6290 |
The argument of the sine extends beyond the $2$ to include the $\pi$. |
| 6291 |
But \verb`\surd2\pi`, displaying as $\surd2\pi$, we understand to |
| 6292 |
be $\surd2\times\pi$. The argument of the surd ends with the $2$. |
| 6293 |
The surd binds more tightly to its argument than is true of unary |
| 6294 |
functions generally. |
| 6295 |
|
| 6296 |
For parsing group I |
| 6297 |
\begin{enumerate} |
| 6298 |
\item if a left bracket is in first position, the mathematical argument |
| 6299 |
ends with the matching right bracket; otherwise |
| 6300 |
\item the argument ends with the item in first position and any L- or M-args |
| 6301 |
required by that item. |
| 6302 |
\end{enumerate} |
| 6303 |
If the factorial sign \verb`!` \emph{preceded} its argument, it too |
| 6304 |
would belong in this parsing group, for it also binds tightly like |
| 6305 |
the surd. This means that an expression like $\surd4!$ is intrinsically |
| 6306 |
ambiguous. Is it the square root of $24$ or the factorial of $2$? |
| 6307 |
In \texttt{numerica} it produces the (perhaps rather odd) error |
| 6308 |
\begin{centred} |
| 6309 |
\verb`\eval{$ \surd 4! $}` $\Longrightarrow$ \eval{$ \surd4! $} |
| 6310 |
\end{centred} |
| 6311 |
Since \verb`\eval` digests a formula from the left, the surd seizes |
| 6312 |
the argument \verb`4`; there is then nothing for the factorial to |
| 6313 |
operate on. Parenthesizing like either \verb`(\surd 4)!` or \verb`\surd(4!)` |
| 6314 |
repairs the situation. Because other unary functions (like the sine |
| 6315 |
or logarithm) do not bind as tightly, this ambiguity does not arise |
| 6316 |
for them. |
| 6317 |
|
| 6318 |
Exponents cause no problem because taking square roots and raising |
| 6319 |
to a power are commutative operations – the result is the same whichever |
| 6320 |
is performed first. |
| 6321 |
\begin{centred} |
| 6322 |
\verb`\eval[pp,ff]{$ \surd 3^4, \surd(3^4), (\surd3)^4 $}` $\Longrightarrow$ |
| 6323 |
\eval[pp,ff]{$ \surd 3^4, \surd(3^4), (\surd3)^4 $}. |
| 6324 |
\end{centred} |
| 6325 |
|
| 6326 |
\subsubsection{Parsing group II} |
| 6327 |
|
| 6328 |
This category includes the trigonometric and hyperbolic functions, |
| 6329 |
their inverses, the various logarithms and the exponential functions, |
| 6330 |
and the signum function \verb`\sgn`. It also includes the denominators |
| 6331 |
of slash fractions \verb`/`. |
| 6332 |
\begin{itemize} |
| 6333 |
\item In parsing group II we wish to accommodate usages like $\ln z^{n}=n\ln z$ |
| 6334 |
(\emph{HMF} 4.1.11), or $2\arctan e^{z}$ (\emph{HMF} 4.3.117), meaning |
| 6335 |
an exponent is included in the argument. This must include exponents |
| 6336 |
of parenthesized arguments to accommodate |
| 6337 |
\[ |
| 6338 |
\ln\left(1+\frac{x}{n}\right)^{n}=n\ln\left(1+\frac{x}{n}\right). |
| 6339 |
\] |
| 6340 |
\item An approximation to Stirling's formula for the factorial is often |
| 6341 |
written $\ln N!\approx N\ln N-N$ (widely used in texts on statistical |
| 6342 |
mechanics). Hence the factorial sign should also be considered part |
| 6343 |
of the argument. |
| 6344 |
\item $\ln xy=\ln x+\ln y$ means the argument must reach over a product |
| 6345 |
of variables. Identities like $\sin2z=2\sin z\cos z$ mean the argument |
| 6346 |
also reaches over numbers, and expressions like $\sin\tfrac{1}{2}\pi x$ |
| 6347 |
(\emph{HMF} 4.3.104) mean that it further reaches over \verb`\tfrac`-s |
| 6348 |
and constants. |
| 6349 |
\item Essentially \emph{anything }can be in first position, and without |
| 6350 |
parentheses; e.g. |
| 6351 |
\begin{itemize} |
| 6352 |
\item unary functions: $\ln\ln z$ (\emph{HMF} 4.1.52), $\ln\tan\dfrac{z}{2}$ |
| 6353 |
(\emph{HMF} 4.3.116), |
| 6354 |
\item fractions: $\ln\dfrac{z_{1}}{z_{2}}$ (\emph{HMF} 4.1.9), $\arcsin\dfrac{(2ax+b)}{(b^{2}-4ac)^{1/2}}$ |
| 6355 |
(\emph{HMF} 3.3.36), $\ln\dfrac{\tan z}{z}$ (\emph{HMF} 4.3.73), |
| 6356 |
\item absolute values: $\ln\abs*{\dfrac{a+x}{a-x}}$ (\emph{HMF} 3.3.25), |
| 6357 |
\item square roots: $\arctan\sqrt{\dfrac{\nu_{1}}{\nu_{2}}F}$ (\emph{HMF |
| 6358 |
}26.6.8) |
| 6359 |
\end{itemize} |
| 6360 |
\end{itemize} |
| 6361 |
With these examples in mind, for parsing group II |
| 6362 |
\begin{enumerate} |
| 6363 |
\item if a left bracket is in first position, the mathematical argument |
| 6364 |
ends with the matching right bracket and any attached exponent, or |
| 6365 |
factorial or double factorial sign; otherwise |
| 6366 |
\item the mathematical argument includes the item in first position and |
| 6367 |
any L- or M-args required by that item; |
| 6368 |
\begin{enumerate} |
| 6369 |
\item if the item in first position is a number, variable, constant or \verb`\tfrac` |
| 6370 |
\begin{enumerate} |
| 6371 |
\item the argument appends the next item if it is a number, variable, constant |
| 6372 |
or \verb`\tfrac`, and so on recursively; or |
| 6373 |
\item the argument appends the next item if it is an exponent, or facorial |
| 6374 |
or double factorial sign, and ends there; otherwise |
| 6375 |
\item the argument ends. |
| 6376 |
\end{enumerate} |
| 6377 |
\item if the item in first position is not a number, variable, constant |
| 6378 |
or \verb`\tfrac` |
| 6379 |
\begin{enumerate} |
| 6380 |
\item the argument appends the next item if it is an exponent, or factorial |
| 6381 |
or double factorial sign, and ends there; otherwise |
| 6382 |
\item the argument ends. |
| 6383 |
\end{enumerate} |
| 6384 |
\end{enumerate} |
| 6385 |
\end{enumerate} |
| 6386 |
Thus an argument may extend over numbers, constants, variables and |
| 6387 |
\verb`\tfrac`-s, as instanced by $\sin2\tfrac{p}{q}\pi x$ which |
| 6388 |
exhibits all elements. |
| 6389 |
|
| 6390 |
There are still areas of ambiguity. Consider the different outcomes |
| 6391 |
here (the logarithms are to base $10$): |
| 6392 |
\begin{centred} |
| 6393 |
\verb`\eval[pp,ff]{$ \log m^3n, \log nm^3 $}[m=10,n=5]` $\Longrightarrow$ |
| 6394 |
\eval[pp,ff]{$ \log m^3n, \log nm^3 $}[m=10,n=5]. |
| 6395 |
\end{centred} |
| 6396 |
In both instances the argument stops with the exponent, which means |
| 6397 |
$n$ is \emph{not} part of the argument in the first. Any criterion |
| 6398 |
is going to miss some instances where a different outcome might be |
| 6399 |
anticipated. Where an argument ends is affected by visual appearance |
| 6400 |
in the \texttt{pdf}. Anything that breaks the `visual flow' of juxtaposed |
| 6401 |
numbers, variables, constants and \verb`\tfrac`-s is considered by |
| 6402 |
\texttt{numerica} to end the argument. An exponent does that. If you |
| 6403 |
feel ambiguity is possible, parenthesize or rearrange to clarify. |
| 6404 |
|
| 6405 |
Similarly, a \verb`\dfrac` breaks the visual flow in the following: |
| 6406 |
\begin{centred} |
| 6407 |
\verb`\eval[pp,ff]{$ \sin\dfrac12\pi, \sin\tfrac12\pi $}` $\Longrightarrow$ |
| 6408 |
\eval[pp,ff]{$ \sin\dfrac12\pi, \sin\tfrac12\pi $}. |
| 6409 |
\end{centred} |
| 6410 |
Nearly always, someone writing an expression like this intends the |
| 6411 |
$\pi$ to be part of the argument. In that case, a \verb`\tfrac` |
| 6412 |
should be used since the \verb`\dfrac` breaks the `visual flow' |
| 6413 |
of the argument. |
| 6414 |
|
| 6415 |
\noindent{}% |
| 6416 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 6417 |
\begin{shaded}% |
| 6418 |
|
| 6419 |
\paragraph{\texttt{\textbackslash frac}} |
| 6420 |
|
| 6421 |
The problem comes with \verb`\frac` which in an inline environment |
| 6422 |
displays like \verb`\tfrac`. I considered making the argument behaviour |
| 6423 |
of \verb`\frac` the same as \verb`\tfrac` for textstyle contexts, |
| 6424 |
and the same as \verb`\dfrac` for displaystyle contexts, but that |
| 6425 |
would have meant the same expression evaluating to different results |
| 6426 |
depending on whether it lay in an inline or displaystyle environment. |
| 6427 |
That was unacceptable and for argument determination \verb`\frac` |
| 6428 |
is treated like \verb`\dfrac` in \emph{all} environments.\end{shaded}% |
| 6429 |
\end{minipage} |
| 6430 |
|
| 6431 |
\paragraph{Slash~fraction denominators} |
| 6432 |
|
| 6433 |
When using \verb`/` to write fractions or indicate division, it is |
| 6434 |
easy to write ambiguous expressions. How should $\pi/2n$ be interpreted? |
| 6435 |
With from-the-left evaluation and calculator precedence rules (which |
| 6436 |
give equal precedence to multiplication and division), this would |
| 6437 |
be interpreted as $(\pi/2)\times n$, but most people will instinctively |
| 6438 |
interpret it as $\pi/(2n)$ and this is what \texttt{numerica} does. |
| 6439 |
It places \verb`/` in parsing group II and treats the denominator |
| 6440 |
of the slash \emph{as if it were the argument of a unary function}. |
| 6441 |
This means that $1/2\sin(\pi/6)$ is parsed as $(1/2)\sin x$ rather |
| 6442 |
than as $1/(2\sin x)$. It also means that $1/2\exp(1)$ and $1/2e$ |
| 6443 |
give different results. In the author's view this is acceptable since |
| 6444 |
they display differently and are not instinctively read in the same |
| 6445 |
way. (But again authors should paranthesize or rearrange to avoid |
| 6446 |
ambiguity.) |
| 6447 |
|
| 6448 |
\paragraph{Trigonometric functions} |
| 6449 |
|
| 6450 |
\label{subsec:miscTrigFns}Trigonometric functions are set to parsing |
| 6451 |
group II. This accommodates many instances of how arguments are used |
| 6452 |
with these functions, but trigonometrical identities and Fourier series |
| 6453 |
in particular make a nonsense of the restrictions. I find $\tan\tfrac{1}{2}(A+B)$ |
| 6454 |
(\emph{HMF }4.3.148) and $\sec\pi(\tfrac{1}{4}+\tfrac{1}{2}az)$ (\emph{HMF |
| 6455 |
}19.3.3), $\cos(2m+p)z$ (\emph{HMF }20.2.3) and $\sin(2n+1)v$ (\emph{HMF |
| 6456 |
}16.38.1), and, on looking through various texts on Fourier series, |
| 6457 |
\[ |
| 6458 |
\cos\frac{2\pi}{T}nt,\quad\cos\frac{2\pi}{T}n(t+\tfrac{1}{2}T), |
| 6459 |
\] |
| 6460 |
\[ |
| 6461 |
\cos(N+\tfrac{1}{2})\frac{2\pi\tau}{T},\quad\sin2\pi\left(\frac{x}{\lambda}-\frac{t}{T}\right). |
| 6462 |
\] |
| 6463 |
Previous versions of \texttt{numerica} employed a setting \verb`()=0,1,2` |
| 6464 |
to parse these outliers from usual practice. From version 3.0.0, this |
| 6465 |
setting has been removed and authors are advised to enclose such arguments |
| 6466 |
in \LaTeX{} braces. The braces do not affect the visual appearance |
| 6467 |
in the \texttt{pdf} but unambiguously tell \texttt{numerica} where |
| 6468 |
the argument begins and ends. |
| 6469 |
|
| 6470 |
\subsubsection{Parsing group III} |
| 6471 |
|
| 6472 |
The only members of this group are \verb`\sum` and \verb`\prod`. |
| 6473 |
A `naked' plus or minus sign is one that is not enclosed by brackets. |
| 6474 |
For parsing group III |
| 6475 |
\begin{enumerate} |
| 6476 |
\item the argument ends |
| 6477 |
\begin{enumerate} |
| 6478 |
\item at the first naked plus or minus sign encountered, or |
| 6479 |
\begin{enumerate} |
| 6480 |
\item first naked comparison sign (or command) encountered, or |
| 6481 |
\item first naked \verb`And` or \verb`Or` sign encountered, or |
| 6482 |
\end{enumerate} |
| 6483 |
\item at the end of the formula. |
| 6484 |
\end{enumerate} |
| 6485 |
\end{enumerate} |
| 6486 |
Almost always this means (a) or (b), and seems to be the instinctive |
| 6487 |
practice. \emph{HMF} has multiple examples in multiple chapters of |
| 6488 |
the argument to a sum ending at a naked plus sign: 7.3.12 \& 7.3.14, |
| 6489 |
9.1.11 \& 9.1.77, 9.6.35 \& 9.6.43, 11.1.9, \ldots{} (at that point |
| 6490 |
I stopped looking). They were all of the form |
| 6491 |
\[ |
| 6492 |
\sum\text{argument}+\ldots |
| 6493 |
\] |
| 6494 |
A minus sign serving the same purpose was harder to find but \emph{HMF} |
| 6495 |
10.4.65 \& 10.4.67 are two instances. I considered whether a \verb`\times` |
| 6496 |
or slash fraction sign \verb`/` might end the argument of a sum, |
| 6497 |
but surely we need to allow things like $\sum1/n^{2}$ which rules |
| 6498 |
out the slash and \emph{HMF} 9.9.11 provides two of a number of instances |
| 6499 |
of sum arguments continuing past explicit \verb`\times` signs (at |
| 6500 |
line breaks when a summand spills onto a second line). |
| 6501 |
|
| 6502 |
\noindent{}% |
| 6503 |
\noindent\begin{minipage}[t]{1\columnwidth}% |
| 6504 |
\begin{shaded}% |
| 6505 |
Please note that parenthesizing to clarify the argument of a sum has |
| 6506 |
limitations. Writing |
| 6507 |
\[ |
| 6508 |
\sum\left(\mathtt{<stuff>}\right)\mathtt{<more\ stuff>} |
| 6509 |
\] |
| 6510 |
does not necessarily end the summand at the right parenthesis: it |
| 6511 |
ends at the first naked $+$ or $-$ sign encountered (if it is not |
| 6512 |
forced by a \verb`\Q` command or \LaTeX{} braces). Sums \emph{have |
| 6513 |
to} include brackets to cope with factors like $(-1)^{n}$.\end{shaded}% |
| 6514 |
\end{minipage}\medskip{} |
| 6515 |
|
| 6516 |
Because they are evaluated using the same code as sums I (at first |
| 6517 |
unthinkingly) placed products with sums but doubts later intruded. |
| 6518 |
In \emph{HMF} products occur only occasionally and are almost all |
| 6519 |
of the form |
| 6520 |
\[ |
| 6521 |
\prod\left(\text{argument}\right) |
| 6522 |
\] |
| 6523 |
where the argument is bracketed (often with \verb`\left \right` modifiers) |
| 6524 |
and the multiplicand ends with the right bracket. At least twice (\emph{HMF |
| 6525 |
}6.1.25 and 24.2.2.1) an exponent ($-1$) is attached to the right |
| 6526 |
bracket and the argument ends there. Looking further afield, a text |
| 6527 |
on number theory has examples where the argument of the product extends |
| 6528 |
to \emph{three} parenthesised factors, $\prod\left(\text{arg}1\right)\left(\text{arg2}\right)\left(\text{arg3}\right)$ |
| 6529 |
and a number of others where it extends to two. A text on theory of |
| 6530 |
functions has |
| 6531 |
\[ |
| 6532 |
\prod_{n=1}^{\infty}\left(1+\frac{z}{n}\right)e^{z/n} |
| 6533 |
\] |
| 6534 |
although \emph{HMF}, for the same expression, encloses the two factors |
| 6535 |
within (large) square brackets, as if some ambiguity existed as to |
| 6536 |
how far the reach of the \verb`\prod` extended. |
| 6537 |
|
| 6538 |
\emph{Tentatively} I retain products here in the same group as sums. |
| 6539 |
|
| 6540 |
\subsubsection{Parsing group IV} |
| 6541 |
|
| 6542 |
Comparison symbols form this group: \verb`=`, \verb`<`, \verb`>`, |
| 6543 |
\verb`\ne`, \verb`\le`, \verb`\ge`, \verb`\leq`, \verb`\geq`, |
| 6544 |
and the various comparison commands from the \texttt{amssymb} package |
| 6545 |
listed in §\ref{subsec:evalAmssymb-comparisons}. It is the argument |
| 6546 |
on the right-hand side of the relation that needs determining (the |
| 6547 |
argument on the left ends at the comparison). For parsing group IV |
| 6548 |
\begin{enumerate} |
| 6549 |
\item the argument ends at |
| 6550 |
\begin{enumerate} |
| 6551 |
\item the first naked \verb`And` or \verb`Or` encountered, or |
| 6552 |
\item the first naked comparison sign or command encountered, or |
| 6553 |
\item the end of the formula. |
| 6554 |
\end{enumerate} |
| 6555 |
\end{enumerate} |
| 6556 |
|
| 6557 |
\subsubsection{Parsing group V} |
| 6558 |
|
| 6559 |
Logical \verb`And` and logical \verb`Or` are the sole members of |
| 6560 |
this group. It is the right-hand side of the \verb`And` or \verb`Or` |
| 6561 |
command that needs determining. For parsing group V |
| 6562 |
\begin{enumerate} |
| 6563 |
\item the argument ends at |
| 6564 |
\begin{enumerate} |
| 6565 |
\item the first naked \verb`And` or \verb`Or` encountered, or |
| 6566 |
\item the end of the formula. |
| 6567 |
\end{enumerate} |
| 6568 |
\end{enumerate} |
| 6569 |
|
| 6570 |
\subsubsection{Disclaimer} |
| 6571 |
|
| 6572 |
The parsing rules of the different groups are not normative; they |
| 6573 |
are not statements of how mathematical formulas should be written. |
| 6574 |
Rather they attempt to capture regularities in how mathematicians |
| 6575 |
write formulas. It is \emph{how things look and are read in the }\texttt{pdf}, |
| 6576 |
not \LaTeX , that is the guide. You are always free to parenthesize |
| 6577 |
as you see fit, to insert cleave commands (\verb`\q` or \verb`\Q`) |
| 6578 |
or to use \LaTeX{} braces to force outcomes. |
| 6579 |
|
| 6580 |
The rule should always be to write expressions that are clear to the |
| 6581 |
reader of the \texttt{pdf}. An expression that is ambiguous to the |
| 6582 |
reader, even if it fits within the parsing rules, is to be deprecated. |
| 6583 |
The \emph{intent} is that \verb`\eval` can parse unambiguous expressions |
| 6584 |
of the kind that mathematicians, scientists, engineers \emph{do} write, |
| 6585 |
rather than falter over `corner cases'. |
| 6586 |
|
| 6587 |
\section{Using \texttt{numerica} with \protect\LyX} |
| 6588 |
|
| 6589 |
\label{sec:miscLyX}The document processor \LyX{} has a facility that |
| 6590 |
enables snippets from a document to be compiled separately and the |
| 6591 |
results presented to the user without having to compile the entire |
| 6592 |
document. The present document was written in \LyX . The demonstration |
| 6593 |
calculations were evaluated using this \emph{instant preview} facility. |
| 6594 |
|
| 6595 |
To use \texttt{numerica} in \LyX{} go to \textsf{Document \lyxarrow{} |
| 6596 |
Settings \lyxarrow{} LaTeX Preamble} and enter |
| 6597 |
\begin{verbatim} |
| 6598 |
\usepackage{numerica} |
| 6599 |
\end{verbatim} |
| 6600 |
then click \textsf{OK}. You may wish to follow the above line in the |
| 6601 |
preamble with \verb`\nmcReuse{}`: |
| 6602 |
\begin{verbatim} |
| 6603 |
\nmcReuse{} |
| 6604 |
\end{verbatim} |
| 6605 |
In that case, type the extra line and \emph{then} click \textsf{OK}. |
| 6606 |
The additional line ensures all saved values are available in your |
| 6607 |
document from the outset. |
| 6608 |
|
| 6609 |
\subsection{Instant~preview} |
| 6610 |
|
| 6611 |
The instant preview facility of \LyX{} performs mini-\LaTeX{} runs on |
| 6612 |
selected parts of a document (for instance, the mathematical parts) |
| 6613 |
and displays the results in \LyX{} while the user continues to work |
| 6614 |
on the surrounding document.\texttt{ numerica} uses these mini-\LaTeX{} |
| 6615 |
runs to do its evaluations and display their results. That means you |
| 6616 |
get feedback on your calculations almost immediately. |
| 6617 |
|
| 6618 |
To use this facility first ensure that instant preview is turned on. |
| 6619 |
This means selecting \textsf{Tools \lyxarrow Preferences \lyxarrow Look |
| 6620 |
\& Feel \lyxarrow{} Display}, ensuring that the \textsf{Display graphics} |
| 6621 |
checkbox is checked, and against \textsf{Instant preview} selecting |
| 6622 |
\textsf{On}, then clicking \textsf{OK}. |
| 6623 |
|
| 6624 |
\subsubsection{Document location} |
| 6625 |
|
| 6626 |
It also matters where your document is located. You may have your |
| 6627 |
own local or personal texmf tree. If your document is located there, |
| 6628 |
perhaps in the \verb`doc` folder, then not all features of preview |
| 6629 |
will work as expected. Presumably this is because both \LyX{} and your |
| 6630 |
\LaTeX{} distribution (e.g.\ \TeX Live or MiK\TeX ) are interacting |
| 6631 |
with the location and interfere. Move your document to another location |
| 6632 |
which your \LaTeX{} distribution has no interest in, and open it in |
| 6633 |
\LyX{} there. |
| 6634 |
|
| 6635 |
\subsubsection{Global vs local previewing} |
| 6636 |
|
| 6637 |
\label{subsec:miscLyXGlobal-vs-local}Compilation of previews occurs |
| 6638 |
in two distinct modes. |
| 6639 |
|
| 6640 |
\paragraph{Global preview generation:} |
| 6641 |
|
| 6642 |
When a document is opened (and preview is \emph{on}), all previews |
| 6643 |
in the document are formed in sequence in the one \LaTeX{} run. This |
| 6644 |
is the global mode. The mini-\LaTeX{} run may well be substantial. |
| 6645 |
It compiles a \verb`.tex` file that begins with the document's preamble |
| 6646 |
with some additions then comes \verb`\begin{document}`. That is followed |
| 6647 |
by a sequence of preview environments, |
| 6648 |
\begin{verbatim} |
| 6649 |
\begin{preview} |
| 6650 |
<stuff> |
| 6651 |
\end{preview} |
| 6652 |
\end{verbatim} |
| 6653 |
one for each preview in the document. Finally there is an \verb`\end{document}` |
| 6654 |
statement. Critically, all previews are between the same \verb`\begin{document}`, |
| 6655 |
\verb`\end{document}` statements, and so earlier previews in the |
| 6656 |
sequence can communicate with later ones. |
| 6657 |
|
| 6658 |
\paragraph{Local preview generation:} |
| 6659 |
|
| 6660 |
The other mode in which preview operates is local. Suppose you have |
| 6661 |
your document open and want to add to it, for instance with a simple |
| 6662 |
evaluation, \verb`\eval{x+y}[x=1,y=2]` in an ERT inset in a preview |
| 6663 |
inset. The resulting mini-\LaTeX{} run is of the form |
| 6664 |
\begin{verbatim} |
| 6665 |
<preamble> |
| 6666 |
\begin{document} |
| 6667 |
\begin{preview} |
| 6668 |
\eval{x+y}[x=1,y=2] |
| 6669 |
\end{preview} |
| 6670 |
\end{document} |
| 6671 |
\end{verbatim} |
| 6672 |
The preamble is as before but only a solitary preview sits between |
| 6673 |
the \verb`\begin` \verb`{document}`, \verb`\end{document}` statements. |
| 6674 |
That preview is isolated from all other, previous previews and will |
| 6675 |
be isolated from all other, later previews. |
| 6676 |
|
| 6677 |
This has implications for the supplementary commands of Chapter~\ref{chap:Supplementary-commands} |
| 6678 |
and means that if you want to transfer information (a macro, a constant, |
| 6679 |
a result) from one preview to another, you need to do it through the |
| 6680 |
preamble or by means of an external file or, in some cases, by forcing |
| 6681 |
a global preview run in which all previews are recompiled between |
| 6682 |
the same \verb`\begin{document}`, \verb`\end{document}` statements. |
| 6683 |
|
| 6684 |
\paragraph{Forcing a global preview run} |
| 6685 |
|
| 6686 |
Closing then opening a document is one way to force a global preview |
| 6687 |
compilation. Another is to change the zoom level. This causes \LyX{} |
| 6688 |
to recompile all previews at the new zoom level. But you may not want |
| 6689 |
to work at the new zoom level. Going back to the old zoom level will |
| 6690 |
force a second recompilation of all previews. For a large document |
| 6691 |
\emph{two} recompilations is too heavy a burden. The secret is to |
| 6692 |
combine a zoom in and a zoom out into one command and attach it to |
| 6693 |
a shortcut. |
| 6694 |
|
| 6695 |
If you go to \textsf{Tools \lyxarrow{} Preferences \lyxarrow{} Editing |
| 6696 |
\lyxarrow{} Shortcuts}, click on the \textsf{New} button and enter |
| 6697 |
\begin{verbatim} |
| 6698 |
command-sequence buffer-zoom-in; buffer-zoom-out |
| 6699 |
\end{verbatim} |
| 6700 |
then assign a shortcut to it (\verb`Alt+Z` for zoom?) you will gain |
| 6701 |
a simple means of forcing a global recompilation of previews. |
| 6702 |
|
| 6703 |
\subsubsection{Mathed} |
| 6704 |
|
| 6705 |
(Mathed = the \LyX{} mathematics editor.) If you have instant preview |
| 6706 |
\emph{on} then one way to use \texttt{numerica} in \LyX{} is to enter |
| 6707 |
an \verb`\eval` command in mathed. Clicking the cursor outside the |
| 6708 |
editor with the mouse or moving it outside with the space bar or arrow |
| 6709 |
keys will then trigger formation of a preview of the editor's contents |
| 6710 |
– a snippet of what will be shown in the \texttt{pdf}. This will be |
| 6711 |
displayed in mathed's place after a generally short `pause for thought' |
| 6712 |
as the mini-\LaTeX{} run progresses behind the scenes. |
| 6713 |
|
| 6714 |
The original expression can be recovered by clicking on the preview. |
| 6715 |
The content of mathed is immediately displayed and can be edited. |
| 6716 |
|
| 6717 |
\paragraph{\protect\LaTeX{} braces~\{~~\}} |
| 6718 |
|
| 6719 |
\LyX{} does not support \texttt{numerica}'s \verb`\eval` command `out |
| 6720 |
of the box' as it does, say, \verb`\frac` or \verb`\sqrt`. To use |
| 6721 |
the \verb`\eval` command in mathed you will need to supply the braces |
| 6722 |
used to delimit its mandatory argument. (For \verb`\frac` and \verb`\sqrt` |
| 6723 |
by contrast, \LyX{} supplies these automatically in the form of blue-outlined |
| 6724 |
boxes.) Unfortunately the \verb`{` key\footnote{\textsf{Shift+{[}} on my keyboard.} |
| 6725 |
does not insert a left brace into the document but rather an escaped |
| 6726 |
left brace \verb`\{` as you can see by looking at \textsf{View \lyxarrow{} |
| 6727 |
Code Preview Pane}. Escaped braces like this are used for grouping |
| 6728 |
terms in \emph{mathematics}; they are not the delimiters of a \LaTeX{} |
| 6729 |
argument. |
| 6730 |
|
| 6731 |
The brace delimiters for \LaTeX{} arguments are entered in mathed by |
| 6732 |
typing a backslash \textsf{\textbackslash{} }then a left brace\textsf{ |
| 6733 |
\{} – two separate key presses rather than a single combined press. |
| 6734 |
This enters a balanced pair of (unescaped) braces with the cursor |
| 6735 |
sitting between them waiting for input. Alternatively, if you have |
| 6736 |
already written an expression that you want to place between braces, |
| 6737 |
select it, then type \textsf{\textbackslash{} }then\textsf{ \{}. |
| 6738 |
|
| 6739 |
\subsubsection{Preview insets} |
| 6740 |
|
| 6741 |
There are problems with using mathed for calculations. |
| 6742 |
\begin{itemize} |
| 6743 |
\item Expressions entered in mathed are necessarily of the form \verb`$ \eval... $` |
| 6744 |
or more generally \verb`delimiter` \verb`\eval...` \verb`delimiter`. |
| 6745 |
But you may wish to wrap the \verb`\eval` command \emph{around} the |
| 6746 |
math delimiters to produce a \emph{formula=result} form of display. |
| 6747 |
In mathed the only way to effect such a display is to write the \emph{formula= |
| 6748 |
}part yourself – which may involve no more than copy and paste but |
| 6749 |
is still additional mouse work/key pressing. |
| 6750 |
\item Mathed does not accept carriage returns. If you want to format a complicated |
| 6751 |
expression for readability by breaking it into separate lines, you |
| 6752 |
can't. The expression is jammed into the one line, along with the |
| 6753 |
settings option content and the vv-list, often extending well beyond |
| 6754 |
the edge of the screen. |
| 6755 |
\end{itemize} |
| 6756 |
For these reasons I have come to prefer \emph{not} using mathed for |
| 6757 |
calculations but instead to use preview insets wrapped around \TeX -code |
| 6758 |
(ERT) insets. \LyX{} uses the shortcut \textsf{Ctrl+L} to insert an |
| 6759 |
ERT inset. Since \LyX{} now does no printing itself, the shortcut \textsf{Ctrl+P} |
| 6760 |
that was formerly used for printing is available for other purposes. |
| 6761 |
On my keyboard, the \textsf{P} key lies diagonally up and to the right |
| 6762 |
but adjacent to the \textsf{L} key. I suggest assigning \textsf{Ctrl+P} |
| 6763 |
to inserting a preview inset. Then typing \textsf{Ctrl+P Ctrl+L} – |
| 6764 |
which means holding the \textsf{Ctrl} key down and tapping two diagonally |
| 6765 |
adjacent keys, \textsf{P} followed immediately by \textsf{L} – will |
| 6766 |
insert an ERT inset inside a preview inset with the cursor sitting |
| 6767 |
inside the ERT inset waiting for input. In the ERT inset you can enter |
| 6768 |
carriage returns, and so format complicated expressions. You can place |
| 6769 |
the vv-list on a separate line or onto consecutive lines. And when |
| 6770 |
you have finished, clicking outside the preview inset will trigger |
| 6771 |
preview into doing its thing and present the result `before your |
| 6772 |
eyes'. |
| 6773 |
|
| 6774 |
To assign the suggested shortcut, go to \textsf{Tools \lyxarrow{} Preferences |
| 6775 |
\lyxarrow{} Editing \lyxarrow{} Shortcuts}. Under \textsf{Cursor, Mouse |
| 6776 |
and Editing Functions} in the main window on the right, scroll down |
| 6777 |
until you come to \textsf{preview-insert}, select it, then click \textsf{Modify}. |
| 6778 |
Now press \textsf{Ctrl+P}. The shortcut will magically appear in the |
| 6779 |
greyed, depressed key.\textsf{ }Click \textsf{OK} and then \textsf{OK} |
| 6780 |
in the \textsf{Preferences} window to close it. (Most of the examples |
| 6781 |
in this document have been evaluated in this way, using \textsf{Ctrl+P |
| 6782 |
Ctrl+L.)} |
| 6783 |
|
| 6784 |
\subsubsection{Errors } |
| 6785 |
|
| 6786 |
Instant preview will display error messages generated by \texttt{numerica} |
| 6787 |
in \LyX{} just as it does the results of calculations. Clicking on |
| 6788 |
the message will show the underlying expression which can then be |
| 6789 |
edited. However \LaTeX{} errors will \emph{not} produce a preview; |
| 6790 |
formation of the preview will stall. To find precisely what has gone |
| 6791 |
wrong, you will need to look at the \LaTeX{} log, but not the log of |
| 6792 |
the overall document; rather the \emph{preview} log. |
| 6793 |
|
| 6794 |
\paragraph{Temporary directory of \protect\LyX} |
| 6795 |
|
| 6796 |
Unfortunately this is tucked away in a temporary directory and is |
| 6797 |
not immediately accessible in \LyX{} (unlike the main \LaTeX{} log from |
| 6798 |
\textsf{Document \lyxarrow{} \LaTeX{} Log}). When \LyX{} is started, |
| 6799 |
it sets up a temporary directory in which to perform various tasks. |
| 6800 |
On Windows systems this will be located in \texttt{C:\textbackslash Users\textbackslash <your |
| 6801 |
name>\textbackslash AppData\textbackslash Local\textbackslash Temp} |
| 6802 |
and will have a name like \texttt{lyx\_tmpdir.XOsSGhBc1344}. |
| 6803 |
|
| 6804 |
One of the tasks \LyX{} uses this temporary directory for is to create |
| 6805 |
preview images when a document is opened. If you look inside \LyX 's |
| 6806 |
temporary directory when a document is first loaded, you will see |
| 6807 |
a subdirectory created, with a name like \texttt{lyx\_tmpbuf0}. There |
| 6808 |
may already be such directories there, in which case the number on |
| 6809 |
the end will be greater than \texttt{0} – it depends on whether other |
| 6810 |
documents are or have been open in the current instance of \LyX . |
| 6811 |
Inside the appropriate \texttt{lyx\_tmpbuf}\texttt{\emph{n}} folder |
| 6812 |
will be the preview log with a name like \texttt{lyxpreviewZL1344.log}. |
| 6813 |
It will usually be accompanied by other files with extensions like |
| 6814 |
\texttt{.dvi}, \texttt{.tex}, and – depending on the number of previews |
| 6815 |
in your document – a number, perhaps a lot, of image files with the |
| 6816 |
extension \texttt{.png}, each one of which is a preview. For a document |
| 6817 |
just loaded there will be only the one preview log, but if you have |
| 6818 |
added preview insets or math insets to your document\textsf{ }in the |
| 6819 |
current editing session there will be a number of such logs and you |
| 6820 |
will need to determine the relevant one by the time stamp. |
| 6821 |
|
| 6822 |
The log files are text files and can be opened in a text editor. The |
| 6823 |
relevant part of the log is towards the end (just before the final |
| 6824 |
statistical summary) where you will find a list of entries like \texttt{Preview: Snippet |
| 6825 |
1 641947 163840 7864588}. If there is an error, it will be noted here |
| 6826 |
among these snippets and will generally make clear what needs remedying. |
| 6827 |
|
| 6828 |
\paragraph{CPU usage, \protect\LaTeX{} processes} |
| 6829 |
|
| 6830 |
It is possible when a preview stalls that the \LaTeX{} process associated |
| 6831 |
with the preview will continue to run, using CPU cycles, slowing overall |
| 6832 |
computer performance, and perhaps resulting in extra fan use giving |
| 6833 |
a different sound to the computer. In Windows 10, the \textsf{Task |
| 6834 |
Manager} (\textsf{Ctrl+Shift+esc}) under the \textsf{Details} tab |
| 6835 |
shows the current executables running. The \textsf{CPU} column will |
| 6836 |
show which processes are preoccupying the CPU. Check whether one or |
| 6837 |
more of these processes looks \LaTeX -related (e.g.\ \texttt{latex.exe} |
| 6838 |
or \texttt{pdflatex.exe}, or \texttt{miktex-pdftex.exe} if using MiK\TeX ). |
| 6839 |
Click the \textsf{Name} column to sort the processes by name and look |
| 6840 |
for the relevant name in the list, select it, and end the process |
| 6841 |
(click the \textsf{End Task} button). |
| 6842 |
|
| 6843 |
I am not familiar with the corresponding situation on Linux or Mac. |
| 6844 |
|
| 6845 |
\subsubsection{Hyperref support vs speed} |
| 6846 |
|
| 6847 |
If you want the \texttt{pdf} produced from your document to support |
| 6848 |
hyperref links and show an outline window in your \texttt{pdf} viewer |
| 6849 |
(generally placed on the left in the viewer) then you need to ensure |
| 6850 |
the checkbox at \textsf{Document Settings \lyxarrow{} PDF Properties |
| 6851 |
\lyxarrow{} Use Hyperref Support} is indeed checked. But you don't |
| 6852 |
need to do this until the final compilation of the document. The advantage |
| 6853 |
of leaving this until the last is that in a large document with many |
| 6854 |
previews the time for preview generation is essentially halved. If |
| 6855 |
hyperref support is enabled, preview generation not only creates all |
| 6856 |
the individual image files that are the previews (files of extension |
| 6857 |
\verb`.png`) but also requires the compilation of a single \texttt{pdf} |
| 6858 |
document showing all the previews in sequence. (Like the previews, |
| 6859 |
the \texttt{pdf} document `hides' in the termporary directory where |
| 6860 |
\LyX{} does its work.) In other words, \emph{two} images are created |
| 6861 |
for each preview, the \verb`.png` image which is the one \LyX{} displays, |
| 6862 |
and another image buried inside the \texttt{pdf} of all images. That |
| 6863 |
second step does not occur if hyperref support is disabled. In a small |
| 6864 |
document, this is not going to matter; in a large document it becomes |
| 6865 |
significant. It is well worth temporarily turning off hyperref support |
| 6866 |
and then, when the time for final compilation comes, turning it back |
| 6867 |
on. |
| 6868 |
|
| 6869 |
\subsection{Supplementary commands in \protect\LyX} |
| 6870 |
|
| 6871 |
There are some difficulties using the supplementary commands successfully |
| 6872 |
with instant preview. |
| 6873 |
|
| 6874 |
\subsubsection{Reuse of earlier previews} |
| 6875 |
|
| 6876 |
One is that whenever \LyX{} has generated a preview image for a particular |
| 6877 |
\LaTeX{} expression, it will use that same image whenever it meets |
| 6878 |
that same \LaTeX{} expression later. That means that a statement like |
| 6879 |
\verb`\macros[view]{}` and the same statement later will display |
| 6880 |
the same image, even though there may have been macros defined or |
| 6881 |
freed in between. The same goes for all the other supplementary functions, |
| 6882 |
including, for example, \verb`\info{sum}`. A second instance of \verb`\info{sum}` |
| 6883 |
will display the image generated by the first instance even though |
| 6884 |
further infinite sums may have been evaluated between the \verb`\info` |
| 6885 |
statements. |
| 6886 |
|
| 6887 |
The remedy is to make some small but insignificant difference to the |
| 6888 |
\LaTeX{} expression in the second instance – generally a change in |
| 6889 |
white space will do. For example: first time \verb`\macros[view]{}`, |
| 6890 |
second time \verb`\macros[view]{ }` where a space has been inserted |
| 6891 |
between the braces; or: first time \verb`\info{sum}`, second time |
| 6892 |
\verb`\info{ sum}` where a space has been inserted before \verb`sum`. |
| 6893 |
This will ensure \LyX{} doesn't fall back on the previously generated |
| 6894 |
image. |
| 6895 |
|
| 6896 |
\subsubsection{\textquoteleft Stalled\textquoteright{} previews} |
| 6897 |
|
| 6898 |
It is possible to put content into an ERT inset inside a preview inset |
| 6899 |
(\textsf{Ctrl+P Ctrl+L}) and for nothing to happen. The preview has |
| 6900 |
apparently stalled. Certainly this can be the case if there is an |
| 6901 |
error in the input (e.g.\ a missing brace) but it also occurs if |
| 6902 |
there is no output to display. For instance \verb`\constants` \verb`{ c=300000000 }` |
| 6903 |
does not produce any visual output. There is nothing for the preview |
| 6904 |
to display and so the preview inset sits there, apparently stalled. |
| 6905 |
This is a security measure for previews in \LyX{} to provide at least |
| 6906 |
some guard against malicious code being run in the preview. If the |
| 6907 |
preview resolved, it would disappear completely from view in the \LyX{} |
| 6908 |
window. |
| 6909 |
|
| 6910 |
If you find the visual appearance of such apparently stalled previews |
| 6911 |
distracting, the addition of some displayable content to the preview |
| 6912 |
will result in it resolving to that content; the content could be |
| 6913 |
as small as a full stop. |
| 6914 |
|
| 6915 |
\subsubsection{Using \texttt{\textbackslash nmcMacros}} |
| 6916 |
|
| 6917 |
As noted earlier, previews are mini-\LaTeX{} runs, either local or |
| 6918 |
global. Each local preview is of the form<preamble> |
| 6919 |
\begin{verbatim} |
| 6920 |
<preamble> |
| 6921 |
\begin{document} |
| 6922 |
\begin{preview} |
| 6923 |
<stuff> |
| 6924 |
\end{preview} |
| 6925 |
\end{document} |
| 6926 |
\end{verbatim} |
| 6927 |
Whatever goes into or comes out of the preview is isolated from any |
| 6928 |
other local preview, unless it is through the preamble or an external |
| 6929 |
file. Sometimes a global preview run can overcome this problem for |
| 6930 |
then all the previews lie between the same \verb`\begin{document}`, |
| 6931 |
\verb`end{document}` statements. However, this does not help with |
| 6932 |
macro definitions. \verb`\def`, \verb`\newcommand`, \verb`\NewDocumentCommand` |
| 6933 |
all provide \emph{local} definitions which remain trapped within their |
| 6934 |
own \verb`\begin{preview}`, \verb`\end{preview}`) statements. Another |
| 6935 |
preview, say containing an \verb`\eval` command, between a different |
| 6936 |
pair of \verb`\begin{preview}`, \verb`\end{preview}`) statements, |
| 6937 |
will not know about the macro definition. |
| 6938 |
|
| 6939 |
There are (at least) three ways out: |
| 6940 |
\begin{enumerate} |
| 6941 |
\item Confine everything to the same preview inset: the definition of a |
| 6942 |
macro, the \verb`\macros` statement, and the use of the macro in |
| 6943 |
an \verb`\eval` command. |
| 6944 |
\item Confine macro definitions to the preamble (\textsf{Document \lyxarrow{} |
| 6945 |
Settings \lyxarrow{} \LaTeX{} Preamble}). |
| 6946 |
\item Within previews use \verb`\gdef` (or \verb`\global\def`) exclusively |
| 6947 |
for making your macro definitions; this makes the macro available |
| 6948 |
to all later previews. |
| 6949 |
\end{enumerate} |
| 6950 |
|
| 6951 |
\subsubsection{Using \texttt{\textbackslash nmcConstants}} |
| 6952 |
|
| 6953 |
Because \verb`\nmcConstants` doesn't use \verb`\def` or \verb`\newcommand` |
| 6954 |
or \verb`\NewDocumentCommand` it is not subject to the same localisation |
| 6955 |
problem as \verb`\nmcMacros`, but the reach of a \verb`\constants` |
| 6956 |
command will still be confined to its own preview unless a \emph{global} |
| 6957 |
preview run is forced; see above §\ref{subsec:miscLyXGlobal-vs-local}. |
| 6958 |
|
| 6959 |
\subsubsection{Using \texttt{\textbackslash nmcReuse}} |
| 6960 |
|
| 6961 |
As noted earlier, \LyX{} creates its previews in a temporary directory, |
| 6962 |
not the document directory. If you want to save values from your current |
| 6963 |
document – say, \texttt{mydoc.lyx} – to \texttt{mydoc.nmc} then you |
| 6964 |
do so as described earlier (§\ref{sec:supplReuse}), but the file |
| 6965 |
\texttt{mydoc.nmc} containing the saved results will be located in |
| 6966 |
the temporary directory. When \LyX{} is closed the file will be deleted |
| 6967 |
along with all the other contents of that directory. |
| 6968 |
|
| 6969 |
Fortunately \LyX{} has a copying mechanism for getting files out of |
| 6970 |
the temporary directory and into the document directory. When a document |
| 6971 |
is exported – say to \texttt{pdf} – it is possible to specify a \emph{copier} |
| 6972 |
to automatically copy back to the document directory or subdirectory |
| 6973 |
various files in the temporary directory. We want the \texttt{.nmc} |
| 6974 |
file containing the saved values to be copied back. Go to \textsf{Tools |
| 6975 |
\lyxarrow{} Preferences \lyxarrow{} File Handling \lyxarrow{} File Formats} |
| 6976 |
and find \textsf{PDF (pdflatex)} (assuming export to \texttt{pdf} |
| 6977 |
by this route) in the list of formats. In\textsf{ }the \textsf{Copier} |
| 6978 |
slot of the dialogue insert the following line of code: |
| 6979 |
\begin{verbatim} |
| 6980 |
python -tt $$s/scripts/ext_copy.py -e nmc,pdf -d $$i $$o |
| 6981 |
\end{verbatim} |
| 6982 |
\verb`ext_copy.py` is a python script that is supplied with \LyX . |
| 6983 |
The \texttt{-e nmc,pdf -d} part of the line tells \texttt{ext\_copy.py} |
| 6984 |
that on export to \texttt{pdf} by the \texttt{pdflatex} route\texttt{ |
| 6985 |
}to copy any files with the extensions \texttt{.nmc} or \texttt{.pdf} |
| 6986 |
from the temporary directory where \LyX{} does its work back to the |
| 6987 |
document directory – the \verb`-d` option (which became available |
| 6988 |
with \LyX{} 2.3.0). |
| 6989 |
|
| 6990 |
But if you have a complex document, it may take too much time to want |
| 6991 |
to export to pdf before closing \LyX , particularly if there are a |
| 6992 |
lot of evaluations in the document. Much faster is to export to \emph{plain |
| 6993 |
text}, not because you want a plain text version of your document |
| 6994 |
but because it too can be used to trigger the copier mechanism. Go |
| 6995 |
to \textsf{Tools \lyxarrow{} Preferences \lyxarrow{} File Handling \lyxarrow{} |
| 6996 |
File Formats} and find \textsf{Plain text} in the list of formats. |
| 6997 |
In the \textsf{Copier} slot enter |
| 6998 |
\begin{verbatim} |
| 6999 |
python -tt $$s/scripts/ext_copy.py -e nmc -d $$i $$o |
| 7000 |
\end{verbatim} |
| 7001 |
The only difference from the previous copier command is the absence |
| 7002 |
of \texttt{pdf}.\footnote{I'm assuming that you don't actually want the plain text version of |
| 7003 |
the file copied back. If you do, then change \texttt{-e nmc} to \texttt{-e |
| 7004 |
nmc,txt}.} This will copy \texttt{mydoc.nmc} with its saved values from the |
| 7005 |
temporary directory back to the document directory. To effect the |
| 7006 |
export, go to \textsf{File \lyxarrow{} Export }and find \textsf{Plain |
| 7007 |
text} in the list of formats and click on it. |
| 7008 |
|
| 7009 |
A shortcut would be nice. For that go to \textsf{Tools \lyxarrow{} |
| 7010 |
Preferences \lyxarrow{} Editing \lyxarrow{} Shortcuts}, click on \textsf{New}, |
| 7011 |
enter \texttt{buffer-export text} in the \textsf{Function:} slot, |
| 7012 |
click on the blank key against \textsf{Shortcut:} and type your shortcut. |
| 7013 |
You may have to try a number before you find one that hasn't already |
| 7014 |
been assigned. (I'm using \textsf{Ctrl+}; for no particular reason |
| 7015 |
beyond the fact that it fits under the fingers easily and saving values |
| 7016 |
to the document directory has a punctuation-like feel to it, a pause |
| 7017 |
in the process of writing.) It is now an easy matter to press the |
| 7018 |
shortcut at the end of a \LyX{} session to copy all the values saved |
| 7019 |
in \texttt{mydoc.nmc} back to a file of the same name in the document |
| 7020 |
directory. And it is brisk, not least because plain text export ignores |
| 7021 |
ERT insets (and hence preview insets wrapped around ERT insets), nor |
| 7022 |
does it evaluate \verb`\eval` commands in math insets. |
| 7023 |
|
| 7024 |
\subsubsection{A final tweak?} |
| 7025 |
|
| 7026 |
But one still needs to \emph{remember} to press the shortcut. The |
| 7027 |
thought arises: can \emph{closing} the current document trigger the |
| 7028 |
copying process? \LyX{} provides a means of linking two commands and |
| 7029 |
assigning a keyboard shortcut to them with its \texttt{command-sequence} |
| 7030 |
\LyX{} function. I suggest assigning a shortcut\textsf{ }to |
| 7031 |
\begin{verbatim} |
| 7032 |
command-sequence buffer-export text; view-close |
| 7033 |
\end{verbatim} |
| 7034 |
Indeed, why not reassign the current shortcut for \texttt{view-close},\texttt{ |
| 7035 |
}which is \textsf{Ctrl+W} on my system, to this command sequence? |
| 7036 |
(I use the \texttt{cua} key bindings – check the \textsf{Bind file:} |
| 7037 |
slot in \textsf{Tools \lyxarrow{} Preferences \lyxarrow{} Editing \lyxarrow{} |
| 7038 |
Shortcuts}.) |
| 7039 |
|
| 7040 |
Please note, however, that \emph{this will work as intended only from |
| 7041 |
\LyX{} 2.4.0}.\footnote{Long-planned and initially due for release in 2021 but still (August |
| 7042 |
2023) not released. But a beta3 version is now available from \url{https://ftp.lip6.fr/pub/lyx/devel/lyx-2.4/}} For \LyX{} 2.3 and earlier, the command sequence will generally fail |
| 7043 |
because of `asynchronous' processing – \texttt{buffer-export }and |
| 7044 |
\texttt{view-close} use different threads and the latter may well |
| 7045 |
start before the former is complete. From \LyX{} 2.4.0 this defect |
| 7046 |
has been fixed. You press your shortcut, the export to plain text |
| 7047 |
occurs and the \texttt{.nmc} file is copied back to the document directory, |
| 7048 |
then the current view is closed. |
| 7049 |
|
| 7050 |
Note that in the other direction, the \verb`.nmc` file in your document |
| 7051 |
directory is \emph{automatically} copied to the temporary directory |
| 7052 |
when needed. Nothing needs to be done by you, the user. |
| 7053 |
|
| 7054 |
\subsection{Use of \protect\LyX{} notes} |
| 7055 |
|
| 7056 |
The central fact about a \LyX{} note is that it does not contribute |
| 7057 |
to the pdf. But instant preview still works there. This suggests a |
| 7058 |
possibility: that a calculation be performed within a \LyX{} note and |
| 7059 |
the result saved using \verb`\nmcReuse` within the same note. The |
| 7060 |
saved value is now available \emph{from file} for use elsewhere in |
| 7061 |
the document. In this way, some selected content from a LyX note \emph{can} |
| 7062 |
find its way into the pdf when the document is compiled. |
| 7063 |
|
| 7064 |
\chapter{Reference summary} |
| 7065 |
|
| 7066 |
\section{Package options} |
| 7067 |
\begin{itemize} |
| 7068 |
\item \verb`comma` sets the comma as the decimal point; items in the variable=value |
| 7069 |
list must then be separated by semicolons; arguments in $n$-ary functions |
| 7070 |
must also be separated by semicolons; by default formulas in a multi-formula |
| 7071 |
calculation should also be separated by a semicolon; |
| 7072 |
\item \verb`rounding`=$n$ sets the default rounding value to the integer |
| 7073 |
$n$; |
| 7074 |
\item \verb`approx` replaces the default \verb`=` between formula and |
| 7075 |
result in (some) displays with \verb`\approx` (displaying as $\approx$; |
| 7076 |
the \verb`eq=<char(s)>` setting is still available to change the |
| 7077 |
symbol for individual calculations). |
| 7078 |
\end{itemize} |
| 7079 |
|
| 7080 |
\section{Commands defined in \texttt{numerica}} |
| 7081 |
\begin{enumerate} |
| 7082 |
\item \texttt{\textbackslash nmcEvaluate, \textbackslash eval } |
| 7083 |
\item \texttt{\textbackslash q, \textbackslash Q }(`cleave' commands) |
| 7084 |
\item \texttt{\textbackslash nmcInfo, \textbackslash info} |
| 7085 |
\item \texttt{\textbackslash nmcMacros, \textbackslash macros} |
| 7086 |
\item \texttt{\textbackslash nmcConstants, \textbackslash constants} |
| 7087 |
\item \texttt{\textbackslash nmcReuse, \textbackslash reuse} |
| 7088 |
\end{enumerate} |
| 7089 |
Provided they have not already been defined when \texttt{numerica} |
| 7090 |
is loaded, the following commands are defined in \texttt{numerica} |
| 7091 |
using \verb`\DeclareMathOperator` from \texttt{amsmath}: |
| 7092 |
\begin{enumerate} |
| 7093 |
\item \texttt{\textbackslash arccsc, \textbackslash arcsec, \textbackslash arccot} |
| 7094 |
\item \texttt{\textbackslash csch, \textbackslash sech} |
| 7095 |
\item \texttt{\textbackslash asinh, \textbackslash acosh, \textbackslash atanh, |
| 7096 |
\textbackslash acsch, \textbackslash asech, \textbackslash acoth} |
| 7097 |
\item \texttt{\textbackslash arsinh, \textbackslash arcosh, \textbackslash artanh, |
| 7098 |
\textbackslash arcsch, \textbackslash arsech, \textbackslash arcoth} |
| 7099 |
\item \texttt{\textbackslash arcsinh, \textbackslash arccosh, \textbackslash arctanh, |
| 7100 |
\textbackslash arccsch, \textbackslash arcsech, \textbackslash arccoth} |
| 7101 |
\item \texttt{\textbackslash sgn, \textbackslash lb} |
| 7102 |
\end{enumerate} |
| 7103 |
Provided they have not already been defined, the following commands |
| 7104 |
are defined in \texttt{numerica} using \verb`\DeclarePairedDelimiter` |
| 7105 |
from \texttt{mathtools}: |
| 7106 |
\begin{verbatim} |
| 7107 |
\abs, \ceil, \floor |
| 7108 |
\end{verbatim} |
| 7109 |
Provided they have not already been defined, the following commands |
| 7110 |
are defined in \texttt{numerica} using \texttt{\textbackslash ProvideDocumentCommand} |
| 7111 |
\begin{verbatim} |
| 7112 |
\comma, \equals, \degree |
| 7113 |
\end{verbatim} |
| 7114 |
The following commands have been redefined in \texttt{numerica} to |
| 7115 |
give more spacing around the underlying \verb`\wedge` and \verb`\vee` |
| 7116 |
symbols: |
| 7117 |
\begin{verbatim} |
| 7118 |
\land, \lor |
| 7119 |
\end{verbatim} |
| 7120 |
|
| 7121 |
\section{\textquoteleft Digestible\textquoteright{} content} |
| 7122 |
|
| 7123 |
\texttt{numerica} knows how to deal with the following content, meaning |
| 7124 |
that any of these elements occurring within an \verb`\eval` command |
| 7125 |
should not of itself cause a \texttt{numerica} error. Not all formatting |
| 7126 |
commands affect display of the output. |
| 7127 |
\begin{enumerate} |
| 7128 |
\item variable names (sequences of tokens given values in the variable=value |
| 7129 |
list) |
| 7130 |
\item digits, decimal point |
| 7131 |
\begin{enumerate} |
| 7132 |
\item \texttt{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, . }or \texttt{,} (if \texttt{comma} |
| 7133 |
package option used) |
| 7134 |
\end{enumerate} |
| 7135 |
\item constants |
| 7136 |
\begin{enumerate} |
| 7137 |
\item \texttt{e, \textbackslash pi, \textbackslash gamma, \textbackslash phi, |
| 7138 |
\textbackslash deg, \textbackslash infty} |
| 7139 |
\end{enumerate} |
| 7140 |
\item arithmetic operators |
| 7141 |
\begin{enumerate} |
| 7142 |
\item \texttt{+, -, {*}, /, \textasciicircum , \textbackslash times, \textbackslash cdot, |
| 7143 |
\textbackslash div} |
| 7144 |
\end{enumerate} |
| 7145 |
\item logical operators |
| 7146 |
\begin{enumerate} |
| 7147 |
\item \texttt{\textbackslash wedge, \textbackslash land, \textbackslash vee, |
| 7148 |
\textbackslash lor, \textbackslash neg, \textbackslash lnot} |
| 7149 |
\end{enumerate} |
| 7150 |
\item degree symbol/switch |
| 7151 |
\begin{enumerate} |
| 7152 |
\item \texttt{\textbackslash degree} (possibly from package \texttt{gensymb}) |
| 7153 |
\end{enumerate} |
| 7154 |
\item comparisons |
| 7155 |
\begin{enumerate} |
| 7156 |
\item \texttt{=, <, >, \textbackslash ne, \textbackslash neq, \textbackslash le, |
| 7157 |
\textbackslash leq, \textbackslash ge, \textbackslash geq} |
| 7158 |
\item (if \texttt{amssymb} loaded) \texttt{\textbackslash nless, \textbackslash ngtr, |
| 7159 |
\textbackslash geqq, \textbackslash geqslant, \textbackslash leqq, |
| 7160 |
\textbackslash leqslant, \textbackslash ngeq, \textbackslash ngeqq, |
| 7161 |
\textbackslash ngeqslant, \textbackslash nleq, \textbackslash nleqq, |
| 7162 |
\textbackslash nleqslant} |
| 7163 |
\end{enumerate} |
| 7164 |
\item brackets, bracket-like elements, modifiers |
| 7165 |
\begin{enumerate} |
| 7166 |
\item \texttt{( ), {[} {]}, \textbackslash\{ \textbackslash\}; \textbackslash lparen |
| 7167 |
\textbackslash rparen} (from \texttt{mathtools})\texttt{; \textbackslash lbrack |
| 7168 |
\textbackslash rbrack, \textbackslash lbrace \textbackslash rbrace} |
| 7169 |
\item \texttt{\textbackslash lvert \textbackslash rvert, \textbackslash lfloor |
| 7170 |
\textbackslash rfloor, \textbackslash lceil \textbackslash rceil} |
| 7171 |
\item \texttt{| |} (cannot be nested, deprecated) |
| 7172 |
\item \texttt{\textbackslash left \textbackslash right;} \texttt{\textbackslash mleft |
| 7173 |
\textbackslash mright, \textbackslash mleftright, \textbackslash mleftrightrestore} |
| 7174 |
(if \texttt{mleftright} loaded) |
| 7175 |
\item \texttt{\textbackslash bigl \textbackslash bigr, \textbackslash Bigl |
| 7176 |
\textbackslash Bigr, \textbackslash biggl \textbackslash biggr, |
| 7177 |
\textbackslash Biggl \textbackslash Biggr} |
| 7178 |
\item \texttt{\textbackslash middle }(if \texttt{mleftright} loaded)\texttt{;\textbackslash big, |
| 7179 |
\textbackslash Big, \textbackslash bigg, \textbackslash Bigg} |
| 7180 |
\item \texttt{.} \texttt{/ |} (used with a modifier) |
| 7181 |
\item \texttt{\textbackslash abs{[}{]}\{\}, \textbackslash abs{*}\{\}, |
| 7182 |
\textbackslash floor{[}{]}\{\}, \textbackslash floor{*}\{\}, \textbackslash ceil{[}{]}\{\}, |
| 7183 |
\textbackslash ceil{*}\{\}} |
| 7184 |
\end{enumerate} |
| 7185 |
\item unary functions (in the mathematical sense) |
| 7186 |
\begin{enumerate} |
| 7187 |
\item \texttt{\textbackslash sin, \textbackslash cos, \textbackslash tan, |
| 7188 |
\textbackslash csc, \textbackslash sec, \textbackslash cot} |
| 7189 |
\item \texttt{\textbackslash arcsin, \textbackslash arccos, \textbackslash arctan, |
| 7190 |
arccsc, \textbackslash arcsec, \textbackslash arccot } |
| 7191 |
\item \texttt{\textbackslash sin\textasciicircum\{-1\}, \textbackslash cos\textasciicircum\{-1\}, |
| 7192 |
\textbackslash tan\textasciicircum\{-1\}, \textbackslash csc\textasciicircum\{-1\}, |
| 7193 |
\textbackslash sec\textasciicircum\{-1\}, \textbackslash cot\textasciicircum\{-1\}} |
| 7194 |
\item \texttt{\textbackslash sinh, \textbackslash cosh, \textbackslash tanh, |
| 7195 |
\textbackslash csch, \textbackslash sech, \textbackslash coth } |
| 7196 |
\item \texttt{\textbackslash asinh, \textbackslash acosh, \textbackslash atanh, |
| 7197 |
\textbackslash acsch, \textbackslash asech, \textbackslash acoth, |
| 7198 |
\textbackslash arsinh, \textbackslash arcosh, \textbackslash artanh, |
| 7199 |
\textbackslash arcsch, \textbackslash arsech, \textbackslash arcoth, |
| 7200 |
\textbackslash arcsinh, \textbackslash arccosh, \textbackslash arctanh, |
| 7201 |
\textbackslash arccsch, \textbackslash arcsech, \textbackslash arccoth} |
| 7202 |
\item \texttt{\textbackslash sinh\textasciicircum\{-1\}, \textbackslash cosh\textasciicircum\{-1\}, |
| 7203 |
\textbackslash tanh\textasciicircum\{-1\}, \textbackslash csch\textasciicircum\{-1\}, |
| 7204 |
\textbackslash sech\textasciicircum\{-1\}, \textbackslash coth\textasciicircum\{-1\}} |
| 7205 |
\item \texttt{\textbackslash exp, \textbackslash lb, \textbackslash lg, |
| 7206 |
\textbackslash ln, \textbackslash log, \textbackslash log\_\{\}, |
| 7207 |
\textbackslash sgn, \textbackslash surd} |
| 7208 |
\item \texttt{\textbackslash sqrt\{\}, \textbackslash abs{[}{]}\{\}, \textbackslash abs{*}\{\}, |
| 7209 |
\textbackslash floor{[}{]}\{\}, \textbackslash floor{*}\{\}, \textbackslash ceil{[}{]}\{\}, |
| 7210 |
\textbackslash ceil{*}\{\}} |
| 7211 |
\item \texttt{!, !! }(both with a prepended argument) |
| 7212 |
\end{enumerate} |
| 7213 |
\item binary functions |
| 7214 |
\begin{enumerate} |
| 7215 |
\item \texttt{\textbackslash tfrac\{\}\{\}, \textbackslash frac\{\}\{\}, |
| 7216 |
\textbackslash dfrac\{\}\{\}, \textbackslash sfrac }(if \texttt{xfrac} |
| 7217 |
loaded) |
| 7218 |
\item \texttt{\textbackslash tbinom\{\}\{\}, \textbackslash binom\{\}\{\}, |
| 7219 |
\textbackslash dbinom\{\}\{\}} |
| 7220 |
\item \texttt{\textbackslash sqrt{[}{]}\{\}} |
| 7221 |
\end{enumerate} |
| 7222 |
\item $n$-ary functions |
| 7223 |
\begin{enumerate} |
| 7224 |
\item \texttt{\textbackslash min, \textbackslash max, \textbackslash gcd} |
| 7225 |
\end{enumerate} |
| 7226 |
\item sum, prod |
| 7227 |
\begin{enumerate} |
| 7228 |
\item \texttt{\textbackslash sum\_\{\}\{\}\textasciicircum\{\}, \textbackslash prod\_\{\}\{\}\textasciicircum\{\} } |
| 7229 |
\end{enumerate} |
| 7230 |
\item formatting commands |
| 7231 |
\begin{enumerate} |
| 7232 |
\item \texttt{,} (comma, in $n$-ary functions) |
| 7233 |
\item \texttt{\{\}, \textbackslash\textbackslash , \&, \textbackslash to} |
| 7234 |
\item \texttt{\textbackslash begin\{\}, \textbackslash end\{\}, \$, \textbackslash{[}, |
| 7235 |
\textbackslash{]}} |
| 7236 |
\item \texttt{\textbackslash dots, \textbackslash ldots, \textbackslash cdots} |
| 7237 |
\item \texttt{\textbackslash{} , \textbackslash , {}, \textbackslash ;, |
| 7238 |
\textbackslash :, \textbackslash !, \textbackslash >} |
| 7239 |
\item \texttt{\textbackslash thinspace, \textbackslash medspace, \textbackslash thickspace,} |
| 7240 |
\item \textbackslash\texttt{negthinspace, \textbackslash negmedspace, |
| 7241 |
\textbackslash negthickspace,} |
| 7242 |
\item \textbackslash\texttt{hspace{*}\{\}, \textbackslash mspace\{\},} |
| 7243 |
\item \texttt{\textbackslash quad, \textbackslash qquad , \textbackslash hfill, |
| 7244 |
\textbackslash hfil} |
| 7245 |
\item \texttt{\textbackslash phantom\{\}, \textbackslash vphantom\{\}, |
| 7246 |
\textbackslash hphantom\{\}} |
| 7247 |
\item \texttt{\textbackslash xmathstrut{[}{]}\{\}} \texttt{, \textbackslash splitfrac\{\}\{\}, |
| 7248 |
\textbackslash splitdfrac\{\}\{\} }(from \texttt{mathtools}), \texttt{\textbackslash mathstrut} |
| 7249 |
\item \texttt{\textbackslash displaystyle, \textbackslash textstyle, \textbackslash scriptstyle, |
| 7250 |
\textbackslash scriptscriptstyle} |
| 7251 |
\item \texttt{\textbackslash label\{\}, \textbackslash ensuremath\{\}, |
| 7252 |
\textbackslash text\{\}, \textbackslash mbox\{\}, \textbackslash smash\{\}} |
| 7253 |
\item \texttt{\textbackslash color{[}{]}\{\}, \textbackslash textcolor{[}{]}\{\}\{\}} |
| 7254 |
\item \texttt{\textbackslash mkern, \textbackslash mskip} |
| 7255 |
\end{enumerate} |
| 7256 |
\item font commands |
| 7257 |
\begin{enumerate} |
| 7258 |
\item \texttt{\textbackslash mathrm\{\}, \textbackslash mathit\{\}, \textbackslash mathcal\{\}, |
| 7259 |
\textbackslash mathtt\{\}, \textbackslash mathbf\{\}, \textbackslash mathbb\{\}, |
| 7260 |
\textbackslash mathsf\{\}, \textbackslash mathfrak\{\}, \textbackslash mathscr\{\}} |
| 7261 |
\item \texttt{\textbackslash mathnormal\{\}, \textbackslash boldsymbol\{\}} |
| 7262 |
\item \texttt{\textbackslash textrm\{\}, \textbackslash textsf\{\}, \textbackslash texttt\{\}, |
| 7263 |
\textbackslash textit\{\}, \textbackslash textsl\{\}, \textbackslash textbf\{\}, |
| 7264 |
\textbackslash textsc\{\}} |
| 7265 |
\end{enumerate} |
| 7266 |
\end{enumerate} |
| 7267 |
|
| 7268 |
\section{Settings} |
| 7269 |
|
| 7270 |
\subsection{Functional settings} |
| 7271 |
\begin{center} |
| 7272 |
\begin{center} |
| 7273 |
\begin{tabular}{>{\raggedright}p{1.5cm}>{\raggedright}p{1.5cm}>{\raggedright}p{3cm}>{\raggedright}p{1.5cm}>{\raggedright}p{1.5cm}} |
| 7274 |
\toprule |
| 7275 |
{\small key} & {\small type} & {\small meaning} & {\small default} & {\small initial}\tabularnewline |
| 7276 |
\midrule |
| 7277 |
{\small\texttt{dbg}} & {\small int} & {\small debug data} & & {\small\texttt{0}}\tabularnewline |
| 7278 |
{\small\texttt{view}} & & {\small\texttt{dbg=1}} & {\small\texttt{dbg=1}} & \tabularnewline |
| 7279 |
{\small\texttt{\textasciicircum}} & {\small char} & {\small exp. mark for sci. notation input} & {\small\texttt{e}} & \tabularnewline |
| 7280 |
{\small\texttt{xx}} & {\small int (0/1)} & {\small accept multi-token variables} & & {\small\texttt{1}}\tabularnewline |
| 7281 |
\multirow{2}{1.5cm}{\texttt{ff}} & \multirow{2}{1.5cm}{{\small char}} & \multirow{2}{3cm}{{\small main arg. multi- formula delimiter}} & \multicolumn{2}{l}{{\small\texttt{, }}{\small (if decimal dot)}}\tabularnewline |
| 7282 |
& & & \multicolumn{2}{l}{{\small\texttt{; }}{\small (if decimal comma)}}\tabularnewline |
| 7283 |
{\small\texttt{1s2}} & {\small int (0/1)} & {\small allow spaced digit groups in numbers} & {\small\texttt{1}} & {\small\texttt{0}}\tabularnewline |
| 7284 |
{\small\texttt{/min}} & {\small$\text{int}\ge1$} & {\small fraction form denom- inator search start} & & {\small\texttt{1}}\tabularnewline |
| 7285 |
{\small\texttt{/max}} & {\small$\text{int}\ge1$} & {\small fraction form denom- inator search end} & & {\small\texttt{200}}\tabularnewline |
| 7286 |
{\small\texttt{vv@}} & \multirow{3}{1.5cm}{{\small int (0/1)}} & \multirow{3}{3cm}{{\small vv-list calculation mode}} & \multirow{3}{1.5cm}{} & \multirow{3}{1.5cm}{{\small\texttt{0}}}\tabularnewline |
| 7287 |
\multirow{2}{1.5cm}{{\small\texttt{vvmode}}} & & & & \tabularnewline |
| 7288 |
& & & & \tabularnewline |
| 7289 |
{\small\texttt{o}} & {\small int (0/1)} & {\small trig. function args in degrees} & {\small\texttt{1}} & {\small\texttt{0}}\tabularnewline |
| 7290 |
{\small\texttt{log}} & {\small num} & {\small base of logs for }{\small{\small\verb`\log`}} & & {\small\texttt{10}}\tabularnewline |
| 7291 |
{\small\texttt{S+}} & {\small int} & {\small extra rounding, sums} & & {\small\texttt{2}}\tabularnewline |
| 7292 |
{\small\texttt{S?}} & {\small$\text{int}\ge0$} & {\small number of query terms, sums} & & {\small\texttt{0}}\tabularnewline |
| 7293 |
{\small\texttt{P+}} & {\small int} & {\small extra rounding, products} & & {\small\texttt{2}}\tabularnewline |
| 7294 |
{\small\texttt{P?}} & {\small$\text{int}\ge0$} & {\small number of query terms, products} & & {\small\texttt{0}}\tabularnewline |
| 7295 |
\midrule |
| 7296 |
{\small\texttt{()}} & \multicolumn{4}{l}{{\small obsolete; see §\ref{sec:settinsDeprecatedObsoleteOptions}}}\tabularnewline |
| 7297 |
{\small\texttt{reuse}} & \multicolumn{4}{l}{{\small obsolete; see §\ref{sec:settinsDeprecatedObsoleteOptions}}}\tabularnewline |
| 7298 |
{\small\texttt{{*}}} & \multicolumn{4}{l}{{\small obsolete; see §\ref{sec:settinsDeprecatedObsoleteOptions}}}\tabularnewline |
| 7299 |
\bottomrule |
| 7300 |
\end{tabular} |
| 7301 |
\par\end{center} |
| 7302 |
\par\end{center} |
| 7303 |
|
| 7304 |
\subsubsection{Debug settings} |
| 7305 |
\begin{itemize} |
| 7306 |
\item \verb`dbg=0`\texttt{ }turns off the debug function, displays the |
| 7307 |
result or error message (this is the initial value); |
| 7308 |
\item \verb`dbg=1`\texttt{ }equivalent to \verb`dbg=2*3*5*7*11` for \verb`\eval`; |
| 7309 |
\item \verb`dbg=2` displays the formula after multi-token variables have |
| 7310 |
been converted to their single token form, \verb`\nmc_a`, \verb`\nmc_b`, |
| 7311 |
etc.; |
| 7312 |
\item \verb`dbg=3` displays the vv-list after multi-token variables have |
| 7313 |
been converted to their single token form; |
| 7314 |
\item \verb`dbg=5` displays the stored variables and their values \emph{after} |
| 7315 |
evaluation (\verb`dbg=3` lists the values as expressions); |
| 7316 |
\item \verb`dbg=7` displays the formula after it has been fp-ified but |
| 7317 |
before it has been fed to \texttt{l3fp} to evaluate; |
| 7318 |
\item \verb`dbg=11` displays the \LaTeX{} form of the final display; it |
| 7319 |
will contain, \emph{inter alia}, the numerical result. |
| 7320 |
\end{itemize} |
| 7321 |
|
| 7322 |
\subsection{Display settings} |
| 7323 |
|
| 7324 |
\begin{tabular}{>{\raggedright}p{1cm}>{\raggedright}p{1.5cm}>{\raggedright}p{3.5cm}>{\centering}p{1.5cm}>{\centering}p{1.5cm}} |
| 7325 |
\toprule |
| 7326 |
{\small key} & {\small type} & {\small meaning} & {\small default} & {\small initial}\tabularnewline |
| 7327 |
\midrule |
| 7328 |
\texttt{f} & {\small int (0/1)} & {\small show/hide formula} & & \tabularnewline |
| 7329 |
{\small\texttt{p}} & {\small token(s)} & {\small concluding punctuation} & {\small\texttt{,}} & \tabularnewline |
| 7330 |
{\small\texttt{pp}} & {\small token(s)} & {\small multi-formula inter- result punctuation} & {\small\texttt{,}} & \tabularnewline |
| 7331 |
\cmidrule{1-1} |
| 7332 |
{\small\texttt{env}} & {\small token(s)} & {\small math environment} & \multicolumn{2}{c}{{\small see Table~\ref{tab:settingsEnvironment-defaults}}}\tabularnewline |
| 7333 |
{\small\texttt{arg}} & {\small token(s)} & {\small arg. for }{\small\texttt{-at}}{\small , }{\small\texttt{array}}{\small{} |
| 7334 |
envs} & \multicolumn{2}{c}{{\small see Table~\ref{tab:settingsEnvironment-defaults}}}\tabularnewline |
| 7335 |
{\small\texttt{eq}} & {\small token(s)} & {\small relation symbol} & \multicolumn{2}{c}{{\small see Table~\ref{tab:settingsEnvironment-defaults}}}\tabularnewline |
| 7336 |
{\small\texttt{vv}} & {\small token(s)} & {\small vv-list specification} & \multicolumn{2}{c}{{\small see Table~\ref{tab:settingsEnvironment-defaults}}}\tabularnewline |
| 7337 |
{\small\texttt{sep}} & {\small token(s)} & {\small separator between multi-formula results} & \multicolumn{2}{c}{{\small see Table~\ref{tab:settingsEnvironment-defaults}}}\tabularnewline |
| 7338 |
{\small\texttt{\textbackslash\}}} & {\small token(s)} & {\small right bracket for inner math environments} & {\small\textbackslash{} }{\small\texttt{\textbackslash\}}} & \tabularnewline |
| 7339 |
\cmidrule{1-1} |
| 7340 |
{\small\texttt{vvi}} & \multicolumn{4}{l}{{\small deprecated; use }{\small\texttt{vv}}}\tabularnewline |
| 7341 |
{\small\texttt{vvd}} & \multicolumn{4}{l}{{\small deprecated; use }{\small\texttt{vv}}}\tabularnewline |
| 7342 |
\bottomrule |
| 7343 |
\end{tabular} |
| 7344 |
|
| 7345 |
\subsection{Environment settings} |
| 7346 |
|
| 7347 |
\begin{tabular}{lccV{\linewidth}l} |
| 7348 |
\toprule |
| 7349 |
{\small\texttt{env}} & {\small rem/}{\small\texttt{arg}} & {\small\texttt{eq}} & {\small\texttt{vv}} & {\small\texttt{sep}}\tabularnewline |
| 7350 |
\midrule |
| 7351 |
{\small\texttt{\$}} & \multirow{3}{*}{} & \multirow{3}{*}{{\small\texttt{=}}} & \multirow{3}{*}{\begin{cellvarwidth}[t] |
| 7352 |
{\small\texttt{,\textbackslash mskip 12muplus}}~\linebreak{} |
| 7353 |
{\small\texttt{6muminus9mu(vv)}} |
| 7354 |
\end{cellvarwidth}} & \multirow{3}{*}{{\small\texttt{\textbackslash quad}}}\tabularnewline |
| 7355 |
{\small\texttt{\textbackslash (}} & & & & \tabularnewline |
| 7356 |
{\small\texttt{math}} & & & & \tabularnewline |
| 7357 |
\cmidrule{1-1} |
| 7358 |
{\small\texttt{\textbackslash{[}}} & & {\small\texttt{=}} & \begin{cellvarwidth}[t] |
| 7359 |
{\small\texttt{,\textbackslash mskip 36mu}}~\linebreak{} |
| 7360 |
{\small\texttt{minus24mu(vv)}} |
| 7361 |
\end{cellvarwidth} & {\small\texttt{\textbackslash{]}\textbackslash{[}}}\tabularnewline |
| 7362 |
\cmidrule{1-1} |
| 7363 |
{\small\texttt{displaymath}} & \multirow{3}{*}{} & \multirow{3}{*}{{\small\texttt{=}}} & \multirow{3}{*}{\begin{cellvarwidth}[t] |
| 7364 |
{\small\texttt{,\textbackslash mskip 36mu}}~\linebreak{} |
| 7365 |
{\small\texttt{minus24mu(vv)}} |
| 7366 |
\end{cellvarwidth}} & \multirow{3}{*}{\begin{cellvarwidth}[t] |
| 7367 |
{\small\texttt{\textbackslash end\{}}{\small\texttt{\emph{env}}}{\small\texttt{\}}}~\linebreak{} |
| 7368 |
{\small\texttt{\textbackslash begin\{}}{\small\texttt{\emph{env}}}{\small\texttt{\}}} |
| 7369 |
\end{cellvarwidth}}\tabularnewline |
| 7370 |
{\small\texttt{equation}} & & & & \tabularnewline |
| 7371 |
{\small\texttt{equation{*}}} & & & & \tabularnewline |
| 7372 |
\cmidrule{1-1} |
| 7373 |
{\small\texttt{multline}} & \multirow{2}{*}{\begin{cellvarwidth}[t] |
| 7374 |
\centering |
| 7375 |
{\small\texttt{\textbackslash eval}}{\small{} in }\linebreak{} |
| 7376 |
{\small{} }{\small\texttt{multline}} |
| 7377 |
\end{cellvarwidth}} & \multirow{2}{*}{{\small\texttt{=}}} & \multirow{2}{*}{\begin{cellvarwidth}[t] |
| 7378 |
{\small\texttt{,\textbackslash mskip 36mu}}~\linebreak{} |
| 7379 |
{\small\texttt{minus24mu(vv)}} |
| 7380 |
\end{cellvarwidth}} & \multirow{2}{*}{{\small\texttt{\textbackslash hfill\textbackslash\textbackslash}}}\tabularnewline |
| 7381 |
{\small\texttt{multline{*}}} & & & & \tabularnewline |
| 7382 |
\cmidrule{1-1} |
| 7383 |
{\small\texttt{multline}} & \multirow{2}{*}{\begin{cellvarwidth}[t] |
| 7384 |
\centering |
| 7385 |
{\small\texttt{multline}}~\linebreak{} |
| 7386 |
{\small in }{\small\texttt{\textbackslash eval}} |
| 7387 |
\end{cellvarwidth}} & \multirow{2}{*}{{\small\texttt{=}}} & \multirow{2}{*}{{\small\texttt{,\textbackslash\textbackslash (vv)}}} & \multirow{2}{*}{\begin{cellvarwidth}[t] |
| 7388 |
{\small\texttt{\textbackslash end\{}}{\small\texttt{\emph{env}}}{\small\texttt{\}}}~\linebreak{} |
| 7389 |
{\small\texttt{\textbackslash begin\{}}{\small\texttt{\emph{env}}}{\small\texttt{\}}} |
| 7390 |
\end{cellvarwidth}}\tabularnewline |
| 7391 |
{\small\texttt{multline{*}}} & & & & \tabularnewline |
| 7392 |
\cmidrule{1-1} |
| 7393 |
{\small\texttt{eqnarray}} & \multirow{2}{*}{} & \multirow{2}{*}{{\small\texttt{\&=\&}}} & \multirow{2}{*}{\begin{cellvarwidth}[t] |
| 7394 |
{\small\texttt{,\textbackslash mskip 36mu}}~\linebreak{} |
| 7395 |
{\small\texttt{minus24mu(vv)}} |
| 7396 |
\end{cellvarwidth}} & \multirow{2}{*}{{\small\texttt{\textbackslash\textbackslash}}}\tabularnewline |
| 7397 |
{\small\texttt{eqnarray{*}}} & & & & \tabularnewline |
| 7398 |
\cmidrule{1-1} |
| 7399 |
{\small\texttt{align}} & \multirow{3}{*}{} & \multirow{3}{*}{{\small\texttt{\&=}}} & \multirow{3}{*}{\begin{cellvarwidth}[t] |
| 7400 |
{\small\texttt{,\textbackslash mskip 36mu}}~\linebreak{} |
| 7401 |
{\small\texttt{minus24mu(vv)}} |
| 7402 |
\end{cellvarwidth}} & \multirow{3}{*}{{\small\texttt{\textbackslash\textbackslash}}}\tabularnewline |
| 7403 |
{\small\texttt{align{*}}} & & & & \tabularnewline |
| 7404 |
{\small\texttt{aligned}} & & & & \tabularnewline |
| 7405 |
\cmidrule{1-1} |
| 7406 |
{\small\texttt{flalign}} & \multirow{2}{*}{} & \multirow{2}{*}{{\small\texttt{\&=}}} & \multirow{2}{*}{{\small\texttt{,\&(vv)}}} & \multirow{2}{*}{{\small\texttt{\textbackslash\textbackslash}}}\tabularnewline |
| 7407 |
{\small\texttt{flalign{*}}} & & & & \tabularnewline |
| 7408 |
\cmidrule{1-1} |
| 7409 |
{\small\texttt{gather}} & \multirow{3}{*}{} & \multirow{3}{*}{{\small\texttt{\&=\&}}} & \multirow{3}{*}{\begin{cellvarwidth}[t] |
| 7410 |
{\small\texttt{,\textbackslash mskip 12muplus}}~\linebreak{} |
| 7411 |
{\small\texttt{6muminus9mu(vv)}} |
| 7412 |
\end{cellvarwidth}} & \multirow{3}{*}{{\small\texttt{\textbackslash\textbackslash}}}\tabularnewline |
| 7413 |
{\small\texttt{gather{*}}} & & & & \tabularnewline |
| 7414 |
{\small\texttt{gathered}} & & & & \tabularnewline |
| 7415 |
\cmidrule{1-1} |
| 7416 |
{\small\texttt{alignat}} & \multirow{3}{*}{{\small\texttt{2}}} & \multirow{3}{*}{{\small\texttt{\&=\textbackslash ;\&}}} & \multirow{3}{*}{{\small\texttt{,\textbackslash qquad\&(vv)}}} & \multirow{3}{*}{{\small\texttt{\textbackslash\textbackslash}}}\tabularnewline |
| 7417 |
{\small\texttt{alignat{*}}} & & & & \tabularnewline |
| 7418 |
{\small\texttt{alignedat}} & & & & \tabularnewline |
| 7419 |
\cmidrule{1-1} |
| 7420 |
{\small\texttt{array}} & {\small\texttt{rcrl}} & {\small\texttt{\&=\&}} & {\small\texttt{,\&(vv)}} & {\small\texttt{\textbackslash\textbackslash}}\tabularnewline |
| 7421 |
\cmidrule{1-1} |
| 7422 |
{\small\texttt{cases}} & \multirow{2}{*}{} & \multirow{2}{*}{{\small\texttt{=}}} & \multirow{2}{*}{{\small\texttt{,\textbackslash quad\textbackslash hfill(vv)}}} & \multirow{2}{*}{{\small\texttt{\textbackslash\textbackslash}}}\tabularnewline |
| 7423 |
{\small\texttt{dcases}} & & & & \tabularnewline |
| 7424 |
\bottomrule |
| 7425 |
\end{tabular} |
| 7426 |
|
| 7427 |
\subsection{Settings for supplementary commands} |
| 7428 |
|
| 7429 |
In principle the settings |
| 7430 |
\begin{verbatim} |
| 7431 |
dbg, view, ^, xx, ff, 1s2, /min, /max, vv@, o, log, S+, S?, P+, P? |
| 7432 |
\end{verbatim} |
| 7433 |
are available for \verb`\nmcInfo`, \verb`\nmcMacros`, \verb`\nmcConstants`, |
| 7434 |
\verb`\nmcReuse` but most will be of little relevance in most cases. |
| 7435 |
\begin{itemize} |
| 7436 |
\item \verb`\nmcInfo` |
| 7437 |
\begin{itemize} |
| 7438 |
\item \verb`view` equivalent to \verb`dbg=2`; |
| 7439 |
\end{itemize} |
| 7440 |
\item \verb`\nmcMacros` |
| 7441 |
\begin{itemize} |
| 7442 |
\item \verb`view` equivalent to \verb`dbg=2*3*5`; |
| 7443 |
\item \verb`free` `deregister' a macro from \texttt{numerica}; |
| 7444 |
\end{itemize} |
| 7445 |
\item \verb`\nmcConstants` |
| 7446 |
\begin{itemize} |
| 7447 |
\item \verb`view` equivalent to \verb`dbg=2*3*5`; |
| 7448 |
\item \verb`add` add the new list of constants to the current one; |
| 7449 |
\end{itemize} |
| 7450 |
\item \verb`\nmcReuse` |
| 7451 |
\begin{itemize} |
| 7452 |
\item \verb`view` equivalent to \verb`dbg=3`; |
| 7453 |
\item \verb`save` the control sequence formed from the supplied name to |
| 7454 |
the \verb`.nmc` file with the numerical result from the latest \verb`\eval` |
| 7455 |
command and define it in \LaTeX ; |
| 7456 |
\item \verb`renew` if necessary overwrite the value of a control sequence |
| 7457 |
in the \verb`.nmc` file and redefine it in \LaTeX . |
| 7458 |
\item \verb`load` load the saved control sequences and define them globally |
| 7459 |
in \LaTeX ; |
| 7460 |
\item \verb`delete` remove the listed control sequence and value from the |
| 7461 |
\verb`.nmc` file and undefine it in \LaTeX ; |
| 7462 |
\end{itemize} |
| 7463 |
\end{itemize} |
| 7464 |
|
| 7465 |
\end{document} |