`iterate`是否有原始元素开始的原因? [英] Is there a reason for `iterate` to start with original element?
问题描述
我有时使用迭代,但我很少在结果列表中需要
参数。
I sometimes use iterate but I rarely need the argument in the resulting list.
From the documentation:
iterate f x == [x, f x, f (f x), ...]
尽管我可以 drop 1
它,我不知道是否存在一个很好的理由(也许是一个自由定理)独立于设计这样的基本功能的实现。
Although I can drop 1
it, I wonder whether there exists a good reason (maybe a free theorem) independent from implementation for designing basic functions like this one.
推荐答案
在讨论迭代函数应用程序时,定义 f ^ 0 == id
是很方便的,所以像<$ c $对于所有的自然数 m ,持有
(f ^ n(x))== f ^(m + n) code>和 n
。
When talking about iterated function application, it is convenient to define f^0 == id
, so that identities like f^m(f^n(x)) == f^(m+n)(x)
hold
for all natural numbers m
and n
.
有了这个定义, iterate
通过首先包含参数来满足以下标识:
With that definition in mind, iterate
satisfies the following identity by including the argument first:
iterate f x !! n == f^n x
这篇关于`iterate`是否有原始元素开始的原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!