关于级联列表排序的引理

问题描述

对于列表的排序,我有以下归纳定义:


Class DecTotalOrder (A : Type) := {
  leb : A -> A -> bool;
  leb_total_dec : forall x y,{leb x y}+{leb y x};
  leb_antisym : forall x y,leb x y -> leb y x -> x = y;
  leb_trans : forall x y z,leb x y -> leb y z -> leb x z }.

Inductive Sorted {A} {dto : DecTotalOrder A} : list A -> Prop :=
| Sorted_0 : Sorted []
| Sorted_1 : forall x,Sorted [x]
| Sorted_2 : forall x y,leb x y ->
                         forall l,Sorted (y :: l) ->
                                   Sorted (x :: y :: l).

以及以下两个定义来声明元素x小于或等于列表中的每个元素(LeLst),并且大于或等于列表中的每个元素(LstLe):

DeFinition LeLst {A} {dto : DecTotalOrder A} (x : A) (l : list A) :=
  List.Forall (leb x) l.

DeFinition LstLe {A} {dto : DecTotalOrder A} (x : A) (l : list A) := 
   List.Forall (fun y => leb y x) l.

我正在尝试证明以下关于排序的引理,该引理基本上表明:如果我们知道h大于或等于l中的每个元素,并且h小于或等于l'中的每个元素,我们可以将其放在两个:

Lemma lem_lstle_lelst {A} {dto: DecTotalOrder A} : forall h l l',LstLe h l -> LeLst h l' -> Sorted (l ++ h :: l').

这似乎很直观,但是我每次都被证明卡住了。这是我目前的尝试:

Lemma lem_lstle_lelst {A} {dto: DecTotalOrder A} : forall h l l',LstLe h l -> LeLst h l' -> Sorted (l ++ h :: l').
Proof.
intros h l l' H_LstLe.
induction H_LstLe.
- intros. simpl. Search (Sorted (_ :: _)).
  unfold LeLst in H. Search (List.Forall _ _).
  induction l'.
  + constructor.
  + Search (List.Forall _ _). 
    constructor. 
      { hauto use: List.Forall_inv. }
      { generalize (List.Forall_inv_tail H).
        intros.
        generalize (List.Forall_inv H).
        intros. 
        generalize (IHl' H0).
        intros.
        generalize (lem_sorted_tail H2).
        intros.

但是我被困在这里,因为这些假设似乎还不够强大:

1 subgoal
A : Type
dto : DecTotalOrder A
h,a : A
l' : list A
H : List.Forall (fun x : A => leb h x) (a :: l')
IHl' : List.Forall (fun x : A => leb h x) l' -> Sorted (h :: l')
H0 : List.Forall (fun x : A => leb h x) l'
H1 : leb h a
H2 : Sorted (h :: l')
H3 : Sorted l'
______________________________________(1/1)
Sorted (a :: l')

如果有人可以给我一个提示,我真的很高兴,也许我的定义有问题,这就是为什么我不能继续证明?还是我只是错过了一些我可以使用的策略?

以下是已证明有关排序的引理列表:

Lemma lem_sorted_tail {A} {dto : DecTotalOrder A}{l x} :
  Sorted (x :: l) -> Sorted l.

Lemma lem_sorted_prepend {A} {dto: DecTotalOrder A} : forall x l l',Sorted((x :: l) ++ l') -> Sorted(l ++ l').

Lemma lem_sort_conc_mid {A} {dto: DecTotalOrder A} : forall x y l,Sorted (x :: y :: l) -> Sorted (x :: l).

解决方法

如评论中所述,引理不可证明。 相反,它的定义必须通过添加有关l的排序属性来扩展 和l'

Lemma lem_lstle_lelst {A} {dto: DecTotalOrder A} : forall h l l',LstLe h l -> LeLst h l' -> Sorted l -> Sorted l' -> Sorted (l ++ h :: l').

这可以通过以下证明:

Proof.
intros h l l' H_Lstle_h_l.
induction H_Lstle_h_l.
- intros H_Lelst_h_l' H_Sort_1 H_Sort_2.
  simpl;inversion H_Lelst_h_l';sauto.
- intros H_Lelst_h_l' H_Sort_1 H_Sort_2.
  generalize (lem_sorted_tail H_Sort_1).
  intros H_Sort_l.
  generalize (IHH_Lstle_h_l H_Lelst_h_l' H_Sort_l H_Sort_2).
  intros H_Sort_l_h_l'.
  generalize (lem_sorted_lelst x l H_Sort_1).
  intros H_Lelst_x_l.
  hauto use: lem_Sorted_prepend_inv.
Qed. 

介绍新的助手引子:

Lemma lem_Sorted_prepend_inv {A} {dto: DecTotalOrder A} : 
  forall x h l l',leb x h ->  Sorted(l ++ h :: l') -> LeLst x l -> Sorted(x::l++ h::l').

Lemma lem_sorted_lelst {A} {dto: DecTotalOrder A} :
  forall x l,Sorted(x :: l) -> LeLst x l.