15-251: Great Theoretical Ideas In Computer Science Recitation 2 Solutions Announcements • Be sure to start early on homeworks! It will be a smoother experience for all involved (less crowded office hours are better for you and us!) • Please practice writing up your solutions beforehand. It will help with: – Structuring your proof on the page in an organized way. – Writing neatly (minimizing erasing/crossing out with practice). – Ensuring your solution is correct (often bugs pop up while writing). • If you aren’t sure about a piece of feedback or why you got a particular score on a problem, please ask us! The TAs initialed which problems they graded, so go to the correct TA if you are at all unsure. We’re here to help! • If you have any questions about the course overall, not restricted to homework, please ask! Again, we want to help you however we can! • Reminder: Make sure that you’re familiar with the collaboration policies on the website. The homework writing sessions and open collaboration problems are very different from many classes, so just make sure you’re clear on the specifics. A Natural System Consider First Order Logic together with the following vocabulary: One constant name: Z One one-argument function name: succ(·) No relation names. Pair this system with the following two axioms: ∀x. Z 6= succ(x) ∀x. ∀y. succ(x) = succ(y) =⇒ x = y (a) Give an interpretation I which makes both axioms true. Our interpretation is in the universe of natural numbers, N. Set Z = 0, and succ(x) = x + 1. We satisfy the first axiom, since there is no natural number you can add one to to get zero. We satisfy the second axiom, as adding one is injective (we can invert it by subtracting one). (b) Define succn (x) to be the succ function applied n times to x. Is it true that in all interpretations I, for all objects x in the interpretation, x = succn (Z) for some n ∈ N? 1 While this is true in our previous interpretation, it is not true for all interpretations. Consider the following: Our universe is N ∪ {c}. We define Z = 0 as before, and succ(n) = n + 1 if n ∈ N. However, for c, we define succ(c) = c. All axioms hold for similar reasons as in the first problem (it is easy to see that if succ(x) = succ(c), x = c). We note that c 6∈ N, and thus cannot be obtained by repeated application of the successor function, so the claim is false. Regular Modulus (a) Prove that the language of binary strings whose numeric interpretation is equal to 0 (mod 3) is regular. We read from the most significant bit to the least. Our DFA has 3 states, denoted Q = {0, 1, 2}. Our transition function δ is defined by δ(s, x) = 2 ∗ s + x (mod 3). Our only accept state is 0. Our initial state is 0. The alphabet is {0, 1}. We claim that if a string s ends in state i, then the string s represents a number in binary which is equal to i (mod 3). To see this, first note that the initial state is 0 (we assume is a valid representation of 0). Inductively, suppose that some string s is in the correct state i. Now, we encounter a new character x. If x = 0, our number s doubles. If x = 1, it doubles and then adds 1. As addition and multiplication are valid operations modulo 3, our transition function deals with these cases correctly, so by induction our claim is true. Now, we thus have that if s ends at state 0, it is 0 (mod 3), and otherwise it is not, which is exactly what our accept states say, concluding the proof. (Note: The technique above is known as “invariant induction”. This is where we prove some invariant about a system holds throughout every step, by proving it works initially, then if it works at any given point, it continues to work after one more step.) (b) What if we read from the least significant bit to the most? 2 The language read this way is still regular! Define our DFA as follows: We have 6 states, denoted Q = {(0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (2, 1)} Our transition function δ is deifned by δ((m, z), x) = (m + x ∗ (z + 1) (mod 3), 1 − z) (This transition function looks a little weird, but it will be explained later). Our accept states are {(0, 0), (0, 1)}. Our initial state is (0, 0). The alphabet is {0, 1}. We claim that if a string s ends in state (m, z), then the string s represents a number in binary (reversed) which is equal to m (mod 3), and has length equal to z (mod 2). The empty string clearly starts in the correct state. Inductively, suppose some string s ends in the correct state (m, z), and the next character we read is x. We wish to show that δ((m, z), x) preserves our invariant for the string sx Preserving the invariant for z is trivial, as every time we read a new character, the parity of the length changes, which 1 − z computes. Now, we prove preservation for m. If x = 0, then the value of s (mod 3) is equal to sx (mod 3), as we just added a most significant zero, which does not affect modulus at all. This is reflected in the transition function, as the first element of the tuple is m + x ∗ (z + 1) = m + 0 = m. If x = 1, then we claim the value of s will change by adding z + 1. If we don’t work modulo 3, adding a 1 in position i will add 2i to the value of the number. However, we are working modulo 3. It is easy to show that if i is even, then we add 1 (mod 3), and we add 2 (mod 3) otherwise. As z = 0 exactly when we add in the even position and z = 1 for odd, adding x ∗ (z + 1) = z + 1 (mod 3) changes the modulus in the correct way. By induction, our invariant is preserved. Now, by invariant, our accept states are clearly correct, as we are looking for 0 modulo 3, and these are the only such states, concluding the proof. I need more states / Prove that Ln = {ank | k > 0} cannot be decided by a DFA with fewer than n + 1 states. 3 Suppose for the sake of contradiction that there were some DFA D which decides Ln on fewer than n + 1 states. Consider what heppens when we give it the string an . First, it must end in some accept state S, as an ∈ Ln . Second, as an has n characters, throughout reading it, we touch n + 1 states (including the initial state). As there are fewer than n + 1 states, by pigeonhole, there is some state S 0 which we reach twice, throughout the string. More formally, there exist x, y, z ∈ N such that y > 0, x + y + z = n, ax ends in state S 0 , and ax ay ends in state S 0 as well (this is how we represent “reaching it twice”). Now, consider that starting at state S 0 and reading string az gets us to state S, as ax ay az = an , which ends in state S. However, this also means ax az ends in state S and accepts. By y > 0, x + z < n. However, an is the shortest string in Ln , as strings must be of the form ank for k > 0. This is a contradiction, as ax az should thus not be accepted, but it is, concluding the proof. Irregular languages are cooler languages Prove that the language L = {ww | w ∈ {a, b}∗ } is irregular. Suppose for the sake of contradiction that L were decided by a DFA D on n states. Consider the set of strings {ak | k ∈ {0, · · · , n}}. As there are n + 1 strings in this set, there must be two strings ak and al (k 6= l) which end in the same state of D, by pigeonhole principle. Now, consider the string ak bak b. Setting w = ak b, this should be accepted by D. However, al bak b should not be, as l 6= k, and there is no choice of w such that al bak b = ww. However, as ak and al end in the same state, and we append bak b to the end of both, both these strings end in the same state, and thus both accept or both reject. As they must have different behaviors but D has the same behavior on both, this is a contradiction, so L is irregular. Closure of Regularity (a) Prove that if L is regular, then LC is regular. Let L be a regular language and consider its DFA. We construct a new DFA by turning every accept state into a normal state, and making every normal state an accept state. This new DFA then accepts a string if and only if L’s DFA did not, which is exactly the definition of complement. It follows that LC is regular. (b) Prove that if L1 and L2 are regular, then L1 ∩ L2 is regular. 4 Use the construction for union from lecture, where we took the cross product of the state sets of L1 and L2 , and copy the same transitions. Instead of setting a state to be accept if either of the elements of the pair accepted, instead we make a state (a, b) accept if and only if both a and b were accept states. This works as we require a string to be accepted by both L1 and L2 , by definition of intersection. (c) Use closure properties to show that L = {w | w ∈ {0, 1}∗ and w has the same number of 0s and 1s} is irregular. Suppose for the sake of contradiction that L were regular. Now, consider L0 = {0n 1m | n, m ∈ N}. This is trivially regular (have a DFA with 3 states, one while looping on 0, one while looping on 1, which is the accept state, and one failure state if we go back to 0). However, note that L ∩ L0 = {0n 1n | n ∈ N}, which we have established to be irregular. As regularity is closed under intersection, we have a contradiction, so L must be irregular. 5
© Copyright 2024