Prime symbol in variable names

From Why start at x, y, z
Revision as of 09:32, 13 July 2021 by Christian Lawson-Perfect (talk | contribs) (→‎Alternatives)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


The prime symbol (\(\prime\)) is often used to distinguish between variable names. For example, given a variable \( f \), some authors might use \( f' \) as a separate variable name, which may or may not be related to the original \( f \). If more than one variation is needed, it is not uncommon to see two or more tick marks, as in \( f, f', f'', f''', f'''', \dots \).

Disadvantages

In calculus, the prime symbol is usually used to indicate differentiation, making the use of the prime symbol ambiguous when naming variables.

In some fonts, the tick mark might be too small to read.

This naming convention is popular enough that programming languages like Haskell and Coq permit the single quote symbol ' as a valid identifier. Code is normally displayed in a monospace font, where extra space before the single quote may make the tick mark appear visually separated from the identifier that it modifies.

In monospace fonts, whitespace around the single quote ' often causes it to appear visually separated from the identifier that it modifies. As an example,

Alternatives

For Pairs:

  • Primes: (\( f, f' \))
  • Numbers: (\( f_0, f_1 \)) or (\( f_1, f_2 \))
  • Letter Pairs: (\( f, g \))

For Sequences:

  • Primes: \( a, a', a'', a''', \dots \),
  • Numbers: \( a_0, a_1, a_2, a_3 \dots \)
  • Letters: \( a, b, c, d \dots \)