Encoding Logic: A LaTeX Primer

How to write the math you’ve just read

Harold Nelson

Why LaTeX?

  • Standardization: It is the industry standard for mathematical publishing and Computer Science papers.
  • Clarity: It forces you to think about the structure of your statement.
  • The Rule: All math logic in this course should be wrapped in dollar signs:
    • $ ... $ for inline math.
    • $$...$$ for standalone equations.

The “Big Three” Symbols

To write the logic from Section 1.1, you only need to memorize these three commands:

Concept Logical Symbol LaTeX Command
Universal \(\forall\) \forall
Existential \(\exists\) \exists
Conditional \(\to\) \to or \implies

Building a Statement: Step-by-Step

Goal: Write “For all \(x\), if \(x\) is an integer, then \(x\) is real.”

  1. Start with the Quantifier: \forall x (\(\forall x\))
  2. Add the Set (Optional): \in \mathbb{Z} (\(\in \mathbb{Z}\))
  3. Add the Conditional: \implies (\(\implies\))
  4. The Result: x \in \mathbb{R} (\(x \in \mathbb{R}\))

Full Code: $\forall x \in \mathbb{Z} \implies x \in \mathbb{R}$

The Logical “Punctuation”

Sometimes you need to separate your quantifiers from your predicates to make them readable.

Symbol Meaning LaTeX Command
Element of \(\in\) \in
Such that \(|\) or \(:\) | or :
Negation \(\neg\) \neg
Set of Integers \(\mathbb{Z}\) \mathbb{Z}
Set of Reals \(\mathbb{R}\) \mathbb{R}

The “Order Matters” Syntax

Remember our Mother/Child example? Here is how to code it:

\(\forall\) Person \(p, \exists\) Mother \(m\): $\forall p, \exists m : \text{isMother}(m, p)$

\(\exists\) Mother \(m, \forall\) Person \(p\): $\exists m, \forall p : \text{isMother}(m, p)$

Pro-Tip: Use \text{...} inside math mode to write normal words so they don’t look like \(slanted\) \(variables\).

Common Mistakes to Avoid

  1. Forgetting the Backslash: * forall will just look like \(forall\).
    • \forall becomes \(\forall\).
  2. Closing the Dollars: * Always ensure every $ has a matching $.
  3. Spaces: * LaTeX ignores most spaces in math mode. Use \, if you desperately need a small space, but usually, the symbols handle it.

Classroom Challenge: Live Code

Look at the following statement. Try to type the LaTeX code for it in your notes:

“There exists an \(n\) such that \(n\) is even and \(n > 10\).”

Solution: $\exists n \mid n \text{ is even} \land n > 10$

(Note: \land is the symbol for “and” \(\land\))

The Quick Reference Sheet

Keep these in your pocket:

  • \forall \(\to \forall\)
  • \exists \(\to \exists\)
  • \to \(\to \to\)
  • \mathbb{R} \(\to \mathbb{R}\) (Real Numbers)
  • \mathbb{Z} \(\to \mathbb{Z}\) (Integers)
  • \mathbb{Q} \(\to \mathbb{Q}\) (Rational Numbers)