2014-11-17 44 views
0

我已經提出了一個與此證明相關的不同問題,所以我很抱歉重複。只有沒有人會回答,因爲另一個人有答案。我寫的這個證明是否正確,如果不是,有什麼不對?

我試圖證明通過結構歸納如下聲明:

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. 

我不知道,如果這個證明是有效的。我需要一些幫助來確定它是否正確,如果不正確 - 哪部分不是。

+0

這是不正確的。如果你正在進行歸納,你必須選擇一個變量來進行歸納。你似乎選擇了xs,這使得基本情況'foldr f st([] ++ yx)= f(foldr f st [])(foldr f st ys)''。 – augustss

+0

我要編輯基本案例。它只是基本情況是不正確的? –

+0

作業?很難相信你必須證明一些關於foldr的內容,但「沒有提供任何定義」。 – d8d0d65b3f7cf42

回答

2

UPD:此問題已修改多次。以下在問題的revision 1中有意義。

這是不可能證明的。你需要f是一個monoid:f a (f b c) == f (f a b) cf a st == af st a == a

可證明的聲明將是foldr f st (xs++ys) == foldr f (foldr f st ys) xs


假設fst定義一個獨異,我們可以得到下面的語句:

foldr f st ([]++ys) == 
    -- by definition of neutral element of list monoid, []++ys == ys 
        == foldr f st ys 
    -- by definition of neutral element of `f` monoid, f st a == a 
        == f st (foldr f st ys) 
    -- by definition of foldr, (foldr f st []) == st 
        == f (foldr f st []) (foldr f st ys) 

然後,

foldr f st ((x:xs)++ys) == 
    -- by associativity of list monoid, (x:xs)++ys == x:(xs++ys) 
        == foldr f st (x:(xs++ys)) 
    -- by definition of foldr, foldr f st (x:t) == f x (foldr f st t) 
        == f x (foldr f st (xs++ys)) 
    -- by induction, foldr f st (xs++ys) == f (foldr f st xs) (foldr f st ys) 
        == f x (f (foldr f st xs) (foldr f st ys)) 
    -- by associativity of monoid `f`, f x (f y z) == f (f x y) z 
        == f (f x (foldr f st xs)) (foldr f st ys) 
    -- by definition of foldr, f x (foldr f st t) == foldr f st (x:t) 
        == f (foldr f st (x:xs)) (foldr f st ys) 

在本質上,這是monoid homomorp的證明hism。列表是一個自由幺半羣,同態存在,並且正是你正在尋找的形式 - 它是f的變形。

+0

非常感謝你。在你寫這篇文章的同時,我想到了它。當我看到你的證明時,它基本上和我的一樣。我更新了以上證據以反映我的解釋,但它與您的解釋相同。我相信我上面的內容現在是正確的。非常非常感謝你。能夠與已知的良好解決方案進行比較是非常有幫助的。 –

+1

@RumenHristov當然,它看起來非常相似。必須注意的是,我的答案是針對你的問題的修訂版本1,甚至在問題的修訂版本4中,你需要首先聲明「f」和「st」以及列表元素的類型是monoid - 否則關於'f'的關聯性和'st'的中立性的陳述就會出現。 –

4

你開始證明什麼,查了幾個例子,如前,

xs = ys = [] ; st = True ; f _ _ = False 
+1

我甚至不知道你在說什麼。 –

+3

@RumenHristov這是你的主張的一個反例。如果兩個列表都是空的,'st'是一個真正的布爾值,並且'f'總是錯誤的,你的索賠不成立。因此,沒有證據可以存在。 – chi

相關問題