N or Space for next slide, P for previous slide, F for full screen, M for menu
Boaz Barak (instructor), Brian Sapozhnikov (Head TF), Albert Chalom, Alexis Ross, Charles O’Mara, Daniel Chen, David Li , Jambay Kinley, Jane Ahn, John Shen, Josh Seides, Laura Pierson, Pranay Tankala, Raymond Lin, Theresa Nguyen, Wanqian Yang, William Fu, Hikari Sorensen (Extension TF), Eric Lu (Patel Fellow)
Laptops/phones only on last 5 rows please.
Up till now: Talked about finite functions \(F:\{0,1\}^n \rightarrow \{0,1\}^m\)
Today: First introduction to infinite functions \(F:\{0,1\}^* \rightarrow \{0,1\}^*\)
Or is it?
\(PROD:\mathbb{N}\times \mathbb{N}\rightarrow \mathbb{N}\). Equivalently \(PROD:\{0,1\}^* \rightarrow \{0,1\}^*\)
Which of the following functions is computable by a NAND++ program? pollev.com/cs121
a. \(ADD(a,b) = a + b\).
b. \(MULTIPLY(a,b) = a \cdot b\)
c. \(LOG(a,b) = \max \{c \in \mathbb{N}: b^c \leq a \}\).
d. All of the above
Which of the following functions is computable by a NAND++ program? pollev.com/cs121
a. \(ADD(a,b) = a + b\).
b. \(MULTIPLY(a,b) = a \cdot b\)
c. \(LOG(a,b) = \max \{c \in \mathbb{N}: b^c \leq a \}\).
d. All of the above
Goal: Compute infinite function \(F:\{0,1\}^* \rightarrow \{0,1\}\) with finite set of instructions.
Need to handle \(\text{Input length} \gg \text{Program length}\).
NAND + LOOPS + Indexing = NAND++
loop
. Effectively
do {
...code...
} until loop==False
i
. Variable such as Temp[i]
replaced with Temp[
\(val\)]
where \(val\) is current value of i
i
in enhanced NAND++ controlled via i += foo
, i -= foo
operations.If \(P\) is a vanilla NAND++ program, to execute \(P\) on \(x\in \{0,1\}^*\) do:
X[0]
… X[
\(n-1\)]
to \(x_0,\ldots,x_{n-1}\). Initialize Xvalid[0]
… Xvalid[
\(n-1\)]
to \(1\).i
with \(\ell\).loop
\(= 0\) then break and output Y[0]
…Y[
\(m-1\)]
where \(m\) is the smallest such that Yvalid[
\(m\)]
\(=0\).Exercise: Break out in groups and explain the above to one another. Make sure you understand why this is equivalent to the definition in the book.
If \(P\) is a vanilla NAND++ program, to execute \(P\) on \(x\in \{0,1\}^*\) do:
Let \(n=|x|\). Initialize the variables X[0]
… X[
\(n-1\)]
to \(x_0,\ldots,x_{n-1}\). Initialize Xvalid[0]
… Xvalid[
\(n-1\)]
to \(1\).
Set \(\ell=0\), \(t=0\).
Do “search and replace” on the code of \(P\) replacing i
with \(\ell\).
Run the lines of \(P\) as it was a NAND program, updating all variables accordingly.
If loop
= 0 then break and output Y[0]
…Y[
\(m-1\)]
where \(m\) is the smallest such that Yvalid[
\(m\)]
\(=0\).
Otherwise set \(t= t+1\), \(\ell = Index(t)\) and go back to 3.
Exercise: Suppose that \(P\) is a NAND++ program that computes a function \(F:\{0,1\}^* \rightarrow \{0,1\}\). Suppose that moreover that for every \(x\in \{0,1\}^n\), the number of lines that \(P\) executes before it halts is always at most \(n^2\).
Prove that there is a NAND program \(Q\) with \(n\) inputs and one output and at most \(10\cdot n^2\) lines, such that for every \(x\in \{0,1\}^n\), \(Q(x)=F(x)\).
Exercise: Suppose that \(P\) is a NAND++ program that computes a function \(F:\{0,1\}^* \rightarrow \{0,1\}\). Suppose that moreover that for every \(x\in \{0,1\}^n\), the number of lines that \(P\) executes before it halts is always at most \(n^2\).
Prove that there is a NAND program \(Q\) with \(n\) inputs and one output and at most \(10\cdot n^2\) lines, such that for every \(x\in \{0,1\}^n\), \(Q(x)=F(x)\).
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?
Talk in groups and decide which of the following quantities is constants - have bounded size independent of how long the input is:
The number of lines in a NAND++ program
The number of states in a Turing machine
The maximum value that the index variable i
achieves in a NAND++ execution.
The rightmost position that the head of a Turing machine reaches during an execution.
The number of symbols in the alphabet of a Turing machine.
The number of variable identifiers in a NAND++ program.
The number of bits needed to describe a Turing machine’s state transition function.
Talk in groups and decide which of the following quantities is constants - have bounded size independent of how long the input is:
The number of lines in a NAND++ program
The number of states in a Turing machine
The maximum value that the index variable i
achieves in a NAND++ execution.
The rightmost position that the head of a Turing machine reaches during an execution.
The number of symbols in the alphabet of a Turing machine.
The number of variable identifiers in a NAND++ program.
The number of bits needed to describe a Turing machine’s state transition function.
The NAND++ program size, NAND++ number of variables, Turing machine states, alphabet and state transition are fixed in advance. (before we get the input)
The number of execution steps of NAND++/TM, position of index variable /head all depend on the input length. (grow with the input length)
The point of NAND++/Turing machines: A constant sized recipe how to execute an unbounded in advance number of operations.
What is computation? Local evolution of global state according to a finite set of instructions.
DNA, physical systems, bee colonies, slime mould, markets..
Three types of memory access:
Question: How do we implement i+= foo
and i -= bar
in NAND++?
Answer: “Breadcrumbs” and “wait for bus strategy”
indexincreasing
set to \(1\) when at Atstart[i]
\(=1\),set to \(0\) when observe a new place (Breadcrumbs[i]
\(=0\)).Breadcrumbs
array initialized to \((0,0,\ldots)\), Breadcrumbs[i]
set to \(1\) at the end of every loop
indexincreasing
set to \(1\) when at Atstart[i]
\(=1\),set to \(0\) when observe a new place (Breadcrumbs[i]
\(=0\)).
Exercise: Prove that \(F\) is computable by one-tape TM if and only if it is computable by two-tape TM.
Exercise: Prove that \(F\) is computable by one-tape TM if and only if it is computable by two-tape TM.
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']\)
Interplay:
Use computation results to show equivalence results.
Once we have equivalence results, can prove computation results in the most convenient model.
temp = NAND(X[0],X[0])
loop = NAND(X[0],temp)
For NAND programs: for every input \(x \in \{0,1\}^n\), \(P(x)\) produces an output \(y\in \{0,1\}^m\).
For NAND++ programs: some programs on some inputs might fail to halt.
NAND: No loops: \(s\) lines = \(s\) computational steps. Can access at most \(3s\) memory location. straightline program / circuit
NAND++: Loops: same line can be repeated in many steps: num steps \(\gg\) num lines Arrays: index variable moves between iterations: memory usage \(\gg\) num lines
Let \(XOR:\{0,1\}^*\) be such that \(XOR(x) = x_0 + x_1 + \cdots + x_{n-1} \mod 2\).
Theorem: There is NAND++ program \(P\) to compute \(XOR\).
It’s not that NAND can’t compute \(XOR\). It’s a category error!
Theorem: For every \(n\in \mathbb{N}\), there is a NAND program \(P_n\) to compute \(XOR_n\): restriction of \(XOR\) to inputs of length \(n\).
More proficient in understanding our models and moving between them.
Food for thought: Consider the function \(reverse:\{0,1\}^* \rightarrow \{0,1\}^*\) such that \(reverse(x_0 \cdots x_{n-1}) = x_{n-1}x_{n-2}\cdots x_0\).
At given point in time, can encode all of the memory contents and state of NAND++ program / Turing machine as finite string.
Length of string = O(number of steps so far)
Configuration at step \(\ell\) very similar to configuration at step \(\ell + 1\). Differs only in constant number of bits
Think in groups: How would you encode the configuration of a program as a string? You can be wasteful in space, but try to make sure that computing the next configuration from the previous one is as simple as possible. Choose vanilla/enhanced NAND++ or Turing machines as per your convenience