Skip to content

Commit 9308547

Browse files
authored
Merge pull request #804 from gz101/master
fix: Misc improvements in Chapter 4,5,6,7
2 parents ab867a3 + 9e0aa49 commit 9308547

4 files changed

+14
-16
lines changed

lec_04_code_and_data.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,11 @@ Similarly, every circuit $C$ of at most $s$ gates can be represented by a string
337337
Since we can represent programs as strings, we can also think of a program as an input to a function.
338338
In particular, for every natural number $s,n,m>0$ we define the function $EVAL_{s,n,m}:\{0,1\}^{S(s)+n} \rightarrow \{0,1\}^m$ as follows:
339339
$$
340-
EVAL_{s,n,m}(px) = \begin{cases} P(x) & \text{$p\in \{0,1\}^{S(s)}$ represents a size-$s$ program $P$ with $n$ inputs and $m$ outputs} \\ 0^m & \text{otherwise} \end{cases} \label{evalcirceq}
340+
EVAL_{s,n,m}(px) = \begin{cases} P(x) & \text{$p\in \{0,1\}^{|S(s)|}$ represents a size-$s$ program $P$ with $n$ inputs and $m$ outputs} \\ 0^m & \text{otherwise} \end{cases} \label{evalcirceq}
341341
$$
342342
where $S(s)$ is defined as in [lengthstringrepreseq](){.eqref} and we use the concrete representation scheme described in [representprogramsec](){.ref}.
343343

344-
That is, $EVAL_{s,n,m}$ takes as input the concatenation of two strings: a string $p\in \{0,1\}^{S(s)}$ and a string $x\in \{0,1\}^n$.
344+
That is, $EVAL_{s,n,m}$ takes as input the concatenation of two strings: a string $p\in \{0,1\}^{|S(s)|}$ and a string $x\in \{0,1\}^n$.
345345
If $p$ is a string that represents a list of triples $L$ such that $(n,m,L)$ is a list-of-tuples representation of a size-$s$ NAND-CIRC program $P$, then $EVAL_{s,n,m}(px)$ is equal to the evaluation $P(x)$ of the program $P$ on the input $x$.
346346
Otherwise, $EVAL_{s,n,m}(px)$ equals $0^m$ (this case is not very important: you can simply think of $0^m$ as some "junk value" that indicates an error).
347347

lec_05_infinite.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,10 @@ Similarly, for every formal language $L \subseteq \Sigma^*$, we say that $L$ is
525525
::: {.example title="A regular function" #regularexpmatching}
526526
Let $\Sigma=\{ a,b,c,d,0,1,2,3,4,5,6,7,8,9 \}$ and $F:\Sigma^* \rightarrow \{0,1\}$ be the function such that $F(x)$ outputs $1$ iff $x$ consists of one or more of the letters $a$-$d$ followed by a sequence of one or more digits (without a leading zero).
527527
Then $F$ is a regular function, since $F=\Phi_e$ where
528-
$$e = (a|b|c|d)(a|b|c|d)^*(0|1|2|3|4|5|6|7|8|9)(0|1|2|3|4|5|6|7|8|9)^*$$
528+
$$e = (a|b|c|d)(a|b|c|d)^*(1|2|3|4|5|6|7|8|9)(0|1|2|3|4|5|6|7|8|9)^*$$
529529
is the expression we saw in [regexpeq](){.eqref}.
530530

531-
If we wanted to verify, for example, that $\Phi_e(abc12078)=1$, we can do so by noticing that the expression $(a|b|c|d)$ matches the string $a$, $(a|b|c|d)^*$ matches $bc$, $(0|1|2|3|4|5|6|7|8|9)$ matches the string $1$, and the expression $(0|1|2|3|4|5|6|7|8|9)^*$ matches the string $2078$. Each one of those boils down to a simpler expression. For example, the expression $(a|b|c|d)^*$ matches the string $bc$ because both of the one-character strings $b$ and $c$ are matched by the expression $a|b|c|d$.
531+
If we wanted to verify, for example, that $\Phi_e(abc12078)=1$, we can do so by noticing that the expression $(a|b|c|d)$ matches the string $a$, $(a|b|c|d)^*$ matches $bc$, $(1|2|3|4|5|6|7|8|9)$ matches the string $1$, and the expression $(0|1|2|3|4|5|6|7|8|9)^*$ matches the string $2078$. Each one of those boils down to a simpler expression. For example, the expression $(a|b|c|d)^*$ matches the string $bc$ because both of the one-character strings $b$ and $c$ are matched by the expression $a|b|c|d$.
532532
:::
533533

534534
Regular expression can be defined over any finite alphabet $\Sigma$, but as usual, we will mostly focus our attention on the _binary case_, where $\Sigma = \{0,1\}$.
@@ -684,7 +684,7 @@ INPUT: Regular expression $e$ over $\Sigma^*$, $x\in \Sigma^n$ where $n\in\N$
684684
OUTPUT: $\Phi_e(x)$
685685
686686
procedure{FMatch}{$e$,$x$}
687-
lIf {$x=""$} return $\CALL{MatchEmpty}(e)$ lendif
687+
lIf {$x=""$} return $\CALL{MatchEmpty}{e}$ lendif
688688
Let $e' \leftarrow \CALL{Restrict}{e,x_{n-1}}$
689689
return $FMatch(e',x_0 \cdots x_{n-2})$
690690
endprocedure

lec_06_loops.md

+8-10
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Let $PAL$ (for _palindromes_) be the function that on input $x\in \{0,1\}^*$, ou
115115

116116
We now show a Turing machine $M$ that computes $PAL$. To specify $M$ we need to specify __(i)__ $M$'s tape alphabet $\Sigma$ which should contain at least the symbols $0$,$1$, $\triangleright$ and $\varnothing$, and __(ii)__ $M$'s _transition function_ which determines what action $M$ takes when it reads a given symbol while it is in a particular state.
117117

118-
In our case, $M$ will use the alphabet $\{ 0,1,\triangleright, \varnothing, \times \}$ and will have $k=13$ states. Though the states are simply numbers between $0$ and $k-1$, we will give them the following labels for convenience:
118+
In our case, $M$ will use the alphabet $\{ 0,1,\triangleright, \varnothing, \times \}$ and will have $k=11$ states. Though the states are simply numbers between $0$ and $k-1$, we will give them the following labels for convenience:
119119

120120
```table
121121
---
@@ -131,13 +131,11 @@ State, Label
131131
3,`LOOK_FOR_0`
132132
4,`LOOK_FOR_1`
133133
5,`RETURN`
134-
6,`REJECT`
135-
7,`ACCEPT`
136-
8,`OUTPUT_0`
137-
9,`OUTPUT_1`
138-
10,`0_AND_BLANK`
139-
11,`1_AND_BLANK`
140-
12,`BLANK_AND_STOP`
134+
6,`OUTPUT_0`
135+
7,`OUTPUT_1`
136+
8,`0_AND_BLANK`
137+
9,`1_AND_BLANK`
138+
10,`BLANK_AND_STOP`
141139
```
142140

143141

@@ -156,7 +154,7 @@ We describe the operation of our Turing machine $M$ in words:
156154

157155
* The `OUTPUT_`$b$ states mean that $M$ will eventually output the value $b$. In both the `OUTPUT_0` and `OUTPUT_1` states, $M$ goes left until it hits $\triangleright$. Once it does so, it makes a right step, and changes to the `1_AND_BLANK` or `0_AND_BLANK` states respectively. In the latter states, $M$ writes the corresponding value, moves right and changes to the `BLANK_AND_STOP` state, in which it writes $\varnothing$ to the tape and halts.
158156

159-
The above description can be turned into a table describing for each one of the $13\cdot 5$ combination of state and symbol, what the Turing machine will do when it is in that state and it reads that symbol. This table is known as the _transition function_ of the Turing machine.
157+
The above description can be turned into a table describing for each one of the $11\cdot 5$ combination of state and symbol, what the Turing machine will do when it is in that state and it reads that symbol. This table is known as the _transition function_ of the Turing machine.
160158

161159

162160
### Turing machines: a formal definition
@@ -181,7 +179,7 @@ For every $x\in \{0,1\}^*$, the _output_ of $M$ on input $x$, denoted by $M(x)$,
181179
* We then repeat the following process:
182180

183181
1. Let $(s',\sigma',D) = \delta_M(s,T[i])$.
184-
2. Set $s \rightarrow s'$, $T[i] \rightarrow \sigma'$.
182+
2. Set $s \leftarrow s'$, $T[i] \leftarrow \sigma'$.
185183
3. If $D=\mathsf{R}$ then set $i \rightarrow i+1$, if $D=\mathsf{L}$ then set $i \rightarrow \max\{i-1,0\}$. (If $D = \mathsf{S}$ then we keep $i$ the same.)
186184
4. If $D=\mathsf{H}$, then halt.
187185

lec_07_other_models.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ It's λ's all the way down!
10031003

10041004
::: { .pause }
10051005
This is a good point to pause and think how you would implement these operations yourself. For example, start by thinking how you could implement $MAP$ using $REDUCE$, and then $REDUCE$ using $RECURSE$ combined with $0,1,IF,PAIR,HEAD,TAIL,NIL,ISEMPTY$.
1006-
You can also $PAIR$, $HEAD$ and $TAIL$ based on $0,1,IF$.
1006+
You can also implement $PAIR$, $HEAD$ and $TAIL$ based on $0,1,IF$.
10071007
The most challenging part is to implement $RECURSE$ using only the operations of the pure λ calculus.
10081008
:::
10091009

0 commit comments

Comments
 (0)