CS3102 Theory of Computation Warm up: Is this function computable - - PowerPoint PPT Presentation

β–Ά
cs3102 theory of
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

CS3102 Theory of Computation

Warm up: Is this function computable with a NAND-Circuit? 𝑔 𝑏 = 1 if UVA wins against ND tonight 0 otherwise

slide-2
SLIDE 2

Logistics

  • Quiz 3 out

– Due Thursday

  • Exercise 3 is out

– Last exercise before midterm

2

slide-3
SLIDE 3

Last Time

  • Showing that NAND/AON can compute any

finite function

  • Started showing how we could have a

function that simulates programs

3

slide-4
SLIDE 4

How are programs run?

  • Have a table of variables
  • Execute code in sequence
  • Update values in table
  • Return a value from the table

4

slide-5
SLIDE 5

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)])

slide-6
SLIDE 6

XOR to bits

6

Variable Number π‘œ = 𝑛 = 𝑑 = Total bits =

slide-7
SLIDE 7

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 π‘œ + 𝑛]

slide-8
SLIDE 8

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

slide-9
SLIDE 9

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 𝑛

slide-10
SLIDE 10

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

slide-11
SLIDE 11

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

π‘ˆ

slide-12
SLIDE 12

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 𝑍

slide-13
SLIDE 13

EVAL in NAND

  • Next we implement πΉπ‘Šπ΅π‘€π‘‘,π‘œ,𝑛 using NAND

13

slide-14
SLIDE 14

π»πΉπ‘ˆ(π‘ˆ, 𝑗)

  • Get the bit at β€œrow” 𝑗 of π‘ˆ
  • Look familiar?
  • How many gates to implement?

14

slide-15
SLIDE 15

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β„“

slide-16
SLIDE 16

UPDATE pseudocode

For π‘˜ in range(2β„“): 𝑏 = 𝐹𝑅𝑉𝐡𝑀𝑇

π‘˜(𝑗)

π‘œπ‘“π‘₯π‘ˆ[π‘˜] = 𝐽𝐺(𝑏, 𝑐, π‘ˆ[π‘˜]) Return π‘œπ‘“π‘₯π‘ˆ

16

Runs 2β„“ times

slide-17
SLIDE 17

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

slide-18
SLIDE 18

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

slide-19
SLIDE 19

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

slide-20
SLIDE 20

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 𝑛

slide-21
SLIDE 21

Comparing Classes

21

If 𝑦 ≀ 𝑧, then π‘‡π½π‘ŽπΉ 𝑑 βŠ† π‘‡π½π‘ŽπΉ(𝑧)

slide-22
SLIDE 22

Theorem

  • Let π‘‡π½π‘ŽπΉπ΅π‘ƒπ‘‚ 𝑑 represent the set of all

functions that can be computed using at most 𝑑 AND/OR/NOT gates

22

π‘‡π½π‘ŽπΉ 𝑑 2 βŠ† π‘‡π½π‘ŽπΉπ΅π‘ƒπ‘‚ 𝑑 βŠ† π‘‡π½π‘ŽπΉ 3𝑑

slide-23
SLIDE 23

Proof

π‘‡π½π‘ŽπΉ 𝑑 2 βŠ† π‘‡π½π‘ŽπΉπ΅π‘ƒπ‘‚ 𝑑 βŠ† π‘‡π½π‘ŽπΉ 3𝑑

23

slide-24
SLIDE 24

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

slide-25
SLIDE 25

25

slide-26
SLIDE 26

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 π‘œ
  • Ξ© 𝑕 π‘œ

∩ 𝑃(𝑕 π‘œ )

slide-27
SLIDE 27

Showing Big-Oh

  • To show: π‘œ log π‘œ ∈ 𝑃 π‘œ2

27

slide-28
SLIDE 28

Showing Big-Omega

  • To Show: 2π‘œ ∈ Ξ© π‘œ2

28

slide-29
SLIDE 29

Showing Big-Theta

  • To Show: log𝑦 π‘œ = Θ log𝑧 π‘œ

29