以证明模式中定义依赖记录元素的人体工程学方式?

huangapple go评论52阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年6月16日 07:56:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76486170.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定