Coq 布尔等式无关性的证明

Coq 布尔等式无关性的证明,coq,proof,Coq,Proof,我试图证明Z_3类型的群公理: Require Import Coq.Arith.PeanoNat. Record Z_3 : Type := Z3 { n :> nat; proof : (Nat.ltb n 3) = true }. Proposition lt_0_3 : (0 <? 3) = true. Proof. simpl. reflexivity. Qed. Definition z3_0 : Z_3 := (Z3 0 lt_0_3). Propo

我试图证明Z_3类型的群公理:

Require Import Coq.Arith.PeanoNat.

Record Z_3 : Type := Z3
{
  n :> nat;
  proof : (Nat.ltb n 3) = true
}.

Proposition lt_0_3 : (0 <? 3) = true.
Proof.
  simpl. reflexivity.
Qed.

Definition z3_0 : Z_3 := (Z3 0 lt_0_3).

Proposition lt_1_3 : (1 <? 3) = true.
Proof.
  reflexivity.
Qed.

Definition z3_1 : Z_3 := (Z3 1 lt_1_3).

Proposition lt_2_3 : (2 <? 3) = true.
Proof.
  reflexivity.
Qed.

Definition z3_2 : Z_3 := (Z3 2 lt_2_3).

Proposition three_ne_0 : 3 <> 0.
Proof.
  discriminate.
Qed.

Lemma mod_upper_bound_bool : forall (a b : nat), (not (eq b O)) -> (Nat.ltb (a mod b) b) = true.
Proof.
  intros a b H. apply (Nat.mod_upper_bound a b) in H. case Nat.ltb_spec0.
  - reflexivity.
  - intros Hcontr. contradiction.
Qed.

Definition Z3_op (x y: Z_3) : Z_3 :=
  let a := (x + y) mod 3 in
  Z3 a (mod_upper_bound_bool _ 3 three_ne_0).

Lemma Z3_eq n m p q : n = m -> Z3 n p = Z3 m q.
Proof.
  intros H. revert p q. rewrite H. clear H. intros. apply f_equal.
需要导入Coq.Arith.PeanoNat。
记录Z_3:类型:=Z3
{
n:>nat;
证明:(Nat.ltb n 3)=正确
}.

命题lt_0_3:(0你可能有兴趣知道一个可判定等式的每两个证明都是相等的。这里解释并证明了这一点:

你特别感兴趣的是引理
UIP\u dec

它将出现几个引理,包括很早的:

Bool.bool_dec: forall b1 b2 : bool, {b1 = b2} + {b1 <> b2}
您可以使用非常好的
Locate
命令找到它:

Locate "{".
会出现

"{ A } + { B }" := sumbool A B : type_scope (default interpretation)

(和其他涉及“{”)的符号。

我做了证明。你能看一下吗?有可能在标准库中找到
bool_dec
吗?我相应地更新了我的答案。
Search
是一个非常强大的工具,我建议尽早学习使用它。
Search sumbool bool.
Bool.bool_dec: forall b1 b2 : bool, {b1 = b2} + {b1 <> b2}
{ A } + { B } := sumbool A B
Locate "{".
"{ A } + { B }" := sumbool A B : type_scope (default interpretation)