diff options
Diffstat (limited to 'Master/texmf-dist/doc/latex/diffcoeff/diffcoeffx.tex')
-rw-r--r-- | Master/texmf-dist/doc/latex/diffcoeff/diffcoeffx.tex | 656 |
1 files changed, 656 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/diffcoeff/diffcoeffx.tex b/Master/texmf-dist/doc/latex/diffcoeff/diffcoeffx.tex new file mode 100644 index 00000000000..d7b48cac28d --- /dev/null +++ b/Master/texmf-dist/doc/latex/diffcoeff/diffcoeffx.tex @@ -0,0 +1,656 @@ +%% LyX 2.2.0 created this file. For more info, see http://www.lyx.org/. +%% Do not edit unless you really know what you are doing. +\documentclass[twoside,english]{article} +\usepackage{lmodern} +\renewcommand{\sfdefault}{lmss} +\renewcommand{\ttdefault}{lmtt} +\usepackage[T1]{fontenc} +\usepackage[latin9]{inputenc} +\usepackage{geometry} +\geometry{verbose,lmargin=4cm,rmargin=3.5cm} +\setcounter{secnumdepth}{2} +\setcounter{tocdepth}{1} +\usepackage{wrapfig} +\usepackage{booktabs} +\usepackage{amstext} +\usepackage{esint} + +\makeatletter + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands. +%% Because html converters don't know tabularnewline +\providecommand{\tabularnewline}{\\} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands. + \newenvironment{example}{\begin{center}\ttfamily}{\end{center}} +\newenvironment{lyxcode} +{\par\begin{list}{}{ +\setlength{\rightmargin}{\leftmargin} +\setlength{\listparindent}{0pt}% needed for AMS classes +\raggedright +\setlength{\itemsep}{0pt} +\setlength{\parsep}{0pt} +\normalfont\ttfamily}% + \item[]} +{\end{list}} +\newcommand{\strong}[1]{\textbf{#1}} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands. +\usepackage{diffcoeffx} + +\@ifundefined{showcaptionsetup}{}{% + \PassOptionsToPackage{caption=false}{subfig}} +\usepackage{subfig} +\makeatother + +\usepackage{babel} +\begin{document} + +\title{\texttt{diffcoeffx}~\\ +extending the \texttt{diffcoeff} package} + +\author{Andrew Parsloe\\ +{\small{}(aparsloe@clear.net.nz)}} +\maketitle +\begin{abstract} +\noindent \texttt{diffcoeffx.sty} is \texttt{diffcoeff.sty} `on steroids'. +It provides additional functionality for the trailing optional argument +and extends the algorithm used to calculate the overall order of differentiation +of mixed partial derivatives. That now accepts order-of-differentiation +specifications that include powers of numbers and variables, subscripts +on variables, and (possibly nested) parentheses with numerical coefficients. +The enhancements come under the category of `gilding the lily'. +\end{abstract} + +\section{The \texttt{diffcoeffx} package} + +The \texttt{diffcoeffx} package is \texttt{diffcoeff} `on steroids', +providing exactly the same commands but with some extra functionality.\texttt{ }It +is called in the usual way in the LaTeX preamble: +\begin{lyxcode} +\textbackslash{}usepackage\{diffcoeffx\} +\end{lyxcode} +It is assumed that you are familiar with the \texttt{diffcoeff} package +and its manual.\texttt{ }There are two enhancements to that package: \texttt{diffcoeffx} +takes the calculation of the overall order of mixed partial derivatives +deep into `overkill' territory, accepting single-token powers of numbers +and variables, single-token subscripts on variables, and possibly nested +parentheses with numerical coefficients. The \texttt{\textbackslash{}times} +token ($\times$) can also be used in an order specification. The other +enhancement is an extension to the capabilities of the trailing optional +argument. + +\subsection[Exploiting the final argument]{Exploiting the trailing optional argument} + +For \texttt{diffcoeff }there was an attempt to give a `natural feel' +to the design choices made and their use. By comparison the additional +functionality that the trailing optional argument acquires in \texttt{diffcoeffx.sty} +is in the nature of a \emph{hack}. It works, but I'm not sure that it should +be encouraged. + +In \texttt{diffcoeff} if you write \texttt{\textbackslash{}diff yx\{\}} +the trailing but \emph{empty} optional argument is ignored. Not so in \texttt{diffcoeffx}: +\begin{example} +\textbackslash{}diffp yx\{\}${\displaystyle \Longrightarrow\quad\diffp yx{}}$ +\end{example} +The parentheses are inserted without a subscript. Thus we can write (for +instance) Lagrange's equations of motion in analytical mechanics in the +manner: +\begin{example} +\textbackslash{}diffp L\{q\_k\}-\textbackslash{}diff{*}\{\textbackslash{}diffp +L\{\textbackslash{}dot\{q\}\_k\}\{\}\}t = 0 $\Longrightarrow\quad{\displaystyle \diffp L{q_{k}}-\diff*{\diffp L{\dot{q}_{k}}{}}t}=0$, +\end{example} +without having to bother with inserting \texttt{\textbackslash{}left(} +and \texttt{\textbackslash{}right}).\texttt{ }The empty trailing optional +argument and the default delimiters for partial derivatives do the job +for us. + +There are many other places in analytical mechanics where using an empty +trailing optional argument is a similarly convenient way of writing large +parentheses, for instance, +\begin{example} +\textbackslash{}dot\{q\_k\}=\textbackslash{}diffp H\{\textbackslash{}diffp +S\{q\_k\}\{\}\} ${\displaystyle \Longrightarrow\quad\dot{q_{k}}=\diffp H{\diffp S{q_{k}}{}}}\!.$ +\end{example} +An application of Lagrange's equations (to a one-dimensional elastic solid) +gives rise to a Langrangian density function, +\begin{example} +\textbackslash{}frac 12\textbackslash{}left\textbackslash{}\{ \textbackslash{}rho\textbackslash{}dot\{\textbackslash{}eta\}\textasciicircum{}2-E\textbackslash{}diff\textbackslash{}eta +x\{;2;()\}\textbackslash{}right \textbackslash{}\} $\Longrightarrow\quad{\displaystyle \frac{1}{2}\left\{ \rho\dot{\eta}^{2}-E\diff\eta x{;2;()}\right\} }.$ +\end{example} +Another application of those equations (the acoustic approximation to the +irrotational motion of a compressible non-viscous fluid) produces a Lagrangian +density +\begin{example} +\textbackslash{}frac 12\textbackslash{}rho\textbackslash{}left\textbackslash{}\{(\textbackslash{}nabla\textbackslash{}psi)\textasciicircum{}2-\textbackslash{}frac +1\{c\textasciicircum{}2\}\textbackslash{}diff\textbackslash{}psi t\{;2;()\}\textbackslash{}right\textbackslash{}\} +$\Longrightarrow\quad{\displaystyle \frac{1}{2}\rho\left\{ (\nabla\psi)^{2}-\frac{1}{c^{2}}\diff\psi t{;2;()}\right\} }.$ +\end{example} +In both examples, the trailing optional argument of the \emph{ordinary} +derivative has been filled by a semicolon-delimited list: \texttt{\{;2;()\}}. +The initial slot where a subscript is specified is empty but the semicolon +is necessarily included. The second spot specifies a \emph{superscript} +and the third slot the delimiters to use. Since parentheses are not the +default delimiters for an ordinary derivative we needed to specify them +explicitly here. However, this does not change the default delimiters which +remain \texttt{.|} for an ordinary derivative and can only be changed by +means of the \texttt{\textbackslash{}diffset} command. + +Both subscript and superscript can be used at the same time. In a text +on ordinary differential equations, an example employing Green's functions +gives rise to +\begin{example} +\textbackslash{}diff{[}n-1{]}Gx\{\textbackslash{}xi-\textbackslash{}epsilon;\textbackslash{}xi+\textbackslash{}epsilon;{[}{]}\} +$\Longrightarrow\quad{\displaystyle \diff[n-1]Gx{\xi-\epsilon;\xi+\epsilon;[]}}$ +\end{example} +the derivative being evaluated at both superscript and subscript values +and the difference taken. Here the trailing optional argument has its first +three slots filled, with square brackets explicitly specified. The same +book includes the example +\begin{example} +\textbackslash{}diff{*}{[}p-1{]}\{x\textasciicircum{}\textbackslash{}alpha\}\textbackslash{}alpha\{\textbackslash{}alpha=a;;\textbackslash{}\{\textbackslash{}\}\} +$\Longrightarrow\quad{\displaystyle \diff*[p-1]{x^{\alpha}}\alpha{\alpha=a;;\{\}}}$ +\end{example} +where, this time braces are specified in the trailing optional argument.\footnote{For LyX users, the braces \textbackslash{}\{ and \textbackslash{}\} are +inserted into a formula in the maths editor simply by typing the braces +without the backslashes. LyX takes care of the latter.} + +This argument can be used to form the absolute value of a derivative, +\begin{example} +\textbackslash{}diff yx\{;;||\} ${\displaystyle \Longrightarrow\quad\diff yx{;;||}}$ +\end{example} +where both initial slots, subscript and superscript, are empty and two +semicolons necessarily included in the trailing optional argument: \texttt{\{;;||\}}. +It also provides an alternative way, indeed \emph{two} alternative ways, +of forming a quotient of derivatives: +\begin{example} +\textbackslash{}diff yx\{;;./\}\textbackslash{}diff xy=\textbackslash{}diff +yx\textbackslash{}diff xy\{;;/.\} ${\displaystyle {\displaystyle \Longrightarrow\quad\diff yx{;;./}}\diff xy={\displaystyle \diff yx}\diff xy{;;/.}}$ +\end{example} +where the delimiter specification \texttt{./} on the left has been changed +to \texttt{/.} on the right. The spacing in the two quotients is not quite +identical, which might be relevant in some contexts. As a more realistic +example of use of the same construct, if $F(x,t)$ is a function of $x$ +and $t$ and $x=x(t)$, then if $\diff Ft=0$, +\begin{example} +\textbackslash{}diff xt=-\textbackslash{}diffp Ft\{;;./\}\textbackslash{}diffp +Fx $\Longrightarrow\quad{\displaystyle \diff xt=-\diffp Ft{;;./}\diffp Fx}$ +\end{example} +For an inline use, you may prefer to use the slash form of the derivative +$\diff y/z{0;;();-1}$. In this case a \emph{fourth} slot in the trailing +optional argument has been filled, the \texttt{nudge override} slot, since +the default nudge is designed to position the subscript relative to the +\emph{displaystyle} delimiters. + +The complete specification of what is available in the trailing optional +argument is: +\begin{example} +\{ subscript; superscript; delimiters; nudge override \} +\end{example} +\begin{itemize} +\item In `normal' use, the \texttt{subscript} is the point of evaluation (ordinary +derivatives), or list of variables held constant (partial derivatives). +Since the list of variables held constant is likely to be comma-separated, +so we have the need for semicolons to separate items in the larger list. +\item The \texttt{superscript} is generally a power to which the derivative is +raised but, as instanced by the Green's function example, it can also be +another point of evaluation of the derivative. +\item The \texttt{delimiters} are, by default, \texttt{.|} for ordinary derivatives +and \texttt{()} for partial derivatives. These are not always the right +ones for a particular task. Rather than changing them \emph{globally} as +the use of \texttt{\textbackslash{}diffset} entails, they can be changed +\emph{locally} for the particular instance by specifying them in this slot. +The global choices are unaffected. +\item If the built-in placement of sub- or superscript relative to the right +delimiter is unsatisfactory, a value specified in the \texttt{nudge override} +slot\texttt{ }overrides the default value locally. The value is a pure +number which \texttt{diffcoeffx} treats as that number of mu (1/18 of an +em). (For comparison, a thin space \textbackslash{}, and a negative thin +space \textbackslash{}! are 3/18 of an em.) The default nudges are shown +in Table~\ref{tab:Default-nudges}. They are intended for displaystyle +presentation, and are not affected by any value included in this slot. +\end{itemize} +\noindent\begin{minipage}[t]{1\columnwidth}% +\begin{wraptable}[10]{o}{0.35\columnwidth}% +\centering{}\caption{\label{tab:Default-nudges}Default nudges} +\begin{tabular}{|c|c|} +\hline +right delimiter & nudge\tabularnewline +\hline +\hline +), > & -6\tabularnewline +\hline +\textbackslash{}\} & -4\tabularnewline +\hline +|, {]} & 0\tabularnewline +\hline +other & 0\tabularnewline +\hline +\end{tabular}\end{wraptable}% +Note that if one wants to use the nudge override with the default delimiters, +it is necessary to indicate all preceding slots, even if they are empty, +e.g., \texttt{\{;;;-3\}}. Similarly, to change the delimiters, to parentheses +say, without sub- or superscript, it is necessary to indicate all preceding +empty slots, but the following one does not need to be indicated: \texttt{\{;;()\}}. +If one wants to specify a superscript, 2 say, but leave all else unchanged, +it is only necessary to specify the one preceding empty slot: \texttt{\{;2\}}. +Trailing empty slots can be omitted, which is why, if one wants to use +the trailing empty argument `as nature intended', i.e., to specify a +point of evaluation or variables held constant, one can close one's mind +to the other potential slots and simply write (for instance) \texttt{\{0\}} +or \texttt{\{x=1\}}.% +\end{minipage} + +\subsection{The enhanced mixed partial derivative algorithm\label{subsec:The-enhanced-mixed}} + +In the documentation for \texttt{diffcoeff.sty} I discussed the transition +table, Table~\ref{tab:Input-output-states}, in which signed \strong{s}, +numeric \strong{n}, or algebraic \strong{a} states changed to one of +the others, or not, depending on the nature of the current token: sign, +digit or variable. Signs and digits were explicitly defined; anything and +everything else was called a (prime) variable. (Not quite true: in fact +\texttt{diffcoeff.sty} checked for \texttt{(}, \texttt{\textasciicircum{}} +and \texttt{\_} and raised an error if they were encountered.)\texttt{ } + +\begin{table}[h] +\noindent \begin{centering} +\caption{A first enhancement} +\subfloat[\label{tab:Input-output-states}State transitions]{\noindent \centering{}\medskip{} +\begin{tabular}{ccccc} +\cmidrule{2-5} + & Curr. state & Curr. token & Action & Next state\tabularnewline +\cmidrule{2-5} +1 & \strong{s} & $s$ & $Ts\to s'$; $T=s'$ & \strong{s}\tabularnewline +\cmidrule{2-5} +2 & \strong{s} & $d$ & $Td$ & \strong{n}\tabularnewline +\cmidrule{2-5} +3 & \strong{s} & $v$ & $Vv$; $T1v$ & \strong{a}\tabularnewline +\cmidrule{2-5} +4 & \strong{n} & $s$ & $\mathbf{N}T$; $T=s$ & \strong{s}\tabularnewline +\cmidrule{2-5} +5 & \strong{n} & $d$ & $Td$ & \strong{n}\tabularnewline +\cmidrule{2-5} +6 & \strong{n} & $v$ & $Vv$; $Tv$ & \strong{a}\tabularnewline +\cmidrule{2-5} +7 & \strong{a} & $s$ & $\mathbf{V}V,$; $V=\textrm{Ø}$; $\mathbf{A}T$; $T=s$ & \strong{s}\tabularnewline +\cmidrule{2-5} +8 & \strong{a} & $d$ & error & \strong{!!}\tabularnewline +\cmidrule{2-5} +9 & \strong{a} & $v$ & $Vv$; $Tv$ & \strong{a}\tabularnewline +\cmidrule{2-5} +\end{tabular}} +\par\end{centering} +\noindent \centering{}\subfloat[\label{tab:Allowing-powers-variables}Allowing powers of variables]{\centering{}% +\begin{tabular}{ccccc} +\cmidrule{2-5} + & Curr. state & Curr. token & Action & Next state\tabularnewline +\cmidrule{2-5} +8 & \strong{a} & $d$ & $Vd$; $Td$ & \strong{a}\tabularnewline +\cmidrule{2-5} +\end{tabular}} +\end{table} +There is a certain inner logic at play here. Multi-token variables like +$kmn$ are included in the above scheme. But having accommodated $mn$, +surely one should be able to handle $mm$, i.e. $m^{2}$? And if $m^{2}$, +then why not $m^{n}$? In fact it is easy to do so. Since the superscript +token \textasciicircum{} is neither sign nor digit, no longer raise an +error if it is encountered but treat it, among the `everything else' +tokens, as a variable. If we change row 8 of the table as in Table~\ref{tab:Allowing-powers-variables} +we have enlarged our scheme to include powers of variables \textendash{} +not only numerical powers (row 8) but also algebraic powers (row 9). As +a side-effect, if we also suppress the raising of an error when the subscript +token \texttt{\_} is encountered, it too will be classified as a variable +and allow numeric and algebraic subscripts on variables: things like $k_{2}$ +or $k_{n}$. + +Implicit in this discussion is the understanding that exponents and subscripts +are restricted to \emph{single tokens}. Coping with multi-token quantities +in those positions would entail changes to other parts of the code, which +I have chosen not to do. + +This is a simple way of enlarging the range of tokens acceptable to the +overall-order algorithm, but it does assume that the user does \emph{not} +include a sign as a superscript or subscript. If they do, then when the +algorithm meets the sign it arrives at row 7 of the table and stores what +is clearly an unintended variable, something like \texttt{k\textasciicircum{}} +or \texttt{k\_}. So, we need to check when a sign is met whether the previous +token was one of \texttt{\textasciicircum{}} or \texttt{\_} and raise an +error if it was. But then the thought arises: if we are going to the trouble +of checking for sub- or superscript tokens, why just raise an error? Why +not incorporate signs in sub- or superscript positions into the scheme? + +To this end, we might introduce a fourth state, the \emph{script} state, +denoted by \strong{p}. A script token, denoted $p$, is one of \texttt{\textasciicircum{}} +or \texttt{\_}. There is only one way to enter a script state, and that +is by appending a script token to a \emph{variable}. Appending a script +token to a sign or number (or, indeed, another script token) raises an +error. Table~\ref{tab:Enlarged-scheme-transitios} is the result. In this +scheme, signs can be used as sub- or superscripts to variables, but not +to numbers. We might console ourselves with the thought that this is, in +any case, a limitation of the calculational engine used to evaluate our +integer expressions. The \texttt{l3int} module of the LaTeX3 bundle \texttt{l3kernel} +cannot handle powers of integers. + +\begin{table}[h] +\caption{\label{tab:Enlarged-scheme-transitios}Transition states for an enlarged +scheme} + +\noindent \centering{}% +\begin{tabular}{ccccc} +\cmidrule{2-5} + & Curr. state & Curr. token & Action & Next state\tabularnewline +\cmidrule{2-5} +1 & \strong{s} & $s$ & $Ts\to s'$; $T=s'$ & \strong{s}\tabularnewline +\cmidrule{2-5} +2 & \strong{s} & $d$ & $Td$ & \strong{n}\tabularnewline +\cmidrule{2-5} +3 & \strong{s} & $v$ & $Vv$; $T1v$ & \strong{a}\tabularnewline +\cmidrule{2-5} +4 & \strong{s} & $p$ & error & \strong{!!}\tabularnewline +\cmidrule{2-5} +5 & \strong{n} & $s$ & $\mathbf{N}T$; $T=s$ & \strong{s}\tabularnewline +\cmidrule{2-5} +6 & \strong{n} & $d$ & $Td$ & \strong{n}\tabularnewline +\cmidrule{2-5} +7 & \strong{n} & $v$ & $Vv$; $Tv$ & \strong{a}\tabularnewline +\cmidrule{2-5} +8 & \strong{n} & $p$ & error & \strong{!!}\tabularnewline +\cmidrule{2-5} +9 & \strong{a} & $s$ & $\mathbf{V}V,$; $V=\textrm{Ø}$; $\mathbf{A}T$; $T=s$ & \strong{s}\tabularnewline +\cmidrule{2-5} +10 & \strong{a} & $x\in\{dv\}$ & $Vx$; $Tx$ & \strong{a}\tabularnewline +\cmidrule{2-5} +11 & \strong{a} & $p$ & $Vp$; $Tp$ & \strong{p}\tabularnewline +\cmidrule{2-5} +12 & \strong{p} & $x\in\{sdv\}$ & $Vx$; $Tx$ & \strong{a}\tabularnewline +\cmidrule{2-5} +13 & \strong{p} & $p$ & error & \strong{!!}\tabularnewline +\cmidrule{2-5} +\end{tabular} +\end{table} +Yet this still leaves an unfinished feeling. While attaching a script token +to a sign or other script token is a nonmathematical usage, attaching a +superscript token to a number is a basic mathematical use, and so two of +the errors raised can really be ignored. For the other, the question nags: +why should we have to remember that although variables can be raised to +powers, numbers cannot be? The urge to enlarge the scheme again is irresistible. +Exponents on numbers should be accepted; but subscripts should not. The +latter is a nonmathematical usage or is used only in special contexts remote +from the present one. But that means we need to distinguish sub- and superscript +tokens. We can't lump them together as `script tokens'. + +\subsubsection{Raising numbers to powers: new states} + +So a first step is to enlarge the number of states. We need an \emph{exponent} +state \strong{e} when we encounter the token \textasciicircum{} and a +\emph{subscript }state \strong{b} when we encounter the token \_. That +allows us to distinguish acceptable forms like \texttt{2\textasciicircum{}3} +($2^{3}$) from unacceptable ones like \texttt{2\_3} ($2_{3}$). But how +do we know which state to transition to when we meet the \texttt{3} in +\texttt{2\textasciicircum{}3}? The current state is the exponent one \strong{e} +and the \texttt{3} could be decorating either a variable or a number. We +need to know the \emph{previous} state as well as the current one. If the +previous state is numeric we transition to a numeric state; if it is algebraic, +we transition to an algebraic state. + +But that also introduces a problem. It is perfectly acceptable to add a +digit to a term in a numeric state. Normally, this is how a multi-digit +number is accumulated: \texttt{23}4, two hundred and thirty four. That +is a very different meaning from \texttt{2\textasciicircum{}34} which means +$2^{3}4$ to us (rather than $2^{34}$ since we accept only single-token +superscripts). At this point, the syntax required by the underlying engine +used for evaluating numerical expressions comes into play. For all numerical +evaluations except those involving exponents, \texttt{l3int} of the LaTeX3 +kernel is used; for expressions involving exponents, \texttt{l3fp} is used. +To \texttt{l3fp}, \texttt{2\textasciicircum{}34} is read as $2^{34}$. +We need to insert a multiplication token between the \texttt{3} and \texttt{4}, +which for \texttt{l3fp} is the asterisk, \texttt{{*}}. Considering the +different tokens that might follow \emph{that}, we are forced to introduce +a third new state, the \emph{multiplicative} state, \strong{m}. So, to +introduce powers of numbers means considering three new states and reference +to the previous state. + +That, of course, is \emph{numeric} powers of numbers. To also allow algebraic +powers, forms like $2^{n}$, introduces further complication. These can't +be evaluated numerically, so presumably they are to be classified as variables. +We need to consider terms like $+2^{n}$, $3*2^{n}$, $3^{m}2^{n}$, and +$2^{n}m$. The problem here is that we have something that looks as if +it is going to be a number (the digit 2) but then transforms into a variable, +$2^{n}$. Do we need a \emph{fourth} new state, the entangled state \strong{q} +(the `q' as in `quantum entanglement')? + +\begin{table} +\noindent \centering{}\caption{\label{tab:Revised-input-output}State transitions of the full scheme} +\medskip{} +\begin{tabular}{cccccc} +\cmidrule{2-6} + & $S_{-}$ & $S$ & $t\in\left\{ sdv\text{\textasciicircum\_}*\right\} $ & Action & $S_{+}$\tabularnewline +\cmidrule{2-6} +1 & & \strong{s} & $s$ & $Ts\to s'$; $T=s'$ & \strong{s}\tabularnewline +\cmidrule{2-6} +2 & & \strong{s} & $d$ & $Qd$; $Td$ & \strong{n}\tabularnewline +\cmidrule{2-6} +3 & & \strong{s} & $v$ & $Vv$; $T1v$ & \strong{a}\tabularnewline +\cmidrule{2-6} +4 & & \strong{n} & $s$ & $Q=\textrm{Ø}$; $\mathbf{N}T$; $T=s$ & \strong{s}\tabularnewline +\cmidrule{2-6} +5 & & \strong{n} & $d$ & $Qd$; $Td$ & \strong{n}\tabularnewline +\cmidrule{2-6} +6 & & \strong{n} & $v$ & $Q=\textrm{Ø}$; $Vv$; $Tv$ & \strong{a}\tabularnewline +\cmidrule{2-6} +7 & & \strong{n} & $\text{\textasciicircum}$ & $Q\text{\textasciicircum}$; $T\text{\textasciicircum}$ & \strong{e}\tabularnewline +\cmidrule{2-6} +8 & & \strong{n} & $*$ & $Q=\textrm{Ø}$; $T*$ & \strong{m}\tabularnewline +\cmidrule{2-6} +9 & & \strong{a} & $s$ & $\mathbf{V}V,$; $V=\textrm{Ø}$; $\mathbf{A}T$; $T=s$ & \strong{s}\tabularnewline +\cmidrule{2-6} +10 & \strong{e} & \strong{a} & $d$ & $Vd$; $Td$ & \strong{a}\tabularnewline +\cmidrule{2-6} +11 & & \strong{a} & $v$ & $Vv$; $Tv$ & \strong{a}\tabularnewline +\cmidrule{2-6} +12 & & \strong{a} & $\text{\textasciicircum}$ & $V\text{\textasciicircum}$; $T\text{\textasciicircum}$ & \strong{e}\tabularnewline +\cmidrule{2-6} +13 & & \strong{a} & $\text{\_}$ & $V\text{\_}$; $T\text{\_}$ & \strong{b}\tabularnewline +\cmidrule{2-6} +14 & \strong{a} & \strong{e} & $t\in\left\{ sdv\right\} $ & $Vt$; $Tt$ & \strong{a}\tabularnewline +\cmidrule{2-6} +15 & \strong{n} & \strong{e} & $d$ & $Q=\textrm{Ø}$; $Td*$ & \strong{m}\tabularnewline +\cmidrule{2-6} +16 & \strong{n} & \strong{e} & $v$ & $Qv$; $Tv$; $V=Q$; $Q=\textrm{Ø}$ & \strong{a}\tabularnewline +\cmidrule{2-6} +17 & \strong{a} & \strong{b} & $t\in\left\{ sdv\right\} $ & $Vt$; $Tt$ & \strong{a}\tabularnewline +\cmidrule{2-6} +18 & \strong{e} & \strong{m} & $s$ & $T1$; $\mathbf{N}T$; $T=s$ & \strong{s}\tabularnewline +\cmidrule{2-6} +19 & & \strong{m} & $d$ & $Qd$; $Td$ & \strong{n}\tabularnewline +\cmidrule{2-6} +20 & & \strong{m} & $v$ & $Vv$; $T1v$ & \strong{a}\tabularnewline +\cmidrule{2-6} +21 & & \strong{m} & $*$ & & \strong{m}\tabularnewline +\cmidrule{2-6} +\end{tabular} +\end{table} +In fact I find that these problems can all be dealt with not by creating +another state but by including another accumulator for \emph{potential} +variables. I'll call it $Q$ (from the quantum suggestion, or perhaps quasi-variable, +or even acqumulator). It stores numbers whose status has not been determined +yet: they might yet be followed by a superscript token which might in turn +be followed by a variable. Once resolved, $Q$ either transfers its contents +to $V$, the variable accumulator, and is emptied (row 16), or is emptied +forthwith (rows 4, 6, 8, 15). + +Table~\ref{tab:Revised-input-output} lists the transitions. I've denoted +the previous state by $S_{-}$, the present state by $S$, and the next +state by $S_{+}$. The final row of the table is intended: do nothing if +we meet a multiplicative token when in a multiplicative state. The first +scan through an order specification (to split it into numeric and algebraic +parts) may introduce a {*} token (rows 8 and 15). We don't want to introduce +a second such token in the recursive determination of the coefficients +of variables. Hence row 21: do nothing. Also, if in the order specification +we have something like $2^{3}*3^{2}$ (since \texttt{2\textasciicircum{}33\textasciicircum{}2} +looks weird), we don't want the manually inserted {*} to cause an error +because of the automatically inserted one (row 15). + +Possibilities not explicitly present in the table generally raise an error, +e.g. current state \strong{s} and current token $\textnormal{\textasciicircum}$, +or previous state \strong{n}, current state \strong{e} and current token +$s$ ($+$ or $-$), and so on. I have omitted them from the table in the +interests of space. The table is big enough already. + +With this table of transitions it is now possible to handle order specifications +that include components like $n^{2}$ or $n^{m}$ or $k^{+}$ or $k_{2}$ +or $k_{n}$ or $2^{2}$ or $2^{3}3^{2}$ or $2\times3^{n}$ or $2^{2}3^{n}$ +or \ldots{} + +Note that the \texttt{\textbackslash{}times} token is converted internally +by \texttt{diffcoeffx.sty} to the asterisk. They can be used interchangeably +but it certainly looks more elegant. + +So, what could be better on a cool winter's evening, snug before the warmth +of the fire, a glass of sustaining liquid to hand, than to do a few mixed +partial derivatives? Like this, +\begin{example} +\textbackslash{}diffp{[}3\textasciicircum{}22\textasciicircum{}22\textasciicircum{}n+m,12\textasciicircum{}n-3m+2\textasciicircum{}3k,5m+2\textbackslash{}times2\textasciicircum{}32\textasciicircum{}n{]}\{F(x,y,z)\}\{x,y,z\}$\Longrightarrow\quad{\displaystyle \diffp[3^{2}2^{2}2^{n}+m,12^{n}-3m+2^{3}k,5m+2\times2^{3}2^{n}]{F(x,y,z)}{x,y,z}}$ +\end{example} +or like this, +\begin{example} +\textbackslash{}diffp{[}k\textasciicircum{}+k\_-+1,2\textbackslash{}times +k\_-,3\textasciicircum{}2k\_-,3k\textasciicircum{}+{]}\{F(x,y,z,w)\}\{x,y,z,w\} +${\displaystyle \Longrightarrow\quad\diffp[k^{+}k_{-}+1,2\times k_{-},3^{2}k_{-},3k^{+}]{F(x,y,z,w)}{x,y,z,w}}$ +\end{example} +In the first example the \texttt{\textbackslash{}times} symbol is inserted +by \texttt{diffcoeffx} in the overall order of differentiation in the numerator +so as to prevent the formation $522^{n}$ which would be read as 522 raised +to the power $n$ \textendash{} and for a similar reason it was used in +specifying the order of differentiation of the variable $z$ in the denominator +in the first example, but could and should have been deleted from the order +of differentiation of the variable $y$ in the second example. + +\subsubsection{Parentheses} + +The other major shortcoming of the basic scheme outlined in \texttt{diffcoeff.sty} +was the inability to handle even the simplest instance of parentheses in +an order specification \textendash{} something like\texttt{ {[}m-(n-1),m+(n-1){]}} +which might well arise in a Taylor expansion. Indeed, there is more reason +for including these in our scheme than exponents of numbers or $+$ or +$-$ as sub- or superscripts. + +How might we fit parentheses to the scheme? We are not seeking a general +treatment. Rather we wish to be able to handle order specifications a little +more complicated (but only a little) than the one just given, say something +like \texttt{{[}m+2(n-1),m-(n-1){]}}, perhaps with nesting. In that case +the following stipulations meet our needs: +\begin{itemize} +\item a left parenthesis, (, either starts an item in the comma list, or is preceded +by a sign or a number or $*$ or (, but \emph{not} by a variable or \textasciicircum{} +or \_ or ); +\item a right parenthesis, ), either concludes an item in the comma list, or +is followed by a sign or ), but \emph{not} by a number or a variable or +\textasciicircum{} or \_ or $*$ or (. +\end{itemize} +These limitations allow nesting of parentheses but not products of parentheses. +The main limitation they impose is that a variable lie \emph{within} parentheses +but not adjoining-outside. They enable us to get away with the following +`cheap and cheerful' scheme. It means we do not need to add parenthesis +states to our scheme. The particular point to note are the $+0$ insertions. +When we start parsing an expression from the left we do not know what it +contains. In particular when we meet a left parenthesis, we have no foreknowledge +of whether the parenthesised expression will be numeric, algebraic or a +mix of both. We need to prepare for both by inserting a left parenthesis +to both numeric and algebraic parts. But that brings us up against a quirk +of \texttt{l3int}, the `engine' behind the numerical evaluations performed +in \texttt{diffcoeff} and \texttt{diffcoeffx}. \texttt{l3int} objects to +an empty pair of parentheses, \texttt{()}, which we would have should either +numeric or algebraic parts be missing from the parenthesised expression. +To avoid this we insert $+0$ and \texttt{l3int} is happy.\texttt{ } + +\begin{table} +\centering{}\caption{\label{tab:Parentheses}Parentheses} +\begin{tabular}{ccccc} +\cmidrule{2-5} + & Curr. state & Curr. token & Action & Next state\tabularnewline +\cmidrule{2-5} +1 & \strong{s} & ( & $T\text{1*(}$; $\mathbf{N}T$; $\mathbf{A}T$; $T=+$ & \strong{s}\tabularnewline +\cmidrule{2-5} +2 & \strong{s} & ) & $\mathbf{N})$; $\mathbf{A})$ & \strong{s}\tabularnewline +\cmidrule{2-5} +3 & \strong{n} & ( & $T*($; $\mathbf{N}T$; $\mathbf{A}T$; $T=+$ & \strong{s}\tabularnewline +\cmidrule{2-5} +4 & \strong{n} & ) & $T)$; $\mathbf{N}T$; $\mathbf{A}\text{+0)}$; $T=+$ & \strong{s}\tabularnewline +\cmidrule{2-5} +5 & \strong{a} & ) & $\mathbf{V}V,$; $V=\textrm{Ø}$; $\mathbf{N}\text{+0)}$; $T)$; $\mathbf{A}T$ +; $T=+$ & \strong{s}\tabularnewline +\cmidrule{2-5} +6 & \strong{m} & ( & $T($; $\mathbf{N}T$; $\mathbf{A}T$; $T=+$ & \strong{s}\tabularnewline +\cmidrule{2-5} +\end{tabular} +\end{table} + +\begin{itemize} +\item Row 1. Quirks of the \texttt{l3int} module of the \LaTeX{}3 kernel mean +we need to insert \strong{1{*}} before the left parenthesis.\footnote{Specifically, \texttt{\textbackslash{}int\_eval\{}\textbf{ }\texttt{\textendash (} +or \texttt{\textbackslash{}int\_eval\{}\textbf{ }\texttt{+(} throw errors.} Note that we add $T$ to \emph{both} the numeric and algebraic parts of +the expression. We are working through our expression $\mathbf{E}$ from +the left, token by token, and have no foreknowledge of what the parenthesised +expression contains, whether algebraic terms only or numeric terms only +or some combination of both. Hence the need to prepare for both. The system +shifts to a signed state \strong{s} with $T=+$, exactly the same as when +beginning to scan $\mathbf{E}$. After all, the parenthesised expression +is an expression in itself. +\item Row 2. This is to allow nested parentheses like )). It shouldn't arise +otherwise. Because of rows 4 and 5, the first right parenthesis puts the +system into a signed state. The current term will be $T=+$, but we ignore +it and store only a right parenthesis in both numeric and algebraic parts. +\item Row 3. We already have a number present in $T$; only the asterisk needs +inserting before the parenthesis. Again we add $T$ to \emph{both} the +numeric and algebraic parts of the expression, initialise $T$ to $+$ +and change the state to a signed one. +\item Row 4. We are in a numeric state. We append ) to the current term and the +current term to the numeric part of the expression. We append $+0)$ to +the algebraic part, and shift to a signed state \strong{s} with $T=+$, +as at the outset. The $+0)$ in the algebraic part is necessary to prevent +an empty parenthesis pair in $\mathbf{A}$ should the parenthesised expression +have contained \emph{no} algebraic term. +\item Row 5. We are in an algebraic state. We append ) to the current term and +the current term to the algebraic part of the expression. We append $+0)$ +to the numeric part and shift to the initial signed state again. The $+0)$ +in the numeric part is necessary to prevent an empty parenthesis pair in +$\mathbf{N}$ should the parenthesised expression have contained \emph{no} +numeric term. +\item Row 6. We are in the new state, the multiplicative state, and the current +token is a left parenthesis. We have already met and inserted an asterisk +(row 5); we don't need to insert another. We append ( to $T$, $T$ to +both numeric and algebraic parts and shift to the initial signed state +again. The use of the multiplicative state prevents a string of asterisks +arising (but we have been able to avoid introducing new states for left +and right parentheses). +\end{itemize} +To work through an example, suppose we have an order specificiation \strong{{[}m+(n\textendash (k\textendash 1)),m\textendash{} 2(n+(k\textendash 1)),k{]}}. +(Digit \strong{1} rather than a lower-case letter \strong{l} within the +parentheses!) Concatenating, with linking + signs gives \strong{m+(n\textendash (k-1))+m\textendash 2(n+(k\textendash 1))+k}. +Splitting into numeric and algebraic parts now results in \strong{+1{*}(\textendash 1{*}(\textendash 1))\textendash 2{*}(+1{*}(\textendash 1))} +for the numeric part, evaluating to \strong{3}, and \strong{+1m+1{*}(+1n\textendash 1{*}(+1k+0))+1m\textendash 2{*}(+1n+1{*}(+1k+0))+1k} +for the algebraic part. + +Removing \strong{m} from the latter and splitting into numeric and algebraic +parts gives \strong{+1+ 1{*}(\textendash 1{*}(+0))+1\textendash 2{*}(+1{*}(+0))} +for the numeric part, evaluating to \strong{2} which is the overall coefficient +of \strong{m}, and \strong{+1{*}(+1n\textendash 1{*}(+1k+0))\textendash 2{*}(+1n+1{*}(+1k+0))+1k} +for the algebraic part. + +Now remove \strong{n} from this resulting algebraic part and again split +into parts. The result is \strong{+1{*}(+1-1{*}(+0))\textendash 2{*}(+1+1{*}(+0))} +for the numeric part, evaluating to \strong{\textendash 1} which is the +overall coefficient of \strong{n}, and \strong{+1{*}(\textendash 1{*}(+1k+0))\textendash 2{*}(+1{*}(+1k+0))+1k} +for the algebraic part. + +Removing \strong{k} from this and splitting gives \strong{+1{*}(\textendash 1{*}(+1+0))\textendash 2{*}(+1{*}(+1+0))+1} +for the numeric part, evaluating to \strong{\textendash 2} which is the +overall coefficient of \strong{k}, and \strong{+1{*}(\textendash 1{*}(+0)) \textendash 2{*}(+1{*}(+0))} +for the algebraic part. But we have run out of variables and so the process +stops at this point: +\begin{example} +\textbackslash{}diffp{[}m+(n-(k-1)),m-2(n+(k-1)),k{]}F\{x,y,z\}$\Longrightarrow{\displaystyle \hspace*{1em}\diffp[m+(n-(k-1)),m-2(n+(k-1)),k]F{x,y,z}}$ +\end{example} + +\end{document} |