小于函数

Less then function

我正在学习 coq 课程 "Logical Foundations"。解决问题:

功能小于或等于:

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.

创建"less then"函数:

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.

但它不起作用 - 输出:"Error: This clause is redundant." 行:

| _ => leb n m

拜托,帮忙。

通过使用match ... with...end,我们可以只检查特定数据类型的构造函数,并根据其构造函数找出它是如何构建的。因此,您不能将 nat 数据类型与另一种 nat 数据类型进行匹配。您可以在 here.

中找到其他示例
Definition blt_nat (n m : nat) : bool :=
  match m with
  | 0 => false
  | S m' => leb n m'
  end.