简体   繁体   English

我怎么说服coq(A / \\ B)/ \\ C == A / \\ B / \\ C?

[英]How do I convince coq that (A/\B)/\C == A /\ B /\ C?

In my proof I stumble upon problems where there is an A /\\ B /\\ C in my assumptions, and I need to prove (A /\\ B) /\\ C . 在我的证明中,我偶然发现了我的假设中存在A /\\ B /\\ C问题,我需要证明(A /\\ B) /\\ C These are logically exactly the same, but coq won't solve these with assumption. 这些在逻辑上完全相同,但是coq不能用assumption.解决这些问题assumption. .

I have been solving these by applying an axiom, but is there a more elegant (and correct) way to handle this? 我一直在通过应用公理来解决这些问题,但是有更优雅(和正确)的方法来处理这个问题吗?

So the way I've gone about it is by defining my lemma, 所以我的方式是通过定义我的引理,

Lemma conj_assoc : forall A B C, A /\ (B /\ C) <-> (A /\ B) /\ C.

That is one implies the other. 这是另一个意味着另一个。

intros. split. will then split this into two goals. 然后将这分为两个目标。

  1. A /\\ (B /\\ C) -> (A /\\ B) /\\ C
  2. (A /\\ B) /\\ C -> A /\\ (B /\\ C)

Proving each of these is roughly the same. 证明这些中的每一个大致相同。 For (1), 对于(1),

  • intro Habc. to get the assumption from the left hand size. 从左手大小得到假设。
  • destruct Habc as [Ha Hbc]. destruct Hbc as [Hb Hc]. to get the individual assumptions. 得到个人的假设。
  • auto to use these assumptions. auto使用这些假设。

I leave it to you to work out (2) but it is very similar. 我留给你研究(2),但它非常相似。

Then Qed. 然后是Qed.

If you have A /\\ B /\\ C as an assumption, and your goal is (A /\\ B) /\\ C , you can use the tactic tauto . 如果您有A /\\ B /\\ C作为假设,并且您的目标是(A /\\ B) /\\ C ,则可以使用战术tauto This tactic solves all tautologies in the propositional calculus. 这种策略解决了命题演算中的所有重言式。 There is also a tactic firstorder which can solve some formulas with quantifiers. 还有一个策略firstorder可以firstorder解决一些公式。

If you have A /\\ B /\\ C and you'd like to pass (A /\\ B) /\\ C as an argument to a lemma, you'll need to work a bit more. 如果你有A /\\ B /\\ C并且想要将(A /\\ B) /\\ C作为参数传递给引理,那么你需要多做一些工作。 One method is to set (A /\\ B) /\\ C as an intermediate goal and prove it: 一种方法是将(A /\\ B) /\\ C为中间目标并证明:

assert ((A /\ B) /\ C). tauto.

If A , B and C are large expressions, you can use a compound tactic to match over the hypothesis H : A /\\ B /\\ C and apply the tauto tactic to it. 如果ABC是大表达式,你可以使用复合策略匹配假设H : A /\\ B /\\ C并将tauto策略应用于它。 This is a heavy-handed approach, overkill in this case, but useful in more complex situations where you want to automate a proof with many similar cases. 这是一种严厉的方法,在这种情况下过度杀伤,但在更复杂的情况下非常有用,在这种情况下,您希望自动化具有许多类似情况的证明。

match type of H with ?x /\ ?y /\ ?z =>
  assert (x /\ (y /\ z)); [tauto | clear H]
end.

There's an easier way, which is to apply a known lemma that performs the transformation. 有一种更简单的方法,即应用执行转换的已知引理。

apply and_assoc in H.

You can find the lemma by browsing the library documentation. 您可以通过浏览库文档找到该引理。 You can also search for it. 你也可以搜索它。 This isn't the easiest lemma to search for because it's an equivalence and the search tools are geared towards implications and equalities. 这不是最容易搜索的因素,因为它是等价的,搜索工具适用于影响和平等。 You can use SearchPattern (_ /\\ _ /\\ _). 您可以使用SearchPattern (_ /\\ _ /\\ _). to look for lemmas of the form forall x1 … xn, ?A /\\ ?B /\\ ?C (where ?A , ?B and ?C can be any expression). 寻找forall x1 … xn, ?A /\\ ?B /\\ ?C形式的forall x1 … xn, ?A /\\ ?B /\\ ?C (其中?A?B?C可以是任何表达式)。 You can use SearchRewrite (_ /\\ _ /\\ _) to look for lemmas of the form forall x1 … xn, (?A /\\ ?B /\\ ?C) = ?D . 您可以使用SearchRewrite (_ /\\ _ /\\ _)来查找forall x1 … xn, (?A /\\ ?B /\\ ?C) = ?D形式的forall x1 … xn, (?A /\\ ?B /\\ ?C) = ?D Unfortunately, this doesn't find what we're after, which is a lemma of the form forall x1 … xn, (?A /\\ ?B /\\ ?C) <-> ?D . 不幸的是,这并没有找到我们所追求的东西,这是forall x1 … xn, (?A /\\ ?B /\\ ?C) <-> ?D形式的引理forall x1 … xn, (?A /\\ ?B /\\ ?C) <-> ?D What does work is 工作是什么

Coq < SearchPattern (_ <-> (_ /\ _ /\ _))
and_assoc: forall A B C : Prop, (A /\ B) /\ C <-> A /\ B /\ C

As a general tip, if you have something like this that you suspect to be obvious, check the standard library. 作为一般提示,如果你有类似的东西,你怀疑是显而易见的,请检查标准库。 Here's how: Locate "/\\". 方法如下: Locate "/\\". produces a response that resolves the Notation for us, 产生一个响应,为我们解决Notation

Notation            Scope     
"A /\ B" := and A B  : type_scope
                      (default interpretation)

Now we can issue the command, SearchAbout and. 现在我们可以发出命令SearchAbout and. to see what is in scope, and find that and_assoc witnesses the implication you are interested in. In fact, you can take a cue from your intuition: the intuition tactic can take advantage of this implication on its own. 看看范围是什么,并发现and_assoc见证了你感兴趣的含义。事实上,你可以从intuition中得到启示: intuition策略可以利用这个含义本身。

Lemma conj_example : forall A B C D,
  (A /\ B) /\ C -> (A /\ (B /\ C) -> D) -> D.
Proof. intuition. Qed.

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

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