Coq 逻辑:In_app_iff exercize
试图解决逻辑第一章中的In_app_iff练习,得出了这个怪物:Coq 逻辑:In_app_iff exercize,coq,logical-foundations,Coq,Logical Foundations,试图解决逻辑第一章中的In_app_iff练习,得出了这个怪物: (* Lemma used later *) Lemma list_nil_app : forall (A : Type) (l : list A), l ++ [] = l. Proof. intros A l. induction l as [| n l' IHl']. - simpl. reflexivity. - simpl. rewrite -> IHl'. reflexivity. Qed.
(* Lemma used later *)
Lemma list_nil_app : forall (A : Type) (l : list A),
l ++ [] = l.
Proof.
intros A l. induction l as [| n l' IHl'].
- simpl. reflexivity.
- simpl. rewrite -> IHl'. reflexivity.
Qed.
(** **** Exercise: 2 stars, standard (In_app_iff) *)
Lemma In_app_iff : forall A l l' (a:A),
In a (l++l') <-> In a l \/ In a l'.
Proof.
intros A l l' a. split.
+ induction l as [| h t IHl].
++ (* l = [] *) destruct l' as [| h' t'].
+++ (* l' = [] *) simpl. intros H. exfalso. apply H.
+++ (* l' = h'::t' *) simpl. intros [H1 | H2].
* right. left. apply H1.
* right. right. apply H2.
++ (* l = h::t *) destruct l' as [| h' t'].
+++ (* l' = [] *) simpl. intros [H1 | H2].
* left. left. apply H1.
* left. right. rewrite list_nil_app in H2. apply H2.
+++ (* l' = h'::t' *) intros H. simpl in H. simpl. destruct H as [H1 | H2].
* left. left. apply H1.
* apply IHl in H2. destruct H2 as [H21 | H22].
** left. right. apply H21.
** simpl in H22. destruct H22 as [H221 | H222].
*** right. left. apply H221.
*** right. right. apply H222.
+ induction l as [| h t IHl].
++ (* l = [] *) simpl. intros [H1 | H2].
+++ exfalso. apply H1.
+++ apply H2.
++ (* l = h::t *) destruct l' as [| h' t'].
+++ simpl. intros [H1 | H2].
++++ rewrite list_nil_app. apply H1.
++++ exfalso. apply H2.
+++ simpl. intros [H1 | H2].
++++ destruct H1 as [H11 | H12].
+++++ left. apply H11.
+++++
我怎样才能从H12
和IHl
中得到在(t++h'::t')
中的事实
因为H12处于分离状态。这足以推断出结论
在IHl中应用H12。
不起作用
请帮帮我。有不同的方法 在这里,
IHl
的结论是目标条款之一,因此反向推理将非常有效
right. (* We will prove the right hand side of the disjunct. *)
apply IHl.
left.
apply H12.
向前推理也是可能的,尽管有点冗长。使用assert
证明IHl
实际需要的假设:
assert (preIHl : In a t \/ In a (h' :: t')).
- ...
- apply IHl in preIHl.
apply preIHl.
旁注:完成此证明不需要对
l'
进行案例分析(您可以提出更简单的证明),而且-
也是构建证明的有效方法(通常,它们按以下顺序使用:-
,+
,*
,-
,+
,+
,**
,等等)@eponier“旁注:完成这个证明不需要对l'进行案例分析(你可以提出一个更简单的证明)”-你能在回答中给出一个如何做的提示吗?你可以用simple
替换第一个destruct l'
,例如,当使用assert
策略时,我更喜欢使用大括号,例如,assert(…)。{some_proof.}
而不是子弹(因为这不是案例分析)。只是风格问题。
assert (preIHl : In a t \/ In a (h' :: t')).
- ...
- apply IHl in preIHl.
apply preIHl.