简体   繁体   English

如何对序列应用战术

[英]How to apply do tactic to a sequence

Diving deep into test_nostutter_1 excersize I found a way to solve it without repeat: 我深入研究test_nostutter_1 exersize,发现了一种无需重复的解决方法:

Example test_nostutter_1: nostutter [3;1;4;1;5;6].
Proof.
  constructor 3.
  (* This will apply the tactics to the 2-nd subgoal *)
  2: {apply eqb_neq. auto. }
  constructor 3.
  2: {apply eqb_neq. auto. }
  constructor 3.
  2: {apply eqb_neq. auto. }
  constructor 3.
  2: {apply eqb_neq. auto. }
  constructor 2.
Qed.

I decided to play more with it and in coq reference manual I found that there is do tactical that can loop a tactic several times. 我决定更多地使用它,在coq参考手册中,我发现有一种战术可以使战术多次循环。

do num expr

expr is evaluated to v which must be a tactic value. 将expr评估为v,该v必须是战术值。 This tactic value v is applied num times. 将此战术值v应用了num次。 Supposing num > 1, after the first application of v, v is applied, at least once, to the generated subgoals and so on. 假设num> 1,在第一次应用v之后,将v至少一次应用于生成的子目标,依此类推。 It fails if the application of v fails before the num applications have been completed. 如果v的应用程序在num个应用程序完成之前失败,它将失败。

So I tried this: 所以我尝试了这个:

do 4 constructor 3; 2: {apply eqb_neq. auto. }

But unfortunately it fails. 但是不幸的是它失败了。 Only this works: 仅此有效:

do 1 constructor 3.

Is it possible to make it work using do? 是否可以使用do使其工作?

Answer 回答

There are several issues in the line 该行中有几个问题

do 4 constructor 3; 2: {apply eqb_neq. auto. }

First of all, you can't use the 2: or {} after the chain operator ; 首先,您不能在链运算符后使用2:{} ; . The closest thing you can use is sequence with local application tac; [tac1 | tac2] 您可以使用的最接近的东西是本地应用程序 tac; [tac1 | tac2] 序列 tac; [tac1 | tac2] tac; [tac1 | tac2] tac; [tac1 | tac2] . tac; [tac1 | tac2] Since we want to do something on just the second branch, we can omit tac1 here. 由于我们只想在第二个分支上做某事,因此我们可以在此处省略tac1

Also, you can't use periods inside a tactical. 另外,您不能在战术内使用句点。 A period marks the end of a statement, but the whole do expression is a single statement. 句点标志着一条语句的结尾,但是整个do表达式只是一个语句。 You should always use sequence operator ; 您应该始终使用序列运算符; to chain several tactics. 链接几种策略。

Finally, do n tac; tac 最后, do n tac; tac do n tac; tac works like (do n tac); tac do n tac; tac工作方式与(do n tac); tac类似(do n tac); tac (do n tac); tac . (do n tac); tac You can wrap a tactic expression with parentheses, eg do n (tac; tac) to change the behavior. 您可以在策略表达式中加上括号,例如用do n (tac; tac)更改行为。

So this one should work: 所以这应该工作:

do 4 (constructor 3; [ | apply eqb_neq; auto ]).

Digression 离题

We can simplify the line in several ways. 我们可以通过几种方式简化生产线。

  • auto can be given extra theorems to automate with. 可以给auto额外的定理进行自动化。 Any goal solvable with apply eqb_neq; auto 可以apply eqb_neq; auto解决任何目标apply eqb_neq; auto apply eqb_neq; auto is also solvable with auto using eqb_neq . apply eqb_neq; auto也可以auto using eqb_neqauto using eqb_neq
do 4 (constructor 3; [ | auto using eqb_neq ]).
  • The auto tactic never fails, so it can be safely used on both branches. auto策略永远不会失败,因此可以在两个分支上安全地使用它。
do 4 (constructor 3; auto using eqb_neq).
  • repeat repeats until something fails or there are no more subgoals. repeat直到出现故障或不再有子目标。 The following will repeat until the 3rd constructor is no longer applicable. 重复以下步骤,直到第3个构造函数不再适用。
repeat (constructor 3; auto using eqb_neq).
  • We can let Coq choose which constructor to apply. 我们可以让Coq选择要应用的构造函数。 This can finish (or almost finish) the proof. 这样可以完成(或几乎完成)证明。
repeat (constructor; auto using eqb_neq).
  • We can also make constructors of nostutter automated by auto using Hint Constructors command. 我们还可以使用“ Hint Constructors命令通过auto使nostutter构造nostutter自动化。 Now we can auto the whole thing. 现在我们可以使整个过程auto (You can place the hint command right after your definition of nostutter , then you can auto it everywhere.) (您可以在您的nostutter定义之后放置hint命令,然后可以在任何地方auto它。)
Hint Constructors nostutter.
auto using eqb_neq.
(* if the above fails, the following increases the search depth so it should succeed. *)
auto 6 using eqb_neq.
  • Actually, the theorem eqb_neq is already registered for auto . 实际上,定理eqb_neq已经被注册为auto So we can just: 这样我们就可以:
auto 6.

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

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