Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: boazbk/tcs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.95
Choose a base ref
...
head repository: boazbk/tcs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Jul 24, 2023

  1. wip

    boazbk committed Jul 24, 2023
    Copy the full SHA
    5160197 View commit details

Commits on Aug 7, 2023

  1. Copy the full SHA
    c09ccc7 View commit details
  2. added missing comma

    Adirlou committed Aug 7, 2023
    Copy the full SHA
    2b514a4 View commit details
  3. Add name to acknowledgements

    Adirlou committed Aug 7, 2023
    Copy the full SHA
    1d32f4d View commit details
  4. Fixed typos in Chapter 18

    Adirlou committed Aug 7, 2023
    Copy the full SHA
    eb7bbec View commit details
  5. correctly place dot

    Adirlou committed Aug 7, 2023
    Copy the full SHA
    9868811 View commit details

Commits on Aug 8, 2023

  1. Copy the full SHA
    d767992 View commit details

Commits on Sep 2, 2023

  1. Merge pull request #793 from Adirlou/probability_typos

    Fixed typos in Chapter 18: Probability Theory 101
    boazbk authored Sep 2, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7c1f400 View commit details
  2. Merge pull request #792 from Adirlou/probability_exercises_typos

    Fixed typos in exercises of Chapter 18: Probability Theory 101
    boazbk authored Sep 2, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    cbb74af View commit details

Commits on Sep 5, 2023

  1. Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d0f11fa View commit details

Commits on Sep 6, 2023

  1. fix typo chapter 3

    gz101 authored Sep 6, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a1e3199 View commit details

Commits on Sep 7, 2023

  1. Update lec_02_representation.md

    Fix sum condition on two's complement
    jeqcho authored Sep 7, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    441f25b View commit details
  2. Update acknowledgements.md

    jeqcho authored Sep 7, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9ba630e View commit details

Commits on Sep 8, 2023

  1. Minor typo in equation

    gz101 authored Sep 8, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c3b3555 View commit details
  2. clarification

    gz101 authored Sep 8, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    07a899f View commit details

Commits on Sep 12, 2023

  1. Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    be558ba View commit details

Commits on Sep 14, 2023

  1. Merge pull request #794 from gz101/patch-1

    fix wording in rational representation
    boazbk authored Sep 14, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1a7e75b View commit details
  2. Merge pull request #796 from gz101/patch-2

    chapter 3 miscellaneous
    boazbk authored Sep 14, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0517ba9 View commit details
  3. Merge pull request #797 from jeqcho/master

    Fixing condition to prevent two's complement overflow when summing
    boazbk authored Sep 14, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5845602 View commit details
  4. Merge pull request #798 from gz101/patch-3

    Minor typo in equation
    boazbk authored Sep 14, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    928a006 View commit details
  5. Merge pull request #800 from alexbernat/patch-1

    lec_03a_computing_every_function.md: Fix typo in lookup theorem (Z -> X)
    boazbk authored Sep 14, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    06c83bc View commit details

Commits on Sep 16, 2023

  1. Copy the full SHA
    14257be View commit details

Commits on Sep 17, 2023

  1. Merge pull request #802 from tanishqkumar/fix-equals-typo-code-and-data

    Typo fix: swap EQUAL and \neg EQUAL in size hierarchy proof
    boazbk authored Sep 17, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    951e0c7 View commit details

Commits on Sep 18, 2023

  1. Update index.md

    boazbk authored Sep 18, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d4cad9e View commit details
  2. Fix typo on tuple encoding

    Changed x,y \in S to (x,y) \in S. In the the former some readers might think that x and y are members of S, but actually the tuple (x,y) is the member of S.
    jeqcho authored Sep 18, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    93b218f View commit details

Commits on Sep 19, 2023

  1. Change (V,b,i) to (V,i,b) for consistency

    Made the change to be consistent with how the domain is defined and how the Python code below was implemented
    jeqcho authored Sep 19, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    027d91b View commit details
  2. fix typos

    gz101 authored Sep 19, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f524231 View commit details
  3. Small typo on p.3

    MarioFares committed Sep 19, 2023
    Copy the full SHA
    a226d89 View commit details
  4. Copy the full SHA
    696ffc2 View commit details

Commits on Sep 20, 2023

  1. Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    cbd1288 View commit details
  2. fix arrow direction

    gz101 authored Sep 20, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0361740 View commit details

Commits on Sep 23, 2023

  1. Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    262eded View commit details
  2. Edit the Turing instructions for palindrome

    So that the choice to enter RIGHT_0 or RIGHT_1 is unambiguous by replacing them with RIGHT_b
    jeqcho authored Sep 23, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6a8554f View commit details
  3. Added $M$ to Turing Machine

    $M$ was never defined in the definition box
    jeqcho authored Sep 23, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    750fe74 View commit details

Commits on Sep 26, 2023

  1. Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c095df6 View commit details
  2. add missing word

    gz101 authored Sep 26, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d18e187 View commit details
  3. missing cardinality

    gz101 authored Sep 26, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    bb87937 View commit details
  4. correct number of states

    gz101 authored Sep 26, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9e0aa49 View commit details
  5. Copy the full SHA
    3f83230 View commit details
  6. Copy the full SHA
    75ce155 View commit details

Commits on Sep 27, 2023

  1. Merge pull request #803 from jeqcho/master

    Fix typo on tuple encoding
    boazbk authored Sep 27, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ab867a3 View commit details
  2. Merge pull request #804 from gz101/master

    fix: Misc improvements in Chapter 4,5,6,7
    boazbk authored Sep 27, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9308547 View commit details
  3. Merge pull request #805 from MarioFares/typos

    Small typo on p.3
    boazbk authored Sep 27, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c78a5fd View commit details
  4. Merge pull request #806 from walnutwaldo/master

    Typo in Lecture 5, restricting regular expressions
    boazbk authored Sep 27, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0c852f3 View commit details
  5. Merge pull request #807 from excepshenal/patch-1

    2 small typos in p 238 in lec_05_infinite
    boazbk authored Sep 27, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    fe683e9 View commit details
  6. Merge pull request #808 from MarioFares/lec7

    Lecture 7: Small typo in overview and p.15
    boazbk authored Sep 27, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d4f5025 View commit details
  7. Copy the full SHA
    dbcb9f8 View commit details

Commits on Sep 28, 2023

  1. Fix lovelace quote italics

    boazbk authored Sep 28, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9f73bc2 View commit details
  2. Italics in quotes

    boazbk authored Sep 28, 2023

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    034748d View commit details
  3. Copy the full SHA
    7fce4df View commit details
2 changes: 2 additions & 0 deletions acknowledgements.md
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ If you make a pull request, please also add your name here in the alphabetical o
* Michelle Chiang
* Gabriel Chiong
* Daniel Chiu
* Je-Qin Chooi
* Chi-Ning Chou
* Michael Colavita
* Brenna Courtney
@@ -107,6 +108,7 @@ If you make a pull request, please also add your name here in the alphabetical o
* Eric Thomas
* Sarah Turnill
* Salil Vadhan
* Adrien Vandenbroucque
* Jeffrey Wang
* Patrick Watts
* Jonah Weissman
10 changes: 2 additions & 8 deletions index.md
Original file line number Diff line number Diff line change
@@ -18,12 +18,7 @@ I am using this text for [Harvard CS 121](http://cs121.boazbarak.org).
It is also used for [UVa CS 3102](https://uvatoc.github.io) and [UCLA CS181](https://hackmd.io/@raghum/introtcs).


See below for individual chapters. You can also download:

* [Book in a single PDF file](https://files.boazbarak.org/introtcs/lnotes_book.pdf) (about 600 pages, 10MB).

* [Table of contents](https://files.boazbarak.org/introtcs/contents.pdf).

See below for individual chapters. You can also download the [book in a single PDF file](https://files.boazbarak.org/introtcs/lnotes_book.pdf) (about 600 pages, 10MB).

If you have any _comments, suggestions, typo fixes_, etc.. I would be very grateful if you post them as an [**issue**](https://github.com/boazbk/tcs/issues) or [**pull request**](https://github.com/boazbk/tcs/pulls) in the [**GitHub repository boazbk/tcs**](https://github.com/boazbk/tcs) where I am maintaining the source files for these notes.
You can also post comments on each chapter in the links below.
@@ -35,6 +30,5 @@ See the [github.com/boazbk/tcscode](the tcscode repository) for jupyter notebook
For prior versions of the book, see the [repository release page](https://github.com/boazbk/tcs/releases). The most updated version of this book is always on this page.


__Frozen version for Fall 2022:__ I will be only making minor edits (typos, local fixes) during the fall so as not to disrupt teaching. For consistency in references and exercises, instructors can use
the following version frozen as of August 21 2022: [Introduction to TCS version 0.94 - August 21, 2022](https://github.com/boazbk/tcs/releases/download/v0.94/introtcs_august21_2022.pdf)
__Frozen version for Fall 20223:__ I will be only making minor edits (typos, local fixes) during the fall so as not to disrupt teaching. For consistency in references and exercises, instructors can use the following version frozen as of July 24, 2023: [Introduction to TCS version 0.95](https://github.com/boazbk/tcs/releases/download/v0.95/lnotes_book_fall2023.pdf)

10 changes: 5 additions & 5 deletions lec_02_representation.md
Original file line number Diff line number Diff line change
@@ -254,7 +254,7 @@ Hence the two's complement representation of such a number $k$ is a string of le


Another way to say this is that we represent a potentially negative number $k \in \{ -2^n,\ldots, 2^n-1 \}$ as the non-negative number $k \mod 2^{n+1}$ (see also [twoscomplementfig](){.ref}).
This means that if two (potentially negative) numbers $k$ and $k'$ are not too large (i.e., $|k|+|k'|<2^{n+1}$), then we can compute the representation of $k+k'$ by adding modulo $2^{n+1}$ the representations of $k$ and $k'$ as if they were non-negative integers.
This means that if two (potentially negative) numbers $k$ and $k'$ are not too large (i.e., $ k + k' \in \{ -2^n,\ldots, 2^n-1 \}$), then we can compute the representation of $k+k'$ by adding modulo $2^{n+1}$ the representations of $k$ and $k'$ as if they were non-negative integers.
This property of the two's complement representation is its main attraction since, depending on their architectures, microprocessors can often perform arithmetic operations modulo $2^w$ very efficiently (for certain values of $w$ such as $32$ and $64$).
Many systems leave it to the programmer to check that values are not too large and will carry out this modular arithmetic regardless of the size of the numbers involved.
For this reason, in some systems adding two large positive numbers can result in a _negative_ number (e.g., adding $2^n-100$ and $2^n-200$ might result in $-300$ since $(2^{n+1}-300) \mod 2^{n+1} = -300$, see also [twoscomplementfig](){.ref}).
@@ -281,9 +281,9 @@ We can map the three-element set $\Sigma$ to the three-element set $\{00,11,01 \
Our final representation for rational numbers is obtained by composing the following steps:


1. Representing a non-negative rational number as a pair of natural numbers.
1. Representing a (potentially negative) rational number as a pair of integers $a,b$ such that $r=a/b$.

2. Representing a natural number by a string via the binary representation.
2. Representing an integer by a string via the binary representation.

3. Combining 1 and 2 to obtain a representation of a rational number as a pair of strings.

@@ -429,7 +429,7 @@ We start by proving [sequencestostrings](){.ref} which is really the heart of [



![We construct a function $\overline{d}$ such that $\overline{d} \neq StF(x)$ for every $x\in \{0,1\}^*$ by ensuring that $\overline{d}(n(x)) \neq StF(x)(n(x))$ for every $x\in \{0,1\}^*$ with lexicographic order $n(x)$. We can think of this as building a table where the columns correspond to numbers $m\in \N$ and the rows correspond to $x\in \{0,1\}^*$ (sorted according to $n(x)$). If the entry in the $x$-th row and the $m$-th column corresponds to $g(m))$ where $g=StF(x)$ then $\overline{d}$ is obtained by going over the "diagonal" elements in this table (the entries corresponding to the $x$-th row and $n(x)$-th column) and ensuring that $\overline{d}(x)(n(x)) \neq StF(x)(x)$. ](../figure/diagonalization.png){#diagrealsfig }
![We construct a function $\overline{d}$ such that $\overline{d} \neq StF(x)$ for every $x\in \{0,1\}^*$ by ensuring that $\overline{d}(n(x)) \neq StF(x)(n(x))$ for every $x\in \{0,1\}^*$ with lexicographic order $n(x)$. We can think of this as building a table where the columns correspond to numbers $m\in \N$ and the rows correspond to $x\in \{0,1\}^*$ (sorted according to $n(x)$). If the entry in the $x$-th row and the $m$-th column corresponds to $g(m))$ where $g=StF(x)$ then $\overline{d}$ is obtained by going over the "diagonal" elements in this table (the entries corresponding to the $x$-th row and $n(x)$-th column) and ensuring that $\overline{d}(n(x)) \neq StF(x)(n(x))$. ](../figure/diagonalization.png){#diagrealsfig }


__Warm-up: "Baby Cantor".__ The proof of [sequencestostrings](){.ref} is rather subtle. One way to get intuition for it is to consider the following finite statement "there is no onto function $f:\{0,\ldots,99\} \rightarrow \{0,1\}^{100}$". Of course we know it's true since the set $\{0,1\}^{100}$ is bigger than the set $[100]$, but let's see a direct proof. For every $f:\{0,\ldots,99\} \rightarrow \{0,1\}^{100}$, we can define the string $\overline{d} \in \{0,1\}^{100}$ as follows: $\overline{d} = (1-f(0)_0, 1-f(1)_1 , \ldots, 1-f(99)_{99})$. If $f$ was onto, then there would exist some $n\in [100]$ such that $f(n) =\overline{d}$, but we claim that no such $n$ exists. Indeed, if there was such $n$, then the $n$-th coordinate of $\overline{d}$ would equal $f(n)_n$ but by definition this coordinate equals $1-f(n)_n$. See also a ["proof by code"](https://trinket.io/python/4cff7e58f4) of this statement.
@@ -682,7 +682,7 @@ The following theorem shows that if $E$ is a prefix-free encoding of $\mathcal{O

::: {.theorem title="Prefix-free implies tuple encoding" #prefixfreethm}
Suppose that $E:\mathcal{O} \rightarrow \{0,1\}^*$ is prefix-free.
Then the following map $\overline{E}:\mathcal{O}^* \rightarrow \{0,1\}^*$ is one to one, for every $o_0,\ldots,o_{k-1} \in \mathcal{O}^*$, we define
Then the following map $\overline{E}:\mathcal{O}^* \rightarrow \{0,1\}^*$ is one to one, for every $(o_0,\ldots,o_{k-1}) \in \mathcal{O}^*$, we define
$$
\overline{E}(o_0,\ldots,o_{k-1}) = E(o_0)E(o_1) \cdots E(o_{k-1}) \;.
$$
4 changes: 2 additions & 2 deletions lec_03_computation.md
Original file line number Diff line number Diff line change
@@ -339,7 +339,7 @@ This suggests that we can use $AND$, $OR$, and $NOT$ as our "basic operations",


::: {.quote}
__Semi-formal definition of an algorithm:__ An _algorithm_ consists of a sequence of steps of the form "compute a new value by applying $AND$, $OR$, or $NOT$ to previously computed values".
__Semi-formal definition of an algorithm:__ An _algorithm_ consists of a sequence of steps of the form "compute a new value by applying $AND$, $OR$, or $NOT$ to previously computed values (assuming that the input was also previously computed)".

An algorithm $A$ _computes_ a function $F$ if for every input $x$ to $F$, if we feed $x$ as input to the algorithm, the value computed in its last step is $F(x)$.
:::
@@ -712,7 +712,7 @@ Since then, (adjusted versions of) this so-called "Moore's law" have been runnin
### Logical gates from transistors

We can use transistors to implement various Boolean functions such as $AND$, $OR$, and $NOT$.
For each a two-input gate $G:\{0,1\}^2 \rightarrow \{0,1\}$, such an implementation would be a system with two input wires $x,y$ and one output wire $z$, such that if we identify high voltage with "$1$" and low voltage with "$0$", then the wire $z$ will be equal to "$1$" if and only if applying $G$ to the values of the wires $x$ and $y$ is $1$ (see [logicgatestransistorsfig](){.ref} and [transistor-nand-fig](){.ref}).
For each two-input gate $G:\{0,1\}^2 \rightarrow \{0,1\}$, such an implementation would be a system with two input wires $x,y$ and one output wire $z$, such that if we identify high voltage with "$1$" and low voltage with "$0$", then the wire $z$ will be equal to "$1$" if and only if applying $G$ to the values of the wires $x$ and $y$ is $1$ (see [logicgatestransistorsfig](){.ref} and [transistor-nand-fig](){.ref}).
This means that if there exists a AND/OR/NOT circuit to compute a function $g:\{0,1\}^n \rightarrow \{0,1\}^m$, then we can compute $g$ in the physical world using transistors as well.

![Implementing logical gates using transistors. Figure taken from [Rory Mangles' website](http://www.northdownfarm.co.uk/rory/tim/basiclogic.htm).](../figure/dtl_logic.png){#logicgatestransistorsfig .margin }
2 changes: 1 addition & 1 deletion lec_03a_computing_every_function.md
Original file line number Diff line number Diff line change
@@ -448,7 +448,7 @@ For $k>1$, we use the following pseudocode:

```python
a = LOOKUP_(k-1)(X[0],...,X[2^(k-1)-1],i[1],...,i[k-1])
b = LOOKUP_(k-1)(X[2^(k-1)],...,Z[2^(k-1)],i[1],...,i[k-1])
b = LOOKUP_(k-1)(X[2^(k-1)],...,X[2^(k-1)],i[1],...,i[k-1])
return IF(i[0],b,a)
```

8 changes: 4 additions & 4 deletions lec_04_code_and_data.md
Original file line number Diff line number Diff line change
@@ -229,7 +229,7 @@ f_i(x) = \begin{cases} b & x=x^* \\ f_{i-1}(x) & x \neq x^*
$$
or in other words
$$
f_i(x) = f_{i-1}(x) \wedge EQUAL(x^*,x) \; \vee \; b \wedge \neg EQUAL(x^*,x)
f_i(x) = IF(EQUAL(x^*,x),b,f_{i-1}(x))
$$
where $EQUAL:\{0,1\}^{2n} \rightarrow \{0,1\}$ is the function that maps $x,x' \in \{0,1\}^n$ to $1$ if they are equal and to $0$ otherwise.
Since (by our choice of $i$), $f_{i-1}$ can be computed using at most $s$ gates and (as can be easily verified) that $EQUAL \in SIZE_n(9n)$,
@@ -337,11 +337,11 @@ Similarly, every circuit $C$ of at most $s$ gates can be represented by a string
Since we can represent programs as strings, we can also think of a program as an input to a function.
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:
$$
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}
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}
$$
where $S(s)$ is defined as in [lengthstringrepreseq](){.eqref} and we use the concrete representation scheme described in [representprogramsec](){.ref}.

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$.
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$.
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$.
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).

@@ -539,7 +539,7 @@ Please make sure that you understand why `GET` and $LOOKUP_\ell$ are the same fu
We saw that we can compute $LOOKUP_\ell$ in time $O(2^\ell) = O(s)$ for our choice of $\ell$.

For every $\ell$, let $UPDATE_\ell:\{0,1\}^{2^\ell + \ell +1} \rightarrow \{0,1\}^{2^\ell}$ correspond to the `UPDATE` function for arrays of length $2^\ell$.
That is, on input $V\in \{0,1\}^{2^\ell}$ , $i\in \{0,1\}^\ell$, $b\in \{0,1\}$, $UPDATE_\ell(V,b,i)$ is equal to $V' \in \{0,1\}^{2^\ell}$ such that
That is, on input $V\in \{0,1\}^{2^\ell}$ , $i\in \{0,1\}^\ell$, $b\in \{0,1\}$, $UPDATE_\ell(V,i,b)$ is equal to $V' \in \{0,1\}^{2^\ell}$ such that
$$
V'_j = \begin{cases} V_j & j \neq i \\ b & j = i \end{cases}
$$
14 changes: 7 additions & 7 deletions lec_05_infinite.md
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ While we can describe $XOR$ using a finite number of symbols (in fact, we just d
The same is true for many other functions capturing important computational tasks, including addition, multiplication, sorting, finding paths in graphs, fitting curves to points, and so on.
To contrast with the finite case, we will sometimes call a function $F:\{0,1\}^* \rightarrow \{0,1\}$ (or $F:\{0,1\}^* \rightarrow \{0,1\}^*$) _infinite_.
However, this does not mean that $F$ takes as input strings of infinite length!
It just means that $F$ can take as input a string of that can be arbitrarily long, and so we cannot simply write down a table of all the outputs of $F$ on different inputs.
It just means that $F$ can take as input a string that can be arbitrarily long, and so we cannot simply write down a table of all the outputs of $F$ on different inputs.

::: { .bigidea #comptask}
A function $F:\{0,1\}^* \rightarrow \{0,1\}^*$ specifies the computational task mapping an input $x\in \{0,1\}^*$ into the output $F(x)$.
@@ -525,10 +525,10 @@ Similarly, for every formal language $L \subseteq \Sigma^*$, we say that $L$ is
::: {.example title="A regular function" #regularexpmatching}
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).
Then $F$ is a regular function, since $F=\Phi_e$ where
$$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)^*$$
$$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)^*$$
is the expression we saw in [regexpeq](){.eqref}.

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$.
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$.
:::

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\}$.
@@ -671,7 +671,7 @@ lIf {$e=\tau$ -for $\tau \in \Sigma$} return $""$ -if $\tau=\sigma$ and return $
lIf {$e=(e'|e'')$} return $(Restrict(e',\sigma) | Restrict(e'',\sigma))$ lendif
lIf {$e=(e')^*$} return $(e')^* (Restrict(e',\sigma))$ lendif
lIf {$e= (e')(e'')$ and $\Phi_{e''}("")=0$} return $(e')(Restrict(e'',\sigma))$ lendif
lIf {$e= (e')(e'')$ and $\Phi_{e''}("")=1$} return $(e')(Restrict(e'',\sigma) \; | \; Restrict(e',\sigma))$ lendif
lIf {$e= (e')(e'')$ and $\Phi_{e''}("")=1$} return $(e' Restrict(e'',\sigma)) \; | \; Restrict(e',\sigma)$ lendif
endprocedure
```

@@ -684,7 +684,7 @@ INPUT: Regular expression $e$ over $\Sigma^*$, $x\in \Sigma^n$ where $n\in\N$
OUTPUT: $\Phi_e(x)$
procedure{FMatch}{$e$,$x$}
lIf {$x=""$} return $\CALL{MatchEmpty}(e)$ lendif
lIf {$x=""$} return $\CALL{MatchEmpty}{e}$ lendif
Let $e' \leftarrow \CALL{Restrict}{e,x_{n-1}}$
return $FMatch(e',x_0 \cdots x_{n-2})$
endprocedure
@@ -765,7 +765,7 @@ INPUT: Regular expression $e$ over $\Sigma^*$, $x\in \Sigma^n$ where $n\in\N$
OUTPUT: $\Phi_e(x)$
procedure{DFAMatch}{$e$,$x$}
Let $S \leftarrow S(e)$ be the set $\{ e[\alpha] | \alpha\in \{0,1\}^* \}$ as defined in the proof of the linear-time matching theorem.
Let $S \leftarrow S(e)$ be the set $\{ e[\alpha] | \alpha\in \Sigma^* \}$ as defined in the proof of the linear-time matching theorem.
For {$e' \in S$}
Let $v_{e'} \leftarrow 1$ -if $\Phi_{e'}("")=1$ and $v_{e'} \leftarrow 0$ otherwise
endfor
@@ -787,7 +787,7 @@ Hence it corresponds to a DFA.
We prove its correctness by induction on the length $n$ of the input.
Specifically, we will argue that before reading $x_i$, the variable $v_{e'}$ is equal to $\Phi_{e'}(x_0 \cdots x_{i-1})$ for every $e' \in S(e)$.
In the case $i=0$ this holds since we initialize $v_{e'} = \Phi_{e'}("")$ for all $e' \in S(e)$.
For $i>0$ this holds by induction since the inductive hypothesis implies that $last_e' = \Phi_{e'}(x_0 \cdots x_{i-2})$ for all $e' \in S(e)$ and by the definition of the set $S(e')$, for every $e' \in S(e)$ and $x_{i-1} \in \Sigma$, $e'' = e'[x_{i-1}]$ is in $S(e)$ and
For $i>0$ this holds by induction since the inductive hypothesis implies that $last_{e'} = \Phi_{e'}(x_0 \cdots x_{i-2})$ for all $e' \in S(e)$ and by the definition of the set $S(e')$, for every $e' \in S(e)$ and $x_{i-1} \in \Sigma$, $e'' = e'[x_{i-1}]$ is in $S(e)$ and
$\Phi_{e'}(x_0 \cdots x_{i-1}) = \Phi_{e''}(x_0 \cdots x_i)$.
:::

32 changes: 15 additions & 17 deletions lec_06_loops.md
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ NAND-TM programs, which add _loops_ and _arrays_ to NAND-CIRC.
* See some basic syntactic sugar and equivalence of variants of Turing machines and NAND-TM programs.


>_ "The bounds of arithmetic were however outstepped the moment the idea of applying the [punched] cards had occurred; and the Analytical Engine does not occupy common ground with mere 'calculating machines.'... In enabling mechanism to combine together general symbols, in successions of unlimited variety and extent, a uniting link is established between the operations of matter and the abstract mental processes of the most abstract branch of mathematical science. "_, Ada Augusta, countess of Lovelace, 1843
>_"The bounds of arithmetic were however outstepped the moment the idea of applying the [punched] cards had occurred; and the Analytical Engine does not occupy common ground with mere 'calculating machines.'... In enabling mechanism to combine together general symbols, in successions of unlimited variety and extent, a uniting link is established between the operations of matter and the abstract mental processes of the most abstract branch of mathematical science."_ , Ada Augusta, countess of Lovelace, 1843


@@ -62,12 +62,12 @@ See [chaploopoverviewfig](){.ref} for an overview of the models presented in thi
## Turing Machines


>_" Computing is normally done by writing certain symbols on paper. We may suppose that this paper is divided into squares like a child's arithmetic book.. The behavior of the \[human\] computer at any moment is determined by the symbols which he is observing, and of his' state of mind' at that moment... We may suppose that in a simple operation not more than one symbol is altered."_, \
>_ "We compare a man in the process of computing ... to a machine which is only capable of a finite number of configurations... The machine is supplied with a 'tape' (the analogue of paper) ... divided into sections (called 'squares') each capable of bearing a 'symbol' "_, Alan Turing, 1936
>_"Computing is normally done by writing certain symbols on paper. We may suppose that this paper is divided into squares like a child's arithmetic book.. The behavior of the \[human\] computer at any moment is determined by the symbols which he is observing, and of his' state of mind' at that moment... We may suppose that in a simple operation not more than one symbol is altered."_ , \
>_"We compare a man in the process of computing ... to a machine which is only capable of a finite number of configurations... The machine is supplied with a 'tape' (the analogue of paper) ... divided into sections (called 'squares') each capable of bearing a 'symbol' "_ , Alan Turing, 1936


>_ "What is the difference between a Turing machine and the modern computer? It's the same as that between Hillary's ascent of Everest and the establishment of a Hilton hotel on its peak."_ , Alan Perlis, 1982.
>_"What is the difference between a Turing machine and the modern computer? It's the same as that between Hillary's ascent of Everest and the establishment of a Hilton hotel on its peak."_ , Alan Perlis, 1982.


@@ -115,7 +115,7 @@ Let $PAL$ (for _palindromes_) be the function that on input $x\in \{0,1\}^*$, ou

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.

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:
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:

```table
---
@@ -131,13 +131,11 @@ State, Label
3,`LOOK_FOR_0`
4,`LOOK_FOR_1`
5,`RETURN`
6,`REJECT`
7,`ACCEPT`
8,`OUTPUT_0`
9,`OUTPUT_1`
10,`0_AND_BLANK`
11,`1_AND_BLANK`
12,`BLANK_AND_STOP`
6,`OUTPUT_0`
7,`OUTPUT_1`
8,`0_AND_BLANK`
9,`1_AND_BLANK`
10,`BLANK_AND_STOP`
```


@@ -146,7 +144,7 @@ We describe the operation of our Turing machine $M$ in words:

* $M$ starts in state `START` and goes right, looking for the first symbol that is $0$ or $1$. If it finds $\varnothing$ before it hits such a symbol then it moves to the `OUTPUT_1` state described below.

* Once $M$ finds such a symbol $b \in \{0,1\}$, $M$ deletes $b$ from the tape by writing the $\times$ symbol, it enters either the `RIGHT_0` or `RIGHT_1` mode according to the value of $b$ and starts moving rightwards until it hits the first $\varnothing$ or $\times$ symbol.
* Once $M$ finds such a symbol $b \in \{0,1\}$, $M$ deletes $b$ from the tape by writing the $\times$ symbol, it enters either the `RIGHT_`$b$ mode and starts moving rightwards until it hits the first $\varnothing$ or $\times$ symbol.

* Once $M$ finds this symbol, it goes into the state `LOOK_FOR_0` or `LOOK_FOR_1` depending on whether it was in the state `RIGHT_0` or `RIGHT_1` and makes one left move.

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

* 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.

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.
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.


### Turing machines: a formal definition
@@ -169,7 +167,7 @@ The above description can be turned into a table describing for each one of the
The formal definition of Turing machines is as follows:

::: {.definition title="Turing Machine" #TM-def}
A (one tape) _Turing machine_ with $k$ states and alphabet $\Sigma \supseteq \{0,1, \triangleright, \varnothing \}$ is represented by a _transition function_
A (one tape) _Turing machine_ $M$ with $k$ states and alphabet $\Sigma \supseteq \{0,1, \triangleright, \varnothing \}$ is represented by a _transition function_
$\delta_M:[k]\times \Sigma \rightarrow [k] \times \Sigma \times \{\mathsf{L},\mathsf{R}, \mathsf{S}, \mathsf{H} \}$.

For every $x\in \{0,1\}^*$, the _output_ of $M$ on input $x$, denoted by $M(x)$, is the result of the following process:
@@ -181,7 +179,7 @@ For every $x\in \{0,1\}^*$, the _output_ of $M$ on input $x$, denoted by $M(x)$,
* We then repeat the following process:

1. Let $(s',\sigma',D) = \delta_M(s,T[i])$.
2. Set $s \rightarrow s'$, $T[i] \rightarrow \sigma'$.
2. Set $s \leftarrow s'$, $T[i] \leftarrow \sigma'$.
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.)
4. If $D=\mathsf{H}$, then halt.

@@ -585,7 +583,7 @@ The idea behind the NAND-TM program to simulate $M$ is to:
Given the above, we can write code of the form:


`state_`$0$ $\ldots$ `state_`$\ell-1$, `Tape_`$0$`[i]`$\ldots$ `Tape_`$\ell'-1$`[i]`, `dir0`,`dir1` $\leftarrow$ `TRANSITION(` `state_`$0$ $\ldots$ `state_`$\ell-1$, `Tape_`$0$`[i]`$\ldots$ `Tape_`$\ell'-1$`[i]`, `dir0`,`dir1` `)`
`state_`$0$ $\ldots$ `state_`$\ell-1$, `Tape_`$0$`[i]`$\ldots$ `Tape_`$\ell'-1$`[i]`, `dir0`,`dir1` $\leftarrow$ `TRANSITION(` `state_`$0$ $\ldots$ `state_`$\ell-1$, `Tape_`$0$`[i]`$\ldots$ `Tape_`$\ell'-1$`[i]` `)`

`MODANDJUMP(dir0,dir1)`

10 changes: 5 additions & 5 deletions lec_07_other_models.md
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ program that computes the same function, and similarly can transform every NAND-
In this chapter we show this extends far beyond Turing machines. The techniques we develop allow us to show that all general-purpose programming
languages (i.e., Python, C, Java, etc.) are _Turing Complete_, in the sense that they can simulate Turing machines and hence compute all functions
that can be computed by a TM. We will also show the other direction- Turing machines can be used to simulate a program in any of these languages and
hence compute any function computable by them. This means that all these programming language are _Turing equivalent_: they are equivalent in power to
hence compute any function computable by them. This means that all these programming languages are _Turing equivalent_: they are equivalent in power to
Turing machines and to each other.
This is a powerful principle, which underlies behind the vast reach of Computer Science.
Moreover, it enables us to "have our cake and eat it too"- since all these models are equivalent, we can choose the model of our convenience for the task at
@@ -441,7 +441,7 @@ The [Wikipedia page](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) for

![In a _two dimensional cellular automaton_ every cell is in position $i,j$ for some integers $i,j \in \Z$. The _state_ of a cell is some value $A_{i,j} \in \Sigma$ for some finite alphabet $\Sigma$. At a given time step, the state of the cell is adjusted according to some function applied to the state of $(i,j)$ and all its neighbors $(i \pm 1, j\pm 1)$. In a _one dimensional cellular automaton_ every cell is in position $i\in \Z$ and the state $A_i$ of $i$ at the next time step depends on its current state and the state of its two neighbors $i-1$ and $i+1$.](../figure/onetwodimensionalca.png){#onetwodimcellularautomatafig}

Since the cells in the game of life are are arranged in an infinite two-dimensional grid, it is an example of a _two dimensional cellular automaton_.
Since the cells in the game of life are arranged in an infinite two-dimensional grid, it is an example of a _two dimensional cellular automaton_.
We can also consider the even simpler setting of a _one dimensional cellular automaton_, where the cells are arranged in an infinite line, see [onetwodimcellularautomatafig](){.ref}.
It turns out that even this simple model is enough to achieve Turing-completeness.
We will now formally define one-dimensional cellular automata and then prove their Turing completeness.
@@ -498,7 +498,7 @@ To turn the above ideas into a rigorous proof (and even statement!) of [onedimca
This notion will be useful for us in later chapters as well.


![A _configuration_ of a Turing machine $M$ with alphabet $\Sigma$ and state space $[k]$ encodes the state of $M$ at a particular step in its execution as a string $\alpha$ over the alphabet $\overline{\Sigma} = \Sigma \times (\{\cdot \} \times [k])$. The string is of length $t$ where $t$ is such that $M$'s tape contains $\varnothing$ in all positions $t$ and larger and $M$'s head is in a position smaller than $t$.
![A _configuration_ of a Turing machine $M$ with alphabet $\Sigma$ and state space $[k]$ encodes the state of $M$ at a particular step in its execution as a string $\alpha$ over the alphabet $\overline{\Sigma} = \Sigma \times (\{\cdot \} \cup [k])$. The string is of length $t$ where $t$ is such that $M$'s tape contains $\varnothing$ in all positions $t$ and larger and $M$'s head is in a position smaller than $t$.
If $M$'s head is in the $i$-th position, then for $j \neq i$, $\alpha_j$ encodes the value of the $j$-th cell of $M$'s tape, while $\alpha_i$ encodes both this value as well as the current state of $M$.
If the machine writes the value $\tau$, changes state to $t$, and moves right, then in the next configuration will contain at position $i$ the value $(\tau,\cdot)$ and at position $i+1$ the value $(\alpha_{i+1},t)$.](../figure/turingmachineconf.png){#turingconfigfig }

@@ -551,7 +551,7 @@ __Completing the proof of [onedimcathm](){.ref}.__ We can now restate [onedimca

::: {.theorem title="One dimensional automata are Turing complete (formal statement)" #onedimcathmformal}
For every Turing machine $M$, if we denote by $\overline{\Sigma}$ the alphabet of its configuration strings, then there is a one-dimensional cellular automaton $r$ over the alphabet $\overline{\Sigma}^*$ such that
$$\left( NEXT_M(\alpha) \right) = NEXT_r \left( \alpha \right)$$
$$ NEXT_M \left( \alpha \right) = NEXT_r \left( \alpha \right)$$
for every configuration $\alpha \in \overline{\Sigma}^*$ of $M$ (again using the convention that we consider $\alpha_i=\varnothing$ if $i$ is "out of bounds").
:::

@@ -1003,7 +1003,7 @@ It's λ's all the way down!

::: { .pause }
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$.
You can also $PAIR$, $HEAD$ and $TAIL$ based on $0,1,IF$.
You can also implement $PAIR$, $HEAD$ and $TAIL$ based on $0,1,IF$.
The most challenging part is to implement $RECURSE$ using only the operations of the pure λ calculus.
:::

8 changes: 4 additions & 4 deletions lec_08_uncomputability.md
Original file line number Diff line number Diff line change
@@ -302,7 +302,7 @@ The proof will use the previously established result [uncomputable-func](){.ref}
Recall that [uncomputable-func](){.ref} shows that the following function $F^*: \{0,1\}^* \rightarrow \{0,1\}$ is uncomputable:

$$
F^*(x) = \begin{cases}1 & x(x)=0 \text{or} x(x)=\bot \\ 0 & \text{otherwise} \end{cases}
F^*(x) = \begin{cases}0 & x(x)=1 \\ 1 & \text{otherwise} \end{cases}
$$
where $x(x)$ denotes the output of the Turing machine described by the string $x$ on the input $x$ (with the usual convention that $x(x)=\bot$ if this computation does not halt).

@@ -334,12 +334,12 @@ We claim that [halttof](){.ref} computes the function $F^*$.
Indeed, suppose that $x(x)=1$ (and hence $F^*(x)=0$).
In this case, $HALT(x,x)=1$ and hence, under our assumption that $M(x,x)=HALT(x,x)$, the value $z$ will equal $1$, and hence [halttof](){.ref} will set $y=x(x)=1$, and output the correct value $0$.

Suppose otherwise that $x(x) \neq 0$. In this case there are two possibilities:
Suppose otherwise that $x(x) \neq 1$ (and hence $F^*(x)=1$). In this case there are two possibilities:

* __Case 1:__ The machine described by $x$ does not halt on the input $x$ (and hence $F^*(x)=1$). In this case, $HALT(x,x)=0$. Since we assume that $M$ computes $HALT$ it means that on input $x,x$, the machine $M$ must halt and output the value $0$. This means that [halttof](){.ref} will set $z=0$ and output $1$.


* __Case 2:__ The machine described by $x$ halts on the input $x$ and outputs some $y' \neq 0$ (and hence $F^*(x)=0$). In this case, since $HALT(x,x)=1$, under our assumptions, [halttof](){.ref} will set $y=y' \neq 0$ and so output $0$.
* __Case 2:__ The machine described by $x$ halts on the input $x$ and outputs some $y' \neq 1$ (and hence $F^*(x)=0$). In this case, since $HALT(x,x)=1$, under our assumptions, [halttof](){.ref} will set $y=y' \neq 1$ and so output $1$.

We see that in all cases, $M'(x)=F^*(x)$, which contradicts the fact that $F^*$ is uncomputable.
Hence we reach a contradiction to our original assumption that $M$ computes $HALT$.
@@ -852,7 +852,7 @@ Moreover, even phrasing the right theorem to prove (i.e., the specification) is

* Unlike the finite case, there are actually functions that are _inherently uncomputable_ in the sense that they cannot be computed by _any_ Turing machine.

* These include not only some "degenerate" or "esoteric" functions but also functions that people have deeply care about and conjectured that could be computed.
* These include not only some "degenerate" or "esoteric" functions but also functions that people have deeply cared about and conjectured that could be computed.

* If the Church-Turing thesis holds then a function $F$ that is uncomputable according to our definition cannot be computed by any means in our physical world.
:::
2 changes: 1 addition & 1 deletion lec_12_NP.md
Original file line number Diff line number Diff line change
@@ -362,7 +362,7 @@ More concretely, if the instance has such an equation then we can know for sure
Our reduction is described in [zeroonetossumnalg ](){.ref}.
On input an instance $E = \{ e_t \}_{t=1}^m$ of $01EQ$ over $n$ variables $x_0,\ldots,x_{n-1}$, we output an $SSUM$ instance $y_0,\ldots,y_{n-1},T$ computed as follows:

* $y_i = \sum_{t=0}^{m-1} B^t v^t_i$ where $v^t_i$ equals $1$ if the variable $x_i$ appears in the equation $e_t$ and equals $0$ otherwise. The number $B$ is set to be $2n$ (any numb er larger than $n$ would work.)
* $y_i = \sum_{t=0}^{m-1} B^t v^i_t$ where $v^i_t$ equals $1$ if the variable $x_i$ appears in the equation $e_t$ and equals $0$ otherwise. The number $B$ is set to be $2n$ (any numb er larger than $n$ would work.)

* $T = \sum_{t=0}^{m-1} B^t b_t$ where $b_t$ is the integer on the right-hand side of the equation $e_t$.

6 changes: 3 additions & 3 deletions lec_13_Cook_Levin.md
Original file line number Diff line number Diff line change
@@ -138,7 +138,7 @@ INPUT: 3CNF formula $\varphi$ on $k$ variables and with $m$ clauses, string $w \
OUTPUT: $1$ iff $w$ satisfies $\varphi$
For{$j \in [m]$}
Let $\ell_1 \vee \ell_2 \vee \ell_j$ be the $j$-th clause of $\varphi$
Let $\ell_1 \vee \ell_2 \vee \ell_3$ be the $j$-th clause of $\varphi$
If{$w$ violates all three literals}
return $0$
Endif
@@ -367,7 +367,7 @@ The proof is a little bit technical but ultimately follows quite directly from t

::: {.proof data-ref="nand-thm"}
Let $F \in \mathbf{NP}$.
To prove [nand-thm](){.ref} we need to give a polynomial-time computable function that will map every $x^* \in \{0,1\}^*$ to a NAND-CIRC program $Q$ such that $F(x)=NANDSAT(Q)$.
To prove [nand-thm](){.ref} we need to give a polynomial-time computable function that will map every $x^* \in \{0,1\}^*$ to a NAND-CIRC program $Q$ such that $F(x^*)=NANDSAT(Q)$.

Let $x^* \in \{0,1\}^*$ be such a string and let $n=|x^*|$ be its length.
By [NP-def](){.ref} there exists $V \in \mathbf{P}$ and positive $a \in \N$ such that $F(x^*)=1$ if and only if there exists $w\in \{0,1\}^{n^a}$ satisfying $V(x^*w)=1$.
@@ -455,7 +455,7 @@ We now show both sides of this equivalence.

__Part I: Completeness.__ Suppose that there is $w\in \{0,1\}^n$ s.t. $Q(w)=1$. Let $z\in \{0,1\}^{n+m}$ be defined as follows: for $i\in [n]$, $z_i=w_i$ and for $i\in \{n,n+1,\ldots,n+m\}$ $z_i$ equals the value that is assigned in the $(i-n)$-th line of $Q$ when executed on $w$. Then by construction $z$ satisfies all of the constraints of $\Psi$ (including the constraint that $z_{\ell^*}=NAND(0,0)=1$ since $Q(w)=1$.)

__Part II: Soundness.__ Suppose that there exists $z\in \{0,1\}^{n+m}$ satisfying $\Psi$. Soundness will follow by showing that $Q(z_0,\ldots,z_{n-1})=1$ (and hence in particular there exists $w\in \{0,1\}^n$, namely $w=z_0\cdots z_{n-1}$, such that $Q(w)=1$). To do this we will prove the following claim $(*)$: for every $\ell \in [m]$, $z_{\ell+n}$ equals the value assigned in the $\ell$-th step of the execution of the program $Q$ on $z_0,\ldots,z_{n-1}$. Note that because $z$ satisfies the constraints of $\Psi$, $(*)$ is sufficient to prove the soundness condition since these constraints imply that the last value assigned to the variable `y_0` in the execution of $Q$ on $z_0\cdots w_{n-1}$ is equal to $1$. To prove $(*)$ suppose, towards a contradiction, that it is false, and let $\ell$ be the smallest number such that $z_{\ell+n}$ is _not_ equal to the value assigned in the $\ell$-th step of the execution of $Q$ on $z_0,\ldots,z_{n-1}$. But since $z$ satisfies the constraints of $\Psi$, we get that $z_{\ell+n}=NAND(z_i,z_j)$ where (by the assumption above that $\ell$ is _smallest_ with this property) these values _do_ correspond to the values last assigned to the variables on the right-hand side of the assignment operator in the $\ell$-th line of the program. But this means that the value assigned in the $\ell$-th step is indeed simply the NAND of $z_i$ and $z_j$, contradicting our assumption on the choice of $\ell$.
__Part II: Soundness.__ Suppose that there exists $z\in \{0,1\}^{n+m}$ satisfying $\Psi$. Soundness will follow by showing that $Q(z_0,\ldots,z_{n-1})=1$ (and hence in particular there exists $w\in \{0,1\}^n$, namely $w=z_0\cdots z_{n-1}$, such that $Q(w)=1$). To do this we will prove the following claim $(*)$: for every $\ell \in [m]$, $z_{\ell+n}$ equals the value assigned in the $\ell$-th step of the execution of the program $Q$ on $z_0,\ldots,z_{n-1}$. Note that because $z$ satisfies the constraints of $\Psi$, $(*)$ is sufficient to prove the soundness condition since these constraints imply that the last value assigned to the variable `y_0` in the execution of $Q$ on $z_0\cdots z_{n-1}$ is equal to $1$. To prove $(*)$ suppose, towards a contradiction, that it is false, and let $\ell$ be the smallest number such that $z_{\ell+n}$ is _not_ equal to the value assigned in the $\ell$-th step of the execution of $Q$ on $z_0,\ldots,z_{n-1}$. But since $z$ satisfies the constraints of $\Psi$, we get that $z_{\ell+n}=NAND(z_i,z_j)$ where (by the assumption above that $\ell$ is _smallest_ with this property) these values _do_ correspond to the values last assigned to the variables on the right-hand side of the assignment operator in the $\ell$-th line of the program. But this means that the value assigned in the $\ell$-th step is indeed simply the NAND of $z_i$ and $z_j$, contradicting our assumption on the choice of $\ell$.
:::


26 changes: 13 additions & 13 deletions lec_15_probability.md
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ It turns out this is true for every $n$:
![The event that if we toss three coins $x_0,x_1,x_2 \in \{0,1\}$ then the sum of the $x_i$'s is even has probability $1/2$ since it corresponds to exactly $4$ out of the $8$ possible strings of length $3$.](../figure/even3coins.png){#eventhreecoinsfig .margin }

> ### {.lemma #evenprob}
For every $n>0$, $$\Pr_{x\sim \{0,1\}^n}[ \text{$\sum_{i=0}^{n-1} x_i$ is even }] = 1/2$$
For every $n>0$, $$\Pr_{x\sim \{0,1\}^n}\left[ \text{$\sum_{i=0}^{n-1} x_i$ is even }\right] = 1/2 \;.$$
> ### { .pause }
To test your intuition on probability, try to stop here and prove the lemma on your own.
@@ -113,12 +113,12 @@ This probability is equal to $1/4$ for $n > 1$. (It is a great exercise for you

Because intersection corresponds to considering the logical AND of the conditions that two events happen, while union corresponds to considering the logical OR, we will sometimes use the $\wedge$ and $\vee$ operators instead of $\cap$ and $\cup$, and so write this probability $p=\Pr[A \cap B]$ defined above also as
$$
\Pr_{x\sim \{0,1\}^n} \left[ \sum_i x_i =0 \mod 2 \; \wedge \; x_0 = 1 \right] \;.
\Pr_{x\sim \{0,1\}^n} \left[ \sum_{i=0}^{n-1} x_i =0 \mod 2 \; \wedge \; x_0 = 1 \right] \;.
$$

If $A \subseteq \{0,1\}^n$ is an event, then $\overline{A} = \{0,1\}^n \setminus A$ corresponds to the event that $A$ does _not_ happen.
Since $|\overline{A}|=2^n-|A|$, we get that
$$\Pr[\overline{A}] = \tfrac{|\overline{A}|}{2^n} = \tfrac{2^n-|A|}{2^n}=1-\tfrac{|A|}{2^n} = 1- \Pr[A]
$$\Pr[\overline{A}] = \tfrac{|\overline{A}|}{2^n} = \tfrac{2^n-|A|}{2^n}=1-\tfrac{|A|}{2^n} = 1- \Pr[A] \;.
$$
This makes sense: since $A$ happens if and only if $\overline{A}$ does _not_ happen, the probability of $\overline{A}$ should be one minus the probability of $A$.

@@ -388,7 +388,7 @@ Much of probability theory is concerned with so called _concentration_ or _tail_
The first and simplest one of them is Markov's inequality:

> ### {.theorem title="Markov's inequality" #markovthm}
If $X$ is a non-negative random variable then for every $k>1$, $\Pr[ X \geq k \E[X] ] \leq 1/k$.
If $X$ is a non-negative random variable then for every $k>0$, $\Pr[ X \geq k \E[X] ] \leq 1/k$.
> ### { .pause }
Markov's Inequality is actually a very natural statement (see also [markovfig](){.ref}). For example, if you know that the average (not the median!) household income in the US is 70,000 dollars, then in particular you can deduce that at most 25 percent of households make more than 280,000 dollars, since otherwise, even if the remaining 75 percent had zero income, the top 25 percent alone would cause the average income to be larger than 70,000 dollars. From this example you can already see that in many situations, Markov's inequality will not be _tight_ and the probability of deviating from expectation will be much smaller: see the Chebyshev and Chernoff inequalities below.
@@ -480,7 +480,7 @@ The following extremely useful theorem shows that such exponential decay occurs
If $X_0,\ldots,X_{n-1}$ are i.i.d random variables such that $X_i \in [0,1]$ and $\E[X_i]=p$ for every $i$,
then for every $\epsilon >0$
$$
\Pr[ \left| \sum_{i=0}^{n-1} X_i - pn \right| > \epsilon n ] \leq 2\cdot e^{-2\epsilon^2 n} . \label{eqchernoff}
\Pr\left[ \left| \sum_{i=0}^{n-1} X_i - pn \right| > \epsilon n \right] \leq 2\cdot e^{-2\epsilon^2 n} . \label{eqchernoff}
$$

We omit the proof, which appears in many texts, and uses Markov's inequality on i.i.d random variables $Y_0,\ldots,Y_n$ that are of the form $Y_i = e^{\lambda X_i}$ for some carefully chosen parameter $\lambda$.
@@ -493,7 +493,7 @@ Since $e$ is roughly $2.7$ (and in particular larger than $2$),
For $n>1/\epsilon^2$, the equation will still be true if we replaced the right-hand side with the simpler $e^{-\epsilon^2 n}$.
Hence we will sometimes use the Chernoff bound as stating that for $X_0,\ldots,X_{n-1}$ and $p$ as above, $n> 1/\epsilon^2$ then
$$
\Pr[ \left| \sum_{i=0}^{n-1} X_i - pn \right| > \epsilon n ] \leq e^{-\epsilon^2 n} . \label{eqchernoffsimpler}
\Pr\left[ \left| \sum_{i=0}^{n-1} X_i - pn \right| > \epsilon n \right] \leq e^{-\epsilon^2 n} . \label{eqchernoffsimpler}
$$
:::

@@ -581,17 +581,17 @@ Prove that $\E[X] = 1/2$.


::: {.exercise title="standard deviation" #stddev}
1. Give an example for a random variable $X$ such that $X$'s standard deviation is _equal to_ ${\mathbb{E}}[ | X - {\mathbb{E}}[X] | ]$
1. Give an example for a random variable $X$ such that $X$'s standard deviation is _equal to_ ${\mathbb{E}}[ | X - {\mathbb{E}}[X] | ]$.

2. Give an example for a random variable $X$ such that $X$'s standard deviation is _not equal to_ ${\mathbb{E}}[ | X - {\mathbb{E}}[X] | ]$
2. Give an example for a random variable $X$ such that $X$'s standard deviation is _not equal to_ ${\mathbb{E}}[ | X - {\mathbb{E}}[X] | ]$.
:::


> ### {.exercise title="Product of expectations" #expprodex}
Prove [expprod](){.ref}
Prove [expprod](){.ref}.

> ### {.exercise title="Transformations preserve independence" #indeplemex}
Prove [indeplem](){.ref}
Prove [indeplem](){.ref}.


> ### {.exercise title="Variance of independent random variables" #varianceex}
@@ -603,15 +603,15 @@ Recall the definition of a distribution $\mu$ over some finite set $S$.
Shannon defined the _entropy_ of a distribution $\mu$, denoted by $H(\mu)$, to be $\sum_{x\in S} \mu(x)\log(1/\mu(x))$.
The idea is that if $\mu$ is a distribution of entropy $k$, then encoding members of $\mu$ will require $k$ bits, in an amortized sense.
In this exercise we justify this definition. Let $\mu$ be such that $H(\mu)=k$. \
1. Prove that for every one to one function $F:S \rightarrow \{0,1\}^*$, $\E_{x \sim \mu} |F(x)| \geq k$. \
1. Prove that for every one-to-one function $F:S \rightarrow \{0,1\}^*$, $\E_{x \sim \mu} |F(x)| \geq k$. \
2. Prove that for every $\epsilon$, there is some $n$ and a one-to-one function $F:S^n \rightarrow \{0,1\}^*$, such that $\E_{x\sim \mu^n} |F(x)| \leq n(k+\epsilon)$,
where $x \sim \mu$ denotes the experiments of choosing $x_0,\ldots,x_{n-1}$ each independently from $S$ using the distribution $\mu$.

> ### {.exercise title="Entropy approximation to binomial" #entropybinomex}
Let $H(p) = p \log(1/p)+(1-p)\log(1/(1-p))$.^[While you don't need this to solve this exercise, this is the function that maps $p$ to the entropy (as defined in [entropyex](){.ref}) of the $p$-biased coin distribution over $\{0,1\}$, which is the function $\mu:\{0,1\}\rightarrow [0,1]$ s.y. $\mu(0)=1-p$ and $\mu(1)=p$.]
Let $H(p) = p \log(1/p)+(1-p)\log(1/(1-p))$.^[While you don't need this to solve this exercise, this is the function that maps $p$ to the entropy (as defined in [entropyex](){.ref}) of the $p$-biased coin distribution over $\{0,1\}$, which is the function $\mu:\{0,1\}\rightarrow [0,1]$ s.t. $\mu(0)=1-p$ and $\mu(1)=p$.]
Prove that for every $p \in (0,1)$ and $\epsilon>0$, if $n$ is large enough then^[__Hint:__ Use Stirling's formula for approximating the factorial function.]
$$
2^{(H(p)-\epsilon)n }\binom{n}{pn} \leq 2^{(H(p)+\epsilon)n}
2^{(H(p)-\epsilon)n } \leq \binom{n}{pn} \leq 2^{(H(p)+\epsilon)n},
$$
where $\binom{n}{k}$ is the binomial coefficient $\tfrac{n!}{k!(n-k)!}$ which is equal to the number of $k$-size subsets of $\{0,\ldots,n-1\}$.

2 changes: 1 addition & 1 deletion lec_17_model_rand.md
Original file line number Diff line number Diff line change
@@ -614,7 +614,7 @@ In other words, we need to show that for every $z\in \{0,1\}^m$ and set $S \subs
$$\Pr_{s \sim \{0,1\}^m}[ z \in S \oplus s ] \geq \tfrac{1}{2}\; \label{sipsergacsprodboundtwoeq}.$$

To show this, we observe that $z \in S \oplus s$ if and only if $s \in S \oplus z$ (can you see why). Hence we can rewrite the probability on the left-hand side of [sipsergacsprodboundtwoeq](){.eqref} as $\Pr_{s\sim \{0,1\}^m}[ s\in S \oplus z]$ which simply equals $|S \oplus z|/2^m = |S|/2^m \geq 1/2$!
This concludes the proof of __CLAIM I__ and hence of [BPPvsNP](){.ref}.
This concludes the proof of __CLAIM II__ and hence of [BPPvsNP](){.ref}.
:::