我要通过归纳来证明
no f xs ==> null (filter f xs)
其中:
filter p [] = []
filter p (x:xs)
| p x = x : filter p xs
| otherwise = filter p xs
null [] = True; null _ = False
no p [] = True
no p (x:xs)
| p x = False
| otherwise = no p xs
Logic implication:
True ==> False = False
_ ==> _ = True
所以,我认为以下是我的假设和我的主张:
Assumption: no f xs ==> null (filter f xs)
Claim: no f (x:xs) ==> null (filter f (x:xs))
我开始尝试证明基本情况(空列表):
no f [] ==> null (filter f [])
== {- Filter.1, filter p [] = [] -}
no f [] ==> null ([])
== {- No.1, no p [] = True-}
True ==> null ([])
== {- Null.1, null [] = True -}
True ==> True
但是我不确定它是否正确,因为我已经证明它们都是真的而不是如果左边的部分是真的而第二部分是假的,那么暗示就是假的(那个是==>)的定义。 它是否正确? 我怎样才能继续证明? 我不清楚如何使用归纳来证明其含义......
提前谢谢!
答案 0 :(得分:1)
这是完整的证据。后来,当我有更多的时间,我将在Agda或Idris上证明这一点并在此处发布代码。
通过xs
的归纳证明。
案例xs = []
:
no f [] ==> null (filter f [])
== {- Filter.1, filter p [] = [] -}
no f [] ==> null ([])
== {- No.1, no p [] = True-}
True ==> null ([])
== {- Null.1, null [] = True -}
True ==> True
案例xs = y : ys
。假设no f ys == null (filter f ys)
。请考虑以下情况:
案例f y == True
:
no f (y : ys) ==> null (filter f (y : ys))
== {- no - f y == True -}
False ==> null (filter f (y : ys))
==
True
案例f y == False
:
no f (y : ys) ==> null (filter f (y : ys))
=={- By definition of filter and no -}
no f ys ==> null (filter f ys)
== {By I.H.}
True
完成证明。