我试图通过结构归纳来证明以下陈述:
foldr f st (xs++yx) = f (foldr f st xs) (foldr f st ys) (foldr.3)
但是我什至不确定如何定义 foldr,所以我被困住了,因为没有向我提供定义。我现在相信 foldr 可以定义为
foldr f st [] = st (foldr.1)
foldr f st x:xs = f x (foldr f st xs) (foldr.2)
现在我想开始处理将空列表传递给 foldr 的基本情况。我有这个,但我认为它不正确。
foldr f st ([]++[]) = f (foldr f st []) (foldr f st [])
LHS:
foldr f st ([]++[]) = foldr f st [] by (++)
foldr f st [] = st by (foldr.1)
RHS:
f (foldr f st []) (foldr f st []) = f st st by (foldr.1)
= st by definition of identity, st = 0
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) (inductive step)
LHS:
foldr f st (x:xs ++ ys) = f x (foldr f st xs) (foldr f st ys) (by foldr.2)
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)
= f x (foldr f st xs) (foldr f st ys)
LHS = RHS, therefore inductive step holds. End of proof.
我不确定这个证明是否有效。我需要一些帮助来确定它是否正确,如果不正确 - 它的哪一部分不是。