代码之家  ›  专栏  ›  技术社区  ›  user4035

如何使coq简化隐含假设中的表达式

  •  0
  • user4035  · 技术社区  · 6 年前

    我试图证明以下引理:

    Inductive even : nat → Prop :=
    | ev_0 : even 0
    | ev_SS (n : nat) (H : even n) : even (S (S n)).
    
    Lemma even_Sn_not_even_n : forall n,
        even (S n) <-> not (even n).
    Proof.
      intros n. split.
      + intros H. unfold not. intros H1. induction H1 as [|n' E' IHn].
        - inversion H.
        - inversion_clear H. apply IHn in H0. apply H0.
      + unfold not. intros H. induction n as [|n' E' IHn].
        -
    Qed.
    

    以下是我最后得到的信息:

    1 subgoal (ID 173)
    
    H : even 0 -> False
    ============================
    even 1
    

    我希望coq将“偶数0”评估为真,“偶数1”评估为假。我试过了 simpl , apply ev_0 in H. 但他们给出了一个错误。怎么办?

    0 回复  |  直到 6 年前
        1
  •  4
  •   Bubbler    6 年前

    标题的答复

    simpl in H.
    

    真实答案

    定义 even

    Inductive even : nat → Prop :=
    | ev_0 : even 0
    | ev_SS (n : nat) (H : even n) : even (S (S n)).
    

    even 0 是个道具,不是傻瓜。看起来你把类型弄混了 True False true false . 它们是完全不同的东西,按照Coq的逻辑是不可互换的。简言之 不简化为 或者别的什么。只是 偶数0 . 如果你想展示 偶数0 如果逻辑上为true,则应构造该类型的值。

    我不记得在LF中有哪些战术可用,但这里有一些可能性:

    (* Since you know `ev_0` is a value of type `even 0`,
       construct `False` from H and destruct it.
       This is an example of forward proof. *)
    set (contra := H ev_0). destruct contra.
    
    (* ... or, in one step: *)
    destruct (H ev_0).
    
    (* We all know `even 1` is logically false,
       so change the goal to `False` and work from there.
       This is an example of backward proof. *)
    exfalso. apply H. apply ev_0.