Mathematical notation
This chapter was written with the assistance of GitHub Copilot, which expanded on outlined ideas and draft notes provided by the author. The content represents the author’s perspective and has been reviewed for accuracy, but the detailed prose was generated through AI assistance.
Notation is part of your prose, and readers parse it the same way they parse a sentence. This chapter collects notational habits that make quantitative writing easier to read.
1 Avoiding double inequalities
Prefer interval notation instead: \(x \in (a, b)\).
Interval notation is easier to read for three reasons:
- It states one relation instead of two, so the reader parses a single claim rather than combining a pair of them.
- It names the set you actually mean, so the same expression can be reused as a domain, a constraint, or the argument of a quantifier.
- It marks inclusive and exclusive endpoints with brackets and parentheses, which are easier to distinguish at a glance than \(\le\) and \(<\).
The same guidance applies to prose: write “for \(x \in (0, 1)\)” rather than “for \(x\) between 0 and 1, exclusive”.
1.0.1 When the middle term is not a single symbol
Interval notation works best when the quantity being constrained is a single expression. When the middle term is complicated, naming it first keeps the constraint short.
Finally, a chain that compares three different quantities — for example \(\hat{\theta}_1 < \hat{\theta}_2 < \hat{\theta}_3\) — is not a constraint on a single quantity, so interval notation does not apply. Write such comparisons as separate statements (\(\hat{\theta}_1 < \hat{\theta}_2\) and \(\hat{\theta}_2 < \hat{\theta}_3\)) unless the ordering of all three is the point you are making.
2 One operation per step
Write a derivation so that each displayed line does exactly one thing to the line before it: apply one rule, substitute one result, or simplify one piece. Give each line its own justification.
Combining steps saves the writer a line and costs every reader a calculation. A reader who cannot see how one line follows from the last has to redo the missing work on scratch paper, or take the step on trust. Either way, an error hidden inside a combined step is harder for the reader, or a reviewer, to catch. The advice on “Trivial” and “trivially” says to write out a step that takes only a line; this section applies that advice to the layout of a displayed derivation.
Common ways to combine steps without noticing:
- substituting a definition and then applying a rule to it (see Applying a definition is a step);
- applying the rule for the derivative of a sum and the chain rule in the same line;
- substituting a result and then simplifying it;
- multiplying constants and factoring them out of a sum;
- expanding a product and collecting like terms;
- canceling \(a\) in \(a + (b - a)\) removes the parentheses (\(a + b - a\)), reorders the terms (\(b + a - a\)), groups the two that cancel (\(b + (a - a)\)), replaces \(a - a\) with \(0\) (\(b + 0\)), and drops the \(+ 0\);
- canceling \(n\) in \(n \cdot \frac{b}{n}\) rewrites the division as multiplication by a reciprocal (\(n \cdot (b \cdot \frac{1}{n})\)), removes the parentheses (\(n \cdot b \cdot \frac{1}{n}\)), reorders the factors (\(b \cdot n \cdot \frac{1}{n}\)), groups the two that cancel (\(b \cdot (n \cdot \frac{1}{n})\)), replaces \(n \cdot \frac{1}{n}\) with \(1\) (\(b \cdot 1\)), and drops the \(\cdot 1\);
- writing “setting this to zero and dividing by \(-2n\) gives”, which hides two operations in a sentence.
2.0.1 Name a step by its standard rule
Justify a line with the standard name of the rule it applies, not an informal description of what it does to the symbols. Write “distribute the sum over the terms” rather than “split the sum”, and “factor the constant out of the sum” rather than “pull out the constant”. A standard name tells the reader which rule to check the line against; an informal one only describes the change.
2.0.2 Applying a definition is a step
Replacing a named quantity with its definition is one of the most important steps in a derivation. This replacement applies the general rules to the specific problem, so never skip it or merge it into the next step. Give it its own line, justified as “definition of …”. The same holds for a result from an earlier part of the same problem: substitute it on its own line, and cite the part.
2.0.3 Using a fact the reader has not seen
When a step relies on a fact the document has not yet shown, such as deviations from a mean summing to zero, prove that fact first, in its own short derivation or exercise, and cite that proof at the step that uses the fact. Don’t leave the fact as an unexplained justification.
2.0.4 Long derivations
Splitting every step makes derivations longer. Keep them readable by breaking them into stages: derive an intermediate result in its own block, then plug that result back into the main derivation. Naming a part of an expression that recurs in every line, such as writing \(d_i\) for \((y_i - \bar{y}) - \beta_x (x_i - \bar{x})\), can also keep each line short.
Show why you need a result before you derive it
Derive an intermediate result only after the main derivation has shown that it needs that result. For example, to differentiate a composite function:
- Start the main derivation, and apply the chain rule. The result is a product of an inner and an outer derivative, not yet known.
- Pause the main derivation, and derive the inner derivative in its own block.
- Derive the outer derivative in its own block.
- Return to the main derivation, and substitute both results.
A reader who encounters the inner derivative first does not yet know what it is for.
Color where a result is used
Give each intermediate result a text color, and use the same color wherever that result appears:
- in the line where a later step needs it, as a placeholder;
- in the line of its own derivation where it is found;
- in each line where it is substituted back in.
State the color key in words at the start of the derivation, so the derivation is still readable without color, for example in grayscale print or for readers who do not see color differences. Use \textcolor{name}{...}, which renders in HTML (MathJax) and in PDF.
3 One equals sign per line
Put at most one equals sign on each line of math. When a result takes two or more equalities, write them as an aligned display, with one equality per row, each row starting with &=.
A chain such as \(a = b = c\) on one line asks the reader to find where each step starts and ends, and to check every step at once. An aligned display puts each step on its own row, so the reader can check one row at a time, and the left-hand side, written once, stays visible above the rows that rewrite it. The rows also leave room for a justification at the end of each step, as One operation per step asks.
The rule applies wherever an equals sign appears:
- Inside an aligned display. A row such as
&= b = cis still a chain; split it into two rows. - In running text. An inline chain such as ❌ \(\bar{x} = \frac{6}{3} = 2\) becomes an aligned display, or two statements in the sentence.
- For a statement that several quantities are equal. Write ✅ \(H_0\colon \beta_j = 0\) for every \(j \in \{1, \ldots, p\}\) rather than ❌ \(H_0\colon \beta_1 = \beta_2 = \cdots = \beta_p = 0\), so that each claim is a single equality.
Separate equations set side by side, such as \(x = 1, \quad y = 2\), each have one equals sign, so they are not chains. They still read more easily as separate rows, or as separate statements in the text.
4 Functions and their values
A function and its value at a point are different objects. In \(\mu_i = \mu(x_i)\), \(\mu\) is a function, and \(\mu(x_i)\) is a number: the value of \(\mu\) at \(x_i\). Written with its placeholder argument, \(\mu(x)\) already denotes a value, so “the value of \(\mu(x)\) at \(x_i\)” names a value of a value. Either drop the placeholder and write “the value of \(\mu\) at \(x_i\)”, or keep the placeholder and name the substitution: “\(\mu(x)\) evaluated at \(x_i\)”.
Use the notation to match:
- Write \(\mu\), or “the mean function”, for the function itself.
- Write \(\mu(x)\) with a placeholder argument where you introduce or define the function, to show what its argument is, as in “a mean function \(\mu(x)\)” or \(\mu(x) := \beta_0 + \beta_x x\), and say “evaluated at” when you substitute a point into it.
- Write \(\mu(x_i)\), or “the value of \(\mu\) at \(x_i\)”, for a value.
Define the fitted value once, then print \(\hat{y}_i\), not \(h(x_i)\), wherever it appears in a loss, a residual or a risk sum. Keep \(h(x)\) where \(h\) itself is the subject, as in “the linear function \(h(x) = \beta_0 + \beta_x x\)”, and where the output is not a prediction of \(y_i\), such as the decision score of a support vector machine or a vector of class probabilities.
In the source, a document that uses the shared macros writes the fitted value with the macro for a predicted outcome, \eoutvar (see Using shared macros), and a document without them may write \hat{y}.
5 Types of functions and procedures
Name the type of every function and procedure when you define it:
- the set it takes its argument from (its domain)
- the set its values lie in (its codomain)
- for each input and output, what kind of mathematical object it is
Say “function”, not “rule” or “map”.
A procedure that takes several inputs is a function of all of them, so list each input with its type. When an output is itself a function, say so and give its domain and codomain too.
A function’s argument is not part of what specifies the function. Give the argument in the definition, as the domain, and list only the other inputs as what specifies the function.
Check each use against the stated types: a function applied to something outside its domain, or a value described with the wrong type, is an error even when the notation looks right.
6 Random variables and their values
A random variable and a value that it takes are different objects. Before the data are collected, the outcome is a random variable; after, it is a number. Statements about the two have different meanings. Write them with different symbols.
Use a capital letter for the random variable and the matching lowercase letter for a value that it takes:
- \(Y\) is the random variable, such as the outcome of a coin flip before the flip;
- \(y\) is one value of \(Y\), such as 1 after the flip lands heads;
- \(Y_i\) is the random variable for the \(i\)-th observation;
- \(y_i\) is that observation’s observed value.
State the convention where you first use the symbols. Keep it in every later section. Do not switch between \(Y_i\) and \(y_i\) for the same quantity unless the meaning changes from “before the data” to “after the data”.
Match the notation to the claim:
- Write \(\Pr(Y \le y)\) for a probability, with the random variable on the left of the inequality and the value on the right.
- Write \(\text{E}[Y]\) and \(\text{Var}(Y)\) for the mean and variance of a random variable, never \(\text{E}[y]\) or \(\text{Var}(y)\) for an observed value.
- Write a statistic computed from observed values with lowercase letters, as in \(\bar{y} = \frac{1}{n}\sum_{i=1}^n y_i\), and the same statistic as a random variable with capitals, \(\bar{Y} = \frac{1}{n}\sum_{i=1}^n Y_i\). The first is a number, such as 2.4. The second has a sampling distribution.
Name the kind of object in the words, too, not only in the symbol. Call a random variable a “variable”, such as “the output variable \(\Outvar\)”, and call a number a “value”, such as “the input value \(\predvar\)” or “the observed value \(\outvar\)”. Do not say “fix \(\predvar\)” or “let \(\predvar\) be fixed”. It does not say whether \(\predvar\) is a variable held constant or a value you chose. Say “choose an input value \(\predvar\)”, or “take the observed value \(\outvar\) as given”.
Some fields reserve capital letters for matrices, or use the same letter for a random variable and its value. In that case, say so where you introduce the symbols. Add a word that tells the reader which meaning applies, such as “the random variable \(Y_i\)” or “the observed value \(y_i\)”.
7 Matching names and notation
A name and its notation must describe the same object. When you name a quantity in words and also show it in symbols, use the symbols that go with that name. A reader who sees the name “dot product” expects to see the notation for a dot product. If the symbols look like a different operation, the reader has to work out whether the name or the symbols is wrong.
Keep the pairing the same everywhere the quantity appears. Notes, assignments, solutions and slides in one course should use one name and one notation for each quantity. When two fields call one idea by different names, choose one name, list the other names where you define the idea, and use only the chosen name afterward (see Name the synonyms).
Before you release a document that reuses a quantity from another one, search both for its name and its symbols, and make them agree.
7.0.1 Label every inline symbol
In prose, write a text label next to every inline math symbol. The label tells the reader what the symbol stands for without making them search for its definition. Put the label before the symbol, as in “the population noise variance, \(\sigma^2\)”.
9 Making expressions concise
Make each expression as concise as possible. The less clutter an expression has, the easier it is to read. This is one case of building every unit from smaller atomic units.
Before you finish a definition, theorem or proof, scan it for a sub-expression that is written out in full more than once, or that is a conceptually coherent chunk even if it appears only once, such as the prediction error (the fitted value minus the outcome) or the loss of a prediction on one observation. Give the chunk a name and a macro, and write the macro everywhere the chunk appears.
Write each expression in its most compact form, built from named sub-pieces that are defined separately. Use one form per expression, and keep it simple. For example, write the expected squared prediction error as the squared bias plus the variance plus the residual variance, and define each of the three pieces on its own, instead of expanding them inside the formula.
Search the shared macros for the chunk before you write it by hand. A macro often exists already, and any expression spelled out in full that a macro or a shorter form could say is the sign that nobody looked. A difference is only the commonest case. For example, an exercise wrote the left side of the bias–variance decomposition as \E{\paren{\newoutvar - \predvalf{\newpredval}}^2}, when \prederrf{\predvalf{\newpredval}} names the same prediction error, and the squared bias, written out the same way, has \biassymf. When you find one such chunk, sweep the other notes repositories for it, in small batches of one repository each.
Add the macro to the shared macro file before you use it, never as a local macro in one document (see Using shared macros), and record its meaning in that file’s interpretations.tsv.
10 Abstracting sub-expressions you are not manipulating
Replace each sub-expression that you are not manipulating with a symbol that stands for it. Keep a sub-expression written out only on the line where you are about to apply its definition, a rule or a theorem to it. Every other line shows the symbol.
This is one case of making each expression as concise as possible. It also asks for the habit behind that advice: split a long expression into short named pieces, and give each piece the symbol or shared macro that names its concept.
Choose the symbol to match the thing it names. For the population mean \(\E{X}\), write \(\mu\). Add a subscript, such as \(\mu_X\), only when the context holds a second mean and the reader could confuse the two. State the abstraction once, in a sentence such as “Let \(\mu = \E{X}\)”, before the first line that uses the symbol.
11 Writing dot products
When two vectors multiply to give a number, write the product as a dot product, \(\tilde{x} \cdot \tilde{\beta}\). Do not write it as a transpose product, \(\tilde{x}' \tilde{\beta}\), or with inner-product brackets, \(\langle \tilde{x}, \tilde{\beta} \rangle\). The dot shows one operation on two vectors. A transpose product asks the reader to picture a row vector times a column vector and to work out that the result is a single number.
Keep the transpose where the product is not a dot product of two vectors:
- a product of matrices, such as \(X'X\)
- an outer product, such as \(\tilde{x}\tilde{x}'\)
- a quadratic form, such as \(\tilde{x}' A \tilde{x}\)
Keep the inner-product brackets where the text means any inner product, such as a definition of an inner product space.
12 Using the notation that best represents the concept
Use the notation that best represents the concept being depicted. Choose the symbol, the macro and the name by asking what the object is, not by asking what is quicker to type or what the nearby text used. A symbol that fits a different concept sends the reader to the wrong idea.
The rules that follow are cases of this principle:
- The predictor matrix and the design matrix are different objects, so they get different symbols.
- The mean function is a mean, so it is \(\truemean\), not \(\predfn\).
- The fitted prediction function is a prediction function, so it is named as one, not as a fitted mean function.
- A reference formula is a general statement, so it is written in its general form, not for one example.
When no rule covers a case, ask the same question: which symbol, name and form best represents the concept here? Then record the answer as a rule, with this principle as its reason.
13 Writing the predictor and design matrices
Write a matrix in matrix styling, not in the plain italic of a scalar. This holds for the predictor matrix \(\mX\) in every file you edit: notes, assignments, solutions, slides and note sheets. A plain italic \(X\) suggests a random variable or a single number. In a group that uses shared macros (see Using shared macros), write the predictor matrix with the matrix macro \mX.
Keep two objects apart, because they are not the same matrix:
- The predictor matrix holds the raw inputs. Its rows are the predictor vectors \(\vx_i\) of the \(n\) observations. Write it
\mX. - The design matrix holds the inputs after any feature map and the intercept trick. Its rows are the design vectors \(\vfeatmap(\vx_i)\). Write it
\design(\mX), or\designfor short.
The same split holds for one observation: the predictor vector is \vx, and the design vector is \vfeatmap(\vx). Without a feature map or an intercept column, the design matrix equals the predictor matrix, but say so rather than reuse one symbol for both.
14 Stating formulas in their general form
On a reference sheet, a formula sheet or a summary, state each formula in its general form. Do not state it only for a specific example. A reader looks a formula up to apply it to a new case, and an example shows only one case.
Put a specific case on the sheet only as a labeled example next to the general formula.
15 Writing the mean function and the prediction function
Write the mean function as \(\truemean\), not as \(\predfn\). The mean function is the population mean of the outcome given the inputs, \(\truemeanf{x}\). In a group that uses shared macros (see Using shared macros), write it \truemeanf{x}.
Name the object you mean. When the text refers to the fitted prediction function as a concept, the rule that turns an input into a predicted outcome, write the fitted prediction function, not the fitted mean function. Write it \epredfnf{x} (symbol \(\epredfn\)) for an estimated one, or \predfnf{x} (symbol \(\predfn\)) for any prediction function. Use the fitted or estimated mean function only where the text is about estimating the mean function \(\truemean\) itself.
16 Writing the log-odds
Use \(\logodds\) (the Greek letter eta) for the log-odds, not \(z\) or another letter. In a group that uses shared macros (see Using shared macros), write it \logodds. Use it wherever the quantity is the log-odds, including the argument of the logistic function, so that the same quantity has one symbol in every chapter and figure. Label a figure axis that shows it “Log-odds, \(\logodds\)” (see Scientific figures).
17 Writing out notational shorthands
A notational shorthand drops part of an expression that the writer expects the reader to fill in. The commonest case is leaving the limits off a sum, product, or integral, as in \(\sum_x f(x)\). In permanent writing (notes, papers, and published slides), write the full form instead: \(\sum_{x \in \mathcal{R}(X)} f(x)\), where \(\mathcal{R}(X)\) is the set of values that \(X\) can take.
The full form costs the writer a few characters and saves every reader a guess. A reader who sees \(\sum_x\) has to work out which values of \(x\) the sum runs over, and readers who work out different answers will disagree about what the expression means. The full form also exposes mistakes. If a count variable takes only non-negative values, a sum written as \(\sum_{x \in \mathbb{Z}}\) shows the wrong set at a glance, while \(\sum_x\) hides the same mistake.
Give the limits of every sum, product, and integral, and state the set that any other index runs over. Board work during a lecture is often less complete, but it should still aim for the full form. The notation page of the Math for Data Science notes catalogs common shorthands and their full forms.
18 Stating assumptions before using them
State each assumption before the step that uses it. A reader processes a derivation line by line, and a condition that arrives after the line it governs forces them to go back and reread that line with the condition in mind. A first-time reader may not realize the line was incomplete, and may conclude that the step is wrong or unjustified.
This covers every kind of condition:
- a restriction on a variable (“for \(x \neq 2\)”);
- a hypothesis of a theorem;
- a case split;
- a fact that a step relies on.
Introduce the variable and its constraint together, as in “let \(x \neq 2\)”, then write the steps that need the constraint. When a step uses a fact proved earlier, cite it in the justification on that line.
An assumptions list and a notation list are different lists:
- An assumptions list states conditions that the result depends on. Write it as a bullet list under “Assume:”.
- A notation list names objects. Write it as a bullet list under “Let:”.
A condition that can fail is an assumption. A parametrization is not: it writes a quantity in terms of named parameters or pieces, so it holds by definition and goes under “Let:”. Do not label a parametrization as an assumption, because that tells the reader a condition is being imposed when none is.
Write the lead-in word once, before the list, and make each bullet complete the lead-in sentence. Do not repeat the word in every bullet, and do not mix the two kinds of list in one list. When both are needed, write the notation list first, because the assumptions use the names it introduces.