Your question touches an interesting aspect of Coq: the difference between propositions (i.e., members of Prop
) and booleans (i.e., members of bool
). Explaining this difference in detail would be somewhat too technical, so I'll just try to focus on your particular example.
Roughly speaking, a Prop
in Coq is not something that evaluates to either True
or False
, like a regular boolean does. Instead, Prop
s have inference rules that can be combined to infer facts. Using those, we can show that a proposition holds, or show that it is contradictory. What makes things subtle is that there is a third possibility, namely that we're not able to either prove or refute the proposition. This happens because Coq is a constructive logic. One of the most well-known consequences of this is that the familiar reasoning principle known as the excluded middle (forall P : Prop, P \/ ~ P
) can't be proved in Coq: if you assert that P \/ ~ P
, this means you're either able to prove P
or to prove ~ P
. You can't assert this without knowing which one holds.
It turns out that for some propositions, we can show that P \/ ~ P
holds. For instance, it is not hard to show forall n m : nat, n = m \/ n <> m
. Following the above remark, this means that for every pair of natural numbers, we are able to produce a proof that they are equal or a proof that they aren't.
On the other hand, if we change nat
to Set
, like in your example, then we will never be able to prove the theorem. To see why, consider the Set
nat * nat
of pairs of natural numbers. If we were able to prove your theorem, then it would follow that nat = nat * nat \/ nat <> nat * nat
. Again, by the above remark, this means that we're either able to prove nat = nat * nat
or nat <> nat * nat
. However, because there is a bijection between both types, we can't say that it is contradictory to assume nat = nat * nat
, but because the types are not syntactically equal, it is also OK to assume that they are different. Technically speaking, the validity of the proposition nat = nat * nat
is independent of Coq's logic.
If you really need the fact that you mentioned, then you need to assert the excluded middle as an axiom (Axiom classical : forall P, P \/ ~ P.
), which will allow you to produce proofs of \/
without having an explicit proof of either side and to reason by cases. Then you would be able to proof your example theorem with something like
intros a b. destruct (classical (a = b)).
left. assumption.
right. assumption.
Hope this helps.
A \/ ~A
, or do you have in mind an example which assumes your specific disjuntiona = b \/ a <> b
? – hardmath