2

I have a definition involving match, similar like this:

Definition five (n: nat): bool :=
match n with
| 5 => true
| _ => false
end.

I try to proof something similar like this:

Theorem fiveT: forall (n: nat),
n <> 5 -> five n = false.
Proof. intros. unfold five.

But when I unfold the definition of five, I don't know how to tell coq that the first match case is irrelevant because of H. How can I proof this?

1 goal
n : nat
H : n <> 5
______________________________________(1/1)
match n with
| 5 => true
| _ => false
end = false

Please note that my real problem is much bigger than this one but I wanted to give a small understandable example, so please don't tell me a complete different approach from mine, thank you :)

Leo G.
  • 33
  • 2
  • You need to destruct [n] in order to simplify the pattern matching. You can do it with `repeat (destruct n; auto)` and then `destruct H; reflexivity` to exploit the assumption `5<>5`. – pjm Jul 29 '22 at 09:09

1 Answers1

1

You can use the contrapositive of your lemma, and then a (not elegant) case analysis to get rid of all the cases different from 5, for which evaluation works trivially (I'm using ssreflect here, but you should get the idea):

From mathcomp Require Import all_ssreflect.

Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.

Definition five (n: nat): bool :=
match n with
| 5 => true
| _ => false
end.
 
Theorem fiveT: forall (n: nat), n <> 5 -> five n = false.
Proof. 
move=> n.
apply: contra_notF.
have [/eqP -> //|ne0] := boolP (n == 0). 
have [/eqP -> //|ne1] := boolP (n == 1). 
have [/eqP -> //|ne2] := boolP (n == 2). 
have [/eqP -> //|ne3] := boolP (n == 3). 
have [/eqP -> //|ne4] := boolP (n == 4). 
have [/eqP -> //|ne5] := boolP (n == 5). 
have [n' -> //=]: exists n', n = S (S (S (S (S (S n'))))).
  exists (n - 6).
  have lt0n: 0 < n by rewrite lt0n.
  have lt1n: 1 < n by rewrite ltn_neqAle lt0n eq_sym ne1.
  have lt2n: 2 < n by rewrite ltn_neqAle lt1n eq_sym ne2.
  have lt3n: 3 < n by rewrite ltn_neqAle lt2n eq_sym ne3.
  have lt4n: 4 < n by rewrite ltn_neqAle lt3n eq_sym ne4.
  have lt5n: 5 < n by rewrite ltn_neqAle lt4n eq_sym ne5.
  by rewrite !subnSK ?subn0.
Qed.

There got to be a cleaner way to do this, though ;)

Pierre Jouvelot
  • 901
  • 3
  • 13