我注意到我一直在为嵌套(有时是相互的)归纳类型重新定义非常相似的归纳原则,因为Coq自动生成的归纳太弱了。这是一个非常简单的例子:
DataContext
Coq自动生成ComboBox
:
Require Import Coq.Lists.List.
Inductive T : Set :=
| C1 : T
| C2 : list T -> T.
Section T_nested_ind.
Variable P : T -> Prop.
Hypothesis C1_case : P C1.
Hypothesis C2_case : forall l : list T, Forall P l -> P (C2 l).
Fixpoint T_nested_ind (t : T) :=
match t with
| C1 => C1_case
| C2 xs =>
let H := (fix fold (xs : list T) : Forall P xs :=
match xs with
| nil => Forall_nil _
| x :: xs => Forall_cons _ (T_nested_ind x) (fold xs)
end) xs in
C2_case xs H
end.
End T_nested_ind.
虽然我需要对列在T_ind
列表中的元素进行归纳假设:
forall P : T -> Prop,
P C1 ->
(forall l : list T, P (C2 l)) ->
forall t : T, P t
答案 0 :(得分:1)
这是一个部分答案:
fix
来做得更好。