2.1. Predicates and Quantifiers
Lecture 1 excluded "x is even" from the propositions because its truth depends on the unbound variable x. A predicate makes this dependence explicit. A predicate on a type α assigns a proposition to each element of α, so in Lean a predicate is a function of type α → Prop.
#check fun n : Nat => n > 3
Quantifiers bind the variable of a predicate and produce a proposition, and Table 2.1.1 names the two.G. Frege, Begriffsschrift, eine der arithmetischen nachgebildete Formelsprache des reinen Denkens, Verlag von Louis Nebert, Halle, 1879. We write P x for the proposition that the predicate P yields at x.
Symbol | Name | Reading |
|---|---|---|
∀ x, P x | universal quantifier | P x holds for every x |
∃ x, P x | existential quantifier | P x holds for some x |
Table 2.1.1. The two quantifiers, with their symbols and readings.
The quantifier binds its variable, so ∀ x, P x depends on no free variable and is a proposition. The variable ranges over a type. For example, ∃ n : Nat, n * n = 9 states that some natural number squares to 9. When the context determines the type, Lean infers it and we omit the annotation.
2.1.1. Examples
The examples below write predicates and quantified propositions and read their types with #check. A predicate has type α → Prop, and a quantified proposition, which binds its variable, has type Prop. The command #eval reports the truth value of a decidable predicate at a concrete point through decide.
Example 1. Applying a predicate to an argument yields a proposition.
#check (fun n : Nat => n < 5) 3
Example 2. A predicate may range over any type, strings among them.
#check fun s : String => s.length > 0
Example 3. A predicate of two arguments is a binary relation, a function into Prop in two stages.
#check fun m n : Nat => m ≤ n
Example 4. A universally quantified statement is a proposition.
#check ∀ n : Nat, n + 0 = n
Example 5. So is an existentially quantified one.
#check ∃ n : Nat, n > 100
Example 6. Nested quantifiers of different kinds still produce a proposition.
#check ∀ m : Nat, ∃ n : Nat, m < n
Example 7. The bound variable of an existential may range over strings.
#check ∃ s : String, s.length = 3
Example 8. A binary relation applied to both of its arguments is again a proposition.
#check (fun m n : Nat => m ≤ n) 2 3
Example 9. At a concrete point a decidable predicate has a computable truth value, here true.
#eval decide (3 < 5)
Example 10. The same computation reports false where the predicate does not hold.
#eval decide (2 = 3)