感觉就像我被困住了,我的朋友们。有人可以解释我从“功能算法设计的珍珠”第 11 章(“不是最大段总和”)中挑选方程。
这是问题(有点简化)让我们有一些具有给定转换的状态:
data State = E | S | M | N
deriving (Show, Eq)
step E False = E
step E True = S
step S False = M
step S True = S
step M False = M
step M True = N
step N False = N
step N True = N
现在,让我们定义pick:
pick q = map snd . filter ((== q) . fst) . map (\a -> (foldl step E a, a))
作者声称以下七个等式成立:
pick E xs = [[]]
pick S [ ] = [ ]
pick S (xs ++ [x]) = map (++[x ]) (pick S xs ++ pick E xs)
pick M [ ] = [ ]
pick M (xs ++ [x ]) = pick M xs ++ pick S xs
pick N [ ] = [ ]
pick N (xs ++ [x]) = pick N xs ++ map (++[x]) (pick N xs ++ pick M xs)
有人可以用简单的话解释我,为什么这些方程式是正确的,我们如何证明一个明显的证据?我觉得我几乎理解了 S 方程,但总的来说这仍然是难以捉摸的。