Haskell自定义函数的归纳证明

时间:2015-11-13 11:09:42

标签: haskell induction

我正在学习归纳,而且我还有一些问题需要弄清楚如何完成我的去除感应的感应证明"删除列表中连续重复项的函数:

destutter [] = []                                          Destrutter.1
destutter (x:xs) = x : (destutter (dropWhile (== x) xs))   Destrutter.2

这是假设:

destutter (destutter xs) == destutter xs

这是我到目前为止所做的:

证明基本案例(空列表)

-- BASE CASE --

Left side:
destutter (destutter xs)
== {- xs = [] -}
destutter (destutter [])
== {- Destrutter.1, destutter [] = [] -}
destutter ([])
== {- Destrutter.1, destutter [] = [] -}
[]

Right side:
destrutter xs
== {- xs = [] -}
destrutter []
== {- Destrutter.1, destutter [] = [] -}
[]

Left side == Right side -> Proved

证明一般情况:

-- GENERAL CASE --

Assumption: destutter (destutter xs) == destutter xs
Claim: destutter (destutter (x:xs)) == destutter (x:xs)

destutter (destutter (x:xs))
== {- Destrutter.2, destutter (x:xs) = x : (destutter (dropWhile (== x) xs)) -}
destutter (x: (destutter (dropWhile (== x) xs)))
== {- Destrutter.2, destutter (x:xs) = x : (destutter (dropWhile (== x) xs)) -}
x : (destrutter (dropWhile (==x) (destutter (dropWhile (== x) xs))))

以下是我遇到的一些问题:我无法弄清楚如何使用这个假设:

destrutter (x:xs)

我尝试了不同的方法,但似乎没有人是正确的。 我做的步骤好吗?我的推理方式是否正确?

0 个答案:

没有答案