## Faster SVD via Polar Decomposition

The car number plate of Gene Golub, who did so much to promote the SVD. Photo credit: P. M. Kroonenberg.

The singular value decomposition (SVD) is one of the most important tools in matrix theory and matrix computations. It is described in many textbooks and is provided in all the standard numerical computing packages. I wrote a two-page article about the SVD for The Princeton Companion to Applied Mathematics, which can be downloaded in pre-publication form as an EPrint.

The polar decomposition is a close cousin of the SVD. While it is probably less well known it also deserves recognition as a fundamental theoretical and computational tool. The polar decomposition is the natural generalization to matrices of the polar form $z = r \mathrm{e}^{\mathrm{i}\theta}$ for complex numbers, where $r\ge0$, $\mathrm{i}$ is the imaginary unit, and $\theta\in(-\pi,\pi]$. The generalization to an $m\times n$ matrix is $A = UH$, where $U$ is $m\times n$ with orthonormal columns and $H$ is $n\times n$ and Hermitian positive semidefinite. Here, $U$ plays the role of $\mathrm{e}^{\mathrm{i}\theta}$ in the scalar case and $H$ the role of $r$.

It is easy to prove existence and uniqueness of the polar decomposition when $A$ has full rank. Since $A = UH$ implies $A^*A = HU^*UH = H^2$, we see that $H$ must be the Hermitian positive definite square root of the Hermitian positive definite matrix $A^*A$. Therefore we set $H = (A^*A)^{1/2}$, after which $U = AH^{-1}$ is forced. It just remains to check that this $U$ has orthonormal columns: $U^*U = H^{-1}A^*AH^{-1} = H^{-1}H^2H^{-1} = I$.

Many applications of the polar decomposition stem from a best approximation property: for any $m\times n$ matrix $A$ the nearest matrix with orthonormal columns is the polar factor $U$, for distance measured in the 2-norm, the Frobenius norm, or indeed any unitarily invariant norm. This result is useful in applications where a matrix that should be unitary turns out not to be so because of errors of various kinds: one simply replaces the matrix by its unitary polar factor.

However, a more trivial property of the polar decomposition is also proving to be important. Suppose we are given $A = UH$ and we compute the eigenvalue decomposition $H = QDQ^*$, where $D$ is diagonal with the eigenvalues of $H$ on its diagonal and $Q$ is a unitary matrix of eigenvectors. Then $A = UH = UQDQ^* = (UQ)DQ^* \equiv P\Sigma Q^*$ is an SVD! My PhD student Pythagoras Papadimitriou and I proposed using this relation to compute the SVD in 1994, and obtained speedups by a factor six over the LAPACK SVD code on the Kendall Square KSR1, a shared memory parallel machine of the time.

Yuji Nakatsukasa and I recently revisited this idea. In a 2013 paper in the SIAM Journal of Scientific Computing we showed that on modern architectures it is possible to compute the SVD via the polar decomposition in a way that is both numerically stable and potentially much faster than the standard Golub–Reinsch SVD algorithm. Our algorithm has two main steps.

1. Compute the polar decomposition by an accelerated Halley algorithm called QDWH devised by Nakatsukasa, Bai, and Gygi (2010), for which the main computational kernel is QR factorization.
2. Compute the eigendecomposition of the Hermitian polar factor by a spectral divide and conquer algorithm. This algorithm repeatedly applies QDWH to the current block to compute an invariant subspace corresponding to the positive or negative eigenvalues and thereby divides the problem into two smaller pieces.

The polar decomposition is fundamental to both steps of the algorithm. While the total number of flops required is greater than for the standard SVD algorithm, the new algorithm has lower communication costs and so should be faster on parallel computing architectures once communication costs are sufficiently greater than the costs of floating point arithmetic. Sukkari, Ltaief, and Keyes have recently shown that on a multicore architecture enhanced with multiple GPUs the new QDWH-based algorithm is indeed faster than the standard approach. Another interesting feature of the new algorithm is that it has been found experimentally to have better accuracy.

The Halley iteration that underlies the QDWH algorithm for the polar decomposition has cubic convergence. A version of QDWH with order of convergence seventeen, which requires just two iterations to converge to double-precision accuracy, has been developed by Nakatsukasa and Freund (2015), and is aimed particularly at parallel architectures. This is a rare example of an iteration with a very high order of convergence actually being of practical use.

## Numerical Linear Algebra and Matrix Analysis

Matrix analysis and numerical linear algebra are two very active, and closely related, areas of research. Matrix analysis can be defined as the theory of matrices with a focus on aspects relevant to other areas of mathematics, while numerical linear algebra (also called matrix computations) is concerned with the construction and analysis of algorithms for solving matrix problems, as well as related topics such as problem sensitivity and rounding error analysis.

My article Numerical Linear Algebra and Matrix Analysis for The Princeton Companion to Applied Mathematics gives a selective overview of these two topics. The table of contents is as follows.

1 Nonsingularity and Conditioning
2 Matrix Factorizations
3 Distance to Singularity and Low-Rank Perturbations
4 Computational Cost
5 Eigenvalue Problems
5.1 Bounds and Localization
5.2 Eigenvalue Sensitivity
5.3 Companion Matrices and the Characteristic Polynomial
5.4 Eigenvalue Inequalities for Hermitian Matrices
5.5 Solving the Non-Hermitian Eigenproblem
5.6 Solving the Hermitian Eigenproblem
5.7 Computing the SVD
5.8 Generalized Eigenproblems
6 Sparse Linear Systems
7 Overdetermined and Underdetermined Systems
7.1 The Linear Least Squares Problem
7.2 Underdetermined Systems
7.3 Pseudoinverse
8 Numerical Considerations
9 Iterative Methods
10 Nonnormality and Pseudospectra
11 Structured Matrices
11.1 Nonnegative Matrices
11.2 M-Matrices
12 Matrix Inequalities
13 Library Software
14 Outlook


## Corless and Fillion’s A Graduate Introduction to Numerical Methods from the Viewpoint of Backward Error Analysis

I acquired this book when it first came out in 2013 and have been dipping into it from time to time ever since. At 868 pages long, the book contains a lot of material and I have only sampled a small part of it. In this post I will not attempt to give a detailed review but rather will explain the distinctive features of the book and why I like it.

As the title suggests, the book is pitched at graduate level, but it will also be useful for advanced undergraduate courses. The book covers all the main topics of an introductory numerical analysis course: floating point arithmetic, interpolation, nonlinear equations, numerical linear algebra, quadrature, numerical solution of differential equations, and more.

In order to stand out in the crowded market of numerical analysis textbooks, a book needs to offer something different. This one certainly does.

• The concepts of backward error and conditioning are used throughout—not just in the numerical linear algebra chapters.
• Complex analysis, and particularly the residue theorem, is exploited throughout the book, with contour integration used as a fundamental tool in deriving interpolation formulas. I was pleased to see section 11.3.2 on the complex step approximation to the derivative of a real-valued function, which provides an interesting alternative to finite differences. Appendix B, titled “Complex Numbers”, provides in just 8 pages excellent advice on the practical usage of complex numbers and functions of a complex variable that would be hard to find in complex analysis texts. For example, it has a clear discussion of branch cuts, making use of Kahan’s counterclockwise continuity principle (eschewing Riemann surfaces, which have “almost no traction in the computer world”), and makes use of the unwinding number introduced by Corless, Hare, and Jeffrey in 1996.
• The barycentric formulation of Lagrange interpolation is used extensively, possibly for the first time in a numerical analysis text. This approach was popularized by Berrut and Trefethen in their 2004 SIAM Review paper, and my proof of the numerical stability of the formulas has helped it to gain popularity. Polynomial interpolation and rational interpolation are both covered.
• Both numerical and symbolic computation are employed—whichever is the most appropriate tool for the topic or problem at hand. Corless is well known for his contributions to symbolic computation and to Maple, but he is equally at home in the world of numerics. Chebfun is also used in a number of places. In addition, section 11.7 gives a 2-page treatment of automatic differentiation.

This is a book that one can dip into at any page and quickly find something that is interesting and beyond standard textbook content. Not many numerical analysis textbooks include the Lambert W function, a topic on which Corless is uniquely qualified to write. (I note that Corless and Jeffrey wrote an excellent article on the Lambert W function for the Princeton Computation to Applied Mathematics.) And not so many use pseudospectra.

I like Notes and References sections and this book has lots of them, with plenty of detail, including references that I was unaware of.

As regards the differential equation content, it includes initial and boundary value problems for ODEs, as well as delay differential equations (DDEs) and PDEs. The DDE chapter uses the MATLAB dde23 and ddesd functions for illustration and, like the other differential equation chapters, discusses conditioning.

The book would probably have benefited from editing to reduce its length. The index is thorough, but many long entries need breaking up into subentries. Navigation of the book would be easier if algorithms, theorems, definitions, remarks, etc., had been numbered in one sequence instead of as separate sequences.

Part of the book’s charm is its sometimes unexpected content. How many numerical analysis textbooks recommend reading a book on the programming language Forth (a small, reverse Polish notation-based language popular on microcomputers when I was a student)? And how many would point out the 1994 “rediscovery” of the trapezoidal rule in an article in the journal Diabetes Care (Google “Tai’s model” for some interesting responses to that article).

I bought the book from SpringerLink via the MyCopy feature, whereby any book available electronically via my institution’s subscription can be bought in (monochrome) hard copy for 24.99 euros, dollars, or pounds (the same price in each currency!).

I give the last word to John Butcher, who concludes the Foreword with “I love this book.”

## Publication Peculiarities: Sequences of Papers

This is the third post is my sequence on publication peculiarities.

It is not unusual to see a sequence of related papers with similar titles, sometimes labelled “Part I”, “Part II” etc. Here I present two sequences of papers with intriguing titles and interesting stories behind them.

## Computing the Logarithm of a Complex Number

The language Algol 60 did not have complex numbers as a built-in data type, so it was necessary to write routines to implement complex arithmetic. The following sequence of papers appeared in Communications of the ACM in the 1960s and concerns writing an Algol 60 code to evaluate the logarithm of a complex number.

J. R. Herndon (1961). Algorithm 48: Logarithm of a complex number. Comm. ACM, 4(4), 179.

A. P. Relph (1962). Certification of Algorithm 48: Logarithm of a complex number. Comm. ACM, 5(6), 347.

M. L. Johnson and W. Sangren (1962). Remark on Algorithm 48: Logarithm of a complex number. Comm. CACM, 5(7), 391.

D. S. Collens (1964). Remark on remarks on Algorithm 48: Logarithm of a complex number. Comm. ACM, 7(8), 485.

D. S. Collens (1964). Algorithm 243: Logarithm of a complex number: Rewrite of Algorithm 48. Comm. CACM, 7(11), 660.

“Remark on remarks”, “rewrite”—what are the reasons for this sequence of papers?

The first paper, by Herndon, gives a short code (7 lines in total) that uses the arctan function to find the argument of a complex number $x+iy$ as $\arctan(y/x)$. Relph notes that the code fails when the real part is zero and that, because it adds $\pi$ to the $\arctan$, the imaginary part is on the wrong range, which should be $(-\pi,\pi]$ for the principal logarithm. Moreover, the original code incorrectly uses log (log to base 10) instead of ln (the natural logarithm).

It would appear that at this time codes were not always run and tested before publication, presumably because of the lack of an available compiler. Indeed Herndon’s paper was published in the April 1961 issues of CACM, and the first Algol 60 compilers had only become available the year before. according to this Wikipedia timeline.

Johnson and Sangren give more discussion about division by zero and obtaining the correct signs.

In his first paper, Collens notes that the Johnson and Sangren code wrongly gives $\log 0 = 0$ and has a missing minus sign in one statement.

Finally, Collens gives a rewritten algorithm that addresses the previously noted deficiencies. It appears to have been run, since some output is shown.

This sequence of papers from the early days of digital computing emphasizes that even for what might seem to be a trivial problem it is not straightforward to design correct, reliable algorithms and codes.

I am working on logarithms and other multivalued functions of matrices, for which many additional complications are present.

## Slow Manifolds

Edward Lorenz is well-known for introducing the Lorenz equations, discovering the Lorenz attractor, and describing the “butterfly effect”. His sequence of papers

E. N. Lorenz (1986). On the existence of a slow manifold. J. Atmos. Sci., 43(15), 1547–1557.

E. N. Lorenz and V. Krishnamurthy (1987). On the nonexistence of a slow manifold. J. Atmos. Sci., 44(20), 2940–2950.

E. N. Lorenz (1992). The slow manifold—What is it? J. Atmos. Sci., 49(24), 2449–2451.

seems to suggest a rather confused line of research!

However, inspection of the papers reveals the reasoning behind the choice of titles. The first paper discusses whether or not a slow manifold exists and shows that this question is nontrivial. The second paper shows that a slow manifold does not exist for one particular model. The third paper shows that the apparent contradiction to the second paper’s result by another author’s 1991 proof of the existence of a slow manifold for the same model can be explained by the use of different definitions of slow manifold.

## Companion Authors Speaking About Their Work

Paul Constantine

The authors of articles in The Princeton Companion to Applied Mathematics are very active in giving talks about their work and about the subject in general.

I have collected a set of links to videos (or, in some cases, audio captures with slides) of authors speaking on or around the topics of their Companion articles. These should give readers added insight into the topics and their authors.

At the time of posting all links were valid, but links have a habit of changing or disappearing. Please let me know of any new links that can be added to this list or existing ones that need changing.

Gil Strang

## The Rise of Mixed Precision Arithmetic

For the last 30 years, most floating point calculations in scientific computing have been carried out in 64-bit IEEE double precision arithmetic, which provides the elementary operations of addition, subtraction, multiplication, and division at a relative accuracy of about $10^{-16}$. We are now seeing growing use of mixed precision, in which different floating point precisions are combined in order to deliver a result of the required accuracy at minimal cost.

Single precision arithmetic (32 bits) is an attractive alternative to double precision because it halves the costs of storing and transferring data, and on Intel chips the SSE extensions allow single precision arithmetic to run twice as fast as double.

The Mandelbrot set computed in double and quadruple precision. Image taken from https://www.thasler.com/blog/blog/glsl-part5.

Quadruple precision arithmetic, which was included in the 2008 revision of the IEEE standard, is supported by some compilers, and it can be implemented in terms of double precision arithmetic via double-double arithmetic.

Arbitrary precision floating point arithmetic is available through, for example, the GNU MPFR library, the mpmath library for Python, the core data type BigFloat in the new language Julia, VPA arithmetic in the MATLAB Symbolic Math Toolbox, or the Advanpix Multiprecision Computing Toolbox for MATLAB.

Half precision arithmetic, in which a number occupies 16 bits, is supported by the IEEE standard for storage but not for computation. It has been argued that for deep learning half precision, with its relative accuracy of about $10^{-4}$, is good enough for training and running neural networks.

Here are some of the ways in which extra precision is currently being used.

• Iterative refinement, in the traditional form that first became popular in the 1960s, improves the quality of an approximate solution to a linear system via updates obtained from residuals computed in extra precision.
• When an algorithm suffers instability it may be possible to overcome it by using extra precision in just a few, key places. This has been done recently in eigensolvers and for matrix orthonormalization.
• Any iterative algorithm that accepts an arbitrary starting point can be run once at a given precision and the solution used to “warm start” a second run of the same algorithm at higher precision. This idea has been used recently in linear programming.
• Numerical integration of differential equations over long time periods may need higher precision in order to allow the phenomena of interest to be observed. A recent example is in the study of Kerr (rotating) black holes, where the underlying hyperbolic partial differential equation is solved using quadruple precision arithmetic running on GPUs.
• When one is developing error bounds or testing algorithms, one needs in principle the exact solution. In practice, a solution computed at high precision and rounded to the working precision is usually adequate, and this is an approach I frequently use in my work in numerical linear algebra.

As the relative costs and ease of computing at different precisions evolve, due to changing architectures and software, as well as the disruptive influence of accelerators such as GPUs, we will see an increasing development and use of mixed precision algorithms. In some ways this is analogous to the increasing interoperability of programming languages (illustrated by C++, Julia, and Python, for example): one uses the main tool (precision) one would like to work with and brings in other tools (precisions) as necessary in order to complete the task.

Posted in research | | 2 Comments

## Famous Mathematicians and The Princeton Companion

The Princeton Companion to Applied Mathematics has a 23-page Part I article “History of Applied Mathematics”, but apart from that it does not contain any articles with a historical or biographical emphasis. In designing the book we felt that the articles in Part II, “Equations, Laws and Functions of Applied Mathematics”, would provide a link into the history of applied mathematics through the various equations, laws, and functions included, most of which are eponymous.

John von Neumann

The index was produced by a professional indexer, who made a judgement on which of the many names in the book had significant enough mentions to index. A phrase “Newton’s method” would not generate an index entry for “Newton”, but a phrase describing something that Newton did might.

The index revealed some interesting features. First, there are many entries for famous mathematicians and scientists: 76 in total, ranging from to Niels Henrik Abel to Thomas Young. This means that even though there are no biographical articles, authors have included plenty of historical and biographical snippets. Second, many of the mathematicians might equally well have been mentioned in a book on pure mathematics (Halmos, Poincaré, Smale, Weil), which indicates the blurred boundary between pure and applied mathematics.

A third feature of the index is that the number of locators for the mathematicians and scientists that it contains varies greatly, from 1 to 20. We can use this to produce a highly non-scientific ranking. Here is a Wordle, in which the font size is proportional to the number of times that each name occurs.

The table of occurrences, which begins

 von Neumann, John 20 Poincaré, Henri 12 Bernoulli family 9 Courant, Richard 9 Prandtl, Ludwig 9 Gauss, Carl Friedrich 8 Kac, Mark 8 Maxwell, James Clerk 8 Merton, Robert 8 Runge, Carl 8 Shannon, Claude 8

can be found in this PDF file.

John von Neumann (1903–-1957) emerges as The Companion’s “most mentioned” applied mathematician. Indeed von Neumann was a hugely influential mathematician who contributed to many fields, as his index entry shows:

von Neumann, John: applied mathematics and, 56–59, 73; computational science and, 336–37, 350; economics and, 71, 644, 650, 869; error analysis and, 77; foams and, 740; Monte Carlo method and, 57; random number generation and, 762; shock waves and, 720; spectral theory and, 239–40, 426

von Neumann’s work has strong connections with my own research interests. With Herman Goldstine he published an important rounding error analysis of Gaussian elimination for inverting a symmetric positive definite matrix. He also introduced the alternating projections method that I have used to solve the nearest correlation matrix problem. And he derived important result on unitarily invariant matrix norms and singular value inequalities

More about von Neumann can be found in the biographies

## How to Use The Princeton Companion to Applied Mathematics

The Princeton Companion to Applied Mathematics, discussed in these previous posts, has a wide target audience, which includes mathematicians at undergraduate level or above; students, researchers, and professionals in other subjects who use mathematics; and mathematically interested lay readers.

Here are some examples of how different people can use the book.

• Undergraduate students can use it to get an overview of topics they are studying and to find out what areas of applied mathematics they might like to pursue at graduate level. Many of the articles have minimal pre-requisites (indeed some contain few, if any, equations). My article Color Spaces and Digital Imaging, for example, requires just knowledge of integration and basic linear algebra.
• A teacher might find useful the articles The History of Applied Mathematics and the four-part article Teaching Applied Mathematics, as well as the various short articles on interesting problems and applications (e.g., Cloaking, Bubbles, The Flight of a Golf Ball, Robotics, Medical Imaging, Text Mining, and Voting Systems).
• Researchers can use the book to find out about topics outside their area that they encounter in seminars but never have the time to study in the research literature.
• Engineers can use the book to find out about some of the latest mathematical developments relevant to their interests. The articles Aircraft Noise, Inerters, and Signal Processing, and the index entries “aerodynamics”, “energy-efficient buildings”, and “finite-element methods”, are good starting points.
• Students at all levels can learn about how to read and write mathematics, including the use of relevant computer tools, from several articles in Part VII, “Final Perspectives”.
• Anyone can use the book for reference. Although it is not a dictionary, encyclopedia, or handbook, The Companion‘s extensive index makes it easy to locate material, including definitions, equations, functions, laws, theorems, and so on.
• The book, produced with $\LaTeX$, is a great example of how to typeset mathematics, with examples of all kinds of equations, figures, and tables. For those learning $\LaTeX$ or new to mathematical typesetting it should be a source of ideas and inspiration. The $\LaTeX$ source code is not provided, but feel free to contact me with questions about how things were done and I will write a post that answers the most common questions.
• The final collection of articles, by mathematicians from China, France, the UK, and the USA, gives advice on how to make the case for mathematics to politicians, and will be of interest to anyone who wishes to promote the importance of mathematics.

## What is Applied Mathematics For?

Those of us working in applied mathematics are well aware that our field has many important uses in the real world. But if we are put on the spot during a conversation and asked to give some examples it can be difficult to conjure up a convincing list.

One response is to point people to The Princeton Companion to Applied Mathematics. Its 186 articles contains a large number of examples of how applied mathematics is put to work in fields such as sport, engineering, economics, physics, biology, computer science, and finance.

Another way to convince people of the value of applied mathematics is to get them to watch the 1-minute SIAM video below. It was constructed from interviews conducted at a variety of SIAM conferences and comprises snippets of 25 mathematicians saying what they use mathematics for.

Well done to Karthika Swamy Cohen and Michelle Montgomery at SIAM, Adam Bauser and his team at Bauser Media Group, and Sonja Stark at PilotGirl Productions, for producing this great advertisement for applied mathematics!

## Top Tips for New LaTeX Users

This article is aimed at relatively new $\LaTeX$ users. It is written particularly for my own students, with the aim of helping them to avoid making common errors. The article exists in two forms: this WordPress blog post and a PDF file generated by $\LaTeX$, both produced from the same Emacs Org file. Since WordPress does not handle $\LaTeX$ very well I recommend reading the PDF version.

## 1. New Paragraphs

In $\LaTeX$ a new paragraph is started by leaving a blank line.

Do not start a new paragraph by using \\ (it merely terminates a line). Indeed you should almost never type \\, except within environments such as array, tabular, and so on.

## 2. Math Mode

Always type mathematics in math mode (as $..$ or $$..$$), to produce “$y = f(x)$” instead of “y = f(x)”, and “the dimension $n$” instead of “the dimension n”. For displayed equations use $$, $..$, or one of the display environments (see Section 7). Punctuation should appear outside math mode, for inline equations, otherwise the spacing will be incorrect. Here is an example. • Correct: The variables x, y, and z satisfy x^2 + y^2 = z^2. • Incorrect: The variables x, y, and z satisfy x^2 + y^2 = z^2. For displayed equations, punctuation should appear as part of the display. All equations must be punctuated, as they are part of a sentence. ## 3. Mathematical Functions in Roman Mathematical functions should be typeset in roman font. This is done automatically for the many standard mathematical functions that $\LaTeX$ supports, such as \sin, \tan, \exp, \max, etc. If the function you need is not built into $\LaTeX$, create your own. The easiest way to do this is to use the amsmath package and type, for example, \usepackage{amsmath} ... % In the preamble. \DeclareMathOperator{\diag}{diag} \DeclareMathOperator{\inert}{Inertia}  Alternatively, if you are not using the amsmath package you can type \def\diag{\mathop{\mathrm{diag}}}  ## 4. Maths Expressions Ellipses (dots) are never explicitly typed as “…”. Instead they are typed as \dots for baseline dots, as in x_1,x_2,\dots,x_n (giving $x_1,x_2,\dots,x_n$) or as \cdots for vertically centered dots, as in x_1 + x_2 + \cdots + x_n (giving $x_1 + x_2 + \cdots + x_n$). Type ith instead of i'th or i^{th}. (For some subtle aspects of the use of ellipses, see How To Typeset an Ellipsis in a Mathematical Expression.) Avoid using \frac to produce stacked fractions in the text. Write $n^3/3$ flops instead of $\frac{n^3}{3}$ flops. For “much less than”, type \ll, giving $\ll$, not <<, which gives $<<$. Similarly, “much greater than” is typed as \gg, giving $\gg$. If you are using angle brackets to denote an inner product use \langle and \rangle: • incorrect: <x,y>, typed as <x,y>. • correct: $\langle x,y \rangle$, typed as \langle x,y \rangle ## 5. Text in Displayed Equations When a displayed equation contains text such as “subject to $x \ge 0$”, instead of putting the text in \mathrm put the text in an \mbox, as in \mbox{subject to x \ge 0}. Note that \mbox switches out of math mode, and this has the advantage of ensuring the correct spacing between words. If you are using the amsmath package you can use the \text command instead of \mbox. ### Example $$
\min\{\, \|A-X\|_F: \mbox{$X$ is a correlation matrix} \,\}.
$$ ## 6. BibTeX Produce your bibliographies using BibTeX, creating your own bib file. Note three important points. • “Export citation” options on journal websites rarely produce perfect bib entries. More often than not the entry has an improperly cased title, an incomplete or incorrectly accented author name, improperly typeset maths in the title, or some other error, so always check and improve the entry. • If you wish to cite one of my papers download the latest version of njhigham.bib (along with strings.bib supplied with it) and include it in your \bibliography command. • Decide on a consistent format for your bib entry keys and stick to it. In the format used in the Numerical Linear Algebra group at Manchester a 2010 paper by Smith and Jones has key smjo10, a 1974 book by Aho, Hopcroft, and Ullman has key ahu74, while a 1990 book by Smith has key smit90. ## 7. Spelling Errors and $\LaTeX$ Errors There is no excuse for your writing to contain spelling errors, given the wide availability of spell checkers. You’ll need a spell checker that understands $\LaTeX$ syntax. There are also tools for checking $\LaTeX$ syntax. One that comes with TeX Live is lacheck, which describes itself as “a consistency checker for LaTeX documents”. Such a tool can point out possible syntax errors, or semantic errors such as unmatched parentheses, and warn of common mistakes. ## 8. Quotation Marks $\LaTeX$ has a left quotation mark, denoted here \lq, and a right quotation mark, denoted here \rq, typed as the single left and right quotes on the keyboard, respectively. A left or right double quotation mark is produced by typing two single quotes of the appropriate type. The double quotation mark always itself produces the same as two right quotation marks. Example: $hello''$ is typed as \lq\lq hello \rq\rq. ## 9. Captions Captions go above tables but below figures. So put the caption command at the start of a table environment but at the end of a figure environment. The \label statement should go after the \caption statement (or it can be put inside it), otherwise references to that label will refer to the subsection in which the label appears rather than the figure or table. ## 10. Tables $\LaTeX$ makes it easy to put many rules, some of them double, in and around a table, using \cline, \hline, and the | column formatting symbol. However, it is good style to minimize the number of rules. A common task for journal copy editors is to remove rules from tables in submitted manuscripts. ## 11. Source Code $\LaTeX$ source code should be laid out so that it is readable, in order to aid editing and debugging, to help you to understand the code when you return to it after a break, and to aid collaborative writing. Readability means that logical structure should be apparent, in the same way as when indentation is used in writing a computer program. In particular, it is is a good idea to start new sentences on new lines, which makes it easier to cut and paste them during editing, and also makes a diff of two versions of the file more readable. ### Example: Good: $$
U(\zbar) = U(-z) =
\begin{cases}
-U(z),   & z\in D, \\
-U(z)-1, & \mbox{otherwise}.
\end{cases}
$$ Bad: $$U(\zbar) = U(-z) =
\begin{cases}-U(z),   & z\in D, \\
-U(z)-1, & \mbox{otherwise}.
\end{cases} ## 12. Multiline Displayed Equations For displayed equations occupying more than one line it is best to use the environments provided by the amsmath package. Of these, align (and align* if equation numbers are not wanted) is the one I use almost all the time. Example: \begin{align*} \cos(A) &= I - \frac{A^2}{2!} + \frac{A^4}{4!} + \cdots,\\ \sin(A) &= A - \frac{A^3}{3!} + \frac{A^5}{5!} - \cdots, \end{align*}  Others, such as gather and aligned, are occasionally needed. Avoid using the standard $\LaTeX$ environment eqnarray, because it doesn’t produce as good results as the amsmath environments, nor is it as versatile. For more details see the article Avoid Eqnarray. ## 13. Synonyms This final category concerns synonyms and is a matter of personal preference. I prefer \ge and \le to the equivalent \geq \leq\ (why type the extra characters?). I also prefer to use .. for math mode instead of $$..$$ and .. for display math mode instead of $..$. My preferences are the original $\TeX$ syntax, while the alternatives were introduced by $\LaTeX$. The slashed forms are obviously easier to parse, but this is one case where I prefer to stick with tradition. If dollar signs are good enough for Don Knuth, they are good enough for me!

I don’t think many people use $\LaTeX$‘s verbose

\begin{math}..\end{math}


or

\begin{displaymath}..\end{displaymath}


Also note that \begin{equation*}..\end{equation*} (for unnumbered equations) exists in the amsmath package but not in in $\LaTeX$ itself.

Posted in LaTeX | 8 Comments