coq - 将 ltac 应用于目标的子表达式
问题描述
这是我正在尝试做的一个简短示例。
假设我有关系
Inductive divisible: nat -> nat -> Type :=
| one : forall n, divisible n 1.
..etc...
我也有以下ltac
Ltac simplify := autorewrite with blah
我想定义一个 ltac,它确实简化为“可分割”目标中的第一项。就像是
Ltac simplify_fst :=
match goal with |- (divisible ?N ?M) =>
autorewrite with subst1 in N
end.
当我在下面尝试上述内容时,
Lemma silly: forall n m, divisible (n + m) 1.
intros. simplify_fst.
我得到一个
Error:
Ltac call to "simplify_fst" failed.
Ltac variable N is bound to n + m which cannot be
coerced to a variable.
是否可以将 ltacs(即使是仅涉及自动展开和自动重写的简单方法)限制在目标的子表达式中?
谢谢你。
解决方案
在您的情况下,remember
可能有用:
Ltac simplify_fst :=
match goal with |- (divisible ?N ?M) =>
let x := fresh "x" in
let Hx := fresh "Hx" in
remember N as x eqn:Hx;
autorewrite with subst1 in Hx;
subst x
end.
推荐阅读
- php - PHP foreach 循环表单没有出现在第一行
- java - 在重复调用的方法中创建的对象会发生什么?
- java - 如何以编程方式安装Android系统应用程序
- r - R-通过添加NA或布尔标准绑定两个不同长度的不同数据帧
- typescript - 如何创建新的 TSDX 项目?
- c++ - 在linux中运行c++ opencv程序的问题:未声明函数
- web - 如何使用正则表达式检查 url 是否包含 WWW?
- php - PHP 7.4 session_start 和 setcookie(会话未启动且 cookie 未设置)
- kotlin - Kotlin - 从函数中提取价值
- javascript - 反应上下文值在子类组件中不可用