Coq 用具体的证明来例示存在句
我目前正在尝试编写一种策略,使用一个可以轻松生成的术语来实例化存在量词(在这个特定示例中,从Coq 用具体的证明来例示存在句,coq,ltac,Coq,Ltac,我目前正在尝试编写一种策略,使用一个可以轻松生成的术语来实例化存在量词(在这个特定示例中,从tauto)。我的第一次尝试: Ltac mytac := match goal with | |- (exists (_ : ?X), _) => cut X; [ let t := fresh "t" in intro t ; exists t; firstorder
tauto
)。我的第一次尝试:
Ltac mytac :=
match goal with
| |- (exists (_ : ?X), _) => cut X;
[ let t := fresh "t" in intro t ; exists t; firstorder
| tauto ]
end.
这种策略适用于一个简单的问题,如
Lemma obv1(X : Set) : exists f : X -> X, f = f.
mytac.
Qed.
然而,对于这样一个目标来说,这是行不通的
Lemma obv2(X : Set) : exists f : X -> X, forall x, f x = x.
mytac. (* goal becomes t x = x for arbitrary t,x *)
在这里,我想使用这种策略,相信
tauto
找到的f
将只是fun x=>x
,从而在特定的证明(应该是身份函数)中进行细分,而不仅仅是我当前脚本中的通用t
。我该如何编写这样的策略呢?您可以使用eexists
引入一个存在变量,并让tauto
实例化它
这将给出以下简单代码
Lemma obv2(X : Set) : exists f : X -> X, forall x, f x = x.
eexists; tauto.
Qed.
您可以使用
eexists
引入存在变量,并让tauto
实例化它
这将给出以下简单代码
Lemma obv2(X : Set) : exists f : X -> X, forall x, f x = x.
eexists; tauto.
Qed.
更常见的是创建一个存在变量,并让一些策略(
eauto
或tauto
等)通过统一实例化变量
另一方面,您也可以使用策略为证人提供策略,具体如下:
Ltac mytac :=
match goal with
| [ |- exists (_:?T), _ ] =>
exists (ltac:(tauto) : T)
end.
Lemma obv1(X : Set) : exists f : X -> X, f = f.
Proof.
mytac.
auto.
Qed.
您需要类型归属:T
,以便术语ltac:(tauto)
中的策略具有正确的目标(存在所期望的类型)
我不确定这是否有用(通常证人的类型不是很有用,你想用目标的其余部分来选择它),但你仍然可以这样做,这很酷。创建一个存在变量并使用一些策略(例如,eauto
或tauto
)通过统一实例化变量
另一方面,您也可以使用策略为证人提供策略,具体如下:
Ltac mytac :=
match goal with
| [ |- exists (_:?T), _ ] =>
exists (ltac:(tauto) : T)
end.
Lemma obv1(X : Set) : exists f : X -> X, f = f.
Proof.
mytac.
auto.
Qed.
您需要类型归属:T
,以便术语ltac:(tauto)
中的策略具有正确的目标(存在所期望的类型)
我不确定这是否有用(通常证人的类型不是很有用,你想用目标的其余部分来选择),但你仍然可以这样做,这很酷。你知道有没有更强大的策略来寻找制服?只是稍微玩玩一下,eexists
+eauto/tauto
方法似乎不适用于像Lemma two_id(X:Set):exists f g:X->X,forall X,f(gx)=X这样的多个实例化,比如Lemma const:forall(xy:Set)(Y:Y),exists f:X->Y,对于所有x',fx=fx.
(所需的统一工具是fun.=>y
),您是否知道是否有更强大的策略来寻找统一工具?只是稍微玩玩一下,eexists
+eauto/tauto
方法似乎不适用于像Lemma two_id(X:Set):exists f g:X->X,forall X,f(gx)=X这样的多个实例化,比如Lemma const:forall(xy:Set)(Y:Y),exists f:X->Y,对于所有x',fx=fx'
(所需的统一标准是fun
)