我同意丹尼尔的方法,不过更一般的方法是写一个
list_gen
,例如使用
repeat
功能:
Require Import List Arith.
Import ListNotations.
Lemma list_gen_spec : forall lng acc, list_gen lng acc = repeat 1 lng ++ acc.
Proof.
induction lng as [| lng IH]; intros xs; simpl; trivial.
rewrite IH.
now rewrite app_cons_middle, repeat_singleton, repeat_app, Nat.add_comm.
Qed.
重复
与一些标准列表函数的交互。
Lemma repeat_singleton {A} (x : A) :
[x] = repeat x 1.
Admitted.
Lemma repeat_app {A} (x : A) n m :
repeat x n ++ repeat x m = repeat x (n + m).
Admitted.
Lemma app_cons {A} (x : A) xs :
x :: xs = [x] ++ xs.
Admitted. (* this is a convenience lemma for the next one *)
Lemma app_cons_middle {A} (y : A) xs ys :
xs ++ y :: ys = (xs ++ [y]) ++ ys.
Admitted.
我把这些引理的证明留作练习。
在证明了规范之后,你的引理可以用一些重写来证明。
Lemma lm1 lng : length(list_gen lng nil) = lng.
Proof.
now rewrite list_gen_spec, app_nil_r, repeat_length.
Qed.