CSE 555 Homework Three and a Half Sample Solutions

This is a bonus homework, and is optional. A context-free grammar is linear if every rule is of the form A → u or A → uBv with A, B ∈ V and u, v ∈ Σ∗. A language is linear if it is generated by a linear grammar. For L ⊆ Σ∗, let half(L) = {w : w ∈ Σ∗, ∃y ∈ Σ∗ with |y| ∈ {|w|, |w| + 1} and wy ∈ L}.

Question 1

Prove: Every is linear but not every linear language is regular. Solution: every regular language is linear: this is true because every regular language is described by a DFA. This DFA can be transformed into a , which has rules of the form A → bC, A → C,A →  for variables A, C, and terminal b. For every rule, there is at most 1 variable on the right-hand side, so this grammar is linear. Therefore, every regular language is linear. Not every linear language is regular: consider L = {0n1n : n ≥ 0}; this is the canonical non-regular language. It is described by the following linear grammar: S →  | 0S1.

Question 2

Prove: Every linear language is context-free but not every context-free language is linear. (Hint: Can you adapt the proof of the pumping lemma for CFLs to get a stronger statement for linear languages?) Solution: we prove the “Pumping Lemma for Linear Languages,” which states: let L be a linear language. Then there is a constant p such that for any w ∈ L with |w| ≥ p, we can write w as uvxyz such that |uvyz| ≤ p, |vy| ≥ 1, and uvixyiz ∈ L for all i ≥ 0. Note that the difference between this and the one for CFLs is that |uvyz| ≤ p here, instead of |vxy| ≤ p. Proof: if L is linear, then there is a linear grammar G for it. Assume that G has no unit-rules (of the form A → A) nor -rules (of the form A → ) (which can be removed while preserving linearity). Consider the derivation tree as given by the Pumping Lemma for CFLs, and consider the longest root-to-leaf path in the tree (which has height large enough to guarantee a variable, say A, repeat). Note that the only instance of variables in the tree appear on this path. Since there are a finite number of variables from S to the first A, and each generates a finite number of terminals, u and z are bounded. Similarly, v and y are also bounded. Every linear language is context-free: by definition, any linear language is generated by a linear grammar. Since linear grammars are a special form of context-free grammars, all linear languages are context-free. For the second part, we just need one example of a CFL that is not linear. Consider L = {w :#a(w) = #b(w)}. Certainly, this is context-free. Assume that L is linear; therefore, there exists a constant p for L. Choose w = apb2pap; we see that w ∈ L and |w| ≥ p. Pumping this string yields another string of the form am+kb2mam+` with either k ≥ 1 or ` ≥ 1. Therefore, this string is not in L, and we can conclude L is not linear.

Question 3

Let CUTLG = {hGi : G is a linear grammar for which half(L(G)) = L(G)}. Prove or disprove: CUTLG is decidable. ∗ Solution: this is undecidable. Consider the problem ALLLG = {hGi : G is a linear grammar and L(G) = Σ }. We prove that this problem is undecidable in the same manner as is done with the proof of ALLCFG undecidable. We need to generate a linear grammar G that accepts all strings that are not accepting computation histories for the given TM M on input w: 1. Strings that do not start with the start configuration–suppose the start state is q0 and the input is w = w1 ··· wn. Then the starting configuration is q0w1 ··· wn. This part needs to generate every string that is not of the form ∗ ∗ ∗ #q0w1 ··· wn#Γ . This is equivalent to recognizing Γ \(#q0w1 ··· wn#Γ )–this is regular, and by Question 1, is linear. 2. Strings that do not end with an accepting configuration–this is very similar to the first grammar, and so therefore is linear.

1 3. Strings in which some configuration does not yield the next one, based on M’s transition function–we construct a variable A will handle, nondeterministically, checking adjacent configurations in which one does not yield the next. Note that the grammar from Question 5 of HW1 is linear. However, this handles when two adjacent configurations are valid: (a) A → xSv for distinct x, v ∈ Γ where S → xS |  for x ∈ Γ. In other words, if there is a mismatch between matching reversed characters in the adjacent configurations, we just go to S and read off the rest of the input. (b) A → xAx for x ∈ Γ (i.e., read off matching characters) (c) A → B (go to the phase of checking for all possible strings that are not valid transitions, described below) (d) C → xSv | # for distinct x, v ∈ Γ, (e) C → xCx for x ∈ Γ, (f) C → x for x ∈ Γ and x 6= #. Now for handling a valid transition between the two consecutive pieces, note that there are only a finite number of possibilities. Therefore, all strings that are recognized as invalid transitions is regular, and therefore linear. The rules of this form are described similarly to Question 5 in HW1, and go from variable B to C (from the description above). We leave it as an exercise to be able to extend this for any number of configurations (hint: any number of tape characters to the left and right of the 2 adjacent configurations, and nondeterminism). Therefore, this is described by a linear grammar. The logic behind the proof for ALLCFG being undecidable follows. Now we show that CUTLG is undecidable via a variation on the reduction from ATM to ALLLG. Suppose that M accepts w–there is an accepting computation history. If we look at the first half of the accepting computation history, then it is not one (since the computation stops immediately when we first reach qaccept)–therefore, we reject (as we did for ALLLG). Now suppose M does not accept w–there is no accepting computation history. Therefore, ALLLG will accept, and since half(Σ∗) = Σ∗ (left as an exercise), we must accept.

Question 4a

Prove or disprove: If half(L) is linear so is L. Solution: this is false. One can see a proof by looking at the language of strings described by the choice of w in Question 2: L = {anb2nan : n ≥ 0}; it is proved there that L is not linear. However, half(L) = {anbn : n ≥ 0}, which is linear.

Question 4b

Prove or disprove: L is regular so is half(L). Solution: this is true, given here: http://www-bcf.usc.edu/~breichar/teaching/2011cs360/half(L)example.pdf.

Question 5

A single-turn is a PDA with the additional restriction that it must execute in two phases. In the first phase, the stack is allowed to grow but never shrink (so every pop must be accompanied by a push in transitions applied); in the second phase, the stack is allowed to shrink but not grow (so every push must be accompanied by a pop in transitions applied). In other works, the stack top can only make one ‘turn’ from growing to shrinking–or more precisely from not shrinking to not growing! Prove: A language is linear if and only if it is recognized by a single-turn PDA. Solution: call these STPDAs (single-turn PDAs). We show that given an LG, we can construct a STPDA; also, we show that given an STPDA, we can construct an LG. (⇒) Given an LG G, we want to construct an STPDA P . This is answered by Ginsburg and Spanier in their “Finite-Turn Pushdown Automata” paper: http://epubs.siam.org/doi/pdf/10.1137/0304034. (⇐) Given an STPDA P , we want to construct an LG G. This is answered at the CSE355 Spring 2016 offering, HW4, Question 4: http://www.public.asu.edu/~ccolbou/src/355hw4s16sol.pdf

2