CS 420/520 - Theory of Computation

Spring 2019


Note: Do not under any circumstances leave your home directory world and/or group accessible in such a manner that others can view your assignment work.

Skip to the latest assignments

  1. Quiz 1

    • Sispser chapter 0 - all Exercises at end of the chapter; Problem 0.11
    • Induction proofs for formulae - given a formula should be able to give a correct proof by induction.
    • Proof by contradiction - give a statement and a good enough hint, should be able to give a correct proof.

    Note - quiz is in the in-class code.

    Taken: in class 17-Jan-2019 / 5 pts
  2. HW 2
    Turned in on paper (printout, or write it out). You may consult the internet for help; if you use anything make a note of it on your assignement. You may discuss with others; if you get any useful advice/hint, make a not of it on your assignment.

    1. (1 pt) My office - come visit me in my office before Tuesday's class. You get points just for doing that.
    2. (1 pt) Other people in the class - talk to at least two other people in the class, and write down their name, ISU email address, and what they'd prefer to do after finishing at ISU (i.e., what kind of job, or graduate school).
    3. (2 pts) Prove by contradiction - for every prime p, the cube root of p is irrational. Note - in general, any k-th root of a prime p is irrational.
    4. (2 pts) Prove by induction - For all integers k > 0, 1*1! + 2*2! + ... k*k! = (k+1)! - 1.
    5. (1 pt) Write a DFA for the language: strings of a's and b's where the number of b's is a multiple of 3. Strings in the language: aa, abababaaaa, bbab, bbbbbb. Strings not in the language: aaab, bba, babbaba.
    6. (1 pt) Write a DFA for the language: strings of a's and b's where there are never 2 a's in a row. Strings in the language: bb, abba, bababbbb. Strings not in the language: aa, baa, aab, bababaa.
    7. (1 pt) Write a DFA for the language: binary numbers that are not powers of 2. Note that a binary number is a power of two if it has exactly a single 1 and the rest 0's. Strings in the language: 110, 101, 10001000. Strings not in the language: 1, 10, 100, 100000.

    Grading notes... For induction you need to state when you use the inductive hypothesis in your induction step... For DFAs and NFAs draw an arrow into the start state, and double-circle the accepting states... For DFAs and NFAs pay attention to boundary conditions (e.g., for #4 having 0 b's).

    Due: 22-Jan-2019 (at start of class) / 9 pts

  3. Quiz 3

    • DFA, NFA, and RE constructions - no more difficult than the examples and exercises from Sipser.

    Note - quiz is in the in class code directory.

    In class: 29-Jan-2019 (at start of class) / 6 pts
  4. HW 4

    1. Give an NFA or DFA for L={strings of 0's and 1's that have an even # of 1's and contain at least one 1}. In L - 101, 110, 11, 0010001, 11011, 101010001. Not in L - 00, 0000, 10001, 1101.
    2. Give a DFA for L={strings of a's and b's that are either all a's, all b's, or a repetetion of ab }. In L - aaa, a, b, bbbb, ababab. Not in L - abb, bababa, bbbba.
    3. Give an RE for L={strings of a's, b's, c's, d's that contain at one of each letter }. In L - abcd, aabdcca, dccdddccbba. Not in L - abc, bdc, bbbddddccc, aaadcccddaa. Note - annoying one to do an RE for; not graded.
    4. Give an RE for L={strings of a's and b's that contain both aa and bb at some point in the string}. In L - aabb, abababaabababbababab, bbaaaa, babaabb. Not in L - ab, abb, bba, aab, aabababababab.
    5. Give an NFA or DFA for L={strings of 0's and 1's that does contain 000 and does not contain 111}.
    6. Give an RE for L={strings of digits that form a prime number between 1 and 30}.

    Due: 31-Jan-2019 (at the start of class) / 5 pts
  5. HW 5

    For the kattis problems your program should be judged as correct by the kattis website. For your filename, use the part of the web address after the last /

    For the other problems, the filename you need to use is mentioned in the problem.

    You handin your problems using the handin system on CS. You should be logged in with whatever account you want to use, and do the following to get started

    handin -C -c cs420 hw5
    When you are finished with the assignment, do
    handin -c cs420 hw5
    Note that the -C is for "checkout", and you should only do that once. If you do that after you have already worked on some files, it will overright them (that is bad!). The -c cs420 lets you work on the files for this class from whatever account you want. You can either be in your hw5 directory or one directory higher when you run the handin command to submit your files. You can run the handin command multiple times, and each time it will replace your previous submission.

    1. Hello World
    2. Sum Kind of Problem
    3. Permuted Arithmetic Sequence
    4. Bonus - Alphabet
    5. Python code for simulating DFA of 2.6, use filename dfa2.6.py
    6. Python code for simulating DFA of 4.2, use filename dfa4.2.py
    7. Python code for simulating NFA with 3 states that accepts {strings of 0's and 1's that end in 00}. Use filename nfa5.7.py
    8. Python code for simulating NFA with three states that accepts {strings of 0's and 1's of the form 1*(001*)*}. Use filename nfa5.8.py
    9. Python code for RE to match an html tag, should check if the <, >, / follow the rules. You are checking if the string is of the form
      <tagName>Something here ... </tagName>
      or not. If yes, you should output the tagName and also the "Something here ...". Don't use any loops in your code. If there are properties you should detect that and output those as well. So if
      <a href='hello.html'>hi there</a>
      then you would output "href='hello.html'" as the properties. Use filename re5.9.py
    10. Python code for RE to match a phone number and output the country code, area code, etc. You should be able to handle numbers like: 237-0000, 812-237-0000, +1-812-237-0000. Don't worry about numbers like (812) 237-0000, and you can use \d+ for the digit groups (don't care how digits in each group). Assume there are at most 4 - characters, and don't use any loops in your code. Note - a few strings that should NOT be accepted as valid: 1-2-3-4-5-6, 234-a234, -234-887. Strings that are okay to accept as valid (to make your life easier): +12, + Use filename re5.10.py

    Grading notes... Each problem was graded as 0, 1, or 1/2. I don't know why I said the total would be out of 8; I should have said 8. But counting it out of 8 anyway. You should have a hw5-grade.txt summarizing what you got right/wrong; that file is in the home directory of whatever account you used to turn in the assignment. If you didn't turn anything on time, you have a 0 for this one. Some test files for some of the problems are in the code directory. Look at the .txt files there. For your hw5-grades.txt, sometimes I just mentioned one of the test cases your solution was wrong for.

    Due: 12-Feb-2019 (AOE) / 8 pts
  6. Quiz 6

    • Given description of a language, either (a) give a DFA, NFA, or RE for the language, or (b) prove it is not regular.
    • Given the transition function (table) of a DFA/NFA, draw the picture. And given the picture, write the transition function/table.
    • Convert between DFA, NFA, RE.
    • Python RE for valid math expression involving integers, +, *, -, / (use \\d for a digit)
    • Python RE for valid variable name, with rules - must start with letter, contains only letters/digits/_ (use \\w for digit-or-letter, [a-zA-Z] for letter)
    • Sipser problems: 1.31, 1.38, 1.41, 1.46, 1.64a
    • Note - quiz is in the code directory.

    Grading notes... #3 from the quiz is extra credit. You have to be very precise in your proofs; don't ever write down something that doesn't follow from your assumptions; you need to write your proofs so that someone who is not in our class can follow it (you need to actually write down "Suppose L is regular. Then the pumping lemma..."); you have to consider all possible things that can happen in your proof (e.g, you can't assume |xy| = p when you're applying the pumping lemma). You have to think through different types of input to try to "break" your RE/DFA/NFA to make sure it handles all the cases. For Python3 RE's remember to use ^ and $ - I didn't take off for missing these this time, but will from now on.

    Taken: in class 14-Feb-2019 / 4 pts

  7. Quiz 7 / Exam 1
    • Content - chapters 0 and 1 of Sipser, all HW's and Quiz's up until now
    • Extra practice - problems from Sipser - chapter 1 exercises (not problems) that have solutions, problems 1.31, 1.36
    • Honors problems -
      1. Sipser problems - 1.37, 1.39, 1.40, 1.43, 1.55, 1.70. Hints/notes... 1.37 - do it first for n=3, have current state keep track of value % n for binary # read in so far. 1.39 - proof could be similar to that of the pumping lemma.

    Taken: in class 21-Feb-2019 / (20 quiz points, and exam 1)

  8. HW 8 - CF's
    1. Give a CFG for the language L = {strings of a's and b's that do NOT contain both aa and bb as substrings}. Note - what I meant was - doesn't contain either aa or bb (so aa is not in the language). I will also accept solutions that have - doesn't contain both (so aa or bb is in the language, but not aabb). For my version of the language: yes - abab, baba, b, a, ba, aba; no - aa, bb, aabb, abb, baa, bababaa.
    2. Give a PDA for the language L = {an bm ak | n+m >= k}. In the language - aaabbaaaaa, aab, abaa, aaa, abbaa. Not in the language - abaaa, abbaaaa, bbaaa.
    3. Give a CFG for the language L = {strings of a's and b's that contain a palindrome of length at least 3}. In the language - aba, baab, aaa, bbabb, baaa, ababb. Not in the language - a, b, aa, bb, ba, bbaa.
    4. Give a PDA for the language from the last problem.
    5. Honor's problems - Sipser 2.15, 2.17, 2.19, 2.27, 2.29, 2.57

    Grading notes... For 2, most people didn't have the correct accept states - make sure to pay attention to that. For 3, some of you had "infinite" strings only (rules always had a variable on the RHS). For 3 and 4, many just did palindromes without taking into account lengths 3 and 4.

    Due: 7-Mar-2019 (at the start of class) / (4 HW points)

  9. HW 9 - CF's
    1. Give a CFG for the language L = {strings of a's, b's, c's that contain at least one of each letter }. In the language - abc, baababababc, caacacacb, cab, cba, aaabbbbc. Not in the language - ababa, babab, cacac, cccbbb, cccc, bbb, aaa.
    2. Give a CFG for the language of HW8.2.
    3. Give a CFG for the language L = {valid RPN expressions of integers that leave a single number on the stack}. Note that the alphabet is: +, -, *, /, digits, space. Use \d for any digit and \s for any whitespace. And your CFG should allow negative numbers. Valid RPN expressions: 4 5 +, 3 2 5 * /, 3 2 * 5 6 - 23 / *. Invalid RPN expressions: 4 5, 4 5 4 *, 4 * 4, *.
    4. Give a PDA for the language from the last problem.
    5. Sipser 2.19 - give the description, not the CFG for compl(L).
    6. Sipser 2.25. Note - not sure about this one...
    7. Show that the following is not CF. L = {wwRw | w is a string of a's and b's}

    Grading: #5 and #6 not graded, so total is out of 5 points.

    Due: 12-Mar-2019 (at the start of class) / (5 HW points)

  10. Quiz 10 - CF's
    • Content is HW's on CF's so far and exercises from chapter 2 in Sipser (except 2.11 and 2.12).
    • Given language show it is CF or not CF.
    • Given PDA or CFG, explain what the language is.
    • Answer other basic questions about PDAs and CFGs.

    Taken: in class 14-Mar-2019 / (4 quiz points)

  11. HW 11 - quiz 10
    • Come up with correct answers for the quiz10 problems. quiz10.docx is in the code directory.

    Due: 19-Mar-2019 (at the start of class) / (4 HW points)

  12. HW 12 - SLY
    1. Checkout the hw12 assignment using handin (see instructions from hw5).
    2. In sly-calc.py, add the following comparison operations and have them do the same thing as what they do in Python: != <= < >= >

      Note - you should not get any shift-reduce warnings when you run your sly-calc. You will need to put the new operations into the precedence variable. Use the same precedence as python3.

    3. In sly-calc.py, add the following bitwise operations and have them do the same thing as what they do in Python: & | ~ ^ << >>
    4. In sly-calc.py, add a command "ls" that prints the values of all variables.

    Note - I will test your programs by piping input command files into your program and verifying that your program gives correct results. A few examples are in the code directory names hw12-testX.txt. You can run these tests by doing
    python3 sly-calc.py < ~jkinne/public_html/cs420-s2019/code/hw12-test1.txt

    Grading notes, things people did wrong - did not have << and >> defined in the lexer before < and >, mixed up << and >>, forgot to do one or more of the operations.

    Grading notes - if your program had a syntax error, 0 credit. Never turn something in that does not run.

    Due: 04-Apr-2019 AOE / (4 HW points)

  13. HW 13 - SLY 2
    1. TBD new language something in sly-calc2.py (possibly for or while loop)
    2. TBD writing a program to do something in our sly-calc.py language (possibly one of the easy earlier python programs)
    3. TBD starting a new slySOMETHING.py (possibly simple human language, Eliza-ish)
    4. TBD something else with new slySOMETHING.py

    Due: after exam 2 / (4 HW points)

  14. HW 14 - TM's
    1. Sipser exercises - 3.1a, 3.1b, and also input 0000, and input 00000
    2. Sipser exercise 3.7
    3. Give an informal description of a TM to accept the following language - {w1.w2.w3 | w1 has same # a’s as w2 and w2 has same # b’s as w3}
    4. Prove that the set of languages that are decidable by a single tape TM machine as described in the book remains the same if you modify the TM definition so that it also can keep it's tape head in the same position (so the options for the tape head are L, R, -).
    5. Prove that if there exist TM's M1 and M2 that decide languages L1 and L2, then there exists a TM M3 that decides the language L1 intersect L2.
    6. Honors problems - 3.9a, 3.11, 3.14

    To turn in the assignment, use handin on the server. Run handin --checkout --class cs420 hw14 to checkout the assignment, and handin --class cs420 hw14 to turn it in.

    Due: Apr 22 noon TH time / (5 HW points)

  15. Quiz 15 - TM's
    • Problems similar to HW 14, over chapter 3 content

    In class: Apr 23 / (4 Quiz points)

  16. HW 16 - quiz 15
    • Turn in correct answers for quiz 15. Quiz 15 is in the usual place. Turn in electronically with handin or before class on Thursday 4/25.

    Due: Apr 25 start of class / (4 HW points)

  17. HW 17 - undecidable problems / reductions - chapters 4, 5
    1. If the following is decidable, describe an algorithm to solve it. If it is not decidable, give a proof that it is not decidable (by reducing to an already known undecidable problem). L = {(M, x) | M is a TM that accepts x in at most n2 steps}
    2. If the following is decidable, describe an algorithm to solve it. If it is not decidable, give a proof that it is not decidable (by reducing to an already known undecidable problem). L = { (M) | M is a TM that accepts at least one string at each input length }
    3. If the following is decidable, describe an algorithm to solve it. If it is not decidable, give a proof that it is not decidable (by reducing to an already known undecidable problem). L = { (G, x) | G is a CFG and x is NOT a string generated by G }
    4. Pick a language that is undecidable that we have not looked at in class or on HW. Define the language, give examples of strings that are in the language and not in the language, and give a proof that the language is not decidable. Note - everyone needs to pick a different language, so you need to check with me on the language that you pick. Languages already selected - .
    5. Sipser (3rd edition) problem 5.30 - using Rice's Theorem to prove languages are undecidable.
    6. Honors problems - 4.11, 4.17, 4.21, 5.3, 5.12, 5.15

    Due: May 2 beginning of class / (5 HW points)

  18. Quiz 18 - reductions / decidability / sample-exam-ish
    • A few new questions - graded
    • Also, sample exam, things that weren't on exams 1-2 - FYI
    • Take home quiz, due to Jeff May 3 by 1pm.

    In class May 2 / (6 Quiz point)

Note: course website layout/code/template from Steve Baker. Anything horrible is not his fault.