Can someone please give me a simple example of existential instantiation and existential generalization in Coq? When I want to prove exists x, P
, where P
is some Prop
that uses x
, I often want to name x
(as x0
or some such), and manipulate P. Can this be one in Coq?

- 104,111
- 38
- 209
- 254

- 1,378
- 11
- 23
-
i know there have been coq questions here in the past, but i suspect that as more sites are introduced the best place for coq questions is now http://cs.stackexchange.com/ (not so happy with the fragmentation myself, but it's a fact of life...) – andrew cooke May 21 '12 at 14:53
-
3@andrewcooke [This hasn't been established conclusively.](http://meta.cs.stackexchange.com/questions/52/scope-limits-on-proof-assistants-e-g-coq) My feeling is that Coq questions are more on-topic on SO if the goal is to get a proof done, and on [cs.se] if the goal is to understand why a proof technique is working or not working, but it's a very thin line. The expertise is spread over [so], [cs.se] and [cstheory.se]. – Gilles 'SO- stop being evil' May 21 '12 at 21:59
1 Answers
If you're going to prove the existential directly and not through a lemma, you can use eapply ex_intro
. This introduces an existential variable (written ?42
). You can then manipulate the term. To complete the proof, you need to eventually provide a way to construct a value for that variable. You can do this explicitly with the instantiate
tactic, or implicitly through tactics such as eauto
.
Beware that it is often cumbersome to work with existential variables. Many tactics assume that all terms are instantiated and may hide existentials in subgoals; you'll only find out when Qed
tells you “Error: Attempt to save an incomplete proof”. You should only use existential variables when you have a plan to instantiate them soon.
Here's a silly example that illustrates the use of eapply
.
Goal exists x, 1 + x = 3.
Proof. (* ⊢ exists x, 1 + x = 3 *)
eapply ex_intro. (* ⊢ 1 + ?42 = 3 *)
simpl. (* ⊢ S ?42 = 3 *)
apply f_equal. (* ⊢ ?42 = 2 *)
reflexivity. (* proof completed *)
Qed.

- 15,074
- 2
- 23
- 43

- 104,111
- 38
- 209
- 254
-
3With Coq trunk you can turn uninstantiated existentials into subgoals at the end of the proof - which is something I wished for for a long time. – Robin Green May 23 '12 at 19:33
-
2An addition to [the previous comment](https://stackoverflow.com/questions/10686164/existential-instantiation-and-generalization-in-coq#comment13933112_10693631): this can be done with [`Grab Existential Variables.`](https://coq.inria.fr/refman/Reference-Manual009.html#GrabEvars) – Anton Trunov Jun 07 '17 at 09:58