Saya mencoba untuk menyerang TAOCP sekali lagi, mengingat beratnya volume sebenarnya saya mengalami kesulitan untuk melakukannya dengan serius. Dalam TAOCP 1 Knuth menulis, halaman 8, konsep-konsep dasar ::
Membiarkan menjadi set huruf yang terbatas. Membiarkan menjadi himpunan semua string di (himpunan semua urutan terurut ... mana dan berada di untuk ). Idenya adalah untuk menyandikan keadaan perhitungan sehingga mereka diwakili oleh string . Sekarang mari menjadi bilangan bulat non-negatif dan Q (negara) menjadi himpunan semua , di mana berada di dan j adalah bilangan bulat ; biarkan (input) menjadi bagian dari Q dengan dan membiarkan (output) menjadi bagian dengan . Jika dan adalah string dalam , kita mengatakan bahwa muncul dalam jika memiliki bentuk untuk string dan . Untuk melengkapi definisi kita, misalkan adalah fungsi dari tipe berikut, yang didefinisikan oleh string , dan integer , untuk :
- jika tidak muncul di
- jika adalah string terpendek yang memungkinkan
Bukan sebagai ilmuwan komputer, saya kesulitan memahami seluruh bagian. Saya agak mendapatkan ide yang ada di balik sistem opcode, tapi saya belum berkembang secara efektif dalam pemahaman. Saya pikir masalah utamanya adalah tat, saya tidak tahu cara membacanya secara efektif.
Apakah mungkin untuk menjelaskan perikop di atas sehingga saya dapat memahaminya, dan memberi saya strategi untuk masuk ke logika dalam menafsirkan pernyataan ini?
sumber
Jawaban:
Kami kehilangan beberapa konteks jadi saya tidak tahu apa maksud Knuth, tapi inilah cara menafsirkan mesin Turing dengan cara ini. Mungkin itu akan membantu Anda memahami apa yang sedang terjadi. Secara umum, cara yang baik untuk memahami konsep adalah dengan memainkannya. Dalam hal paradigma pemrograman, itu berarti menulis sebuah program. Dalam hal ini, saya akan menunjukkan cara menulis program apa pun .
Misalkan rekaman mesin Turing memiliki simbol{0,1,ϵ} (dimana ϵ stands for "empty"), and add one more symbol which represents the location of the head H . Your states are going to be pairs of the form (q,α) , where q is a state of the Turing machine, and α∈{0,…,14} . We also identify (F,0) with N for any final state.
On (non-empty) inputx , your starting point will be (Hx,(s,0)) , where s is the starting state. The difficult part is to encode states. Suppose that at state q , upon reading input x , you replace it with a(q,x) , move in direction D(q,x)∈{L,R} , and switch to state σ(q,x) . For the θ s, we have
Now applyf repeatedly until you get stuck. If you follow the construction, you will see that we have simulated the running of the Turing machine.
sumber
Let us break it down bit by bit. First of all, remember what Knuth wrote on page 7:
This is the outline. You have to read "represent" as "contain";Q is going to contain states (some of which are in I , some are in Ω ) and f is going to be a transition function between states; think of it as a program.
This is just a reiteration of whatA∗ is. See also here.
This is probably the key sentence. We are talking about computations, that is execution sequences of some (programming language) statements which manipulate some state, which can be thought of as values in memory cells, or valuations of variables. Knuth says here that he wants to encode these states in an abstract way, namely as word over some alphabet.
Example: Consider a program that uses (at most)k variables, each of which stores an integer. That is, a state is given by the tuple of values (x1,…,xk) where xk is the (current) value of the k -th variable. In order to encode states of this form in a formal language, we can choose A={0,1,#} with # a separator. Now model such a state by #x1¯¯¯¯¯#⋯#xk¯¯¯¯¯# where xi¯¯¯¯¯ is the binary encoding of xi .
Specifically,(3,5,0) would be #11#101#0# .
You misquoted there (bad Stefano!); the parentheses are not in the original text, and they were misleading (see above). Knuth definesQ here as the set of all possible states (σ∈A∗ ) at all possible places in the computation (j can be understood as program counter). Therefore, Q contains all statement-indexed states any computation of the algorithm given by f can assume. By definition, we start with program counter 0 and end in N , thus states indexed 0 are input states and those indexed N are output states.
I hope that this is clear; it is just a (re)definition of substrings.
This is a a small programming language; if you fixθj,ψj,aj,bj , you have a program. On program counter j , f replaces the left-most occurrence θj in the state with ψj and goes to statement bj . If there is no θj in the current state, it goes to statement aj . The program loops if statement N is reached, modelling termination.
On the upper half of page 8, there is a more concrete example of a "program"f . Keep in mind that Knuth is going to use assembly language later on; this informs how he looks at programs (atomic statements connected by jumps).
sumber
That text describes the following (Python) pseudocode:
The function f is presumably going to be applied repeatedly.
The last three bullet points is all you really need once you understand the notations. All that comes before is a bit analogous to explaining how Python works before giving the Python code.
sumber