【发布时间】:2017-10-06 14:01:50
【问题描述】:
我们有一个函数可以将元素插入到列表的特定索引中。
Fixpoint inject_into {A} (x : A) (l : list A) (n : nat) : option (list A) :=
match n, l with
| 0, _ => Some (x :: l)
| S k, [] => None
| S k, h :: t => let kwa := inject_into x t k
in match kwa with
| None => None
| Some l' => Some (h :: l')
end
end.
上述函数的以下性质与问题相关(证明省略,l 的直接归纳,n 未修复):
Theorem inject_correct_index : forall A x (l : list A) n,
n <= length l -> exists l', inject_into x l n = Some l'.
我们有一个置换的计算定义,iota k 是一个 nats 列表[0...k]:
Fixpoint permute {A} (l : list A) : list (list A) :=
match l with
| [] => [[]]
| h :: t => flat_map (
fun x => map (
fun y => match inject_into h x y with
| None => []
| Some permutations => permutations
end
) (iota (length t))) (permute t)
end.
我们要证明的定理:
Theorem num_permutations : forall A (l : list A) k,
length l = k -> length (permute l) = factorial k.
通过对l 的归纳,我们可以(最终)达到以下目标:length (permute (a :: l)) = S (length l) * length (permute l)。如果我们现在简单地cbn,那么最终的目标表述如下:
length
(flat_map
(fun x : list A =>
map
(fun y : nat =>
match inject_into a x y with
| Some permutations => permutations
| None => []
end) (iota (length l))) (permute l)) =
length (permute l) + length l * length (permute l)
这里我想通过destruct (inject_into a x y) 继续,考虑到x 和y 是lambda 参数,这是不可能的。请注意,由于引理inject_correct_index,我们永远不会得到None 分支。
如何从这个证明状态出发? (请注意,我并不是要简单地完成定理的证明,这完全不相关。)
【问题讨论】:
-
A minimal reproducible example 与所有进口将帮助我们帮助你:)
-
@AntonTrunov 可以让它稍微小一点,希望 2 个定义在合理范围内。
-
您可能想用
Lemma eq_map X Y (f g : X -> Y) l : (forall x, f x = g x) -> map f l = map g l. Proof. intros h_eq; induction l as [|x l ihl]; [easy|]. now simpl; rewrite h_eq, ihl. Qed.重写,flat_map也类似。这样,您可以断言所需的扩展相等性。