逻辑:In_app_iff练习

问题描述 投票:0回答:1

试图从逻辑章节解决In_app_iff excersize我来到这个怪物:

(* 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.
              +++++

这是我最后得到的:

A : Type
h : A
t : list A
h' : A
t' : list A
a : A
IHl : In a t \/ In a (h' :: t') -> In a (t ++ h' :: t')
H12 : In a t
============================
h = a \/ In a (t ++ h' :: t')

我如何从H12IHl得到In a (t ++ h' :: t')的事实?

因为H12是分离的。这足以推断出结论。

apply H12 in IHl.不起作用。

请帮忙。

coq logical-foundations
1个回答
1
投票

有不同的方法来解决这个问题。

在这里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.
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.