Formal Methods 101: First-Order Logic (FOL)

This is part 4 of 11 in the Formal Methods 101 series. It extends the propositional logic from part 3 with variables and quantifiers.

Introduction

First-order logic (FOL) extends zero-order (propositional) logic to include variables and quantifiers.

Its operators are used to form expressions over variables. These expressions are known as predicates: Boolean-valued functions that return TRUE or FALSE depending on the values assigned to their variables.

First-order logic is made up of logical symbols (negation, binary connectives and quantifiers) and non-logical symbols (predicate symbols and functions).

Non-logical symbols

Predicate variables

  • A predicate variable (symbol) with a valence of 0: A
  • A predicate variable (symbol) with a valence of 2: A(b, d)

A predicate variable is Boolean-valued, so it may take the value TRUE (1) or FALSE (0). A predicate may have n arguments and is said to have a valence (or arity, the number of arguments) from 0 up to n. The argument values determine whether the predicate evaluates to TRUE or FALSE.

Functions

An example function is f(b, v). This follows the standard definition of a function, which is not required to return a Boolean value.

Logical symbols

The connectives are the same as in propositional logic, applied to predicates.

OperatorSymbolExample predicateTrue when
Negation (NOT)¬¬AA is assigned FALSE
Conjunction (AND)∧A ∧ BA and B are both assigned TRUE
Disjunction (OR)∨A ∨ Bat least one of A and B is assigned TRUE
Material implication→A → BB is TRUE, or A is FALSE
Material bijection↔A ↔ BA and B are assigned the same value
  • Negation: if A is assigned TRUE, the predicate ¬A evaluates to FALSE; if A is assigned FALSE, ¬A evaluates to TRUE.
  • Conjunction: the predicate is TRUE if and only if (iff) the variables A and B are both assigned TRUE.
  • Disjunction: the predicate is TRUE iff A or B (or both) is assigned TRUE.
  • Material implication: if A is TRUE, then B is TRUE. It gives no information about B when A is not TRUE. The predicate may be TRUE or FALSE depending on whether it breaks the rule of material implication.
  • Material bijection: if A is TRUE, then B is TRUE, and if B is TRUE, then A is TRUE; if A is FALSE, then B is FALSE, and if B is FALSE, then A is FALSE. The values of A and B are never different. It is equivalent to implication both ways, (A → B) ∧ (B → A), and the predicate may be TRUE or FALSE depending on whether it breaks that rule.

Quantifiers

The two quantifiers bind a variable over the domain of discourse. ∀ (for all) says a predicate holds for every element of the domain, and ∃ (there exists) says it holds for at least one.

Left: the predicate Even(x) over the domain 1 to 4 is false, true, false, true, so there exists an x with Even(x) (witness 2) but not for all x (counterexample 1). Right: over {1, 2, 3}, every x has a larger y except 3, so for all x there exists y with x less than y is false.
Two small domains. On the left, one witness is enough for ∃ but one counterexample defeats ∀. On the right, the nested quantifiers ∀x ∃y (x < y) fail because the largest element has no larger partner.

Order of operations

Operators are evaluated in this order:

  1. ¬ is evaluated first.
  2. ∧ is evaluated next.
  3. ∨ is evaluated next.
  4. The ∀ and ∃ quantifiers are evaluated next.
  5. → is evaluated last (and so is ↔).

In the examples I put the quantified formula in parentheses, so its scope is explicit whichever precedence convention is used.

An example predicate

∀B ∃A ( (C(x, y) ∧ ¬D) → ((A ∧ E(t, z)) ∨ F) )

This reads: for all B, there exists an A such that, C and not D implies A and E, or F.

As the example shows, first-order logic is very expressive. It can be used to build extensive, complex models of a domain of discourse.