英文:
Ergonomic way to define elements of dependent records in proof mode?
问题
I tend to have trouble defining elements of dependent records when I would like to define their fields in proof mode.
Consider the following simple minimal example:
Record foo : Type := {
num : nat;
num_refl : num = num
}.
Goal foo.
Proof.
econstructor.
(* goal is now ?num = ?num *)
Abort.
I would like to be able to instantiate ?num
in proof mode since ?num stands in for expressions that generally will be difficult to write out by hand. Ideally, I would like to be able to do something like the following:
Proof.
better_econstructor.
(* generates two goals, nat and ?num = ?num *)
- exact 2.
- (* goal is now 2 = 2 *) reflexivity.
Defined.
Are there any approaches that mimic this style? Right now, I define the non-dependent stuff elsewhere and then do the proofs using refine, i.e. something like
Goal foo.
Proof.
refine {|
num := two;
num_refl := _
|}.
reflexivity.
Defined.
This works but is a bit tedious when it involves copying and pasting a lot of types.
英文:
I tend to have trouble defining elements of dependent records when I would like to define their fields in proof mode.
Consider the following simple minimal example:
Record foo : Type := {
num : nat;
num_refl : num = num
}.
Goal foo.
Proof.
econstructor.
(* goal is now ?num = ?num *)
Abort.
I would like to be able to instantiate ?num
in proof mode since ?num stands in for expressions that generally will be difficult to write out by hand. Ideally, I would like to be able to do something like the following:
Goal foo.
Proof.
better_econstructor.
(* generates two goals, nat and ?num = ?num *)
- exact 2.
- (* goal is now 2 = 2 *) reflexivity.
Defined.
Are there any approaches that mimic this style? Right now, I define the non-dependent stuff elsewhere and then do the proofs using refine, i.e. something like
Definition two : nat := 2.
Goal foo.
Proof.
refine {|
num := two;
num_refl := _
|}.
reflexivity.
Defined.
This works but is a bit tedious when it involves copying and pasting a lot of types.
答案1
得分: 2
你可以使用 unshelve tac
战术。它应用 tac
并将其创建的每个存在性变量转换为一个目标。
Goal foo.
Proof.
unshelve econstructor.
英文:
You can use the unshelve tac
tactical. It applies tac
and transforms every existential variable it creates into a goal.
Goal foo.
Proof.
unshelve econstructor.
答案2
得分: 1
另一种更明确的解决方案(在此使用ssreflect语法)是使用本地引理:
Goal foo.
Proof.
have two : nat by exact: 2.
econstructor.
exact: (erefl two).
Qed.
英文:
Another more explicit solution (using ssreflect syntax here) would be to use a local lemma:
Goal foo.
Proof.
have two : nat by exact: 2.
econstructor.
exact: (erefl two).
Qed.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论