简体   繁体   English

Coq true = false区分失败,没有原始相等性

[英]Coq true = false discriminate fails, no primitive equality

I'm trying to prove the following, and I think I have the right approach to solving by enumerating all the cases for b and all the single argument boolean functions f (should be 4 functions over 2 boolean values), proving the point by exhaustively destructing everything. 我试图证明以下内容,并且我想通过列举b所有情况和所有单参数布尔函数f (应该是2个布尔值中的4个函数)来解决问题的正确方法,并通过详尽地证明了这一点破坏一切。

Theorem example :
  forall (f : bool -> bool) (b : bool),
  f (f b) = b.
Proof.
  intros.
  destruct (f (f b)).
  - destruct b. 
    + reflexivity. 
    + Fail discriminate. admit. 
  - destruct b eqn:Hqebb.
    + Fail discriminate. admit. 
    + reflexivity.  
Qed.

However, when I try to discriminate on the 2nd and 3rd steps, on false = true I get the following error: 但是,当我尝试区分第二步和第三步时,在false = true出现以下错误:

Ltac call to "discriminate" failed.
No primitive equality found.

I've used discriminate before with inductive types and it worked as expected, so I was surprised it didn't work here with boolean types. 我以前使用过归纳类型来区分,它按预期方式工作,所以令我惊讶的是,它在布尔类型中不起作用。 Any ideas why? 有什么想法吗?

If you have an hypothesis true = false (which is impossible), you can use discriminate to finish the goal. 如果您有一个假设true = false (这是不可能的),则可以使用discriminate来完成目标。 In the goal you are stuck with, you are asked to prove true = false . 在您坚持的目标中,要求您证明 true = false No tactic can do that, it's an impossible task! 没有战术可以做到这一点,这是不可能完成的任务!

The particular example theorem you used is actually false: 您使用的特定示例定理实际上是错误的:

Theorem not_example:
  ~ forall (f : bool -> bool) (b : bool), f (f b) = b.
Proof.  
  intros H.
  specialize (H (fun _ => true) false).
  simpl in H.
  discriminate.
Qed.

But in general, as Arthur said, the way to do this is is to use the eqn: option to destruct , to remember the relevant equations. 但是总的来说,正如亚瑟(Arthur)所说,做到这一点的方法是使用eqn:选项来destruct ,以记住相关的方程式。 Eg here is a proof script that mostly proves your theorem, except for the cases where it is false: 例如,这里是一个证明脚本,主要用于证明您的定理,但错误的情况除外:

Theorem example :
  forall (f : bool -> bool) (b : bool),
  f (f b) = b.
Proof.
  intros.
  destruct (f true) eqn:?; destruct (f false) eqn:?; destruct b; try congruence.

The discriminate tactic only works if your context has a hypothesis that equates terms of inductive type that start with different constructors. 仅当您的上下文具有与其他构造函数开头的归纳类型术语相等的假设时, discriminate策略才有效。 When you perform the first call to discriminate , the context looks like this: 当您执行第一个调用discriminate ,上下文如下所示:

f : bool -> bool
============================
true = false

As you can see, the context does not contain any equality hypotheses, so discriminate cannot do anything. 如您所见,上下文不包含任何相等性假设,因此discriminate不能做任何事情。 To solve this, you need to use the eqn: option to the destruct tactic, so that Coq records all the relevant facts in the context. 要解决此问题,您需要对destruct策略使用eqn:选项,以便Coq在上下文中记录所有相关事实。 For example, if you call 例如,如果您致电

destruct b eqn:H.

and b is of type bool , then in addition to generating two subgoals as usual, Coq will add the hypotheses H : b = true and H : b = false . 并且bbool类型,则Coq除了照常生成两个子目标之外,还将添加假设H : b = trueH : b = false

(I appreciate that you changed your question, but I just wanted to note that the theorem you put there now is not provable. It shouldn't be too difficult to adapt this to your original question.) (感谢您更改了问题,但我只是想指出,您现在提出的定理是不可证明的。将其应用于您的原始问题应该不会太困难。)

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

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