Sorting 使用Coq进行快速排序验证
我正在写一篇关于使用Coq系统对快速排序算法进行程序验证的论文。我已经在Coq中定义了快速排序,但我的主管和我自己都不太习惯使用策略来编写实际的证明。有没有人能帮你做这部分的coq证明?以下是我们到目前为止得出的结论:Sorting 使用Coq进行快速排序验证,sorting,quicksort,coq,Sorting,Quicksort,Coq,我正在写一篇关于使用Coq系统对快速排序算法进行程序验证的论文。我已经在Coq中定义了快速排序,但我的主管和我自己都不太习惯使用策略来编写实际的证明。有没有人能帮你做这部分的coq证明?以下是我们到目前为止得出的结论: Inductive nat : Type := | O : nat | S : nat -> nat. Check (S (S (S (S O)))). Definition isZero (n:nat) : bool := match n with
Inductive nat : Type :=
| O : nat
| S : nat -> nat.
Check (S (S (S (S O)))).
Definition isZero (n:nat) : bool :=
match n with
O => true
|S p => false
end.
Inductive List: Set :=
| nil: List
| cons: nat -> List -> List.
Fixpoint Concat (L R: List) : List :=
match L with
| nil => R
| cons l ls => cons l (Concat ls R)
end.
Fixpoint Less (n m:nat) :=
match m with
O => false
|S q => match n with
O => true
|S p => Less p q
end
end.
Fixpoint Lesseq (n m:nat) :=
match n with
O => true
|S p => match m with
O => false
|S q => Lesseq p q
end
end.
Fixpoint Greatereq (n m:nat) :=
match n with
O => true
|S p => match m with
O => true
|S q => Greatereq p q
end
end.
Fixpoint Allless (l:List) (n:nat) : List :=
match l with
nil => nil
|cons m ls => match Less n m with
false => Allless ls n
|true => cons m (Allless ls n)
end
end.
Fixpoint Allgeq (l:List) (n:nat) : List :=
match l with
nil => nil
|cons m ls => match Greatereq n m with
false => Allgeq ls n
|true => cons m (Allgeq ls n)
end
end.
Fixpoint qaux (n:nat) (l:List) : List :=
match n with
O => nil
|S p => match l with
nil => nil
|cons m ls => let low := Allless ls m in
(let high := Allgeq ls m in
Concat (qaux p low) (cons m (qaux p high)))
end
end.
Fixpoint length (l:List) : nat :=
match l with
nil => O
|cons m ls => S (length ls)
end.
Fixpoint Quicksort (l:List) : List := qaux (length l) l.
我知道为了证明我们需要一个引理或一个定理,但我不知道从哪里开始。谢谢你的帮助:)关于你的代码,你可以证明很多很好的定理
- 定义将数字和列表映射到列表中数字索引的函数pos
- Th 1:对于所有列表S和S中的a、b,(a将您的问题视为“符号测试”问题。编写一个函数,测试您的输出是否正确,然后显示初始代码和测试函数的所有组合都按预期工作
下面是我最喜欢的数据类型排序算法测试函数
然后,您可以通过以下方式开始验证:Fixpoint sorted (l : List) : bool := match l with cons a l' => match l' with cons b l'' => if Lesseq a b then sorted l' else false | nil => true end | nil => true end.
但是,在证明主引理之前,你必须证明许多中间引理。因此,形式证明与测试非常相似,只是你要确保测试的全面覆盖Lemma Quicksort_sorted : forall l, sorted (Quicksort l) = true.