将函数转换为 table 查找是什么意思?

What does it mean to convert a function to a table look up?

this video titled Don't fear the monad, between 05:02 and 06:05 中,Brian Beckman 说:

Every imperative programmer goes through this phase of learning that functions can be replaced with table look-ups. Often, you do this for performance. You want to make the sin function or the cosine function, just make a table and interpolate in that table....Everybody learns this trick.

我想知道他所说的这个技巧是什么意思,以及它如何提高性能。能详细说说吗?

这是否意味着像 Dictionary<TKey, Func<TInput, TReturn>> 那样进行某种查找?

这意味着每个算法,只要有足够的(可能是无限的)内存,就可以将基于输入值的预先计算的输出值存储在(索引)数组中,从而将算法转换为 O(1) 数组查找。这是一个与计算本身一样古老的技巧,比计算机早几个世纪。科学家们总是使用预先计算值的表格来快速获得结果,而无需进行实际计算。

涵盖此主题的维基百科文章是 https://en.wikipedia.org/wiki/Lookup_table

顺便说一句,许多现实生活中的算法(这里想到 CRC)也这样做,尤其是当速度至关重要时(实时应用程序)。请注意,存储预计算值所需的内存量与预期精度和输入变量的数量直接相关。