Negation: tactic unfold
Coq用符号~表示命题的否定。~ P是P -> False的一个语法,我们可以用像下面这样的否定来建立定理:
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.
策略断言(assert)
有时候,我们需要从一个中间目标来证明我们当前的目标。assert或assert (h: h)策略将h作为一个新的子目标引入;在你证明了新的目标之后,你可以用假设h: h来证明你原来的目标。下面是一个例子:
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.
策略破坏(destruct)
在作业2中,我们使用反转策略来打破假设中的连接或分离。还有另一个更常用的策略来处理连词和析取:破坏策略。这个策略用两个假设P和Q代替一个假设P /\ Q。或者,如果假设是一个分离的P \/ Q,这个策略产生两个子目标:在一个P持有,在另一个Q持有。策略析构还可以为归纳类型的每个构造函数生成一个子目标。
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.
中科大软院--hbj老师 形式化课程笔记--欢迎留言或私信交流