Coq-覆盖相等的概念以向集合中添加元素

Coq-覆盖相等的概念以向集合中添加元素,coq,Coq,我试图使用Coq的列表集创建一组NAT。但是,我在向集合中添加成员时遇到了问题 这是我正在运行的代码 Require Import ListSet Nat. Axiom eq_dec : forall x y : nat, {x = y} + {x <> y}. Compute (set_add eq_dec 0 (set_add eq_dec 0 nil)). 但是,我无法将这两者串在一起以获得所需的输出,即 0::nil%列表:设置nat 我非常感谢您在这方面的帮助。您的函

我试图使用Coq的列表集创建一组NAT。但是,我在向集合中添加成员时遇到了问题

这是我正在运行的代码

Require Import ListSet Nat.

Axiom eq_dec : forall x y : nat, {x = y} + {x <> y}.

Compute (set_add eq_dec 0 (set_add eq_dec 0 nil)).
但是,我无法将这两者串在一起以获得所需的输出,即

0::nil%列表:设置nat

我非常感谢您在这方面的帮助。

您的函数nats_equal实际上并不是您编写的eq_dec公理的实现,因为它返回一个布尔值,而没有相关的证明。您可以使用Coq的策略创建定义,将您的公理转化为定义。放置定义。最后意味着定义是透明的,因此Coq可以用它来计算,但在其他方面,这与你开始一个定理,证明它,然后用Qed结束它时是一样的

在本例中,证明很容易,因为Coq有一个内置的策略来证明可判定等式,这甚至适用于递归类型

也就是说,NAT的可判定等式已经存在于标准库中,因此您不需要自己定义它:

(* how to even search for the type in eq_dec? *)
Locate "{".
(* Notation
"{ A } + { B }" := sumbool A B : type_scope (default interpretation)
*)

(* now we know what the notation means and can search for it: *)
Search sumbool nat.
(* PeanoNat.Nat.eq_dec: forall n m : nat, {n = m} + {n <> m} *)

(* alternately, we can use some more specific searches: *)
Search (forall (_ _:nat), {_ = _} + {_ <> _}).
Search ({@eq nat _ _} + {_ <> _}).
(* same as above, but use special notation for equality at a specific type *)
Search ({_ = _ :> nat} + {_ <> _}).
如果您导入PeanoNat,您可以使用更好的名称Nat.eq_dec来引用它。

您的函数nats_equal实际上不是您编写的eq_dec公理的实现,因为它返回一个布尔值,而没有相关的证明。您可以使用Coq的策略创建定义,将您的公理转化为定义。放置定义。最后意味着定义是透明的,因此Coq可以用它来计算,但在其他方面,这与你开始一个定理,证明它,然后用Qed结束它时是一样的

在本例中,证明很容易,因为Coq有一个内置的策略来证明可判定等式,这甚至适用于递归类型

也就是说,NAT的可判定等式已经存在于标准库中,因此您不需要自己定义它:

(* how to even search for the type in eq_dec? *)
Locate "{".
(* Notation
"{ A } + { B }" := sumbool A B : type_scope (default interpretation)
*)

(* now we know what the notation means and can search for it: *)
Search sumbool nat.
(* PeanoNat.Nat.eq_dec: forall n m : nat, {n = m} + {n <> m} *)

(* alternately, we can use some more specific searches: *)
Search (forall (_ _:nat), {_ = _} + {_ <> _}).
Search ({@eq nat _ _} + {_ <> _}).
(* same as above, but use special notation for equality at a specific type *)
Search ({_ = _ :> nat} + {_ <> _}).

如果您导入PeanoNat,您可以使用更好的名称Nat.eq_dec来引用它。

好的观点,添加了一些更具体的方法来搜索可判定的相等。您可能还想提到Scheme equality for…好的观点,添加了一些更具体的方法来搜索可判定的相等。您可能还想提到Scheme equality for。。。
(* how to even search for the type in eq_dec? *)
Locate "{".
(* Notation
"{ A } + { B }" := sumbool A B : type_scope (default interpretation)
*)

(* now we know what the notation means and can search for it: *)
Search sumbool nat.
(* PeanoNat.Nat.eq_dec: forall n m : nat, {n = m} + {n <> m} *)

(* alternately, we can use some more specific searches: *)
Search (forall (_ _:nat), {_ = _} + {_ <> _}).
Search ({@eq nat _ _} + {_ <> _}).
(* same as above, but use special notation for equality at a specific type *)
Search ({_ = _ :> nat} + {_ <> _}).