我已經提出了一個與此證明相關的不同問題,所以我很抱歉重複。只有沒有人會回答,因爲另一個人有答案。我寫的這個證明是否正確,如果不是,有什麼不對?
我試圖證明通過結構歸納如下聲明:
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