对目标类型的子项进行策略性抽象

发布于 2024-12-29 10:23:22 字数 1030 浏览 2 评论 0原文

作为一个粗略且未经训练的背景,在 HoTT 中,人们从归纳定义的类型中推断出

Inductive paths {X : Type } : X -> X -> Type :=
 | idpath : forall x: X, paths x x.

它允许非常一般的

Lemma transport {X : Type } (P : X -> Type ){ x y : X} (γ : paths x y):
  P x -> P y.
Proof.
 induction γ.
 exact (fun a => a).
Defined.

构造引理传输是HoTT“替换”或“重写”策略的核心;据我所知,诀窍是,假设你或我可以抽象地认识到一个目标,即

...
H : paths x y
[ Q : (G x) ]
_____________
(G y)

找出必要的依赖类型 G,以便我们可以应用(传输 GH)。到目前为止,我发现这

Ltac transport_along γ :=
match (type of γ) with 
| ?a ~~> ?b =>
 match goal with
 |- ?F b => apply (transport F γ)
 | _ => idtac "apparently couldn't abstract" b "from the goal."  end 
| _ => idtac "Are you sure" γ "is a path?" end.

还不够普遍。也就是说,第一个idtac 使用得相当频繁。

问题是

[有没有|什么是]正确的做法

As a rough and untutored background, in HoTT, one deduces the heck out of the inductively defined type

Inductive paths {X : Type } : X -> X -> Type :=
 | idpath : forall x: X, paths x x.

which allows the very general construction

Lemma transport {X : Type } (P : X -> Type ){ x y : X} (γ : paths x y):
  P x -> P y.
Proof.
 induction γ.
 exact (fun a => a).
Defined.

The Lemma transport would be at the heart of HoTT "replace" or "rewrite" tactics; the trick, so far as I understand it, would be, supposing a goal which you or I can abstractly recognize as

...
H : paths x y
[ Q : (G x) ]
_____________
(G y)

to figure out what is the necessary dependent type G, so that we can apply (transport G H). So far, all I've figured out is that

Ltac transport_along γ :=
match (type of γ) with 
| ?a ~~> ?b =>
 match goal with
 |- ?F b => apply (transport F γ)
 | _ => idtac "apparently couldn't abstract" b "from the goal."  end 
| _ => idtac "Are you sure" γ "is a path?" end.

isn't general enough. That is, the first idtac gets used rather often.

The question is

[Is there a | what is the] Right Thing to Do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

横笛休吹塞上声 2025-01-05 10:23:22

关于对类型中的关系使用重写,存在一个 bug,这会允许你只说rewrite <- y.

同时,

Ltac transport_along γ :=
  match (type of γ) with 
    | ?a ~~> ?b => pattern b; apply (transport _ y)
    | _ => idtac "Are you sure" γ "is a path?"
  end.

可能会做你想做的事情。

There is a bug about using rewrite for relations in type, which would allow you to just say rewrite <- y.

In the mean time,

Ltac transport_along γ :=
  match (type of γ) with 
    | ?a ~~> ?b => pattern b; apply (transport _ y)
    | _ => idtac "Are you sure" γ "is a path?"
  end.

probably does what you want.

冬天旳寂寞 2025-01-05 10:23:22

Tom Prince 在他的回答中提到的功能请求已获得批准:

Require Import Coq.Setoids.Setoid Coq.Classes.CMorphisms.
Inductive paths {X : Type } : X -> X -> Type :=
| idpath : forall x: X, paths x x.

Lemma transport {X : Type } (P : X -> Type ){ x y : X} (γ : paths x y):
  P x -> P y.
Proof.
  induction γ.
  exact (fun a => a).
Defined.

Global Instance paths_Reflexive {A} : Reflexive (@paths A) := idpath.
Global Instance paths_Symmetric {A} : Symmetric (@paths A).
Proof. intros ?? []; constructor. Defined.

Global Instance proper_paths {A} (x : A) : Proper paths x := idpath x.
Global Instance paths_subrelation
       (A : Type) (R : crelation A)
       {RR : Reflexive R}
  : subrelation paths R.
Proof.
  intros ?? p.
  apply (transport _ p), RR.
Defined.
Global Instance reflexive_paths_dom_reflexive
       {B} {R' : crelation B} {RR' : Reflexive R'}
       {A : Type}
  : Reflexive (@paths A ==> R')%signature.
Proof. intros ??? []; apply RR'. Defined.

Goal forall (x y : nat) G, paths x y -> G x -> G y.
  intros x y G H Q.
  rewrite <- H.
  exact Q.
Qed.

我通过比较获得的日志找到了所需的实例当 H : paths x y 和当 H : eq x 时,从 setoid_rewrite <- H 设置类型类调试 y 。

The feature request mentioned by Tom Prince in his answer has been granted:

Require Import Coq.Setoids.Setoid Coq.Classes.CMorphisms.
Inductive paths {X : Type } : X -> X -> Type :=
| idpath : forall x: X, paths x x.

Lemma transport {X : Type } (P : X -> Type ){ x y : X} (γ : paths x y):
  P x -> P y.
Proof.
  induction γ.
  exact (fun a => a).
Defined.

Global Instance paths_Reflexive {A} : Reflexive (@paths A) := idpath.
Global Instance paths_Symmetric {A} : Symmetric (@paths A).
Proof. intros ?? []; constructor. Defined.

Global Instance proper_paths {A} (x : A) : Proper paths x := idpath x.
Global Instance paths_subrelation
       (A : Type) (R : crelation A)
       {RR : Reflexive R}
  : subrelation paths R.
Proof.
  intros ?? p.
  apply (transport _ p), RR.
Defined.
Global Instance reflexive_paths_dom_reflexive
       {B} {R' : crelation B} {RR' : Reflexive R'}
       {A : Type}
  : Reflexive (@paths A ==> R')%signature.
Proof. intros ??? []; apply RR'. Defined.

Goal forall (x y : nat) G, paths x y -> G x -> G y.
  intros x y G H Q.
  rewrite <- H.
  exact Q.
Qed.

I found the required instances by comparing the logs I got with Set Typeclasses Debug from setoid_rewrite <- H when H : paths x y and when H : eq x y.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文