在coq中如何证明强排序列表?

在coq中如何证明强排序列表?,coq,proof,formal-verification,Coq,Proof,Formal Verification,我正在尝试制作一个Coq河内校样塔作为学习练习。经过数小时徒劳的尝试后,我的第一次证明中的最后一个目标被卡住了 你能解释一下我的程序失败的原因,以及如何纠正它吗 编辑:回顾代码,似乎我需要证明StronglySorted le(l:list nat)才能证明有序堆叠,不是吗 Require Import List. Require Import Arith. Require Import Coq.Sorting.Sorting. Definition stack_disk := fun (

我正在尝试制作一个Coq河内校样塔作为学习练习。经过数小时徒劳的尝试后,我的第一次证明中的最后一个目标被卡住了

你能解释一下我的程序失败的原因,以及如何纠正它吗

编辑:回顾代码,似乎我需要证明
StronglySorted le(l:list nat)
才能证明
有序堆叠
,不是吗

Require Import List.
Require Import Arith.
Require Import Coq.Sorting.Sorting.

Definition stack_disk :=
  fun (n:nat) (l:list nat) =>
    match l with
      | nil => n::nil
      | n'::l' =>
          if n' <? n
          then n::l
          else l
    end.

Eval compute in (stack_disk 2 (1::0::nil)).
Eval compute in (stack_disk 2 (2::1::0::nil)).

Lemma ordered_stacking: forall (n:nat) (l:list nat),
  StronglySorted le l -> StronglySorted le (stack_disk n l) -> StronglySorted le (n::l).
  Proof.
    intros n l H.
    induction l as [|hl tl];simpl;auto.
    destruct (hl <? n).
    auto.
    constructor.
    apply H.

问题是您没有记录
n
匹配
|nil=>n::nil
|n'::l'=>

如果n'问题是您没有记录
n
匹配
|nil=>n::nil
|n'::l'=>
如果
1 subgoal
n, hl : nat
tl : list nat
H : StronglySorted le (hl :: tl)
IHtl : StronglySorted le tl ->
       StronglySorted le (stack_disk n tl) -> StronglySorted le (n :: tl)
H0 : StronglySorted le (hl :: tl)
______________________________________(1/1)
Forall (le n) (hl :: tl)
Require Import List.
Require Import Arith.
Require Import Coq.Sorting.Sorting.

Definition stack_disk :=
  fun (n:nat) (l:list nat) =>
    match l with
      | nil => n::nil
      | n'::l' =>
          if n' <? n
          then n::l
          else l
    end.

Lemma ordered_stacking: forall (n:nat) (l:list nat),
  StronglySorted le l -> StronglySorted le (stack_disk n l) -> StronglySorted le (n::l).
Proof.
  intros n [|m l].
  - intros _ _; repeat constructor.
  - simpl. intros H1 H2.
    destruct (Nat.ltb_spec m n); trivial.
    constructor; trivial.
    apply StronglySorted_inv in H1.
    destruct H1 as [_ H1].
    constructor; trivial.
    revert H1; apply Forall_impl.
    now intros p; apply Nat.le_trans.
Qed.