Coq 小于等于函数
我正在通过coq课程。解决问题: 具有较少或相等的功能:Coq 小于等于函数,coq,logical-foundations,Coq,Logical Foundations,我正在通过coq课程。解决问题: 具有较少或相等的功能: Fixpoint leb (n m : nat) : bool := match n with | O => true | S n' => match m with | O => false | S m' => leb n' m' end end. Definition blt_nat (n m : nat) : bool (* REPLACE
Fixpoint leb (n m : nat) : bool :=
match n with
| O => true
| S n' =>
match m with
| O => false
| S m' => leb n' m'
end
end.
Definition blt_nat (n m : nat) : bool
(* REPLACE THIS LINE WITH ":= _your_definition_ ." *). Admitted.
创建“小于”功能:
Fixpoint leb (n m : nat) : bool :=
match n with
| O => true
| S n' =>
match m with
| O => false
| S m' => leb n' m'
end
end.
Definition blt_nat (n m : nat) : bool
(* REPLACE THIS LINE WITH ":= _your_definition_ ." *). Admitted.
据我所知,它应该是这样工作的:
if (n == m)
return false
else
return (leb n m)
我创造了这个:
Definition blt_nat (n m : nat) : bool
match n with
| m => false
| _ => leb n m
end.
但它不起作用-输出:“错误:此子句是多余的。”对于行:
| _ => leb n m
请帮助。使用
匹配。。。使用…end
,我们只需检查特定数据类型的构造函数,并了解它是如何基于其构造函数构建的。因此,您无法将一个nat数据类型与另一个nat数据类型进行匹配。您可以在中找到其他示例
我对
coq
没有经验,但我怀疑第一个案例|m=>…
与m
不匹配,而是匹配任何值并调用该值m
(覆盖原始m
)。这可能会有帮助: