coq - 当参数在范围内时自动专门化 forall
问题描述
考虑以下简单问题:
Goal forall (R : relation nat) (a b c d e f g h : nat),
(forall m n : nat, R m n -> False) -> (R a b) -> False.
Proof.
intros ? a b c d e f g h H1 H2.
saturate H1. (* <-- TODO implement this *)
assumption.
Qed.
我目前使用各种可能的假设组合saturate
实例化的实现,导致时间和内存使用的二次膨胀。相反,我希望它检查并看到它需要 a ,因此在上下文中有意义的唯一参数组合是and then 。H1
nat
forall
R m n
a
b
有一个已知的解决方案吗?我的直觉是使用 evas,但如果我可以在不牺牲显着性能的情况下避免使用它们,我愿意。
解决方案
这可能太简单了,我们的想法是尝试apply H1
每个假设:
Ltac saturate H :=
match goal with
(* For any hypothesis I... *)
| [ I : _ |- _ ] =>
(* 1. Clone it (to not lose information). *)
let J := fresh I in pose proof I as J;
(* 2. apply H. *)
apply H in J;
(* 3. Abort if we already knew the resulting fact. *)
let T := type of J in
match goal with
| [ I1 : T, I2 : T |- _ ] => fail 2
end + idtac;
(* 4. Keep going *)
try (saturate H)
end.
例子:
Require Setoid. (* To get [relation] in scope so the example compiles *)
(* Made the example a little less trivial to better test the backtracking logic. *)
Goal forall (R S : relation nat) (a b c d e f g h : nat),
(forall m n : nat, R m n -> S m n) -> (R a b) -> R c d -> S a b.
Proof.
intros R S a b c d e f g h H1 H2 H3.
(* --- BEFORE ---
H2: R a b
H3: R c d
*)
saturate H1.
(* --- AFTER ---
H2: R a b
H3: R c d
H0: S c d
H4: S a b
*)
assumption.
Qed.
推荐阅读
- wcf - 使用邮递员测试 WCF 服务
- mongodb - Mongo 查找加入子/子对象?
- javascript - Javascript循环遍历列表不起作用
- virtualbox - 我正在尝试使用 scapy 进行 arp 欺骗攻击,但我的目标 arp 表注册了我的 IP 地址而不是被欺骗的
- python - Django:通过函数后如何过滤模型对象?
- python - 调用 f.write() 后文件仍然为空
- unit-testing - 存根异常后,Mockito 存根不起作用
- android - Android MVVM + Room 通过其他 LiveData 对象创建 LiveData RecyclerViewItem 对象
- c# - 如何在 ASP.NET Core 应用程序中使用 Razor 类库
- azure-devops - 如何不创建 azurerm_mssql_database_extended_auditing_policy