How to do cases with an inductive type in Coq

后端 未结 2 784
南旧
南旧 2021-01-04 14:08

I wan to use the destruct tactic to prove a statement by cases. I have read a couple of examples online and I\'m confused. Could someone explain it better?

2条回答
  •  轮回少年
    2021-01-04 14:51

    How to discard impossible cases? Well, it's true that the first two obligations are impossible to prove, but note they have contradicting assumptions (zero <> zero and one <> one, respectively). So you will be able to prove those goals with tauto (there are also more primitive tactics that will do the trick, if you are interested).

    inversion is a more advanced version of destruct. Additional to 'destructing' the inductive, it will sometimes generate some equalities (that you may need). It itself is a simple version of induction, which will additionally generate an induction hypothesis for you.

    If you have several inductive types in your goal, you can destruct/invert them one by one.

    More detailed walk-through:

    Inductive three := zero | one | two .
    
    Lemma test : forall a, a <> zero /\ a <> one -> a = two.
    Proof.
      intros a H.
      destruct H. (* to get two parts of conjunction *)
      destruct a. (* case analysis on 'a' *)
    (* low-level proof *)
      compute in H. (* to see through the '<>' notation *)
      elimtype False. (* meaning: assumptions are contradictory, I can prove False from them *)
      apply H.
      reflexivity.
    (* can as well be handled with more high-level tactics *)
      firstorder.
    (* the "proper" case *)
      reflexivity.
    Qed.
    

提交回复
热议问题