Formal Software Verification

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.

fun n => n > 3 : Nat Prop#check fun n : Nat => n > 3
fun n => n > 3 : Nat  Prop

Quantifiers bind the variable of a predicate and produce a proposition.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

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.