gpt4 book ai didi

coq - Ltac : optional arguments tactic

转载 作者:行者123 更新时间:2023-12-03 14:15:46 25 4
gpt4 key购买 nike

我想在 coq 中制定一个 Ltac 策略,它需要 1 个或 3 个参数。我读过 ltac_No_arg LibTactics 模块,但如果我理解正确,我将不得不调用我的策略:

Coq < mytactic arg_1 ltac_no_arg ltac_no_arg.

这不是很方便。

有没有办法得到这样的结果? :
Coq < mytactic arg_1.

Coq < mytactic arg_1 arg_2 arg_3.

最佳答案

我们可以使用 Tactic Notation 尝试解决您的问题的机制,因为它可以处理可变参数。

让我们重用 ltac_No_arg并定义一个虚拟战术mytactic出于演示的目的

Inductive ltac_No_arg : Set :=
| ltac_no_arg : ltac_No_arg.

Ltac mytactic x y z :=
match type of y with
| ltac_No_arg => idtac "x =" x (* a bunch of cases omitted *)
| _ => idtac "x =" x "; y =" y "; z =" z
end.

现在让我们定义上述策略符号:
Tactic Notation "mytactic_notation" constr(x) :=
mytactic x ltac_no_arg ltac_no_arg.
Tactic Notation "mytactic_notation" constr(x) constr(y) constr(z) :=
mytactic x y z.

测试:
Goal True.
mytactic_notation 1.
mytactic_notation 1 2 3.
Abort.

关于coq - Ltac : optional arguments tactic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44840624/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com