I am using the Coq Proof Assistant to implement a model of a (small) programming language (extending an implementation of Featherweight Java by Bruno De Fraine, Erik Ernst,
I ran into a similar problem and Coq 8.3's "dependent induction" tactic took care of business.
I was sure CPDT had some commentary on this issue, but it's not entirely obvious where it is. Here are some links:
http://adam.chlipala.net/cpdt/html/Cpdt.Predicates.html Section "Predicates with Implicit Equality" shows perhaps the very simplest case where Coq "loses information" (on a destruct, rather than an induction.) It also explains WHY this information is lost: when you destruct a type applied to an argument which is not a free variable, those types are replaced with free variables first (which is why Coq loses the information.)
http://adam.chlipala.net/cpdt/html/Cpdt.Universes.html Section "Methods for Avoiding Axioms" shows some tricks for avoiding axiom K, including the "equality trick" described by Gilles. Search for "using a common equality-based trick for supporting induction on non-variable arguments to type families"
I think that this phenomenon is closely related to dependent pattern matching.
This is a general problem when you need to induct over a hypothesis with a dependent type (sub_type (c_typ u) (c_typ v)
) whose parameters have a particular structure (c_typ u
). There is a general trick, which is to selectively rewrite the structured parameter to a variable, keeping the equality in the environment.
set (t1 := c_typ u) in H; assert (Eq1 : t1 = c_typ u) by reflexivity; clearbody t1.
set (t2 := c_typ u) in H; assert (Eq2 : t2 = c_typ u) by reflexivity; clearbody t2.
induction H. (*often "; try subst" or "; try rewrite Eq1; try rewrite Eq2" *).
Since Coq 8.2, this common set-assert-clearbody pattern is performed by the built-in tactic remember term as ident in *goal_occurences*
.
Here's a silly lemma proved using this tactic.
Lemma subtype_r_left_equal :
forall r1 t2, sub_type (r_typ r1) t2 -> r_typ r1 = t2.
Proof.
intros.
remember (r_typ r1) as t1 in H.
induction H.
congruence.
solve [firstorder].
discriminate.
Qed.
Bonus tip (from experience, but it's been a while so I don't remember the details): when you're doing fairly syntactic reasoning on type systems (which tends to be the case when you do these kinds of mechanical proofs), it can be convenient to keep typing judgements in Set
. Think of typing derivations as objects you're reasoning about. I remember cases where it was convenient to introduce equalities on typing derivation, which doesn't always work with typing derivations in Prop
.
With your Problem.v
, here's a proof of the reflexivity case. For transitivity, I suspect your induction hypothesis isn't strong enough. This may be a byproduct of the way you simplified the problem, though transitivity often does require surprisingly involved induction hypotheses or lemmas.
Fact sub_type_fields: forall u v fsv,
sub_type (c_typ u) (c_typ v) -> fields v fsv ->
exists fs, fields u (fsv ++ fs).
Proof.
intros.
remember (c_typ u) as t1 in H.
remember (c_typ v) as t2 in H.
induction H.
(* case st_refl *)
assert (v = u). congruence. subst v t.
exists nil. rewrite <- app_nil_end. assumption.
(* case st_trans *)
subst t1 t3.
(* case st_extends *)
Admitted.