作为一个粗略而无条件的背景,在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.
Lemma transport
将成为HoTT“替换”或“重写”策略的核心;据我所知,这个伎俩就是假设你或我可以抽象地认出的目标
...
H : paths x y
[ Q : (G x) ]
_____________
(G y)
找出必要的依赖类型G,以便我们可以apply (transport 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
经常被使用。
问题是
[有没有|什么是正确的事情?
答案 0 :(得分:5)
对于类型中的关系使用重写有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.
可能会做你想要的。
答案 1 :(得分:2)
Tom Prince在his answer中提到的功能请求已被授予:
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.
我通过Set Typeclasses Debug
setoid_rewrite <- H
和H : paths x y
时H : eq x y
与C++
的日志进行比较,找到了所需的实例。