通过归纳假设证明(Haskell)
我想证明这句话,mapf(mapgl)=mapg(mapfl) 使得f(gx)=g(fx) 我需要用基本情况和归纳情况来证明这一点。可以按基本情况和归纳情况进行证明,如下所示:通过归纳假设证明(Haskell),haskell,Haskell,我想证明这句话,mapf(mapgl)=mapg(mapfl) 使得f(gx)=g(fx) 我需要用基本情况和归纳情况来证明这一点。可以按基本情况和归纳情况进行证明,如下所示: map f (map g l) = map g (map f l) map f (map g l) = map g (map f l) Base Case: L.H.S map f.(map g []) [ ]= R.H.S map g
map f (map g l) = map g (map f l)
map f (map g l) = map g (map f l)
Base Case:
L.H.S map f.(map g []) [ ]=
R.H.S map g (map f []=[]
map f ( map g [ ])=
map g [ ] = []
map f [ ] = [ ]
Inductive Case: L=(x:xs)
Inductive Hypotheses: ∀ (f.g)
map f (map g (xs)) =
map g (map f (xs)))
L.H.S map f (map g (x:xs))=
map f (g (x): map g (xs))=
(f(g (x)): map f (map g (xs))
(f(g x)) : ((map f) . (map g)) xs=
map f (map g (xs)) (using the Inductive Hypotheses)
map g (map f (xs))) R.H.S
但我认为我的证明是错的。有什么建议吗?OP表示这是一项作业 证明
映射f。mapg==mapg。地图f
已提供f。g==g。f
,其中定义为(f.g)x=f(gx)
归纳数据类型定义:
data [a] = [] -- [] is of type [a]
| (:) a [a] -- if x is of type a, and xs is of type [a],
-- then (x:xs) is of type [a]
基本情况:
(map f . map g) [] = map f (map g []) -- by definition of `.`
= map f [] -- by definition of map
= [] -- by definition of map
= map g [] -- by definition of map
= map g (map f []) -- by definition of map
无论f
和g
是什么。基本情况已得到证实
归纳情况:在归纳假设下,对于某个长度的列表xs
,它是正确的,证明对于前面有一个以上元素的列表(x:xs)
,它是正确的:
(map f . map g) (x:xs)
= map f ( map g (x:xs) ) -- by definition of `.`
= map f ( g x : map g xs ) -- by definition of map
= f ( g x ) : map f ( map g xs ) -- by definition of map
= g ( f x ) : map f ( map g xs ) -- by the condition on f,g
= g ( f x ) : map g ( map f xs ) -- by the Induction Hypothesis
= map g ( f x : map f xs ) -- by definition of map
= map g ( map f (x:xs) ) -- by definition of map
归纳的例子已经被证明了。我想你把
(f(gx)):…
放在末尾你有这个(f(gx)):((mapf)。(mapg))xs=mapf(mapg(xs))
,但是你在右边列表的任何地方都没有(f(gx))
元素,我认为对于所有的x
s,你的主要假设应该是f(gx)=g(fx)
——如果是这样,请编辑你的问题,添加缺少的f
你的陈述是错误的。让g=show。长度
和f=反向
。然后gx=g(fx)
用于所有列表x
。让l=[[0..9]]
。现在mapf(mapgl)=mapf[“10”]=[“01”]
,但是mapg(mapfl)=mapg[[9,8..0]=[“10”]
@Hani:melpomene提供了一个反例来反驳你的说法。正如chi所指出的,你的假设似乎有误。如果我们有f。g=g。f
,然后map(f.g)=map(g.f)
,然后,根据函子定律,map f。mapg=mapg。映射f
(通过列表形状的归纳,您将能够得出相同的结论)。