[英]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使其工作?
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 ]).
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_neq
与auto using eqb_neq
。 do 4 (constructor 3; [ | auto using eqb_neq ]).
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. repeat (constructor 3; auto using eqb_neq).
repeat (constructor; auto using eqb_neq).
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.
eqb_neq
is already registered for auto
. eqb_neq
已经被注册为auto
。 So we can just: auto 6.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.