【University of Science and Technology of China-Formal Course】PartA: More Coq Tactics

Negation: tactic unfold

Coq uses the symbol ~ to indicate the negation of a proposition. ~ P is a grammar of P -> False. We can establish theorems with negation like the following:

Theorem example_1: forall P: Prop,
        ~(P /\ ~P).
    Proof.
        unfold not.
        intros.
        inversion H.
        apply H1.
        apply H0.
    Qed.

Exercise1:~(P \/ Q) -> ~P /\ ~Q

Theorem exercise_1: forall P Q :Prop,
~(P \/ Q) -> ~P /\ ~Q.
Proof.
       unfold not.
       intros.
       split.
       intros.
       destruct H.
       left.
       apply H0.
       intros.
       destruct H.
       right.
       apply H0.
Qed.

Policy assertion (assert)
Sometimes, we need to prove our current goal from an intermediate goal. The assert or assert (h: h) strategy introduces h as a new sub-goal; after you prove the new goal, you can use the hypothesis h: h to prove your original goal. Below is an example:

 Theorem example2 : forall P Q: Prop,
        (P /\ ~P) -> Q.
    Proof.
        unfold not.
        intros.
        assert (f : False).
        inversion H.
        apply H1.
        apply H0.
        inversion f.
    Qed.

Strategy Destruct (destruct)
In Assignment 2, we use a reversal strategy to break the hypothetical connection or separation. There is another more commonly used strategy to deal with conjunctions and disjunctions: the destruction strategy. This strategy replaces one hypothesis P /\ Q with two hypotheses P and Q. Or, if the hypothesis is a separate P \/ Q, this strategy produces two sub-goals: hold in one P and hold in another Q. Strategy destruction can also generate a sub-goal for each constructor of the inductive type.

Theorem example3 : forall P Q R: Prop,
        P \/ Q -> (P -> R) -> (Q -> R) -> R
    Proof.
        intros.
        destruct H as [Hp|Hq].
        apply H0 in Hp.
        apply Hp.
        apply H1 in Hq.
        apply Hq.
    Qed.

Exercise 2: Using the tactic destruct, to prove

       P /\ (Q \/ R) <-> (P /\ Q) \/ (P /\ R).
    
Theorem exercise_1: forall P Q R:Prop,
  P /\ (Q \/ R) <-> (P /\ Q) \/ (P /\ R).
Proof.
       intros.
       split.
       intros.
       inversion H.
       destruct H1 as [Hq | Hr].
       left.
       split.
       apply H0.
       apply Hq.
       right.
       split.
       apply H0.
       apply Hr.

       intros.
       inversion H.
       destruct H as [H1 | H2].
       split.
       inversion H0.
       apply H.
       inversion H0.
       left.
       apply H2.
       inversion H2.
       split.
       apply H.
       right.
       apply H1.
       inversion H0.
       split.
       apply H1.
       right.
       apply H2.
Qed.

University of Science and Technology of China-hbj teacher formalized course notes-welcome to leave a message or exchange private messages

 

Guess you like

Origin blog.csdn.net/weixin_41950078/article/details/109651304