Coq Ltac对目标类型的子项进行抽象

Coq Ltac对目标类型的子项进行抽象,coq,Coq,作为一个粗糙的、未经训练的背景,我们可以推断出归纳定义的类型 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 γ. exa

作为一个粗糙的、未经训练的背景,我们可以推断出归纳定义的类型

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,以便我们可以
应用(传输G H)
。到目前为止,我只知道

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
经常被使用

问题是

有没有什么是正确的做法


有一个关于对类型中的关系使用重写的问题,它允许您只说
重写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.
需要导入Coq.Setoids.Setoid Coq.Classes.CMorphisms。
感应路径{X:Type}:X->X->Type:=
|idpath:forall x:x,path x。
引理传输{X:Type}(P:X->Type){xy:X}(γ:路径xy):
Px->Py。
证明。
诱导γ。
精确(乐趣a=>a)。
定义
全局实例路径_自反{A}:自反(@paths A):=idpath。
全局实例路径\u对称{A}:对称(@paths A)。
证明。介绍??[]; 构造器。定义
全局实例正确路径{A}(x:A):正确路径x:=idpath x。
全局实例路径\u子关系
(A:类型)(R:皱纹A)
{RR:reflective R}
:子关系路径R。
证明。
介绍??P
应用(传输),RR。
定义
全局实例自反\u路径\u dom\u自反
{B} {R':creation B}{RR':自反R'}
{A:Type}
:自反(@path A==>R')%签名。
证明。介绍???[]; 应用RR’。定义
所有(xy:nat)G的目标,路径xy->gx->gy。
简介x y G H Q。
重写
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.