[英]How do define a custom induction principle in coq?
This is kind of a follow up on a previous question I asked, but now I'm just trying to implement my own induction principle for the equality type, which I'm not sure how to do without some kind of pattern matching.这是对我之前提出的问题的跟进,但现在我只是想为相等类型实现我自己的归纳原则,如果没有某种模式匹配,我不知道该怎么做。 I'm avoiding using the induction tactic in the below definition, as this obviously leads to a kind of chicken vs. egg conundrum.
我避免在下面的定义中使用归纳策略,因为这显然会导致一种鸡与蛋的难题。 Is there any possible way to do this with some basic tactics except indction, as well as via the vanilla Definition J2:=...?
除了indction 以及通过 vanilla Definition J2:=... 之外的一些基本策略是否有任何可能的方法来做到这一点?
(* define a similair induction principle from this agda code*)
J2 : {A : Set} → (D : (x y : A) → (I A x y) → Set)
→ (d : (a : A) → (D a a r )) → (x y : A) → (p : I A x y) → D x y p
J2 D d x .x r = d x
Theorem J2 {A} :
forall (D : forall (x y : A), Id A x y -> Prop),
forall (d : forall (a : A), (D a a (refl A a))),
forall (x y : A) (p : Id A x y), D x y p.
Proof.
intros.
inversion p.
subst.
apply D y.
This yields the following error, and I'm not sure how to indicate that p must be a refl without the induction tactic.这会产生以下错误,我不确定如何表明 p 必须是没有归纳策略的 refl 。
1 subgoal (ID 34)
A : Type
D : forall x y : A, Id A x y -> Prop
d : forall a : A, D a a (refl A a)
y : A
p : Id A y y
============================
D y y p
Which yields the following error.这会产生以下错误。
Error:
In environment
A : Type
D : forall x y : A, Id A x y -> Prop
d : forall a : A, D a a (refl A a)
y : A
p : Id A y y
Unable to unify "D y y (refl A y)" with "D y y p".
Finally, a somewhat adjoint error, when I try writing apply d in y
I get the following error.最后,一个有点伴随的错误,当我尝试
apply d in y
我收到以下错误。
Error:
Unable to apply lemma of type "forall a : A, D a a (refl A a)"
on hypothesis of type "A".
Why isn't the typechecker happy?为什么类型检查器不高兴?
Instead of inversion p
, use destruct p
, which does pattern-matching in a straightforward way.使用
destruct p
代替inversion p
,它以直接的方式进行模式匹配。
inversion
is only meant to work on assumptions whose proof terms are not used in the goal. inversion
仅适用于目标中未使用证明术语的假设。 Here p
is used in the goal.这里
p
用于目标。
Is there any possible way to do this with some basic tactics except indction, as well as via the vanilla Definition J2:=...?
除了 indction 以及通过 vanilla Definition J2:=... 之外的一些基本策略是否有任何可能的方法来做到这一点?
Let me answer to the second part of your question:让我回答你问题的第二部分:
Inductive Id (A : Type) (x : A) : A -> Type :=
| refl : Id A x x.
Definition J2 {A} :
forall
(D : forall (x y : A), Id A x y -> Prop)
(d : forall (a : A), (D a a (refl A a)))
(x y : A) (p : Id A x y),
D x y p
:=
fun D d x y p =>
match p in Id _ _ y
return D x y p
with
| refl _ _ => d x
end.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.