I had never seen this issue before, but it makes sense, although one could probably argue that it is a bug in inversion
.
This problem is due to the fact that inversion
is implemented by case analysis. In Coq's logic, one cannot in general perform case analysis on a logical hypothesis (i.e., something whose type is a Prop
) if the result is something of computational nature (i.e., if the sort of the type of the thing being returned is a Type
). One reason for this is that the designers of Coq wanted to make it possible to erase proof arguments from programs when extracting them into code in a sound way: thus, one is only allowed to do case analysis on a hypothesis to produce something computational if the thing being destructed cannot alter the result. This includes:
- Propositions with no constructors, such as
False
.
- Propositions with only one constructor, as long as that constructor takes no arguments of computational nature. This includes
True
, Acc
(the accessibility predicated used for doing well-founded recursion), but excludes the existential quantifier ex
.
As you noticed, however, it is possible to circumvent that rule by converting some proposition you want to use for producing your result to another one you can do case analysis on directly. Thus, if you have a contradictory assumption, like in your case, you can first use it to prove False
(which is allowed, since False
is a Prop
), and then eliminating False
to produce your result (which is allowed by the above rules).
In your example, inversion
is being too conservative by giving up just because it cannot do case analysis on something of type 0 < 0
in that context. It is true that it can't do case analysis on it directly by the rules of the logic, as explained above; however, one could think of making a slightly smarter implementation of inversion
that recognizes that we are eliminating a contradictory hypothesis and adds False
as an intermediate step, just like you did. Unfortunately, it seems that we need to do this trick by hand to make it work.