Coq:排序列表的子列表也会排序吗?

时间:2018-11-02 21:09:10

标签: coq

我试图证明如果将列表(L1 ++ a :: L2)强排序为“小于或等于”,则意味着该列表(L1 ++ L2)也已排序(因为它只是一个排序后的列表减去一个元素)。到目前为止,我有

Definition sorted := (StronglySorted (λ x y, x ≤ y)).
Lemma sorted_sublist : ∀ (L1 L2 : list Z) (a : Z), 
                      sorted (L1 ++ a :: L2) ⇒ sorted (L1 ++ L2).
Proof.
  intros.
  induction L1.
  - simpl.
    simpl in H.
    apply StronglySorted_inv in H.    
    destruct H.
    exact H.
  - apply StronglySorted_inv in H.
    destruct H.
    apply IHL1 in H.
    apply SSorted_cons.
    exact H.
    fold (L1 ++ L2).
    fold (L1 ++ a :: L2) in H0.

我留下了 hypotheses and goal。 有任何想法如何完成证明吗?

1 个答案:

答案 0 :(得分:1)

您可以首先以非正式的方式使自己相信这个假设(用符号表示)

H0 : Forall (fun y : Z => (a0 <= y)%Z) (L1 ++ a :: L2)

暗示目标

Forall (fun y : Z => (a0 <= y)%Z) (L1 ++ L2)

所以您在正确的道路上。上述暗示可以通过对L1的另一个归纳证明。

该方法之所以合理,是因为StronglySorted实际上是由双重归纳法类似地定义的:每个后缀都经过严格排序(第一次归纳法),并且头部比其他元素小(对于第一步的第二个归纳法)。

相关问题