简体   繁体   中英

How to deal with “false = true” proposition while proving theorems in coq

I am new to coq and trying to prove this theorem

Inductive expression : Type :=
  | Var (n : nat)
.
.

Theorem variable_equality : forall x : nat, forall n : nat,
  ((equals x n) = true) -> (Var x = Var n).

This is the definition of equals


Fixpoint equals (n1 : nat) (n2 : nat) :=
  match (n1, n2) with
    | (O, O)      => true
    | (O, S n)    => false
    | (S n, O)    => false
    | (S n, S n') => equals n n'
  end.

This is my solution so far

Proof.
intros x n. induction x as [| x' IH].
  - destruct n. 
    + reflexivity.
    + simpl. intro. 

and I end up with something like this

1 subgoal 
n : nat
H : false = true
-------------------------
Var 0 = Var (S n)

I understand that this output means that the proposition "Var 0 = Var (S n)" should follow from the proposition "false = true" if the theorem has to be correct, but I don't know what to do about it and move ahead with my proof. Any help would be appreciated.

Thanks in advance!

Another option: instead of inversion , use congruence :

Goal false=true -> False.
  congruence.
Qed.

This tactic is dedicated to exploiting disjointness of constructors.

Use inversion on such hypothesis as in:

Goal false=true -> False.
intros H.
inversion H.
Qed.

Another option, discriminate which is the dedicated tactic for this kind of goals: it is supposed to solve exactly this kind of problems (ie equalities of distinct constructors in your hypotheses) and no more.

Goal false = true -> False.
discriminate.
Qed.

Additionally, it is a terminator , which means it fails if the goal is not solved after its use, contrarily to inversion and congruence which will succeed in some cases where they do not solve the expected problem and succeed in an "unexpected" way.

eg

Goal true = true -> True.
inversion 1.
Qed.

and

Goal true = true -> S 1 = S 1.
congruence.
Qed.

Personally, I use by [] (which is also a terminator) from ssreflect for this kind of goals and for all "trivial" goals of the sort:

Require Import ssreflect.

Goal false = true -> False.
by [].
Qed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM