我已经定义了列表的归纳定义(称为listkind
),以便轻松实现
让我通过归纳listkind
而不是列表来证明一个特定的定理。
Inductive listkind {X}: list X -> Prop :=
| l_nil : listkind []
| l_one : forall a:X, listkind [a]
| l_app : forall l, listkind l -> forall a b, listkind ([a]++l++[b]).
(使用此属性,为了证明列表的内容,我必须证明列表是[],[a]或[a] ++ l ++ [b]的情况,而不是列表是[]或a :: l。在我的特定定理中,这些情况更合适并使证明更简单。)
但是,为了能够在我的证明中使用listkind,我必须证明
Lemma all_lists_are_listkind: (forall {X} (l:list X), listkind l).
尝试了各种方法之后,我发现自己陷入了困境。 我非常感谢看到如何进行这样的证明, 最好使用最小的coq魔法。
答案 0 :(得分:2)
这是一个解决方案:
Require Import List Omega.
Lemma all_lists_are_listkind_size: forall {X} (n:nat) (l:list X), length l <= n -> listkind l.
Proof.
intros X.
induction n as [ | n hi]; simpl in *; intros l hl.
- destruct l as [ | hd tl]; simpl in *.
+ now constructor.
+ now inversion hl.
- destruct l as [ | hd tl]; simpl in *.
+ now constructor.
+ induction tl using rev_ind.
* now constructor.
* constructor.
apply hi.
rewrite app_length in hl; simpl in hl.
omega. (* a bit overkill but it does the arithmetic job *)
Qed.
Lemma all_lists_are_listkind: forall {X} (l:list X), listkind l.
Proof.
intros.
apply all_lists_are_listkind_size with (length l).
apply le_refl.
Qed.
主要思想是你的列表与常规列表具有相同的大小,并且自然的归纳比在非平凡的列表形式上的归纳更顺利。
希望它有所帮助, 诉