完成证明的指导

时间:2018-06-01 07:36:38

标签: coq proof theorem-proving

我很欣赏完成此证明的一些指导。我被困在最后admit(我已经完成了其他的没有问题,但我省略了真正的证据)。

我在推理后添加了评论,因为我觉得它比我试图在一个段落中描述它更好。

这是正在使用的函数的定义:

In = 
fix In (A : Type) (x : A) (l : list A) {struct l} : Prop := match l with
                                                            | [ ] => False
                                                            | x' :: l' => x' = x \/ In A x l'
                                                            end
     : forall A : Type, A -> list A -> Prop

Argument A is implicit and maximally inserted
Argument scopes are [type_scope _ _]
map = 
fix map (X Y : Type) (f : X -> Y) (l : list X) {struct l} : list Y := match l with
                                                                      | [ ] => [ ]
                                                                      | h :: t => f h :: map X Y f t
                                                                      end
     : forall X Y : Type, (X -> Y) -> list X -> list Y

Arguments X, Y are implicit and maximally inserted
Argument scopes are [type_scope type_scope function_scope _]

这就是引理:

Lemma foo :
  forall (A B : Type) (f : A -> B) (l : list A) (y : B),
    In y (map f l) <->
    exists x, f x = y /\ In x l.
Proof.
  intros A B f l y. split.
  - admit.
  - induction l as [|x0 l' HIl'].
    * admit.
    * (*
      HIl': (exists x : A, f x = y /\ In x l') -> In y (map f l')
      Goal: (exists x : A, f x = y /\ In x (x0 :: l')) -> In y (map f (x0 :: l'))
      *)
      intros H. simpl.
      (*
      Goal: f x0 = y \/ In y (map f l')
      *)
      right.
      (*
      Taking the right side, because if `f x0 = y`, then the induction
      hypothesis would tell us nothing.
      *)
      apply HIl'.
      (*
      Goal: exists x : A, f x = y /\ In x l'
      *)
      destruct H as [x1 H']. exists x1.
      (*
      This `x1` should be the element that is in both `l'` and `x0 ::
      l'`, because we discarded the case when `f x0 = y`.

      Goal: f x1 = y /\ In x1 l'
      *)
      destruct H' as [H'l H'r]. split.
      + (* Goal: fx1 = y *) apply H'l .
      + (* Goal: In x1 l' *)
        (*
           `x1` must be in `l'`, because we know it is in x0 :: l` by H'r:
           H'r: In x1 (x0 :: l')
           and we discarded the case where `f x0 = y`.
        *)
        destruct H'r as [H'rl | H'rr].
        { (* Stuck!!! *) admit. }
        { apply H'rr. } Abort.

3 个答案:

答案 0 :(得分:3)

Lemma foo :
  forall (A B : Type) (f : A -> B) (l : list A) (y : B),
    In y (map f l) <->
    exists x, f x = y /\ In x l.
Proof.
  - admit.
  - induction l as [|x0 l' HIl'].
    * admit.
    * (*
      -- HIl': (exists x : A, f x = y /\ In x l') -> In y (map f l')
      -- Goal: (exists x : A, f x = y /\ In x (x0 :: l')) -> In y (map f (x0 :: l'))
      *)
      intros H. simpl.
      (*
      -- Goal: f x0 = y \/ In y (map f l')

      you might need to destruct H first.
       *)
      destruct H.
      destruct H.
      (* right. *)
      (*
      -- Taking the right side, because if `f x0 = y`, then the induction
      -- hypothesis would tell us nothing.
      acatually, consider x = x0, we can subst and just apply H here.
      we will destruct on H0 to analysis case x = x0 || In x l'.
       *)
      destruct H0. {
        left.
        rewrite H0.
        assumption.
      }
      (* in this case we select rhs. *)
      {
        right.
        apply HIl'.
        exists x.
        split. {
          assumption.
        }
        {
          assumption.
        }
      }
Admitted.

很抱歉我在工作,我想我会在一分钟内编辑它。

您会注意到In x l的假设应该被破坏然后单独分析。当您对l进行归纳时,它将替换为In x (x0 :: l),对于x = x0In x l,联合应该保留。

答案 1 :(得分:3)

Lemma foo :
  forall (A B : Type) (f : A -> B) (l : list A) (y : B),
    In y (map f l) <->
    exists x, f x = y /\ In x l.
Proof.
  induction l; split; intros.
  - now inversion H.
  - now firstorder.
  - inversion H.
    + now exists a; firstorder.
    + apply IHl in H0.
      destruct H0 as [x Hx].
      now exists x; firstorder.
  - destruct H as [x [Hx [Hi | Hi]]].
    + now left; subst.
    + right.
      apply IHl.
      exists x.
      firstorder.
Qed.

答案 2 :(得分:3)

right.策略为时尚早。此时H告诉我们x位于(x0 :: l),但如果这是因为x = x0会怎样?然后就没有办法证明正确的替代方案,但在这种情况下左边的方法是正确的。因此,在选择Hleft方之前,您必须解构right