简体   繁体   English

如何破坏目标的存在性

[英]How to destruct a exist in goal for coq

This is a bit generic so feel free to ask for details, I simplified to make the problem easier to communicate. 这有点通用,所以随时询问细节,我简化了问题的沟通范围。

Say my goal is 说我的目标是

let (r,_) := f x in Q r

where fx has type {u | P u} 其中fx类型为{u | P u} {u | P u} . {u | P u}

I want to "destruct" this so that I have Q r as the goal with P r as a hypothesis. 我想“破坏”这一点,以便以Q r为目标,以P r为假设。 What is the best way to achieve this ? 实现此目标的最佳方法是什么? In the past, I have achieved what I wanted by 过去,我实现了我想要的

pose (f x).

and then simplifying. 然后简化。

Per request here is some simplified code. 每个请求都是一些简化的代码。

Parameter T:Type.
Parameter P:T -> Prop.

Axiom A : {t:T|P t}.

Definition myvar:T.
  destruct A.
  exact x.
Defined.
Theorem B : P myvar.
unfold myvar; destruct A.

will solve your goal in this particular case. 将在这种情况下解决您的目标。

In general, the destruct tactic can be used with with any term and it will try to abstract the term out and destruct it. 通常, destruct策略可以与任何术语一起使用,并且它将尝试将术语抽象出来并对其进行销毁。 However, note that this may fail sometimes, particularly when using dependent types. 但是,请注意,有时这可能会失败,尤其是在使用依赖类型时。

The reason is that destruct uses the gallina match underneath, and in Coq, pattern matching may lose some typing information if not done carefully, search for "Convoy Pattern" for more information. 原因是destruct使用下面的Gallina match ,并且在Coq中,如果不仔细进行模式匹配,可能会丢失一些键入信息,请搜索“ Convoy Pattern”以获取更多信息。

You can name the 'outputs' of a destruct tactic if you want: 您可以根据需要命名destruct策略的“输出”:

(* Stupid definitions to create a minimal example *)
Parameter A: Set.
Parameter P Q: A -> Prop.
Definition f (x: A) : {r | P r }.
Admitted.

Goal (forall x, let (r, _) := f x in Q r).
intro x.
destruct f as [r hr]. (* you goal has now r: A and hr : P r as premises *)
Abort.

Edit: more info after comment. 编辑:评论后的更多信息。 If you don't name them, Coq will do it automatically for you using a scheme based on xi variables ( x0, x1, ... ). 如果您没有命名,Coq将使用基于xi变量( x0, x1, ... )的方案为您自动完成。 You can only force the naming of the first variable if you don't care about the name of the second part using destruct f as [r]. 如果您不关心使用destruct f as [r].的第二部分的名称,则只能强制第一个变量的命名destruct f as [r].

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM