1

I am passing through coq course "Logical Foundations". Solving problem:

Having less or equal function:

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.

create "less then" function:

Definition blt_nat (n m : nat) : bool
  (* REPLACE THIS LINE WITH ":= _your_definition_ ." *). Admitted.

As far as I understand it should work like this:

if (n == m)
   return false
else
    return (leb n m)

I created this:

Definition blt_nat (n m : nat) : bool
  match n with
  | m => false
  | _ => leb n m
  end.

But it doesn't work - outputs: "Error: This clause is redundant." for the line:

| _ => leb n m

Please, help.

user4035
  • 22,508
  • 11
  • 59
  • 94
  • 4
    I'm not experienced with `coq` but I suspect the first case `| m => ...` doesn't match on `m`, but matches on any value and calls that value `m` (overriding the original `m`). This might be helpful: https://stackoverflow.com/a/46384468/ – Aurel Bílý Dec 31 '18 at 14:19

1 Answers1

2

By using match ... with...end, we can just check the constructors of a particular datatype and find out how it is built based on its constructors. So you cannot do matching a datatype of nat with another datatype of nat. You can find other examples in here.

Definition blt_nat (n m : nat) : bool :=
  match m with
  | 0 => false
  | S m' => leb n m'
  end.
user4035
  • 22,508
  • 11
  • 59
  • 94
Tom And.
  • 125
  • 6