cs3102 theory of
play

CS3102 Theory of Computation - PowerPoint PPT Presentation

CS3102 Theory of Computation www.cs.virginia.edu/~njb2b/cstheory/s2020 Warm up: What features present in Java/Python are missing from straightline programs? Logistics Exercise 1 due this afternoon Didnt submit? You have 48 hours to


  1. CS3102 Theory of Computation www.cs.virginia.edu/~njb2b/cstheory/s2020 Warm up: What features present in Java/Python are missing from straightline programs?

  2. Logistics • Exercise 1 due this afternoon – Didn’t submit? You have 48 hours to do so with a 25% penalty • Quiz 2 due today • Exercise 2 is out. – Some stuff due Thursday, the rest due Tuesday 2

  3. Last Time • Boolean Circuits as a model of computing • Straightline Programs as a model of computing • Proved NAND-Straightline = NAND-Circ = AON-Circ = AON-straightline 3

  4. Majority with Boolean Circuits # Gates = # Lines x[0] x[1] x[2] 4

  5. NAND Straightline = AON Straightline NAND -> AON AON -> NAND ​ x = NOT(a) x = NAND(a,b) x = OR(a,b )​ Becomes Becomes Becomes ​ x= NAND(a,a) temp = AND(a,b) t1 = NAND(a,a) x = NOT(temp) t2 = NAND(b,b) x = AND(a,b) x= NAND(t1,t2) Becomes temp= NAND(a,b) x=NAND(temp,temp) 5

  6. Syntactic Sugar • "Full-featured" programming languages are identical to simple ones • We can add new features without changing the underlying computing model • These features can make programs easier to reason about and more readable 6

  7. User-Defined Procedures 7

  8. "Translating" Procedures • Adding procedures does not change computing model • We can convert a program with procedures into a program without them 8

  9. Procedure for translating procedures • Paste code from procedure • Use arguments in place of parameters • Rename variables from the procedure to be "fresh" Before After 9

  10. How many gates? • How many NAND gates does this use to compute MAJ? 10

  11. Conditionals • Values of some variables might depend on a condition • Code • Translated 11

  12. Translating Conditionals • Pre-compute each of the possible values • Use a procedure to determine which to assign 12

  13. Lookup • Indexing into a bitstring • The 𝑀𝑝𝑝𝑙𝑣𝑞 function of order 𝑙 : 𝑀𝑃𝑃𝐿𝑉𝑄 𝑙 : 0,1 2 𝑙 +𝑙 → 0,1 Defined such that for 𝑦 ∈ 0,1 2 𝑙 , 𝑗 ∈ 0,1 𝑙 : 𝑀𝑃𝑃𝐿𝑉𝑄 𝑙 𝑦, 𝑗 = 𝑦 𝑗 13

  14. 𝑀𝑃𝑃𝐿𝑉𝑄 𝑙 𝑙 = 3 i : x : 0 1 0 0 1 1 1 0 0 1 0 Last 𝑙 bits of input First 2 𝑙 bits of input Considered as an index Considered as a bitstring 14

  15. Theorem There is a NAND-Cricuit that computes 𝑀𝑃𝑃𝐿𝑉𝑄 𝑙 : 0,1 2 𝑙 +𝑙 → {0,1} Moreover, the number of gates required is at most 4 ⋅ 2 𝑙 15

  16. Proof idea • Consider index 𝑗 • If the first bit of 𝑗 is 0, then the bit we're looking for is in the first half of 𝑦 • Do lookup for 𝑙 − 1 𝑗 : 𝑦 : 0 1 0 0 1 1 1 0 0 1 0 𝑗 : 𝑦 : 0 1 0 0 1 0 16

  17. Defining 𝑀𝑃𝑃𝐿𝑉𝑄 𝑙 For 𝑙 ≥ 2, 𝑀𝑃𝑃𝐿𝑉𝑄 𝑙 (𝑦 0 , … , 𝑦 2 𝑙 −1 , 𝑗 0 , … , 𝑗 𝑙−1 ) is equal to: 𝐽𝐺(𝑗 0 , 𝑀𝑃𝑃𝐿𝑉𝑄 𝑙−1 𝑦 2 𝑙−1 , … , 𝑦 2 𝑙 −1 , 𝑗 1 , … , 𝑗 𝑙−1 , 𝑀𝑃𝑃𝐿𝑉𝑄 𝑙−1 (𝑦 0 , … , 𝑦 2 𝑙−1 −1 , 𝑗 1 , … , 𝑗 𝑙−1 ) 17

  18. Base Case Next Step 18

  19. LOOKUP2 LOOKUP3 and 4 19

  20. Counting Gates Show this uses at most 4 ⋅ 2 𝑙 gates (lines of code) 20

  21. Counting Gates Show this uses at most 4 ⋅ 2 𝑙 gates (lines of code) 21

  22. Computing Every Finite Function • Next we'll show that NAND is universal • Any finite function can be computed by some NAND-straightline program (equivalently, a NAND-circuit) 22

  23. Idea Input Output We will have one variable to represent each 000 0 possible input. We'll do a lookup with the 001 0 actual input to select the proper output 010 1 011 0 100 1 101 1 110 0 111 0 23

  24. Straightline Code for F Input Output 000 0 001 0 010 1 011 0 100 1 101 1 110 0 111 0 24

  25. Getting 0 and 1 25

  26. Computing any function • Make a variable to represent each possible input • Assign its value to match the correct output • Use LOOKUP to select the proper output for the given input 26

  27. How many gates? • How many gates does this construction take? You can compute any finite function 𝑔: 0,1 𝑜 → 0,1 𝑛 with a NAND Circuit using no more than 𝑑 ⋅ 𝑛 ⋅ 2 𝑜 gates 2 𝑜 Note: This can be imporved to 𝑑 ⋅ 𝑛 ⋅ 𝑜 (theorem 4.16 in TCS) 27

  28. Counting gates 1. Create variables for each input 2. Assign 0,1 to each input 3. Do the LOOKUP 28

  29. What does this mean? • Your laptop is a 64-bit machine. Given enough transistors, it can compute any function 𝑔: 0,1 64 → 0,1 64 29

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend