Keeping information when using induction?

前端 未结 3 1624
[愿得一人]
[愿得一人] 2020-12-29 07:44

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,

3条回答
  •  渐次进展
    2020-12-29 08:30

    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.
    

提交回复
热议问题