CS3102 Theory of Computation - - PowerPoint PPT Presentation

cs3102 theory of
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 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?

slide-2
SLIDE 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

slide-3
SLIDE 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

slide-4
SLIDE 4

Majority with Boolean Circuits

4

x[0] x[1] x[2]

# Gates = # Lines

slide-5
SLIDE 5

NAND Straightline = AON Straightline

NAND -> AON x = NAND(a,b)

Becomes

temp = AND(a,b) x = NOT(temp) AON -> NAND

x = NOT(a)

Becomes

x= NAND(a,a) x = AND(a,b)

Becomes

temp= NAND(a,b) x=NAND(temp,temp)

5

x = OR(a,b)​

Becomes​

t1 = NAND(a,a) t2 = NAND(b,b) x= NAND(t1,t2)

slide-6
SLIDE 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

slide-7
SLIDE 7

User-Defined Procedures

7

slide-8
SLIDE 8

"Translating" Procedures

  • Adding procedures does not change

computing model

  • We can convert a program with procedures

into a program without them

8

slide-9
SLIDE 9

Procedure for translating procedures

  • Paste code from procedure
  • Use arguments in place of parameters
  • Rename variables from the procedure to be "fresh"

9

Before After

slide-10
SLIDE 10

How many gates?

  • How many NAND gates does this use to

compute MAJ?

10

slide-11
SLIDE 11

Conditionals

  • Values of some variables might depend on a

condition

  • Code
  • Translated

11

slide-12
SLIDE 12

Translating Conditionals

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

12

slide-13
SLIDE 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

slide-14
SLIDE 14

𝑀𝑃𝑃𝐿𝑉𝑄𝑙

14

1 1 1 1 𝑙 = 3 1 First 2𝑙 bits of input Considered as a bitstring Last 𝑙 bits of input Considered as an index

x: i:

slide-15
SLIDE 15

Theorem

15

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

slide-16
SLIDE 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

16

1 1 1 1 1

𝑦: 𝑗: 𝑦: 𝑗:

1 1

slide-17
SLIDE 17

Defining 𝑀𝑃𝑃𝐿𝑉𝑄𝑙

17

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)

slide-18
SLIDE 18

Base Case

18

Next Step

slide-19
SLIDE 19

LOOKUP2

19

LOOKUP3 and 4

slide-20
SLIDE 20

Counting Gates

20

Show this uses at most 4 ⋅ 2𝑙 gates (lines of code)

slide-21
SLIDE 21

Counting Gates

21

Show this uses at most 4 ⋅ 2𝑙 gates (lines of code)

slide-22
SLIDE 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

slide-23
SLIDE 23

Idea

23

Input Output 000 001 010 1 011 100 1 101 1 110 111

We will have one variable to represent each possible input. We'll do a lookup with the actual input to select the proper output

slide-24
SLIDE 24

Straightline Code for F

24

Input Output 000 001 010 1 011 100 1 101 1 110 111

slide-25
SLIDE 25

Getting 0 and 1

25

slide-26
SLIDE 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

slide-27
SLIDE 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 Note: This can be imporved to 𝑑 ⋅ 𝑛 ⋅

2𝑜 𝑜 (theorem

4.16 in TCS)

27

slide-28
SLIDE 28

Counting gates

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

28

slide-29
SLIDE 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