N or Space for next slide, P for previous slide, F for full screen, M for menu
Boaz Barak (instructor), Salil Vadhan (co-instructor), Juan Perdomo (Head TF).
Team: Aditya Mahadevan, Brian Sapozhnikov (surveys), Chan Kang (extension), Gabe Abrams (Ed Tech), Gabe Montague (NAND web), Jessica Zhu (proof workshops), John Shen, Juan Esteller (NAND implementation), Karl Otness, Katherine Binney, Mark Goldstein (clicker expert), Stefan Spataru, Susan Xu, Tara Sowrirajan, Thomas Orton (Advanced Section)
Slides will be posted online.
Laptops/phones only on last 3 rows please.
Course resources
Calendar
Salil review lecture Tuesday 10/10 evening
Midterm prep questions
Main theorems
No pset before midterm
Think of variables as arrays
Config: seqeuence of blocks. Initially \(n\)*, eventually largest index reached \(i\).
Main point: Computation is sequence of simple operations.
1930’s: Three different definitions of “computable functions”
\(\lambda\) calculus (Alonzo Church 1932,1936)
General recursive functions (Kurt Gödel 1934)
Turing machines (Alan Turing 1937)
Church: Conjectured “\(\lambda\) computable = computable”.
Gödel: Unconvinced. Proposes “general recursive”
Church+Kleene: Two definitions equivalent
Gödel: Maybe both equivalent but “wrong”
Turing: Defines “Turing machines” (shows equivalent to \(\lambda\) calculus)
Gödel, Church, everyone: Convinced captures computation
What’s the corresponding element in a Turing machine to the NAND++ index variable i?
a. Current state
b. Alphabet size
c. Head position
d. State transition function
Models person with:
Unbounded sheet of paper (“tape”)
Finite working memory (“states”)
Each step: Read/Write one symbol, update memory, move to adjacent tape location.
Example: Person computing \(a \times b\) using gradeschool algorithm.
Question: Why did Turing try to model a person and not an electronic computer?
Features: integer variables | arithmetic operations | arithmetic with index
Question: How can we simulate integer arrays with two dimensional bit arrays?
Features: Integer variables | 2-dim arrays | Arithmetic operations | Arithmetic with index
Question: How can we simulate two dimensional arrays with one dimensional arrays?
Answer: Replace the indices \((i,j)\) with \(PAIR(i,j)\) where \(PAIR:\mathbb{N}^2 \rightarrow \mathbb{N}\) is one-to-one (e.g., \(PAIR(x,y)=\tfrac{1}{2}(x+y+1)(x+y)+x\))
Features: Integer variables | 2-dim arrays | Arithmetic operations | Arithmetic with index
Question: How can we implement arithmetic operations on bit-representations of integers?
Answer: Like we learned in school
Features: Integer variables | 2-dim arrays | Arithmetic operations | Arithmetic with index
Question: How can we use \(i++\) and \(i--\) to implement
COPYTOi(foo)
Answer:
Array
marker
initially set to \((1,0,\ldots)\)
Repeat: decrement
foo
and move \(1\) in
marker
one step right.
Move \(i\) until we reach point where
marker
is equal to \(1\).
Features: Integer variables | 2-dim arrays | Arithmetic operations | Arithmetic with index | Increment/decrement index
Question: How do we implement \(i++\) and \(i--\) in NAND++?
Answer: “Breadcrumbs” and “wait for bus strategy”
atstart_i
initialized to \((1,0,0,0,\ldots)\)
breadcrumbs_i
set to \(1\) at the end of every loop
indexincreasing
set to \(1\) when at \(i=0\),set to \(0\) at new point.
marker
usually all zeroes, set to \(1\) at a point we want to reach again.
Def: A Turing Machine is \(M:[k] \times \Sigma \rightarrow [k] \times \Sigma \times \{L,R\}\)
Turing Machine Simulator (see also this)
Question: Prove that two-way infinite tape is same as one-way infinite tape.
Idea: Odd location tape 1, Even location tape 2.
Add “marker” for heads location: \(\Sigma \mapsto \Sigma \times \{ m,u \}\)
Simulate one step:
New state: \([k] \mapsto [k] \times [k'] \approx [k\times k']\)
Thm: \(F\) NAND++-computable iff \(F\) TM-computable
Proof: \(\Leftarrow\): easy to simulate TM by NAND<<
\(\Rightarrow\): not hard to simulate NAND++ by TM. (head location = \(i\), state = line number + variables with absolute indices)
If \(f = \lambda x.e\) then \(f y\) is \(e[x \rightarrow y]\).
Currying \(\lambda x,y. exp = \lambda x.(\lambda y. exp)\)
Precedence rule: \(f x y = (f x) y\).
Question: Suppose that \(F = \lambda f. (\lambda x. (f x)f)\), \(1 = \lambda x.(\lambda y.x)\) and \(0=\lambda x.(\lambda y.y)\). What is \(F \; 1\; 0\)?
a. \(1\)
b. \(0\)
c. \(\lambda x.1\)
d. \(\lambda x.0\)
Informal: \(F\) is \(\lambda\)-computable if equal to \(\lambda\) expression.
Recall: \(NIL\) - empty list, \(PAIR\) - create pair. List \((a,b,c) = PAIR \; a \; (PAIR \; b \; (PAIR\; c \; NIL))\)
Formal: \(F:\{0,1\}^* \rightarrow \{0,1\}\) is \(\lambda\)-computable if exists \(\lambda\)-expression \(e\) such that for every \(x\in \{0,1\}^n\), \(F(x_0,\ldots,x_{n-1})\) equals
Thm: \(F\) is \(\lambda\)-computable iff \(F\) is NAND++ computable.
Proof: \(\Rightarrow\): repeat “search and replace” to evaluate \(\lambda\) expressions.
\(\Leftarrow\): crucial insight is \(NEXT_P\) is computable by “search and replace”
To define \(MAP\), \(FILTER\), \(REDUCE\) we need recursion
Turing Eret @turingmachine
Hat-tip: Matt Might (see also Y combinator in Javascript)
Example:
Question: Why is this a recursive definition for \(PAR\; L\)?
Non recursive function:
Lemma: \(PAR = APAR \; APAR\) satisfies equation \(\color{red}{(*)}\)
Proof: Plug \(f=APAR\) in \(\color{green}{(**)}\).
Cor: \(PAR \; L\) is the parity of \(L\) for every list \(L\).
Thm: Let \(Y = \lambda f. (\lambda x. f (x\; x)) (\lambda y. f (y\; y))\). Then for every \(F\), \(f=YF\) solves the recursive/fixed-point equation \(f=F\; f\).
Pf: Write
\(Y\; F = \color{green}{(\lambda x. F (x\; x))} \color{red}{(\lambda y. F (y\; y))}\) =\(\color{green}{F (x\; x)}[x \rightarrow \color{red}{\lambda y.F(y \; y)}]\)
=\(\color{green}{F(}\color{red}{(\lambda y.F(y \; y))} \; \color{red}{(\lambda y.F(y \; y))} \color{green}{)}\)
=\(F(Y F)\)
Using this can define \(FILTER\),\(MAP\),\(REDUCE\), etc..
Simulate \(NEXT_P\)
Recursively repeat until halt
Crucial observations:
“Computable” \(\approx\) TM-computable
= \(\lambda\)-computable
= NAND++ computable
= NAND<< computable
= Python-computable
\(\approx\) “Human computable”
\(\approx\) “Alien computable”
= ….