## Name: ________Student ID: __ ___________

## CS181 Winter 2019 – Final

## Due Friday, March 15, 11:59 PM

*• *This exam is open-book and open-notes, but any materials not used in this course are prohibited, including any material found on the internet. ** Collaboration is prohibited. **Please avoid temptation by not working on the final while you are in the presence of any other student who has taken or is currently taking CS181.

**If you have any questions about the exam, ask the TA or Professor Sahai by email or after class.**

**Be extra careful if you live with or meet regularly with a student of this class.****You are allowed to use any theorem shown in class or in the textbook, as long as you clearly cite it. Please monitor Piazza for any clarifications.**

**Do not ask other students.****post any questions on piazza.**

**Do not***• *We suggest that you spend approximately 12 hours (not necessarily contiguous) to take this exam. Start early so that you have time to understand and think about the problems. **The solutions must be** submitted on Gradescope by 11:59 PM on Friday, March 15.

*• *Place your name and UID on every page of your solutions. Retain this cover sheet and the next sheet with the table as the first pages of your solutions. **Please use separate pages for each question.**

**All problems require clear and well-written explanations.**

*• *There are 4 questions worth a total of 230 points and an extra credit question worth 40 points.

*• *For each part (except for the extra credit), if you describe a non-trivial approach that you tried using to solve the problem but realized it doesn’t work and explain correctly why it doesn’t work and then write“I don’t know” you will get 20% points for that problem. You will ** not **get 20% points for just writing “I don’t know”. Whether your stated approach was indeed non-trivial is solely at the discretion of the grader.

### 1. Decidability/Recognizability (60 points)

### Height

For a Turing machine * M *, let height(

*) denote the length of the shortest string accepted by*

*M**(or*

*M**if*

*∞**does not accept any string). Consider the following language*

*M** L*

_{height}=

*height(*

*{(M ) |**)*

*M*

*< |(M )|},*that is the language of Turing machines that accept a string that is shorter than their own description.

**a) (15 points) **Show that

*L*_{height}is undecidable.

**b) (15 points) **Show that

*L*_{height}is recognizable.

*For all parts, remember to first write your intuition before writing your formal solution.*

### Trump Machine

A Turing machine * M *over alphabet Σ =

*0*

*{**1*

*,**$*

*,**and tape alphabet Γ =*

*}**0*

*{H,**1*

*,**$*

*,**is a Trump machine if for all*

*, #}**Σ*

*x ∈**such that*

^{∗}*contains at least 5*

*x**7 billion $ symbols, during the execution of*

*.**on input*

*M**,*

*x**erases all $ symbols from its tape (replaces them with blanks), writes a single wall symbol*

*M**, and then shuts down (either accepts or rejects).*

*#*Let

* L*

_{Trump}=

*is a Trump machine*

*{(M ) | M*

*}.***c) (15 points) **Show that

*L*_{Trump}is undecidable.

**d) (15 points) **Show that

*L*_{Trump}is unrecognizable.

*For all parts, remember to first write your intuition before writing your formal solution.*

### 2. Inconclusive Decider (40 points)

An Inconclusive Decider is like a decider except that on some set of inputs, instead of accepting or reject- ing, it may instead halt and output “INCONCLUSIVE”.

Formally, we say that a language * L *is

*-Inconclusive-Decidable for some*

*k**N*

*k ∈**if there exists a Turing machine*

*∪ {∞}**such that*

*M**• *For all * x *such that

*,*

*x ∈ L**either halts and outputs “ACCEPT” or halts and outputs “INCONCLUSIVE”.*

*M**• *For all * x *such that

*,*

*x ∈/ L**either halts and outputs “REJECT” or halts and outputs “INCONCLUSIVE”.*

*M**• M *halts and outputs “INCONCLUSIVE” on at most

*distinct inputs*

*k**.*

*x*(Note that L is decidable if and only if it is 0-Inconclusive-Decidable)

**a) (5 points) **Show that all languages are

*-Inconclusive-Decidable.*

*∞***b) (20 points) **Show that

*L*_{Halt}

*=*

*ε**(*

*{(M ) | M**) halts*

*ε**is*

*}***1-Inconclusive-Decidable.**

**not****c) (15 points) **Show that

*L*_{Halt}

*=*

*ε**(*

*{(M ) | M**) halts*

*ε**is*

*}***2-Inconclusive-Decidable.**

**not***For all parts, remember to first write your intuition before writing your formal solution.*

### 3. Perpetual Machines (70 points)

An perpetual machine * P *is like a Turing machine, except that it never halts on any input. Instead of containing accept and reject states,

*and*

*q*_{accept}*, it contains a non-halting accepting state*

*q*_{reject}*. When*

*q*^{∗}*enters*

*P**, instead of terminating its computation, it continues executing and can transition out of this state.*

*q*^{∗}A perpetual machine * P *computes a language

*if*

*L**• *For all * x ∈ L*,

*(*

*P**) enters*

*x**an infinite number of times*

*q*^{∗}*• *For all * x ƒ∈ L*,

*(*

*P**) does not enter*

*x**an infinite number of times*

*q*^{∗}If there does not exist any perpetual machine * P *that computes a language

*, we say that*

*L**is uncom- putable by perpetual machines.*

*L***a) (25 points) **Show that the language

* L*

_{loop}=

*is a Turing machine and*

*{(M ) | M**(*

*M**) loops*

*ε*

*}*is computable by perpetual machines.

**b) (20 points) **Construct a language

*Σ*

*L ⊆**that is uncomputable by perpetual machines and prove that this is the case.*

^{∗}

*(Hint: Use diagonalization)***c) (25 points) **Show that the language

* L*

_{Empty}=

*is a Turing machine and*

*{(M ) | M**(*

*L**) =*

*M*

*∅}*is computable by perpetual machines.

**d) (Extra Credit, 40 points) **Show that the language

*L*_{EQ} = * {*(

*(M*_{1}

*), (M*_{2}

*)*

*)*

*| M*_{1}and

*M*_{2}are Turing machines and

*(*

*L*

*M*_{1}) =

*(*

*L*

*M*_{2})

*}*is computable by perpetual machines.

*For all parts, remember to first write your intuition before writing your formal solution.*

### 4. Card Shuffling (60 points)

Let * C *= (

*) be a card-shuffling game, described by a natural number*

*N, R**and a set of allowed card- shuffling rules*

*N**. We introduce some notation and define the game below.*

*R**• *Normal Deck: A deck of * N *cards labeled (1

*2*

*,**3*

*,**).*

*, …, N**• *Ace Deck: A normal deck but with the first card replaced by an Ace. In other words, a deck of * N *cards labeled (

*2*

*A,**3*

*,**).*

*, …, N**• *Shuffling Rule: A shuffling rule specifies an allowed shuffle (permutation) of any finite number of cards. In particular, each rule is a tuple (* {A, *1

*2*

*,**1*

*, …, N }k, {A,**2*

*,**), where the left side of the tuple specifies the card sequence that can be shuffled with this rule, and the right side of the tuple specifies the new card sequence after the shuffle. For example, ((2*

*, …, N }k**7*

*,**4*

*,**1)*

*,**(1*

*,**2*

*,**4*

*,**7)) means that if we see cards labeled 2*

*,**7*

*,**4*

*,**1 next to each other in this order, then we can shuffle/rearrange them to be in the new order of 1*

*,**2*

*,**4*

*,**7.*

*,**is the set of allowed shuffling rules and is a subset of the set of all possible shuffles.*

*R**• *Game Setup: In a row, we place face-up the cards of an Ace deck in order and then place face-up the cards of a normal deck in order.

*• *Gameplay: Each turn, we may do one of the following:

**– **Add a normal deck: Place face-up the cards of a normal deck in order to the right of all cards currently placed.

**– **Perform a shuffle: Choose any number of consecutive cards and shuffle them according to some allowed shuffle rule in * R*. In other words, choose any number of consecutive cards that are in the order specified in the left hand side of some rule in

*, and then reorder them to be in the order specified by the right hand side of the same rule.*

*R**• *Win Condition: You win if you can get a card labeled * N *into the leftmost card position by playing this game. You can use as many turns as you want. (See example on next page.)

Let * L *=

*= (*

*{C**)*

*N, R**It is possible to win game*

*|**. Prove that*

*C}**is undecidable.*

*L**Hint: Consider shuffles of 2N or 3N cards.*

You may assume that every TM can be converted into an equivalent TM that will never try to move left on the leftmost tape position, and if this new TM halts, it always halts when the head is at the leftmost tape position.

*Remember to first write your intuition before writing your formal solution.*

### Example:

Let * C *=

*3*

*{**((*

*, {**2*

*A,**3*

*,**1*

*,**2*

*,**3)*

*,**(*

*,**2*

*A,**3*

*,**2*

*,**1*

*,**3))*

*,**((2*

*,**1*

*,**3*

*,**1*

*,**2*

*,**3)*

*,**(3*

*,**2*

*,**1*

*,**3*

*,**2*

*,**1))*

*,**((*

*,**2*

*A,**3*

*,**3*

*,**2*

*,**1)*

*,**(3*

*,**2*

*,**1*

*,**3*

*,**2*

*,**))*

*, A**.Then, you can win game C after four turns.*

*}*