coq - 某个数字加 1 的证明会改变 Coq 中的奇偶校验

标签 coq

我将 Even 定义为:

Inductive even : nat -> Prop :=
  | ev0: even O
  | evSS: forall n, even n -> even (S (S n)).

但现在我想证明:

Lemma add1_diff (x: nat) : even (S x) = ~even x.

我可以证明:

even (S O) = (~ even O)

提前致谢。

最佳答案

您通常无法证明两个 Prop 的相等。 Prop 中的相等意味着逻辑陈述的证明项是相等的。有时会出现这种情况,但很少见。以下是一些示例:

Require Import PeanoNat.
Import Nat.

Inductive even : nat -> Prop :=
  | ev0: even O
  | evSS: forall n, even n -> even (S (S n)).

Example ex1 (n : nat) : (n >= 1) = (1 <= n).
Proof.
  (* The proofs are equal because >= is defined in terms of <= *)
  reflexivity.
Qed.

Example ex2: even (2+2) = even 4.
Proof.
  (* The proofs are equal because 2+2 can be reduced to 4 *)
  reflexivity.
Qed.

Example ex3 (n : nat) : even (2+n) = even (n+2).
Proof.
  (* The proofs are equal because 2+n is equal to n+2 *)
  rewrite add_comm.
  reflexivity.
Qed.

Example ex4 (n : nat): even (S (S n)) = even n.
Proof.
  (* The proofs cannot be equal, because the left side proof always
     requires one evSS constructor more than the right hand side. *)
Abort.

出于这个原因,我们使用两个 Prop 的等价性,即 <-> ,而不是平等。最后一条语句的等价性是可证明的:

Example ex4 (n : nat): even (S (S n)) <-> even n.
Proof.
  split; intros H.
  - inversion H.
    assumption.
  - constructor.
    assumption.
Qed.

所以回答你的问题:两个陈述的相等性很可能无法证明,但等价性是可以证明的。如果您需要帮助,请询问。

关于coq - 某个数字加 1 的证明会改变 Coq 中的奇偶校验,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68076259/

相关文章:

coq - 同底指数之和

syntax - Coq 介绍语法

coq - 连词和。 Coq 中的含义

coq - 在 coq 中推广一组证明

types - 如何在 coq 中定义自定义归纳原理?

coq - Coq arrow -> 在 Coq 定理中是什么意思?

bash - Dockerfile 中需要冗余 eval $(opam env)

monads - 在 Coq 中证明延续传递式 Monad

types - Coq:显示环境中一个或多个类型中的所有术语

coq - 如何在 Coq 中从头开始证明 'S x > 0' ?