我已经提出了一个与此证明相关的不同问题,所以我很抱歉重复。只有没有人会回答,因为另一个人有答案。我写的这个证明是否正确,如果不是,有什么不对?
我试图证明通过结构归纳如下声明:
foldr f st (xs++yx) = f (foldr f st xs) (foldr f st ys) (foldr.3)
这些foldr相似的定义:
foldr f st [] = st (foldr.1)
foldr f st x:xs = f x (foldr f st xs) (foldr.2)
现在我要开始的基本情况通过空工作列表到xs。我有这个,但我不知道这是否正确。
foldr f st ([]++ys) = f (foldr f st []) (foldr f st ys)
LHS:
foldr f st ([]++ys)
= foldr f st ys by (++) and by (foldr.1)
RHS:
f (foldr f st []) (foldr f st ys) =
= f st (foldr f st ys) by (foldr.1)
= foldr f st ys by def of st = 0 and f = (+)
LHS = RHS, therefore base case holds
现在,这是我对我的归纳步:
Assume that:
foldr f st (xs ++ ys) = f (foldr f st xs) (foldr f st ys) (ind. hyp)
Show that:
foldr f st (x:xs ++ ys) = f (foldr f st x:xs) (foldr f st ys)
LHS:
foldr f st (x:xs ++ ys)
= f x (foldr f st (xs++yx)) (by foldr.2)
= f x (f (foldr f st xs) (foldr f st ys)) (by ind. hyp)
= f (f x (foldr f st xs)) (foldr f st ys) (by assosiativity of f)
RHS:
f (foldr f st x:xs) (foldr f st ys)
= f (f x (foldr f st xs)) (foldr f st ys) (by foldr.2)
LHS = RHS, therefore inductive step holds. End of proof.
我不知道,如果这个证明是有效的。我需要一些帮助来确定它是否正确,如果不正确 - 哪部分不是。
这是不正确的。如果你正在进行归纳,你必须选择一个变量来进行归纳。你似乎选择了xs,这使得基本情况'foldr f st([] ++ yx)= f(foldr f st [])(foldr f st ys)''。 – augustss
我要编辑基本案例。它只是基本情况是不正确的? –
作业?很难相信你必须证明一些关于foldr的内容,但“没有提供任何定义”。 – d8d0d65b3f7cf42