如何检查 Coq 中两个整数之间的相等性?

How to check equality between two integers in Coq?

我正在尝试检查 Coq 中两个整数之间的相等性,但我收到此错误:"The term "first = second" has type "Prop" which is not a (co-)inductive类型。”。 Coq 中是否有提供相等性检查的库?这是我的代码:

Definition verify_eq (first : Z) (second : Z) : Z :=
   if first = second then 0 else 1.

你走运了!在定义 Z 的同一模块中(我假设标准库中有 ZArith),有一个术语 Z.eqb : Z -> Z -> bool 给出了整数相等性的布尔测试(技术上它在子模块 Z — 这就是名称中有 Z 的原因)。

Require Import ZArith. (* I assume you already imported this, since you're using Z *)

Definition verify_eq (first : Z) (second : Z) : Z :=
   if Z.eqb first second then 0 else 1.