[英]How do define a custom induction principle in coq?
這是對我之前提出的問題的跟進,但現在我只是想為相等類型實現我自己的歸納原則,如果沒有某種模式匹配,我不知道該怎么做。 我避免在下面的定義中使用歸納策略,因為這顯然會導致一種雞與蛋的難題。 除了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.
這會產生以下錯誤,我不確定如何表明 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
這會產生以下錯誤。
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".
最后,一個有點伴隨的錯誤,當我嘗試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".
為什么類型檢查器不高興?
使用destruct p
代替inversion p
,它以直接的方式進行模式匹配。
inversion
僅適用於目標中未使用證明術語的假設。 這里p
用於目標。
除了 indction 以及通過 vanilla Definition J2:=... 之外的一些基本策略是否有任何可能的方法來做到這一點?
讓我回答你問題的第二部分:
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.