How to give a counterxample in Coq?
Question
Is it possible to give a counterexample for a statement which doesn't hold in general? Like, for example that the all quantor does not distribute over the connective or. How would you state that to begin with?
Parameter X : Set. Parameter P : X -> Prop. Parameter Q : X -> Prop. (* This holds in general *)(forall x : X, P x /\ Q x) -> (forall x : X, P x) /\ (forall x : X, Q x)(forall x : X, P x /\ Q x) -> (forall x : X, P x) /\ (forall x : X, Q x)H: forall x : X, P x /\ Q x(forall x : X, P x) /\ (forall x : X, Q x)H: forall x : X, P x /\ Q xforall x : X, P xH: forall x : X, P x /\ Q xforall x : X, Q xapply H. Qed. (* This doesn't hold in general *)H: forall x : X, P x /\ Q xforall x : X, Q xAbort.(forall x : X, P x \/ Q x) -> (forall x : X, P x) \/ (forall x : X, Q x)
Answer (Ptival)
Here is a quick and dirty way to prove something similar to what you want:
~ (forall (X : Type) (P Q : X -> Prop), (forall x : X, P x \/ Q x) -> (forall x : X, P x) \/ (forall x : X, Q x))~ (forall (X : Type) (P Q : X -> Prop), (forall x : X, P x \/ Q x) -> (forall x : X, P x) \/ (forall x : X, Q x))H: forall (X : Type) (P Q : X -> Prop), (forall x : X, P x \/ Q x) -> (forall x : X, P x) \/ (forall x : X, Q x)FalseH: forall (X : Type) (P Q : X -> Prop), (forall x : X, P x \/ Q x) -> (forall x : X, P x) \/ (forall x : X, Q x)forall x : bool, x = true \/ x = falseH: forall (X : Type) (P Q : X -> Prop), (forall x : X, P x \/ Q x) -> (forall x : X, P x) \/ (forall x : X, Q x)
X: forall x : bool, x = true \/ x = falseFalsedestruct x; intuition.H: forall (X : Type) (P Q : X -> Prop), (forall x : X, P x \/ Q x) -> (forall x : X, P x) \/ (forall x : X, Q x)forall x : bool, x = true \/ x = falseH: forall (X : Type) (P Q : X -> Prop), (forall x : X, P x \/ Q x) -> (forall x : X, P x) \/ (forall x : X, Q x)
X: forall x : bool, x = true \/ x = falseFalseH: (forall x : bool, (fun b : bool => b = true) x) \/ (forall x : bool, (fun b : bool => b = false) x)
X: forall x : bool, x = true \/ x = falseFalseH: forall x : bool, x = true
X: forall x : bool, x = true \/ x = falseFalseH: forall x : bool, x = false
X: forall x : bool, x = true \/ x = falseFalsenow specialize (H true). Qed.H: forall x : bool, x = false
X: forall x : bool, x = true \/ x = falseFalse
I have to quantify X, P and Q inside the negation in order to be able to provide the one I want. You couldn't quite do that with your Parameters as they somehow fixed an abstract X, P and Q, thus making your theorem potentially true.
Answer (Yves)
In general, if you want to produce a counterexample, you can state the negation of the formula and then prove that this negation is satisfied.