I was trying out the examples from the Coq documentation Software Foundations (http://www.cis.upenn.edu/~bcpierce/sf/current/Induction.html#lab40) when I noticed that to solve the example give in the link:
Theorem andb_true_elim1 : ∀b c : bool,
andb b c = true → b = true.
Proof.
intros b c H.
destruct b.
Case "b = true". (* <----- here *)
reflexivity.
Case "b = false". (* <---- and here *)
rewrite ← H.
reflexivity.
Qed.
we are destructing b which appears on the left of c for "andb". However to do the exercise that follows in the book i.e.
Theorem andb_true_elim2 : ∀b c : bool,
andb b c = true → c = true.
Proof.
(* FILL IN HERE *) Admitted.
I found the same method does not help. "reflexivity" did not help which I assume is due to the position of 'b' in the subgoal. Eventually I completed the proof in the following manner:
Theorem andb_true_elim2 : forall b c:bool,
andb b c = true -> c = true.
Proof.
intros b c H.
destruct c.
Case "c=true".
reflexivity.
Case "c=false".
rewrite <- H.
destruct b.
reflexivity.
reflexivity.
Qed.
Can someone explain why the above code worked and the following dint?
Theorem andb_true_elim2 : forall b c:bool,
andb b c = true -> c = true.
Proof.
intros b c H.
destruct c.
Case "c=true".
reflexivity.
Case "c=false".
rewrite <- H.
reflexivity.
答案 0 :(得分:1)
最后一次证明不起作用的原因是 以下是Coq。{/ p>中 请注意,我们会根据 first 参数做出决定。因此,当您在第一个参数上使用 由于andb
定义的方式以及Coq简化此类定义的方式(reflexivity
在目标中执行一些简化)。< / p>
andb
的定义
Definition andb (b1 b2:bool) : bool := if b1 then b2 else false.
destruct
然后使用reflexivity
时,您可以让Coq减少andb b c
(到false
或{ {1}})。c
的不对称定义, second 参数的案例分析不起作用,因为Coq无法减少函数体内的andb
表达式