我在 Isabelle/HOL 中实现了一些插入排序算法,用于生成代码(ML、Python 等)。我确信相应的函数可以正常工作,但我需要创建一些定理来证明它并确保它可以正常工作。我的功能是:
(* The following functions are used to prove the algorithm works fine *)
fun menor_igual :: "nat ⇒ nat list ⇒ bool" where
"menor_igual n [] = True" |
"menor_igual n (x # xs) = (n ≤ x ∧ menor_igual n xs)"
fun ordenado :: "nat list ⇒ bool" where
"ordenado [] = True" |
"ordenado (x # xs) = (menor_igual x xs ∧ ordenado xs)"
fun cuantos :: "nat list ⇒ nat ⇒ nat" where
"cuantos [] num = 0" |
"cuantos (x # xs) num = (if x = num then Suc (cuantos xs num) else cuantos xs num)"
(* These functions make the algorithm itself *)
fun insertar:: "nat ⇒ nat list ⇒ nat list" where
"insertar num [] = [num]" |
"insertar num (x # xs) = (if (num ≤ x) then (num # x # xs) else x # insertar num xs)"
fun asc :: "nat list ⇒ nat list" where
"asc [] = []" |
"asc (x # xs) = insertar x (asc xs)"
问题是我不知道如何正确创建定理。我需要证明有序列表与原始列表具有相同的长度,并且两个列表具有相同的元素名称。我的第一个定理是:
theorem "ordenado (asc xs)"
apply (induction xs rule: asc.induct)
apply auto
theorem "cuantos (asc xs) x = cuantos xs x"
apply (induction xs rule: asc.induct)
apply auto
第一个定理试图证明列表是正确排序的,第二个定理试图证明两个列表具有相同的长度。
当我应用归纳和自动时,我希望得到 0 个子目标,这说明定理是正确的并且算法工作正常,但是在那之后我不知道如何删除子目标,我的意思是我不知道该怎么做简化规则(lemma [simp]: ""
)来做,我会感谢你的帮助。