Formal Software Verification

2.3. The Existential Quantifier🔗

To prove ∃ x, P x, exhibit a witness and prove the proposition at it. The anonymous constructor of Lecture 1 pairs the witness with the proof. The term rfl proves an equation whose two sides compute to the same value.

example : n : Nat, n * n = 9 := 3, rfl

The tactic exists provides the witness in tactic mode and closes the remaining goal when it holds by computation.

example : n : Nat, n * n = 9 := n, n * n = 9 All goals completed! 🐙

To use a hypothesis h : ∃ x, P x, name a witness and the proof that it satisfies P. The proposition ∃ x, P x has the single constructor intro, so the tactic cases treats it as it treated disjunction in Lecture 1, now with one case.

example (α : Type) (P Q : α Prop) (h : x, P x Q x) : x, P x := α:TypeP:α PropQ:α Proph: x, P x Q x x, P x cases h with α:TypeP:α PropQ:α Propa:αha:P a Q a x, P x All goals completed! 🐙

The tactic obtain destructures the hypothesis in one step, with a pattern that mirrors the anonymous constructor.

example (α : Type) (P Q : α Prop) (h : x, P x Q x) : x, Q x := α:TypeP:α PropQ:α Proph: x, P x Q x x, Q x α:TypeP:α PropQ:α Propa:αha:P a Q a x, Q x All goals completed! 🐙

The theorem below combines the two quantifiers. A pointwise implication carries existence from P to Q, and the witness does not change.

theorem exists_imp_exists (α : Type) (P Q : α Prop) (h : x, P x Q x) : ( x, P x) x, Q x := α:TypeP:α PropQ:α Proph: (x : α), P x Q x( x, P x) x, Q x α:TypeP:α PropQ:α Proph: (x : α), P x Q xhex: x, P x x, Q x α:TypeP:α PropQ:α Proph: (x : α), P x Q xa:αhPa:P a x, Q x All goals completed! 🐙