CS3102 Theory of Computation Warm up: Is this function computable - - PowerPoint PPT Presentation
CS3102 Theory of Computation Warm up: Is this function computable - - PowerPoint PPT Presentation
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
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])
5
Variable Number a b 1 temp1 2 temp2 3 return 4 (2,0,0) (3,1,1) (4,2,3) (2,1,[(2,0,0),(3,1,1),(4,2,3)])
XOR to bits
6
Variable Number π = π = π‘ = Total bits =
XOR to bits
7
Variable Number a b 1 u 2 v 3 w 4 return 5 π = 2 π = 1 π‘ = 4 Total bits = 3 [numbers per line] β 3 [bits per number] β 4[lines] + 6 [length of π + π]
How big is this?
1. Number each variable 2. Represent each line as 3 numbers (outvar, in1, in2) 3. Represent program as (n,m,[Lines])
8
βlog2 3π‘β bits each
π π‘ β€ 4π‘βlog2 3π‘β β = βlog2 3π‘β
3π‘ β βlog2 3π‘β bits 2βlog2 π‘β bits
Defining EVAL
9
Input: bit string representing a program (first π(π‘) bits) plus input values (remaining π bits) Output: the result of running the represented program
- n the provided input, or π 0's if there's a "compile
error"
πΉππ΅ππ‘,π,π: 0,1 π π‘ +π β 0,1 π
Defining the EVAL function
10
Variable Value 1 2 3 4 5 Representation: (2, 0, 1), (3, 0, 2), (4, 1, 2), (5, 3, 4) Input: 0, 1
π = 2 π = 1
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:
β Numbers π, π, π‘, π’ representing the number of inputs, outputs, variables, and lines respectively β π, a list of triples representing the program β A string π¦ to be given as input to the program
- Output:
β Evaluation of the program represented by π when run
- n input π¦
12
Let π be table of size π’ For π in range(π): π = UPDATE(π, π, π¦[π]) For (π,π,π) in π: π = GET(π, π) π = GET(π, π) π = UPDATE(π, π, NAND(π,π)) For π in range(π): π[π] = GET(π, π’ β π + π) Return π
EVAL in NAND
- Next we implement πΉππ΅ππ‘,π,π using NAND
13
π»πΉπ(π, π)
- Get the bit at βrowβ π of π
- Look familiar?
- How many gates to implement?
14
UPDATE
15
- 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 πππΈπ΅ππΉβ: 0,1 π‘β+β+1 β 0,1 2β
UPDATE pseudocode
For π in range(2β): π = πΉπ ππ΅ππ
π(π)
πππ₯π[π] = π½πΊ(π, π, π[π]) Return πππ₯π
16
Runs 2β times
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
- 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
ππ½ππΉ(1000π2π) Contains all functions π: 0,1 π β 0,1 π
Comparing Classes
21
If π¦ β€ π§, then ππ½ππΉ π‘ β ππ½ππΉ(π§)
Theorem
- Let ππ½ππΉπ΅ππ π‘ represent the set of all
functions that can be computed using at most π‘ AND/OR/NOT gates
22
ππ½ππΉ π‘ 2 β ππ½ππΉπ΅ππ π‘ β ππ½ππΉ 3π‘
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
26
- π(π π )
- 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 π
- Ξ© π π
β© π(π π )
Showing Big-Oh
- To show: π log π β π π2
27
Showing Big-Omega
- To Show: 2π β Ξ© π2
28
Showing Big-Theta
- To Show: logπ¦ π = Ξ logπ§ π
29