简体   繁体   English

在 coq 中证明定理时如何处理“false = true”命题

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

I am new to coq and trying to prove this theorem我是 coq 的新手并试图证明这个定理

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这是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.我知道这个 output 意味着如果定理必须是正确的,那么命题“Var 0 = Var (S n)”应该遵循命题“false = true”,但我不知道该怎么做并移动继续我的证明。 Any help would be appreciated.任何帮助,将不胜感激。

Thanks in advance!提前致谢!

Another option: instead of inversion , use congruence :另一种选择:而不是inversion ,使用congruence

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

This tactic is dedicated to exploiting disjointness of constructors.这种策略致力于利用构造函数的不相交性。

Use inversion on such hypothesis as in:对这样的假设使用inversion ,例如:

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.另一种选择, discriminate这是针对此类目标的专用策略:它应该完全解决此类问题(即假设中不同构造函数的相等性),仅此而已。

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.此外,它是一个终结者,这意味着如果目标在使用后没有得到解决,它就会失败,这与inversioncongruence相反,在某些情况下它们不会解决预期的问题并以“意外”的方式成功。

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:就个人而言,我使用 ssreflect 中的by [] (它也是一个终止符)来实现这种目标和所有“微不足道”的目标:

Require Import ssreflect.

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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