Computing Every Function

Pyro·2021년 10월 3일
0

계산이론

목록 보기
5/5

지난 시간에 Computation 을 엄밀히 정의하면서,
computation 을 Circuit 으로 구현하든, 프로그램으로 구현하든,
그게 그거라는 것을 보였다.

또한 NAND 하나로, AND / OR / NOT 3가지를 다 표현 가능하니,
NAND 하나만으로 computation 을 구현할 수 있다.

이번 시간에는 NAND 하나만으로, 정말로 모든 함수를 compute 할 수 있는지 증명해보려 한다.

Definition (Lookup function)

LOOKUPk:{0,1}2k+k{0,1}LOOKUP_k: \{0,1\}^{2^k+k}\rightarrow \{0,1\}
Lookup function of order kk is defined as follows:
x=x0x1x2k1{0,1}2kx = x_0 x_1 \ldots x_{2^{k}-1} \in\{0,1\}^{2^k}
i=i0i1ik1{0,1}ki = i_0 i_1 \ldots i_{k-1} \in \{0,1\}^k

LOOKUPk(x,i)=xi{0,1}LOOKUP_k(x,i) = x_i \in \{0,1\}

where xix_i = ithi^{th} entry of xx.

즉 Lookup function 이란, i bit string 을 숫자로 바꾸어서,
해당하는 숫자의 위치에 있는 i 번째 bit 를 x bit string 에서 가져오는 함수이다.

Lemma 4.11 (Lookup recursion)

k2k \geq 2
a=LOOKUPk1(x0,,x2k11,i1,,ik1)a = LOOKUP_{k-1}(x_0,\ldots,x_{2^{k-1}-1},i_1,\ldots,i_{k-1})
b=LOOKUPk1(x2k1,,x2k1,i1,,ik1)b = LOOKUP_{k-1}(x_{2^{k-1}},\ldots,x_{2^k-1},i_1,\ldots,i_{k-1})

LOOKUPk(x0,,x2k1,i0,,ik1)={aif i0=0bif i0=1LOOKUP_k(x_0,\ldots,x_{2^k-1},i_0,\ldots,i_{k-1}) = \begin{cases} a &\text{if $i_0 = 0$} \\ b &\text{if $i_0 = 1$} \end{cases}

Proof

If i0=0i_{0} = 0, then the index ii is in {0,,2k11}\{0,\ldots,2^{k-1}-1\}.
Perform the lookup on the first half of xx.
Then, LOOKUPk(x,i)=LOOKUPk1(x0,,x2k11,i1,,ik1)=aLOOKUP_k(x,i) = LOOKUP_{k-1}(x_0,\ldots,x_{2^{k-1}-1},i_1,\ldots,i_{k-1}) = a

If i0=1i_{0} = 1, then the index ii is in {2k1,,2k1}\{2^{k-1},\ldots,2^k-1\}.
Perform the lookup on the "second half" of xx.
Then, LOOKUPk(x,i)=LOOKUPk1(x2k1,,x2k1,i1,,ik1)=bLOOKUP_k(x,i) = LOOKUP_{k-1}(x_{2^{k-1}},\ldots,x_{2^k-1},i_1,\ldots,i_{k-1}) = b

증명이라기보다는 Lookup recursion 함수에 대한 설명 같다.

Theorem 4.10 (Lookup function 의 구현)

LOOKUPk:{0,1}2k+k{0,1}LOOKUP_k: \{0,1\}^{2^k+k}\rightarrow \{0,1\} is a lookup function.
For k>0\forall k > 0, \exists NAND-CIRC program that computes LOOKUPkLOOKUP_k.
Moreover, the number of lines in this program 42k\leq 4 \cdot 2^k

Proof

For k=1k = 1,
LOOKUP1:{0,1}3{0,1}LOOKUP_1: \{0,1\}^{3}\rightarrow \{0,1\} can be computed by
4 line NAND-CIRC program.

def IF(cond,a,b):
  notcond = NAND(cond,cond)
  temp = NAND(b,notcond)
  temp1 = NAND(a,cond)
  return NAND(temp,temp1)

For k2k \geq 2,
We can apply Lemma 4.11.
a=LOOKUPk1(x0,,x2k11,i1,,ik1)a = LOOKUP_{k-1}(x_0,\ldots,x_{2^{k-1}-1},i_1,\ldots,i_{k-1}) \
b=LOOKUPk1(x2k1,,x2k1,i1,,ik1)b = LOOKUP_{k-1}(x_{2^{k-1}},\ldots,x_{2^k-1},i_1,\ldots,i_{k-1})

LOOKUPk(x0,,x2k1,i0,,ik1)={aif i0=0bif i0=1LOOKUP_k(x_0,\ldots,x_{2^k-1},i_0,\ldots,i_{k-1}) = \begin{cases} a &\text{if $i_0 = 0$} \\ b &\text{if $i_0 = 1$} \end{cases}

Recursively call LOOKUPkLOOKUP_k until kk becomes 1.
Then, we have 42k4 \cdot 2^k lines of NAND-CIRC program.

Theorem 4.12 (Universality of NAND)

For n,m>0n,m>0 and function f:{0,1}n{0,1}mf: \{0,1\}^n\rightarrow \{0,1\}^m
\exists constant c>0c>0 such that
\exists Boolean circuit with at most cm2nc \cdot m 2^n gates that computes the function ff.

Proof

For \forall function f:{0,1}n{0,1}f: \{0,1\}^n \rightarrow \{0,1\},
we can write a NAND-CIRC program that does the following:

  1. Initialize 2n2^n variables of the form
    temp = NAND(X[0], X[1])
    one = NAND(X[0], temp)
    zero = NAND(one, one)
    x0=f(000)x_0 = f(00\cdots0), \cdots, x2n1=f(111)x_{2^n-1} = f(11\cdots1)
    This requires 3+2n3 + 2^n lines of code.
  1. Compute LOOKUPnLOOKUP_n on the 2n2^n variables initialized in the previous step,
    with the index variable i=i0i1in1i = i_0 i_1 \dots i_{n-1} being the input variables.
    LOOKUPn(x0,,x2n1,i0,,in1)LOOKUP_n(x_0,\dots,x_{2^n-1},i_0,\cdots,i_{n-1})
    This requires at most 42n4\cdot 2^n lines of code by Theorem 4.10.

y=y0ym1{0,1}my = y_0 \dots y_{m-1} \in \{0,1\}^m
l[m]={0,1,,m1}l \in [m] = \{0, 1, \dots, m-1\}
total number of lines for computing one bit yl{0,1}y_l \in \{0,1\}
(3+2n)+(42n)=3+52n\leq (3+2^n) + (4\cdot 2^n) = 3 + 5 \cdot 2^n

Repeat the computation of one bit yl{0,1}y_l \in \{0,1\} for m times.
Then, we can get y=y0ym1{0,1}my = y_0 \dots y_{m-1} \in \{0,1\}^m

\therefore the total number of lines for computing function m(3+52n)\leq m \cdot (3 + 5 \cdot 2^n)

This completes the proof.

profile
dreams of chronic and sustained passion

0개의 댓글