Coq:定义一个从 sigma 类型到它的第二个投影的函数(并使其成为强制)

Coq: defining a function from a sigma type to its second projection (and making it a coercion)

我无法从 sigma 类型证明第二个投影的类型:

Variable X:Type.
Variable Phy: X -> Type.
Definition e {x:X}: {x:X & Phy x} -> Phy x. 
intro. Fail exact (@projT2 _ _ X0).
(*The term "projT2 X0" has type "Phy (projT1 X0)"
while it is expected to have type "Phy x" (cannot unify
"(fun x : X => Phy x) (projT1 X0)" and "Phy x").*)

是否有{x:X & Phy x}(或{x:X | Phy x})的见证不足以通过投影获得Phy x的见证?无论哪种方式,我都可以通过假设证人来定义 e(更愚蠢)。此外,我想将其强制转换(但失败):

Reset e.
Definition PhyX := {x:X & Phy x}.
Definition e {x:X} {z:Phy x} {y:PhyX}: PhyX -> Phy x := fun y => z.
Coercion e: PhyX >-> Funclass. (*e does not respect the uniform inheritance condition*)

现在的问题是:我可以更明智地定义 e and/or 使其成为强制转换吗?

编辑:我认为假设 Phy x 的见证是必要的,因为 existTdeclared 的方式:existT (x:A) (_:P x)。这是上面最后两行代码的更好版本(仍然无法使其成为强制):

Definition e {x:X} {h:Phy x}: PhyX -> Phy x := fun _ => projT2 (existT _ _ h).
Coercion e: PhyX >-> Phy. (*e does not respect the uniform inheritance condition*)

在您的定义中,有两个 X 值:一个作为 {x:X} 的参数给出,另一个隐藏在 sigma 中。这两者不可互换。

可以做的是:

Definition e (p : {x:X & Phy x}) : Phy (projT1 p).
  destruct p; simpl; assumption.
Defined.