CS3102 Theory of Computation Warm up: Is this function computable with a NAND-Circuit? π π = 1 if UVA wins against ND tonight 0 otherwise
Logistics β’ Quiz 3 out β Due Thursday β’ Exercise 3 is out β Last exercise before midterm 2
Last Time β’ Showing that NAND/AON can compute any finite function β’ Started showing how we could have a function that simulates programs 3
How are programs run? β’ Have a table of variables β’ Execute code in sequence β’ Update values in table β’ Return a value from the table 4
Programs as Bits β’ To evaluate a program with another program, we need to convert the first program into bits 1. Number each variable (first n go to input, last m to outputs) 2. Represent each line as 3 numbers (outvar, in1, in2) 3. Represent program as (n,m,[Lines]) Variable Number a 0 (2,0,0) b 1 (3,1,1) temp1 2 (4,2,3) temp2 3 (2,1,[(2,0,0),(3,1,1),(4,2,3)]) return 4 5
XOR to bits Variable Number π = π = π‘ = Total bits = 6
XOR to bits Variable Number a 0 b 1 u 2 π = 2 v 3 π = 1 w 4 π‘ = 4 return 5 Total bits = 3 [numbers per line] β 3 [bits per number] β 4[lines] + 6 [length of π + π ] 7
How big is this? 1. Number each variable βlog 2 3π‘β bits each 2. Represent each line as 3 numbers (outvar, in1, in2) 3π‘ β βlog 2 3π‘β bits 3. Represent program as (n,m,[Lines]) 2βlog 2 π‘β bits π π‘ β€ 4π‘βlog 2 3π‘β β = βlog 2 3π‘β 8
Defining EVAL πΉππ΅π π‘,π,π : 0,1 π π‘ +π β 0,1 π Input: bit string representing a program (first π(π‘) bits) plus input values (remaining π bits) Output: the result of running the represented program on the provided input, or π 0's if there's a "compile error" 9
π = 2 Defining the EVAL function π = 1 Variable Value Representation: 0 (2, 0, 1), (3, 0, 2), (4, 1, 2), 1 (5, 3, 4) 2 Input: 0, 1 3 4 5 10
Psuedocode for EVAL π β’ Table π : β holds variables and their values β’ π»πΉπ(π, π) β Returns the bit of π associated with variable π β’ πππΈπ΅ππΉ(π, π, π) β Returns a new table such that variable π 's value has been changed to π 11
Psuedocode for EVAL β’ Input: Let π be table of size π’ Numbers π , π , π‘ , π’ For π in range( π ): β representing the number of π = UPDATE( π , π , π¦[π] ) inputs, outputs, variables, For ( π , π , π ) in π : and lines respectively π = GET( π , π ) π , a list of triples β π = GET( π , π ) representing the program π = UPDATE( π , π , NAND( π , π )) A string π¦ to be given as input β For π in range( π ): to the program π [ π ] = GET( π , π’ β π + π ) β’ Output: Return π β Evaluation of the program represented by π when run on input π¦ 12
EVAL in NAND β’ Next we implement πΉππ΅π π‘,π,π using NAND 13
π»πΉπ(π, π) β’ Get the bit at βrowβ π of π β’ Look familiar? β’ How many gates to implement? 14
UPDATE πππΈπ΅ππΉ β : 0,1 π‘ β +β+1 β 0,1 2 β β’ To change index π of table π to bit π β’ For every index except π , return the same value β’ For index π , return b instead β’ Define πΉπ ππ΅π π : 0,1 β β {0,1} which returns 1 if the input binary number is equal to j Note: πΉπ ππ΅π π can be done in π β β gates 15
UPDATE pseudocode For π in range( 2 β ): π = πΉπ ππ΅ππ π (π) Runs 2 β times πππ₯π[π ] = π½πΊ(π, π, π[π]) Return πππ₯π 16
Conclusion β’ What we know: β We can compute any finite function with circuits β We can compute a function to evaluate programs of a certain size β’ Big question: β How expensive are functions? β Some are more expensive than others, how big could they get? β If I wanted to be able to evaluate a program for any function 0,1 π β {0,1} , how big would the eval circuit need to be? 17
Complexity β’ The "complexity" of a function: β Measure of the resources required to compute that function β’ Complexity Class: β A set of functions defined by a complexity measure 18
Categorizing Functions by Circuit Size β’ No functions require more than ππ2 π gates β Proved last class β’ Some functions require much less β E.g. IF β’ Observation: some functions are more "complicated" than others! β’ Idea: categorize functions by resources required to implement them using a particular computing model 19
SIZE β’ ππ½ππΉ(π‘) : The set of all functions that can be implemented by a circuit of at most s NAND gates ππ½ππΉ(1000π2 π ) Contains all functions π: 0,1 π β 0,1 π β’ TCS also uses: β ππ½ππΉ π,π π‘ :The set of all π -input, π -output functions that can be implemented with at most π‘ NAND gates β ππ½ππΉ π π‘ : The set of all π -input, 1 -output functions that can be implemented with at most π‘ NAND gates 20
Comparing Classes If π¦ β€ π§ , then ππ½ππΉ π‘ β ππ½ππΉ(π§) 21
Theorem β’ Let ππ½ππΉ π΅ππ π‘ represent the set of all functions that can be computed using at most π‘ AND/OR/NOT gates ππ½ππΉ π‘ 2 β ππ½ππΉ π΅ππ π‘ β ππ½ππΉ 3π‘ 22
Proof ππ½ππΉ π‘ 2 β ππ½ππΉ π΅ππ π‘ β ππ½ππΉ 3π‘ 23
O, Ξ©, Ξ β’ Groups functions together β’ Each uses a function as a bound for other functions β’ O (Big-Oh): β O(f(n)) = the set of all functions "asymptotically upper-bounded" by f β’ Ξ© (Big -Omega): β Ξ©(f(n)) = the set of all functions "asymptotically lower-bounded" by f β’ Ξ (Big -Theta): β Ξ(f(n)) = the set of all functions "asymptotically tight -bounded" by f 24
25
Definitions β’ π(π π ) β’ At most within constant of π for large π β’ {π: β β β|β constants π, π 0 > 0 s.t. βπ > π 0 , π π β€ π β π(π)} β’ Ξ©(π π ) β’ At least within constant of π for large π β’ {π: β β β|β constants π, π 0 > 0 s.t. βπ > π 0 , π π β₯ π β π(π)} β’ Ξ π π β’ β Tightly β within constant of π for large π β’ Ξ© π π β© π(π π ) 26
Showing Big-Oh β’ To show: π log π β π π 2 27
Showing Big-Omega β’ To Show: 2 π β Ξ© π 2 28
Showing Big-Theta β’ To Show: log π¦ π = Ξ log π§ π 29
Recommend
More recommend