计算机编程艺术记号问题

发布于 2024-07-14 02:00:47 字数 889 浏览 7 评论 0原文

我刚刚开始阅读 TAOCP 第 1 卷,但无法理解其风格。

Knuth 提到一种计算方法是四元组(Q、I、Omega、f)——但我很难理解其中每一个的含义。 我理解他的第一个例子,但不理解他的第二个例子,

我正在看第三版的第8页。


在本章末尾处有一个讨论字符串集的算法。

(我已经用一些更容易输入的变量替换了希腊变量 - 抱歉)

令 A 为有限字母集,并令 A* 为 A 上所有字符串的集合。 这个想法是对计算的状态进行编码,以便它们由 A* 的字符串表示

Q = (s,j) where s is in A* and j is an integer, 0 <= j <= N 
I = subset of Q with j = 0
Omega = subset with j = N
f = function below  

(注意 p 和 w 是字符串) 如果 和 s 是 A* 中的字符串,如果 s 对于字符串 p 和 w 具有 pTw 形式,则我们说 T 出现在 s 中。

f(s,j) = (s,aj)             if Tj does not occur in s;
f(s,j) = (pYjw,bj)   if p is the shortest possible string for which s = pYjw
f(s,N) = (s,N)

我理解制作字符串集的概念,但不理解他在这里试图说的全部。 为什么我需要 Q、I、Omega? f 真正向我解释的是什么(为什么 f 中需要 3 个函数?)?

任何人都可以帮忙阐明一些情况吗?

I'm just starting to read TAOCP Volume 1 and I'm having trouble understanding the style.

Knuth mentions a computational method to be a quadruple (Q,I, Omega, f) -- but I am having trouble understanding what each of these is intended to be. I understand his first example, but don't understand his second

I'm looking at page 8 of the third edition.


Near the end of the chapter there is an algorithm that talks about sets of strings.

(I have replaced Greek variables with some easier to type ones -- sorry)

Let A be a finite set of letters, and let A* be the set of all string on A.
The idea is to encode the states of the computation so that they are represented by strings of A*

Q = (s,j) where s is in A* and j is an integer, 0 <= j <= N 
I = subset of Q with j = 0
Omega = subset with j = N
f = function below  

(note that p & w are strings)
If and s are strings in A*, we say that T occurs in s if s has the form pTw for strings p and w.

f(s,j) = (s,aj)             if Tj does not occur in s;
f(s,j) = (pYjw,bj)   if p is the shortest possible string for which s = pYjw
f(s,N) = (s,N)

I understand the concept of making sets of strings, but don't understand all that he is trying to say here. Why do I need Q, I, Omega? What is the f really explaining to me (why do I need 3 functions in f?)??

Can anyone help shed some light?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

妄想挽回 2024-07-21 02:00:47

Q = 状态集(以便 (s, j) 表示 s 在时间 j 的状态)
I = 初始状态(因此要求 j == 0
Omega = 最终状态(因此要求 j == N
f = 转换函数

此外,不存在名为 f 的三个函数,而是 f 由三个方程分段定义。

Q = set of states (so that (s, j) represents state s at time j)
I = initial states (hence the requirement that j == 0)
Omega = final states (hence the requirement that j == N)
f = transition function

Also, there aren't three functions named f but rather f is piecewise-defined by three equations.

末が日狂欢 2024-07-21 02:00:47

为了充分披露,我最近写了一篇文章,关于理解 Knuth(示例前)的正式定义算法。 下面的大部分内容只是深入回答您的第一个问题的文章中相关文本的复制/粘贴;

您关于 (Q, I, Ω, f) 的第一个问题


让我们正式定义一个计算方法为四元组 (Q, I,
Ω, f),其中 Q 是包含子集 I 和 Ω 的集合,f 是
从 Q 到自身的函数。

当 Knuth 将计算方法称为四元组时,他只是说计算方法由四个明确定义的部分组成。 他将这四个部分标记为(Q, I, Ω, f)。 然后他继续简要描述这个四元组的每个组成部分。 IΩ 是集合(事物的集合),Q 也是包含集合 I< 中的事物的集合/code> 和 Ω。 此时,很容易错误地认为他的意思是 Q 仅包含集合 IΩ 而没有其他内容。 但后来我们发现事实并非如此。 最后,他将 f 描述为从 Q 到自身的函数。 这意味着 f 是一个进程,它接受来自集合 Q 中的一个元素的输入,并返回或输出 Q 中的另一个元素。

此外,f 应该使 Ω 逐点固定; 也就是说,f(q) 应该
Ω 的所有元素 q 都相等。

这本质上意味着,如果参数是集合Ω(中的事物)的成员或元素,我们的函数 f 返回的内容将与其参数相同(即值不会改变) 。 当 Knuth 在他的下一个声明中做出澄清时,这就更有意义了; 剧透警告 - Ω 是我们计算方法的一组可能输出。 一旦我们知道了这一点,就更容易理解了。 将输出传递回我们的函数不会改变它。

四个量Q、I、Ω、f分别表示
计算、输入、输出和
计算规则。

所以Q是一个包含所有可能的计算状态的集合,即输入、输出以及其间所有阶段的所有可能的变化。 集合I包含所有可能的输入。 集合Ω包含所有可能的输出(很抱歉,如果我之前破坏了你的启示)。 最后,f代表计算规则; 也就是说,应用于每个状态的过程以获得下一个状态,最终(希望如此)直到我们得到输出。


为了澄清,f 表示一个函数,该函数的输出是根据其可能的输入定义的。 在此特定示例中,它仅具有三种可能的输出,并且在其他算法中可能具有更多(或更少)。 那么,以这种方式定义算法的组成部分的目的是什么? 通过使用形式符号定义它们,在分析特定算法时也可以对它们进行分析和数学检查。

关于将算法视为一组字符串的问题

我回答了关于此主题的另一个问题。 但本质上,Knuth 在这里所做的是使用马尔可夫算法来实现他已经描述的内容。 值得研究(并研究一些示例)马尔可夫算法,以帮助您准确理解这里发生的情况。

参考文献

  1. 马尔可夫算法 Wiki
  2. 我的定义算法文章。
  3. Knuth 计算机编程艺术 ex 1.1.8

For full disclosure, I recently wrote an article on understanding Knuth's (pre-example) formal definition of an algorithm. A substantial portion of the below is just a copy/paste of the relevant text from the article answering your first question in depth;

Your first question on (Q, I, Ω, f)


Let us formally define a computational method to be a quadruple (Q, I,
Ω, f), in which Q is a set containing subsets I and Ω and f is a
function from Q into itself.

When Knuth refers to a computational method as a quadruple he is simply saying that a computational method is composed of four distinctly defined parts. He labels these four parts as (Q, I, Ω, f). He then moves on to briefly describe each component of this quadruple. I and are sets (collections of things), and Q is also a set which contains the things in the sets I and . At this point it’s easy to mistakenly assume that he means that Q contains only the sets I and and nothing else. But we later find that this is not the case. Lastly he describes f as a function from Q into itself. What this means is that f is a process which takes an input which is an element from the set Q and returns or outputs another element from Q.

Furthermore f should leave Ω pointwise fixed; that is, f(q) should
equal q for all elements q of Ω.

What this essentially means is that, what our function f returns, will be the same as its argument (i.e. the value will not change) if the argument is a member or element of (thing in) set . This makes more sense when Knuth makes a clarification in his next statement; Spoiler alert - is the set of possible outputs of our computational method. Once we know this it’s a little easier to understand. Passing an output back into our function will not change it.

The four quantities Q, I, Ω, f are intended to represent respectively
the states of the computation, the input, the output, and the
computational rule.

So Q is a set that contains all possible states of the computation i.e. all the possible variations of input, output and all the stages in between. The set I contains all possible inputs. The set contains all possible outputs (sorry if I spoiled that revelation for you earlier). And finally, f represents the computational rule; that is, the process/es applied to each state to get the next state, eventually (hopefully) until we get our output.


To clarify, f represents a single function that has outputs defined based on its possible inputs. It only has three possible outputs in this specific example, and could have more (or less) in other algorithms. So, whats the purpose of defining the components of an algorithm in this way? By having them defined using formal notation they can also be analysed and subjected to mathematical examination when it comes to analysing specific algorithms.

Question about Treating the algorithm as a set of Strings

I answered another question on this subject here. But essentially what Knuth is doing here is using a Markov's algorithm to achieve what he has already described. It is worth studying (and working through a few examples of) Markov algorithms to help you understand exactly what is occurring here.

References

  1. Markov's Algorithms Wiki
  2. My Defining an Algorithm article.
  3. Knuth the art of computer programming ex 1.1.8
骄傲 2024-07-21 02:00:47

我不是 100% 确定,但看起来 Q 是 0 <= J <= N 的所有有序对 (s, j) 的集合。这将是您的域。 它是给定一些 N 和字符串 s 的所有可能状态的集合。

I 是 Q 的子集,其中所有有序对都包含 J=0,或您的初始状态。
Omega 是 Q 的子集,其中所有有序对都包含 J=N,或您的最终状态。

f 是域 Q 上的实际函数。

编辑

将函数定义视为与一个函数类似的东西,但根据给定的输入而有不同的情况。 想象一下您将用某种语言编写的函数。 例如:

tuple f(string s, int i)
{
    if (Tj not in s)
        (s, aj)
    else if ( p is shortest possible length such that s = pYjw)
        (pYjw,bj)
    else if ( i == N )
        (s, N)
}

另一个例子是斐波那契函数定义。 看看它是如何定义的?
合理?

I'm not 100% sure, but it looks like Q is the set of all ordered pairs (s, j) for 0 <= J <= N. This will be your domain. It is the set of all possible states given some N and string s.

I is your subset of Q where all ordered pairs contain J=0, or your initial states.
Omega is your subset of Q where all ordered pairs contain J=N, or your final states.

f is the actual function over domain Q.

EDIT

Think of the function definition being something along the lines of one function, but different cases depending on the given input. Think of a function you would writing in a language. ex:

tuple f(string s, int i)
{
    if (Tj not in s)
        (s, aj)
    else if ( p is shortest possible length such that s = pYjw)
        (pYjw,bj)
    else if ( i == N )
        (s, N)
}

Another example is the Fibonacci function definition. See how that is defined?
Make sense?

不再见 2024-07-21 02:00:47

如果你已经完成了他在书前面提到的欧几里得的最大公约数算法。 这个想法是将每次迭代的开始标记为初始阶段,然后定义循环的一次迭代中将出现的状态数(即 N)。 现在您会记得,我们接受了答案,并在 m 除以 n 的余数等于零时停止计算。 即我们正在搜索字符串 Yj 的特定出现位置。 当计算到达循环的最后阶段时,它必然会停止或重复。

if u would have gone through the euclid's gcd algorithm that he stated earlier in the book. the idea is to mark the starting of each iteration as an initial stage and then define the number of states that will come in one iteration of loop (namely N). now as you will remember that we accepted the answer and halted the computation when the remainder of m divided by n equaled zero. i.e. we were searching for a particular occurrence of a string Yj. when the compuataion reaches itz final stage in the loop it is bound to halt or reiterate.

樱花落人离去 2024-07-21 02:00:47

请记住,我们正在定义“计算方法”而不是算法。 天真的计算方法是什么?

具有算法所有特征(除了可能缺乏有限性)的“过程”可以称为计算方法。

简单来说Q是一种计算方法。

Q = {all possible states of computations, I, Ω}
I = {all possible inputs}
Ω = {all possible outputs}
f = computational rule

f 是从 Q 到自身的函数。

f: Q  --->  Q
  [I]      [Ω]

f 应该让 Ω pointwise 固定,这意味着:

f(q) = q, ∀ q ∈ Ω
请注意,它不是任何不同的函数,而是相同的计算规则,只是分隔为 Ω

现在,一个过程将具有一个序列。 显然,计算方法也必须有一个序列。
因此,

集合I中的每个输入x定义一个计算序列x0, x1, x2, ...,如下:
x0 = x 且 xk+1 = f(xk),k ≥ 0。

x0 如何计算> = x?
不要忘记输入 x 是一个序列,因此初始输入序列将是 x0
当我们处理一个序列时,当我们关注“k”状态时,序列中元素的顺序和位置很重要。 因此,计算规则 f 使得第 kth 元素的位置或更精确的单词“state”将是 k+1th 状态。
这样,我们可以将该函数单独应用于每个新状态以获得后续状态。

如果 xk+1 不是 Ω,那么根据函数的定义它就没有意义。 这就是高德纳的措辞。

如果 k 是 xk 为 Ω 的最小整数,则计算序列将在 k 步中终止,在这种情况下,据说会产生输出 xk 来自 x。

因此,这是计算方法的定义。 计算规则就是算法。

remember we are defining a 'computational method' and not an algorithm. what is a computational method naively?

a "procedure" that has all characteristics of an algorithm except that it possibly lacks finiteness, may be called a computational method.

simply put Q is a computational method.

Q = {all possible states of computations, I, Ω}
I = {all possible inputs}
Ω = {all possible outputs}
f = computational rule

f is a function from Q into itself.

f: Q  --->  Q
  [I]      [Ω]

f should leave Ω pointwise fixed which means:

f(q) = q, ∀ q ∈ Ω
note it is not any different function but the same computationalrule just seperated to Ω

Now a procedure will have a sequence. And obviously, a computational method must also have a sequence.
Hence,

Each input x in the set I defines a computational sequence x0, x1, x2, ..., as follows:
x0 = x and xk+1 = f(xk) for k ≥ 0.

How x0 = x?
Don't forget the input x is a sequence and so the initial input sequence would be x0.
As we are dealing with a sequence, and when we are concerning about 'k' states, the order and the position of elements in the sequence matters. And so, the computational rule f is such that the position or more precise word 'state' of the kth element would be k+1th state.
that way, we can seperately apply the function to each new state to get the state that follows.

if xk+1 is not in Ω, then it makes no sense by definition of a function. Hence the wording of Knuth.

The computational sequence is said to terminate in k steps if k is the smallest integer for which xk is in Ω and in this case, it is said to produce the output xk from x.

Thus this is the definition of a computational method. the computational rule is the algorithm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文